mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 19:46:21 +00:00
Rewrite: When redirecting old slugs, include URL endpoints.
Historically, `wp_old_slug_redirect()` has only ever redirected the old slug of posts, it hasn't included URL endpoints, or worked with comment feed URLs. By adding support for these, we ensure a greater range of URLs aren't killed when the slug changes. Props swissspdy. Fixes #33920. Built from https://develop.svn.wordpress.org/trunk@34659 git-svn-id: http://core.svn.wordpress.org/trunk@34623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8bb4c2c2e9
commit
635d3bb34e
@ -4725,12 +4725,14 @@ class WP_Query {
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @global WP_Query $wp_query Global WP_Query instance.
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
* @global WP_Query $wp_query Global WP_Query instance.
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
|
||||
*/
|
||||
function wp_old_slug_redirect() {
|
||||
global $wp_query;
|
||||
if ( is_404() && '' != $wp_query->query_vars['name'] ) :
|
||||
global $wp_query, $wp_rewrite;
|
||||
|
||||
if ( '' !== $wp_query->query_vars['name'] ) :
|
||||
global $wpdb;
|
||||
|
||||
// Guess the current post_type based on the query vars.
|
||||
@ -4767,10 +4769,33 @@ function wp_old_slug_redirect() {
|
||||
if ( ! $id )
|
||||
return;
|
||||
|
||||
$link = get_permalink($id);
|
||||
$link = get_permalink( $id );
|
||||
|
||||
if ( !$link )
|
||||
if ( is_feed() ) {
|
||||
$link = user_trailingslashit( trailingslashit( $link ) . 'feed' );
|
||||
} elseif ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) {
|
||||
$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged'] );
|
||||
} elseif ( is_404() ) {
|
||||
// Add rewrite endpoints if necessary.
|
||||
foreach ( $wp_rewrite->endpoints as $endpoint ) {
|
||||
if ( $endpoint[2] && false !== get_query_var( $endpoint[2], false ) ) {
|
||||
$link = user_trailingslashit( trailingslashit( $link ) . $endpoint[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the old slug redirect URL.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $link The redirect URL.
|
||||
*/
|
||||
$link = apply_filters( 'old_slug_redirect_url', $link );
|
||||
|
||||
if ( ! $link ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_redirect( $link, 301 ); // Permanent redirect
|
||||
exit;
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34658';
|
||||
$wp_version = '4.4-alpha-34659';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
x
Reference in New Issue
Block a user