-
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
Used WP_Query
in wp_get_post_autosave
instead of raw query
#7962
base: trunk
Are you sure you want to change the base?
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. |
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. |
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 for your patch!
It looks good at first glance. Just two things:
- While there is some test coverage for this function already via other tests, it would be good to add dedicated tests for this function. Of course they should all pass :)
- Let's remove all those inline comments. They don't provide any additional value.
Additional props to @im3dabasia who opened #7965 |
src/wp-includes/revision.php
Outdated
'post_name' => $post_id . '-autosave-v1', // Autosave name. | ||
'posts_per_page' => 1, // Only need the latest autosave. | ||
'orderby' => 'date', // Order by post date (latest first). | ||
'order' => 'DESC', // Descending order for latest. | ||
'fields' => 'ids', // We only need the post ID to fetch the post object. |
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.
Don' need the inline comment
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 I have implemented the suggestions.
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.
Requests some review that will fix tests.
src/wp-includes/revision.php
Outdated
$autosave_id = $query->posts[0]; | ||
|
||
return get_post( $autosave_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.
$autosave_id = $query->posts[0]; | |
return get_post( $autosave_id ); | |
return get_post( $query->posts[0] ); |
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 Implemented the suggestion, please check.
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.
Overall looks solid to me. Left some nit-pick feedbacks.
/** | ||
* @group post | ||
*/ | ||
class Tests_Post_GetPostAutosave extends WP_UnitTestCase { |
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.
class Tests_Post_GetPostAutosave extends WP_UnitTestCase { | |
class Tests_Post_wpGetPostAutosave extends WP_UnitTestCase { |
/** | ||
* Ticket #62658 | ||
* | ||
* @see https://core.trac.wordpress.org/ticket/62658 | ||
*/ |
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.
/** | |
* Ticket #62658 | |
* | |
* @see https://core.trac.wordpress.org/ticket/62658 | |
*/ | |
/** | |
* Set up before class. | |
* | |
* @param WP_UnitTest_Factory $factory Factory. | |
*/ |
/** | ||
* Test when no autosave exists for a 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.
/** | |
* Test when no autosave exists for a post. | |
*/ | |
/** | |
* Test when no autosave exists for a post. | |
* | |
* @ticket 62658 | |
*/ |
Add @ticket
annotation for unit test.
/** | ||
* Test when an autosave exists for a 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.
/** | |
* Test when an autosave exists for a post. | |
*/ | |
/** | |
* Test when an autosave exists for a post. | |
* | |
* @ticket 62658 | |
*/ |
/** | ||
* Test when an autosave exists for a specific user. | ||
*/ |
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 when an autosave exists for a specific user. | |
*/ | |
/** | |
* Test when an autosave exists for a specific user. | |
* | |
* @ticket 62658 | |
*/ |
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 Thanks for the feedback, I have implemented the suggestions.
$this->assertInstanceOf( 'WP_Post', $autosave ); | ||
$this->assertSame( self::$editor_id, (int) $autosave->post_author, 'Post author does not match.' ); | ||
$this->assertSame( $autosave_id, $autosave->ID, 'Autosave ID does not match.' ); | ||
} |
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.
WP_Query has caching. Can we add a test here, that creates an autosaves, checks result and the creates a two autosave with the same user and gets the new result?
Co-authored-by: Jonny Harris <[email protected]>
Co-authored-by: Jonny Harris <[email protected]>
@narenin take a look pending feedback #7962 (comment) from @spacedmonkey |
Trac ticket: https://core.trac.wordpress.org/ticket/62658
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.