Changeset 42343 for trunk/src/wp-admin/options-permalink.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/options-permalink.php
r42228 r42343 10 10 require_once( dirname( __FILE__ ) . '/admin.php' ); 11 11 12 if ( ! current_user_can( 'manage_options' ) ) 12 if ( ! current_user_can( 'manage_options' ) ) { 13 13 wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) ); 14 15 $title = __('Permalink Settings'); 14 } 15 16 $title = __( 'Permalink Settings' ); 16 17 $parent_file = 'options-general.php'; 17 18 18 get_current_screen()->add_help_tab( array( 19 'id' => 'overview', 20 'title' => __('Overview'), 21 'content' => '<p>' . __('Permalinks are the permanent URLs to your individual pages and blog posts, as well as your category and tag archives. A permalink is the web address used to link to your content. The URL to each post should be permanent, and never change — hence the name permalink.') . '</p>' . 22 '<p>' . __( 'This screen allows you to choose your permalink structure. You can choose from common settings or create custom URL structures.' ) . '</p>' . 23 '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>', 24 ) ); 25 26 get_current_screen()->add_help_tab( array( 27 'id' => 'permalink-settings', 28 'title' => __('Permalink Settings'), 29 'content' => '<p>' . __( 'Permalinks can contain useful information, such as the post date, title, or other elements. You can choose from any of the suggested permalink formats, or you can craft your own if you select Custom Structure.' ) . '</p>' . 30 '<p>' . __( 'If you pick an option other than Plain, your general URL path with structure tags (terms surrounded by <code>%</code>) will also appear in the custom structure field and your path can be further modified there.' ) . '</p>' . 31 '<p>' . __('When you assign multiple categories or tags to a post, only one can show up in the permalink: the lowest numbered category. This applies if your custom structure includes <code>%category%</code> or <code>%tag%</code>.') . '</p>' . 32 '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>', 33 ) ); 34 35 get_current_screen()->add_help_tab( array( 36 'id' => 'custom-structures', 37 'title' => __('Custom Structures'), 38 'content' => '<p>' . __('The Optional fields let you customize the “category” and “tag” base names that will appear in archive URLs. For example, the page listing all posts in the “Uncategorized” category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.') . '</p>' . 39 '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>', 40 ) ); 19 get_current_screen()->add_help_tab( 20 array( 21 'id' => 'overview', 22 'title' => __( 'Overview' ), 23 'content' => '<p>' . __( 'Permalinks are the permanent URLs to your individual pages and blog posts, as well as your category and tag archives. A permalink is the web address used to link to your content. The URL to each post should be permanent, and never change — hence the name permalink.' ) . '</p>' . 24 '<p>' . __( 'This screen allows you to choose your permalink structure. You can choose from common settings or create custom URL structures.' ) . '</p>' . 25 '<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>', 26 ) 27 ); 28 29 get_current_screen()->add_help_tab( 30 array( 31 'id' => 'permalink-settings', 32 'title' => __( 'Permalink Settings' ), 33 'content' => '<p>' . __( 'Permalinks can contain useful information, such as the post date, title, or other elements. You can choose from any of the suggested permalink formats, or you can craft your own if you select Custom Structure.' ) . '</p>' . 34 '<p>' . __( 'If you pick an option other than Plain, your general URL path with structure tags (terms surrounded by <code>%</code>) will also appear in the custom structure field and your path can be further modified there.' ) . '</p>' . 35 '<p>' . __( 'When you assign multiple categories or tags to a post, only one can show up in the permalink: the lowest numbered category. This applies if your custom structure includes <code>%category%</code> or <code>%tag%</code>.' ) . '</p>' . 36 '<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>', 37 ) 38 ); 39 40 get_current_screen()->add_help_tab( 41 array( 42 'id' => 'custom-structures', 43 'title' => __( 'Custom Structures' ), 44 'content' => '<p>' . __( 'The Optional fields let you customize the “category” and “tag” base names that will appear in archive URLs. For example, the page listing all posts in the “Uncategorized” category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.' ) . '</p>' . 45 '<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>', 46 ) 47 ); 41 48 42 49 get_current_screen()->set_help_sidebar( 43 '<p><strong>' . __( 'For more information:') . '</strong></p>' .44 '<p>' . __( '<a href="https://codex.wordpress.org/Settings_Permalinks_Screen">Documentation on Permalinks Settings</a>') . '</p>' .45 '<p>' . __( '<a href="https://codex.wordpress.org/Using_Permalinks">Documentation on Using Permalinks</a>') . '</p>' .46 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'50 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 51 '<p>' . __( '<a href="https://codex.wordpress.org/Settings_Permalinks_Screen">Documentation on Permalinks Settings</a>' ) . '</p>' . 52 '<p>' . __( '<a href="https://codex.wordpress.org/Using_Permalinks">Documentation on Using Permalinks</a>' ) . '</p>' . 53 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' 47 54 ); 48 55 49 $home_path = get_home_path();50 $iis7_permalinks = iis7_supports_permalinks();56 $home_path = get_home_path(); 57 $iis7_permalinks = iis7_supports_permalinks(); 51 58 $permalink_structure = get_option( 'permalink_structure' ); 52 59 53 60 $prefix = $blog_prefix = ''; 54 if ( ! got_url_rewrite() ) 61 if ( ! got_url_rewrite() ) { 55 62 $prefix = '/index.php'; 63 } 56 64 57 65 /** … … 65 73 } 66 74 67 $category_base 68 $tag_base 69 $update_required 75 $category_base = get_option( 'category_base' ); 76 $tag_base = get_option( 'tag_base' ); 77 $update_required = false; 70 78 71 79 if ( $iis7_permalinks ) { 72 if ( ( ! file_exists( $home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )80 if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) { 73 81 $writable = true; 74 else82 } else { 75 83 $writable = false; 84 } 76 85 } elseif ( $is_nginx ) { 77 86 $writable = false; … … 80 89 $writable = true; 81 90 } else { 82 $writable = false;91 $writable = false; 83 92 $existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) ); 84 93 $new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) ); … … 89 98 $using_index_permalinks = $wp_rewrite->using_index_permalinks(); 90 99 91 if ( isset( $_POST['permalink_structure']) || isset($_POST['category_base']) ) {92 check_admin_referer( 'update-permalink');100 if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { 101 check_admin_referer( 'update-permalink' ); 93 102 94 103 if ( isset( $_POST['permalink_structure'] ) ) { 95 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) 104 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) { 96 105 $permalink_structure = $_POST['selection']; 97 else106 } else { 98 107 $permalink_structure = $_POST['permalink_structure']; 108 } 99 109 100 110 if ( ! empty( $permalink_structure ) ) { 101 111 $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) ); 102 if ( $prefix && $blog_prefix ) 112 if ( $prefix && $blog_prefix ) { 103 113 $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure ); 104 else114 } else { 105 115 $permalink_structure = $blog_prefix . $permalink_structure; 116 } 106 117 } 107 118 … … 113 124 if ( isset( $_POST['category_base'] ) ) { 114 125 $category_base = $_POST['category_base']; 115 if ( ! empty( $category_base ) ) 116 $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); 126 if ( ! empty( $category_base ) ) { 127 $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); 128 } 117 129 $wp_rewrite->set_category_base( $category_base ); 118 130 } … … 120 132 if ( isset( $_POST['tag_base'] ) ) { 121 133 $tag_base = $_POST['tag_base']; 122 if ( ! empty( $tag_base ) ) 123 $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); 134 if ( ! empty( $tag_base ) ) { 135 $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); 136 } 124 137 $wp_rewrite->set_tag_base( $tag_base ); 125 138 } … … 155 168 156 169 <form name="form" action="options-permalink.php" method="post"> 157 <?php wp_nonce_field('update-permalink') ?> 158 159 <p><?php 170 <?php wp_nonce_field( 'update-permalink' ); ?> 171 172 <p> 173 <?php 160 174 printf( 161 175 /* translators: %s: Codex URL */ … … 163 177 __( 'https://codex.wordpress.org/Using_Permalinks' ) 164 178 ); 165 ?></p> 179 ?> 180 </p> 166 181 167 182 <?php 168 183 if ( is_multisite() && ! is_subdomain_install() && is_main_site() && 0 === strpos( $permalink_structure, '/blog/' ) ) { 169 184 $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure ); 170 $category_base = preg_replace( '|^/?blog|', '', $category_base );171 $tag_base = preg_replace( '|^/?blog|', '', $tag_base );185 $category_base = preg_replace( '|^/?blog|', '', $category_base ); 186 $tag_base = preg_replace( '|^/?blog|', '', $tag_base ); 172 187 } 173 188 … … 180 195 ); 181 196 ?> 182 <h2 class="title"><?php _e( 'Common Settings'); ?></h2>197 <h2 class="title"><?php _e( 'Common Settings' ); ?></h2> 183 198 <table class="form-table permalink-structure"> 184 199 <tr> 185 <th><label><input name="selection" type="radio" value="" <?php checked( '', $permalink_structure); ?> /> <?php _e( 'Plain' ); ?></label></th>186 <td><code><?php echo get_option( 'home'); ?>/?p=123</code></td>187 </tr> 188 <tr> 189 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[1]); ?>" <?php checked($structures[1], $permalink_structure); ?> /> <?php _e('Day and name'); ?></label></th>190 <td><code><?php echo get_option( 'home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td>191 </tr> 192 <tr> 193 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[2]); ?>" <?php checked($structures[2], $permalink_structure); ?> /> <?php _e('Month and name'); ?></label></th>194 <td><code><?php echo get_option( 'home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td>195 </tr> 196 <tr> 197 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[3]); ?>" <?php checked($structures[3], $permalink_structure); ?> /> <?php _e('Numeric'); ?></label></th>198 <td><code><?php echo get_option( 'home') . $blog_prefix . $prefix . '/' . _x( 'archives', 'sample permalink base' ) . '/123'; ?></code></td>199 </tr> 200 <tr> 201 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[4]); ?>" <?php checked($structures[4], $permalink_structure); ?> /> <?php _e('Post name'); ?></label></th>202 <td><code><?php echo get_option( 'home') . $blog_prefix . $prefix . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td>200 <th><label><input name="selection" type="radio" value="" <?php checked( '', $permalink_structure ); ?> /> <?php _e( 'Plain' ); ?></label></th> 201 <td><code><?php echo get_option( 'home' ); ?>/?p=123</code></td> 202 </tr> 203 <tr> 204 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" <?php checked( $structures[1], $permalink_structure ); ?> /> <?php _e( 'Day and name' ); ?></label></th> 205 <td><code><?php echo get_option( 'home' ) . $blog_prefix . $prefix . '/' . date( 'Y' ) . '/' . date( 'm' ) . '/' . date( 'd' ) . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td> 206 </tr> 207 <tr> 208 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[2] ); ?>" <?php checked( $structures[2], $permalink_structure ); ?> /> <?php _e( 'Month and name' ); ?></label></th> 209 <td><code><?php echo get_option( 'home' ) . $blog_prefix . $prefix . '/' . date( 'Y' ) . '/' . date( 'm' ) . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td> 210 </tr> 211 <tr> 212 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[3] ); ?>" <?php checked( $structures[3], $permalink_structure ); ?> /> <?php _e( 'Numeric' ); ?></label></th> 213 <td><code><?php echo get_option( 'home' ) . $blog_prefix . $prefix . '/' . _x( 'archives', 'sample permalink base' ) . '/123'; ?></code></td> 214 </tr> 215 <tr> 216 <th><label><input name="selection" type="radio" value="<?php echo esc_attr( $structures[4] ); ?>" <?php checked( $structures[4], $permalink_structure ); ?> /> <?php _e( 'Post name' ); ?></label></th> 217 <td><code><?php echo get_option( 'home' ) . $blog_prefix . $prefix . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/'; ?></code></td> 203 218 </tr> 204 219 <tr> 205 220 <th> 206 <label><input name="selection" id="custom_selection" type="radio" value="custom" <?php checked( ! in_array($permalink_structure, $structures) ); ?> />207 <?php _e( 'Custom Structure'); ?>221 <label><input name="selection" id="custom_selection" type="radio" value="custom" <?php checked( ! in_array( $permalink_structure, $structures ) ); ?> /> 222 <?php _e( 'Custom Structure' ); ?> 208 223 </label> 209 224 </th> 210 225 <td> 211 <code><?php echo get_option( 'home') . $blog_prefix; ?></code>212 <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr( $permalink_structure); ?>" class="regular-text code" />226 <code><?php echo get_option( 'home' ) . $blog_prefix; ?></code> 227 <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr( $permalink_structure ); ?>" class="regular-text code" /> 213 228 <div class="available-structure-tags hide-if-no-js"> 214 229 <div id="custom_selection_updated" aria-live="assertive" class="screen-reader-text"></div> … … 261 276 <li> 262 277 <button type="button" 263 264 265 266 278 class="button button-secondary" 279 aria-label="<?php echo esc_attr( sprintf( $explanation, $tag ) ); ?>" 280 data-added="<?php echo esc_attr( sprintf( $structure_tag_added, $tag ) ); ?>" 281 data-used="<?php echo esc_attr( sprintf( $structure_tag_already_used, $tag ) ); ?>"> 267 282 <?php echo '%' . $tag . '%'; ?> 268 283 </button> … … 278 293 </table> 279 294 280 <h2 class="title"><?php _e('Optional'); ?></h2> 281 <p><?php 295 <h2 class="title"><?php _e( 'Optional' ); ?></h2> 296 <p> 297 <?php 282 298 /* translators: %s: placeholder that must come at the start of the URL */ 283 printf( __( 'If you like, you may enter custom structures for your category and tag URLs here. For example, using <code>topics</code> as your category base would make your category links like <code>%s/topics/uncategorized/</code>. If you leave these blank the defaults will be used.' ), get_option( 'home' ) . $blog_prefix . $prefix ); ?></p> 299 printf( __( 'If you like, you may enter custom structures for your category and tag URLs here. For example, using <code>topics</code> as your category base would make your category links like <code>%s/topics/uncategorized/</code>. If you leave these blank the defaults will be used.' ), get_option( 'home' ) . $blog_prefix . $prefix ); 300 ?> 301 </p> 284 302 285 303 <table class="form-table"> 286 304 <tr> 287 <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e( 'Category base'); ?></label></th>305 <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e( 'Category base' ); ?></label></th> 288 306 <td><?php echo $blog_prefix; ?> <input name="category_base" id="category_base" type="text" value="<?php echo esc_attr( $category_base ); ?>" class="regular-text code" /></td> 289 307 </tr> 290 308 <tr> 291 <th><label for="tag_base"><?php _e( 'Tag base'); ?></label></th>292 <td><?php echo $blog_prefix; ?> <input name="tag_base" id="tag_base" type="text" value="<?php echo esc_attr( $tag_base); ?>" class="regular-text code" /></td>293 </tr> 294 <?php do_settings_fields( 'permalink', 'optional'); ?>309 <th><label for="tag_base"><?php _e( 'Tag base' ); ?></label></th> 310 <td><?php echo $blog_prefix; ?> <input name="tag_base" id="tag_base" type="text" value="<?php echo esc_attr( $tag_base ); ?>" class="regular-text code" /></td> 311 </tr> 312 <?php do_settings_fields( 'permalink', 'optional' ); ?> 295 313 </table> 296 314 297 <?php do_settings_sections( 'permalink'); ?>315 <?php do_settings_sections( 'permalink' ); ?> 298 316 299 317 <?php submit_button(); ?> 300 318 </form> 301 <?php if ( !is_multisite() ) { ?> 302 <?php if ( $iis7_permalinks ) : 303 if ( isset($_POST['submit']) && $permalink_structure && ! $using_index_permalinks && ! $writable ) : 304 if ( file_exists($home_path . 'web.config') ) : ?> 305 <p><?php 319 <?php if ( ! is_multisite() ) { ?> 320 <?php 321 if ( $iis7_permalinks ) : 322 if ( isset( $_POST['submit'] ) && $permalink_structure && ! $using_index_permalinks && ! $writable ) : 323 if ( file_exists( $home_path . 'web.config' ) ) : 324 ?> 325 <p> 326 <?php 306 327 printf( 307 328 /* translators: 1: web.config, 2: Codex URL, 3: CTRL + a, 4: element code */ … … 312 333 '<code>/<configuration>/<system.webServer>/<rewrite>/<rules></code>' 313 334 ); 314 ?></p> 335 ?> 336 </p> 315 337 <form action="options-permalink.php" method="post"> 316 <?php wp_nonce_field( 'update-permalink')?>338 <?php wp_nonce_field( 'update-permalink' ); ?> 317 339 <p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea></p> 318 340 </form> 319 <p><?php 341 <p> 342 <?php 320 343 printf( 321 344 /* translators: %s: web.config */ … … 323 346 '<code>web.config</code>' 324 347 ); 325 ?></p> 348 ?> 349 </p> 326 350 <?php else : ?> 327 <p><?php 351 <p> 352 <?php 328 353 printf( 329 354 /* translators: 1: Codex URL, 2: web.config, 3: CTRL + a */ … … 333 358 '<kbd>CTRL + a</kbd>' 334 359 ); 335 ?></p> 360 ?> 361 </p> 336 362 <form action="options-permalink.php" method="post"> 337 <?php wp_nonce_field( 'update-permalink')?>338 <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules( true) ); ?></textarea></p>363 <?php wp_nonce_field( 'update-permalink' ); ?> 364 <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules( true ) ); ?></textarea></p> 339 365 </form> 340 <p><?php 366 <p> 367 <?php 341 368 printf( 342 369 /* translators: %s: web.config */ … … 344 371 '<code>web.config</code>' 345 372 ); 346 ?></p> 373 ?> 374 </p> 347 375 <?php endif; ?> 348 376 <?php endif; ?> 349 377 <?php elseif ( $is_nginx ) : ?> 350 378 <p><?php _e( '<a href="https://codex.wordpress.org/Nginx">Documentation on Nginx configuration</a>.' ); ?></p> 351 <?php else: 352 if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) : ?> 353 <p><?php 379 <?php 380 else : 381 if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) : 382 ?> 383 <p> 384 <?php 354 385 printf( 355 386 /* translators: 1: .htaccess, 2: Codex URL, 3: CTRL + a */ … … 359 390 '<kbd>CTRL + a</kbd>' 360 391 ); 361 ?></p> 392 ?> 393 </p> 362 394 <form action="options-permalink.php" method="post"> 363 <?php wp_nonce_field( 'update-permalink')?>395 <?php wp_nonce_field( 'update-permalink' ); ?> 364 396 <p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->mod_rewrite_rules() ); ?></textarea></p> 365 397 </form>
Note: See TracChangeset
for help on using the changeset viewer.