| 3099 | } |
| 3100 | |
| 3101 | /** |
| 3102 | * Registers the personal data exporter for users. |
| 3103 | * |
| 3104 | * @param array $exporters An array of personal data exporters. |
| 3105 | * @return array An array of personal data exporters. |
| 3106 | */ |
| 3107 | function wp_register_user_personal_data_exporter( $exporters ) { |
| 3108 | $exporters[] = array( |
| 3109 | 'exporter_friendly_name' => __( 'WordPress User' ), |
| 3110 | 'callback' => 'wp_user_personal_data_exporter', |
| 3111 | ); |
| 3112 | |
| 3113 | return $exporters; |
| 3114 | } |
| 3115 | |
| 3116 | /** |
| 3117 | * Finds and exports personal data associated with an email address from the user and user_meta table. |
| 3118 | * |
| 3119 | * @param string $email_address The users email address. |
| 3120 | * @param int $page |
| 3121 | * @return array An array of personal data. |
| 3122 | */ |
| 3123 | function wp_user_personal_data_exporter( $email_address, $page = 1 ) { |
| 3124 | $email_address = trim( strtolower( $email_address ) ); |
| 3125 | |
| 3126 | $data_to_export = array(); |
| 3127 | |
| 3128 | $user = get_user_by( 'email', $email_address ); |
| 3129 | $user_meta = get_user_meta( $user->ID ); |
| 3130 | |
| 3131 | $user_prop_to_export = array( |
| 3132 | 'ID' => __( 'User ID' ), |
| 3133 | 'user_login' => __( 'User Login Name' ), |
| 3134 | // 'user_pass' => __( 'User Password (hashed)'), |
| 3135 | 'user_nicename' => __( 'User Nice Name' ), |
| 3136 | 'user_email' => __( 'User Email' ), |
| 3137 | 'user_url' => __( 'User URL' ), |
| 3138 | 'user_registered' => __( 'User Registered At'), |
| 3139 | 'user_status' => __( 'User Status'), |
| 3140 | 'display_name' => __( 'User Display Name'), |
| 3141 | 'nickname' => __( 'User Nickname' ), |
| 3142 | 'first_name' => __( 'User First Name' ), |
| 3143 | 'last_name' => __( 'User Last Name' ), |
| 3144 | 'description' => __( 'User Description' ), |
| 3145 | ); |
| 3146 | |
| 3147 | $user_data_to_export = array(); |
| 3148 | |
| 3149 | foreach ( $user_prop_to_export as $key => $name ) { |
| 3150 | $value = ''; |
| 3151 | |
| 3152 | switch ( $key ) { |
| 3153 | case 'ID': |
| 3154 | case 'user_login': |
| 3155 | // case 'user_pass': |
| 3156 | case 'user_nicename': |
| 3157 | case 'user_email': |
| 3158 | case 'user_url': |
| 3159 | case 'user_registered': |
| 3160 | case 'display_name': |
| 3161 | $value = $user->data->$key; |
| 3162 | break; |
| 3163 | case 'user_status': |
| 3164 | if ($user->data->user_status == '0') { |
| 3165 | $value = __( 'Active' ); |
| 3166 | } elseif ($user->data->user_status = '1' ) { |
| 3167 | $value = __( 'Inactive' ); |
| 3168 | } else { |
| 3169 | $value = $user->data->user_status; |
| 3170 | } |
| 3171 | break; |
| 3172 | //case '' |
| 3173 | case 'nickname': |
| 3174 | case 'first_name': |
| 3175 | case 'last_name': |
| 3176 | case 'description': |
| 3177 | $value = $user_meta[ $key ][0]; |
| 3178 | } |
| 3179 | |
| 3180 | if ( ! empty( $value ) ) { |
| 3181 | $user_data_to_export[] = array( 'name' => $name, 'value' => $value); |
| 3182 | } |
| 3183 | |
| 3184 | } |
| 3185 | |
| 3186 | $data_to_export[] = array( |
| 3187 | 'group_id' => 'user', |
| 3188 | 'group_label' => __( 'User' ), |
| 3189 | 'item_id' => "user-{$user->ID}", |
| 3190 | 'data' => $user_data_to_export, |
| 3191 | ); |
| 3192 | |
| 3193 | $done = true; |
| 3194 | |
| 3195 | return array( |
| 3196 | 'data' => $data_to_export, |
| 3197 | 'done' => $done, |
| 3198 | ); |