| 3188 | |
| 3189 | /** |
| 3190 | * Registers the personal data exporter for users. |
| 3191 | * |
| 3192 | * @since 4.9.6 |
| 3193 | * |
| 3194 | * @param array $exporters An array of personal data exporters. |
| 3195 | * @return array An array of personal data exporters. |
| 3196 | */ |
| 3197 | function wp_register_user_personal_data_exporter( $exporters ) { |
| 3198 | $exporters[] = array( |
| 3199 | 'exporter_friendly_name' => __( 'WordPress User' ), |
| 3200 | 'callback' => 'wp_user_personal_data_exporter', |
| 3201 | ); |
| 3202 | |
| 3203 | return $exporters; |
| 3204 | } |
| 3205 | |
| 3206 | /** |
| 3207 | * Finds and exports personal data associated with an email address from the user and user_meta table. |
| 3208 | * |
| 3209 | * @since 4.9.6 |
| 3210 | * |
| 3211 | * @param string $email_address The users email address. |
| 3212 | * @return array An array of personal data. |
| 3213 | */ |
| 3214 | function wp_user_personal_data_exporter( $email_address ) { |
| 3215 | $email_address = trim( $email_address ); |
| 3216 | |
| 3217 | $data_to_export = array(); |
| 3218 | |
| 3219 | $user = get_user_by( 'email', $email_address ); |
| 3220 | |
| 3221 | if ( ! $user ) { |
| 3222 | return array( |
| 3223 | // Is it enough to return an empty array here? |
| 3224 | 'data' => array(), |
| 3225 | 'done' => true, |
| 3226 | ); |
| 3227 | } |
| 3228 | |
| 3229 | $user_meta = get_user_meta( $user->ID ); |
| 3230 | |
| 3231 | $user_prop_to_export = array( |
| 3232 | 'ID' => __( 'User ID' ), |
| 3233 | 'user_login' => __( 'User Login Name' ), |
| 3234 | 'user_nicename' => __( 'User Nice Name' ), |
| 3235 | 'user_email' => __( 'User Email' ), |
| 3236 | 'user_url' => __( 'User URL' ), |
| 3237 | 'user_registered' => __( 'User Registered At'), |
| 3238 | 'user_status' => __( 'User Status'), |
| 3239 | 'display_name' => __( 'User Display Name'), |
| 3240 | 'nickname' => __( 'User Nickname' ), |
| 3241 | 'first_name' => __( 'User First Name' ), |
| 3242 | 'last_name' => __( 'User Last Name' ), |
| 3243 | 'description' => __( 'User Description' ), |
| 3244 | ); |
| 3245 | |
| 3246 | $user_data_to_export = array(); |
| 3247 | |
| 3248 | foreach ( $user_prop_to_export as $key => $name ) { |
| 3249 | $value = ''; |
| 3250 | |
| 3251 | switch ( $key ) { |
| 3252 | case 'ID': |
| 3253 | case 'user_login': |
| 3254 | case 'user_nicename': |
| 3255 | case 'user_email': |
| 3256 | case 'user_url': |
| 3257 | case 'user_registered': |
| 3258 | case 'display_name': |
| 3259 | $value = $user->data->$key; |
| 3260 | break; |
| 3261 | case 'user_status': |
| 3262 | if ( '0' == $user->data->user_status ) { |
| 3263 | $value = __( 'Active' ); |
| 3264 | } elseif ( '1' == $user->data->user_status ) { |
| 3265 | $value = __( 'Inactive' ); |
| 3266 | } else { |
| 3267 | $value = $user->data->user_status; |
| 3268 | } |
| 3269 | break; |
| 3270 | case 'nickname': |
| 3271 | case 'first_name': |
| 3272 | case 'last_name': |
| 3273 | case 'description': |
| 3274 | $value = $user_meta[ $key ][0]; |
| 3275 | } |
| 3276 | |
| 3277 | if ( ! empty( $value ) ) { |
| 3278 | $user_data_to_export[] = array( |
| 3279 | 'name' => $name, |
| 3280 | 'value' => $value, |
| 3281 | ); |
| 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | $data_to_export[] = array( |
| 3286 | 'group_id' => 'user', |
| 3287 | 'group_label' => __( 'User' ), |
| 3288 | 'item_id' => "user-{$user->ID}", |
| 3289 | 'data' => $user_data_to_export, |
| 3290 | ); |
| 3291 | |
| 3292 | return array( |
| 3293 | 'data' => $data_to_export, |
| 3294 | 'done' => true, |
| 3295 | ); |
| 3296 | } |