Ticket #16379: 16379.8.updated.patch
File 16379.8.updated.patch, 13.5 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/post.php
1059 1059 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 1060 1060 */ 1061 1061 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 1062 global $wpdb; 1062 global $wpdb, $current_screen; 1063 1063 1064 $post = get_post($id); 1064 1065 1066 if ( isset( $current_screen ) ) 1067 $context = $current_screen->id; 1068 else 1069 $context = isset( $_POST['context'] ) ? $_POST['context'] : ''; 1070 1065 1071 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 1066 1072 1067 1073 if ( 'publish' == get_post_status( $post ) ) { … … 1072 1078 $title = __('Temporary permalink. Click to edit this part.'); 1073 1079 } 1074 1080 1075 if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { 1076 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1081 if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) { 1082 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1083 $return .= '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1077 1084 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) 1078 1085 $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; 1079 if ( isset( $view_post))1086 if ( isset( $view_post ) && 'options-reading' == $context ) 1080 1087 $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-small'>$view_post</a></span>\n"; 1081 1088 1082 1089 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1099 1106 } 1100 1107 1101 1108 $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>'; 1102 $display_link = str_replace( array('%pagename%','%postname%'), $post_name_html, $permalink);1103 $view_link = str_replace( array('%pagename%','%postname%'), $post_name, $permalink);1104 $return = '<strong>' . __('Permalink:') . "</strong>\n";1109 $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink ); 1110 $view_link = str_replace( array( '%pagename%', '%postname%' ), $post_name, $permalink ); 1111 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1105 1112 $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; 1106 1113 $return .= '‎'; // Fix bi-directional text display defect in RTL languages. 1107 1114 $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n"; 1108 1115 $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; 1109 if ( isset( $view_post))1116 if ( isset( $view_post ) && 'options-reading' != $context ) 1110 1117 $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n"; 1111 1118 1112 1119 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1322 1329 1323 1330 return $url; 1324 1331 } 1332 1333 /** 1334 * Creates new pages to be set as a front page or a page for posts in Reading Settings. 1335 * 1336 * @since 3.5.0 1337 * @access private 1338 */ 1339 function _create_pages_for_reading_settings() { 1340 if ( ! isset( $_POST['show_on_front'] ) ) 1341 return; 1342 1343 $post_type = get_post_type_object( 'page' ); 1344 if ( ! current_user_can( $post_type->cap->edit_posts ) ) 1345 wp_die( __( 'You are not allowed to create pages on this site.' ) ); 1346 1347 if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) { 1348 1349 $title = esc_html( stripslashes( $_POST['page_on_front_title'] ) ); 1350 $existing_page = get_page_by_title( $title ); 1351 1352 // If page already exists and it's public, there's no need to create a new page 1353 if ( $existing_page && 'publish' == $existing_page->post_status ) { 1354 $page_id = $existing_page->ID; 1355 } else { 1356 $page_id = wp_insert_post( array( 1357 'post_title' => $title, 1358 'post_type' => 'page', 1359 'post_status' => 'publish' 1360 ) ); 1361 } 1362 1363 if ( $page_id && ! is_wp_error( $page_id ) ) 1364 $_POST['page_on_front'] = $page_id; 1365 } 1366 1367 if ( isset( $_POST['page_for_posts'] ) ) { 1368 if ( ! $page = get_post( (int) $_POST['page_for_posts'] ) ) 1369 return; 1370 1371 $page->post_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) ); 1372 $page->post_name = esc_html( stripslashes( $_POST['post_name'] ) ); 1373 $page->post_status = 'publish'; 1374 1375 wp_update_post( $page ); 1376 } 1377 } 1378 add_action( 'admin_init', '_create_pages_for_reading_settings' ); -
wp-admin/js/post.js
576 576 post_id: post_id, 577 577 new_slug: new_slug, 578 578 new_title: $('#title').val(), 579 context: pagenow, 579 580 samplepermalinknonce: $('#samplepermalinknonce').val() 580 581 }, function(data) { 581 582 $('#edit-slug-box').html(data); -
wp-admin/css/wp-admin.css
2934 2934 font-size: 11px; 2935 2935 } 2936 2936 2937 #front-static-pages #edit-slug-box { 2938 padding: 0; 2939 } 2940 2937 2941 #editable-post-name-full { 2938 2942 display: none; 2939 2943 } -
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 * … … 24 26 ?> 25 27 <script type="text/javascript"> 26 28 //<![CDATA[ 27 jQuery(document).ready( function($){29 jQuery(document).ready( function($) { 28 30 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); 33 43 }; 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 }); 36 49 }); 37 50 //]]> 38 51 </script> 39 52 <?php 40 53 } 41 add_action( 'admin_head', 'options_reading_add_js');54 add_action( 'admin_head', 'options_reading_add_js' ); 42 55 43 56 /** 44 57 * Render the blog charset setting. … … 50 63 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>'; 51 64 } 52 65 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 */ 74 function 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">' . __( '— Select —' ) . "</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 53 94 get_current_screen()->add_help_tab( array( 54 95 'id' => 'overview', 55 96 'title' => __('Overview'), … … 82 123 <form method="post" action="options.php"> 83 124 <?php 84 125 settings_fields( 'reading' ); 126 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 85 127 86 128 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) 87 129 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); 88 ?>89 130 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' ) ) : 131 if ( 'page' == get_option( 'show_on_front' ) ) { 132 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 95 133 update_option( 'show_on_front', 'posts' ); 96 endif; 134 } 97 135 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' ); 136 if ( ! $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 } 101 144 ?> 102 145 <table class="form-table"> 103 146 <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> 116 154 <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' => __( '— Select —' ), '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' => __( '— Select —' ), '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> 119 161 </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> 120 176 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 121 177 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 122 178 <?php endif; ?> 123 179 </fieldset></td> 124 180 </tr> 125 <?php endif; ?>126 181 <tr valign="top"> 127 182 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 128 183 <td>