Skip to content

Commit b05fbba

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@53713 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b2f108b commit b05fbba

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/wp-admin/options-permalink.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,49 +238,43 @@
238238
$tag_base = preg_replace( '|^/?blog|', '', $tag_base );
239239
}
240240

241-
$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-
249241
$url_base = home_url( $blog_prefix . $index_php_prefix );
250242

251-
$default_structure_inputs = array(
252-
0 => array(
243+
$default_structures = 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
);
283275

276+
$default_structure_values = wp_list_pluck( $default_structures, 'value' );
277+
284278
$available_tags = array(
285279
/* translators: %s: Permalink structure tag. */
286280
'year' => __( '%s (The year of the post, four digits, for example 2004.)' ),
@@ -336,7 +330,7 @@
336330
<td>
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']; ?>"
342336
name="selection" aria-describedby="permalink-<?php echo $input['id']; ?>"
@@ -355,7 +349,7 @@
355349
<div class="row">
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>
361355
<label for="custom_selection"><?php _e( 'Custom Structure' ); ?></label>

0 commit comments

Comments
 (0)