WordPress.org

Make WordPress Core

Ticket #43922: 43922.diff

File 43922.diff, 3.0 KB (added by coreymckrill, 3 years ago)

Process confirmation of completed data erasure. Note that this patch depends on the patch in #43913 to work correctly.

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

     
    133133add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
    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, 6 );
    137138add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
    138139
  • src/wp-admin/includes/user.php

     
    917917}
    918918
    919919/**
     920 * Intercept personal data eraser page ajax responses in order to determine if the request is complete yet.
     921 * @see wp_privacy_personal_data_erasure_page
     922 * @since 4.9.6
     923 *
     924 * @param array $response The response from the personal data eraser for the given page.
     925 * @param int $eraser_index The index of the personal data eraser. Begins at 1.
     926 * @param string $email_address The email address of the user whose personal data this is.
     927 * @param int $page The page of personal data for this eraser. Begins at 1.
     928 * @param int $request_id The request ID for this personal data erasure.
     929 * @return array The filtered response.
     930 */
     931function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) {
     932        /* Do some simple checks on the shape of the response from the eraser.
     933         * If the eraser response is malformed, don't attempt to consume it - let it
     934         * pass through to generate a warning to the user by default ajax processing.
     935         */
     936        if ( ! is_array( $response ) ) {
     937                return $response;
     938        }
     939
     940        if ( ! array_key_exists( 'done', $response ) ) {
     941                return $response;
     942        }
     943
     944        if ( ! array_key_exists( 'items_removed', $response ) ) {
     945                return $response;
     946        }
     947
     948        if ( ! array_key_exists( 'items_retained', $response ) ) {
     949                return $response;
     950        }
     951
     952        if ( ! array_key_exists( 'messages', $response ) ) {
     953                return $response;
     954        }
     955
     956        // Get the request data.
     957        $request = wp_get_user_request_data( $request_id );
     958
     959        if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
     960                wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) );
     961        }
     962
     963        // If we are not yet on the last page of the last exporter, return now.
     964        $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     965        $is_last_eraser = $eraser_index === count( $erasers );
     966        $eraser_done = $response['done'];
     967        if ( ! $is_last_eraser || ! $eraser_done ) {
     968                return $response;
     969        }
     970
     971        // Update the request to completed state.
     972        _wp_privacy_completed_request( $request_id );
     973
     974        return $response;
     975}
     976
     977/**
    920978 * Add requests pages.
    921979 *
    922980 * @since 4.9.6