Skip to content
6 changes: 6 additions & 0 deletions src/wp-admin/includes/class-wp-privacy-policy-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ public static function notice( $post = null ) {
$current_screen = get_current_screen();
$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );

// If the privacy policy page has been deleted, reset the option and bail.
if ( $policy_page_id && ! get_post( $policy_page_id ) ) {
update_option( 'wp_page_for_privacy_policy', 0 );
return;
}
Comment on lines +332 to +336
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.

In practice, would this logic ever run now? Considering that the wp_page_for_privacy_policy option is set to 0 whenever the policy page is trashed or deleted, this condition would seem to just be here for extreme defensive programming. It doesn't seem necessary though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@westonruter as far as i tested back then it was added so also existing websites where the privacy policy page was deleted it gets catched after the patch has been added. for websites deleting pages after the patch your right this will not be needed.


if ( 'post' !== $current_screen->base || $policy_page_id !== $post->ID ) {
return;
}
Expand Down
15 changes: 1 addition & 14 deletions src/wp-admin/options-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,7 @@ static function ( $body_class ) {
'error'
);
} else {
if ( 'trash' === $privacy_policy_page->post_status ) {
add_settings_error(
'page_for_privacy_policy',
'page_for_privacy_policy',
sprintf(
/* translators: %s: URL to Pages Trash. */
__( 'The currently selected Privacy Policy page is in the Trash. Please create or select a new Privacy Policy page or <a href="%s">restore the current page</a>.' ),
'edit.php?post_status=trash&post_type=page'
),
'error'
);
} else {
$privacy_policy_page_exists = true;
}
$privacy_policy_page_exists = true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@
add_action( 'init', 'create_initial_post_types', 0 ); // Highest priority.
add_action( 'admin_menu', '_add_post_type_submenus' );
add_action( 'before_delete_post', '_reset_front_page_settings_for_post' );
add_action( 'before_delete_post', '_reset_privacy_policy_page_for_post' );
add_action( 'wp_trash_post', '_reset_front_page_settings_for_post' );
add_action( 'wp_trash_post', '_reset_privacy_policy_page_for_post' );
add_action( 'change_locale', 'create_initial_post_types' );

// Post Formats.
Expand Down
22 changes: 22 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4027,6 +4027,28 @@ function _reset_front_page_settings_for_post( $post_id ) {
unstick_post( $post->ID );
}

/**
* Resets the Privacy Policy page ID option when the Privacy Policy page
* is deleted or trashed, to prevent uncached database queries for a
* non-existent page.
*
* @since 7.1.0
* @access private
*
* @param int $post_id The ID of the post being deleted or trashed.
*/
function _reset_privacy_policy_page_for_post( int $post_id ): void {
$post = get_post( $post_id );

if ( ! $post ) {
Comment thread
masteradhoc marked this conversation as resolved.
Outdated
return;
}

if ( 'page' === $post->post_type && ( (int) get_option( 'wp_page_for_privacy_policy' ) === (int) $post_id ) ) {
Comment thread
masteradhoc marked this conversation as resolved.
Outdated
update_option( 'wp_page_for_privacy_policy', 0 );
}
}

/**
* Moves a post or page to the Trash
*
Expand Down
Loading