Privacy: Store plugin callbacks in associative array for flexibility.
The personal data export and erasure tools allow plugins to register their own callbacks, in order to add additional data to the export and erasure processes. Previously, these were registered without specifying a constant identifier in the array of callbacks. Using mutable integers makes it difficult for plugins to modify the callbacks of other plugins, though. Using associative array keys instead provides a covenient and reliable way to identify and interact with another plugin's callbacks. Props desrosj, allendav, ocean90. Fixes #43931. Built from https://develop.svn.wordpress.org/trunk@43154 git-svn-id: http://core.svn.wordpress.org/trunk@42983 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
58b2e6e143
commit
3d4c461e50
|
@ -133,7 +133,7 @@ add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
|
||||||
add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
|
add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
|
||||||
|
|
||||||
// Privacy hooks
|
// Privacy hooks
|
||||||
add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 6 );
|
add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
|
||||||
add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
|
add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
|
||||||
|
|
||||||
// Privacy policy text changes check.
|
// Privacy policy text changes check.
|
||||||
|
|
|
@ -4409,24 +4409,24 @@ function wp_ajax_wp_privacy_export_personal_data() {
|
||||||
wp_send_json_error( __( 'Exporter index out of range.' ) );
|
wp_send_json_error( __( 'Exporter index out of range.' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = $exporter_index - 1;
|
|
||||||
|
|
||||||
if ( $page < 1 ) {
|
if ( $page < 1 ) {
|
||||||
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
|
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$exporter = $exporters[ $index ];
|
$exporter_keys = array_keys( $exporters );
|
||||||
|
$exporter_key = $exporter_keys[ $exporter_index - 1 ];
|
||||||
|
$exporter = $exporters[ $exporter_key ];
|
||||||
|
|
||||||
if ( ! is_array( $exporter ) ) {
|
if ( ! is_array( $exporter ) ) {
|
||||||
wp_send_json_error(
|
wp_send_json_error(
|
||||||
/* translators: %d: array index */
|
/* translators: %s: array index */
|
||||||
sprintf( __( 'Expected an array describing the exporter at index %d.' ), $exporter_index )
|
sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
|
if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
|
||||||
wp_send_json_error(
|
wp_send_json_error(
|
||||||
/* translators: %d: array index */
|
/* translators: %s: array index */
|
||||||
sprintf( __( 'Exporter array at index %d does not include a friendly name.' ), $exporter_index )
|
sprintf( __( 'Exporter array at index %s does not include a friendly name.' ), $exporter_key )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( ! array_key_exists( 'callback', $exporter ) ) {
|
if ( ! array_key_exists( 'callback', $exporter ) ) {
|
||||||
|
@ -4442,8 +4442,8 @@ function wp_ajax_wp_privacy_export_personal_data() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback = $exporters[ $index ]['callback'];
|
$callback = $exporter['callback'];
|
||||||
$exporter_friendly_name = $exporters[ $index ]['exporter_friendly_name'];
|
$exporter_friendly_name = $exporter['exporter_friendly_name'];
|
||||||
|
|
||||||
$response = call_user_func( $callback, $email_address, $page );
|
$response = call_user_func( $callback, $email_address, $page );
|
||||||
if ( is_wp_error( $response ) ) {
|
if ( is_wp_error( $response ) ) {
|
||||||
|
@ -4495,8 +4495,9 @@ function wp_ajax_wp_privacy_export_personal_data() {
|
||||||
* @param int $page The page for this response.
|
* @param int $page The page for this response.
|
||||||
* @param int $request_id The privacy request post ID associated with this request.
|
* @param int $request_id The privacy request post ID associated with this request.
|
||||||
* @param bool $send_as_email Whether the final results of the export should be emailed to the user.
|
* @param bool $send_as_email Whether the final results of the export should be emailed to the user.
|
||||||
|
* @param int $exporter_key The key (slug) of the exporter that provided this data.
|
||||||
*/
|
*/
|
||||||
$response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email );
|
$response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key );
|
||||||
|
|
||||||
if ( is_wp_error( $response ) ) {
|
if ( is_wp_error( $response ) ) {
|
||||||
wp_send_json_error( $response );
|
wp_send_json_error( $response );
|
||||||
|
@ -4591,8 +4592,9 @@ function wp_ajax_wp_privacy_erase_personal_data() {
|
||||||
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
|
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = $eraser_index - 1; // Convert to zero based for eraser index.
|
$eraser_keys = array_keys( $erasers );
|
||||||
$eraser = $erasers[ $index ];
|
$eraser_key = $eraser_keys[ $eraser_index - 1 ];
|
||||||
|
$eraser = $erasers[ $eraser_key ];
|
||||||
|
|
||||||
if ( ! is_array( $eraser ) ) {
|
if ( ! is_array( $eraser ) ) {
|
||||||
/* translators: %d: array index */
|
/* translators: %d: array index */
|
||||||
|
@ -4614,8 +4616,8 @@ function wp_ajax_wp_privacy_erase_personal_data() {
|
||||||
wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) );
|
wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback = $erasers[ $index ]['callback'];
|
$callback = $eraser['callback'];
|
||||||
$eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name'];
|
$eraser_friendly_name = $eraser['eraser_friendly_name'];
|
||||||
|
|
||||||
$response = call_user_func( $callback, $email_address, $page );
|
$response = call_user_func( $callback, $email_address, $page );
|
||||||
|
|
||||||
|
@ -4706,12 +4708,13 @@ function wp_ajax_wp_privacy_erase_personal_data() {
|
||||||
* @since 4.9.6
|
* @since 4.9.6
|
||||||
*
|
*
|
||||||
* @param array $response The personal data for the given exporter and page.
|
* @param array $response The personal data for the given exporter and page.
|
||||||
* @param int $exporter_index The index of the exporter that provided this data.
|
* @param int $eraser_index The index of the eraser that provided this data.
|
||||||
* @param string $email_address The email address associated with this personal data.
|
* @param string $email_address The email address associated with this personal data.
|
||||||
* @param int $page The page for this response.
|
* @param int $page The page for this response.
|
||||||
* @param int $request_id The privacy request post ID associated with this request.
|
* @param int $request_id The privacy request post ID associated with this request.
|
||||||
|
* @param int $eraser_key The key (slug) of the eraser that provided this data.
|
||||||
*/
|
*/
|
||||||
$response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id );
|
$response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id, $eraser_key );
|
||||||
|
|
||||||
if ( is_wp_error( $response ) ) {
|
if ( is_wp_error( $response ) ) {
|
||||||
wp_send_json_error( $response );
|
wp_send_json_error( $response );
|
||||||
|
|
|
@ -2262,9 +2262,10 @@ All at ###SITENAME###
|
||||||
* @param int $page The page of personal data for this exporter. Begins at 1.
|
* @param int $page The page of personal data for this exporter. Begins at 1.
|
||||||
* @param int $request_id The request ID for this personal data export.
|
* @param int $request_id The request ID for this personal data export.
|
||||||
* @param bool $send_as_email Whether the final results of the export should be emailed to the user.
|
* @param bool $send_as_email Whether the final results of the export should be emailed to the user.
|
||||||
|
* @param string $exporter_key The slug (key) of the exporter.
|
||||||
* @return array The filtered response.
|
* @return array The filtered response.
|
||||||
*/
|
*/
|
||||||
function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email ) {
|
function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key ) {
|
||||||
/* Do some simple checks on the shape of the response from the exporter.
|
/* Do some simple checks on the shape of the response from the exporter.
|
||||||
* If the exporter response is malformed, don't attempt to consume it - let it
|
* If the exporter response is malformed, don't attempt to consume it - let it
|
||||||
* pass through to generate a warning to the user by default ajax processing.
|
* pass through to generate a warning to the user by default ajax processing.
|
||||||
|
|
|
@ -3285,7 +3285,7 @@ function wp_handle_comment_submission( $comment_data ) {
|
||||||
* @return array $exporters An array of personal data exporters.
|
* @return array $exporters An array of personal data exporters.
|
||||||
*/
|
*/
|
||||||
function wp_register_comment_personal_data_exporter( $exporters ) {
|
function wp_register_comment_personal_data_exporter( $exporters ) {
|
||||||
$exporters[] = array(
|
$exporters['wordpress-comments'] = array(
|
||||||
'exporter_friendly_name' => __( 'WordPress Comments' ),
|
'exporter_friendly_name' => __( 'WordPress Comments' ),
|
||||||
'callback' => 'wp_comments_personal_data_exporter',
|
'callback' => 'wp_comments_personal_data_exporter',
|
||||||
);
|
);
|
||||||
|
@ -3390,7 +3390,7 @@ function wp_comments_personal_data_exporter( $email_address, $page = 1 ) {
|
||||||
* @return array $erasers An array of personal data erasers.
|
* @return array $erasers An array of personal data erasers.
|
||||||
*/
|
*/
|
||||||
function wp_register_comment_personal_data_eraser( $erasers ) {
|
function wp_register_comment_personal_data_eraser( $erasers ) {
|
||||||
$erasers[] = array(
|
$erasers['wordpress-comments'] = array(
|
||||||
'eraser_friendly_name' => __( 'WordPress Comments' ),
|
'eraser_friendly_name' => __( 'WordPress Comments' ),
|
||||||
'callback' => 'wp_comments_personal_data_eraser',
|
'callback' => 'wp_comments_personal_data_eraser',
|
||||||
);
|
);
|
||||||
|
@ -3498,4 +3498,3 @@ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) {
|
||||||
'done' => $done,
|
'done' => $done,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4102,7 +4102,7 @@ function wpview_media_sandbox_styles() {
|
||||||
* @return array An array of personal data exporters.
|
* @return array An array of personal data exporters.
|
||||||
*/
|
*/
|
||||||
function wp_register_media_personal_data_exporter( $exporters ) {
|
function wp_register_media_personal_data_exporter( $exporters ) {
|
||||||
$exporters[] = array(
|
$exporters['wordpress-media'] = array(
|
||||||
'exporter_friendly_name' => __( 'WordPress Media' ),
|
'exporter_friendly_name' => __( 'WordPress Media' ),
|
||||||
'callback' => 'wp_media_personal_data_exporter',
|
'callback' => 'wp_media_personal_data_exporter',
|
||||||
);
|
);
|
||||||
|
|
|
@ -2834,7 +2834,7 @@ function _wp_privacy_action_request_types() {
|
||||||
* @return array An array of personal data exporters.
|
* @return array An array of personal data exporters.
|
||||||
*/
|
*/
|
||||||
function wp_register_user_personal_data_exporter( $exporters ) {
|
function wp_register_user_personal_data_exporter( $exporters ) {
|
||||||
$exporters[] = array(
|
$exporters['wordpress-user'] = array(
|
||||||
'exporter_friendly_name' => __( 'WordPress User' ),
|
'exporter_friendly_name' => __( 'WordPress User' ),
|
||||||
'callback' => 'wp_user_personal_data_exporter',
|
'callback' => 'wp_user_personal_data_exporter',
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.0-alpha-43150';
|
$wp_version = '5.0-alpha-43154';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue