-
Notifications
You must be signed in to change notification settings - Fork 46
How to add item to a meta box
Now that we know how to add a meta box to a column, we can now use items. Items can be tables or form input. Both can be added to a meta box. The first thing to do is to create an item.
We recommend you to choose "panel-ho" for adding table. Such as meta box, there are many type of tables. To combine table with meta box (panel-ho), a table ought have "table-panel" as type. If it's set to "table", a classic table will be outputted.
You can add table this way :
$this->gui->set_item( Array );
This method takes an array as parameters. Array which accepts thoses keys : label, placeholder, type[radio,checkbox,text,visual_editor,password,select,textarea,table,table-panel],text(String/Array),value(String/Array)
Each keys aren't supported by the entire items. Some keys are just ignored such as "value" and "text" for "table" and "table-panel" item.
Therefore, creating table will be made this way :
$this->gui->set_item( array(
'type' => 'table' // or table-panel
'label' => __( 'Custom Table' ),
'cols' => array( __( 'Cols 1') , __( 'Cols 2' ), __( 'Cols 3' ), __( 'Cols 4' ) ),
'rows' => array( array( __( 'Row 1' ), __( 'Row 2' ), __( 'Row 3'), __( 'Row 4' ) ) )
) );
For "Table" and "Table-panel" item, two new keys are required "cols" and "row". Cols represent table header and "Rows" represent each table row.
Creating form input is different from creating table. What you should keep in mind is that each items are displayed in the way and order they are created. So now that we're about to create a form input, this one will be outputted after the table created earlier.
This is the way forms input are created :
$this->gui->set_item( array(
'type' => 'text',
'name' => 'custom_input',
'placeholder' => __( 'Custom Input' ),
'text' => __( 'Custom text input' ),
'value' => ''
) );
Tips: You may have noticed that some keys are commonly used as HTML attributes. The type "visual_editor" add Tendoo Visual Editor (CkEditor) as input.
Now again, we're about to use "push_to" method, chained to "set_item" method. Instead of specifying numeric variable as column id, we'll use meta box namespace.
Reminder : Meta box namespace is the first parameter used on "add_meta" method.
To add both item (table or form input) to a meta box, follow this step :
$this->gui->set_item( /* Setting Item */ )->push_to( 'custom_meta' );
// Where "custom_meta" is a valid meta box already created.