Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#5763 closed defect (bug) (invalid)

register_hook and register_new_user are broken

Reported by: whooami Owned by: ryan
Milestone: Priority: normal
Severity: major Version: 2.5
Component: General Keywords: plugin dev-feedback
Focuses: Cc:


In the SVN, hooking into register_post with a plugin, doesnt work:

function email_check() {
		global $errors;
		if ($user_email != "secret@secret.org")
		$errors->add('icky_email', __('<strong>ERROR</strong>: your email blows.'));


add_action('register_post', 'email_check');

This was fixable this by adding the the global $errors to the function, register_new_user:

function register_new_user($user_login, $user_email) {
	global $errors; 

Change History (11)

#1 @lloydbudd
8 years ago

  • Version set to 2.5

#2 @ryan
8 years ago

  • Owner changed from anonymous to ryan

#3 @ryan
8 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6821]) Pass login, email, and errors to register_post action. fixes #5763

#4 @dlo
8 years ago

  • Resolution fixed deleted
  • Severity changed from normal to major
  • Status changed from closed to reopened
  • Summary changed from register_hook and register_new_user are broke to register_hook and register_new_user are broken

Hooking to register_post in a plugin still doesn't work, even after change 6821.

$errors variable remain unchanged when returning from hooked function in the register_new_user function (in login.php) as $errors is certainly passed by value and not by reference.

#5 @dlo
8 years ago

To add some precision:
Running PHP 4.4.3, I had to revert to the solution given by whooami at the beginning of this ticket to be able to get back the errors triggered by my custom function hooked to 'register_form' action in the $error variable of the register_new_user function.

Is this due to the fact that objects are passed by value in PHP 4 when they are passed by reference in PHP 5, thus making the [6821] change ineffective with some configuration? Nevertheless, it's a bit annoying to have to modify the wp-login.php file to get a plugin working. Ehh?

Is it possible to consider the implementation of the whooami solution as a quick workaround for WordPress 2.5 ?

#6 @ryan
8 years ago

Why not use the registration_errors filter for modifying $errors?

 $errors = apply_filters( 'registration_errors', $errors );

#7 @whooami
8 years ago


$errors = apply_filters( 'registration_errors', $errors );

I'm dense, can you explain to me where that would be used inside a plugin that is calling $errors? I cant seem to figure it out.

#8 follow-up: @dlo
8 years ago


Using the filter 'registration_errors' is just fine.
You were right in pointing that at me. I was focused on the action 'register_form' and didn't pay attention to the filter just one line below !
Nethertheless, is it a feature or a bug the fact that you can't modify the $errors variable during the 'register_form' action execution ?

#9 @mrmist
7 years ago

  • Keywords dev-feedback added

#10 in reply to: ↑ 8 @Denis-de-Bernardy
7 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Nethertheless, is it a feature or a bug the fact that you can't modify the $errors variable during the 'register_form' action execution ?

It's php related. in php4, you'd need a reference to modify the $error. but call_user_func() et al won't let you pass one.

#11 @Denis-de-Bernardy
7 years ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.