Based on the trick by zeo I found a way to disable editing of the following fields on a user’s profile page in the admin:
- e-mail
- first_name
- last_name
- url (site)
There are for sure better ways to do the matching based upon the regular expressions but hey, it works!
Place this code in your functions.php file:
class Edit_Email {
function start() {
ob_start();
}
function footer() {
$content = ob_get_contents();
ob_end_clean();
$this->replace( $content );
echo $content;
}
function replace( &$content ) {
// E-mail:
$pattern = array(
'/E-mail <span.+?<\/span>/',
'/<input type="text"(.*?)value="(\\S+@\\S+\\.\\w+)[^>]*\/>/'
);
$replacement = array(
'E-mail',
'<input type="hidden"\1value="\2" /> \2 '
);/* Please Contact Tech support to change your email. */
$content = preg_replace( $pattern, $replacement, $content );
// first_name
$pattern = array(
'/<input type="text" name="first_name" (.*?)value="(.*?)" class="regular-text" \/>/'
);
$replacement = array(
'<input type="hidden" name="first_name" \1 value="\2" /> \2 '
);
$content = preg_replace( $pattern, $replacement, $content );
// last_name
$pattern = array(
'/<input type="text" name="last_name" (.*?)value="(.*?)" class="regular-text" \/>/'
);
$replacement = array(
'<input type="hidden" name="last_name" \1 value="\2" /> \2 '
);
$content = preg_replace( $pattern, $replacement, $content );
// site (url)
$pattern = array(
'/<input type="text" name="url" (.*?)value="(.*?)" class="regular-text code" \/>/'
);
$replacement = array(
'<input type="hidden" name="url" \1 value="\2" /> \2 '
);
$content = preg_replace( $pattern, $replacement, $content );
}
}
if ( ! current_user_can( 'edit_users' ) && ( $pagenow == 'profile.php' ) ) :
$edit_email = new Edit_Email();
$edit_email->start();
add_action( 'admin_footer', array( &$edit_email, 'footer' ) );
endif;
Disabling firstname, lastname, e-mail and site fields on user profile page in wordpress admin
Based on the trick by zeo I found a way to disable editing of the following fields on a user’s profile page in the admin:
There are for sure better ways to do the matching based upon the regular expressions but hey, it works!
Place this code in your functions.php file: