-
Notifications
You must be signed in to change notification settings - Fork 124
Adding your own field types
joehoyle edited this page Nov 17, 2012
·
14 revisions
To add your own field type you must extend the base class CMB_Field
and implement some methods. Primarily you will need to add the html()
method which is responsible for outputting a single copy of your field.
Taking an email field as an example:
class Email_Field extends CMB_Field {
public function html() {
?>
<p>
<input type="email" name="<?php echo $this->name ?>" value="<?php echo esc_attr( $this->get_value() ) ?>" />
</p>
<?php
}
}
There are several other methods you can implement, for example if you field needs extra JavaScript or CSS you can wp_enqueue_script
/ wp_enqueue_script
by implementing enqueue_scripts
and enqueue_styles
respectively. See https://github.com/humanmade/Custom-Meta-Boxes/blob/master/classes.fields.php#L688 for an example of this.
- Setup/Install Custom Meta Boxes
- Creating a custom meta box
- Displaying Field Data
- Optional Generic Field Args
- Repeatable Fields
General
- Text Field
- Small Text Field
- Number Field
- URL Field
- Textarea Field
- Code Field
- Select Field
- Checkbox Input Field
- Radio Input Field
Date & Time
WordPress
Media
Utilities