Make WordPress Core


Ignore:
Timestamp:
02/11/2020 06:57:51 PM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r47245 r47270  
    30073007        }
    30083008
     3009        // Get the list of reserved names.
     3010        $reserved_names = array_values( $user_props_to_export );
     3011
     3012        /**
     3013         * Filter to extend the Users profile data for the privacy exporter.
     3014         *
     3015         * @since 5.4.0
     3016         *
     3017         * @param array    $additional_user_profile_data {
     3018         *     An array of name-value pairs of additional user data items. Default empty array.
     3019         *
     3020         *     @type string $name  The user-facing name of an item name-value pair,e.g. 'IP Address'.
     3021         *     @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'.
     3022         * }
     3023         * @param WP_User  $user           The user whose data is being exported.
     3024         * @param string[] $reserved_names An array of reserved names. Any item in `$additional_user_data`
     3025         *                                 that uses one of these for its `name` will not be included in the export.
     3026         */
     3027        $_extra_data = apply_filters( 'wp_privacy_additional_user_profile_data', array(), $user, $reserved_names );
     3028
     3029        if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) {
     3030                // Remove items that use reserved names.
     3031                $extra_data = array_filter(
     3032                        $_extra_data,
     3033                        function( $item ) use ( $reserved_names ) {
     3034                                return ! in_array( $item['name'], $reserved_names );
     3035                        }
     3036                );
     3037
     3038                if ( count( $extra_data ) !== count( $_extra_data ) ) {
     3039                        _doing_it_wrong(
     3040                                __FUNCTION__,
     3041                                sprintf(
     3042                                        /* translators: %s: wp_privacy_additional_user_profile_data */
     3043                                        __( 'Filter %s returned items with reserved names.' ),
     3044                                        '<code>wp_privacy_additional_user_profile_data</code>'
     3045                                ),
     3046                                '5.4.0'
     3047                        );
     3048                }
     3049
     3050                if ( ! empty( $extra_data ) ) {
     3051                        $user_data_to_export = array_merge( $user_data_to_export, $extra_data );
     3052                }
     3053        }
     3054
    30093055        $data_to_export[] = array(
    30103056                'group_id'          => 'user',
Note: See TracChangeset for help on using the changeset viewer.