Making WordPress.org


Ignore:
Timestamp:
10/10/2014 10:24:46 PM (12 years ago)
Author:
coffee2code
Message:

Code Reference: redirect singularized slugs for parsed post types to correct pluralized version

File:
1 edited

Legend:

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

    r897 r898  
    2626                add_action( 'template_redirect', array( __CLASS__, 'redirect_resources' ) );
    2727                add_action( 'template_redirect', array( __CLASS__, 'redirect_pluralized_handbooks' ), 1 );
     28                add_action( 'template_redirect', array( __CLASS__, 'redirect_pluralized_reference_post_types' ), 1 );
    2829        }
    2930
    … …  
    8788        }
    8889
     90        /**
     91         * Redirects requests for the pluralized slugs of the code reference parsed
     92         * post types.
     93         *
     94         * Note: this is a convenience redirect and not a fix for any officially
     95         * deployed links.
     96         */
     97        public static function redirect_pluralized_reference_post_types() {
     98                $path = trailingslashit( $_SERVER['REQUEST_URI'] );
     99
     100                $post_types = array(
     101                        'class'    => 'classes',
     102                        'function' => 'functions',
     103                        'hook'     => 'hooks',
     104                        'method'   => 'methods',
     105                );
     106
     107                // '/reference/$singular(/*)?' => '/reference/$plural(/*)?'
     108                foreach ( $post_types as $post_type_slug_singular => $post_type_slug_plural ) {
     109                        if ( 0 === stripos( $path, "/reference/{$post_type_slug_singular}/" ) ) {
     110                                $path = "/reference/{$post_type_slug_plural}/" . substr( $path, strlen( "/reference/{$post_type_slug_singular}/" ) );
     111                                wp_redirect( $path, 301 );
     112                                exit();
     113                        }
     114                }
     115        }
     116
    89117} // DevHub_Redirects
    90118
Note: See TracChangeset for help on using the changeset viewer.