Skip to content

65758 added check for post status in wp_privacy_send_personal_data_export_email() - #12759

Open
pbearne wants to merge 11 commits into
WordPress:trunkfrom
pbearne:65758
Open

65758 added check for post status in wp_privacy_send_personal_data_export_email()#12759
pbearne wants to merge 11 commits into
WordPress:trunkfrom
pbearne:65758

Conversation

@pbearne

@pbearne pbearne commented Jul 29, 2026

Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings July 29, 2026 20:22
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @[email protected].

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne, mindctrl, masteradhoc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request tightens the behavior of wp_privacy_send_personal_data_export_email() by ensuring it only sends export emails for requests in appropriate lifecycle states, and updates locale-related tests to confirm the correct request.

Changes:

  • Add a request status validation gate to wp_privacy_send_personal_data_export_email() (only allow request-confirmed / request-completed).
  • Fix two unit tests to confirm the newly-created request ID (instead of the shared fixture request ID) before attempting to send an export email.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php Updates locale-related tests to confirm the correct request before sending the export email.
src/wp-admin/includes/privacy-tools.php Adds request status validation to prevent sending export emails for requests in invalid states.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-admin/includes/privacy-tools.php
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI review requested due to automatic review settings July 29, 2026 20:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/wp-admin/includes/privacy-tools.php:604

  • This new status guard is a behavior change (requests in request-pending/request-failed will now return WP_Error instead of attempting to send). There doesn’t appear to be a targeted unit test asserting the new failure mode for wp_privacy_send_personal_data_export_email(); the updated export-page test currently hits this guard only because the fixture request is unconfirmed.

Add a dedicated test in tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php that creates an export_personal_data request, leaves it unconfirmed (or marks it request-failed), and asserts a WP_Error is returned with this message.

	if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
		return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
	}

tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:506

  • This test is named and documented as exercising the wp_mail() failure path, but it now expects the new “Invalid request status…” message. That happens because the shared request fixture (self::$request_id) is created as request-pending and never confirmed in this test class, so wp_privacy_send_personal_data_export_email() bails out before attempting to send mail. This makes the test stop validating the intended behavior and can hide regressions in the actual mail-failure handling.

Create and confirm a request for this test (or confirm the existing one) and keep asserting the “Unable to send…” message to ensure you’re testing the wp_mail() failure branch.

	public function test_send_error_on_last_page_of_last_exporter_when_mail_delivery_fails() {
		// Cause `wp_mail()` to return false, to simulate mail delivery failure. Filter removed in tearDown.
		add_filter( 'wp_mail_from', '__return_empty_string' );

		// Process data, given the last exporter, on the last page and send as email.
		$this->_setup_expected_failure( '{"success":false,"data":"Invalid request status when sending personal data export email."}' );

Copilot AI review requested due to automatic review settings July 29, 2026 20:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:506

  • This test is named and documented as a mail-delivery-failure scenario, but it now expects an "Invalid request status" error. Because the shared fixture request created in wpSetUpBeforeClass() is never confirmed (it stays request-pending), wp_privacy_send_personal_data_export_email() returns early on the new status check and wp_mail() is never exercised—making the wp_mail_from filter irrelevant and leaving the mail-failure behavior untested in this code path.

To keep this test aligned with its intent, confirm the request before processing and restore the expected message for an actual wp_mail() failure. If you also want coverage for the new invalid-status guard, add a separate test that leaves the request unconfirmed and asserts the new message.

		// Cause `wp_mail()` to return false, to simulate mail delivery failure. Filter removed in tearDown.
		add_filter( 'wp_mail_from', '__return_empty_string' );

		// Process data, given the last exporter, on the last page and send as email.
		$this->_setup_expected_failure( '{"success":false,"data":"Invalid request status when sending personal data export email."}' );

@masteradhoc

Copy link
Copy Markdown

Thanks @pbearne for the PR - we have some Unit Tests failing, could you recheck them?
@mindctrl would you mind testing this PR as well given you've recently reviewed quite some privacy test PRs? :)

@mindctrl mindctrl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting multiple test failures running the privacy group of tests.

npm run test:php -- --group privacy


There were 6 errors:

1) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_wp_privacy_process_personal_data_export_page with data set #4 (array(true, array()))
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:274

2) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_raw_data_post_meta with data set #0 (true)
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:443

3) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_add_post_meta_with_groups_data_only_available_when_export_file_generated with data set #0 (true)
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:482

4) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_add_post_meta_with_groups_data_only_available_when_export_file_generated with data set #1 (false)
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:482

5) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_return_response_without_export_file_url_when_sent_as_email_for_last_exporter_on_last_page
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:555

6) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_request_status_transitions_correctly with data set #0 ('request-completed', 'last', 'last', 'last', true, 'last')
WPDieException:

/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:609

ERRORS!
Tests: 250, Assertions: 508, Errors: 6.

It looks like we need more lines similar to this: _wp_privacy_account_request_confirmed( self::$request_id ); to confirm the request.

Copilot AI review requested due to automatic review settings July 30, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/privacy-tools.php:604

  • The new status gate is a behavior change (requests in request-pending/other statuses will now error). Please add a unit test covering this path (e.g., create an export_personal_data user request left in request-pending and assert wp_privacy_send_personal_data_export_email() returns a WP_Error with the expected error code/message), to prevent regressions and document the intended contract.
	if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
		return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
	}

Copilot AI review requested due to automatic review settings July 30, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/privacy-tools.php:604

  • The new request-status guard changes behavior (pending/failed requests now return a WP_Error) but there’s no unit test asserting this new failure mode. Adding a PHPUnit test (e.g., set the request post_status to request-pending and assert wp_privacy_send_personal_data_export_email() returns invalid_request) would prevent regressions and document the intended contract.
	if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
		return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants