wppaste
WordPress

wp_password_change_notification( WP_User $user )

Since
2.7.0
Source
wp-includes/pluggable.php:2187
Notifies the blog admin of a user changing password, normally via email.

Compatibility

WordPress
since 2.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$userWP_User
User object.

Performance profile

How much work a call to wp_password_change_notification() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Sends mail via wp_mail().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
12–86

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.

Plugin surface
1 hook

Third-party callbacks on 'wp_password_change_notification_email' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • querycontent queryget_user_by()called directly
  • hookthird-party callbacksapply_filters()called directly
  • mailsends mailwp_mail()called directly
  • cacheobject cachewp_cache_get()one call below wp_password_change_notification()
  • serializeserialisationmaybe_unserialize()one call below wp_password_change_notification()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_password_change_notification() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always12get_option(), strcasecmp()
always83get_option(), strcasecmp(), get_option(), get_user_by(), get_locale(), switch_to_locale(), __(), sprintf(), get_option(), wp_specialchars_decode(), get_option(), __(), apply_filters(), sprintf(), wp_specialchars_decode(), wp_mail()
always84get_option(), strcasecmp(), get_option(), get_user_by(), switch_to_user_locale(), __(), sprintf(), get_option(), wp_specialchars_decode(), get_option(), __(), apply_filters(), sprintf(), wp_specialchars_decode(), wp_mail()
always85get_option(), strcasecmp(), get_option(), get_user_by(), get_locale(), switch_to_locale(), __(), sprintf(), get_option(), wp_specialchars_decode(), get_option(), __(), apply_filters(), sprintf(), wp_specialchars_decode(), wp_mail(), restore_previous_locale()
always86get_option(), strcasecmp(), get_option(), get_user_by(), switch_to_user_locale(), __(), sprintf(), get_option(), wp_specialchars_decode(), get_option(), __(), apply_filters(), sprintf(), wp_specialchars_decode(), wp_mail(), restore_previous_locale()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 92 instructions, 12–86 executed per call, 3 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while wp_password_change_notification() runs, in this order:

  1. apply_filters( wp_password_change_notification_email )filterline 2234 (+47 into the body)

    Filters the contents of the password change notification email sent to the site admin.

Uses · 10

Source code

	function wp_password_change_notification( $user ) {		/*		 * Send a copy of password change notification to the admin,		 * but check to see if it's the admin whose password we're changing, and skip this.		 */		if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { 			$admin_user = get_user_by( 'email', get_option( 'admin_email' ) ); 			if ( $admin_user ) {				$switched_locale = switch_to_user_locale( $admin_user->ID );			} else {				$switched_locale = switch_to_locale( get_locale() );			} 			/* translators: %s: User name. */			$message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n";			/*			 * The blogname option is escaped with esc_html() on the way into the database in sanitize_option().			 * We want to reverse this for the plain text arena of emails.			 */			$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 			$wp_password_change_notification_email = array(				'to'      => get_option( 'admin_email' ),				/* translators: Password change notification email subject. %s: Site title. */				'subject' => __( '[%s] Password Changed' ),				'message' => $message,				'headers' => '',			); 			/**			 * Filters the contents of the password change notification email sent to the site admin.			 *			 * @since 4.9.0			 *			 * @param array   $wp_password_change_notification_email {			 *     Used to build wp_mail().			 *			 *     @type string $to      The intended recipient - site admin email address.			 *     @type string $subject The subject of the email.			 *     @type string $message The body of the email.			 *     @type string $headers The headers of the email.			 * }			 * @param WP_User $user     User object for user whose password was changed.			 * @param string  $blogname The site title.			 */			$wp_password_change_notification_email = apply_filters( 'wp_password_change_notification_email', $wp_password_change_notification_email, $user, $blogname ); 			wp_mail(				$wp_password_change_notification_email['to'],				wp_specialchars_decode( sprintf( $wp_password_change_notification_email['subject'], $blogname ) ),				$wp_password_change_notification_email['message'],				$wp_password_change_notification_email['headers']			); 			if ( $switched_locale ) {				restore_previous_locale();			}		}	}

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/pluggable.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.