_reset_front_page_settings_for_post()WP 3.7.0

Resets the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed.

Also ensures the post is no longer sticky.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

null. Nothing (null).

Usage

_reset_front_page_settings_for_post( $post_id );
$post_id(int) (required)
Post ID.

Changelog

Since 3.7.0 Introduced.

_reset_front_page_settings_for_post() code WP 6.5.2

function _reset_front_page_settings_for_post( $post_id ) {
	$post = get_post( $post_id );

	if ( 'page' === $post->post_type ) {
		/*
		 * If the page is defined in option page_on_front or post_for_posts,
		 * adjust the corresponding options.
		 */
		if ( get_option( 'page_on_front' ) == $post->ID ) {
			update_option( 'show_on_front', 'posts' );
			update_option( 'page_on_front', 0 );
		}
		if ( get_option( 'page_for_posts' ) == $post->ID ) {
			update_option( 'page_for_posts', 0 );
		}
	}

	unstick_post( $post->ID );
}