Make WordPress Core


Ignore:
Timestamp:
09/11/2022 10:33:29 PM (20 months ago)
Author:
antpb
Message:

Autosave/REST API: Block autosaving from overwriting changes when locked from editing.

Previously when a user was locked from editing a post in the block editor, autosave functionality was allowed to overwrite changes made by the editor that has taken control. This patch honors the lock status keeping autosave from conflicitng with other content editors.

Props jhart35, adamsilverstein, sathyapulse, chanthaboune, primetimejas, joemcgill, kadamwhite.
Fixes #55659.

File:
1 edited

Legend:

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

    r51962 r54130  
    221221        $user_id           = get_current_user_id();
    222222
    223         if ( ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status ) && $post->post_author == $user_id ) {
     223        // We need to check post lock to ensure the original author didn't leave their browser tab open.
     224        if ( ! function_exists( 'wp_check_post_lock' ) ) {
     225            require_once ABSPATH . 'wp-admin/includes/post.php';
     226        }
     227
     228        $post_lock = wp_check_post_lock( $post->ID );
     229        $is_draft  = 'draft' === $post->post_status || 'auto-draft' === $post->post_status;
     230
     231        if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock ) {
    224232            // Draft posts for the same author: autosaving updates the post and does not create a revision.
    225233            // Convert the post object to an array and add slashes, wp_update_post() expects escaped array.
Note: See TracChangeset for help on using the changeset viewer.