Make WordPress Core

Changeset 53713


Ignore:
Timestamp:
07/17/2022 01:36:27 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use a single input array on Permalink Settings screen.

This reduces the amount of code to edit in case of any changes to the default permalink structures.

Follow-up to [53706], [53710].

See #55647, #55498.

File:
1 edited

Legend:

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

    r53712 r53713  
    239239}
    240240
     241$url_base = home_url( $blog_prefix . $index_php_prefix );
     242
    241243$default_structures = array(
    242         0 => '',
    243         1 => $index_php_prefix . '/%year%/%monthnum%/%day%/%postname%/',
    244         2 => $index_php_prefix . '/%year%/%monthnum%/%postname%/',
    245         3 => $index_php_prefix . '/' . _x( 'archives', 'sample permalink base' ) . '/%post_id%',
    246         4 => $index_php_prefix . '/%postname%/',
    247 );
    248 
    249 $url_base = home_url( $blog_prefix . $index_php_prefix );
    250 
    251 $default_structure_inputs = array(
    252         0 => array(
     244        array(
    253245                'id'      => 'plain',
    254246                'label'   => __( 'Plain' ),
     247                'value'   => '',
    255248                'example' => home_url( '/?p=123' ),
    256                 'value'   => $default_structures[0],
    257249        ),
    258         1 => array(
     250        array(
    259251                'id'      => 'day-name',
    260252                'label'   => __( 'Day and name' ),
     253                'value'   => $index_php_prefix . '/%year%/%monthnum%/%day%/%postname%/',
    261254                'example' => $url_base . '/' . gmdate( 'Y/m/d' ) . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/',
    262                 'value'   => $default_structures[1],
    263255        ),
    264         2 => array(
     256        array(
    265257                'id'      => 'month-name',
    266258                'label'   => __( 'Month and name' ),
     259                'value'   => $index_php_prefix . '/%year%/%monthnum%/%postname%/',
    267260                'example' => $url_base . '/' . gmdate( 'Y/m' ) . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/',
    268                 'value'   => $default_structures[2],
    269261        ),
    270         3 => array(
    271                 'id'      => 'day-numeric',
     262        array(
     263                'id'      => 'numeric',
    272264                'label'   => __( 'Numeric' ),
     265                'value'   => $index_php_prefix . '/' . _x( 'archives', 'sample permalink base' ) . '/%post_id%',
    273266                'example' => $url_base . '/' . _x( 'archives', 'sample permalink base' ) . '/123',
    274                 'value'   => $default_structures[3],
    275267        ),
    276         4 => array(
     268        array(
    277269                'id'      => 'post-name',
    278270                'label'   => __( 'Post name' ),
     271                'value'   => $index_php_prefix . '/%postname%/',
    279272                'example' => $url_base . '/' . _x( 'sample-post', 'sample permalink structure' ) . '/',
    280                 'value'   => $default_structures[4],
    281273        ),
    282274);
     275
     276$default_structure_values = wp_list_pluck( $default_structures, 'value' );
    283277
    284278$available_tags = array(
    … …  
    337331                <fieldset class="structure-selection">
    338332                        <legend class="screen-reader-text"><?php _e( 'Permalink structure' ); ?></legend>
    339                         <?php foreach ( $default_structure_inputs as $input ) : ?>
     333                        <?php foreach ( $default_structures as $input ) : ?>
    340334                        <div class="row">
    341335                                <input id="permalink-input-<?php echo $input['id']; ?>"
    … …  
    356350                                <input id="custom_selection"
    357351                                        name="selection" type="radio" value="custom"
    358                                         <?php checked( ! in_array( $permalink_structure, $default_structures, true ) ); ?>
     352                                        <?php checked( ! in_array( $permalink_structure, $default_structure_values, true ) ); ?>
    359353                                />
    360354                                <div>
Note: See TracChangeset for help on using the changeset viewer.