Skip to content

Creating your own custom meta fields

nadavrt edited this page May 29, 2015 · 4 revisions

If you need a field type that is not included in the class you can add it by including a case for it in the $field['type'] switch inside the render_field method in simple-meta-boxes.php. Both regular fields and repeatable group fields can be add this way. If you wish to add a custom repeater field you will also need to add this field to the $field['type'] switch inside the render_repeater_field method.

To create a mandatory custom sanitation filter for this field first create a sanitation method for it (see Using sanitation filters and methods to learn how). Then search for the //Mandatory Sanitize Methods: note in the save_meta_data method in simple-meta-boxes.php and add a call to the sanitation method for this field type after it.

If you are planning to use the required key with this custom field most chances are you will also need to edit simple-meta-boxes.js. The SMBFieldValidator class inside simple-meta-boxes.js is the one responsible for validating required fields, and it already has some predefined methods for your convenience.

Clone this wiki locally