Skip to content

Privacy: Reset wp_page_for_privacy_policy when the page is trashed or deleted - #11443

Closed
masteradhoc wants to merge 33 commits into
WordPress:trunkfrom
masteradhoc:56694-uncached-database-reads
Closed

Privacy: Reset wp_page_for_privacy_policy when the page is trashed or deleted#11443
masteradhoc wants to merge 33 commits into
WordPress:trunkfrom
masteradhoc:56694-uncached-database-reads

Conversation

@masteradhoc

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/56694

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet 4.6
Used for: Code review and manual test suggestions to test extensively; final implementation were reviewed and fully tested by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Apr 5, 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.

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

Props masteradhoc, westonruter, joedolson, mukesh27.

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

@github-actions

github-actions Bot commented Apr 5, 2026

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.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

Left some initial feedbacks.

Comment thread src/wp-includes/post.php Outdated
Comment thread src/wp-includes/post.php Outdated
masteradhoc and others added 2 commits April 6, 2026 08:50
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@masteradhoc

Copy link
Copy Markdown
Author

Your feedback has been added, thanks @mukeshpanchal27 !

@westonruter

Copy link
Copy Markdown
Member

This will need unit tests as well.

Comment thread src/wp-includes/post.php Outdated
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Comment thread src/wp-includes/post.php Outdated
Comment thread src/wp-admin/includes/class-wp-privacy-policy-content.php
@masteradhoc

Copy link
Copy Markdown
Author

Thanks to @nimesh-xecurify for his work on the Tests at #11520

Comment thread src/wp-includes/default-filters.php Outdated
@westonruter

Copy link
Copy Markdown
Member

Thanks to @nimesh-xecurify for his work on the Tests at #11520

In the future, it would be helpful to preserve that attribution by using a Co-authored-by commit message trailer when moving such code around.

For example:

Co-authored-by: nimeshatxecurify <nimeshatxecurify@git.wordpress.org>

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 PR ensures the wp_page_for_privacy_policy option is cleared when the selected Privacy Policy page is trashed or permanently deleted, preventing the setting from pointing at an invalid page and adding a small “self-heal” in the admin notice path.

Changes:

  • Add _reset_privacy_policy_page_for_post() and hook it to before_delete_post and wp_trash_post to reset wp_page_for_privacy_policy to 0.
  • Simplify the Privacy Settings screen logic by removing the special-case error for when the selected page is in the Trash.
  • Add PHPUnit coverage for trash/delete resets, “do not reset” cases, the admin-notice self-heal behavior, and avoiding unnecessary option updates.

Reviewed changes

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

Show a summary per file
File Description
tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php Adds new test coverage for resetting/self-healing behavior around wp_page_for_privacy_policy.
src/wp-includes/post.php Introduces _reset_privacy_policy_page_for_post() to clear the option when the selected page is trashed/deleted.
src/wp-includes/default-filters.php Hooks the new reset callback into core delete/trash actions.
src/wp-admin/options-privacy.php Removes the “policy page is in the Trash” settings error path.
src/wp-admin/includes/class-wp-privacy-policy-content.php Adds a self-healing guard to reset the option if it points to a non-existent page.

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

Comment thread tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php
Comment thread src/wp-includes/post.php
Comment thread tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php
westonruter and others added 2 commits June 2, 2026 11:25
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Comment thread src/wp-includes/default-filters.php Outdated
Comment thread src/wp-admin/options-privacy.php
@masteradhoc
masteradhoc requested a review from westonruter June 17, 2026 05:37
@masteradhoc

Copy link
Copy Markdown
Author

@mukeshpanchal27 @westonruter anything left here that needs to get adjusted?

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Copilot AI review requested due to automatic review settings July 24, 2026 18:22

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

pento pushed a commit that referenced this pull request Jul 24, 2026
If the privacy page is deleted but the setting is left intact, an admin_hook would fire on every admin screen attempting to notify about changes in the privacy policy. With the page deleted, this database read is never cached, since it returns no results.

Add a `before_delete_post` hook to reset setting if the post is deleted. Add a guard to reset the option on the privacy screen to cover edge cases. 

Developed in #11443, #11520

Props johnjamesjacoby, masteradhoc, westonruter, nimeshatxecurify, mukesh27, joedolson.
Fixes #56694.

git-svn-id: https://develop.svn.wordpress.org/trunk@62845 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62845
GitHub commit: 6d1d03d

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 24, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 24, 2026
If the privacy page is deleted but the setting is left intact, an admin_hook would fire on every admin screen attempting to notify about changes in the privacy policy. With the page deleted, this database read is never cached, since it returns no results.

Add a `before_delete_post` hook to reset setting if the post is deleted. Add a guard to reset the option on the privacy screen to cover edge cases. 

Developed in WordPress/wordpress-develop#11443, WordPress/wordpress-develop#11520

Props johnjamesjacoby, masteradhoc, westonruter, nimeshatxecurify, mukesh27, joedolson.
Fixes #56694.
Built from https://develop.svn.wordpress.org/trunk@62845


git-svn-id: http://core.svn.wordpress.org/trunk@62125 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@masteradhoc
masteradhoc deleted the 56694-uncached-database-reads branch July 24, 2026 19:24
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.

5 participants