wppaste
WordPress

update_option_new_admin_email( string $old_value, string $value )

Since
3.0.0, 4.9.0
Source
wp-admin/includes/misc.php:1470
Sends a confirmation request email when a change of site admin email address is attempted.

Description

The new site admin address will not become active until confirmed.

Compatibility

WordPress
since 4.9.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

$old_valuestring
The old site admin email address.
$valuestring
The proposed new site admin email address.

Performance profile

How much work a call to update_option_new_admin_email() 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
8–116

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

Plugin surface
2 hooks

Third-party callbacks on 'new_admin_email_content', 'new_admin_email_subject' 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
  • hookthird-party callbacksapply_filters()called directly
  • mailsends mailwp_mail()called directly
  • cacheobject cachewp_cache_get()one call below update_option_new_admin_email()
  • serializeserialisationmaybe_unserialize()one call below update_option_new_admin_email()
  • transienttransientget_transient()one call below update_option_new_admin_email()

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

What one call costs · 6 distinct outcomes

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

WhenInstructionsCalls it makes
$value === false8get_option()
$value !== false && !is_email()12get_option(), is_email()
$value !== false && is_email()112get_option(), is_email(), time(), wp_rand(), md5(), update_option(), get_current_user_id(), switch_to_user_locale(), __(), apply_filters(), wp_get_current_user(), self_admin_url(), esc_url(), get_option(), wp_specialchars_decode(), home_url(), get_option(), home_url(), parse_url(), __(), sprintf(), apply_filters(), wp_mail()
$value !== false && is_email()114get_option(), is_email(), time(), wp_rand(), md5(), update_option(), get_current_user_id(), switch_to_user_locale(), __(), apply_filters(), wp_get_current_user(), self_admin_url(), esc_url(), get_option(), wp_specialchars_decode(), home_url(), get_option(), get_option(), wp_specialchars_decode(), __(), sprintf(), apply_filters(), wp_mail()
$value !== false && is_email()114get_option(), is_email(), time(), wp_rand(), md5(), update_option(), get_current_user_id(), switch_to_user_locale(), __(), apply_filters(), wp_get_current_user(), self_admin_url(), esc_url(), get_option(), wp_specialchars_decode(), home_url(), get_option(), home_url(), parse_url(), __(), sprintf(), apply_filters(), wp_mail(), restore_previous_locale()
$value !== false && is_email()116get_option(), is_email(), time(), wp_rand(), md5(), update_option(), get_current_user_id(), switch_to_user_locale(), __(), apply_filters(), wp_get_current_user(), self_admin_url(), esc_url(), get_option(), wp_specialchars_decode(), home_url(), get_option(), get_option(), wp_specialchars_decode(), __(), sprintf(), apply_filters(), wp_mail(), restore_previous_locale()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1248–1164
8.51248–1164
8.41248–116415 fewer instructions than PHP 8.3
8.31398–1314
8.21398–1314
8.11398–1314
7.41398–1314

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 · 2

2 hooks fire while update_option_new_admin_email() runs, in this order:

  1. apply_filters( new_admin_email_content )filterline 1526 (+56 into the body)

    Filters the text of the email sent when a change of site admin email address is attempted.

  2. apply_filters( new_admin_email_subject )filterline 1554 (+84 into the body)

    Filters the subject of the email sent when a change of site admin email address is attempted.

Uses · 15

Show all 15
  • home_url()Retrieves the URL for the current site where the front end is accessible.
  • 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 update_option_new_admin_email( $old_value, $value ) {	if ( get_option( 'admin_email' ) === $value || ! is_email( $value ) ) {		return;	} 	$hash            = md5( $value . time() . wp_rand() );	$new_admin_email = array(		'hash'     => $hash,		'newemail' => $value,	);	update_option( 'adminhash', $new_admin_email, false ); 	$switched_locale = switch_to_user_locale( get_current_user_id() ); 	/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */	$email_text = __(		'Howdy ###USERNAME###, Someone with administrator capabilities recently requested to have theadministration email address changed on this site:###SITEURL### To confirm this change, please click on the following link:###ADMIN_URL### You can safely ignore and delete this email if you do not want totake this action. This email has been sent to ###EMAIL### Regards,All at ###SITENAME######SITEURL###'	); 	/**	 * Filters the text of the email sent when a change of site admin email address is attempted.	 *	 * The following strings have a special meaning and will get replaced dynamically:	 *  - ###USERNAME###  The current user's username.	 *  - ###ADMIN_URL### The link to click on to confirm the email change.	 *  - ###EMAIL###     The proposed new site admin email address.	 *  - ###SITENAME###  The name of the site.	 *  - ###SITEURL###   The URL to the site.	 *	 * @since MU (3.0.0)	 * @since 4.9.0 This filter is no longer Multisite specific.	 *	 * @param string $email_text      Text in the email.	 * @param array  $new_admin_email {	 *     Data relating to the new site admin email address.	 *	 *     @type string $hash     The secure hash used in the confirmation link URL.	 *     @type string $newemail The proposed new site admin email address.	 * }	 */	$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email ); 	$current_user = wp_get_current_user();	$content      = str_replace( '###USERNAME###', $current_user->user_login, $content );	$content      = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content );	$content      = str_replace( '###EMAIL###', $value, $content );	$content      = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content );	$content      = str_replace( '###SITEURL###', home_url(), $content ); 	if ( '' !== get_option( 'blogname' ) ) {		$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );	} else {		$site_title = parse_url( home_url(), PHP_URL_HOST );	} 	$subject = sprintf(		/* translators: New admin email address notification email subject. %s: Site title. */		__( '[%s] New Admin Email Address' ),		$site_title	); 	/**	 * Filters the subject of the email sent when a change of site admin email address is attempted.	 *

Changelog

Introduced in 3.0.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.

4.9.0
This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.from the docblock
3.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-admin/includes/misc.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.