WordPress禁止用户编辑个人资料

昨天群里有朋友询问如何禁止用户编辑他们的个人资料,下面分享一下相关方法。

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

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

1
2
3
4
5
6
7
8
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.' );
    }
}

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.’ );
}
}

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// ===== remove edit profile link from admin bar and side menu and kill profile page if not an admin
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' );
}

// ===== remove edit profile link from admin bar and side menu and kill profile page if not an admin
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’ );
}

请根据自己的需要,修改 wp_die() 里面的提示内容。

如果想让用户可以查看自己的个人资料,但是却不让他们编辑?可以参考:https://www.wpdaxue.com/disable-profile-fields.html

参考资料:http://wordpress.stackexchange.com/questions/29000

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2023 Tadke.com. 琼ICP备20000547号