From 5a29f108e0dc2f5e60aa4fbdaf4e12b99fc57524 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 11 Feb 2020 18:59:05 +0000 Subject: [PATCH] Privacy: Introduce `wp_privacy_additional_user_data` filter to make it easier to include additional user meta in a personal data export. Props pbiron, xkon, garrett-eclipse, azaozz. Fixes #47509. Built from https://develop.svn.wordpress.org/trunk@47270 git-svn-id: http://core.svn.wordpress.org/trunk@47070 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 46 +++++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 4dece3f2e9..5e0d238eeb 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -3006,6 +3006,52 @@ function wp_user_personal_data_exporter( $email_address ) { } } + // Get the list of reserved names. + $reserved_names = array_values( $user_props_to_export ); + + /** + * Filter to extend the Users 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, + function( $item ) use ( $reserved_names ) { + return ! in_array( $item['name'], $reserved_names ); + } + ); + + if ( count( $extra_data ) !== count( $_extra_data ) ) { + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: %s: wp_privacy_additional_user_profile_data */ + __( 'Filter %s returned items with reserved names.' ), + 'wp_privacy_additional_user_profile_data' + ), + '5.4.0' + ); + } + + if ( ! empty( $extra_data ) ) { + $user_data_to_export = array_merge( $user_data_to_export, $extra_data ); + } + } + $data_to_export[] = array( 'group_id' => 'user', 'group_label' => __( 'User' ), diff --git a/wp-includes/version.php b/wp-includes/version.php index 731837d9ae..0170bb3197 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47269'; +$wp_version = '5.4-alpha-47270'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.