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