Created a new role (price_admin
) with the following code and added capabilities. The menu item appeared, but clicking it shows "you are not authorized to access this page".
function ui_new_role() {
add_role('price_admin',
'Price Calculator Admin',
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true,
'publish_posts' => true,
'upload_files' => true,
)
);
$roles = array('price_admin','editor','administrator');
foreach($roles as $the_role) {
$role = get_role($the_role);
$role->add_cap( 'read' );
$role->add_cap( 'read_price');
$role->add_cap( 'edit_price' );
$role->add_cap( 'edit_prices' );
$role->add_cap( 'edit_others_prices' );
$role->add_cap( 'edit_published_prices' );
$role->add_cap( 'publish_prices' );
}
}
add_action('admin_init', 'ui_new_role');
My register_post_type
code is:
register_post_type(
'price',
array(
'labels' => array('name' => 'Treatment Questions'),
'capability_type' => array('price','prices'),
'map_meta_cap' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => 'my-menu',
'menu_position' => 15,
'supports' => array('title'),
'taxonomies' => array('location'),
'has_archive' => true,
)
);
Edit:
I use add_menu_page
;
add_menu_page('My Page Title', 'Price Calculator', 'manage_options', 'my-menu', 'show_price', 'dashicons-calculator', '13');
This is how it looks like for my new user; (Cannot access both subpages.)
price_admin
role or the capabilities required to manage the posts in your CPT? And just a note that adding custom roles should not be done on every (admin) init, and instead, it should be done upon plugin activation or when switching to another theme.my-menu
)? Did you useadd_menu_page()
oradd_submenu_page()
, and can you show your code?Sorry, you are not authorized to access this page
. I've added more info in the question. I don't think thatadd_menu_page
syntax is correct.