Ticket #16379: 16379.2.patch
File 16379.2.patch, 13.3 KB (added by , 13 years ago) |
---|
-
wp-admin/css/wp-admin.css
2855 2855 padding: 0 10px; 2856 2856 } 2857 2857 2858 #front-static-pages #edit-slug-box { 2859 padding: 0; 2860 } 2861 2858 2862 #editable-post-name-full { 2859 2863 display: none; 2860 2864 } -
wp-admin/includes/post.php
1078 1078 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 1079 1079 */ 1080 1080 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 1081 global $wpdb; 1081 global $wpdb, $current_screen; 1082 1082 1083 $post = get_post($id); 1083 1084 1085 if ( isset( $current_screen ) ) 1086 $context = $current_screen->id; 1087 else 1088 $context = isset( $_POST['context'] ) ? $_POST['context'] : ''; 1089 1084 1090 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 1085 1091 1086 1092 if ( 'publish' == $post->post_status ) { … … 1091 1097 $title = __('Temporary permalink. Click to edit this part.'); 1092 1098 } 1093 1099 1094 if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { 1095 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1100 if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) { 1101 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1102 $return .= '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1096 1103 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) 1097 1104 $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; 1098 if ( isset( $view_post))1105 if ( isset( $view_post ) && 'options-reading' == $context ) 1099 1106 $return .= "<span id='view-post-btn'><a href='$permalink' class='button'>$view_post</a></span>\n"; 1100 1107 1101 1108 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1118 1125 } 1119 1126 1120 1127 $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>'; 1121 $display_link = str_replace( array('%pagename%','%postname%'), $post_name_html, $permalink);1122 $view_link = str_replace( array('%pagename%','%postname%'), $post_name, $permalink);1123 $return = '<strong>' . __('Permalink:') . "</strong>\n";1128 $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink ); 1129 $view_link = str_replace( array( '%pagename%', '%postname%' ), $post_name, $permalink ); 1130 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1124 1131 $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; 1125 1132 $return .= '‎'; // Fix bi-directional text display defect in RTL languages. 1126 1133 $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"; 1127 1134 $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; 1128 if ( isset( $view_post))1135 if ( isset( $view_post ) && 'options-reading' != $context ) 1129 1136 $return .= "<span id='view-post-btn'><a href='$view_link' class='button'>$view_post</a></span>\n"; 1130 1137 1131 1138 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1343 1350 1344 1351 return $url; 1345 1352 } 1353 1354 /** 1355 * Creates new pages to be set as a front page or a page for posts in Reading Settings. 1356 * 1357 * @since 3.5.0 1358 * @access private 1359 */ 1360 function _create_pages_for_reading_settings() { 1361 if ( ! isset( $_POST['show_on_front'] ) ) 1362 return; 1363 1364 $post_type = get_post_type_object( 'page' ); 1365 if ( ! current_user_can( $post_type->cap->edit_posts ) ) 1366 wp_die( __( 'You are not allowed to create pages on this site.' ) ); 1367 1368 if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) { 1369 $page_on_front_title = esc_html( stripslashes( $_POST['page_on_front_title'] ) ); 1370 1371 $page_id = wp_insert_post( array( 1372 'post_title' => $page_on_front_title, 1373 'post_type' => 'page', 1374 'post_status' => 'publish' 1375 ) ); 1376 1377 if ( $page_id && ! is_wp_error( $page_id ) ) 1378 $_POST['page_on_front'] = $page_id; 1379 } 1380 1381 if ( isset( $_POST['page_for_posts'] ) ) { 1382 $page_for_posts_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) ); 1383 $page_for_posts_slug = esc_html( stripslashes( $_POST['post_name'] ) ); 1384 1385 $existing_page = get_page_by_path( $page_for_posts_slug ); 1386 if ( $existing_page && 'publish' == $existing_page->post_status && $existing_page->post_title === $page_for_posts_title ) { 1387 $_POST['page_for_posts'] = $existing_page->ID; 1388 } else { 1389 $page = get_post( (int) $_POST['page_for_posts'] ); 1390 if ( ! $page ) 1391 return; 1392 1393 $page->post_title = $page_for_posts_title; 1394 $page->post_name = $page_for_posts_slug; 1395 $page->post_status = 'publish'; 1396 1397 wp_update_post( $page ); 1398 } 1399 } 1400 } 1401 add_action( 'admin_init', '_create_pages_for_reading_settings' ); -
wp-admin/js/post.js
569 569 post_id: post_id, 570 570 new_slug: new_slug, 571 571 new_title: $('#title').val(), 572 context: pagenow, 572 573 samplepermalinknonce: $('#samplepermalinknonce').val() 573 574 }, function(data) { 574 575 $('#edit-slug-box').html(data); -
wp-admin/options-reading.php
15 15 $title = __( 'Reading Settings' ); 16 16 $parent_file = 'options-general.php'; 17 17 18 wp_enqueue_script( 'post' ); 19 18 20 /** 19 21 * Display JavaScript on the page. 20 22 * … … 25 27 ?> 26 28 <script type="text/javascript"> 27 29 //<![CDATA[ 28 jQuery(document).ready( function($){30 jQuery(document).ready( function($) { 29 31 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') ); 34 41 }; 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 }); 37 47 }); 38 48 //]]> 39 49 </script> 40 50 <?php 41 51 } 42 add_action( 'admin_head', 'add_js');52 add_action( 'admin_head', 'add_js' ); 43 53 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 */ 63 function _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\">" . __( '— Select —' ) . "</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 44 78 get_current_screen()->add_help_tab( array( 45 79 'id' => 'overview', 46 80 'title' => __('Overview'), … … 66 100 <form name="form1" method="post" action="options.php"> 67 101 <?php 68 102 settings_fields( 'reading' ); 103 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 69 104 70 105 function options_reading_blog_charset() { 71 106 echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />'; … … 76 111 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading' ); 77 112 else 78 113 echo '<input name="blog_charset" type="hidden" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" />'; 79 ?>80 114 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' ) ) : 115 if ( 'page' == get_option( 'show_on_front' ) ) { 116 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 86 117 update_option( 'show_on_front', 'posts' ); 87 endif;88 118 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 if ( empty( $page_for_posts ) ) { 126 $page_for_posts = get_default_post_to_edit( 'page', true ); 127 $page_for_posts->post_title = _x( 'Blog', 'default page for posts title' ); 128 $page_for_posts->post_name = sanitize_title( $page_for_posts->post_title ); 129 } 130 } 92 131 ?> 93 132 <table class="form-table"> 94 133 <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> 107 141 <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' => __( '— Select —' ), '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' => __( '— Select —' ), '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> 110 148 </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> 111 163 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 112 164 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 113 165 <?php endif; ?> 114 166 </fieldset></td> 115 167 </tr> 116 <?php endif; ?>117 168 <tr valign="top"> 118 169 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 119 170 <td>