WordPress禁止用户编辑个人资料

下面分享如何禁止用户编辑他们的个人资料相关方法。

禁止所有用户编辑自己的个人资料

管理员也不能编辑自己的个人资料(貌似没必要),但是他可以编辑他人的个人资料

//禁止所有用户编辑自己的个人资料
add_action( 'admin_init', 'stop_access_profile' );
function stop_access_profile() {
    remove_menu_page( 'profile.php' );
    remove_submenu_page( 'users.php', 'profile.php' );
    if(IS_PROFILE_PAGE === true) {
        wp_die( 'You are not permitted to change your own profile information. Please contact a member of HR to have your profile information changed.' );
    }
}

禁止非管理员用户编辑自己的个人资料

除了管理员以外,其他用户都不能编辑自己的个人资料

// ===== 从管理栏和侧菜单中删除编辑配置文件链接,如果不是管理员,则删除配置文件页面
if( !current_user_can('activate_plugins') ) {
function mytheme_admin_bar_render() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('edit-profile', 'user-actions');
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
 
function stop_access_profile() {
    if(IS_PROFILE_PAGE === true) {
        wp_die( 'Please contact your administrator to have your profile information changed.' );
    }
    remove_menu_page( 'profile.php' );
    remove_submenu_page( 'users.php', 'profile.php' );
}
add_action( 'admin_init', 'stop_access_profile' );
}