WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#38891 closed defect (bug) (invalid)

Profile of wp_password_change_notification does not fit with the do_action( 'after_password_reset', $user, $new_pass );

Reported by: jyd44 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

In wp-includes/pluggable.php, the function wp_password_change_notification
is declared as: function wp_password_change_notification( $user )

in wp-includes/default_filters.php, line 369, the action is added as:
add_action( 'after_password_reset', 'wp_password_change_notification' );

in wp-includes/user.php, line 2228, the action 'after_password_reset' is called as:
do_action( 'after_password_reset', $user, $new_pass );

Is it possible to clarify.

Change History (1)

#1 @aaroncampbell
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hey @jyd44,

So the way actions and filters work, the fourth parameter for both add_action() and add_filter() is $accepted_args, which defaults to 1. So in the case of add_action( 'after_password_reset', 'wp_password_change_notification' ); that you mentioned, it's saying that wp_password_change_notification() only accepts a single argument. When do_action( 'after_password_reset', $user, $new_pass ); is called, it passes on to WP_Hook::do_action() and then to WP_Hook::apply_filters(), which slices the arguments array to the size originally specified (in this case 1).

Since wp_password_change_notification() only needs $user, that's all that gets sent to it. If you wanted your own function to be able to make use of both arguments that get passed, then when you call add_action, you just need to pass 2 as the fourth parameter:
add_action( 'after_password_reset', 'your_password_related_function', null, 2 );

I hope that clears things up!

Note: See TracTickets for help on using tickets.