[wp-trac] [WordPress Trac] #47279: $post object passed to clean_post_cache action can contain outdated values
WordPress Trac
noreply at wordpress.org
Wed May 15 14:28:45 UTC 2019
#47279: $post object passed to clean_post_cache action can contain outdated values
-------------------------------+-----------------------------
Reporter: tabrisrp | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
This occurs when publishing or deleting a post.
In the `clean_post_cache()` function, `get_post( $post )` is called and
assigned to `$post`.
At that moment, the value of the `$post` parameter `post_status` = `draft`
if publishing, `publish` if deleting the post.
There is then a call to `wp_cache_delete( $post->ID, 'post_meta' );`,
which correctly updates the value of post_status, if you perform another
`get_post()` right after.
But, the `$post` object is then passed to the action `clean_post_cache`,
with the outdated values instead.
So if someone hooks a function on `clean_post_cache`, and uses the `$post`
object passed, it's going to receive incorrect values compared to what
would be expected. But if you perform a `get_post()` inside that function,
you will get the correct values.
I only tested this with the `post_status` parameter, but this might be
affecting others too.
I would expect that the `$post` object passed to the `clean_post_cache`
action contains up-to-date values.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47279>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list