Make WordPress Core

Changeset 22136


Ignore:
Timestamp:
10/08/2012 09:25:13 PM (11 years ago)
Author:
nacin
Message:

Move the static front page saving routine to a single sanitize_option() callback for show_on_front. page_on_front and page_for_posts are now manually set by this callback, and not separately by options.php. see #16379.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r22129 r22136  
    13381338 * @access private
    13391339 */
    1340 function _create_pages_for_reading_settings() {
    1341     // If we're saving the Reading Settings screen, intercept.
    1342     if ( ! isset( $_POST['show_on_front'] ) )
    1343         return;
     1340function _show_on_front_reading_settings( $show_on_front_value ) {
     1341    // If we're not saving the Reading Settings screen, don't intercept.
     1342    if ( ! $_POST || ! strpos( wp_get_referer(), 'options-reading.php' ) )
     1343        return $show_on_front_value;
     1344
     1345    if ( 'posts' == $show_on_front_value ) {
     1346        update_option( 'page_on_front', 0 );
     1347        update_option( 'page_for_posts', 0 );
     1348        return $show_on_front_value;
     1349    }
    13441350
    13451351    // If a new front page was meant to be created, go forth and create it.
    1346     if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) {
     1352    if ( 'new' == $_POST['page_on_front'] ) {
     1353
     1354        // If the user can't create pages, revert.
    13471355        if ( ! current_user_can( 'create_posts', 'page' ) ) {
    1348             $_POST['page_on_front'] = 0;
    1349             $_POST['show_on_front'] = 'posts';
    1350             add_settings_error( 'page_on_front', __( 'You are not allowed to create pages on this site.' ) );
     1356            // If an existing page is set, keep things as is, rather than reverting to showing posts.
     1357            if ( get_option( 'page_on_front' ) ) {
     1358                $show_on_front_value = 'page';
     1359            } else {
     1360                $show_on_front_value = 'posts';
     1361                update_option( 'page_on_front', 0 );
     1362                update_option( 'page_for_posts', 0 );
     1363            }
     1364            add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) );
     1365            return $show_on_front_value;
    13511366        }
    13521367
    13531368        $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) );
    13541369
    1355         // If page already exists and it's public, there's no need to create a new page
     1370        // If page already exists and it's public, there's no need to create a new page.
    13561371        if ( $existing_page && 'publish' == $existing_page->post_status ) {
    13571372            $page_id = $existing_page->ID;
     
    13651380                // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means.
    13661381                //       Consider then showing that context in the list table as a good-first-step.
    1367             ), true );
    1368         }
    1369 
    1370         // Make sure page_on_front is properly saved by options.php.
    1371         if ( is_wp_error( $page_id ) )
    1372             $_POST['page_on_front'] = 0;
    1373         else
    1374             $_POST['page_on_front'] = $page_id;
     1382            ) );
     1383        }
     1384
     1385        if ( $page_id ) {
     1386            update_option( 'page_on_front', $page_id );
     1387        // If we can't save it, revert.
     1388        } elseif ( get_option( 'page_on_front' ) ) {
     1389            // If an existing page is set, keep things as is, rather than reverting to showing posts.
     1390            $show_on_front_value = 'page';
     1391        } else {
     1392            $show_on_front_value = 'posts';
     1393            update_option( 'page_on_front', 0 );
     1394            update_option( 'page_for_posts', 0 );
     1395            return $show_on_front_value;
     1396        }
     1397    } elseif ( $_POST['page_on_front'] ) {
     1398        update_option( 'page_on_front', $_POST['page_on_front'] );
     1399    } else {
     1400        // They didn't select a page at all. Sad face.
     1401        $show_on_front_value = 'posts';
     1402        update_option( 'page_on_front', 0 );
     1403        update_option( 'page_for_posts', 0 );
     1404        add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) );
     1405        return $show_on_front_value;
    13751406    }
    13761407
    13771408    // If a page for posts was meant to be specified, update/create it.
    1378     if ( ! isset( $_POST['page_for_posts'] ) )
    1379         return;
     1409    if ( ! isset( $_POST['page_for_posts'] ) ) {
     1410        update_option( 'page_for_posts', 0 );
     1411        return $show_on_front_value;
     1412    }
    13801413
    13811414    $page_for_posts = (int) $_POST['page_for_posts'];
     1415
    13821416    if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) {
    1383         $_POST['page_for_posts'] = 0;
    1384         return;
    1385     }
    1386 
    1387     // @todo The UI (see @todo's in options-reading) should cover the next 3 conditionals,
    1388     //       which means we shouldn't need to bother with setting a settings error here.
    1389     //       However, we may wish to restore settings before bailing, beyond setting
    1390     //       page_for_posts to 0 (which we then expect to get cleaned up by options.php).
     1417        update_option( 'page_for_posts', 0 );
     1418        return $show_on_front_value;
     1419    }
     1420
    13911421    if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) {
    1392         $_POST['page_for_posts'] = 0;
    1393         return;
     1422        update_option( 'page_for_posts', 0 );
     1423        return $show_on_front_value;
    13941424    }
    13951425
    13961426    if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) {
    1397         $_POST['page_for_posts'] = 0;
    1398         return;
     1427        update_option( 'page_for_posts', 0 );
     1428        return $show_on_front_value;
    13991429    }
    14001430
     
    14081438    }
    14091439
    1410     $page_id = wp_insert_post( $args, true );
    1411     if ( is_wp_error( $page_id ) )
    1412         $_POST['page_for_posts'] = 0;
    1413 }
    1414 add_filter( 'admin_init', '_create_pages_for_reading_settings' );
     1440    $page_id = wp_insert_post( $args );
     1441    update_option( 'page_for_posts', $page_id );
     1442
     1443    return $show_on_front_value;
     1444}
     1445add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' );
  • trunk/wp-admin/options-reading.php

    r22127 r22136  
    3333        if ( checked )
    3434            $('#page_for_posts').prop('checked', true).change();
     35        else
     36            section.removeClass('page-for-posts');
    3537    });
    3638    $('#page_for_posts').change( function() {
     
    117119    //       Otherwise, we must assume they cannot create pages (throughout), and thus
    118120    //       should fall back to the dropdown.
    119     if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) {
     121    $page_for_posts = get_page_by_path( sanitize_title( $title ) );
     122    if ( ! $page_for_posts || $page_for_posts->ID == get_option( 'page_on_front' ) ) {
    120123        $page_for_posts = get_default_post_to_edit( 'page', true );
    121124        $page_for_posts->post_title = $title;
  • trunk/wp-admin/options.php

    r22006 r22136  
    6363    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    6464    'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
    65     'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
     65    'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'blog_public' ),
    6666    'writing' => array( 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format' )
    6767);
Note: See TracChangeset for help on using the changeset viewer.