Making WordPress.org


Ignore:
Timestamp:
01/12/2015 10:28:01 AM (10 years ago)
Author:
kovshenin
Message:

WordCamp.org: When permalinks is set to /postname/ redirect old /year/month/day/postname/

@see https://make.wordpress.org/community/2014/12/18/while-working-on-the-new-url-structure-project/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-misc.php

    r918 r1128  
    135135}
    136136add_filter( 'get_space_allowed', 'wcorg_modify_default_space_allotment' );
     137
     138/**
     139 * Redirects from /year/month/day/slug/ to /slug/ for new URL formats.
     140 */
     141function wcorg_subdomactories_redirect() {
     142    if ( ! is_404() )
     143        return;
     144
     145    if ( get_option( 'permalink_structure' ) != '/%postname%/' )
     146        return;
     147
     148    // russia.wordcamp.org/2014/2014/11/25/post-name/
     149    if ( ! preg_match( '#^/[0-9]{4}/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$#', $_SERVER['REQUEST_URI'], $matches ) )
     150        return;
     151
     152    wp_safe_redirect( esc_url_raw( set_url_scheme( home_url( $matches[1] ) ) ) );
     153    die();
     154}
     155add_action( 'template_redirect', 'wcorg_subdomactories_redirect' );
Note: See TracChangeset for help on using the changeset viewer.