Make WordPress Core


Ignore:
Timestamp:
11/19/2012 01:28:32 AM (12 years ago)
Author:
nacin
Message:

Revert page on front changes. Reverts [22127] [22129] [22135] [22136]. see #16379.

File:
1 edited

Legend:

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

    r22532 r22653  
    10561056 * @param string $new_title Optional. New title.
    10571057 * @param string $new_slug Optional. New slug.
    1058  * @param string|WP_Screen $screen Optional. Screen where the editor is being shown.
    10591058 * @return string The HTML of the sample permalink slug editor.
    10601059 */
    1061 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null, $screen = null ) {
     1060function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
    10621061    global $wpdb;
    10631062    $post = get_post($id);
    10641063
    10651064    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    1066 
    1067     if ( isset( $screen ) )
    1068         $screen = convert_to_screen( $screen );
    1069     else
    1070         $screen = get_current_screen();
    10711065
    10721066    if ( 'publish' == get_post_status( $post ) ) {
     
    10791073
    10801074    if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
    1081         if ( 'options-reading' == $screen->id )
    1082             return '';
    10831075        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
    10841076        if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
    10851077            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    1086         if ( isset($view_post) )
     1078        if ( isset( $view_post ) )
    10871079            $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-small'>$view_post</a></span>\n";
    10881080
     
    11091101    $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
    11101102    $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
    1111     $return  = ( 'options-reading' == $screen->id ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     1103    $return =  '<strong>' . __('Permalink:') . "</strong>\n";
    11121104    $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
    11131105    $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
    11141106    $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    11151107    $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    1116     if ( isset( $view_post ) && 'options-reading' != $screen->id )
     1108    if ( isset($view_post) )
    11171109        $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n";
    11181110
     
    13301322    return $url;
    13311323}
    1332 
    1333 /**
    1334  * Creates new pages to be set as a front page or a page for posts in Reading Settings.
    1335  *
    1336  * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure.
    1337  *
    1338  * @since 3.5.0
    1339  * @access private
    1340  */
    1341 function _show_on_front_reading_settings( $show_on_front_value ) {
    1342     // If we're not saving the Reading Settings screen, don't intercept.
    1343     if ( ! $_POST || ! strpos( wp_get_referer(), 'options-reading.php' ) )
    1344         return $show_on_front_value;
    1345 
    1346     if ( 'posts' == $show_on_front_value ) {
    1347         update_option( 'page_on_front', 0 );
    1348         update_option( 'page_for_posts', 0 );
    1349         return $show_on_front_value;
    1350     }
    1351 
    1352     // If a new front page was meant to be created, go forth and create it.
    1353     if ( 'new' == $_POST['page_on_front'] ) {
    1354 
    1355         // If the user can't create pages, revert.
    1356         if ( ! current_user_can( 'create_posts', 'page' ) ) {
    1357             // If an existing page is set, keep things as is, rather than reverting to showing posts.
    1358             if ( get_option( 'page_on_front' ) ) {
    1359                 $show_on_front_value = 'page';
    1360             } else {
    1361                 $show_on_front_value = 'posts';
    1362                 update_option( 'page_on_front', 0 );
    1363                 update_option( 'page_for_posts', 0 );
    1364             }
    1365             add_settings_error( 'page_on_front', 'create_pages', __( 'You are not allowed to create pages on this site.' ) );
    1366             return $show_on_front_value;
    1367         }
    1368 
    1369         $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) );
    1370 
    1371         // If page already exists and it's public, there's no need to create a new page.
    1372         if ( $existing_page && 'publish' == $existing_page->post_status ) {
    1373             $page_id = $existing_page->ID;
    1374         } else {
    1375             $page_id = wp_insert_post( array(
    1376                 'post_title' => $_POST['page_on_front_title'],
    1377                 'post_type' => 'page',
    1378                 'post_status' => 'publish',
    1379                 'comment_status' => 'closed',
    1380                 'ping_status' => 'closed',
    1381                 // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means.
    1382                 //       Consider then showing that context in the list table as a good-first-step.
    1383             ) );
    1384         }
    1385 
    1386         if ( $page_id ) {
    1387             update_option( 'page_on_front', $page_id );
    1388         // If we can't save it, revert.
    1389         } elseif ( get_option( 'page_on_front' ) ) {
    1390             // If an existing page is set, keep things as is, rather than reverting to showing posts.
    1391             $show_on_front_value = 'page';
    1392         } else {
    1393             $show_on_front_value = 'posts';
    1394             update_option( 'page_on_front', 0 );
    1395             update_option( 'page_for_posts', 0 );
    1396             return $show_on_front_value;
    1397         }
    1398     } elseif ( $_POST['page_on_front'] ) {
    1399         update_option( 'page_on_front', $_POST['page_on_front'] );
    1400     } else {
    1401         // They didn't select a page at all. Sad face.
    1402         $show_on_front_value = 'posts';
    1403         update_option( 'page_on_front', 0 );
    1404         update_option( 'page_for_posts', 0 );
    1405         add_settings_error( 'page_on_front', 'no_page_selected', __( 'You must select a page to set a static front page.' ) );
    1406         return $show_on_front_value;
    1407     }
    1408 
    1409     // If a page for posts was meant to be specified, update/create it.
    1410     if ( ! isset( $_POST['page_for_posts'] ) ) {
    1411         update_option( 'page_for_posts', 0 );
    1412         return $show_on_front_value;
    1413     }
    1414 
    1415     $page_for_posts = (int) $_POST['page_for_posts'];
    1416 
    1417     if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) {
    1418         update_option( 'page_for_posts', 0 );
    1419         return $show_on_front_value;
    1420     }
    1421 
    1422     if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) {
    1423         update_option( 'page_for_posts', 0 );
    1424         return $show_on_front_value;
    1425     }
    1426 
    1427     if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) {
    1428         update_option( 'page_for_posts', 0 );
    1429         return $show_on_front_value;
    1430     }
    1431 
    1432     $args = add_magic_quotes( $page );
    1433     $args['post_title']  = $_POST['page_for_posts_title'];
    1434     $args['post_name']   = $_POST['post_name'];
    1435     $args['post_status'] = 'publish';
    1436     if ( 'auto-draft' == $page['post_status'] ) {
    1437         $args['comment_status'] = 'closed';
    1438         $args['ping_status'] = 'closed';
    1439     }
    1440 
    1441     $page_id = wp_insert_post( $args );
    1442     update_option( 'page_for_posts', $page_id );
    1443 
    1444     return $show_on_front_value;
    1445 }
    1446 add_filter( 'sanitize_option_show_on_front', '_show_on_front_reading_settings' );
Note: See TracChangeset for help on using the changeset viewer.