Making WordPress.org


Ignore:
Timestamp:
07/15/2022 12:25:33 AM (3 years ago)
Author:
dufresnesteven
Message:

Learn: Sync with git WordPress/learn@cb551b095dd6941eda68c26750e249d907044142

File:
1 edited

Legend:

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

    r11961 r11966  
    11421142
    11431143/**
     1144 * Redirect old pages to their new homes.
     1145 *
     1146 * @return void
     1147 */
     1148function wporg_learn_redirect_old_urls() {
     1149    if ( ! is_404() ) {
     1150        return;
     1151    }
     1152
     1153    $redirects = array(
     1154        // Source => Destination, any characters after the source will be appended to the destination.
     1155        '/workshop/'                      => '/tutorial/',
     1156        '/workshops'                      => '/tutorials',
     1157        '/social-learning'                => '/online-workshops',
     1158        '/workshop-presenter-application' => '/tutorial-presenter-application',
     1159    );
     1160
     1161    // Use `REQUEST_URI` rather than `$wp->request`, to get the entire source URI including url parameters.
     1162    $request = $_SERVER['REQUEST_URI'] ?? '';
     1163
     1164    foreach ( $redirects as $source => $destination ) {
     1165        if ( str_starts_with( $request, $source ) ) {
     1166            $redirect = $destination;
     1167
     1168            // Append any extra request parameters.
     1169            if ( strlen( $request ) > strlen( $source ) ) {
     1170                $redirect .= substr( $request, strlen( $source ) );
     1171            }
     1172
     1173            wp_safe_redirect( $redirect );
     1174            die();
     1175        }
     1176    }
     1177}
     1178add_action( 'template_redirect', 'wporg_learn_redirect_old_urls' );
     1179
     1180/**
    11441181 * Add file MIME types for upload.
    11451182 *
Note: See TracChangeset for help on using the changeset viewer.