$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>capabilities - Enable plugins for a specific user role|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

capabilities - Enable plugins for a specific user role

matteradmin9PV0评论

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

Post a comment

comment list (0)

  1. No comments so far