[wp-trac] [WordPress Trac] #5305: permalinks broken when article name is numeric
WordPress Trac
noreply at wordpress.org
Tue Aug 18 02:24:50 UTC 2015
#5305: permalinks broken when article name is numeric
------------------------------+---------------------------
Reporter: thomask | Owner: valendesigns
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 4.3
Component: Permalinks | Version: 2.3.1
Severity: major | Resolution:
Keywords: has-patch commit | Focuses:
------------------------------+---------------------------
Comment (by boonebgorges):
The bbPress ticket cited above is not strictly caused by the changes in
[33262], but [33262] did expose an ancient bug in `wp_insert_post()`.
In cases where a post has an empty `post_name` - generally this happens
when `post_title` is empty - `wp_insert_post()` generates a `post_name`
from the post's `ID`. (See eg [33261].) The function then directly updates
the database using `$wpdb->update()`.
https://core.trac.wordpress.org/browser/tags/4.2.4/src/wp-
includes/post.php#L3407
A few lines later, `wp_insert_post()` generates a guid for new posts,
using `get_permalink()`.
https://core.trac.wordpress.org/browser/tags/4.2.4/src/wp-
includes/post.php?marks=3438#L3434
The problem is that `get_permalink()` generates its return value based on
a *cached* post, if available. Prior to [33262], the cache for the newly
created post would always be empty at this point, which means that the
fresh data would always be pulled from the database. But the `get_post()`
call introduced in [33262] means that the cache is populated before the
guid is determined, meaning that `get_permalink()` is looking at stale
data. (`wp_insert_post()` does clear the post cache, but only later in the
function.)
The solution is to clear the post cache immediately after the database
update. See [attachment:5305.20.diff].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/5305#comment:109>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list