Skip to content

Instantly share code, notes, and snippets.

@Benoti
Last active August 29, 2015 14:11
Show Gist options
  • Save Benoti/9f95369194f68bc04b49 to your computer and use it in GitHub Desktop.
Save Benoti/9f95369194f68bc04b49 to your computer and use it in GitHub Desktop.
[SNIPPET OF CODE] For debugging cmb2 => this plugin doesn't work if another plugin with cmb2 library has already been activate. Working if the another is deactivated.
$fcpt_posttype = 'submissions';
global $fcpt_posttype;
global $myCustomTypeOptions;
// Register Custom Post Type submissions
function brozzme_fcpt_submission_post_type() {
global $fcpt_posttype;
$capabilities = array(
'publish_posts' => 'publish_submissions_entry',
'edit_posts' => 'edit_submissions_entry',
'edit_others_posts' => 'edit_others_submissions_entry',
'delete_posts' => 'delete_submissions_entry',
'delete_others_posts' => 'delete_others_submissions_entry',
'read_private_posts' => 'read_private_submissions_entry',
'edit_post' => 'edit_submissions_entry',
'delete_post' => 'delete_submissions_entry',
'read_post' => 'read_submissions_entry'
);
$labels = array(
'name' => _x( 'Demandes', 'Post Type General Name', 'brozzme' ),
'singular_name' => _x( 'Demande', 'Post Type Singular Name', 'brozzme' ),
'menu_name' => __( 'Messages reçus', 'brozzme' ),
'parent_item_colon' => __( 'Parent Item:', 'brozzme' ),
'all_items' => __( 'Messages', 'brozzme' ),
'view_item' => __( 'View Item', 'brozzme' ),
'add_new_item' => __( 'Add New Message', 'brozzme' ),
'add_new' => __( 'Add New', 'brozzme' ),
'edit_item' => __( 'Edit Item', 'brozzme' ),
'update_item' => __( 'Update Item', 'brozzme' ),
'search_items' => __( 'Search Item', 'brozzme' ),
'not_found' => __( 'Not found', 'brozzme' ),
'not_found_in_trash' => __( 'Not found in Trash', 'brozzme' ),
);
$args = array(
'label' => $fcpt_posttype,
'description' => __( 'Enregistrement des formulaires de demande de renseignements', 'brozzme' ),
'labels' => $labels,
'taxonomies' => array('post_tag'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => '5',
'menu_icon' => 'dashicons-id-alt',
'can_export' => true,
'has_archive' => true,
'rewrite' => array('slug' => $fcpt_posttype),
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'post',
'supports' => array('title', 'custom-fields', 'thumbnail' )
);
register_post_type( $fcpt_posttype, $args );
}
add_action( 'init', 'brozzme_fcpt_submission_post_type' );
add_filter('cmb2_meta_boxes', 'brozzme_form_cpt_metaboxes');
/**
* Define the metabox and field configurations.
*
* @param array $meta_boxes
* @return array
*/
function brozzme_form_cpt_metaboxes( $meta_boxes ) {
// Start with an underscore to hide fields from custom fields list
$prefix = 'fcpt_';
/**
* Sample metabox to demonstrate each field type included
*/
$meta_boxes['submissions'] = array(
'id' => 'submissions',
'title' => 'Messages',
'object_types' => array('submissions'), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
// 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend
'fields' => array(
array(
'name' => 'Instructions',
'desc' => 'Set up your own display block.',
'type' => 'title',
),
array(
'name' => 'Name',
'desc' => 'user name',
'id' => $prefix.'_name',
'type' => 'text_medium'
),
array(
'name' => __( 'Last name', 'cmb2' ),
'desc' => 'user last name',
'id' => $prefix. 'last_name',
'type' => 'text_medium',
),
array(
'name' => 'Email',
'desc' => 'user email',
'id' => $prefix.'email',
'type' => 'text_email'
),
array(
'name' => 'Message',
'desc' => 'user message',
'id' => $prefix.'message',
'type' => 'textarea'
),
)
);
return $meta_boxes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment