昨天群裡有朋友詢問如何禁止用戶編輯他們的個人資料,下面分享一下相關方法。
禁止所有用戶編輯自己的個人資料
管理員也不能編輯自己的個人資料(貌似沒必要),但是他可以編輯他人的個人資料
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