昨天群里有朋友詢問如何禁止用戶編輯他們的個人資料,下面分享一下相關方法。
禁止所有用戶編輯自己的個人資料
管理員也不能編輯自己的個人資料(貌似沒必要),但是他可以編輯他人的個人資料
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' );
}
請根據(jù)自己的需要,修改 wp_die() 里面的提示內容。
如果想讓用戶可以查看自己的個人資料,但是卻不讓他們編輯?可以參考:http://www.ydqwiac.cn/disable-profile-fields.html
參考資料:http://wordpress.stackexchange.com/questions/29000
聲明:本站所有文章,如無特殊說明或標注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發(fā)布本站內容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯(lián)系我們進行處理。





他有用的
如果讓新用戶注冊時就默認有一段"個人描述"
第一段代碼沒有什么實際用途,管理員也是可以修改主題的
只是說不能修改個人資料,沒說不能修改主題啊