I've created a new user role(based on shop manager) with user role editor, i need to show a custom plugin for this role.
Thanks
$user = wp_get_current_user();
if ( in_array( 'custom_role', (array) $user->roles ) ) {
//The user has the "custom" role
add_action( 'some_menu', 'my_plugin_menu' );
}
function my_plugin_menu() { add_options_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_admin_page'); }
I've created a new user role(based on shop manager) with user role editor, i need to show a custom plugin for this role.
Thanks
$user = wp_get_current_user();
if ( in_array( 'custom_role', (array) $user->roles ) ) {
//The user has the "custom" role
add_action( 'some_menu', 'my_plugin_menu' );
}
function my_plugin_menu() { add_options_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_admin_page'); }
Share
Improve this question
edited Dec 4, 2018 at 7:03
Eugenio Chessa
asked Dec 3, 2018 at 14:31
Eugenio ChessaEugenio Chessa
111 bronze badge
1
- you could relaize this kind of behaviour with the help of a plugin aka restrict user access. try one of these (not all are fitting your needs, but the first two and some others should do, what you are looking for) – honk31 Commented Dec 4, 2018 at 17:54
1 Answer
Reset to default 0You can try something like this
if ( is_myrole() ) { add_action( 'some_menu', 'my_plugin_menu' ); }
function my_plugin_menu() { add_options_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_admin_page'); }