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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47236 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-02-10 05:30:03 +00:00
parent d321144c67
commit 8fef1b28a9
2 changed files with 106 additions and 4 deletions

View File

@ -2959,7 +2959,7 @@ function wp_user_personal_data_exporter( $email_address ) {
$user_meta = get_user_meta( $user->ID );
$user_prop_to_export = array(
$user_props_to_export = array(
'ID' => __( 'User ID' ),
'user_login' => __( 'User Login Name' ),
'user_nicename' => __( 'User Nice Name' ),
@ -2975,7 +2975,7 @@ function wp_user_personal_data_exporter( $email_address ) {
$user_data_to_export = array();
foreach ( $user_prop_to_export as $key => $name ) {
foreach ( $user_props_to_export as $key => $name ) {
$value = '';
switch ( $key ) {
@ -3012,6 +3012,42 @@ function wp_user_personal_data_exporter( $email_address ) {
'data' => $user_data_to_export,
);
/**
* Introduce any Community Events Location data that is available.
*
* @since 5.4.0
*/
if ( isset( $user_meta['community-events-location'] ) ) {
$location = maybe_unserialize( $user_meta['community-events-location'][0] );
$location_props_to_export = array(
'description' => __( 'City' ),
'country' => __( 'Country' ),
'latitude' => __( 'Latitude' ),
'longitude' => __( 'Longitude' ),
'ip' => __( 'IP' ),
);
$location_data_to_export = array();
foreach ( $location_props_to_export as $key => $name ) {
if ( ! empty( $location[ $key ] ) ) {
$location_data_to_export[] = array(
'name' => $name,
'value' => $location[ $key ],
);
}
}
$data_to_export[] = array(
'group_id' => 'community-events-location',
'group_label' => __( 'Community Events Location' ),
'group_description' => __( 'User’s location data used for the Community Events in the WordPress Events and News dashboard widget.' ),
'item_id' => "community-events-location-{$user->ID}",
'data' => $location_data_to_export,
);
}
return array(
'data' => $data_to_export,
'done' => true,

View File

@ -1651,7 +1651,7 @@ class Tests_User extends WP_UnitTestCase {
}
/**
* Testing the `wp_user_personal_data_exporter_no_user` function when no user exists.
* Testing the `wp_user_personal_data_exporter()` function when no user exists.
*
* @ticket 43547
*/
@ -1667,7 +1667,7 @@ class Tests_User extends WP_UnitTestCase {
}
/**
* Testing the `wp_user_personal_data_exporter_no_user` function when the requested
* Testing the `wp_user_personal_data_exporter()` function when the requested
* user exists.
*
* @ticket 43547
@ -1685,4 +1685,70 @@ class Tests_User extends WP_UnitTestCase {
// Number of exported user properties.
$this->assertSame( 11, count( $actual['data'][0]['data'] ) );
}
/**
* Testing the `wp_user_personal_data_exporter()` function
* with Community Events Location IP data.
*
* @ticket 43921
*/
function test_wp_community_events_location_ip_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$location_data = array( 'ip' => '0.0.0.0' );
update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
$actual = wp_user_personal_data_exporter( $test_user->user_email );
$this->assertTrue( $actual['done'] );
// Contains 'Community Events Location'.
$this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
// Contains location IP.
$this->assertEquals( 'IP', $actual['data'][1]['data'][0]['name'] );
$this->assertEquals( '0.0.0.0', $actual['data'][1]['data'][0]['value'] );
}
/**
* Testing the `wp_user_personal_data_exporter()` function
* with Community Events Location city data.
*
* @ticket 43921
*/
function test_wp_community_events_location_city_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$location_data = array(
'description' => 'Cincinnati',
'country' => 'US',
'latitude' => '39.1271100',
'longitude' => '-84.5143900',
);
update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
$actual = wp_user_personal_data_exporter( $test_user->user_email );
$this->assertTrue( $actual['done'] );
// Contains 'Community Events Location'.
$this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
// Contains location city.
$this->assertEquals( 'City', $actual['data'][1]['data'][0]['name'] );
$this->assertEquals( 'Cincinnati', $actual['data'][1]['data'][0]['value'] );
// Contains location country.
$this->assertEquals( 'Country', $actual['data'][1]['data'][1]['name'] );
$this->assertEquals( 'US', $actual['data'][1]['data'][1]['value'] );
// Contains location latitude.
$this->assertEquals( 'Latitude', $actual['data'][1]['data'][2]['name'] );
$this->assertEquals( '39.1271100', $actual['data'][1]['data'][2]['value'] );
// Contains location longitude.
$this->assertEquals( 'Longitude', $actual['data'][1]['data'][3]['name'] );
$this->assertEquals( '-84.5143900', $actual['data'][1]['data'][3]['value'] );
}
}