Improve category check in redirect_canonical() when permastruct contains category slug.

[37262] changed a check in `redirect_canonical()` so that it checked
categories in the object cache rather than querying the database. However,
the check was based on the identity of `WP_Term` objects, which in
certain cases can be augmented by the main WP query routine, causing
failures of the `in_array()` check. This caused unnecessary redirects
for URLs where `is_single()` is true, but the URL is different from the
post permalink, such as the `embed` endpoint.

`has_term()` also checks the cache, but does not sufer from this bug.

Props cmillerdev.
Fixes #36602.

git-svn-id: https://develop.svn.wordpress.org/trunk@38216 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-08-08 18:48:53 +00:00
parent b12c1a8ad2
commit 0bbd0f3a5f
2 changed files with 4 additions and 2 deletions

View File

@@ -62,6 +62,9 @@ class Tests_Canonical_Category extends WP_Canonical_UnitTestCase {
// Nonexistent category will redirect to correct one.
array( '/foo/post0/', array( 'url' => '/cat0/post0/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'page' => '' ) ) ),
// Embed URLs should not redirect to post permalinks.
array( '/cat0/post0/embed/', array( 'url' => '/cat0/post0/embed/', 'qv' => array( 'category_name' => 'cat0', 'name' => 'post0', 'embed' => 'true' ) ) ),
);
}
}