Make WordPress Core


Ignore:
Timestamp:
05/09/2018 01:01:12 AM (7 years ago)
Author:
iandunn
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.
Fixes #43922.

File:
1 edited

Legend:

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

    r43183 r43185  
    919919
    920920/**
     921 * Mark erasure requests as completed after processing is finished.
     922 *
     923 * This intercepts the Ajax responses to personal data eraser page requests, and
     924 * monitors the status of a request. Once all of the processing has finished, the
     925 * request is marked as completed.
     926 *
     927 * @since 4.9.6
     928 *
     929 * @see wp_privacy_personal_data_erasure_page
     930 *
     931 * @param array  $response      The response from the personal data eraser for
     932 *                              the given page.
     933 * @param int    $eraser_index  The index of the personal data eraser. Begins
     934 *                              at 1.
     935 * @param string $email_address The email address of the user whose personal
     936 *                              data this is.
     937 * @param int    $page          The page of personal data for this eraser.
     938 *                              Begins at 1.
     939 * @param int    $request_id    The request ID for this personal data erasure.
     940 * @return array The filtered response.
     941 */
     942function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) {
     943    /*
     944     * If the eraser response is malformed, don't attempt to consume it; let it
     945     * pass through, so that the default Ajax processing will generate a warning
     946     * to the user.
     947     */
     948    if ( ! is_array( $response ) ) {
     949        return $response;
     950    }
     951
     952    if ( ! array_key_exists( 'done', $response ) ) {
     953        return $response;
     954    }
     955
     956    if ( ! array_key_exists( 'items_removed', $response ) ) {
     957        return $response;
     958    }
     959
     960    if ( ! array_key_exists( 'items_retained', $response ) ) {
     961        return $response;
     962    }
     963
     964    if ( ! array_key_exists( 'messages', $response ) ) {
     965        return $response;
     966    }
     967
     968    $request = wp_get_user_request_data( $request_id );
     969
     970    if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
     971        wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) );
     972    }
     973
     974    /** This filter is documented in wp-admin/includes/ajax-actions.php */
     975    $erasers        = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     976    $is_last_eraser = count( $erasers ) === $eraser_index;
     977    $eraser_done    = $response['done'];
     978
     979    if ( ! $is_last_eraser || ! $eraser_done ) {
     980        return $response;
     981    }
     982
     983    _wp_privacy_completed_request( $request_id );
     984
     985    return $response;
     986}
     987
     988/**
    921989 * Add requests pages.
    922990 *
Note: See TracChangeset for help on using the changeset viewer.