WordPress教程

WordPress禁止用户编辑个人资料

阿里云

对于一个资深 WordPress 用户,各种奇葩的要求都会遇到,昨天群里有朋友就问如何禁止用户编辑他们的个人资料,是不是很奇怪的问题,那么下面分享一下相关方法。

禁止所有用户

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

也想出现在这里?联系我们
创客主机
  1. add_action( 'admin_init', 'stop_access_profile' );
  2. function stop_access_profile() {
  3.     remove_menu_page( 'profile.php' );
  4.     remove_submenu_page( 'users.php', 'profile.php' );
  5.     if(IS_PROFILE_PAGE === true) {
  6.         wp_die( 'You are not permitted to change your own profile information. Please contact a member of HR to have your profile information changed.' );
  7.     }
  8. }

禁止非管理员

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

  1. // ===== remove edit profile link from admin bar and side menu and kill profile page if not an admin
  2. if( !current_user_can('activate_plugins') ) {
  3. function mytheme_admin_bar_render() {
  4.     global $wp_admin_bar;
  5.     $wp_admin_bar->remove_menu('edit-profile', 'user-actions');
  6. }
  7. add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
  8.  
  9. function stop_access_profile() {
  10.     if(IS_PROFILE_PAGE === true) {
  11.         wp_die( 'Please contact your administrator to have your profile information changed.' );
  12.     }
  13.     remove_menu_page( 'profile.php' );
  14.     remove_submenu_page( 'users.php', 'profile.php' );
  15. }
  16. add_action( 'admin_init', 'stop_access_profile' );
  17. }

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

WordPress 禁止用户编辑个人资料

已有 398 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!