Custom-Metabox Documentation

Quick Start

Download Custom-Metabox. Include the custom-metabox/class-ap-custom-metabox-apply.php with your plugin index.php or functions.php file. After that copy & paste this code.

Explain

“ap_meta_apply” with the filter hook new field has been added.

First, reset Initially announced fields with this empty array.

Within this field, array passes the post type  & other properties.  Window title will be the “label” name.  Within “post_option” array. Inputs array contains all the fields array.

Add new field:

NOTE: – After add_filter  have to instantiate AP_Custom_Metabox_apply class.

Start with Apply class

Download Custom-Metabox. Include the custom-metabox/class-ap-custom-metabox-apply.php with your plugin index.php or functions.php file.  Uncomment new AP_Custom_Metabox_apply();  last line of  class-ap-custom-metabox-apply.php file.  Edit the fields array to add your own custom  metaboxes.

Add new meta box for ‘post’ post type

Preview of Custom Field

You can add Preview of the custom field after saving if necessary.

Note: – Preview is not supported for Repeater & gallery field.

Add a Preview 

Action hook “ap_display_function_(Custom Field name)”. For “portfolio_vd” field the action hook will be  “ap_display_function_portfolio_vd”. The first parameter contains the value of the field.  For example, I have embedded the URL here. So if you give a Youtube video URL after saving the post it will display the youtube video.

 

 

 

 

 

 

 

 

 

 

 

Repeater Field

To add repeater field type will be “repeater “. Array Key “child_inputs”.  Within child_inputs array add all the field you want to repeat.

Dependency with Nested Dependancy

Nested dependency is available with Custom Metabox.

What is  Dependancy?

A field will display depending on the value of another field.   This is called dependency.

Suppose there Email example field will display if Text example field value is email. otherwise not.

What is  Nested Dependancy?

A field will display depending on the value of another dependent field. So the Dependent field Value is matched with given value the field will display if the dependent field is also displaying other both field will be hidden.

Suppose URL Example field will display if the Email example field value is “abcd@def.com” & Email example is also displaying. So the Text example field value is not “email” both fields will be hidden.

 

dependency array accepts three keys (name, value & sub).

‘name’ will be the class name of the dependent field. This is required.

‘value’ will be the value of the dependent field for which this field will display. This is also required.

‘sub’  is for nested dependency only. This is optional. ‘sub’ will be the class name of the dependent’s dependent field.

Fields

Text

Textarea

URL

Email

Color

Select/Dropdown

Radio

Gallery

We are still working with the PHP script. If you want to contribute you can send a pull request. More field type will be added.  We are trying to make the process easy of adding custom field type.

Leave a Reply

Your email address will not be published. Required fields are marked *