Created
February 2, 2019 11:22
-
-
Save flegfleg/2ac283d05d1706f818404b24cac6472a to your computer and use it in GitHub Desktop.
add caps to wp custom post types
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
<?php | |
function create_post_type_items() { | |
register_post_type( 'acme_item', | |
array( | |
'labels' => array( | |
'name' => __( 'CB2 Items' ), | |
'singular_name' => __( 'CB2 Item' ) | |
), | |
'public' => true, | |
'has_archive' => true, | |
'capabilities' => array( | |
'edit_post' => 'edit_item', | |
'edit_posts' => 'edit_items', | |
'edit_others_posts' => 'edit_other_items', | |
'publish_posts' => 'publish_items', | |
'read_post' => 'read_item', | |
'read_private_posts' => 'read_private_items', | |
'delete_post' => 'delete_item' | |
), | |
// adding map_meta_cap will map the meta correctly | |
'map_meta_cap' => true | |
) | |
); | |
} | |
function create_post_type_locations() { | |
register_post_type( 'acme_location', | |
array( | |
'labels' => array( | |
'name' => __( 'CB2_Locations' ), | |
'singular_name' => __( 'CB2 Location' ) | |
), | |
'public' => true, | |
'has_archive' => true, | |
'capabilities' => array( | |
'edit_post' => 'edit_location', | |
'edit_posts' => 'edit_locations', | |
'edit_others_posts' => 'edit_other_locations', | |
'publish_posts' => 'publish_locations', | |
'read_post' => 'read_location', | |
'read_private_posts' => 'read_private_locations', | |
'delete_post' => 'delete_location' | |
), | |
// adding map_meta_cap will map the meta correctly | |
'map_meta_cap' => true | |
) | |
); | |
} | |
add_action( 'init', 'create_post_type_items' ); | |
add_action('init', 'create_post_type_locations'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment