Opened 5 years ago
Last modified 5 years ago
#47279 new defect (bug)
$post object passed to clean_post_cache action can contain outdated values
Reported by: | tabrisrp | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
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.