Make WordPress Core

Changeset 47236


Ignore:
Timestamp:
02/10/2020 05:30:03 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Include community-events-location user meta value in Personal Data Export.

The value is used by the WordPress Events and News widget to show relevant WP community events.

The location information may include an IP address, location description, and latitude/longitude coordinates.

Props garrett-eclipse, coreymckrill, xkon.
Fixes #43921.

Location:
trunk
Files:
2 edited

Legend:

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

    r47219 r47236  
    29602960    $user_meta = get_user_meta( $user->ID );
    29612961
    2962     $user_prop_to_export = array(
     2962    $user_props_to_export = array(
    29632963        'ID'              => __( 'User ID' ),
    29642964        'user_login'      => __( 'User Login Name' ),
     
    29762976    $user_data_to_export = array();
    29772977
    2978     foreach ( $user_prop_to_export as $key => $name ) {
     2978    foreach ( $user_props_to_export as $key => $name ) {
    29792979        $value = '';
    29802980
     
    30133013    );
    30143014
     3015    /**
     3016     * Introduce any Community Events Location data that is available.
     3017     *
     3018     * @since 5.4.0
     3019     */
     3020    if ( isset( $user_meta['community-events-location'] ) ) {
     3021        $location = maybe_unserialize( $user_meta['community-events-location'][0] );
     3022
     3023        $location_props_to_export = array(
     3024            'description' => __( 'City' ),
     3025            'country'     => __( 'Country' ),
     3026            'latitude'    => __( 'Latitude' ),
     3027            'longitude'   => __( 'Longitude' ),
     3028            'ip'          => __( 'IP' ),
     3029        );
     3030
     3031        $location_data_to_export = array();
     3032
     3033        foreach ( $location_props_to_export as $key => $name ) {
     3034            if ( ! empty( $location[ $key ] ) ) {
     3035                $location_data_to_export[] = array(
     3036                    'name'  => $name,
     3037                    'value' => $location[ $key ],
     3038                );
     3039            }
     3040        }
     3041
     3042        $data_to_export[] = array(
     3043            'group_id'          => 'community-events-location',
     3044            'group_label'       => __( 'Community Events Location' ),
     3045            'group_description' => __( 'User’s location data used for the Community Events in the WordPress Events and News dashboard widget.' ),
     3046            'item_id'           => "community-events-location-{$user->ID}",
     3047            'data'              => $location_data_to_export,
     3048        );
     3049    }
     3050
    30153051    return array(
    30163052        'data' => $data_to_export,
  • trunk/tests/phpunit/tests/user.php

    r47122 r47236  
    16521652
    16531653    /**
    1654      * Testing the `wp_user_personal_data_exporter_no_user` function when no user exists.
     1654     * Testing the `wp_user_personal_data_exporter()` function when no user exists.
    16551655     *
    16561656     * @ticket 43547
     
    16681668
    16691669    /**
    1670      * Testing the `wp_user_personal_data_exporter_no_user` function when the requested
     1670     * Testing the `wp_user_personal_data_exporter()` function when the requested
    16711671     * user exists.
    16721672     *
     
    16861686        $this->assertSame( 11, count( $actual['data'][0]['data'] ) );
    16871687    }
     1688
     1689    /**
     1690     * Testing the `wp_user_personal_data_exporter()` function
     1691     * with Community Events Location IP data.
     1692     *
     1693     * @ticket 43921
     1694     */
     1695    function test_wp_community_events_location_ip_personal_data_exporter() {
     1696        $test_user = new WP_User( self::$contrib_id );
     1697
     1698        $location_data = array( 'ip' => '0.0.0.0' );
     1699        update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
     1700
     1701        $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1702
     1703        $this->assertTrue( $actual['done'] );
     1704
     1705        // Contains 'Community Events Location'.
     1706        $this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
     1707
     1708        // Contains location IP.
     1709        $this->assertEquals( 'IP', $actual['data'][1]['data'][0]['name'] );
     1710        $this->assertEquals( '0.0.0.0', $actual['data'][1]['data'][0]['value'] );
     1711    }
     1712
     1713    /**
     1714     * Testing the `wp_user_personal_data_exporter()` function
     1715     * with Community Events Location city data.
     1716     *
     1717     * @ticket 43921
     1718     */
     1719    function test_wp_community_events_location_city_personal_data_exporter() {
     1720        $test_user = new WP_User( self::$contrib_id );
     1721
     1722        $location_data = array(
     1723            'description' => 'Cincinnati',
     1724            'country'     => 'US',
     1725            'latitude'    => '39.1271100',
     1726            'longitude'   => '-84.5143900',
     1727        );
     1728        update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
     1729
     1730        $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1731
     1732        $this->assertTrue( $actual['done'] );
     1733
     1734        // Contains 'Community Events Location'.
     1735        $this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
     1736
     1737        // Contains location city.
     1738        $this->assertEquals( 'City', $actual['data'][1]['data'][0]['name'] );
     1739        $this->assertEquals( 'Cincinnati', $actual['data'][1]['data'][0]['value'] );
     1740
     1741        // Contains location country.
     1742        $this->assertEquals( 'Country', $actual['data'][1]['data'][1]['name'] );
     1743        $this->assertEquals( 'US', $actual['data'][1]['data'][1]['value'] );
     1744
     1745        // Contains location latitude.
     1746        $this->assertEquals( 'Latitude', $actual['data'][1]['data'][2]['name'] );
     1747        $this->assertEquals( '39.1271100', $actual['data'][1]['data'][2]['value'] );
     1748
     1749        // Contains location longitude.
     1750        $this->assertEquals( 'Longitude', $actual['data'][1]['data'][3]['name'] );
     1751        $this->assertEquals( '-84.5143900', $actual['data'][1]['data'][3]['value'] );
     1752
     1753    }
    16881754}
Note: See TracChangeset for help on using the changeset viewer.