mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
REST API: Use wp_get_lastest_revision_id_and_total_count function in WP_REST_Posts_Controller class.
Add new function called `wp_get_lastest_revision_id_and_total_count`, that performs an optimized query to get the last revision and total and use it in `WP_REST_Posts_Controller` class. Props Spacedmonkey, timothyblynjacobs, furi3r, peterwilsoncc. Fixes #55857. git-svn-id: https://develop.svn.wordpress.org/trunk@53759 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2024,8 +2024,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
}
|
||||
|
||||
if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
|
||||
$revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
|
||||
$revisions_count = count( $revisions );
|
||||
$revision = wp_get_lastest_revision_id_and_total_count( $post->ID );
|
||||
$revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0;
|
||||
|
||||
$links['version-history'] = array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
|
||||
@@ -2033,8 +2033,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
);
|
||||
|
||||
if ( $revisions_count > 0 ) {
|
||||
$last_revision = array_shift( $revisions );
|
||||
|
||||
$last_revision = $revision['revision'];
|
||||
$links['predecessor-version'] = array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ),
|
||||
'id' => $last_revision,
|
||||
|
||||
Reference in New Issue
Block a user