Ejemplo n.º 1
0
 public function testCmb()
 {
     // Start with an underscore to hide fields from custom fields list.
     $prefix = '_yourgridprefix_demo_';
     /**
      * Sample metabox to demonstrate each field type included.
      */
     $cmb = new_cmb2_box(array('id' => $prefix . 'metabox', 'title' => __('Test Metabox using a Grid', 'cmb2'), 'object_types' => array('page')));
     $field1 = $cmb->add_field(array('name' => __('Test Text', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'text', 'type' => 'text'));
     $field2 = $cmb->add_field(array('name' => __('Test Text Small', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'textsmall', 'type' => 'text'));
     $field3 = $cmb->add_field(array('name' => __('Test Text Medium', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'textmedium', 'type' => 'text'));
     $field4 = $cmb->add_field(array('name' => __('Website URL', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'url', 'type' => 'text'));
     $field5 = $cmb->add_field(array('name' => __('Test Text Email', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'email', 'type' => 'text'));
     $cmb2Grid = new \Cmb2Grid\Grid\Cmb2Grid($cmb);
     $row = $cmb2Grid->addRow();
     $row->addColumns(array(array($field1, 'class' => 'col-md-8'), array($field2, 'class' => 'col-md-4')));
     $row = $cmb2Grid->addRow();
     $row->addColumns(array($field3, $field4, $field5));
 }
Ejemplo n.º 2
0
 /**
  * NOTE:     Your metabox on Demo CPT
  *
  * @since    0.0.1
  */
 public function cmb_demo_metaboxes()
 {
     // Start with an underscore to hide fields from custom fields list
     $prefix = '_demo_';
     $cmb_demo = new_cmb2_box(array('id' => $prefix . 'metabox', 'title' => __('Demo Metabox', $this->plugin_slug), 'object_types' => array('demo'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true));
     $cmb2Grid = new \Cmb2Grid\Grid\Cmb2Grid($cmb_demo);
     $row = $cmb2Grid->addRow();
     $field1 = $cmb_demo->add_field(array('name' => __('Text', $this->plugin_slug), 'desc' => __('field description (optional)', $this->plugin_slug), 'id' => $prefix . $this->plugin_slug . '_text', 'type' => 'text'));
     $field2 = $cmb_demo->add_field(array('name' => __('Text Small', $this->plugin_slug), 'desc' => __('field description (optional)', $this->plugin_slug), 'id' => $prefix . $this->plugin_slug . '_textsmall', 'type' => 'text_small'));
     $row->addColumns(array($field1, $field2));
 }