Changeset 11966 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
- Timestamp:
- 07/15/2022 12:25:33 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r11961 r11966 1142 1142 1143 1143 /** 1144 * Redirect old pages to their new homes. 1145 * 1146 * @return void 1147 */ 1148 function 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 } 1178 add_action( 'template_redirect', 'wporg_learn_redirect_old_urls' ); 1179 1180 /** 1144 1181 * Add file MIME types for upload. 1145 1182 *
Note: See TracChangeset
for help on using the changeset viewer.