Changeset 43055
- Timestamp:
- 05/01/2018 01:58:02 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r43054 r43055 353 353 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' ); 354 354 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' ); 355 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_user_personal_data_exporter' ); 355 356 add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' ); 356 357 add_action( 'init', 'wp_schedule_delete_old_privacy_export_files' ); -
trunk/src/wp-includes/user.php
r43014 r43055 2827 2827 2828 2828 /** 2829 * Registers the personal data exporter for users. 2830 * 2831 * @since 4.9.6 2832 * 2833 * @param array $exporters An array of personal data exporters. 2834 * @return array An array of personal data exporters. 2835 */ 2836 function wp_register_user_personal_data_exporter( $exporters ) { 2837 $exporters[] = array( 2838 'exporter_friendly_name' => __( 'WordPress User' ), 2839 'callback' => 'wp_user_personal_data_exporter', 2840 ); 2841 2842 return $exporters; 2843 } 2844 2845 /** 2846 * Finds and exports personal data associated with an email address from the user and user_meta table. 2847 * 2848 * @since 4.9.6 2849 * 2850 * @param string $email_address The users email address. 2851 * @return array An array of personal data. 2852 */ 2853 function wp_user_personal_data_exporter( $email_address ) { 2854 $email_address = trim( $email_address ); 2855 2856 $data_to_export = array(); 2857 2858 $user = get_user_by( 'email', $email_address ); 2859 2860 if ( ! $user ) { 2861 return array( 2862 'data' => array(), 2863 'done' => true, 2864 ); 2865 } 2866 2867 $user_meta = get_user_meta( $user->ID ); 2868 2869 $user_prop_to_export = array( 2870 'ID' => __( 'User ID' ), 2871 'user_login' => __( 'User Login Name' ), 2872 'user_nicename' => __( 'User Nice Name' ), 2873 'user_email' => __( 'User Email' ), 2874 'user_url' => __( 'User URL' ), 2875 'user_registered' => __( 'User Registration Date' ), 2876 'display_name' => __( 'User Display Name' ), 2877 'nickname' => __( 'User Nickname' ), 2878 'first_name' => __( 'User First Name' ), 2879 'last_name' => __( 'User Last Name' ), 2880 'description' => __( 'User Description' ), 2881 ); 2882 2883 $user_data_to_export = array(); 2884 2885 foreach ( $user_prop_to_export as $key => $name ) { 2886 $value = ''; 2887 2888 switch ( $key ) { 2889 case 'ID': 2890 case 'user_login': 2891 case 'user_nicename': 2892 case 'user_email': 2893 case 'user_url': 2894 case 'user_registered': 2895 case 'display_name': 2896 $value = $user->data->$key; 2897 break; 2898 case 'nickname': 2899 case 'first_name': 2900 case 'last_name': 2901 case 'description': 2902 $value = $user_meta[ $key ][0]; 2903 break; 2904 } 2905 2906 if ( ! empty( $value ) ) { 2907 $user_data_to_export[] = array( 2908 'name' => $name, 2909 'value' => $value, 2910 ); 2911 } 2912 } 2913 2914 $data_to_export[] = array( 2915 'group_id' => 'user', 2916 'group_label' => __( 'User' ), 2917 'item_id' => "user-{$user->ID}", 2918 'data' => $user_data_to_export, 2919 ); 2920 2921 return array( 2922 'data' => $data_to_export, 2923 'done' => true, 2924 ); 2925 } 2926 2927 /** 2829 2928 * Update log when privacy request is confirmed. 2830 2929 * -
trunk/tests/phpunit/tests/user.php
r42855 r43055 30 30 'user_url' => 'http://tacos.com', 31 31 'role' => 'contributor', 32 'nickname' => 'Johnny', 33 'description' => 'I am a WordPress user that cares about privacy.', 32 34 ) 33 35 ); … … 1581 1583 $this->assertSame( array( 'administrator' ), get_userdata( $editor )->roles ); 1582 1584 } 1585 1586 /** 1587 * Testing the `wp_user_personal_data_exporter_no_user` function when no user exists. 1588 * 1589 * @ticket 43547 1590 */ 1591 function test_wp_user_personal_data_exporter_no_user() { 1592 $actual = wp_user_personal_data_exporter( 'not-a-user-email@test.com' ); 1593 1594 $expected = array( 1595 'data' => array(), 1596 'done' => true, 1597 ); 1598 1599 $this->assertSame( $expected, $actual ); 1600 } 1601 1602 /** 1603 * Testing the `wp_user_personal_data_exporter_no_user` function when the requested 1604 * user exists. 1605 * 1606 * @ticket 43547 1607 */ 1608 function test_wp_user_personal_data_exporter() { 1609 $test_user = new WP_User( self::$contrib_id ); 1610 1611 $actual = wp_user_personal_data_exporter( $test_user->user_email ); 1612 1613 $this->assertTrue( $actual['done'] ); 1614 1615 // Number of exported users. 1616 $this->assertSame( 1, count( $actual['data'] ) ); 1617 1618 // Number of exported user properties. 1619 $this->assertSame( 12, count( $actual['data'][0]['data'] ) ); 1620 } 1583 1621 }
Note: See TracChangeset
for help on using the changeset viewer.