From ea399e28a94b033275fd22b5000b760fda444524 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 7 Jul 2023 17:53:23 +0000 Subject: [PATCH] Revisions: return existing autosave after saving with unchanged data. Correctly return the existing autosave when an unchanged autosave is saved, instead of returning an error. Fix regressions after r55154 where an error and not the original autosave was returned when saving with unchanged data (for example, clicking the preview button repeatedly). Returning the autosave (ID) is the expected behavior for the endpoint. Follow up to [55154] Props Mamaduka, jeroenrotty, mrfoxtalbot. Fixes #58739. Built from https://develop.svn.wordpress.org/trunk@56163 git-svn-id: http://core.svn.wordpress.org/trunk@55675 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-autosaves-controller.php | 13 +++++-------- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php index 6b2da40eb3..1eacba38e8 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php @@ -371,19 +371,16 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { } } - if ( ! $autosave_is_different ) { - return new WP_Error( - 'rest_autosave_no_changes', - __( 'There is nothing to save. The autosave and the post content are the same.' ), - array( 'status' => 400 ) - ); - } - $user_id = get_current_user_id(); // Store one autosave per author. If there is already an autosave, overwrite it. $old_autosave = wp_get_post_autosave( $post_id, $user_id ); + if ( ! $autosave_is_different && $old_autosave ) { + // Nothing to save, return the existing autosave. + return $old_autosave->ID; + } + if ( $old_autosave ) { $new_autosave['ID'] = $old_autosave->ID; $new_autosave['post_author'] = $user_id; diff --git a/wp-includes/version.php b/wp-includes/version.php index 361fbc1647..69bed8706b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-beta3-56162'; +$wp_version = '6.3-beta3-56163'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.