Opened 5 years ago
Last modified 5 years ago
#48658 new defect (bug)
Post, Page, and Attachment permalinks can be silently overwritten when Permalinks are set to /%postname%/
Reported by: | raamdev | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.4 |
Component: | Permalinks | Keywords: | |
Focuses: | Cc: |
Description
When a new post is created with a permalink that matches an existing attachment page permalink, the attachment page permalink is silently overwritten. The expected behavior of having -2
appended to the new post permalink does not occur and instead the existing attachment page becomes inaccessible via its permalink, which starts pointing to the new post instead.
Steps to reproduce:
- Ensure pretty permalinks are enabled in Settings -> Permalinks (e.g.,
/%postname%/
) - Upload something to the Media Library (e.g.,
happy-pumpkin.jpg
) - Note the Attachment Page permalink generated from the upload (e.g.,
/happy-pumpkin/
) - Publish a new post with a title that will produce the same permalink (e.g., a post title of "Happy Pumpkin" will generate a new post permalink of
/happy-pumpkin/
, not/happy-pumpkin-2/
as expected) - Now both the attachment page and the new post have the same permalink (
/happy-pumpkin/
, in this example) and the attachment page permalink has been silently overwritten.
When the attachment page permalink is overwritten, there's no way to access that attachment page on the front-end (it now points at the new post). There's also no obvious way to manually change the permalink.
In testing, what works is to edit some detail of the attachment in the Media Library—once the change is saved, the permalink is regenerated and updated to include -2
, which then makes the attachment page accessible again.
Change History (3)
#1
@
5 years ago
- Summary changed from Generating a new post permalink silently overwrites existing attachment permalink to Page and attachment permalink can be silently overwritten when Permalinks are set to /%postname%/
It looks like this bug is worse than I thought. It doesn’t affect just attachments. It also affects Posts and Pages.
/%postname%/
)/hello-moon/
/hello-moon/
(which you can do!)The post gets published but the permalink leads you to the Page not the Post.
If you reverse the process and create the Post first, the permalink also leads you to the Page instead of the Post.
It looks like this is because /wp-includes/post.php#L4388 assumes that Pages are in a separate namespace from Posts (this assumption is noted in an earlier comment: /wp-includes/post.php#L4360-L4363), but this is not the case for top-level Pages when the Permalinks are set to "Post name" (
/%postname%/
).