From b51a0cb0f8bdfab62aa2ad2a367958bc98ba25cc Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 16 Nov 2007 17:39:15 +0000 Subject: [PATCH] Update page on front settings when deleting the page on front. Props hailin. fixes #5361 git-svn-id: http://svn.automattic.com/wordpress/trunk@6337 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index b32a4ee1fd..c02fdd70e1 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -504,9 +504,22 @@ function wp_delete_post($postid = 0) { $parent_data = array( 'post_parent' => $post->post_parent ); $parent_where = array( 'post_parent' => $postid ); - if ( 'page' == $post->post_type ) - $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'page' ) ); + 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') == $postid ) { + update_option('show_on_front', 'posts'); + delete_option('page_on_front'); + } + if ( get_option('page_for_posts') == $postid ) { + delete_option('page_for_posts'); + } + // Point children of this page to its parent + $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'page' ) ); + } + + // Point all attachments to this post up one level $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));