From 8561f22f4d9e816ecd78f46ef187acc72f01d8dd Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 29 Jan 2018 23:04:22 +0000 Subject: [PATCH] Customize: Ensure heartbeat keeps changeset locked when in branching mode. Props dlh. See #42024. Fixes #42658. git-svn-id: https://develop.svn.wordpress.org/trunk@42612 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 1 + src/wp-includes/class-wp-customize-manager.php | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 5afcd783bd..785fc7f895 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -8208,6 +8208,7 @@ // Check for lock when sending heartbeat requests. $( document ).on( 'heartbeat-send.update_lock_notice', function( event, data ) { data.check_changeset_lock = true; + data.changeset_uuid = api.settings.changeset.uuid; } ); // Handle heartbeat ticks. diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index bc215fef56..2cddb70370 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -3204,15 +3204,26 @@ final class WP_Customize_Manager { * @return array The Heartbeat response. */ public function check_changeset_lock_with_heartbeat( $response, $data, $screen_id ) { - if ( array_key_exists( 'check_changeset_lock', $data ) && 'customize' === $screen_id && current_user_can( 'customize' ) && $this->changeset_post_id() ) { - $lock_user_id = wp_check_post_lock( $this->changeset_post_id() ); + if ( isset( $data['changeset_uuid'] ) ) { + $changeset_post_id = $this->find_changeset_post_id( $data['changeset_uuid'] ); + } else { + $changeset_post_id = $this->changeset_post_id(); + } + + if ( + array_key_exists( 'check_changeset_lock', $data ) + && 'customize' === $screen_id + && $changeset_post_id + && current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post_id ) + ) { + $lock_user_id = wp_check_post_lock( $changeset_post_id ); if ( $lock_user_id ) { $response['customize_changeset_lock_user'] = $this->get_lock_user_data( $lock_user_id ); } else { // Refreshing time will ensure that the user is sitting on customizer and has not closed the customizer tab. - $this->refresh_changeset_lock( $this->changeset_post_id() ); + $this->refresh_changeset_lock( $changeset_post_id ); } }