Make WordPress Core

Ticket #16379: 16379.5.patch

File 16379.5.patch, 13.0 KB (added by SergeyBiryukov, 12 years ago)

Refreshed after [21856]

  • wp-admin/css/wp-admin.css

     
    28702870        font-size: 11px;
    28712871}
    28722872
     2873#front-static-pages #edit-slug-box {
     2874        padding: 0;
     2875}
     2876
    28732877#editable-post-name-full {
    28742878        display: none;
    28752879}
  • wp-admin/includes/post.php

     
    10551055 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
    10561056 */
    10571057function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
    1058         global $wpdb;
     1058        global $wpdb, $current_screen;
     1059
    10591060        $post = get_post($id);
    10601061
     1062        if ( isset( $current_screen ) )
     1063                $context = $current_screen->id;
     1064        else
     1065                $context = isset( $_POST['context'] ) ? $_POST['context'] : '';
     1066
    10611067        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    10621068
    10631069        if ( 'publish' == $post->post_status ) {
     
    10681074                $title = __('Temporary permalink. Click to edit this part.');
    10691075        }
    10701076
    1071         if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
    1072                 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
     1077        if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
     1078                $return  = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     1079                $return .= '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
    10731080                if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
    10741081                        $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-tiny" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    1075                 if ( isset($view_post) )
     1082                if ( isset( $view_post ) && 'options-reading' == $context )
    10761083                        $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-tiny'>$view_post</a></span>\n";
    10771084
    10781085                $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
     
    10951102        }
    10961103
    10971104        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    1098         $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
    1099         $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
    1100         $return =  '<strong>' . __('Permalink:') . "</strong>\n";
     1105        $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink );
     1106        $view_link = str_replace( array( '%pagename%', '%postname%' ), $post_name, $permalink );
     1107        $return  = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
    11011108        $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
    11021109        $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
    11031110        $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-tiny hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    11041111        $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    1105         if ( isset($view_post) )
     1112        if ( isset( $view_post ) && 'options-reading' != $context )
    11061113                $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-tiny'>$view_post</a></span>\n";
    11071114
    11081115        $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
     
    13181325
    13191326        return $url;
    13201327}
     1328
     1329/**
     1330 * Creates new pages to be set as a front page or a page for posts in Reading Settings.
     1331 *
     1332 * @since 3.5.0
     1333 * @access private
     1334 */
     1335function _create_pages_for_reading_settings() {
     1336        if ( ! isset( $_POST['show_on_front'] ) )
     1337                return;
     1338
     1339        $post_type = get_post_type_object( 'page' );
     1340        if ( ! current_user_can( $post_type->cap->edit_posts ) )
     1341                wp_die( __( 'You are not allowed to create pages on this site.' ) );
     1342
     1343        if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) {
     1344                $page_id = wp_insert_post( array(
     1345                        'post_title' => esc_html( stripslashes( $_POST['page_on_front_title'] ) ),
     1346                        'post_type' => 'page',
     1347                        'post_status' => 'publish'
     1348                ) );
     1349
     1350                if ( $page_id && ! is_wp_error( $page_id ) )
     1351                        $_POST['page_on_front'] = $page_id;
     1352        }
     1353
     1354        if ( isset( $_POST['page_for_posts'] ) ) {
     1355                if ( ! $page = get_post( (int) $_POST['page_for_posts'] ) )
     1356                        return;
     1357
     1358                $page->post_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) );
     1359                $page->post_name = esc_html( stripslashes( $_POST['post_name'] ) );
     1360                $page->post_status = 'publish';
     1361
     1362                wp_update_post( $page );
     1363        }
     1364}
     1365add_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') );
     41
     42                                if ( ! postsPage.is(':visible') )
     43                                        postsPage.prop('checked', true);
    3444                        };
    35                 check_disabled();
    36                 section.find('input:radio').change(check_disabled);
     45
     46                toggleInputs();
     47                $.each( [ frontPage, postsPage, frontPageSelect ], function() {
     48                        $(this).change( toggleInputs );
     49                });
    3750        });
    3851//]]>
    3952</script>
    4053<?php
    4154}
    42 add_action('admin_head', 'options_reading_add_js');
     55add_action( 'admin_head', 'options_reading_add_js' );
    4356
     57/**
     58 * Retrieve or display list of pages as a dropdown (select list).
     59 *
     60 * @package WordPress
     61 * @subpackage Reading_Settings_Screen
     62 * @since 3.5.0
     63 *
     64 * @param array|string $args List attributes.
     65 * @return string HTML content
     66 */
     67function options_reading_dropdown_pages( $args ) {
     68        $r = wp_parse_args( $args );
     69        extract( $r, EXTR_SKIP );
     70
     71        $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "'>\n";
     72        $output .= "\t<option value=\"0\">" . __( '&mdash; Select &mdash;' ) . "</option>\n";
     73        $output .= "\t<option value=\"new\" id=\"new-page\">" . __( 'Add New Page' ) . "</option>\n";
     74        $pages = get_pages( $r );
     75        if ( ! empty( $pages ) )
     76                $output .= walk_page_dropdown_tree( $pages, 0, $r );
     77        $output .= "</select>\n";
     78
     79        return apply_filters( 'wp_dropdown_pages', $output );
     80}
     81
    4482get_current_screen()->add_help_tab( array(
    4583        'id'      => 'overview',
    4684        'title'   => __('Overview'),
     
    73111<form method="post" action="options.php">
    74112<?php
    75113settings_fields( 'reading' );
     114wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
    76115
    77116function options_reading_blog_charset() {
    78117        echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
     
    81120
    82121if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
    83122        add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) );
    84 ?>
    85123
    86 <?php if ( ! get_pages() ) : ?>
    87 <input name="show_on_front" type="hidden" value="posts" />
    88 <table class="form-table">
    89 <?php
    90         if ( 'posts' != get_option( 'show_on_front' ) ) :
     124if ( 'page' == get_option( 'show_on_front' ) ) {
     125        if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    91126                update_option( 'show_on_front', 'posts' );
    92         endif;
     127}
    93128
    94 else :
    95         if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    96                 update_option( 'show_on_front', 'posts' );
     129if ( ! $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) {
     130        $title = _x( 'Blog', 'default page for posts title' );
     131        if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) {
     132                $page_for_posts = get_default_post_to_edit( 'page', true );
     133                $page_for_posts->post_title = $title;
     134                $page_for_posts->post_name = sanitize_title( $title );
     135        }
     136}
    97137?>
    98138<table class="form-table">
    99139<tr valign="top">
    100 <th scope="row"><?php _e( 'Front page displays' ); ?></th>
    101 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend>
    102         <p><label>
    103                 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> />
    104                 <?php _e( 'Your latest posts' ); ?>
    105         </label>
    106         </p>
    107         <p><label>
    108                 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
    109                 <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?>
    110         </label>
    111         </p>
     140<th scope="row"><?php _e( 'Enable a static front page' ); ?></th>
     141<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend>
     142<p><label>
     143        <input name="show_on_front" type="checkbox" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
     144        <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?>
     145</label>
     146</p>
    112147<ul>
    113         <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>
    114         <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>
     148        <li>
     149                <label for="page_on_front"><?php echo options_reading_dropdown_pages( array( 'name' => 'page_on_front', 'selected' => get_option( 'page_on_front' ) ) ); ?></label>
     150                <label for="page_on_front_title"><?php _e( 'New page title:' ); ?>
     151                        <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' ); ?>" />
     152                </label>
     153        </li>
    115154</ul>
     155<p><label>
     156        <input name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" class="tog" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> />
     157        <?php _e( 'Show latest posts on a separate page' ); ?>
     158</label>
     159</p>
     160<ul>
     161        <li>
     162                <label for="page_for_posts_title"><?php _e( 'Posts page title:' ); ?>
     163                        <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" />
     164                </label>
     165                <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>
     166                <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" />
     167        </li>
     168</ul>
    116169<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
    117170<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div>
    118171<?php endif; ?>
    119172</fieldset></td>
    120173</tr>
    121 <?php endif; ?>
    122174<tr valign="top">
    123175<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
    124176<td>