Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-permalink.php

    r42228 r42343  
    1010require_once( dirname( __FILE__ ) . '/admin.php' );
    1111
    12 if ( ! current_user_can( 'manage_options' ) )
     12if ( ! current_user_can( 'manage_options' ) ) {
    1313    wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) );
    14 
    15 $title = __('Permalink Settings');
     14}
     15
     16$title       = __( 'Permalink Settings' );
    1617$parent_file = 'options-general.php';
    1718
    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 &#8212; 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 &#8220;category&#8221; and &#8220;tag&#8221; base names that will appear in archive URLs. For example, the page listing all posts in the &#8220;Uncategorized&#8221; 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 ) );
     19get_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 &#8212; 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
     29get_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
     40get_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 &#8220;category&#8221; and &#8220;tag&#8221; base names that will appear in archive URLs. For example, the page listing all posts in the &#8220;Uncategorized&#8221; 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);
    4148
    4249get_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>'
    4754);
    4855
    49 $home_path = get_home_path();
    50 $iis7_permalinks = iis7_supports_permalinks();
     56$home_path           = get_home_path();
     57$iis7_permalinks     = iis7_supports_permalinks();
    5158$permalink_structure = get_option( 'permalink_structure' );
    5259
    5360$prefix = $blog_prefix = '';
    54 if ( ! got_url_rewrite() )
     61if ( ! got_url_rewrite() ) {
    5562    $prefix = '/index.php';
     63}
    5664
    5765/**
     
    6573}
    6674
    67 $category_base       = get_option( 'category_base' );
    68 $tag_base            = get_option( 'tag_base' );
    69 $update_required     = false;
     75$category_base   = get_option( 'category_base' );
     76$tag_base        = get_option( 'tag_base' );
     77$update_required = false;
    7078
    7179if ( $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' ) ) {
    7381        $writable = true;
    74     else
     82    } else {
    7583        $writable = false;
     84    }
    7685} elseif ( $is_nginx ) {
    7786    $writable = false;
     
    8089        $writable = true;
    8190    } else {
    82         $writable = false;
     91        $writable        = false;
    8392        $existing_rules  = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
    8493        $new_rules       = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
     
    8998$using_index_permalinks = $wp_rewrite->using_index_permalinks();
    9099
    91 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
    92     check_admin_referer('update-permalink');
     100if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) {
     101    check_admin_referer( 'update-permalink' );
    93102
    94103    if ( isset( $_POST['permalink_structure'] ) ) {
    95         if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
     104        if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) {
    96105            $permalink_structure = $_POST['selection'];
    97         else
     106        } else {
    98107            $permalink_structure = $_POST['permalink_structure'];
     108        }
    99109
    100110        if ( ! empty( $permalink_structure ) ) {
    101111            $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
    102             if ( $prefix && $blog_prefix )
     112            if ( $prefix && $blog_prefix ) {
    103113                $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
    104             else
     114            } else {
    105115                $permalink_structure = $blog_prefix . $permalink_structure;
     116            }
    106117        }
    107118
     
    113124    if ( isset( $_POST['category_base'] ) ) {
    114125        $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        }
    117129        $wp_rewrite->set_category_base( $category_base );
    118130    }
     
    120132    if ( isset( $_POST['tag_base'] ) ) {
    121133        $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        }
    124137        $wp_rewrite->set_tag_base( $tag_base );
    125138    }
     
    155168
    156169<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
    160174        printf(
    161175            /* translators: %s: Codex URL */
     
    163177            __( 'https://codex.wordpress.org/Using_Permalinks' )
    164178        );
    165     ?></p>
     179    ?>
     180    </p>
    166181
    167182<?php
    168183if ( is_multisite() && ! is_subdomain_install() && is_main_site() && 0 === strpos( $permalink_structure, '/blog/' ) ) {
    169184    $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 );
    172187}
    173188
     
    180195);
    181196?>
    182 <h2 class="title"><?php _e('Common Settings'); ?></h2>
     197<h2 class="title"><?php _e( 'Common Settings' ); ?></h2>
    183198<table class="form-table permalink-structure">
    184199    <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>
    203218    </tr>
    204219    <tr>
    205220        <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' ); ?>
    208223            </label>
    209224        </th>
    210225        <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" />
    213228            <div class="available-structure-tags hide-if-no-js">
    214229                <div id="custom_selection_updated" aria-live="assertive" class="screen-reader-text"></div>
     
    261276                            <li>
    262277                                <button type="button"
    263                                         class="button button-secondary"
    264                                         aria-label="<?php echo esc_attr( sprintf( $explanation, $tag ) ); ?>"
    265                                         data-added="<?php echo esc_attr( sprintf( $structure_tag_added, $tag ) ); ?>"
    266                                         data-used="<?php echo esc_attr( sprintf( $structure_tag_already_used, $tag ) ); ?>">
     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 ) ); ?>">
    267282                                    <?php echo '%' . $tag . '%'; ?>
    268283                                </button>
     
    278293</table>
    279294
    280 <h2 class="title"><?php _e('Optional'); ?></h2>
    281 <p><?php
     295<h2 class="title"><?php _e( 'Optional' ); ?></h2>
     296<p>
     297<?php
    282298/* 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>
     299printf( __( '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>
    284302
    285303<table class="form-table">
    286304    <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>
    288306        <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>
    289307    </tr>
    290308    <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' ); ?>
    295313</table>
    296314
    297 <?php do_settings_sections('permalink'); ?>
     315<?php do_settings_sections( 'permalink' ); ?>
    298316
    299317<?php submit_button(); ?>
    300318</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
     321if ( $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
    306327    printf(
    307328        /* translators: 1: web.config, 2: Codex URL, 3: CTRL + a, 4: element code */
     
    312333        '<code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code>'
    313334    );
    314 ?></p>
     335?>
     336</p>
    315337<form action="options-permalink.php" method="post">
    316 <?php wp_nonce_field('update-permalink') ?>
     338<?php wp_nonce_field( 'update-permalink' ); ?>
    317339    <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>
    318340</form>
    319 <p><?php
     341<p>
     342<?php
    320343    printf(
    321344        /* translators: %s: web.config */
     
    323346        '<code>web.config</code>'
    324347    );
    325 ?></p>
     348?>
     349</p>
    326350        <?php else : ?>
    327 <p><?php
     351<p>
     352<?php
    328353    printf(
    329354        /* translators: 1: Codex URL, 2: web.config, 3: CTRL + a */
     
    333358        '<kbd>CTRL + a</kbd>'
    334359    );
    335 ?></p>
     360?>
     361</p>
    336362<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>
    339365</form>
    340 <p><?php
     366<p>
     367<?php
    341368    printf(
    342369        /* translators: %s: web.config */
     
    344371        '<code>web.config</code>'
    345372    );
    346 ?></p>
     373?>
     374</p>
    347375        <?php endif; ?>
    348376    <?php endif; ?>
    349377<?php elseif ( $is_nginx ) : ?>
    350378    <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
     380else :
     381    if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) :
     382    ?>
     383<p>
     384<?php
    354385    printf(
    355386        /* translators: 1: .htaccess, 2: Codex URL, 3: CTRL + a */
     
    359390        '<kbd>CTRL + a</kbd>'
    360391    );
    361 ?></p>
     392?>
     393</p>
    362394<form action="options-permalink.php" method="post">
    363 <?php wp_nonce_field('update-permalink') ?>
     395<?php wp_nonce_field( 'update-permalink' ); ?>
    364396    <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>
    365397</form>
Note: See TracChangeset for help on using the changeset viewer.