为特定用户角色启用插件

时间:2018-12-03 作者:Eugenio Chessa

我已经用user role editor创建了一个新的用户角色(基于shop manager),我需要为这个角色显示一个自定义插件。

谢谢

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

1 个回复
SO网友:dado

你可以试试这样的

if(is\\u myrole()){add\\u action(\'some\\u menu\',\'my\\u plugin\\u menu\');}

函数my\\u plugin\\u menu(){add\\u options\\u page(\'my plugin Settings\',\'my plugin\',\'manage\\u options\',\'my plugin Settings\',\'my plugin admin\\u page\');}

相关推荐

正在尝试获取wp-includes/capabilities.php中非对象的属性

在调试中,我每分钟都会收到以下通知序列。日志:[23-Oct-2012 13:27:33 UTC] PHP Notice: Trying to get property of non-object in mysite/wp-includes/capabilities.php on line 1022 [23-Oct-2012 13:27:33 UTC] PHP Notice: Trying to get property of non-object in mysite/wp-includes/