[wp-trac] [WordPress Trac] #23074: Changing post's URL and then setting it back causes redirect loop (wp_old_slug_redirect)
WordPress Trac
noreply at wordpress.org
Thu Nov 23 15:17:29 UTC 2023
#23074: Changing post's URL and then setting it back causes redirect loop
(wp_old_slug_redirect)
-------------------------------------------------+-------------------------
Reporter: vbuterin | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.5
Component: Canonical | Version: 3.5
Severity: major | Resolution:
Keywords: has-patch needs-refresh has-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Comment (by afercia):
Replying to [comment:15 MikeHansenMe]:
> Looking at the code in wp_check_for_changed_slugs I think the problem is
that the function returns before it ever gets to add/remove slugs because
the post is not publish status. I have a patch for
wp_check_for_changed_slug and some unit tests.
Kudos to @MikeHansenMe for discovering this. Unfortunately it's 9 years
that this needs to be fixed and it's still buggy. To add some more
details:
[https://github.com/WordPress/wordpress-
develop/blob/9099d9789bc0baadd65c46b1b7724f28dd2887a5/src/wp-
includes/post.php#L6896-L6899 This condition] in
`wp_check_for_changed_slugs()` appears to be based on an incorrect
assumption:
{{{
// We're only concerned with published, non-hierarchical objects.
if ( ! ( 'publish' === $post->post_status || ( 'attachment' ===
get_post_type( $post ) && 'inherit' === $post->post_status ) ) ||
is_post_type_hierarchical( $post->post_type ) ) {
return;
}
}}}
== Private posts
Private posts can be viewed by logged-in users. As such, redirects need to
work for private posts as well. The problem is that a slug change isn't
added/removed for private posts. No slug change detection, no redirect.
It is possible that condition dates before the introduction or private
posts, not sure. Regardless it needs to be changed to take into account
all cases were a post is viewable and redirects are expected to work.
== Other cases
I may be missing many things here but:
- Why attachment pages are excluded? Users can change the attachment page
`slug` in the admin and in that case no redirect will happen. Worth
reminding attachment pages can be re-enabled via the filter
`pre_option_wp_attachment_pages_enabled`.
- Why hierarchical posts (e.g. pages) are excluded? After changing a page
slug, no redirect happens.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/23074#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list