-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Author caching in WP_Query::the_post() can trigger an error. #3553
Author caching in WP_Query::the_post() can trigger an error. #3553
Conversation
Two things are tested: 1) That requesting post objects warms the author cache 2) That requesting a subset of fields will not throw an error
f09540d
to
c9502de
Compare
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
src/wp-includes/class-wp-query.php
Outdated
$post_ids = array_filter( $this->posts, 'is_numeric' ); | ||
$post_ids = array_filter( $post_ids ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$post_ids = array_filter( $this->posts, 'is_numeric' ); | |
$post_ids = array_filter( $post_ids ); | |
$post_ids = array_filter( array_filter( $this->posts, 'is_numeric' ) ); |
We could do this, might be a little cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd pushed 3b5fca1 before seeing this, on the basis that comments are needed to explain why array_filter is called twice.
_prime_post_caches( $post_ids, $this->query_vars['update_post_term_cache'], $this->query_vars['update_post_meta_cache'] ); | ||
} | ||
$post_objects = array_map( 'get_post', $this->posts ); | ||
update_post_author_caches( $post_objects ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me, this will have a similar problem to #56952 and throw an error if called before pluggable functions are loaded.
It might be worth returning early in update_post_author_caches()
if cache_users()
is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
https://core.trac.wordpress.org/ticket/56948
The first commit ensures the tests are failing prior to the changes, the second to only warm the cache when
WP_Query::$posts
is populated withWP_Post
objects.