- 
      
- 
        Save anthonybudd/80a3d3233c1dde86e2a0f5bc4402428c to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public static function fieldsCallback(){ | |
| $this_ = Self::newWithoutConstructor(); | |
| if(method_exists($this_, 'cmb2Fields')){ | |
| $fields = $this_->cmb2Fields(); | |
| if(function_exists('new_cmb2_box') && is_array($fields)){ | |
| if(!isset($fields['meta_box'])){ | |
| $fields['meta_box'] = [ | |
| 'id' => get_called_class(), | |
| 'title' => get_called_class(), | |
| 'object_types' => array($this_->postType), | |
| ]; | |
| } | |
| $cmb = new_cmb2_box($fields['meta_box']); | |
| unset($fields['meta_box']); | |
| foreach($fields as $field){ | |
| $cmb->add_field($field); | |
| } | |
| } | |
| } | |
| } | |
| public function cmb2Fields(){ | |
| return [ | |
| [ | |
| 'name' => 'Test Text', | |
| 'id' => 'text', | |
| 'type' => 'text', | |
| ],[ | |
| 'name' => 'Website URL', 'cmb2', | |
| 'id' => 'url', | |
| 'type' => 'text_url', | |
| ] | |
| ]; | |
| } | |
| add_action('cmb2_admin_init', [get_called_class(), 'fieldsCallback']); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment