Last active
June 7, 2016 15:39
-
-
Save bacoords/2cff4fad9641e794e6b07bcf14f7a674 to your computer and use it in GitHub Desktop.
CMB2 Example Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: CMB2 Wiki | |
// https://github.com/WebDevStudios/CMB2/blob/master/example-functions.php | |
// https://github.com/WebDevStudios/CMB2/wiki/Basic-Usage | |
add_action( 'cmb2_admin_init', 'prefix_register_demo_metabox' ); | |
function prefix_register_demo_metabox() { | |
$prefix = '_prefix_' | |
$cmb = new_cmb2_box( array( | |
'id' => $prefix . 'metabox', | |
'title' => __( 'Test Metabox', 'cmb2' ), | |
'object_types' => array( 'post', ), // Post type | |
// 'show_on_cb' => 'yourprefix_show_if_front_page', // function should return a bool value | |
// 'context' => 'normal', | |
// 'priority' => 'high', | |
// 'show_names' => true, // Show field names on the left | |
// 'cmb_styles' => false, // false to disable the CMB stylesheet | |
// 'closed' => true, // true to keep the metabox closed by default | |
) ); | |
// URL text field | |
$cmb->add_field( array( | |
'name' => __( 'Website URL', 'cmb2' ), | |
'desc' => __( 'field description (optional)', 'cmb2' ), | |
'id' => $prefix . 'url', | |
'type' => 'text_url', | |
// 'protocols' => array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'), // Array of allowed protocols | |
// 'repeatable' => true, | |
) ); | |
// Email text field | |
$cmb->add_field( array( | |
'name' => __( 'Test Text Email', 'cmb2' ), | |
'desc' => __( 'field description (optional)', 'cmb2' ), | |
'id' => $prefix . 'email', | |
'type' => 'text_email', | |
// 'repeatable' => true, | |
) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment