允许非管理员用户访问插件

时间:2015-08-26 作者:anniechocs

我希望不是管理员的用户能够使用我的日历插件,但除了管理员之外,它在仪表板上不可用。

1 个回复
SO网友:Khaled Sadek

从…起Codex

function add_theme_caps(){
 global $pagenow;

 if ( \'themes.php\' == $pagenow && isset( $_GET[\'activated\'] ) ){ // Test if theme is activated
  // Theme is activated
  // gets the author role
  $role = get_role( \'author\' );

  // This only works, because it accesses the class instance.
  // would allow the author to edit others\' posts for current theme only
  $role->add_cap( \'edit_others_posts\' ); 
 }
 else {
  // Theme is deactivated
  // Remove the capacity when theme is deactivated
  $role->remove_cap( \'edit_others_posts\' ); 
 }
}
add_action( \'load-themes.php\', \'add_theme_caps\' );
通过小编辑,作者可以安装、编辑和激活插件

function add_theme_caps(){
    global $pagenow;

    if ( \'themes.php\' == $pagenow && isset( $_GET[\'activated\'] ) ){ // Test if theme is activated
    // Theme is activated
    // gets the author role
    $role = get_role( \'author\' );

    // This only works, because it accesses the class instance.
    // would allow the author to edit others\' posts for current theme only
    $role->add_cap( \'activate_plugins\' ); 
    $role->add_cap( \'edit_plugins\' ); 
    $role->add_cap( \'install_plugins\' ); 
}
else {
    // Theme is deactivated
    // Remove the capacity when theme is deactivated
    $role->remove_cap( \'edit_others_posts\' ); 
}
}
add_action( \'load-themes.php\', \'add_theme_caps\' );