Ticket #16379: 16379.7.diff
File 16379.7.diff, 13.5 KB (added by , 12 years ago) |
---|
-
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 1345 $page_with_title = get_page_by_title( $_POST['page_on_front_title'] ); 1346 1347 // If page already exists and it's public, there's no need to create a new page 1348 if ( $page_with_title && 'publish' == $page_with_title->post_status ) { 1349 $page_id = $page_with_title->ID; 1350 } else { 1351 $page_id = wp_insert_post( array( 1352 'post_title' => esc_html( stripslashes( $_POST['page_on_front_title'] ) ), 1353 'post_type' => 'page', 1354 'post_status' => 'publish' 1355 ) ); 1356 } 1357 1358 if ( $page_id && ! is_wp_error( $page_id ) ) 1359 $_POST['page_on_front'] = $page_id; 1360 } 1361 1362 if ( isset( $_POST['page_for_posts'] ) ) { 1363 if ( ! $page = get_post( (int) $_POST['page_for_posts'] ) ) 1364 return; 1365 1366 $page->post_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) ); 1367 $page->post_name = esc_html( stripslashes( $_POST['post_name'] ) ); 1368 $page->post_status = 'publish'; 1369 1370 wp_update_post( $page ); 1371 } 1372 } 1373 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/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/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 $pages = get_pages( $r ); 78 $default_add_new = ''; 79 80 // If no pages, or only sample page, show the "Add new page" option be default 81 if ( empty( $pages ) || 1 == count($pages) && 'sample-page' == $pages[0]->post_name ) 82 $default_add_new = 'selected="selected"'; 83 84 $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $name ) . "'>\n"; 85 $output .= "\t<option value=\"0\">" . __( '— Select —' ) . "</option>\n"; 86 $output .= "\t<option value=\"new\" id=\"new-page\" " . $default_add_new . ">" . __( 'Add new page' ) . "</option>\n"; 87 88 if ( ! empty( $pages ) ) 89 $output .= walk_page_dropdown_tree( $pages, 0, $r ); 90 $output .= "</select>\n"; 91 92 return apply_filters( 'wp_dropdown_pages', $output ); 93 } 94 53 95 get_current_screen()->add_help_tab( array( 54 96 'id' => 'overview', 55 97 'title' => __('Overview'), … … 82 124 <form method="post" action="options.php"> 83 125 <?php 84 126 settings_fields( 'reading' ); 127 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 85 128 86 129 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) 87 130 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); 88 ?>89 131 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' ) ) : 132 if ( 'page' == get_option( 'show_on_front' ) ) { 133 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 95 134 update_option( 'show_on_front', 'posts' ); 96 endif; 135 } 97 136 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' ); 137 if ( ! $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) { 138 $title = _x( 'Blog', 'default page for posts title' ); 139 if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) { 140 $page_for_posts = get_default_post_to_edit( 'page', true ); 141 $page_for_posts->post_title = $title; 142 $page_for_posts->post_name = sanitize_title( $title ); 143 } 144 } 101 145 ?> 102 146 <table class="form-table"> 103 147 <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> 148 <th scope="row"><?php _e( 'Enable a static front page' ); ?></th> 149 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend> 150 <p><label> 151 <input name="show_on_front" type="checkbox" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 152 <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?> 153 </label> 154 </p> 116 155 <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> 156 <li> 157 <label for="page_on_front"><?php echo options_reading_dropdown_pages( array( 'name' => 'page_on_front', 'selected' => get_option( 'page_on_front' ) ) ); ?></label> 158 <label for="page_on_front_title"><?php _e( 'titled:' ); ?> 159 <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' ); ?>" /> 160 </label> 161 </li> 119 162 </ul> 163 <p><label> 164 <input name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" class="tog" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> /> 165 <?php _e( 'Show latest posts on a separate page' ); ?> 166 </label> 167 </p> 168 <ul> 169 <li> 170 <label for="page_for_posts_title"><?php _e( 'Page title:' ); ?> 171 <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" /> 172 </label> 173 <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> 174 <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" /> 175 </li> 176 </ul> 120 177 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 121 178 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 122 179 <?php endif; ?> 123 180 </fieldset></td> 124 181 </tr> 125 <?php endif; ?>126 182 <tr valign="top"> 127 183 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 128 184 <td>