[wp-trac] [WordPress Trac] #32537: 404 error on empty title
WordPress Trac
noreply at wordpress.org
Mon Jun 15 23:27:02 UTC 2015
#32537: 404 error on empty title
--------------------------+------------------------------
Reporter: arhit | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Permalinks | Version: 4.2.2
Severity: critical | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by tyxla):
I just confirmed this bug.
After in-depth inspection, I discovered that this occurs because in the
`wp_unique_post_slug()` that is being called in the Permalink section in
the administration (the `edit-slug-box` section).
Here is a quick example: when you publish a post with no title (but with
some content), if the post ID is 20, the post name becomes 20-2 in the
Permalink section. When using `/%postname%/` permalink structure the post
URL becomes `http://example.com/20-2/`, but the post name in the database
remains `20`. This is why the 404 error occurs.
The Permalink section properly calls `wp_unique_post_slug()`, which
changes `20` to `20-2` to avoid conflicts with date archives (see
https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/post.php#L3803).
But, as said earlier, the post name remains 20, which leads to the 404 not
found error.
Currently, in case the post status is `publish`, and the post title and
post name are empty, the post name is automatically being made the same as
the post ID. As a fix I recommend that we use `wp_unique_post_slug()` on
the post name, so it becomes 20-2 as well, making it equal to the current
behavior in the administration. Of course, this would happen only if the
post title is empty, otherwise the current behavior should be retained.
I'm attaching a patch with a fix for that issue. Also including a unit
test that replicates the issue.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32537#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list