Make WordPress Core


Ignore:
Timestamp:
07/28/2017 05:43:00 PM (7 years ago)
Author:
swissspidy
Message:

Permalinks: Add buttons for the available structure tags to the admin UI.

Often times, it can be confusing to set a custom permalink structure. One has to double-check the documentation, make
sure to correctly insert the structure tag, and hope not to break their site.

With this addition, the available structure tags are being displayed as a list of easily clickable buttons that can be
used to insert tags to the custom structure input field and to remove them again.

Props kpdesign, swissspidy, joedolson, afercia.
Fixes #29872.

File:
1 edited

Legend:

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

    r38720 r41182  
    207207            <code><?php echo get_option('home') . $blog_prefix; ?></code>
    208208            <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" />
     209            <div class="available-structure-tags hide-if-no-js">
     210                <div id="custom_selection_updated" aria-live="assertive" class="screen-reader-text"></div>
     211                <?php
     212                $available_tags = array(
     213                    /* translators: %s: permalink structure tag */
     214                    'year'     => __( '%s (The year of the post, four digits, for example 2004.)' ),
     215                    /* translators: %s: permalink structure tag */
     216                    'monthnum' => __( '%s (Month of the year, for example 05.)' ),
     217                    /* translators: %s: permalink structure tag */
     218                    'day'      => __( '%s (Day of the month, for example 28.)' ),
     219                    /* translators: %s: permalink structure tag */
     220                    'hour'     => __( '%s (Hour of the day, for example 15.)' ),
     221                    /* translators: %s: permalink structure tag */
     222                    'minute'   => __( '%s (Minute of the hour, for example 43.)' ),
     223                    /* translators: %s: permalink structure tag */
     224                    'second'   => __( '%s (Second of the minute, for example 33.)' ),
     225                    /* translators: %s: permalink structure tag */
     226                    'post_id'  => __( '%s (The unique ID of the post, for example 423.)' ),
     227                    /* translators: %s: permalink structure tag */
     228                    'postname' => __( '%s (The sanitized post title (slug).)' ),
     229                    /* translators: %s: permalink structure tag */
     230                    'category' => __( '%s (Category slug. Nested sub-categories appear as nested directories in the URI.)' ),
     231                    /* translators: %s: permalink structure tag */
     232                    'author'   => __( '%s (A sanitized version of the author name.)' ),
     233                );
     234
     235                /**
     236                 * Filters the list of available permalink structure tags on the Permalinks settings page.
     237                 *
     238                 * @since 4.8.0
     239                 *
     240                 * @param array $available_tags A key => value pair of available permalink structure tags.
     241                 */
     242                $available_tags = apply_filters( 'available_permalink_structure_tags', $available_tags );
     243
     244                /* translators: %s: permalink structure tag */
     245                $structure_tag_added = __( '%s added to permalink structure' );
     246
     247                /* translators: %s: permalink structure tag */
     248                $structure_tag_already_used = __( '%s (already used in permalink structure)' );
     249
     250                if ( ! empty( $available_tags ) ) :
     251                    ?>
     252                    <p><?php _e( 'Available tags:' ); ?></p>
     253                    <ul role="list">
     254                        <?php
     255                        foreach ( $available_tags as $tag => $explanation ) {
     256                            ?>
     257                            <li>
     258                                <button type="button"
     259                                        class="button button-secondary"
     260                                        aria-label="<?php echo esc_attr( sprintf( $explanation, $tag ) ); ?>"
     261                                        data-added="<?php echo esc_attr( sprintf( $structure_tag_added, $tag ) ); ?>"
     262                                        data-used="<?php echo esc_attr( sprintf( $structure_tag_already_used, $tag ) ); ?>">
     263                                    <?php echo '%' . $tag . '%'; ?>
     264                                </button>
     265                            </li>
     266                            <?php
     267                        }
     268                        ?>
     269                    </ul>
     270                <?php endif; ?>
     271            </div>
    209272        </td>
    210273    </tr>
Note: See TracChangeset for help on using the changeset viewer.