wp_user_personal_data_exporter() – Finds and exports personal data associated with an email address from the user and user_meta table.

You appear to be a bot. Output may be restricted

Description

Finds and exports personal data associated with an email address from the user and user_meta table.

Usage

$array = wp_user_personal_data_exporter( $email_address );

Parameters

$email_address
( string ) required – The user's email address.

Returns

array An array of personal data.

Source

File name: wordpress/wp-includes/user.php


Lines:

1 to 100 of 190
function wp_user_personal_data_exporter( $email_address ) {
  $email_address = trim( $email_address );

  $data_to_export = array();

  $user = get_user_by( 'email', $email_address );

  if ( ! $user ) {
    return array(
      'data' => array(),
      'done' => true,
    );
  }

  $user_meta = get_user_meta( $user->ID );

  $user_props_to_export = array(
    'ID'              => __( 'User ID' ),
    'user_login'      => __( 'User Login Name' ),
    'user_nicename'   => __( 'User Nice Name' ),
    'user_email'      => __( 'User Email' ),
    'user_url'        => __( 'User URL' ),
    'user_registered' => __( 'User Registration Date' ),
    'display_name'    => __( 'User Display Name' ),
    'nickname'        => __( 'User Nickname' ),
    'first_name'      => __( 'User First Name' ),
    'last_name'       => __( 'User Last Name' ),
    'description'     => __( 'User Description' ),
  );

  $user_data_to_export = array();

  foreach ( $user_props_to_export as $key => $name ) {
    $value = '';

    switch ( $key ) {
      case 'ID':
      case 'user_login':
      case 'user_nicename':
      case 'user_email':
      case 'user_url':
      case 'user_registered':
      case 'display_name':
        $value = $user->data->$key;
        break;
      case 'nickname':
      case 'first_name':
      case 'last_name':
      case 'description':
        $value = $user_meta[ $key ][0];
        break;
    }

    if ( ! empty( $value ) ) {
      $user_data_to_export[] = array(
        'name'  => $name,
        'value' => $value,
      );
    }
  }

  // Get the list of reserved names.
  $reserved_names = array_values( $user_props_to_export );

  
/**
 * Filters the user's profile data for the privacy exporter.
 *
 * @since 5.4.0
 *
 * @param array    $additional_user_profile_data {
 *     An array of name-value pairs of additional user data items. Default empty array.
 *
 *     @type string $name  The user-facing name of an item name-value pair,e.g. 'IP Address'.
 *     @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'.
 * }
 * @param WP_User  $user           The user whose data is being exported.
 * @param string[] $reserved_names An array of reserved names. Any item in `$additional_user_data`
 *                                 that uses one of these for its `name` will not be included in the export.
 */
  $_extra_data = apply_filters( 'wp_privacy_additional_user_profile_data', array(), $user, $reserved_names );

  if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) {
    // Remove items that use reserved names.
    $extra_data = array_filter(
      $_extra_data,
      static function( $item ) use ( $reserved_names ) {
        return ! in_array( $item['name'], $reserved_names, true );
      }
    );

    if ( count( $extra_data ) !== count( $_extra_data ) ) {
      _doing_it_wrong(
        wp_user_personal_data_exporter,
        sprintf(
          /* translators: %s: wp_privacy_additional_user_profile_data */
          __( 'Filter %s returned items with reserved names.' ),
          '<code>wp_privacy_additional_user_profile_data</code>'
        ),
        '5.4.0'

 View on GitHub View on Trac