Making WordPress.org


Ignore:
Timestamp:
07/29/2021 07:02:19 PM (3 years ago)
Author:
ryelle
Message:

Pattern Directory: Sync with git WordPress/pattern-directory@83dd83bb283a1f3c47c54b2f07d726d917ca6bd2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php

    r11146 r11159  
    1616
    1717add_filter( 'archive_template', __NAMESPACE__ . '\use_index_php_as_template' );
    18 add_action( 'template_redirect', __NAMESPACE__ . '\rewrite_search_url' );
     18add_action( 'template_redirect', __NAMESPACE__ . '\rewrite_urls' );
    1919
    2020/**
     
    9999                    'site' => esc_url( home_url() ),
    100100                    'login' => esc_url( wp_login_url() ),
     101                    'register' => esc_url( wp_registration_url() ),
    101102                ) ) ),
    102103            ),
     
    178179    if ( $pagename ) {
    179180        list( $_pagename ) = explode( '/', $pagename );
    180         if ( in_array( $_pagename, array( 'my-patterns', 'my-favorites' ) ) ) {
     181        if ( in_array( $_pagename, array( 'my-patterns', 'favorites' ) ) ) {
    181182            // Need to get the page ID because this is set before `pre_get_posts` fires.
    182183            $page = get_page_by_path( $_pagename );
     
    206207function add_rewrite() {
    207208    add_rewrite_rule( '^my-patterns/[^/]+/?$', 'index.php?pagename=my-patterns', 'top' );
    208     add_rewrite_rule( '^my-favorites/.+/?$', 'index.php?pagename=my-favorites', 'top' );
     209    add_rewrite_rule( '^favorites/.+/?$', 'index.php?pagename=favorites', 'top' );
    209210}
    210211
     
    256257
    257258/**
    258  * Rewrites the search url from s={keyword} to /search/{keyword}.
     259 * Set up redirects for the site.
    259260 *
    260261 * @return void
    261262 */
    262 function rewrite_search_url() {
     263function rewrite_urls() {
     264    // Redirect searches to `/search/term`.
    263265    if ( is_search() && ! empty( $_GET['s'] ) ) {
    264266        wp_redirect( home_url( '/search/' ) . urlencode( trim( get_query_var( 's' ) ) ) . '/' );
     267        exit();
     268    }
     269    // Redirect old slug `my-favorites` to `favorites`, see WordPress/pattern-directory#332.
     270    $path = str_replace( 'patterns/', '', trim( $_SERVER['REQUEST_URI'], '/' ) );
     271    if ( preg_match( '/^my-favorites(.*)/', $path, $matches ) ) {
     272        wp_redirect( home_url( '/favorites/' . $matches[1] . '/' ) );
    265273        exit();
    266274    }
Note: See TracChangeset for help on using the changeset viewer.