Ticket #16379: 16379.5.patch
File 16379.5.patch, 13.0 KB (added by , 12 years ago) |
---|
-
wp-admin/css/wp-admin.css
2870 2870 font-size: 11px; 2871 2871 } 2872 2872 2873 #front-static-pages #edit-slug-box { 2874 padding: 0; 2875 } 2876 2873 2877 #editable-post-name-full { 2874 2878 display: none; 2875 2879 } -
wp-admin/includes/post.php
1055 1055 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 1056 1056 */ 1057 1057 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 1058 global $wpdb; 1058 global $wpdb, $current_screen; 1059 1059 1060 $post = get_post($id); 1060 1061 1062 if ( isset( $current_screen ) ) 1063 $context = $current_screen->id; 1064 else 1065 $context = isset( $_POST['context'] ) ? $_POST['context'] : ''; 1066 1061 1067 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 1062 1068 1063 1069 if ( 'publish' == $post->post_status ) { … … 1068 1074 $title = __('Temporary permalink. Click to edit this part.'); 1069 1075 } 1070 1076 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"; 1073 1080 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) 1074 1081 $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 ) 1076 1083 $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-tiny'>$view_post</a></span>\n"; 1077 1084 1078 1085 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1095 1102 } 1096 1103 1097 1104 $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"; 1101 1108 $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; 1102 1109 $return .= '‎'; // Fix bi-directional text display defect in RTL languages. 1103 1110 $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"; 1104 1111 $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; 1105 if ( isset( $view_post))1112 if ( isset( $view_post ) && 'options-reading' != $context ) 1106 1113 $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-tiny'>$view_post</a></span>\n"; 1107 1114 1108 1115 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1318 1325 1319 1326 return $url; 1320 1327 } 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 */ 1335 function _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 } 1365 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') ); 41 42 if ( ! postsPage.is(':visible') ) 43 postsPage.prop('checked', true); 34 44 }; 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 }); 37 50 }); 38 51 //]]> 39 52 </script> 40 53 <?php 41 54 } 42 add_action( 'admin_head', 'options_reading_add_js');55 add_action( 'admin_head', 'options_reading_add_js' ); 43 56 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 */ 67 function 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\">" . __( '— Select —' ) . "</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 44 82 get_current_screen()->add_help_tab( array( 45 83 'id' => 'overview', 46 84 'title' => __('Overview'), … … 73 111 <form method="post" action="options.php"> 74 112 <?php 75 113 settings_fields( 'reading' ); 114 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 76 115 77 116 function options_reading_blog_charset() { 78 117 echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />'; … … 81 120 82 121 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) 83 122 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); 84 ?>85 123 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' ) ) : 124 if ( 'page' == get_option( 'show_on_front' ) ) { 125 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 91 126 update_option( 'show_on_front', 'posts' ); 92 endif; 127 } 93 128 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' ); 129 if ( ! $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 } 97 137 ?> 98 138 <table class="form-table"> 99 139 <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> 112 147 <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' => __( '— Select —' ), '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' => __( '— Select —' ), '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> 115 154 </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> 116 169 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 117 170 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 118 171 <?php endif; ?> 119 172 </fieldset></td> 120 173 </tr> 121 <?php endif; ?>122 174 <tr valign="top"> 123 175 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 124 176 <td>