Making WordPress.org


Ignore:
Timestamp:
10/29/2014 08:07:38 PM (12 years ago)
Author:
coffee2code
Message:

Code Reference: override default handbook configuration (and other affected areas) to make the canonical post type slug plural

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/redirects.php

    r898 r954  
    2525                add_action( 'template_redirect', array( __CLASS__, 'redirect_handbook' ) );
    2626                add_action( 'template_redirect', array( __CLASS__, 'redirect_resources' ) );
    27                 add_action( 'template_redirect', array( __CLASS__, 'redirect_pluralized_handbooks' ), 1 );
     27                add_action( 'template_redirect', array( __CLASS__, 'redirect_singularized_handbooks' ), 1 );
    2828                add_action( 'template_redirect', array( __CLASS__, 'redirect_pluralized_reference_post_types' ), 1 );
    2929        }
    … …  
    6767
    6868        /**
    69          * Redirects requests for the pluralized slugs of the handbooks.
    70          *
    71          * Note: this is a convenience redirect of just the naked slugs and not a
    72          * fix for any deployed links.
     69         * Redirects requests for the singularized form of handbook slugs to the
     70         * pluralized version.
    7371         */
    74         public static function redirect_pluralized_handbooks() {
    75                 $name = get_query_var( 'name' );
     72        public static function redirect_singularized_handbooks() {
     73                $path = trailingslashit( $_SERVER['REQUEST_URI'] );
    7674
    77                 // '/plugins' => '/plugin'
    78                 if ( 'plugins' == $name ) {
    79                         wp_redirect( get_post_type_archive_link( 'plugin-handbook' ), 301 );
     75                // '/plugin' => '/plugins'
     76                if ( 0 === strpos( $path, '/plugin/' ) ) {
     77                        $path = get_post_type_archive_link( 'plugin-handbook' ) . substr( $path, 8 );
     78                        wp_redirect( $path, 301 );
    8079                        exit();
    8180                }
    8281
    83                 // '/themes' => '/theme'
    84                 if ( 'themes' == $name ) {
    85                         wp_redirect( get_post_type_archive_link( 'theme-handbook' ), 301 );
     82                // '/theme' => '/themes'
     83                if ( 0 === strpos( $path, '/theme/' ) ) {
     84                        $path = get_post_type_archive_link( 'theme-handbook' ) . substr( $path, 7 );
     85                        wp_redirect( $path, 301 );
    8686                        exit();
    8787                }
Note: See TracChangeset for help on using the changeset viewer.