Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

does anybody know how to hook or filter the user-edit.php file so that an user's email address is disabled from editing akin to how the username is disabled ..??..

i can edit the core file (gasp) and include disabled="disabled" in the form and this works but i'm at a loss as to how to add the disable via hook or filter ..

i can also run a function like this that hides the email address via css

/* Change WordPress dashboard CSS */
function custom_admin_styles() {
echo '<style type="text/css">#email { display: none !important; }</style>';
}
add_action('admin_head', 'custom_admin_styles');

but that pulls out the whole email thus form looks funny and then i believe that with a DOM Editor like Firebug, one can still access that email field thus change it ... ugh ...

ideally, i would like to replace this entire user-edit.php code from this ->

<label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th><td><input type="text" name="email" id="email" value="<?php echo esc_attr($profileuser->user_email) ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Emails cannot be changed.'); ?></span>

to something like this ->

<label for="email"><?php _e('E-mail'); ?> </label></th><td><?php echo esc_attr($profileuser->user_email) ?>" Please Contact Tech support to change your email

thanks in advance for any pointers you can share ... cordially, chuck scott

share|improve this question
    
you can use JQuery .append to disable it but it's a hackish way –  Bainternet Mar 10 '11 at 21:05

5 Answers 5

gonna answer my own thread here ... turns out there is no way to hook or filter or string replace other than to hack core code and here is link to account of said hacks, even risking kitties -> http://themehybrid.com/support/topic/fyi-how-to-prohibit-email-changes-in-profile-even-if-a-kitten-dies

share|improve this answer

The hack given below has been tested with WordPress 3.1.

Open user-edit.php, find:

<th><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
<td><input type="text" name="email" id="email" value="<?php echo esc_attr($profileuser->user_email) ?>" class="regular-text" /></span>

and replace with:

<th><label for="email"><?php _e('E-mail'); ?> <span class="description"></span></label></th>
<td><input type="hidden" name="email" id="email" value="<?php echo esc_attr($profileuser->user_email) ?>" class="regular-text" /><?php echo esc_attr($profileuser->user_email) ?></span>

It is just a workaround that visually removes the ability to change email addresses, not actually disable the feature.

share|improve this answer

Dirty hack, feel free to modify.

Only admins or users with edit_users cap "can change" email, others can't.

Theme functions.php:

class Edit_Email {
    function start() {
        ob_start();
    }

    function footer() {
        $content = ob_get_contents();

        ob_end_clean();

        $this->replace( $content );

        echo $content;
    }

    function replace( &$content ) {
        $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 );
    }
}

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;
share|improve this answer

Not exact answer, but to prevent email change (actual change, not field edit) you could tweak around this action:

add_action( 'user_profile_update_errors', 'prevent_email_change', 10, 3 );

function prevent_email_change( $errors, $update, $user ) {

    $old = get_user_by('id', $user->ID);

    if( $user->user_email != $old->user_email )
        $user->user_email = $old->user_email;
}
share|improve this answer

You can use JQuery to disable the email (and any other fields in the edit profile page).

For example, something like this in a plugin:

  //Disables certain fields (email, password) in WP Admin edit user page (user-edit.php)
   global $pagenow;
   if ( $pagenow == 'user-edit.php' ) {
        add_action( 'admin_footer', 'disable_userprofile_fields' );
   }

    /**
    * Disables certain fields (email, password) in WP Admin edit user page (user-edit.php)
    */
    function disable_userprofile_fields() {
    ?>
        <script>
            jQuery(document).ready( function($) {
                if ( $('input[name=email]').length ) {
                    $('input[name=email]').attr("disabled", "disabled");
                }
                if ( $('input[name=pass1]').length ) {
                    $('input[name=pass1]').attr("disabled", "disabled");
                }
                if ( $('input[name=pass2]').length ) {
                    $('input[name=pass2]').attr("disabled", "disabled");
                }
            });
        </script>
    <?php
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.