1

How do we customize the "Registration complete. Please check your e-mail." message that appears when registering on WordPress 4.0? In previous versions, Dave Ross solution worked:

add_filter( 'wp_login_errors', 'override_reg_complete_msg', 10, 2 );
function override_reg_complete_msg( $errors, $redirect_to ) {
   if( isset( $errors->errors['registered'] ) ) {
     $needle = __('Registration complete. Please check your e-mail.');
     foreach( $errors->errors['registered'] as $index => $msg ) {
       if( $msg === $needle ) {
         $errors->errors['registered'][$index] = 'Your new message';
       }
     }
   }

   return $errors;
}

Looking through wp-login.php, no changes have been made to the Filter the login page errors info. Why is the above code not working in WP 4?

3

If you need an alternative way, you can always hook into the login_init and modify the gettext filter:

add_filter( 'login_init',
    function()
    {
      add_filter( 'gettext', 'wpse_161709', 99, 3 );
    }
);

function wpse_161709( $translated_text, $untranslated_text, $domain )
{
    $old = "Registration complete. Please check your e-mail.";
    $new = "New text here";

    if ( $untranslated_text === $old )
    {         
        $translated_text = $new;
        remove_filter( current_filter(), __FUNCTION__ );
    }
    return $translated_text;
}

Update — The WP_Error class has changed:

There seems to be a change in the definition of the errors property of the WP_Errors class:

In WordPress version 3.9 we got this part:

var $errors = array();

but in WordPress version 4.0 it has been changed to:

private $error_data = array();

So the scope of this property has been changed from public to private.

That's the reason why you can't modify it directly in WordPress 4.0+.

... but you can instead use the magic __set and __get methods of the WP_Error class introduced in WordPress 4.0.

Then your code example could be modified to:

add_filter( 'wp_login_errors', 'wpse_161709', 10, 2 );

function wpse_161709( $errors, $redirect_to )
{
   if( isset( $errors->errors['registered'] ) )
   {
     // Use the magic __get method to retrieve the errors array:
     $tmp = $errors->errors;   

     // What text to modify:
     $old = __('Registration complete. Please check your email.');
     $new = 'Your new message';

     // Loop through the errors messages and modify the corresponding message:
     foreach( $tmp['registered'] as $index => $msg )
     {
       if( $msg === $old )
           $tmp['registered'][$index] = $new;        
     }
     // Use the magic __set method to override the errors property:
     $errors->errors = $tmp;

     // Cleanup:
     unset( $tmp );
   }  
   return $errors;
}

to change this particular error message.

Here are screenshot examples:

Before:

Before

After:

After

  • 1
    I think the other approach would work if the errors property of the WP_Error class would be public, but it's private. – birgire Sep 17 '14 at 15:41
  • 1
    I updated the answer with an example how you can modify your code snippet, using the magic set method (introduced in WP 4.0 as well) of the WP_Error class. – birgire Sep 18 '14 at 12:39
  • 1
    Good question. Well both are unstable regarding changes to the message string. In general it might be easier to use the gettext filter, but we want to make sure it's not running through too many filterable texts on the site, they can be many ;-) In general I would try to use the method that's more "specific" or "less general" in solving the task, what ever that means ;-) So I think I would go with the wp_login_errors filter. – birgire Sep 18 '14 at 14:02
  • 1
    Just a correction to this answer. Please change the line to "Registration complete. Please check your email." (note e-mail has been changed to email). This is obviously required to make this work. Thanks! :D EDIT: I only now noticed that this was my original question haha, came here via a google search. – Christine Cooper Apr 17 '16 at 13:47
  • 1
    Thanks @ChristineCooper for the update, please feel free to adjust the answer as needed - thanks in advance ;-) hehe yes it has happened to me too, to google my own forgotten answers - maybe there exists a phrase for that kind of re-discovery ? ;-) – birgire Apr 17 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.