WordPress.org

Make WordPress Core

Changeset 43108


Ignore:
Timestamp:
05/02/2018 03:33:22 AM (20 months ago)
Author:
SergeyBiryukov
Message:

Privacy: add attachments to the personal data export file.

Props allendav.
Merges [43054] to the 4.9 branch.
See #43883.

Location:
branches/4.9
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/file.php

    r43096 r43108  
    18401840
    18411841        foreach ( (array) $group_item_data as $group_item_datum ) {
     1842            $value = $group_item_datum['value'];
     1843            // If it looks like a link, make it a link
     1844            if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) {
     1845                $value = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
     1846            }
     1847
    18421848            $group_html .= '<tr>';
    18431849            $group_html .= '<th>' . esc_html( $group_item_datum['name'] ) . '</th>';
    1844             $group_html .= '<td>' . wp_kses( $group_item_datum['value'], $allowed_tags, $allowed_protocols ) . '</td>';
     1850            $group_html .= '<td>' . wp_kses( $value, $allowed_tags, $allowed_protocols ) . '</td>';
    18451851            $group_html .= '</tr>';
    18461852        }
  • branches/4.9/src/wp-includes/default-filters.php

    r43101 r43108  
    325325add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 );
    326326add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
     327add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' );
    327328add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
    328329add_action( 'init', 'wp_schedule_delete_old_privacy_export_files' );
  • branches/4.9/src/wp-includes/media.php

    r43064 r43108  
    39583958    return array( $mediaelement, $wpmediaelement );
    39593959}
     3960
     3961/**
     3962 * Registers the personal data exporter for media
     3963 *
     3964 * @param array   $exporters   An array of personal data exporters.
     3965 * @return array  An array of personal data exporters.
     3966 */
     3967function wp_register_media_personal_data_exporter( $exporters ) {
     3968    $exporters[] = array(
     3969        'exporter_friendly_name' => __( 'WordPress Media' ),
     3970        'callback'               => 'wp_media_personal_data_exporter',
     3971    );
     3972
     3973    return $exporters;
     3974}
     3975
     3976/**
     3977 * Finds and exports attachments associated with an email address.
     3978 *
     3979 * @since 4.9.6
     3980 *
     3981 * @param  string $email_address The attachment owner email address.
     3982 * @param  int    $page          Attachment page.
     3983 * @return array  $return        An array of personal data.
     3984 */
     3985function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
     3986    // Limit us to 50 attachments at a time to avoid timing out.
     3987    $number = 50;
     3988    $page   = (int) $page;
     3989
     3990    $data_to_export = array();
     3991
     3992    $user = get_user_by( 'email' , $email_address );
     3993    if ( false === $user ) {
     3994        return array(
     3995            'data' => $data_to_export,
     3996            'done' => true,
     3997        );
     3998    }
     3999
     4000    $post_query = new WP_Query(
     4001        array(
     4002            'author'         => $user->ID,
     4003            'posts_per_page' => $number,
     4004            'paged'          => $page,
     4005            'post_type'      => 'attachment',
     4006            'post_status'    => 'any',
     4007            'orderby'        => 'ID',
     4008            'order'          => 'ASC',
     4009        )
     4010    );
     4011
     4012    foreach ( (array) $post_query->posts as $post ) {
     4013        $attachment_url = wp_get_attachment_url( $post->ID );
     4014
     4015        if ( $attachment_url ) {
     4016            $post_data_to_export = array(
     4017                array( 'name'  => __( 'URL' ), 'value' => $attachment_url ),
     4018            );
     4019
     4020            $data_to_export[] = array(
     4021                'group_id'    => 'media',
     4022                'group_label' => __( 'Media' ),
     4023                'item_id'     => "post-{$post->ID}",
     4024                'data'        => $post_data_to_export,
     4025            );
     4026        }
     4027    }
     4028
     4029    $done = $post_query->max_num_pages <= $page;
     4030
     4031    return array(
     4032        'data' => $data_to_export,
     4033        'done' => $done,
     4034    );
     4035}
Note: See TracChangeset for help on using the changeset viewer.