昨天群里有朋友询问如何禁止用户编辑他们的个人资料,下面分享一下相关方法。
禁止所有用户编辑自己的个人资料
管理员也不能编辑自己的个人资料(貌似没必要),但是他可以编辑他人的个人资料
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
本文WordPress禁止用户编辑个人资料到此结束。脆弱的心灵创伤太多,追求才是愈合你伤口最好的良药。小编再次感谢大家对我们的支持!