| 1 |
<?php |
| 2 |
/** |
| 3 |
* Personal data exporters. |
| 4 |
*/ |
| 5 |
|
| 6 |
defined( 'ABSPATH' ) || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* UsersWP_Privacy_Exporters Class. |
| 10 |
*/ |
| 11 |
class UsersWP_Privacy_Exporters { |
| 12 |
/** |
| 13 |
* Finds and exports user data by email address. |
| 14 |
* |
| 15 |
* @since 1.0.14 |
| 16 |
* @param string $email_address The user email address. |
| 17 |
* @param int $page Page. |
| 18 |
* @return array An array of user data in name value pairs |
| 19 |
*/ |
| 20 |
public static function user_data_exporter( $email_address, $page ) { |
| 21 |
$user = get_user_by( 'email', $email_address ); |
| 22 |
$data_to_export = array(); |
| 23 |
|
| 24 |
if ( $user instanceof WP_User ) { |
| 25 |
$data_to_export[] = array( |
| 26 |
'group_id' => 'uwp_user', |
| 27 |
'group_label' => __( 'UsersWP user data', 'userswp' ), |
| 28 |
'group_description' => __( 'The UsersWP user data', 'userswp' ), |
| 29 |
'item_id' => 'user', |
| 30 |
'data' => self::get_user_meta_data( $user ), |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
return array( |
| 35 |
'data' => $data_to_export, |
| 36 |
'done' => true, |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Get personal data (key/value pairs) for a user object. |
| 42 |
* |
| 43 |
* @since 1.0.14 |
| 44 |
* @param WP_User $user user object. |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
protected static function get_user_meta_data( $user ) { |
| 48 |
$metadata = uwp_get_usermeta_row($user->ID); |
| 49 |
|
| 50 |
$personal_data = array(); |
| 51 |
$skip_keys = array('user_id', 'user_privacy', 'tabs_privacy'); |
| 52 |
$skip_keys = apply_filters('uwp_privacy_export_skip_user_data_columns', $skip_keys, $user); |
| 53 |
|
| 54 |
if($metadata) { |
| 55 |
foreach ($metadata as $key => $value) { |
| 56 |
if (!empty($value) && !in_array($key, $skip_keys)) { |
| 57 |
|
| 58 |
if(in_array($key, array('avatar_thumb', 'banner_thumb'))){ |
| 59 |
$uploads = wp_upload_dir(); |
| 60 |
$upload_url = $uploads['baseurl']; |
| 61 |
$value = $upload_url.$value; |
| 62 |
} |
| 63 |
|
| 64 |
$key = self::get_formatted_column_name($key); |
| 65 |
|
| 66 |
$personal_data[] = array( |
| 67 |
'name' => $key, |
| 68 |
'value' => $value, |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Allow extensions to register their own personal data for this user for the export. |
| 76 |
* |
| 77 |
* @since 1.0.14 |
| 78 |
* @param array $personal_data Array of name value pairs. |
| 79 |
* @param WP_User $user user object. |
| 80 |
*/ |
| 81 |
$personal_data = apply_filters( 'uwp_privacy_export_user_personal_data', $personal_data, $user ); |
| 82 |
|
| 83 |
return $personal_data; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Get formatted table column name. |
| 89 |
* |
| 90 |
* @since 1.0.14 |
| 91 |
* @param string $string string to replace. |
| 92 |
* @param array $arrays array of keys to match. |
| 93 |
* @return string |
| 94 |
*/ |
| 95 |
public static function get_formatted_column_name($string, $arrays = array('uwp_account_', 'uwp_', '_')){ |
| 96 |
|
| 97 |
$temp_string = $string; |
| 98 |
|
| 99 |
if( !empty($arrays) && count($arrays) > 0 ) { |
| 100 |
|
| 101 |
foreach ( $arrays as $replace_val) { |
| 102 |
$temp_string = str_replace($replace_val," ",$temp_string); |
| 103 |
} |
| 104 |
|
| 105 |
$temp_string = trim($temp_string); |
| 106 |
$temp_string = ucfirst($temp_string); |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
return $temp_string; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|