Skip to content

Instantly share code, notes, and snippets.

@ejntaylor
Created November 24, 2016 09:57
Show Gist options
  • Save ejntaylor/d5f8a251dda1583492243846b060d0db to your computer and use it in GitHub Desktop.
Save ejntaylor/d5f8a251dda1583492243846b060d0db to your computer and use it in GitHub Desktop.
<?php
// cmb2
// hook the function to the cmb2_init action
add_action( 'cmb2_init', 'cmb2_sample_metaboxes' );
// create the function that creates metaboxes and populates them with fields
function cmb2_sample_metaboxes() {
// set the prefix (start with an underscore to hide it from the custom fields list
$prefix = '_my_prefix_';
// create the metabox
$cmb = new_cmb2_box( array(
'id' => 'site_meta',
'title' => 'Site Metabox',
'object_types' => array( 'sites' ), // post type
'context' => 'normal', // 'normal', 'advanced' or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // show field names on the left
'cmb_styles' => true, // false to disable the CMB stylesheet
'closed' => true, // keep the metabox closed by default
// 'save_fields' => false,
) );
$cmb->add_field( array(
'name' => 'Site URL',
'id' => 'site_url',
'type' => 'text_url',
) );
$cmb->add_field( array(
'name' => 'Site Referring URL',
'id' => 'site_url_refer',
'type' => 'text_url',
) );
$cmb->add_field( array(
'name' => 'Site Title',
'id' => 'site_title',
'type' => 'text',
) );
$cmb->add_field( array(
'name' => 'Site Blog URL',
'id' => 'site_url_blog',
'type' => 'text_url',
) );
$cmb->add_field( array(
'name' => 'Site Admin Email',
'id' => 'site_admin_email',
'type' => 'text_email',
) );
$cmb->add_field( array(
'name' => 'Prize File',
'desc' => 'Upload file for prize downloads',
'id' => 'site_prize_file',
'type' => 'file',
// Optionally hide the text input for the url:
'options' => array(
'url' => false,
),
) );
$cmb->add_field( array(
'name' => 'First Email',
'id' => 'site_admin_first_email',
'type' => 'wysiwyg',
) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment