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
This commit is contained in:
Andrew Ozz 2018-05-01 13:44:50 +00:00
parent 3b98427140
commit ef14780ff0
3 changed files with 84 additions and 1 deletions

View File

@ -1976,9 +1976,15 @@ function wp_privacy_generate_personal_data_export_group_html( $group_data ) {
$group_html .= '<tbody>';
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 = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
}
$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 .= '<td>' . wp_kses( $value, $allowed_tags, $allowed_protocols ) . '</td>';
$group_html .= '</tr>';
}

View File

@ -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' );

View File

@ -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,
);
}