Make WordPress Core

Ticket #16379: 16379.8.patch

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

     
    28732873        font-size: 11px;
    28742874}
    28752875
     2876#front-static-pages #edit-slug-box {
     2877        padding: 0;
     2878}
     2879
    28762880#editable-post-name-full {
    28772881        display: none;
    28782882}
  • 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
     1345                $title = esc_html( stripslashes( $_POST['page_on_front_title'] ) );
     1346                $existing_page = get_page_by_title( $title );
     1347
     1348                // If page already exists and it's public, there's no need to create a new page
     1349                if ( $existing_page && 'publish' == $existing_page->post_status ) {
     1350                        $page_id = $existing_page->ID;
     1351                } else {
     1352                        $page_id = wp_insert_post( array(
     1353                                'post_title' => $title,
     1354                                'post_type' => 'page',
     1355                                'post_status' => 'publish'
     1356                        ) );
     1357                }
     1358
     1359                if ( $page_id && ! is_wp_error( $page_id ) )
     1360                        $_POST['page_on_front'] = $page_id;
     1361        }
     1362
     1363        if ( isset( $_POST['page_for_posts'] ) ) {
     1364                if ( ! $page = get_post( (int) $_POST['page_for_posts'] ) )
     1365                        return;
     1366
     1367                $page->post_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) );
     1368                $page->post_name = esc_html( stripslashes( $_POST['post_name'] ) );
     1369                $page->post_status = 'publish';
     1370
     1371                wp_update_post( $page );
     1372        }
     1373}
     1374add_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 *
     
    2426?>
    2527<script type="text/javascript">
    2628//<![CDATA[
    27         jQuery(document).ready(function($){
     29        jQuery(document).ready( function($) {
    2830                var section = $('#front-static-pages'),
    29                         staticPage = section.find('input:radio[value="page"]'),
    30                         selects = section.find('select'),
    31                         check_disabled = function(){
    32                                 selects.prop( 'disabled', ! staticPage.prop('checked') );
     31                        frontPage = section.find('input:checkbox[name="show_on_front"]'),
     32                        postsPage = section.find('input:checkbox[name="page_for_posts"]'),
     33                        frontPageSelect = section.find('select'),
     34                        toggleInputs = function() {
     35                                frontPage.closest('p').next().toggle( frontPage.prop('checked') );
     36                                frontPage.closest('p').next().find('label[for$="title"]').toggle( 'new' == frontPageSelect.find(':selected').val() );
     37
     38                                postsPage.closest('p').toggle( frontPage.prop('checked') );
     39                                postsPage.closest('p').next().toggle( postsPage.is(':visible') && postsPage.prop('checked') );
     40
     41                                if ( ! postsPage.is(':visible') )
     42                                        postsPage.prop('checked', true);
    3343                        };
    34                 check_disabled();
    35                 section.find('input:radio').change(check_disabled);
     44
     45                toggleInputs();
     46                $.each( [ frontPage, postsPage, frontPageSelect ], function() {
     47                        $(this).change( toggleInputs );
     48                });
    3649        });
    3750//]]>
    3851</script>
    3952<?php
    4053}
    41 add_action('admin_head', 'options_reading_add_js');
     54add_action( 'admin_head', 'options_reading_add_js' );
    4255
    4356/**
    4457 * Render the blog charset setting.
     
    5063        echo '<p class="description">' . __( 'The <a href="http://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
    5164}
    5265
     66/**
     67 * Retrieve or display list of pages as a dropdown (select list).
     68 *
     69 * @since 3.5.0
     70 *
     71 * @param array|string $args List attributes.
     72 * @return string HTML content.
     73 */
     74function options_reading_dropdown_pages( $args ) {
     75        $r = wp_parse_args( $args );
     76        extract( $r, EXTR_SKIP );
     77
     78        $pages = get_pages( $r );
     79
     80        // If no pages, or only sample page, show the "Add new page" option by default
     81        $default_add_new = ( ! $selected && ( ! $pages || 1 == count( $pages ) && __( 'sample-page' ) == $pages[0]->post_name ) );
     82       
     83        $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "'>\n";
     84        $output .= "\t" . '<option value="0">' . __( '&mdash; Select &mdash;' ) . "</option>\n";
     85        $output .= "\t" . '<option value="new" id="new-page"' . selected( $default_add_new, true, false ) . '>' . __( 'Add new page' ) . "</option>\n";
     86
     87        if ( $pages )
     88                $output .= walk_page_dropdown_tree( $pages, 0, $r );
     89        $output .= "</select>\n";
     90
     91        return apply_filters( 'wp_dropdown_pages', $output );
     92}
     93
    5394get_current_screen()->add_help_tab( array(
    5495        'id'      => 'overview',
    5596        'title'   => __('Overview'),
     
    82123<form method="post" action="options.php">
    83124<?php
    84125settings_fields( 'reading' );
     126wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
    85127
    86128if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
    87129        add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) );
    88 ?>
    89130
    90 <?php if ( ! get_pages() ) : ?>
    91 <input name="show_on_front" type="hidden" value="posts" />
    92 <table class="form-table">
    93 <?php
    94         if ( 'posts' != get_option( 'show_on_front' ) ) :
     131if ( 'page' == get_option( 'show_on_front' ) ) {
     132        if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    95133                update_option( 'show_on_front', 'posts' );
    96         endif;
     134}
    97135
    98 else :
    99         if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    100                 update_option( 'show_on_front', 'posts' );
     136if ( ! $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) {
     137        $title = _x( 'Blog', 'default page for posts title' );
     138        if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) {
     139                $page_for_posts = get_default_post_to_edit( 'page', true );
     140                $page_for_posts->post_title = $title;
     141                $page_for_posts->post_name = sanitize_title( $title );
     142        }
     143}
    101144?>
    102145<table class="form-table">
    103146<tr valign="top">
    104 <th scope="row"><?php _e( 'Front page displays' ); ?></th>
    105 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend>
    106         <p><label>
    107                 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> />
    108                 <?php _e( 'Your latest posts' ); ?>
    109         </label>
    110         </p>
    111         <p><label>
    112                 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
    113                 <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?>
    114         </label>
    115         </p>
     147<th scope="row"><?php _e( 'Enable a static front page' ); ?></th>
     148<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend>
     149<p><label>
     150        <input name="show_on_front" type="checkbox" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
     151        <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?>
     152</label>
     153</p>
    116154<ul>
    117         <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>
    118         <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>
     155        <li>
     156                <label for="page_on_front"><?php echo options_reading_dropdown_pages( array( 'name' => 'page_on_front', 'selected' => get_option( 'page_on_front' ) ) ); ?></label>
     157                <label for="page_on_front_title"><?php _e( 'titled:' ); ?>
     158                        <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' ); ?>" />
     159                </label>
     160        </li>
    119161</ul>
     162<p><label>
     163        <input name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" class="tog" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> />
     164        <?php _e( 'Show latest posts on a separate page' ); ?>
     165</label>
     166</p>
     167<ul>
     168        <li>
     169                <label for="page_for_posts_title"><?php _e( 'Page title:' ); ?>
     170                        <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" />
     171                </label>
     172                <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>
     173                <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" />
     174        </li>
     175</ul>
    120176<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
    121177<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div>
    122178<?php endif; ?>
    123179</fieldset></td>
    124180</tr>
    125 <?php endif; ?>
    126181<tr valign="top">
    127182<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
    128183<td>