Make WordPress Core

Ticket #16379: 16379.3.patch

File 16379.3.patch, 13.3 KB (added by SergeyBiryukov, 12 years ago)
  • wp-admin/css/wp-admin.css

     
    28612861        padding: 0 10px;
    28622862}
    28632863
     2864#front-static-pages #edit-slug-box {
     2865        padding: 0;
     2866}
     2867
    28642868#editable-post-name-full {
    28652869        display: none;
    28662870}
  • wp-admin/includes/post.php

     
    10601060 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
    10611061 */
    10621062function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
    1063         global $wpdb;
     1063        global $wpdb, $current_screen;
     1064
    10641065        $post = get_post($id);
    10651066
     1067        if ( isset( $current_screen ) )
     1068                $context = $current_screen->id;
     1069        else
     1070                $context = isset( $_POST['context'] ) ? $_POST['context'] : '';
     1071
    10661072        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    10671073
    10681074        if ( 'publish' == $post->post_status ) {
     
    10731079                $title = __('Temporary permalink. Click to edit this part.');
    10741080        }
    10751081
    1076         if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
    1077                 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
     1082        if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
     1083                $return  = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     1084                $return .= '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
    10781085                if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
    10791086                        $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    1080                 if ( isset($view_post) )
     1087                if ( isset( $view_post ) && 'options-reading' == $context )
    10811088                        $return .= "<span id='view-post-btn'><a href='$permalink' class='button'>$view_post</a></span>\n";
    10821089
    10831090                $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
     
    11001107        }
    11011108
    11021109        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    1103         $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
    1104         $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
    1105         $return =  '<strong>' . __('Permalink:') . "</strong>\n";
     1110        $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink );
     1111        $view_link = str_replace( array( '%pagename%', '%postname%' ), $post_name, $permalink );
     1112        $return  = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
    11061113        $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
    11071114        $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
    11081115        $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    11091116        $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    1110         if ( isset($view_post) )
     1117        if ( isset( $view_post ) && 'options-reading' != $context )
    11111118                $return .= "<span id='view-post-btn'><a href='$view_link' class='button'>$view_post</a></span>\n";
    11121119
    11131120        $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
     
    13231330
    13241331        return $url;
    13251332}
     1333
     1334/**
     1335 * Creates new pages to be set as a front page or a page for posts in Reading Settings.
     1336 *
     1337 * @since 3.5.0
     1338 * @access private
     1339 */
     1340function _create_pages_for_reading_settings() {
     1341        if ( ! isset( $_POST['show_on_front'] ) )
     1342                return;
     1343
     1344        $post_type = get_post_type_object( 'page' );
     1345        if ( ! current_user_can( $post_type->cap->edit_posts ) )
     1346                wp_die( __( 'You are not allowed to create pages on this site.' ) );
     1347
     1348        if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) {
     1349                $page_on_front_title = esc_html( stripslashes( $_POST['page_on_front_title'] ) );
     1350
     1351                $page_id = wp_insert_post( array(
     1352                        'post_title' => $page_on_front_title,
     1353                        'post_type' => 'page',
     1354                        'post_status' => 'publish'
     1355                ) );
     1356
     1357                if ( $page_id && ! is_wp_error( $page_id ) )
     1358                        $_POST['page_on_front'] = $page_id;
     1359        }
     1360
     1361        if ( isset( $_POST['page_for_posts'] ) ) {
     1362                $page_for_posts_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) );
     1363                $page_for_posts_slug = esc_html( stripslashes( $_POST['post_name'] ) );
     1364
     1365                $existing_page = get_page_by_path( $page_for_posts_slug );
     1366                if ( $existing_page && 'publish' == $existing_page->post_status && $existing_page->post_title === $page_for_posts_title ) {
     1367                        $_POST['page_for_posts'] = $existing_page->ID;
     1368                } else {
     1369                        $page = get_post( (int) $_POST['page_for_posts'] );
     1370                        if ( ! $page )
     1371                                return;
     1372
     1373                        $page->post_title = $page_for_posts_title;
     1374                        $page->post_name = $page_for_posts_slug;
     1375                        $page->post_status = 'publish';
     1376
     1377                        wp_update_post( $page );
     1378                }
     1379        }
     1380}
     1381add_action( 'admin_init', '_create_pages_for_reading_settings' );
  • wp-admin/js/post.js

     
    569569                                        post_id: post_id,
    570570                                        new_slug: new_slug,
    571571                                        new_title: $('#title').val(),
     572                                        context: pagenow,
    572573                                        samplepermalinknonce: $('#samplepermalinknonce').val()
    573574                                }, function(data) {
    574575                                        $('#edit-slug-box').html(data);
  • wp-admin/options-reading.php

     
    1515$title = __( 'Reading Settings' );
    1616$parent_file = 'options-general.php';
    1717
     18wp_enqueue_script( 'post' );
     19
    1820/**
    1921 * Display JavaScript on the page.
    2022 *
     
    2527?>
    2628<script type="text/javascript">
    2729//<![CDATA[
    28         jQuery(document).ready(function($){
     30        jQuery(document).ready( function($) {
    2931                var section = $('#front-static-pages'),
    30                         staticPage = section.find('input:radio[value="page"]'),
    31                         selects = section.find('select'),
    32                         check_disabled = function(){
    33                                 selects.prop( 'disabled', ! staticPage.prop('checked') );
     32                        frontPage = section.find('input:checkbox[name="show_on_front"]'),
     33                        postsPage = section.find('input:checkbox[name="page_for_posts"]'),
     34                        frontPageSelect = section.find('select'),
     35                        toggleInputs = function() {
     36                                frontPage.closest('p').next().toggle( frontPage.prop('checked') );
     37                                frontPage.closest('p').next().find('label[for$="title"]').toggle( 'new' == frontPageSelect.find(':selected').val() );
     38
     39                                postsPage.closest('p').toggle( frontPage.prop('checked') );
     40                                postsPage.closest('p').next().toggle( postsPage.is(':visible') && postsPage.prop('checked') );
    3441                        };
    35                 check_disabled();
    36                 section.find('input:radio').change(check_disabled);
     42
     43                toggleInputs();
     44                $.each( [ frontPage, postsPage, frontPageSelect ], function() {
     45                        $(this).change( toggleInputs );
     46                });
    3747        });
    3848//]]>
    3949</script>
    4050<?php
    4151}
    42 add_action('admin_head', 'add_js');
     52add_action( 'admin_head', 'add_js' );
    4353
     54/**
     55 * Retrieve or display list of pages as a dropdown (select list).
     56 *
     57 * @since 3.5.0
     58 * @access private
     59 *
     60 * @param array|string $args List attributes.
     61 * @return string HTML content
     62 */
     63function _dropdown_pages( $args ) {
     64        $r = wp_parse_args( $args );
     65        extract( $r, EXTR_SKIP );
     66
     67        $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "'>\n";
     68        $output .= "\t<option value=\"0\">" . __( '&mdash; Select &mdash;' ) . "</option>\n";
     69        $output .= "\t<option value=\"new\" id=\"new-page\">" . __( 'Add New Page' ) . "</option>\n";
     70        $pages = get_pages( $r );
     71        if ( ! empty( $pages ) )
     72                $output .= walk_page_dropdown_tree( $pages, 0, $r );
     73        $output .= "</select>\n";
     74
     75        return apply_filters( 'wp_dropdown_pages', $output );
     76}
     77
    4478get_current_screen()->add_help_tab( array(
    4579        'id'      => 'overview',
    4680        'title'   => __('Overview'),
     
    66100<form name="form1" method="post" action="options.php">
    67101<?php
    68102settings_fields( 'reading' );
     103wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
    69104
    70105function options_reading_blog_charset() {
    71106        echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
     
    76111        add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading' );
    77112else
    78113        echo '<input name="blog_charset" type="hidden" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" />';
    79 ?>
    80114
    81 <?php if ( ! get_pages() ) : ?>
    82 <input name="show_on_front" type="hidden" value="posts" />
    83 <table class="form-table">
    84 <?php
    85         if ( 'posts' != get_option( 'show_on_front' ) ) :
     115if ( 'page' == get_option( 'show_on_front' ) ) {
     116        if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    86117                update_option( 'show_on_front', 'posts' );
    87         endif;
    88118
    89 else :
    90         if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    91                 update_option( 'show_on_front', 'posts' );
     119        if ( get_option( 'page_for_posts' ) ) {
     120                $page_for_posts = get_post( get_option( 'page_for_posts' ) );
     121                if ( 'publish' != $page_for_posts->post_status )
     122                        delete_option( 'page_for_posts' );
     123        }
     124}
     125
     126if ( empty( $page_for_posts ) ) {
     127        $page_for_posts = get_default_post_to_edit( 'page', true );
     128        $page_for_posts->post_title = _x( 'Blog', 'default page for posts title' );
     129        $page_for_posts->post_name = sanitize_title( $page_for_posts->post_title );
     130}
    92131?>
    93132<table class="form-table">
    94133<tr valign="top">
    95 <th scope="row"><?php _e( 'Front page displays' ); ?></th>
    96 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend>
    97         <p><label>
    98                 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> />
    99                 <?php _e( 'Your latest posts' ); ?>
    100         </label>
    101         </p>
    102         <p><label>
    103                 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
    104                 <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?>
    105         </label>
    106         </p>
     134<th scope="row"><?php _e( 'Enable a static front page' ); ?></th>
     135<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend>
     136<p><label>
     137        <input name="show_on_front" type="checkbox" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
     138        <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?>
     139</label>
     140</p>
    107141<ul>
    108         <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li>
    109         <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label></li>
     142        <li>
     143                <label for="page_on_front"><?php echo _dropdown_pages( array( 'name' => 'page_on_front', 'selected' => get_option( 'page_on_front' ) ) ); ?></label>
     144                <label for="page_on_front_title"><?php _e( 'New page title:' ); ?>
     145                        <input name="page_on_front_title" type="text" id="page_on_front_title" value="<?php echo esc_attr_x( 'Home', 'default page on front title' ); ?>" />
     146                </label>
     147        </li>
    110148</ul>
     149<p><label>
     150        <input name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" class="tog" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> />
     151        <?php _e( 'Show latest posts on a separate page' ); ?>
     152</label>
     153</p>
     154<ul>
     155        <li>
     156                <label for="page_for_posts_title"><?php _e( 'Posts page title:' ); ?>
     157                        <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" />
     158                </label>
     159                <p id="edit-slug-box"><?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?></p>
     160                <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" />
     161        </li>
     162</ul>
    111163<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
    112164<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div>
    113165<?php endif; ?>
    114166</fieldset></td>
    115167</tr>
    116 <?php endif; ?>
    117168<tr valign="top">
    118169<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
    119170<td>