-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix attempt to read post ID on update_post_thumbnail_cache #6636
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thanks @itzmekhokan for PR. Could you please add unit tests that cover that scenario?
/* | ||
* Check $post is valid post object of WP_Post or not, | ||
* while some cases it can be an array of $posts 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.
* | |
* |
Fix PHPCS
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.
@mukeshpanchal27 fixed and updated test cases.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
@@ -79,11 +80,28 @@ public function test_update_post_thumbnail_cache() { | |||
) | |||
); | |||
|
|||
// Test case where `$query1->posts` should return Array of post IDs. | |||
$query1 = new WP_Query( |
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.
Nit pick, let's use 2.
$query1 = new WP_Query( | |
$query2 = new WP_Query( |
$this->assertFalse( $query1->thumbnails_cached ); | ||
|
||
update_post_thumbnail_cache( $query1 ); | ||
|
||
$this->assertTrue( $query1->thumbnails_cached ); |
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.
$this->assertFalse( $query1->thumbnails_cached ); | |
update_post_thumbnail_cache( $query1 ); | |
$this->assertTrue( $query1->thumbnails_cached ); | |
$this->assertFalse( $query2->thumbnails_cached ); | |
update_post_thumbnail_cache( $query2 ); | |
$this->assertTrue( $query2->thumbnails_cached ); |
@@ -79,11 +80,28 @@ public function test_update_post_thumbnail_cache() { | |||
) | |||
); | |||
|
|||
// Test case where `$query1->posts` should return Array of 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.
// Test case where `$query1->posts` should return Array of post IDs. | |
// Test case where `$query2->posts` should return Array of post IDs. |
$this->assertFalse( $query->thumbnails_cached ); | ||
|
||
update_post_thumbnail_cache( $query ); | ||
|
||
$this->assertTrue( $query->thumbnails_cached ); | ||
|
||
// Check test cases for `$query1`. |
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.
// Check test cases for `$query1`. | |
// Check test cases for `$query2`. |
* | ||
* See https://core.trac.wordpress.org/ticket/59521. | ||
*/ | ||
if ( ! ( $post instanceof WP_Post ) ) { |
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.
if ( ! ( $post instanceof WP_Post ) ) { | |
if ( ! $post instanceof WP_Post ) { |
Nit-pick
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've added some notes.
The main one is to avoid repeating code that already exists in get_post_thumbnail_id()
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.
This looks good to me.
In order to be able to get it in the current release, I took the liberty of pushing some changes to this PR (sorry I missed them in my prior review):
- renamed a variable and improve the comment I originally suggested
- split the tests in to two: one for querying post objects, one for querying the post IDs
- merged in trunk.
7106868
to
4cec893
Compare
4cec893
to
729e7da
Compare
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.
@aaronjorbin has validated the tests changes so I'll put this in for beta 3.
Fix attempt to read post ID on
update_post_thumbnail_cache
function as some cases$wp_query->posts
return array of post IDs instead ofWP_Post
object.Trac ticket: #59521
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.