Make WordPress Core

Changeset 43188 for branches/4.9


Ignore:
Timestamp:
05/09/2018 02:32:41 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Mark erasure requests as completed after processing.

r42986 introduced the beginnings of an Ajax handler for processing requests to erase personal data. At the time, a method for marking requests as completed was planned, but had not yet been created. This commit introduces that mechanism, bringing the erasure process closer to completion.

Props coreymckrill, allendav.
Merges [43185] to the 4.9 branch.
Fixes #43922.

Location:
branches/4.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/admin-filters.php

    r43157 r43188  
    134134
    135135// Privacy hooks
     136add_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 );
    136137add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
    137138add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
  • branches/4.9/src/wp-admin/includes/user.php

    r43187 r43188  
    878878
    879879/**
     880 * Mark erasure requests as completed after processing is finished.
     881 *
     882 * This intercepts the Ajax responses to personal data eraser page requests, and
     883 * monitors the status of a request. Once all of the processing has finished, the
     884 * request is marked as completed.
     885 *
     886 * @since 4.9.6
     887 *
     888 * @see wp_privacy_personal_data_erasure_page
     889 *
     890 * @param array  $response      The response from the personal data eraser for
     891 *                              the given page.
     892 * @param int    $eraser_index  The index of the personal data eraser. Begins
     893 *                              at 1.
     894 * @param string $email_address The email address of the user whose personal
     895 *                              data this is.
     896 * @param int    $page          The page of personal data for this eraser.
     897 *                              Begins at 1.
     898 * @param int    $request_id    The request ID for this personal data erasure.
     899 * @return array The filtered response.
     900 */
     901function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) {
     902    /*
     903     * If the eraser response is malformed, don't attempt to consume it; let it
     904     * pass through, so that the default Ajax processing will generate a warning
     905     * to the user.
     906     */
     907    if ( ! is_array( $response ) ) {
     908        return $response;
     909    }
     910
     911    if ( ! array_key_exists( 'done', $response ) ) {
     912        return $response;
     913    }
     914
     915    if ( ! array_key_exists( 'items_removed', $response ) ) {
     916        return $response;
     917    }
     918
     919    if ( ! array_key_exists( 'items_retained', $response ) ) {
     920        return $response;
     921    }
     922
     923    if ( ! array_key_exists( 'messages', $response ) ) {
     924        return $response;
     925    }
     926
     927    $request = wp_get_user_request_data( $request_id );
     928
     929    if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
     930        wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) );
     931    }
     932
     933    /** This filter is documented in wp-admin/includes/ajax-actions.php */
     934    $erasers        = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     935    $is_last_eraser = count( $erasers ) === $eraser_index;
     936    $eraser_done    = $response['done'];
     937
     938    if ( ! $is_last_eraser || ! $eraser_done ) {
     939        return $response;
     940    }
     941
     942    _wp_privacy_completed_request( $request_id );
     943
     944    return $response;
     945}
     946
     947/**
    880948 * Add requests pages.
    881949 *
Note: See TracChangeset for help on using the changeset viewer.