如何禁用订阅者的链接仪表板?

时间:2014-12-14 09:58:11

标签: php wordpress admin

是否在入口外阻止非管理员用户的仪表板只能阻止Dashboard链接并允许将其个人资料更改为密码?仅用于订户的示例。

function blockuser_init_redirect(){
  if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){
    wp_redirect(home_url());
    exit;
  }
}
add_action('init','blockuser_init_redirect');

1 个答案:

答案 0 :(得分:0)

  

试试这个

add_action( 'admin_init', 'redirect_non_admin_users' );
/**
 * Redirect non-admin users to home page
 *
 * This function is attached to the 'admin_init' action hook.
 */
function redirect_non_admin_users() {
    if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
        wp_redirect( home_url() );
        exit;
    }
}