Skip to content

Instantly share code, notes, and snippets.

@dcavins
Created May 5, 2015 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dcavins/fd73d7f0b67f6c2581fa to your computer and use it in GitHub Desktop.
Save dcavins/fd73d7f0b67f6c2581fa to your computer and use it in GitHub Desktop.
Declaring a Sample CPT and Custom Menu
// Create the CPT using special caps
add_action( 'init', 'register_cpt_sample_cpt' );
function register_cpt_sample_cpt() {
$labels = array(
'name' => _x( 'Sample CPT', 'sample_cpt' ),
'singular_name' => _x( 'Sample CPT', 'sample_cpt' ),
'add_new' => _x( 'Add New', 'sample_cpt' ),
'add_new_item' => _x( 'Add New Sample CPT', 'sample_cpt' ),
'edit_item' => _x( 'Edit Sample CPT', 'sample_cpt' ),
'new_item' => _x( 'New Sample CPT', 'sample_cpt' ),
'view_item' => _x( 'View Sample CPT', 'sample_cpt' ),
'search_items' => _x( 'Search Sample CPT', 'sample_cpt' ),
'not_found' => _x( 'No sample cpt found', 'sample_cpt' ),
'not_found_in_trash' => _x( 'No sample cpt found in Trash', 'sample_cpt' ),
'parent_item_colon' => _x( 'Parent Sample CPT:', 'sample_cpt' ),
'menu_name' => _x( 'Sample CPT', 'sample_cpt' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array( 'title', 'editor' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => 'custom_menu',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'sample_cpt',
'map_meta_cap' => true
);
register_post_type( 'sample_cpt', $args );
}
add_action( 'admin_menu', array( $this, 'register_admin_page_aggregator' ) );
add_menu_page( $page_title = 'Custom Menu',
$menu_title = 'Custom Menu',
$capability = 'edit_sample_cpt',
$menu_slug = 'custom_menu',
$function = 'sample_display_function',
$icon_url = 'dashicons-arrow-right',
$position = 48 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment