wppaste
WordPress

send_confirmation_on_profile_email( int $user_id = 0 )

Since
3.0.0, 4.9.0, 7.0.3
Source
wp-includes/user.php:3867
Sends a confirmation request email when a change of user email address is attempted.

Compatibility

WordPress
since 7.0.3
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

$user_idintoptional
The ID of the user whose email is being changed. Defaults to $_POST['user_id'] if set, otherwise 0.Default: 0

Performance profile

How much work a call to send_confirmation_on_profile_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
12–136

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

Plugin surface
1 hook

Third-party callbacks on 'new_user_email_content' 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
  • querycontent queryget_user_by()one call below send_confirmation_on_profile_email()
  • transienttransientget_transient()one call below send_confirmation_on_profile_email()
  • cacheobject cachewp_cache_get()one call below send_confirmation_on_profile_email()
  • serializeserialisationmaybe_unserialize()one call below send_confirmation_on_profile_email()

What one call costs · 8 distinct outcomes

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

WhenInstructionsCalls it makes
always12–27wp_get_current_user()
isset($value)22–34absint(), wp_get_current_user()
!is_email()43–49wp_get_current_user(), is_email(), __(), ->add(), addslashes()
isset($value) && !is_email()53–56absint(), wp_get_current_user(), is_email(), __(), ->add(), addslashes()
is_email() && email_exists()56–62wp_get_current_user(), is_email(), email_exists(), __(), ->add(), delete_user_meta(), addslashes()
isset($value) && is_email() && email_exists()66–69absint(), wp_get_current_user(), is_email(), email_exists(), __(), ->add(), delete_user_meta(), addslashes()
is_email() && !email_exists()123–129wp_get_current_user(), is_email(), email_exists(), time(), wp_rand(), md5(), update_user_meta(), get_option(), wp_specialchars_decode(), __(), apply_filters(), self_admin_url(), esc_url(), home_url(), __(), sprintf(), wp_mail()
isset($value) && is_email() && !email_exists()133–136absint(), wp_get_current_user(), is_email(), email_exists(), time(), wp_rand(), md5(), update_user_meta(), get_option(), wp_specialchars_decode(), __(), apply_filters(), self_admin_url(), esc_url(), home_url(), __(), sprintf(), wp_mail()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17512–1368
8.517512–1368
8.417512–136815 fewer instructions than PHP 8.3
8.319012–1518
8.219012–1518
8.119012–1518
7.419012–1518

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 send_confirmation_on_profile_email() runs, in this order:

  1. apply_filters( new_user_email_content )filterline 3962 (+95 into the body)

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

Uses · 16

Show all 16
  • self_admin_url()Retrieves the URL to the admin area for either the current site or the network depending on context.
  • 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.
  • WP_Error::__construct()Initializes the error.

Source code

function send_confirmation_on_profile_email( $user_id = 0 ) {	global $errors; 	// Maintain backward compatibility for those relying on a check based on $_POST['user_id'].	if ( ! $user_id && isset( $_POST['user_id'] ) ) {		$user_id = absint( $_POST['user_id'] );	} 	$current_user = wp_get_current_user();	if ( ! is_object( $errors ) ) {		$errors = new WP_Error();	} 	if ( 0 === $current_user->ID || $current_user->ID !== (int) $user_id ) {		return false;	} 	if ( $current_user->user_email !== $_POST['email'] ) {		if ( ! is_email( $_POST['email'] ) ) {			$errors->add(				'user_email',				__( '<strong>Error:</strong> The email address is not correct.' ),				array(					'form-field' => 'email',				)			); 			$_POST['email'] = addslashes( $current_user->user_email );			return;		} 		if ( email_exists( $_POST['email'] ) ) {			$errors->add(				'user_email',				__( '<strong>Error:</strong> The email address is already used.' ),				array(					'form-field' => 'email',				)			);			delete_user_meta( $current_user->ID, '_new_email' ); 			$_POST['email'] = addslashes( $current_user->user_email );			return;		} 		$hash           = md5( $_POST['email'] . time() . wp_rand() );		$new_user_email = array(			'hash'     => $hash,			'newemail' => $_POST['email'],		);		update_user_meta( $current_user->ID, '_new_email', $new_user_email ); 		$sitename = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 		/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */		$email_text = __(			'Howdy ###USERNAME###, You recently requested to have the email address on your account changed. If this is correct, please click on the following link to change it:###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 user 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.

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.

7.0.3
Added the $user_id parameter, which is sent with the personal_options_update action.from the docblock
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 7.1.0 tag, from src/wp-includes/user.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.