Я создал несколько пользовательских типов сообщений и пользовательскую роль. Все работает нормально, пока я не назначу пользовательские типы сообщений для пользовательского меню, после этого мой пользователь больше не будет иметь доступа к пользовательским типам сообщений. Я получаю следующую ошибку: «Извините, у вас нет доступа к этой странице».
Я хочу, чтобы все типы сообщений, предлагаемые мной в предложении, находились в раскрывающемся меню Предложения. Это работает, но когда я нажимаю на пользовательские типы сообщений, моя роль пользователя больше не может получить доступ к типам сообщений. Что я делаю неправильно? Я просмотрел все, но не могу найти ответ.
Пользовательское меню:
function offers_admin_menu() {
add_menu_page(
'Offers',
'Offers',
'read',
'offers-menu',
'',
'dashicons-tag',
10);
}
add_action( 'admin_menu', 'offers_admin_menu' );
Пользовательский тип сообщения:
//Register Veganuary Offer Post Type
add_action('init', 'register_custom_offer_type');
function register_custom_offer_type() {
register_post_type('offer',
array(
'labels' => array(
'name' => _x('Veganuary Offers', 'Veganuary Offer'),
'singular_name' => _x('Veganuary Offer', 'domain'),
'add_new' => _x('Add New', 'domain'),
'add_new_item' => _x('Add New Veganuary Offer', 'domain'),
'edit' => _x('Edit', 'domain'),
'edit_item' => _x('Edit Veganuary Offer', 'domain'),
'new_item' => _x('New Veganuary Offer', 'domain'),
'view' => _x('View Veganuary Offer', 'domain'),
'view_item' => _x('View Veganuary Offer', 'domain'),
'search_items' => _x('Search Veganuary Offers', 'domain'),
'not_found' => _x('No Veganuary Offers found', 'domain'),
'not_found_in_trash' => _x('No Veganuary Offers found in Trash', 'domain')
),
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
'can_export' => true,
'taxonomies' => array( 'category' ),
'show_in_menu' => 'offers-menu',
'menu_icon' => 'dashicons-tag',
'register_meta_box_cb' => '',
'map_meta_cap' => false,
'capability_type' => 'offer',
'capabilities' => array(
'read_post' => 'read_offer',
'publish_posts' => 'publish_offers',
'edit_posts' => 'edit_offers',
'edit_others_posts' => 'edit_others_offers',
'delete_posts' => 'delete_offers',
'delete_others_posts' => 'delete_others_offers',
'read_private_posts' => 'read_private_offers',
'edit_post' => 'edit_offer',
'delete_post' => 'delete_offer',
),
));
}
Пользовательская роль пользователя:
//Create Restaurant Owner
add_action('init', 'restaurant_owner_user_role');
function restaurant_owner_user_role() {
add_role('restaurant_owner', 'Restaurant Owner');
}
//Adds Restaurant Owner Custom Capabilities
function add_rest_caps() {
$restaurant = get_role( 'restaurant_owner' );
$restaurant->add_cap( 'edit_restaurant' );
$restaurant->add_cap( 'delete_restaurant' );
$restaurant->remove_cap( 'read_restaurant' );
$restaurant->add_cap( 'publish_restaurants' );
$restaurant->add_cap( 'edit_restaurants' );
$restaurant->remove_cap( 'edit_others_restaurants' );
$restaurant->remove_cap( 'delete_restaurants' );
$restaurant->remove_cap( 'delete_others_restaurants' );
$restaurant->remove_cap( 'read_private_restaurants' );
$restaurant->add_cap( 'edit_offer' );
$restaurant->add_cap( 'delete_offer' );
$restaurant->add_cap( 'read_offer' );
$restaurant->remove_cap( 'publish_offers' );
$restaurant->add_cap( 'edit_offers' );
$restaurant->remove_cap( 'edit_others_offers' );
$restaurant->remove_cap( 'delete_offers' );
$restaurant->remove_cap( 'delete_others_offers' );
$restaurant->remove_cap( 'read_private_offers' );
$restaurant->add_cap( 'edit_restaurant_week' );
$restaurant->add_cap( 'delete_restaurant_week' );
$restaurant->add_cap( 'read_restaurant_week' );
$restaurant->remove_cap( 'publish_restaurant_weeks' );
$restaurant->add_cap( 'edit_restaurant_weeks' );
$restaurant->remove_cap( 'edit_others_restaurant_weeks' );
$restaurant->remove_cap( 'delete_restaurant_weeks' );
$restaurant->remove_cap( 'delete_others_restaurant_weeks' );
$restaurant->remove_cap( 'read_private_restaurant_weeks' );
}
add_action( 'init', 'add_rest_caps');