WordPress.org

Make WordPress Core

Changeset 43054


Ignore:
Timestamp:
05/01/2018 01:44:50 PM (20 months ago)
Author:
azaozz
Message:

Privacy: add attachments to the personal data export file.

Props allendav.
See #43883.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r43047 r43054  
    19771977
    19781978        foreach ( (array) $group_item_data as $group_item_datum ) {
     1979            $value = $group_item_datum['value'];
     1980            // If it looks like a link, make it a link
     1981            if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) {
     1982                $value = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
     1983            }
     1984
    19791985            $group_html .= '<tr>';
    19801986            $group_html .= '<th>' . esc_html( $group_item_datum['name'] ) . '</th>';
    1981             $group_html .= '<td>' . wp_kses( $group_item_datum['value'], $allowed_tags, $allowed_protocols ) . '</td>';
     1987            $group_html .= '<td>' . wp_kses( $value, $allowed_tags, $allowed_protocols ) . '</td>';
    19821988            $group_html .= '</tr>';
    19831989        }
  • trunk/src/wp-includes/default-filters.php

    r43046 r43054  
    352352add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 );
    353353add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
     354add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' );
    354355add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
    355356add_action( 'init', 'wp_schedule_delete_old_privacy_export_files' );
  • trunk/src/wp-includes/media.php

    r42871 r43054  
    40944094    return array( $mediaelement, $wpmediaelement );
    40954095}
     4096
     4097/**
     4098 * Registers the personal data exporter for media
     4099 *
     4100 * @param array   $exporters   An array of personal data exporters.
     4101 * @return array  An array of personal data exporters.
     4102 */
     4103function wp_register_media_personal_data_exporter( $exporters ) {
     4104    $exporters[] = array(
     4105        'exporter_friendly_name' => __( 'WordPress Media' ),
     4106        'callback'               => 'wp_media_personal_data_exporter',
     4107    );
     4108
     4109    return $exporters;
     4110}
     4111
     4112/**
     4113 * Finds and exports attachments associated with an email address.
     4114 *
     4115 * @since 4.9.6
     4116 *
     4117 * @param  string $email_address The attachment owner email address.
     4118 * @param  int    $page          Attachment page.
     4119 * @return array  $return        An array of personal data.
     4120 */
     4121function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
     4122    // Limit us to 50 attachments at a time to avoid timing out.
     4123    $number = 50;
     4124    $page   = (int) $page;
     4125
     4126    $data_to_export = array();
     4127
     4128    $user = get_user_by( 'email' , $email_address );
     4129    if ( false === $user ) {
     4130        return array(
     4131            'data' => $data_to_export,
     4132            'done' => true,
     4133        );
     4134    }
     4135
     4136    $post_query = new WP_Query(
     4137        array(
     4138            'author'         => $user->ID,
     4139            'posts_per_page' => $number,
     4140            'paged'          => $page,
     4141            'post_type'      => 'attachment',
     4142            'post_status'    => 'any',
     4143            'orderby'        => 'ID',
     4144            'order'          => 'ASC',
     4145        )
     4146    );
     4147
     4148    foreach ( (array) $post_query->posts as $post ) {
     4149        $attachment_url = wp_get_attachment_url( $post->ID );
     4150
     4151        if ( $attachment_url ) {
     4152            $post_data_to_export = array(
     4153                array( 'name'  => __( 'URL' ), 'value' => $attachment_url ),
     4154            );
     4155
     4156            $data_to_export[] = array(
     4157                'group_id'    => 'media',
     4158                'group_label' => __( 'Media' ),
     4159                'item_id'     => "post-{$post->ID}",
     4160                'data'        => $post_data_to_export,
     4161            );
     4162        }
     4163    }
     4164
     4165    $done = $post_query->max_num_pages <= $page;
     4166
     4167    return array(
     4168        'data' => $data_to_export,
     4169        'done' => $done,
     4170    );
     4171}
Note: See TracChangeset for help on using the changeset viewer.