Make WordPress Core


Ignore:
Timestamp:
07/07/2023 05:51:11 PM (23 months ago)
Author:
adamsilverstein
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php

    r55988 r56163  
    372372        }
    373373
    374         if ( ! $autosave_is_different ) {
    375             return new WP_Error(
    376                 'rest_autosave_no_changes',
    377                 __( 'There is nothing to save. The autosave and the post content are the same.' ),
    378                 array( 'status' => 400 )
    379             );
    380         }
    381 
    382374        $user_id = get_current_user_id();
    383375
    384376        // Store one autosave per author. If there is already an autosave, overwrite it.
    385377        $old_autosave = wp_get_post_autosave( $post_id, $user_id );
     378
     379        if ( ! $autosave_is_different && $old_autosave ) {
     380            // Nothing to save, return the existing autosave.
     381            return $old_autosave->ID;
     382        }
    386383
    387384        if ( $old_autosave ) {
Note: See TracChangeset for help on using the changeset viewer.