Make WordPress Core

Changeset 48211


Ignore:
Timestamp:
06/29/2020 10:31:12 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Customize: Do not allow changesets to be deleted when someone is editing them.

This makes the behavior consistent with that of locked posts, which can't be deleted via the list tables when another user is editing them.

Props dlh.
Fixes #50501.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r48109 r48211  
    426426
    427427        // Don't show if the user cannot edit a given customize_changeset post currently being previewed.
    428         if ( is_customize_preview() && $wp_customize->changeset_post_id() && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) {
     428        if ( is_customize_preview() && $wp_customize->changeset_post_id()
     429                && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() )
     430        ) {
    429431                return;
    430432        }
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r48104 r48211  
    31403140                }
    31413141
    3142                 if ( $changeset_post_id && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) {
    3143                         wp_send_json_error(
    3144                                 array(
    3145                                         'code'    => 'changeset_trash_unauthorized',
    3146                                         'message' => __( 'Unable to trash changes.' ),
    3147                                 )
    3148                         );
     3142                if ( $changeset_post_id ) {
     3143                        if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) {
     3144                                wp_send_json_error(
     3145                                        array(
     3146                                                'code'    => 'changeset_trash_unauthorized',
     3147                                                'message' => __( 'Unable to trash changes.' ),
     3148                                        )
     3149                                );
     3150                        }
     3151
     3152                        $lock_user = (int) wp_check_post_lock( $changeset_post_id );
     3153
     3154                        if ( $lock_user && get_current_user_id() !== $lock_user ) {
     3155                                wp_send_json_error(
     3156                                        array(
     3157                                                'code'     => 'changeset_locked',
     3158                                                'message'  => __( 'Changeset is being edited by other user.' ),
     3159                                                'lockUser' => $this->get_lock_user_data( $lock_user ),
     3160                                        )
     3161                                );
     3162                        }
    31493163                }
    31503164
  • trunk/tests/phpunit/tests/ajax/CustomizeManager.php

    r47122 r48211  
    514514                $this->assertEquals( 'changeset_trash_unauthorized', $this->_last_response_parsed['data']['code'] );
    515515                remove_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) );
     516
     517                $lock_user_id  = static::factory()->user->create( array( 'role' => 'administrator' ) );
     518                $previous_user = get_current_user_id();
     519                wp_set_current_user( $lock_user_id );
     520                $wp_customize->set_changeset_lock( $wp_customize->changeset_post_id() );
     521                wp_set_current_user( $previous_user );
     522                $this->make_ajax_call( 'customize_trash' );
     523                $this->assertFalse( $this->_last_response_parsed['success'] );
     524                $this->assertEquals( 'changeset_locked', $this->_last_response_parsed['data']['code'] );
     525                delete_post_meta( $wp_customize->changeset_post_id(), '_edit_lock' );
    516526
    517527                wp_update_post(
Note: See TracChangeset for help on using the changeset viewer.