WordPress禁止用户编辑个人资料
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。脚本之家小编现在分享给大家,也给大家做个参考。 对于一个资深 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() 里面的提示内容,如果您有更好的方式不妨和我们分享一下。 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
