加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

WordPress禁止用户编辑个人资料

发布时间:2020-12-14 14:25:09 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 对于一个资深 wordpress 用户,各种奇葩的要求都会遇到,昨天群里有朋友就问如何禁止用户编辑他们的个人资料,是不是很奇怪的问题,那么下面分享一下相

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

对于一个资深 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' );

}

以上就是 WordPress 禁止用户编辑个人资料的相关代码,请根据自己的需要,修改 wp_die() 里面的提示内容,如果您有更好的方式不妨和我们分享一下。

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读