capabilities - Enable plugins for a specific user role

admin2025-06-05  2

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
Add a comment  | 

1 Answer 1

Reset to default 0

You 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'); }

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749130112a316618.html

最新回复(0)