<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[43012] trunk/src: Privacy: add means to export personal data by username or email address.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/43012">43012</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/43012","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-04-27 19:53:37 +0000 (Fri, 27 Apr 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Privacy: add means to export personal data by username or email address. Generate a zipped export file containing all data. First run.
Props allendav.
See <a href="https://core.trac.wordpress.org/ticket/43546">#43546</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesadminfiltersphp">trunk/src/wp-admin/includes/admin-filters.php</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
<li><a href="#trunksrcwpadminincludesuserphp">trunk/src/wp-admin/includes/user.php</a></li>
<li><a href="#trunksrcwpadminjsxfnjs">trunk/src/wp-admin/js/xfn.js</a></li>
<li><a href="#trunksrcwpincludescommentphp">trunk/src/wp-includes/comment.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesadminfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/admin-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/admin-filters.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-admin/includes/admin-filters.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -132,6 +132,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Privacy hooks
+add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 6 );
+add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Privacy policy text changes check.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 20 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,4 +147,3 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Stop checking for text changes after the policy page is updated.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_updated' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4327,16 +4327,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Ajax handler for exporting a user's personal data.
+ *
+ * @since 4.9.6
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function wp_ajax_wp_privacy_export_personal_data() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- check_ajax_referer( 'wp-privacy-export-personal-data', 'security' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_id = (int) $_POST['id'];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $request_id ) ) {
+ wp_send_json_error( __( 'Error: Invalid request ID.' ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! current_user_can( 'manage_options' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( __( 'Error: Invalid request.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $email_address = sanitize_text_field( $_POST['email'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ check_ajax_referer( 'wp-privacy-export-personal-data-' . $request_id, 'security' );
+
+ // Get the request data.
+ $request = wp_get_user_request_data( $request_id );
+
+ if ( ! $request || 'export_personal_data' !== $request->action_name ) {
+ wp_send_json_error( __( 'Error: Invalid request type.' ) );
+ }
+
+ $email_address = $request->email;
+ if ( ! is_email( $email_address ) ) {
+ wp_send_json_error( __( 'Error: A valid email address must be given.' ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $exporter_index = (int) $_POST['exporter'];
</span><span class="cx" style="display: block; padding: 0 10px"> $page = (int) $_POST['page'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( "true" === $_POST['sendAsEmail'] ) : false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the array of exporter callbacks.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4348,8 +4371,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * [
</span><span class="cx" style="display: block; padding: 0 10px"> * callback string Callable exporter that accepts an email address and
</span><span class="cx" style="display: block; padding: 0 10px"> * a page and returns an array of name => value
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * pairs of personal data
- * exporter_friendly_name string Translated user facing friendly name for the exporter
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * pairs of personal data.
+ * exporter_friendly_name string Translated user facing friendly name for the exporter.
</ins><span class="cx" style="display: block; padding: 0 10px"> * ]
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4375,26 +4398,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( 'Page index cannot be less than one.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Surprisingly, email addresses can contain mutli-byte characters now
- $email_address = trim( mb_strtolower( $email_address ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $exporter = $exporters[ $index ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_email( $email_address ) ) {
- wp_send_json_error( 'A valid email address must be given.' );
- }
-
- $exporter = $exporters[ $index ];
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $exporter ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( "Expected an array describing the exporter at index {$exporter_index}." );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
+ wp_send_json_error( "Exporter array at index {$exporter_index} does not include a friendly name." );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! array_key_exists( 'callback', $exporter ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_send_json_error( "Exporter array at index {$exporter_index} does not include a callback." );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_send_json_error( "Exporter does not include a callback: {$exporter['exporter_friendly_name']}." );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_callable( $exporter['callback'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_send_json_error( "Exporter callback at index {$exporter_index} is not a valid callback." );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_send_json_error( "Exporter callback is not a valid callback: {$exporter['exporter_friendly_name']}." );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
- wp_send_json_error( "Exporter array at index {$exporter_index} does not include a friendly name." );
- }
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $callback = $exporters[ $index ]['callback'];
</span><span class="cx" style="display: block; padding: 0 10px"> $exporter_friendly_name = $exporters[ $index ]['exporter_friendly_name'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4417,7 +4434,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( "Expected done (boolean) in response array from exporter: {$exporter_friendly_name}." );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // No exporters, so we're done
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // No exporters, so we're done.
</ins><span class="cx" style="display: block; padding: 0 10px"> $response = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'data' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'done' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4435,8 +4452,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $exporter_index The index of the exporter that provided this data.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $email_address The email address associated with this personal data.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $page The zero-based page for this response.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id The privacy request post ID associated with this request.
+ * @param bool $send_as_email Whether the final results of the export should be emailed to the user.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $response ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( $response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4462,7 +4482,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> check_ajax_referer( 'wp-privacy-erase-personal-data-' . $request_id, 'security' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Find the request CPT
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get the request data.
</ins><span class="cx" style="display: block; padding: 0 10px"> $request = wp_get_user_request_data( $request_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
</span></span></pre></div>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/file.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/file.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-admin/includes/file.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1934,3 +1934,432 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Generate a single group for the personal data export report.
+ *
+ * @since 4.9.6
+ *
+ * @param array $group_data {
+ * The group data to render.
+ *
+ * @type string $group_label The user-facing heading for the group, e.g. 'Comments'.
+ * @type array $items {
+ * An array of group items.
+ *
+ * @type array $group_item_data {
+ * An array of name-value pairs for the item.
+ *
+ * @type string $name The user-facing name of an item name-value pair, e.g. 'IP Address'.
+ * @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'.
+ * }
+ * }
+ * }
+ * @return string The HTML for this group and its items.
+ */
+function wp_privacy_generate_personal_data_export_group_html( $group_data ) {
+ $allowed_tags = array(
+ 'a' => array(
+ 'href' => array(),
+ 'target' => array()
+ ),
+ 'br' => array()
+ );
+ $allowed_protocols = array( 'http', 'https' );
+ $group_html = '';
+
+ $group_html .= '<h2>' . esc_html( $group_data['group_label'] ) . '</h2>';
+ $group_html .= '<div>';
+
+ foreach ( (array) $group_data['items'] as $group_item_id => $group_item_data ) {
+ $group_html .= '<table>';
+ $group_html .= '<tbody>';
+
+ foreach ( (array) $group_item_data as $group_item_datum ) {
+ $group_html .= '<tr>';
+ $group_html .= '<th>' . esc_html( $group_item_datum['name'] ) . '</th>';
+ $group_html .= '<td>' . wp_kses( $group_item_datum['value'], $allowed_tags, $allowed_protocols ) . '</td>';
+ $group_html .= '</tr>';
+ }
+
+ $group_html .= '</tbody>';
+ $group_html .= '</table>';
+ }
+
+ $group_html .= '</div>';
+
+ return $group_html;
+}
+
+/**
+ * Generate the personal data export file.
+ *
+ * @since 4.9.6
+ *
+ * @param int $request_id The export request ID.
+ */
+function wp_privacy_generate_personal_data_export_file( $request_id ) {
+ // Maybe make this a cron job instead.
+ wp_privacy_delete_old_export_files();
+
+ if ( ! class_exists( 'ZipArchive' ) ) {
+ wp_send_json_error( __( 'Unable to generate export file. ZipArchive not available.' ) );
+ }
+
+ // Get the request data.
+ $request = wp_get_user_request_data( $request_id );
+
+ if ( ! $request || 'export_personal_data' !== $request->action_name ) {
+ wp_send_json_error( __( 'Invalid request ID when generating export file' ) );
+ }
+
+ $email_address = $request->email;
+
+ if ( ! is_email( $email_address ) ) {
+ wp_send_json_error( __( 'Invalid email address when generating export file' ) );
+ }
+
+ // Create the exports folder if needed.
+ $upload_dir = wp_upload_dir();
+ $exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
+ $exports_url = trailingslashit( $upload_dir['baseurl'] . '/exports' );
+
+ $result = wp_mkdir_p( $exports_dir );
+ if ( is_wp_error( $result ) ) {
+ wp_send_json_error( $result->get_error_message() );
+ }
+
+ // Protect export folder from browsing.
+ $index_pathname = $exports_dir . 'index.html';
+ if ( ! file_exists( $index_pathname ) ) {
+ $file = fopen( $index_pathname, 'w' );
+ if ( false === $file ) {
+ wp_send_json_error( __( 'Unable to protect export folder from browsing' ) );
+ }
+ fwrite( $file, 'Silence is golden.' );
+ fclose( $file );
+ }
+
+ $stripped_email = str_replace( '@', '-at-', $email_address );
+ $stripped_email = sanitize_title( $stripped_email ); // slugify the email address
+ $obscura = md5( rand() );
+ $file_basename = 'wp-personal-data-file-' . $stripped_email . '-' . $obscura;
+ $html_report_filename = $file_basename . '.html';
+ $html_report_pathname = $exports_dir . $html_report_filename;
+ $file = fopen( $html_report_pathname, 'w' );
+ if ( false === $file ) {
+ wp_send_json_error( __( 'Unable to open export file (HTML report) for writing' ) );
+ }
+
+ $title = sprintf(
+ // translators: %s Users e-mail address.
+ __( 'Personal Data Export for %s' ),
+ $email_address
+ );
+
+ // Open HTML.
+ fwrite( $file, "<!DOCTYPE html>\n" );
+ fwrite( $file, "<html>\n" );
+
+ // Head.
+ fwrite( $file, "<head>\n" );
+ fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" );
+ fwrite( $file, "<style type='text/css'>" );
+ fwrite( $file, "body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }" );
+ fwrite( $file, "table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }" );
+ fwrite( $file, "th { padding: 5px; text-align: left; width: 20%; }" );
+ fwrite( $file, "td { padding: 5px; }" );
+ fwrite( $file, "tr:nth-child(odd) { background-color: #fafafa; }" );
+ fwrite( $file, "</style>" );
+ fwrite( $file, "<title>" );
+ fwrite( $file, esc_html( $title ) );
+ fwrite( $file, "</title>" );
+ fwrite( $file, "</head>\n" );
+
+ // Body.
+ fwrite( $file, "<body>\n" );
+
+ // Heading.
+ fwrite( $file, "<h1>" . esc_html__( 'Personal Data Export' ) . "</h1>" );
+
+ // And now, all the Groups.
+ $groups = get_post_meta( $request_id, '_export_data_grouped', true );
+
+ // First, build an "About" group on the fly for this report.
+ $about_group = array(
+ 'group_label' => __( 'About' ),
+ 'items' => array(
+ 'about-1' => array(
+ array(
+ 'name' => __( 'Report generated for' ),
+ 'value' => $email_address,
+ ),
+ array(
+ 'name' => __( 'For site' ),
+ 'value' => get_bloginfo( 'name' ),
+ ),
+ array(
+ 'name' => __( 'At URL' ),
+ 'value' => get_bloginfo( 'url' ),
+ ),
+ array(
+ 'name' => __( 'On' ),
+ 'value' => current_time( 'mysql' ),
+ ),
+ ),
+ ),
+ );
+
+ // Merge in the special about group.
+ $groups = array_merge( array( 'about' => $about_group ), $groups );
+
+ // Now, iterate over every group in $groups and have the formatter render it in HTML.
+ foreach ( (array) $groups as $group_id => $group_data ) {
+ fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) );
+ }
+
+ fwrite( $file, "</body>\n" );
+
+ // Close HTML.
+ fwrite( $file, "</html>\n" );
+ fclose( $file );
+
+ // Now, generate the ZIP.
+ $archive_filename = $file_basename . '.zip';
+ $archive_pathname = $exports_dir . $archive_filename;
+ $archive_url = $exports_url . $archive_filename;
+
+ $zip = new ZipArchive;
+
+ if ( TRUE === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) {
+ $zip->addFile( $html_report_pathname, 'index.html' );
+ $zip->close();
+ } else {
+ wp_send_json_error( __( 'Unable to open export file (archive) for writing' ) );
+ }
+
+ // And remove the HTML file.
+ unlink( $html_report_pathname );
+
+ // Save the export file in the request.
+ update_post_meta( $request_id, '_export_file_url', $archive_url );
+ update_post_meta( $request_id, '_export_file_path', $archive_pathname );
+}
+
+/**
+ * Send an email to the user with a link to the personal data export file
+ *
+ * @since 4.9.6
+ *
+ * @param int $request_id The request ID for this personal data export.
+ * @return true|WP_Error True on success or `WP_Error` on failure.
+ */
+function wp_privacy_send_personal_data_export_email( $request_id ) {
+ // Get the request data.
+ $request = wp_get_user_request_data( $request_id );
+
+ if ( ! $request || 'export_personal_data' !== $request->action_name ) {
+ return new WP_Error( 'invalid', __( 'Invalid request ID when sending personal data export email.' ) );
+ }
+
+/* translators: Do not translate LINK, EMAIL, SITENAME, SITEURL: those are placeholders. */
+$email_text = __(
+'Howdy,
+
+Your request for an export of personal data has been completed. You may
+download your personal data by clicking on the link below. This link is
+good for the next 3 days.
+
+###LINK###
+
+This email has been sent to ###EMAIL###.
+
+Regards,
+All at ###SITENAME###
+###SITEURL###'
+);
+
+ /**
+ * Filters the text of the email sent with a personal data export file.
+ *
+ * The following strings have a special meaning and will get replaced dynamically:
+ * ###LINK### URL of the personal data export file for the user.
+ * ###EMAIL### The email we are sending to.
+ * ###SITENAME### The name of the site.
+ * ###SITEURL### The URL to the site.
+ *
+ * @since 4.9.6
+ *
+ * @param string $email_text Text in the email.
+ * @param int $request_id The request ID for this personal data export.
+ */
+ $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
+
+ $email_address = $request->email;
+ $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
+ $site_name = is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' );
+ $site_url = network_home_url();
+
+ $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
+ $content = str_replace( '###EMAIL###', $email_address, $content );
+ $content = str_replace( '###SITENAME###', wp_specialchars_decode( $site_name, ENT_QUOTES ), $content );
+ $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
+
+ $mail_success = wp_mail(
+ $email_address,
+ sprintf(
+ __( '[%s] Personal Data Export' ),
+ wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
+ ),
+ $content
+ );
+
+ if ( ! $mail_success ) {
+ return new WP_Error( 'error', __( 'Unable to send personal data export email.' ) );
+ }
+
+ return true;
+}
+
+/**
+ * Intercept personal data exporter page ajax responses in order to assemble the personal data export file.
+ * @see wp_privacy_personal_data_export_page
+ * @since 4.9.6
+ *
+ * @param array $response The response from the personal data exporter for the given page.
+ * @param int $exporter_index The index of the personal data exporter. Begins at 1.
+ * @param string $email_address The email address of the user whose personal data this is.
+ * @param int $page The page of personal data for this exporter. Begins at 1.
+ * @param int $request_id The request ID for this personal data export.
+ * @param bool $send_as_email Whether the final results of the export should be emailed to the user.
+ * @return array The filtered response.
+ */
+function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email ) {
+ /* Do some simple checks on the shape of the response from the exporter.
+ * If the exporter response is malformed, don't attempt to consume it - let it
+ * pass through to generate a warning to the user by default ajax processing.
+ */
+ if ( ! is_array( $response ) ) {
+ return $response;
+ }
+
+ if ( ! array_key_exists( 'done', $response ) ) {
+ return $response;
+ }
+
+ if ( ! array_key_exists( 'data', $response ) ) {
+ return $response;
+ }
+
+ if ( ! is_array( $response['data'] ) ) {
+ return $response;
+ }
+
+ // Get the request data.
+ $request = wp_get_user_request_data( $request_id );
+
+ if ( ! $request || 'export_personal_data' !== $request->action_name ) {
+ wp_send_json_error( __( 'Invalid request ID when merging exporter data' ) );
+ }
+
+ $export_data = array();
+
+ // First exporter, first page? Reset the report data accumulation array.
+ if ( 1 === $exporter_index && 1 === $page ) {
+ update_post_meta( $request_id, '_export_data_raw', $export_data );
+ } else {
+ $export_data = get_post_meta( $request_id, '_export_data_raw', true );
+ }
+
+ // Now, merge the data from the exporter response into the data we have accumulated already.
+ $export_data = array_merge( $export_data, $response['data'] );
+ update_post_meta( $request_id, '_export_data_raw', $export_data );
+
+ // If we are not yet on the last page of the last exporter, return now.
+ $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
+ $is_last_exporter = $exporter_index === count( $exporters );
+ $exporter_done = $response['done'];
+ if ( ! $is_last_exporter || ! $exporter_done ) {
+ return $response;
+ }
+
+ // Last exporter, last page - let's prepare the export file.
+
+ // First we need to re-organize the raw data hierarchically in groups and items.
+ $groups = array();
+ foreach ( (array) $export_data as $export_datum ) {
+ $group_id = $export_datum['group_id'];
+ $group_label = $export_datum['group_label'];
+ if ( ! array_key_exists( $group_id, $groups ) ) {
+ $groups[ $group_id ] = array(
+ 'group_label' => $group_label,
+ 'items' => array(),
+ );
+ }
+
+ $item_id = $export_datum['item_id'];
+ if ( ! array_key_exists( $item_id, $groups[ $group_id ]['items'] ) ) {
+ $groups[ $group_id ]['items'][ $item_id ] = array();
+ }
+
+ $old_item_data = $groups[ $group_id ]['items'][ $item_id ];
+ $merged_item_data = array_merge( $export_datum['data'], $old_item_data );
+ $groups[ $group_id ]['items'][ $item_id ] = $merged_item_data;
+ }
+
+ // Then save the grouped data into the request.
+ delete_post_meta( $request_id, '_export_data_raw' );
+ update_post_meta( $request_id, '_export_data_grouped', $groups );
+
+ // And now, generate the export file, cleaning up any previous file
+ $export_path = get_post_meta( $request_id, '_export_file_path', true );
+ if ( ! empty( $export_path ) ) {
+ delete_post_meta( $request_id, '_export_file_path' );
+ @unlink( $export_path );
+ }
+ delete_post_meta( $request_id, '_export_file_url' );
+
+ // Generate the export file from the collected, grouped personal data.
+ do_action( 'wp_privacy_personal_data_export_file', $request_id );
+
+ // Clear the grouped data now that it is no longer needed.
+ delete_post_meta( $request_id, '_export_data_grouped' );
+
+ // If the destination is email, send it now.
+ if ( $send_as_email ) {
+ $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
+ if ( is_wp_error( $mail_success ) ) {
+ wp_send_json_error( $mail_success->get_error_message() );
+ }
+ } else {
+ // Modify the response to include the URL of the export file so the browser can fetch it.
+ $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
+ if ( ! empty( $export_file_url ) ) {
+ $response['url'] = $export_file_url;
+ }
+ }
+
+ // Update the request to completed state.
+ _wp_privacy_completed_request( $request_id );
+
+ return $response;
+}
+
+/**
+ * Cleans up export files older than three days old.
+ *
+ * @since 4.9.6
+ */
+function wp_privacy_delete_old_export_files() {
+ $upload_dir = wp_upload_dir();
+ $exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
+ $export_files = list_files( $exports_dir );
+
+ foreach( (array) $export_files as $export_file ) {
+ $file_age_in_seconds = time() - filemtime( $export_file );
+
+ if ( 3 * DAY_IN_SECONDS < $file_age_in_seconds ) {
+ @unlink( $export_file );
+ }
+ }
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/user.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-admin/includes/user.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -664,33 +664,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( isset( $_POST['export_personal_data_email_send'] ) ) { // WPCS: input var ok.
- check_admin_referer( 'bulk-privacy_requests' );
-
- $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['export_personal_data_email_send'] ) ) ) ); // WPCS: input var ok, sanitization ok.
- $result = false;
-
- /**
- * TODO: Email the data to the user here.
- */
-
- if ( is_wp_error( $result ) ) {
- add_settings_error(
- 'export_personal_data_email_send',
- 'export_personal_data_email_send',
- $result->get_error_message(),
- 'error'
- );
- } else {
- _wp_privacy_completed_request( $request_id );
- add_settings_error(
- 'export_personal_data_email_send',
- 'export_personal_data_email_send',
- __( 'Personal data was sent to the user successfully.' ),
- 'updated'
- );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> } elseif ( isset( $_POST['action'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $action = isset( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : ''; // WPCS: input var ok, CSRF ok.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -819,6 +792,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> _wp_personal_data_handle_actions();
</span><span class="cx" style="display: block; padding: 0 10px"> _wp_personal_data_cleanup_requests();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // "Borrow" xfn.js for now so we don't have to create new files.
+ wp_enqueue_script( 'xfn' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $requests_table = new WP_Privacy_Data_Export_Requests_Table( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'plural' => 'privacy_requests',
</span><span class="cx" style="display: block; padding: 0 10px"> 'singular' => 'privacy_request',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1361,16 +1337,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $request_id = $item->ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $download_data_markup = '<div class="download_personal_data" ' .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $download_data_markup = '<div class="export_personal_data" ' .
</ins><span class="cx" style="display: block; padding: 0 10px"> 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
</span><span class="cx" style="display: block; padding: 0 10px"> 'data-request-id="' . esc_attr( $request_id ) . '" ' .
</span><span class="cx" style="display: block; padding: 0 10px"> 'data-nonce="' . esc_attr( $nonce ) .
</span><span class="cx" style="display: block; padding: 0 10px"> '">';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $download_data_markup .= '<span class="download_personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .
- '<span style="display:none" class="download_personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .
- '<span style="display:none" class="download_personal_data_failed">' . __( 'Download Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $download_data_markup .= '<span class="export_personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .
+ '<span style="display:none" class="export_personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .
+ '<span style="display:none" class="export_personal_data_success"><a href="#" >' . __( 'Download Personal Data Again' ) . '</a></span>' .
+ '<span style="display:none" class="export_personal_data_failed">' . __( 'Download Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $download_data_markup .= '</div>';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $row_actions = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'download_data' => $download_data_markup,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1393,7 +1372,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> esc_html_e( 'Waiting for confirmation' );
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'request-confirmed':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO Complete in follow on patch.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
+ $exporters_count = count( $exporters );
+ $request_id = $item->ID;
+ $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
+
+ echo '<div class="export_personal_data" ' .
+ 'data-send-as-email="1" ' .
+ 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
+ 'data-request-id="' . esc_attr( $request_id ) . '" ' .
+ 'data-nonce="' . esc_attr( $nonce ) .
+ '">';
+
+ ?>
+ <span class="export_personal_data_idle"><a class="button" href="#" ><?php _e( 'Email Data' ); ?></a></span>
+ <span style="display:none" class="export_personal_data_processing button updating-message" ><?php _e( 'Sending Email...' ); ?></span>
+ <span style="display:none" class="export_personal_data_success success-message" ><?php _e( 'Email Sent!' ); ?></span>
+ <span style="display:none" class="export_personal_data_failed"><?php _e( 'Email Failed!' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>
+ <?php
+
+ echo '</div>';
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'request-failed':
</span><span class="cx" style="display: block; padding: 0 10px"> submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1461,6 +1459,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '<span style="display:none" class="remove_personal_data_processing" >' . __( 'Removing Data...' ) . '</span>' .
</span><span class="cx" style="display: block; padding: 0 10px"> '<span style="display:none" class="remove_personal_data_failed">' . __( 'Force Remove Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $remove_data_markup .= '</div>';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $row_actions = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'remove_data' => $remove_data_markup,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1502,6 +1502,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <span style="display:none" class="remove_personal_data_failed"><?php _e( 'Removing Data Failed!' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo '</div>';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'request-failed':
</span><span class="cx" style="display: block; padding: 0 10px"> submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
</span></span></pre></div>
<a id="trunksrcwpadminjsxfnjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/xfn.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/xfn.js 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-admin/js/xfn.js 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,7 +22,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Privacy request action handling
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> jQuery( document ).ready( function( $ ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var strings = window.privacyToolsL10n || {};
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,17 +38,98 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
</span><span class="cx" style="display: block; padding: 0 10px"> clearResultsAfterRow( $requestRow );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ var itemList = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( additionalMessages.length ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO - render additionalMessages after the summaryMessage
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $.each( additionalMessages, function( index, value ) {
+ itemList = itemList + '<li>' + value + '</li>';
+ } );
+ itemList = '<ul>' + itemList + '</ul>';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $requestRow.after( function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return '<tr class="request-results"><td colspan="5"><div class="notice inline notice-alt ' + classes + '"><p>' +
- summaryMessage +
- '</p></div></td></tr>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return '<tr class="request-results"><td colspan="5">' +
+ '<div class="notice inline notice-alt ' + classes + '">' +
+ '<p>' + summaryMessage + '</p>' +
+ itemList +
+ '</div>' +
+ '</td>' +
+ '</tr>';
</ins><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $( '.export_personal_data a' ).click( function( event ) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ var $this = $( this );
+ var $action = $this.parents( '.export_personal_data' );
+ var $requestRow = $this.parents( 'tr' );
+ var requestID = $action.data( 'request-id' );
+ var nonce = $action.data( 'nonce' );
+ var exportersCount = $action.data( 'exporters-count' );
+ var sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
+
+ $action.blur();
+ clearResultsAfterRow( $requestRow );
+
+ function on_export_done_success( zipUrl ) {
+ set_action_state( $action, 'export_personal_data_success' );
+ if ( 'undefined' !== typeof zipUrl ) {
+ window.location = zipUrl;
+ } else if ( ! sendAsEmail ) {
+ on_export_failure( strings.noExportFile );
+ }
+ }
+
+ function on_export_failure( errorMessage ) {
+ set_action_state( $action, 'export_personal_data_failed' );
+ if ( errorMessage ) {
+ appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] );
+ }
+ }
+
+ function do_next_export( exporterIndex, pageIndex ) {
+ $.ajax(
+ {
+ url: window.ajaxurl,
+ data: {
+ action: 'wp-privacy-export-personal-data',
+ exporter: exporterIndex,
+ id: requestID,
+ page: pageIndex,
+ security: nonce,
+ sendAsEmail: sendAsEmail
+ },
+ method: 'post'
+ }
+ ).done( function( response ) {
+ if ( ! response.success ) {
+ // e.g. invalid request ID
+ on_export_failure( response.data );
+ return;
+ }
+ var responseData = response.data;
+ if ( ! responseData.done ) {
+ setTimeout( do_next_export( exporterIndex, pageIndex + 1 ) );
+ } else {
+ if ( exporterIndex < exportersCount ) {
+ setTimeout( do_next_export( exporterIndex + 1, 1 ) );
+ } else {
+ on_export_done_success( responseData.url );
+ }
+ }
+ } ).fail( function( jqxhr, textStatus, error ) {
+ // e.g. Nonce failure
+ on_export_failure( error );
+ } );
+ }
+
+ // And now, let's begin
+ set_action_state( $action, 'export_personal_data_processing' );
+ do_next_export( 1, 1 );
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $( '.remove_personal_data a' ).click( function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> event.preventDefault();
</span><span class="cx" style="display: block; padding: 0 10px"> event.stopPropagation();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,7 +172,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function on_erasure_failure() {
</span><span class="cx" style="display: block; padding: 0 10px"> set_action_state( $action, 'remove_personal_data_failed' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- appendResultsAfterRow( $requestRow, 'notice-error', strings.anErrorOccurred, [] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function do_next_erasure( eraserIndex, pageIndex ) {
</span></span></pre></div>
<a id="trunksrcwpincludescommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-includes/comment.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3352,6 +3352,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> case 'comment_link':
</span><span class="cx" style="display: block; padding: 0 10px"> $value = get_comment_link( $comment->comment_ID );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = '<a href="' . $value . '" target="_blank" rel="noreferrer noopener">' . $value . '</a>';
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-includes/script-loader.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -715,7 +715,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'foundAndRemoved' => __( 'All of the personal data found for this user was removed.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'noneRemoved' => __( 'Personal data was found for this user but was not removed.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'someNotRemoved' => __( 'Personal data was found for this user but some of the personal data found was not removed.' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'anErrorOccurred' => __( 'An error occurred while attempting to find and remove personal data.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'removalError' => __( 'An error occurred while attempting to find and remove personal data.' ),
+ 'noExportFile' => __( 'No personal data export file was generated.' ),
+ 'exportError' => __( 'An error occurred while attempting to export personal data.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2018-04-27 17:30:28 UTC (rev 43011)
+++ trunk/src/wp-includes/user.php 2018-04-27 19:53:37 UTC (rev 43012)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3145,7 +3145,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.9.6
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $request_id Request ID to get data about.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array|false
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return WP_User_Request|false
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_user_request_data( $request_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $request_id = absint( $request_id );
</span></span></pre>
</div>
</div>
</body>
</html>