diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index fe22d87a06..b843b513aa 100644
|
|
|
final class WP_Customize_Manager { |
| 1136 | 1136 | if ( ! $changeset_post_id ) { |
| 1137 | 1137 | $this->_changeset_data = array(); |
| 1138 | 1138 | } else { |
| 1139 | | if ( $this->autosaved() ) { |
| | 1139 | if ( $this->autosaved() && is_user_logged_in() ) { |
| 1140 | 1140 | $autosave_post = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); |
| 1141 | 1141 | if ( $autosave_post ) { |
| 1142 | 1142 | $data = $this->get_changeset_post_data( $autosave_post->ID ); |
| … |
… |
final class WP_Customize_Manager { |
| 2897 | 2897 | $post_array['edit_date'] = true; // Prevent date clearing. |
| 2898 | 2898 | $r = wp_update_post( wp_slash( $post_array ), true ); |
| 2899 | 2899 | |
| 2900 | | // Delete autosave revision when the changeset is updated. |
| 2901 | | $autosave_draft = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); |
| 2902 | | if ( $autosave_draft ) { |
| 2903 | | wp_delete_post( $autosave_draft->ID, true ); |
| | 2900 | // Delete autosave revision for user when the changeset is updated. |
| | 2901 | if ( ! empty( $args['user_id'] ) ) { |
| | 2902 | $autosave_draft = wp_get_post_autosave( $changeset_post_id, $args['user_id'] ); |
| | 2903 | if ( $autosave_draft ) { |
| | 2904 | wp_delete_post( $autosave_draft->ID, true ); |
| | 2905 | } |
| 2904 | 2906 | } |
| 2905 | 2907 | } |
| 2906 | 2908 | } else { |
| … |
… |
final class WP_Customize_Manager { |
| 3532 | 3534 | * @since 4.9.0 |
| 3533 | 3535 | */ |
| 3534 | 3536 | public function handle_dismiss_autosave_or_lock_request() { |
| | 3537 | // Calls to dismiss_user_auto_draft_changesets() and wp_get_post_autosave() require non-zero get_current_user_id(). |
| | 3538 | if ( ! is_user_logged_in() ) { |
| | 3539 | wp_send_json_error( 'unauthenticated', 401 ); |
| | 3540 | } |
| | 3541 | |
| 3535 | 3542 | if ( ! $this->is_preview() ) { |
| 3536 | 3543 | wp_send_json_error( 'not_preview', 400 ); |
| 3537 | 3544 | } |
| … |
… |
final class WP_Customize_Manager { |
| 4619 | 4626 | $changeset_post_id = $this->changeset_post_id(); |
| 4620 | 4627 | if ( ! $this->saved_starter_content_changeset && ! $this->autosaved() ) { |
| 4621 | 4628 | if ( $changeset_post_id ) { |
| 4622 | | $autosave_revision_post = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); |
| | 4629 | if ( is_user_logged_in() ) { |
| | 4630 | $autosave_revision_post = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); |
| | 4631 | } |
| 4623 | 4632 | } else { |
| 4624 | 4633 | $autosave_autodraft_posts = $this->get_changeset_posts( |
| 4625 | 4634 | array( |
diff --git tests/phpunit/tests/ajax/CustomizeManager.php tests/phpunit/tests/ajax/CustomizeManager.php
index 32d17e891f..933b9920ec 100644
|
|
|
class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { |
| 552 | 552 | * @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets() |
| 553 | 553 | */ |
| 554 | 554 | public function test_handle_dismiss_autosave_or_lock_request() { |
| 555 | | $uuid = wp_generate_uuid4(); |
| 556 | | $wp_customize = $this->set_up_valid_state( $uuid ); |
| | 555 | $uuid = wp_generate_uuid4(); |
| | 556 | $wp_customize = $this->set_up_valid_state( $uuid ); |
| | 557 | $valid_user_id = get_current_user_id(); |
| | 558 | |
| | 559 | // Temporarily remove user to test requirement that user is logged in. See #42450. |
| | 560 | wp_set_current_user( 0 ); |
| | 561 | $this->make_ajax_call( 'customize_dismiss_autosave_or_lock' ); |
| | 562 | $this->assertFalse( $this->_last_response_parsed['success'] ); |
| | 563 | $this->assertEquals( 'unauthenticated', $this->_last_response_parsed['data'] ); |
| | 564 | wp_set_current_user( $valid_user_id ); |
| 557 | 565 | |
| 558 | 566 | $this->make_ajax_call( 'customize_dismiss_autosave_or_lock' ); |
| 559 | 567 | $this->assertFalse( $this->_last_response_parsed['success'] ); |
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
index 5af7826d0c..cdadf019f4 100644
|
|
|
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
| 524 | 524 | ), |
| 525 | 525 | wp_list_pluck( $wp_customize->changeset_data(), 'value' ) |
| 526 | 526 | ); |
| | 527 | |
| | 528 | // If there is no user, don't fetch the most recent autosave. See #42450. |
| | 529 | wp_set_current_user( 0 ); |
| | 530 | $wp_customize = new WP_Customize_Manager( |
| | 531 | array( |
| | 532 | 'changeset_uuid' => $uuid, |
| | 533 | 'autosaved' => true, |
| | 534 | ) |
| | 535 | ); |
| | 536 | $this->assertEquals( $data, $wp_customize->changeset_data() ); |
| 527 | 537 | } |
| 528 | 538 | |
| 529 | 539 | /** |