-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Privacy: Reset wp_page_for_privacy_policy when the page is trashed or deleted #11443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
masteradhoc
wants to merge
33
commits into
WordPress:trunk
from
masteradhoc:56694-uncached-database-reads
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
869faa0
add _reset_privacy_policy_page_for_post function
masteradhoc e5745b5
add actions
masteradhoc 6b3e05b
add reset option
masteradhoc 3930d1c
Removed the "page is in trash" error
masteradhoc e391d36
add feedback of mukesh
masteradhoc f4dfb44
add feedback of mukesh
masteradhoc 555e5c6
Fix whitespace
masteradhoc 47d48d6
fix phpstan error
masteradhoc beb4349
add westons feedback
masteradhoc fbf18e4
remove redundant code
masteradhoc f8e9ddb
add unit tests
masteradhoc d398eeb
upgrade failing test
masteradhoc ccfd7f2
update test
masteradhoc 49426c4
fix tests
masteradhoc e903c22
Merge branch 'trunk' into 56694-uncached-database-reads
masteradhoc bbe7337
Merge branch 'trunk' into 56694-uncached-database-reads
westonruter 4477dd6
Add void return types
westonruter 1ba5c0f
Add assertion for factory output
westonruter bd4b5f1
Use native property hint
westonruter 0572273
Remove unnecessary tags from unit test class
westonruter b60e3ee
Revert "Remove unnecessary tags from unit test class"
westonruter 20afd2c
wait until trash operation was successful
masteradhoc 7f20c96
Merge branch 'trunk' into 56694-uncached-database-reads
masteradhoc a9dab60
reset wp_page_for_privacy_policy on permanent deletion only, not on t…
masteradhoc ef2ea1b
Merge branch '56694-uncached-database-reads' of https://github.com/ma…
masteradhoc 12e9319
update docblock and testcase
masteradhoc ada2915
add test cases
masteradhoc e20b62b
Merge branch 'WordPress:trunk' into 56694-uncached-database-reads
masteradhoc 4eee3f5
update tests
masteradhoc 877c32c
Merge branch '56694-uncached-database-reads' of https://github.com/ma…
masteradhoc c0dd628
fix The closing brace for the class must go on the next line after th…
masteradhoc 80a466c
Merge branch 'trunk' into 56694-uncached-database-reads
masteradhoc 0e757af
Merge remote-tracking branch 'upstream/trunk' into pr/11443
joedolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| <?php | ||
| /** | ||
| * Tests for _reset_privacy_policy_page_for_post() and the self-healing | ||
| * check in WP_Privacy_Policy_Content::notice(). | ||
| * | ||
| * @package WordPress | ||
| * @subpackage UnitTests | ||
| * @since 7.1.0 | ||
| * | ||
| * @group privacy | ||
| * | ||
| * @covers ::_reset_privacy_policy_page_for_post | ||
| */ | ||
| class Tests_Privacy_WpPrivacyResetPolicyPageForPost extends WP_UnitTestCase { | ||
| /** | ||
| * ID of the page set as the Privacy Policy page. | ||
| */ | ||
| private int $policy_page_id; | ||
|
|
||
| public function set_up(): void { | ||
| parent::set_up(); | ||
|
|
||
| $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); | ||
| assert( is_int( $page_id ) ); | ||
| $this->policy_page_id = $page_id; | ||
|
westonruter marked this conversation as resolved.
|
||
| update_option( 'wp_page_for_privacy_policy', $this->policy_page_id ); | ||
| } | ||
|
|
||
| public function tear_down(): void { | ||
| delete_option( 'wp_page_for_privacy_policy' ); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that trashing the Privacy Policy page does NOT reset the option, | ||
| * so that restoring from trash preserves the assignment. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_trashing_privacy_policy_page_does_not_reset_option(): void { | ||
| wp_trash_post( $this->policy_page_id ); | ||
|
|
||
| $this->assertSame( | ||
| $this->policy_page_id, | ||
| (int) get_option( 'wp_page_for_privacy_policy' ), | ||
| 'Trashing the Privacy Policy page should not reset wp_page_for_privacy_policy.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that permanently deleting the Privacy Policy page resets the option to 0. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_deleting_privacy_policy_page_resets_option(): void { | ||
| wp_delete_post( $this->policy_page_id, true ); | ||
|
|
||
| $this->assertSame( 0, (int) get_option( 'wp_page_for_privacy_policy' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that trashing a different page does not change the option. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_trashing_a_different_page_does_not_reset_option(): void { | ||
| $other_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); | ||
| $this->assertIsInt( $other_page_id ); | ||
| wp_trash_post( $other_page_id ); | ||
|
|
||
| $this->assertSame( | ||
| $this->policy_page_id, | ||
| (int) get_option( 'wp_page_for_privacy_policy' ), | ||
| 'Trashing an unrelated page should not reset wp_page_for_privacy_policy.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that deleting a non-page post type does not change the option. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_deleting_non_page_post_type_does_not_reset_option(): void { | ||
| $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); | ||
| $this->assertIsInt( $post_id ); | ||
| wp_delete_post( $post_id, true ); | ||
|
|
||
| $this->assertSame( | ||
| $this->policy_page_id, | ||
| (int) get_option( 'wp_page_for_privacy_policy' ), | ||
| 'Deleting a non-page post should not reset wp_page_for_privacy_policy.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that WP_Privacy_Policy_Content::notice() resets the option to 0 | ||
| * when the stored ID points to a page that no longer exists. | ||
| * | ||
| * @ticket 56694 | ||
| * | ||
| * @covers WP_Privacy_Policy_Content::notice | ||
| */ | ||
| public function test_notice_self_heals_when_policy_page_does_not_exist(): void { | ||
| require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php'; | ||
|
|
||
| update_option( 'wp_page_for_privacy_policy', 99999 ); | ||
|
|
||
| $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); | ||
| $this->assertIsInt( $user_id ); | ||
| wp_set_current_user( $user_id ); | ||
| if ( is_multisite() ) { | ||
| grant_super_admin( $user_id ); | ||
| } | ||
| set_current_screen( 'post' ); | ||
|
|
||
| $post = self::factory()->post->create_and_get( array( 'post_type' => 'page' ) ); | ||
| $this->assertInstanceOf( WP_Post::class, $post ); | ||
| WP_Privacy_Policy_Content::notice( $post ); | ||
|
|
||
| $this->assertSame( | ||
| 0, | ||
| (int) get_option( 'wp_page_for_privacy_policy' ), | ||
| 'notice() should reset the option to 0 when the stored page does not exist.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that _reset_privacy_policy_page_for_post() does not call | ||
| * update_option() when wp_page_for_privacy_policy is already 0. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_no_update_option_when_policy_page_already_zero(): void { | ||
| update_option( 'wp_page_for_privacy_policy', 0 ); | ||
|
|
||
| $call_count = 0; | ||
| add_filter( | ||
| 'pre_update_option_wp_page_for_privacy_policy', | ||
| static function ( $value ) use ( &$call_count ) { | ||
| ++$call_count; | ||
| return $value; | ||
| } | ||
| ); | ||
|
|
||
| $other_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); | ||
| $this->assertIsInt( $other_page_id ); | ||
| wp_delete_post( $other_page_id, true ); | ||
|
|
||
|
westonruter marked this conversation as resolved.
|
||
| $this->assertSame( | ||
| 0, | ||
| $call_count, | ||
| 'update_option() should not be called when wp_page_for_privacy_policy is already 0.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that untrashing the Privacy Policy page preserves the option, | ||
| * confirming the trash/restore cycle keeps the assignment intact. | ||
| * | ||
| * @ticket 56694 | ||
| */ | ||
| public function test_untrashing_privacy_policy_page_preserves_option(): void { | ||
| wp_trash_post( $this->policy_page_id ); | ||
| wp_untrash_post( $this->policy_page_id ); | ||
|
|
||
| $this->assertSame( | ||
| $this->policy_page_id, | ||
| (int) get_option( 'wp_page_for_privacy_policy' ), | ||
| 'Untrashing the Privacy Policy page should preserve wp_page_for_privacy_policy.' | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.