wppaste
WordPress

wp_send_user_request( string $request_id ): true|WP_Error

Since
4.9.6
Source
wp-includes/user.php:4743
Send a confirmation request email to confirm an action.

Description

If the request is not already pending, it will be updated.

Compatibility

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

$request_idstring
ID of the request created via wp_create_user_request().

Return value

true|WP_Error
True on success, WP_Error on failure.

Performance profile

How much work a call to wp_send_user_request() 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
18–142

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

Plugin surface
3 hooks

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

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

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

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 · 9 distinct outcomes

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

WhenInstructionsCalls it makes
always18absint(), wp_get_user_request(), __()
empty($request)132absint(), wp_get_user_request(), get_locale(), switch_to_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail()
!empty($request)133absint(), wp_get_user_request(), switch_to_user_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail()
empty($request)134absint(), wp_get_user_request(), get_locale(), switch_to_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale()
!empty($request)135absint(), wp_get_user_request(), switch_to_user_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale()
empty($request)139absint(), wp_get_user_request(), get_locale(), switch_to_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), __(), add_query_arg()
!empty($request)140absint(), wp_get_user_request(), switch_to_user_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), __(), add_query_arg()
empty($request)141absint(), wp_get_user_request(), get_locale(), switch_to_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale(), __(), add_query_arg()
!empty($request)142absint(), wp_get_user_request(), switch_to_user_locale(), wp_user_request_action_description(), wp_generate_user_request_key(), wp_login_url(), confirmaction(), get_option(), wp_specialchars_decode(), home_url(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale(), __(), add_query_arg()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15718–1424
8.515718–1424
8.415718–142415 fewer instructions than PHP 8.3
8.317218–1574
8.217218–1574
8.117218–1574
7.417218–1574

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

3 hooks fire while wp_send_user_request() runs, in this order:

  1. apply_filters( user_request_action_email_subject )filterline 4795 (+52 into the body)

    Filters the subject of the email sent when an account action is attempted.

  2. apply_filters( user_request_action_email_content )filterline 4840 (+97 into the body)

    Filters the text of the email sent when an account action is attempted.

  3. apply_filters( user_request_action_email_headers )filterline 4870 (+127 into the body)

    Filters the headers of the email sent when an account action is attempted.

Uses · 18

Show all 18

Used by · 2

Source code

function wp_send_user_request( $request_id ) {	$request_id = absint( $request_id );	$request    = wp_get_user_request( $request_id ); 	if ( ! $request ) {		return new WP_Error( 'invalid_request', __( 'Invalid personal data request.' ) );	} 	// Localize message content for user; fallback to site default for visitors.	if ( ! empty( $request->user_id ) ) {		$switched_locale = switch_to_user_locale( $request->user_id );	} else {		$switched_locale = switch_to_locale( get_locale() );	} 	$email_data = array(		'request'     => $request,		'email'       => $request->email,		'description' => wp_user_request_action_description( $request->action_name ),		'confirm_url' => add_query_arg(			array(				'action'      => 'confirmaction',				'request_id'  => $request_id,				'confirm_key' => wp_generate_user_request_key( $request_id ),			),			wp_login_url()		),		'sitename'    => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),		'siteurl'     => home_url(),	); 	/* translators: Confirm privacy data request notification email subject. 1: Site title, 2: Name of the action. */	$subject = sprintf( __( '[%1$s] Confirm Action: %2$s' ), $email_data['sitename'], $email_data['description'] ); 	/**	 * Filters the subject of the email sent when an account action is attempted.	 *	 * @since 4.9.6	 *	 * @param string $subject    The email subject.	 * @param string $sitename   The name of the site.	 * @param array  $email_data {	 *     Data relating to the account action email.	 *	 *     @type WP_User_Request $request     User request object.	 *     @type string          $email       The email address this is being sent to.	 *     @type string          $description Description of the action being performed so the user knows what the email is for.	 *     @type string          $confirm_url The link to click on to confirm the account action.	 *     @type string          $sitename    The site name sending the mail.	 *     @type string          $siteurl     The site URL sending the mail.	 * }	 */	$subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data ); 	/* translators: Do not translate DESCRIPTION, CONFIRM_URL, SITENAME, SITEURL: those are placeholders. */	$content = __(		'Howdy, A request has been made to perform the following action on your account:      ###DESCRIPTION### To confirm this, please click on the following link:###CONFIRM_URL### You can safely ignore and delete this email if you do not want totake this action. Regards,All at ###SITENAME######SITEURL###'	); 	/**	 * Filters the text of the email sent when an account action is attempted.	 *	 * The following strings have a special meaning and will get replaced dynamically:	 *	 * ###DESCRIPTION### Description of the action being performed so the user knows what the email is for.	 * ###CONFIRM_URL### The link to click on to confirm the account action.

Changelog

Introduced in 4.9.6. One change between 6.7.7 and 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.

6.9.7
Parameter $request_id retyped from string to int.verified against source
4.9.6
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 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.