Ticket #47509: 47509.3.diff
File 47509.3.diff, 3.8 KB (added by , 5 years ago) |
---|
-
src/wp-includes/user.php
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index a1478679f6..f84bade569 100644
a b function wp_user_personal_data_exporter( $email_address ) { 3003 3003 } 3004 3004 } 3005 3005 3006 // get the list of reserved names. 3007 $reserved_names = array_values( $user_prop_to_export ); 3008 3009 /** 3010 * Filter to extend the Users personal data for the privacy exporter. 3011 * 3012 * @since 5.4.0 3013 * 3014 * @param array $additional_user_data { 3015 * An array of name-value pairs of additional user data items. Default: the empty array. 3016 * 3017 * @type string $name The user-facing name of an item name-value pair, e.g. 'IP Address'. 3018 * @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'. 3019 * } 3020 * @param WP_User $user The user whose data is being exported. 3021 * @param string[] $reserved_names An array of reserved names. Any item in 3022 * `$additional_user_data` that uses one of these 3023 * for it's `name` will not be included in the export. 3024 */ 3025 $_extra_data = apply_filters( 'wp_privacy_additional_user_data', array(), $user, $reserved_names ); 3026 3027 if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) { 3028 // remove items that use reserved names. 3029 $extra_data = array_filter( 3030 $_extra_data, 3031 function( $item ) use ( $reserved_names ) { 3032 return ! in_array( $item['name'], $reserved_names ); 3033 } 3034 ); 3035 3036 if ( count( $extra_data ) !== count( $_extra_data ) ) { 3037 _doing_it_wrong( 3038 __FUNCTION__, 3039 sprintf( 3040 /* translators: %s: wp_privacy_additional_user_data */ 3041 __( 'Filter %s returned items with reserved names.' ), 3042 '<code>wp_privacy_additional_user_data</code>' 3043 ), 3044 '5.4.0' 3045 ); 3046 } 3047 3048 if ( ! empty( $extra_data ) ) { 3049 $user_data_to_export = array_merge( $user_data_to_export, $extra_data ); 3050 } 3051 } 3052 3006 3053 $data_to_export[] = array( 3007 3054 'group_id' => 'user', 3008 3055 'group_label' => __( 'User' ), 3009 'group_description' => __( 'User’s profiledata.' ),3056 'group_description' => __( 'User’s meta data.' ), 3010 3057 'item_id' => "user-{$user->ID}", 3011 3058 'data' => $user_data_to_export, 3012 3059 ); -
tests/phpunit/tests/user.php
diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 74c533b69d..9c1c3671b9 100644
a b class Tests_User extends WP_UnitTestCase { 1671 1671 // Number of exported user properties. 1672 1672 $this->assertSame( 11, count( $actual['data'][0]['data'] ) ); 1673 1673 } 1674 1675 1676 /** 1677 * Testing the `wp_user_personal_data_exporter_no_user` function when no user exists. 1678 * 1679 * @since 5.4.0 1680 * 1681 * @ticket 47509 1682 */ 1683 function test_filter_wp_privacy_additional_user_data() { 1684 $test_user = new WP_User( self::$contrib_id ); 1685 1686 add_filter( 'wp_privacy_additional_user_data', array( $this, 'export_additional_user_data' ) ); 1687 1688 $array = wp_user_personal_data_exporter( $test_user->user_email ); 1689 1690 remove_filter( 'wp_privacy_additional_user_data', array( $this, 'export_additional_user_data' ) ); 1691 1692 $num = 0; 1693 1694 foreach ( $array['data'][0]['data'] as $data ) { 1695 foreach ( $data as $key => $value ) { 1696 if ( 'Test Additional Data Name' === $value ) { 1697 $num++; 1698 } 1699 1700 if ( 'Test Additional Data Value' === $value ) { 1701 $num++; 1702 } 1703 } 1704 } 1705 1706 $this->assertSame( 2, $num ); 1707 } 1708 1709 /** 1710 * Filter callback to add additional data to the User Group on Export Requests. 1711 * 1712 * @since 5.4.0 1713 * 1714 * @ticket 47509 1715 * 1716 * @return array $additional_data The additional User data. 1717 */ 1718 public function export_additional_user_data() { 1719 $additional_data = array( 1720 array( 1721 'name' => 'Test Additional Data Name', 1722 'value' => 'Test Additional Data Value', 1723 ), 1724 ); 1725 1726 return $additional_data; 1727 } 1674 1728 }