Ticket #5763 (reopened defect)

Opened 7 months ago

Last modified 5 months ago

register_hook and register_new_user are broken

Reported by: whooami Assigned to: ryan
Priority: normal Milestone: 2.9
Component: General Version: 2.5
Severity: major Keywords: plugin
Cc:

Description

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

02/04/08 15:56:02 changed by lloydbudd

  • version set to 2.5.

02/07/08 18:33:10 changed by ryan

  • owner changed from anonymous to ryan.

02/13/08 18:42:15 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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

03/20/08 17:22:15 changed by dlo

  • status changed from closed to reopened.
  • resolution deleted.
  • severity changed from normal to major.
  • 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.

03/21/08 11:28:56 changed by dlo

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 ?

03/21/08 15:31:35 changed by ryan

Why not use the registration_errors filter for modifying $errors?

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

03/24/08 18:46:45 changed by whooami

Ryan,

$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.

03/25/08 12:45:16 changed by dlo

Ryan,

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 ?