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
This commit is contained in:
Adam Silverstein 2023-07-07 17:53:23 +00:00
parent c7a4311ba0
commit ea399e28a9
2 changed files with 6 additions and 9 deletions

View File

@ -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;

View File

@ -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.