WordPress怎么禁止非管理员进入仪表盘

仪表盘的入口为wp-admin/index.php文件,并引用dashboard api。所以要想禁止非管理员进入仪表盘,可直接借用wp_dashboard_setup这个hooks进行判断。

示例代码:

add_action('wp_dashboard_setup', 'wpdit_banto_dashboard');

function wpdit_banto_dashboard() {

if ( ! is_super_admin() ) {

wp_redirect( site_url('/') ); //直接跳转到站点首页以禁止访问dashboard

}

}

如果想删除WordPress仪表盘,可以将下面的代码添加到您的当前主题的 functions.php 文件:

function disable_dashboard_widgets() {

global $wp_meta_boxes;

// wp..

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);

}

add_action('wp_dashboard_setup', 'disable_dashboard_widgets', 999);
投上你的一票

本文出处:老蒋部落 » WordPress怎么禁止非管理员进入仪表盘 | 欢迎分享( 公众号:老蒋朋友圈 )

公众号 「老蒋朋友圈」获取站长新知 / 加QQ群 【1012423279】获取商家优惠推送