Make WordPress Core

Changeset 43117


Ignore:
Timestamp:
05/02/2018 04:20:35 AM (9 years ago)
Author:
SergeyBiryukov
Message:

Privacy: add user information to the personal data export file.

Props TZ-Media, desrosj.
Merges [43055] and [43116] to the 4.9 branch.
See #43547.

Location:
branches/4.9
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/default-filters.php

    r43108 r43117  
    326326add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
    327327add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' );
     328add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_user_personal_data_exporter' );
    328329add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
    329330add_action( 'init', 'wp_schedule_delete_old_privacy_export_files' );
  • branches/4.9/src/wp-includes/user.php

    r43092 r43117  
    27492749
    27502750/**
     2751 * Registers the personal data exporter for users.
     2752 *
     2753 * @since 4.9.6
     2754 *
     2755 * @param array $exporters  An array of personal data exporters.
     2756 * @return array An array of personal data exporters.
     2757 */
     2758function wp_register_user_personal_data_exporter( $exporters ) {
     2759        $exporters[] = array(
     2760                'exporter_friendly_name' => __( 'WordPress User' ),
     2761                'callback'               => 'wp_user_personal_data_exporter',
     2762        );
     2763
     2764        return $exporters;
     2765}
     2766
     2767/**
     2768 * Finds and exports personal data associated with an email address from the user and user_meta table.
     2769 *
     2770 * @since 4.9.6
     2771 *
     2772 * @param string $email_address  The users email address.
     2773 * @return array An array of personal data.
     2774 */
     2775function wp_user_personal_data_exporter( $email_address ) {
     2776        $email_address = trim( $email_address );
     2777
     2778        $data_to_export = array();
     2779
     2780        $user = get_user_by( 'email', $email_address );
     2781
     2782        if ( ! $user ) {
     2783                return array(
     2784                        'data' => array(),
     2785                        'done' => true,
     2786                );
     2787        }
     2788
     2789        $user_meta = get_user_meta( $user->ID );
     2790
     2791        $user_prop_to_export = array(
     2792                'ID'              => __( 'User ID' ),
     2793                'user_login'      => __( 'User Login Name' ),
     2794                'user_nicename'   => __( 'User Nice Name' ),
     2795                'user_email'      => __( 'User Email' ),
     2796                'user_url'        => __( 'User URL' ),
     2797                'user_registered' => __( 'User Registration Date' ),
     2798                'display_name'    => __( 'User Display Name' ),
     2799                'nickname'        => __( 'User Nickname' ),
     2800                'first_name'      => __( 'User First Name' ),
     2801                'last_name'       => __( 'User Last Name' ),
     2802                'description'     => __( 'User Description' ),
     2803        );
     2804
     2805        $user_data_to_export = array();
     2806
     2807        foreach ( $user_prop_to_export as $key => $name ) {
     2808                $value = '';
     2809
     2810                switch ( $key ) {
     2811                        case 'ID':
     2812                        case 'user_login':
     2813                        case 'user_nicename':
     2814                        case 'user_email':
     2815                        case 'user_url':
     2816                        case 'user_registered':
     2817                        case 'display_name':
     2818                                $value = $user->data->$key;
     2819                                break;
     2820                        case 'nickname':
     2821                        case 'first_name':
     2822                        case 'last_name':
     2823                        case 'description':
     2824                                $value = $user_meta[ $key ][0];
     2825                                break;
     2826                }
     2827
     2828                if ( ! empty( $value ) ) {
     2829                        $user_data_to_export[] = array(
     2830                                'name'  => $name,
     2831                                'value' => $value,
     2832                        );
     2833                }
     2834        }
     2835
     2836        $data_to_export[] = array(
     2837                'group_id'    => 'user',
     2838                'group_label' => __( 'User' ),
     2839                'item_id'     => "user-{$user->ID}",
     2840                'data'        => $user_data_to_export,
     2841        );
     2842
     2843        return array(
     2844                'data' => $data_to_export,
     2845                'done' => true,
     2846        );
     2847}
     2848
     2849/**
    27512850 * Update log when privacy request is confirmed.
    27522851 *
  • branches/4.9/tests/phpunit/tests/user.php

    r41624 r43117  
    2828                        'user_email' => 'blackburn@battlefield3.com',
    2929                        'user_url' => 'http://tacos.com',
    30                         'role' => 'contributor'
     30                        'role' => 'contributor',
     31                        'nickname' => 'Johnny',
     32                        'description' => 'I am a WordPress user that cares about privacy.',
    3133                ) );
    3234
    … …  
    14501452                $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, 'Email subject does contains HTML entities' );
    14511453        }
     1454
     1455        /**
     1456         * Testing the `wp_user_personal_data_exporter_no_user` function when no user exists.
     1457         *
     1458         * @ticket 43547
     1459         */
     1460        function test_wp_user_personal_data_exporter_no_user() {
     1461                $actual = wp_user_personal_data_exporter( 'not-a-user-email@test.com' );
     1462
     1463                $expected = array(
     1464                        'data' => array(),
     1465                        'done' => true,
     1466                );
     1467
     1468                $this->assertSame( $expected, $actual );
     1469        }
     1470
     1471        /**
     1472         * Testing the `wp_user_personal_data_exporter_no_user` function when the requested
     1473         * user exists.
     1474         *
     1475         * @ticket 43547
     1476         */
     1477        function test_wp_user_personal_data_exporter() {
     1478                $test_user = new WP_User( self::$contrib_id );
     1479
     1480                $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1481
     1482                $this->assertTrue( $actual['done'] );
     1483
     1484                // Number of exported users.
     1485                $this->assertSame( 1, count( $actual['data'] ) );
     1486
     1487                // Number of exported user properties.
     1488                $this->assertSame( 11, count( $actual['data'][0]['data'] ) );
     1489        }
    14521490}
Note: See TracChangeset for help on using the changeset viewer.