wp_privacy_send_personal_data_export_email( int $request_id ): true|WP_Error
- Since
- 4.9.6
- Source
wp-admin/includes/privacy-tools.php:588
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_idint- The request ID for this personal data export.
Return value
true|WP_Error- True on success or
WP_Erroron failure.
Performance profile
How much work a call to wp_privacy_send_personal_data_export_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
- Scaling
- Constant
- Instructions
- 14–149
- Plugin surface
- 5 hooks
- Called by
- 1
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 164.
Third-party callbacks on 'wp_privacy_export_expiration', 'wp_privacy_personal_data_email_to', 'wp_privacy_personal_data_email_subject' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - mailsends mail
wp_mail()called directly - querycontent query
get_post()one call below wp_privacy_send_personal_data_export_email() - cacheobject cache
wp_cache_get()one call below wp_privacy_send_personal_data_export_email() - serializeserialisation
maybe_unserialize()one call below wp_privacy_send_personal_data_export_email()
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_privacy_send_personal_data_export_email() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–17 | wp_get_user_request(), __() |
empty($request) | 139 | wp_get_user_request(), get_locale(), switch_to_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail() |
!empty($request) | 140 | wp_get_user_request(), switch_to_user_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail() |
empty($request) | 141 | wp_get_user_request(), get_locale(), switch_to_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale() |
!empty($request) | 142 | wp_get_user_request(), switch_to_user_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale() |
empty($request) | 146 | wp_get_user_request(), get_locale(), switch_to_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), __(), request() |
!empty($request) | 147 | wp_get_user_request(), switch_to_user_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), __(), request() |
empty($request) | 148 | wp_get_user_request(), get_locale(), switch_to_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale(), __(), request() |
!empty($request) | 149 | wp_get_user_request(), switch_to_user_locale(), apply_filters(), get_option(), time(), date_i18n(), wp_privacy_exports_url(), get_post_meta(), get_option(), wp_specialchars_decode(), home_url(), apply_filters(), __(), sprintf(), apply_filters(), __(), apply_filters(), sanitize_url(), sanitize_url(), apply_filters(), wp_mail(), restore_previous_locale(), __(), request() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 164 | 14–149 | 5 | |
| 8.5 | 164 | 14–149 | 5 | |
| 8.4 | 164 | 14–149 | 5 | 15 fewer instructions than PHP 8.3 |
| 8.3 | 179 | 14–164 | 5 | |
| 8.2 | 179 | 14–164 | 5 | |
| 8.1 | 179 | 14–164 | 5 | |
| 7.4 | 179 | 14–164 | 5 |
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 · 5
5 hooks fire while wp_privacy_send_personal_data_export_email() runs, in this order:
- apply_filters( wp_privacy_export_expiration )filterline 604 (+16 into the body)
Filters the lifetime, in seconds, of a personal data export file.
- apply_filters( wp_privacy_personal_data_email_to )filterline 623 (+35 into the body)
Filters the recipient of the personal data export email notification.
- apply_filters( wp_privacy_personal_data_email_subject )filterline 659 (+71 into the body)
Filters the subject of the email sent when an export request is completed.
- apply_filters( wp_privacy_personal_data_email_content )filterline 704 (+116 into the body)
Filters the text of the email sent with a personal data export file.
- apply_filters( wp_privacy_personal_data_email_headers )filterline 737 (+149 into the body)
Filters the headers of the email sent with a personal data export file.
Uses · 16
- wp_get_user_request()Returns the user request object for the specified request ID.
- __()Retrieves the translation of $text.
- 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.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- date_i18n()Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds.
- get_option()Retrieves an option value based on an option name.
- wp_privacy_exports_url()Returns the URL of the directory used to store personal data export files.
- get_post_meta()Retrieves a post meta field for the given post ID.
- wp_specialchars_decode()Converts a number of HTML entities into their special characters.
- home_url()Retrieves the URL for the current site where the front end is accessible.
Show all 16
- sanitize_url()Sanitizes a URL for database or redirect usage.
- wp_mail()Sends an email, similar to PHP's mail function.
- restore_previous_locale()Restores the translations according to the previous locale.
- WP_Error::__construct()Initializes the error.
Used by · 1
- wp_privacy_process_personal_data_export_page()Intercept personal data exporter page Ajax responses in order to assemble the personal data export file.
Source code
<?phpfunction wp_privacy_send_personal_data_export_email( $request_id ) { // Get the request. $request = wp_get_user_request( $request_id ); if ( ! $request || 'export_personal_data' !== $request->action_name ) { return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) ); } // 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() ); } /** This filter is documented in wp-includes/functions.php */ $expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS ); $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration ); $exports_url = wp_privacy_exports_url(); $export_file_name = get_post_meta( $request_id, '_export_file_name', true ); $export_file_url = $exports_url . $export_file_name; $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $site_url = home_url(); /** * Filters the recipient of the personal data export email notification. * Should be used with great caution to avoid sending the data export link to wrong emails. * * @since 5.3.0 * * @param string $request_email The email address of the notification recipient. * @param WP_User_Request $request The request that is initiating the notification. */ $request_email = apply_filters( 'wp_privacy_personal_data_email_to', $request->email, $request ); $email_data = array( 'request' => $request, 'expiration' => $expiration, 'expiration_date' => $expiration_date, 'message_recipient' => $request_email, 'export_file_url' => $export_file_url, 'sitename' => $site_name, 'siteurl' => $site_url, ); /* translators: Personal data export notification email subject. %s: Site title. */ $subject = sprintf( __( '[%s] Personal Data Export' ), $site_name ); /** * Filters the subject of the email sent when an export request is completed. * * @since 5.3.0 * * @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 int $expiration The time in seconds until the export file expires. * @type string $expiration_date The localized date and time when the export file expires. * @type string $message_recipient The address that the email will be sent to. Defaults * to the value of `$request->email`, but can be changed * by the `wp_privacy_personal_data_email_to` filter. * @type string $export_file_url The export file URL. * @type string $sitename The site name sending the mail. * @type string $siteurl The site URL sending the mail. * } */ $subject = apply_filters( 'wp_privacy_personal_data_email_subject', $subject, $site_name, $email_data ); /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */ $email_text = __( 'Howdy, Your request for an export of personal data has been completed. You maydownload your personal data by clicking on the link below. For privacyand security, we will automatically delete the file on ###EXPIRATION###,Changelog
Introduced in 4.9.6. 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 6.7.7 tag, from
src/wp-admin/includes/privacy-tools.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.