wp_password_change_notification( WP_User $user )
- Since
- 2.7.0
- Source
wp-includes/pluggable.php:2197
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
- Scaling
- Constant
- Instructions
- 12–86
- Plugin surface
- 1 hook
- Called by
- 0
Sends mail via wp_mail().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.
Third-party callbacks on 'wp_password_change_notification_email' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - querycontent query
get_user_by()called directly - hookthird-party callbacks
apply_filters()called directly - mailsends mail
wp_mail()called directly - cacheobject cache
wp_cache_get()one call below wp_password_change_notification() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | get_option(), strcasecmp() |
| always | 83 | get_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() |
| always | 84 | get_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() |
| always | 85 | get_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() |
| always | 86 | get_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:
- apply_filters( wp_password_change_notification_email )filterline 2244 (+47 into the body)
Filters the contents of the password change notification email sent to the site admin.
Uses · 10
- get_option()Retrieves an option value based on an option name.
- get_user_by()Retrieves user info by a given field.
- switch_to_user_locale()Switches the translations according to the given user's locale.
- switch_to_locale()Switches the translations according to the given locale.
- get_locale()Retrieves the current locale.
- __()Retrieves the translation of $text.
- wp_specialchars_decode()Converts a number of HTML entities into their special characters.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_mail()Sends an email, similar to PHP's mail function.
- restore_previous_locale()Restores the translations according to the previous locale.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.