外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>用户交互>WordPress禁止用户编辑个人资料

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

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

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

// ===== 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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
用户交互

为WordPress评论表单添加Quicktags按钮

2013-5-25 7:45:18

用户交互

禁止某个用户在线编辑WordPress主题文件

2013-6-9 10:45:49

4 条回复 A文章作者 M管理员
  1. 他有用的

  2. 如果让新用户注册时就默认有一段"个人描述"

  3. 第一段代码没有什么实际用途,管理员也是可以修改主题的

    • 只是说不能修改个人资料,没说不能修改主题啊

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索