wp_privacy_generate_personal_data_export_file( int $request_id )
- Since
- 4.9.6
- Source
wp-admin/includes/privacy-tools.php:310
Generate the personal data export file.
Parameters
$request_idint- The export request ID.
Hooks fired · 1
One hook fires while wp_privacy_generate_personal_data_export_file() runs, in this order:
- do_action( wp_privacy_personal_data_export_file_created )actionline 563 (+253 into the body)
Fires right after all personal data has been written to the export file.
Uses · 26
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- __()Retrieves the translation of $text.
- wp_get_user_request()Returns the user request object for the specified request ID.
- is_email()Verifies that an email is valid.
- wp_privacy_exports_dir()Returns the directory used to store personal data export files.
- wp_privacy_exports_url()Returns the URL of the directory used to store personal data export files.
- wp_mkdir_p()Recursive directory creation based on full path.
- wp_generate_password()Generates a random password drawn from the defined set of characters.
- wp_unique_filename()Gets a filename that is sanitized and unique for the given directory.
- wp_normalize_path()Normalizes a filesystem path.
- _x()Retrieves translated string with gettext context.
- get_bloginfo()Retrieves information about the current site.
Show all 26
- current_time()Retrieves the current time based on specified type.
- get_post_meta()Retrieves a post meta field for the given post ID.
- _doing_it_wrong()Marks something as being incorrectly called.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- esc_html()Escaping for HTML blocks.
- esc_html__()Retrieves the translation of $text and escapes it for safe use in HTML output.
- sanitize_title_with_dashes()Sanitizes a title, replacing whitespace and a few other characters with dashes.
- esc_attr()Escaping for HTML attributes.
- wp_privacy_generate_personal_data_export_group_html()Generate a single group for the personal data export report.
- update_post_meta()Updates a post meta field based on the given post ID.
- delete_post_meta()Deletes a post meta field for the given post ID.
- wp_delete_file()Deletes a file.
- do_action()Calls the callback functions that have been added to an action hook.
- ZipArchive::__construct()
Source
function wp_privacy_generate_personal_data_export_file( $request_id ) { if ( ! class_exists( 'ZipArchive' ) ) { wp_send_json_error( __( 'Unable to generate personal data export file. ZipArchive not available.' ) ); } // Get the request. $request = wp_get_user_request( $request_id ); if ( ! $request || 'export_personal_data' !== $request->action_name ) { wp_send_json_error( __( 'Invalid request ID when generating personal data export file.' ) ); } $email_address = $request->email; if ( ! is_email( $email_address ) ) { wp_send_json_error( __( 'Invalid email address when generating personal data export file.' ) ); } // Create the exports folder if needed. $exports_dir = wp_privacy_exports_dir(); $exports_url = wp_privacy_exports_url(); if ( ! wp_mkdir_p( $exports_dir ) ) { wp_send_json_error( __( 'Unable to create personal data export folder.' ) ); } // Protect export folder from browsing. $index_pathname = $exports_dir . 'index.php'; if ( ! file_exists( $index_pathname ) ) { $file = fopen( $index_pathname, 'w' ); if ( false === $file ) { wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) ); } fwrite( $file, "<?php\n// Silence is golden.\n" ); fclose( $file ); } $obscura = wp_generate_password( 32, false, false ); $file_basename = 'wp-personal-data-file-' . $obscura; $html_report_filename = wp_unique_filename( $exports_dir, $file_basename . '.html' ); $html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename ); $json_report_filename = $file_basename . '.json'; $json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename ); /* * Gather general data needed. */ // Title. $title = sprintf( /* translators: %s: User's email address. */ __( 'Personal Data Export for %s' ), $email_address ); // First, build an "About" group on the fly for this report. $about_group = array( /* translators: Header for the About section in a personal data export. */ 'group_label' => _x( 'About', 'personal data group label' ), /* translators: Description for the About section in a personal data export. */ 'group_description' => _x( 'Overview of export report.', 'personal data group description' ), 'items' => array( 'about-1' => array( array( 'name' => _x( 'Report generated for', 'email address' ), 'value' => $email_address, ), array( 'name' => _x( 'For site', 'website name' ), 'value' => get_bloginfo( 'name' ), ), array( 'name' => _x( 'At URL', 'website URL' ), 'value' => get_bloginfo( 'url' ), ), array( 'name' => _x( 'On', 'date/time' ), 'value' => current_time( 'mysql' ), ), ),History
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 7.0.4 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.