Ticket #16379: 16379.patch
File 16379.patch, 6.1 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/post.php
1342 1342 1343 1343 return $url; 1344 1344 } 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 */ 1352 function _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 } 1378 add_action( 'admin_init', '_create_new_page' ); -
wp-admin/options-reading.php
25 25 ?> 26 26 <script type="text/javascript"> 27 27 //<![CDATA[ 28 jQuery(document).ready( function($){28 jQuery(document).ready( function($) { 29 29 var section = $('#front-static-pages'), 30 30 staticPage = section.find('input:radio[value="page"]'), 31 31 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') ); 34 34 }; 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 ); 37 44 }); 38 45 //]]> 39 46 </script> 40 47 <?php 41 48 } 42 add_action( 'admin_head', 'add_js');49 add_action( 'admin_head', 'add_js' ); 43 50 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 */ 60 function _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\">" . __( '— Select —' ) . "</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 44 75 get_current_screen()->add_help_tab( array( 45 76 'id' => 'overview', 46 77 'title' => __('Overview'), … … 66 97 <form name="form1" method="post" action="options.php"> 67 98 <?php settings_fields( 'reading' ); ?> 68 99 69 <?php if ( ! get_pages() ) : ?>70 <input name="show_on_front" type="hidden" value="posts" />71 <table class="form-table">72 100 <?php 73 if ( 'p osts' != 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' ) ) ) 74 102 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' );80 103 ?> 81 104 <table class="form-table"> 82 105 <tr valign="top"> … … 93 116 </label> 94 117 </p> 95 118 <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' => __( '— Select —' ), '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' => __( '— Select —' ), '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> 98 129 </ul> 99 130 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 100 131 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 101 132 <?php endif; ?> 102 133 </fieldset></td> 103 134 </tr> 104 <?php endif; ?>105 135 <tr valign="top"> 106 136 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 107 137 <td>