From ef14780ff010b37fe0236958f6154e37f0e26125 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 1 May 2018 13:44:50 +0000 Subject: [PATCH] Privacy: add attachments to the personal data export file. Props allendav. See #43883. git-svn-id: https://develop.svn.wordpress.org/trunk@43054 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 8 ++- src/wp-includes/default-filters.php | 1 + src/wp-includes/media.php | 76 +++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 200f581da8..b090ed717f 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -1976,9 +1976,15 @@ function wp_privacy_generate_personal_data_export_group_html( $group_data ) { $group_html .= ''; foreach ( (array) $group_item_data as $group_item_datum ) { + $value = $group_item_datum['value']; + // If it looks like a link, make it a link + if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) { + $value = '' . esc_html( $value ) . ''; + } + $group_html .= ''; $group_html .= '' . esc_html( $group_item_datum['name'] ) . ''; - $group_html .= '' . wp_kses( $group_item_datum['value'], $allowed_tags, $allowed_protocols ) . ''; + $group_html .= '' . wp_kses( $value, $allowed_tags, $allowed_protocols ) . ''; $group_html .= ''; } diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index a3c68eed86..797353b961 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -351,6 +351,7 @@ add_action( 'welcome_panel', 'wp_welcome_panel' ); add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' ); add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 ); add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' ); +add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' ); add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' ); add_action( 'init', 'wp_schedule_delete_old_privacy_export_files' ); add_action( 'wp_privacy_delete_old_export_files', 'wp_privacy_delete_old_export_files' ); diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a52048f475..87321fe945 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -4093,3 +4093,79 @@ function wpview_media_sandbox_styles() { return array( $mediaelement, $wpmediaelement ); } + +/** + * Registers the personal data exporter for media + * + * @param array $exporters An array of personal data exporters. + * @return array An array of personal data exporters. + */ +function wp_register_media_personal_data_exporter( $exporters ) { + $exporters[] = array( + 'exporter_friendly_name' => __( 'WordPress Media' ), + 'callback' => 'wp_media_personal_data_exporter', + ); + + return $exporters; +} + +/** + * Finds and exports attachments associated with an email address. + * + * @since 4.9.6 + * + * @param string $email_address The attachment owner email address. + * @param int $page Attachment page. + * @return array $return An array of personal data. + */ +function wp_media_personal_data_exporter( $email_address, $page = 1 ) { + // Limit us to 50 attachments at a time to avoid timing out. + $number = 50; + $page = (int) $page; + + $data_to_export = array(); + + $user = get_user_by( 'email' , $email_address ); + if ( false === $user ) { + return array( + 'data' => $data_to_export, + 'done' => true, + ); + } + + $post_query = new WP_Query( + array( + 'author' => $user->ID, + 'posts_per_page' => $number, + 'paged' => $page, + 'post_type' => 'attachment', + 'post_status' => 'any', + 'orderby' => 'ID', + 'order' => 'ASC', + ) + ); + + foreach ( (array) $post_query->posts as $post ) { + $attachment_url = wp_get_attachment_url( $post->ID ); + + if ( $attachment_url ) { + $post_data_to_export = array( + array( 'name' => __( 'URL' ), 'value' => $attachment_url ), + ); + + $data_to_export[] = array( + 'group_id' => 'media', + 'group_label' => __( 'Media' ), + 'item_id' => "post-{$post->ID}", + 'data' => $post_data_to_export, + ); + } + } + + $done = $post_query->max_num_pages <= $page; + + return array( + 'data' => $data_to_export, + 'done' => $done, + ); +}