Make WordPress Core

Ticket #16379: 16379.patch

File 16379.patch, 6.1 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/includes/post.php

     
    13421342
    13431343        return $url;
    13441344}
     1345
     1346/**
     1347 * Creates a new page to be set as a front page or a posts page in Reading Settings.
     1348 *
     1349 * @since 3.5.0
     1350 * @access private
     1351 */
     1352function _create_new_page() {
     1353        if ( ! isset( $_POST[ 'page_on_front' ] ) && ! isset( $_POST[ 'page_for_posts' ] ) )
     1354                return;
     1355
     1356        if ( 'new' != $_POST[ 'page_on_front' ] && 'new' != $_POST[ 'page_for_posts' ] )
     1357                return;
     1358
     1359        $post_type = get_post_type_object( 'page' );
     1360        if ( ! current_user_can( $post_type->cap->edit_posts ) )
     1361                wp_die( __( 'You are not allowed to create pages on this site.' ) );
     1362
     1363        foreach ( array( 'page_on_front', 'page_for_posts' ) as $option ) {
     1364                if ( ! isset( $_POST[ $option . '_name' ] ) || 'new' != $_POST[ $option ] )
     1365                        continue;
     1366
     1367                $page_title = esc_html( stripslashes( $_POST[ $option . '_name' ] ) );
     1368                $page = get_page_by_title( $page_title );
     1369
     1370                if ( $page && 'publish' == $page->post_status )
     1371                        $page_id = $page->ID;
     1372                else
     1373                        $page_id = wp_insert_post( array( 'post_title' => $page_title, 'post_type' => 'page', 'post_status' => 'publish' ) );
     1374
     1375                $_POST[ $option ] = $page_id;
     1376        }
     1377}
     1378add_action( 'admin_init', '_create_new_page' );
  • wp-admin/options-reading.php

     
    2525?>
    2626<script type="text/javascript">
    2727//<![CDATA[
    28         jQuery(document).ready(function($){
     28        jQuery(document).ready( function($) {
    2929                var section = $('#front-static-pages'),
    3030                        staticPage = section.find('input:radio[value="page"]'),
    3131                        selects = section.find('select'),
    32                         check_disabled = function(){
    33                                 selects.prop( 'disabled', ! staticPage.prop('checked') );
     32                        toggle_selects = function() {
     33                                selects.closest('ul').toggle( staticPage.prop('checked') );
    3434                        };
    35                 check_disabled();
    36                 section.find('input:radio').change(check_disabled);
     35                        toggle_new_page_input = function() {
     36                                $(this).closest('li').find('label[for$="name"], .description').toggle( 'new' == $(this).val() );
     37                        };
     38                       
     39                toggle_selects();
     40                section.find('input:radio').change( toggle_selects );
     41
     42                selects.each( toggle_new_page_input );
     43                selects.change( toggle_new_page_input );
    3744        });
    3845//]]>
    3946</script>
    4047<?php
    4148}
    42 add_action('admin_head', 'add_js');
     49add_action( 'admin_head', 'add_js' );
    4350
     51/**
     52 * Retrieve or display list of pages as a dropdown (select list).
     53 *
     54 * @since 3.5.0
     55 * @access private
     56 *
     57 * @param array|string $args List attributes.
     58 * @return string HTML content
     59 */
     60function _dropdown_pages( $args ) {
     61        $r = wp_parse_args( $args );
     62        extract( $r, EXTR_SKIP );
     63
     64        $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "'>\n";
     65        $output .= "\t<option value=\"0\">" . __( '&mdash; Select &mdash;' ) . "</option>\n";
     66        $pages = get_pages( $r );
     67        if ( ! empty( $pages ) )
     68                $output .= walk_page_dropdown_tree( $pages, 0, $r );
     69        $output .= "\t<option value=\"new\">" . __( 'Create New Page' ) . "</option>\n";
     70        $output .= "</select>\n";
     71
     72        return apply_filters( 'wp_dropdown_pages', $output );
     73}
     74
    4475get_current_screen()->add_help_tab( array(
    4576        'id'      => 'overview',
    4677        'title'   => __('Overview'),
     
    6697<form name="form1" method="post" action="options.php">
    6798<?php settings_fields( 'reading' ); ?>
    6899
    69 <?php if ( ! get_pages() ) : ?>
    70 <input name="show_on_front" type="hidden" value="posts" />
    71 <table class="form-table">
    72100<?php
    73         if ( 'posts' != get_option( 'show_on_front' ) ) :
     101        if ( 'page' == get_option( 'show_on_front' ) && ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) )
    74102                update_option( 'show_on_front', 'posts' );
    75         endif;
    76 
    77 else :
    78         if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
    79                 update_option( 'show_on_front', 'posts' );
    80103?>
    81104<table class="form-table">
    82105<tr valign="top">
     
    93116        </label>
    94117        </p>
    95118<ul>
    96         <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>
    97         <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>
     119        <li>
     120                <label for="page_on_front"><?php printf( __( 'Front page: %s' ), _dropdown_pages( array( 'name' => 'page_on_front', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label>
     121                <label for="page_on_front_name"><?php printf( __( 'New page name: %s' ), '<input type="text" id="page_on_front_name" value="' . _x( 'Home', 'page on front' ) . '" name="page_on_front_name">' ); ?></label>
     122                <p class="description"><?php _e( 'A new page named "Home" will be added and saved as the home page.' ); ?></p>
     123        </li>
     124        <li>
     125                <label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), _dropdown_pages( array( 'name' => 'page_for_posts', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label>
     126                <label for="page_for_posts_name"><?php printf( __( 'New page name: %s' ), '<input type="text" id="page_for_posts_name" value="' . _x( 'Blog', 'page for posts' ) . '" name="page_for_posts_name">' ); ?></label>
     127                <p class="description"><?php _e( 'A new page named "Blog" will be added and saved as the posts page.' ); ?></p>
     128        </li>
    98129</ul>
    99130<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
    100131<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div>
    101132<?php endif; ?>
    102133</fieldset></td>
    103134</tr>
    104 <?php endif; ?>
    105135<tr valign="top">
    106136<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
    107137<td>