Index: wp-includes/default-filters.php =================================================================== --- wp-includes/default-filters.php (revision 22380) +++ wp-includes/default-filters.php (working copy) @@ -258,6 +258,7 @@ add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment' ); add_action( 'upgrader_scheduled_cleanup', 'wp_delete_attachment' ); add_action( 'welcome_panel', 'wp_welcome_panel' ); +add_action( 'page_for_posts_message', 'display_page_for_posts_message' ); // Navigation menu actions add_action( 'delete_post', '_wp_delete_post_menu_item' ); Index: wp-admin/includes/post.php =================================================================== --- wp-admin/includes/post.php (revision 22380) +++ wp-admin/includes/post.php (working copy) @@ -1330,6 +1330,27 @@ } /** + * Checks if page on front is set, else shows latests posts + * + * @since 3.5.0 + * @access private + */ + +function _show_on_front_cant_create_pages () { + + // If an existing page is set, keep things as is, rather than reverting to showing posts. + if ( get_option( 'page_on_front' ) ) { + $show_on_front_value = 'page'; + } else { + $show_on_front_value = 'posts'; + update_option( 'page_on_front', 0 ); + update_option( 'page_for_posts', 0 ); + } + add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) ); + return $show_on_front_value; +} + +/** * Creates new pages to be set as a front page or a page for posts in Reading Settings. * * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure. @@ -1338,108 +1359,99 @@ * @access private */ function _show_on_front_reading_settings( $show_on_front_value ) { + // If we're not saving the Reading Settings screen, don't intercept. if ( ! $_POST || ! strpos( wp_get_referer(), 'options-reading.php' ) ) return $show_on_front_value; - + + // If 'latest posts' is set, stop here if ( 'posts' == $show_on_front_value ) { update_option( 'page_on_front', 0 ); update_option( 'page_for_posts', 0 ); + return $show_on_front_value; } + + // They didn't select a page at all. Sad face. + if ( ! $_POST['page_on_front_title'] ) { + $show_on_front_value = 'posts'; + update_option( 'page_on_front', 0 ); + update_option( 'page_for_posts', 0 ); + add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) ); + return $show_on_front_value; + } + + // PAGE_ON_FRONT + $existing_page_on_front = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); - // If a new front page was meant to be created, go forth and create it. - if ( 'new' == $_POST['page_on_front'] ) { - + if ( $existing_page_on_front && $existing_page_on_front->ID && 'publish' == $existing_page_on_front->post_status && 'page' == $existing_page_on_front->post_type ) { + + // If a page exists with this same title, use it + update_option( 'page_on_front', (int) $existing_page_on_front->ID ); + } else { + // If the user can't create pages, revert. if ( ! current_user_can( 'create_posts', 'page' ) ) { - // If an existing page is set, keep things as is, rather than reverting to showing posts. - if ( get_option( 'page_on_front' ) ) { - $show_on_front_value = 'page'; - } else { - $show_on_front_value = 'posts'; - update_option( 'page_on_front', 0 ); - update_option( 'page_for_posts', 0 ); - } - add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) ); - return $show_on_front_value; + return _show_on_front_cant_create_pages(); } - - $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) ); - - // If page already exists and it's public, there's no need to create a new page. - if ( $existing_page && 'publish' == $existing_page->post_status ) { - $page_id = $existing_page->ID; - } else { - $page_id = wp_insert_post( array( - 'post_title' => $_POST['page_on_front_title'], - 'post_type' => 'page', - 'post_status' => 'publish', - 'comment_status' => 'closed', - 'ping_status' => 'closed', - // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. - // Consider then showing that context in the list table as a good-first-step. - ) ); - } - + + // Create new page + $page_id = wp_insert_post( array( + 'post_title' => wp_strip_all_tags( $_POST['page_on_front_title'] ), + 'post_type' => 'page', + 'post_status' => 'publish', + 'comment_status' => 'closed', + 'ping_status' => 'closed' + // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means. + // Consider then showing that context in the list table as a good-first-step. + ) ); + if ( $page_id ) { update_option( 'page_on_front', $page_id ); - // If we can't save it, revert. - } elseif ( get_option( 'page_on_front' ) ) { - // If an existing page is set, keep things as is, rather than reverting to showing posts. - $show_on_front_value = 'page'; } else { - $show_on_front_value = 'posts'; - update_option( 'page_on_front', 0 ); - update_option( 'page_for_posts', 0 ); - return $show_on_front_value; + + // If we can't save it, revert. + return _show_on_front_cant_create_pages(); } - } elseif ( $_POST['page_on_front'] ) { - update_option( 'page_on_front', $_POST['page_on_front'] ); - } else { - // They didn't select a page at all. Sad face. - $show_on_front_value = 'posts'; - update_option( 'page_on_front', 0 ); - update_option( 'page_for_posts', 0 ); - add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) ); - return $show_on_front_value; } - - // If a page for posts was meant to be specified, update/create it. - if ( ! isset( $_POST['page_for_posts'] ) ) { - update_option( 'page_for_posts', 0 ); + + // PAGE_FOR_POSTS + if ( ! isset( $_POST['page_for_posts_name'] ) ) { return $show_on_front_value; } - - $page_for_posts = (int) $_POST['page_for_posts']; - - if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) { - update_option( 'page_for_posts', 0 ); - return $show_on_front_value; + + $existing_page_for_posts = get_page_by_path( stripslashes( $_POST['page_for_posts_name'] ) ); + + if ( $existing_page_for_posts && $existing_page_for_posts->ID && 'publish' == $existing_page_for_posts->post_status && 'page' == $existing_page_for_posts->post_type ) { + + // If a page exists with this same name, use it + update_option( 'page_for_posts', (int) $existing_page_for_posts->ID ); + } else { + + // If the user can't create pages, revert. + if ( ! current_user_can( 'create_posts', 'page' ) ) { + return _show_on_front_cant_create_pages(); + } + + // Create new page + $page_id = wp_insert_post( array( + 'post_title' => 'Latest posts', + 'post_name' => wp_strip_all_tags( $_POST['page_for_posts_name'] ), + 'post_type' => 'page', + 'post_status' => 'publish', + 'comment_status' => 'closed', + 'ping_status' => 'closed' + ) ); + + if ( $page_id ) { + update_option( 'page_for_posts', $page_id ); + } else { + + // If we can't save it, revert. + return _show_on_front_cant_create_pages(); + } } - if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) { - update_option( 'page_for_posts', 0 ); - return $show_on_front_value; - } - - if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) { - update_option( 'page_for_posts', 0 ); - return $show_on_front_value; - } - - $args = add_magic_quotes( $page ); - $args['post_title'] = $_POST['page_for_posts_title']; - $args['post_name'] = $_POST['post_name']; - $args['post_status'] = 'publish'; - if ( 'auto-draft' == $page['post_status'] ) { - $args['comment_status'] = 'closed'; - $args['ping_status'] = 'closed'; - } - - $page_id = wp_insert_post( $args ); - update_option( 'page_for_posts', $page_id ); - return $show_on_front_value; } -add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' ); +add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' ); \ No newline at end of file Index: wp-admin/edit-form-advanced.php =================================================================== --- wp-admin/edit-form-advanced.php (revision 22380) +++ wp-admin/edit-form-advanced.php (working copy) @@ -306,8 +306,20 @@ wp_nonce_field( 'autosave', 'autosavenonce', false ); wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); -?> +do_action( 'page_for_posts_message' ); + +function display_page_for_posts_message () { + global $post; + + if ( $post->ID == get_option( 'page_for_posts' ) ) { ?> +
+ +