Privacy: add attachments to the personal data export file.

Props allendav.
Merges [43054] to the 4.9 branch.
See #43883.
Built from https://develop.svn.wordpress.org/branches/4.9@43108


git-svn-id: http://core.svn.wordpress.org/branches/4.9@42937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-05-02 03:34:25 +00:00
parent 2083557ea9
commit 8114ac92ef
4 changed files with 85 additions and 2 deletions

View File

@ -1839,9 +1839,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

@ -324,6 +324,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

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

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9.6-alpha-43107';
$wp_version = '4.9.6-alpha-43108';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.