Wordpress custom post type capabilities, admin can't edit post type -
i'm having wired problem wordpress. below code events post type, works without capabilities when capabilities added default roles (admin, editor, etc...) cant use post type. admin role able see custom taxonomies.
i have custom user role "edit_events => true" user role able submit events review. want, built in roles can't see post type!
i've tried every capabilities tutorial find, seem pretty same , can't how of them differ code.
function register_custom_event_type() { $labels = array( 'name' => _x('events', 'event'), 'singular_name' => _x('event', 'event'), 'add_new' => _x('add new', 'event'), 'add_new_item' => _x('add new event', 'event'), 'edit_item' => _x('edit event', 'event'), 'new_item' => _x('new event', 'event'), 'view_item' => _x('view event', 'event'), 'search_items' => _x('search events', 'event'), 'not_found' => _x('no events found', 'event'), 'not_found_in_trash' => _x('no events found in trash', 'event'), 'parent_item_colon' => _x('parent event:', 'event'), 'menu_name' => _x('events', 'event'), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'supports' => array('title', 'editor', 'thumbnail', 'author'), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, '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' => 'event', 'capabilities' => array( 'read_post' => 'read_event', 'publish_posts' => 'publish_events', 'edit_posts' => 'edit_events', 'edit_others_posts' => 'edit_others_events', 'delete_posts' => 'delete_events', 'delete_others_posts' => 'delete_others_events', 'read_private_posts' => 'read_private_events', 'edit_post' => 'edit_event', 'delete_post' => 'delete_event', ), 'map_meta_cap' => true ); register_post_type('event', $args); } add_action('init', 'register_custom_event_type');
i found work around in end.
i thought default wordpress roles have same capabilities post type normal post, reason don't.
adding capabilities manually seems work.
function add_event_caps() { $role = get_role( 'administrator' ); $role->add_cap( 'edit_event' ); $role->add_cap( 'edit_events' ); $role->add_cap( 'edit_others_events' ); $role->add_cap( 'publish_events' ); $role->add_cap( 'read_event' ); $role->add_cap( 'read_private_events' ); $role->add_cap( 'delete_event' ); } add_action( 'admin_init', 'add_event_caps');
Comments
Post a Comment