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. Built from https://develop.svn.wordpress.org/trunk@54130 git-svn-id: http://core.svn.wordpress.org/trunk@53689 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3ca1825716
commit
f185aeb638
|
@ -220,7 +220,15 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
|||
$prepared_post->ID = $post->ID;
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if ( ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status ) && $post->post_author == $user_id ) {
|
||||
// We need to check post lock to ensure the original author didn't leave their browser tab open.
|
||||
if ( ! function_exists( 'wp_check_post_lock' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/post.php';
|
||||
}
|
||||
|
||||
$post_lock = wp_check_post_lock( $post->ID );
|
||||
$is_draft = 'draft' === $post->post_status || 'auto-draft' === $post->post_status;
|
||||
|
||||
if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock ) {
|
||||
// Draft posts for the same author: autosaving updates the post and does not create a revision.
|
||||
// Convert the post object to an array and add slashes, wp_update_post() expects escaped array.
|
||||
$autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true );
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-alpha-54129';
|
||||
$wp_version = '6.1-alpha-54130';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue