Make WordPress Core

Changeset 41720


Ignore:
Timestamp:
10/04/2017 12:00:47 AM (9 years ago)
Author:
westonruter
Message:

Customize: Let establish_loaded_changeset query changesets from any author not just current user when determining which changeset to autoload in non-branching mode.

See #39896.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r41694 r41720  
    613613                                        'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ),
    614614                                        'exclude_restore_dismissed' => false,
     615                                        'author' => 'any',
    615616                                        'posts_per_page' => 1,
    616617                                        'order' => 'DESC',
  • trunk/tests/phpunit/tests/customize/manager.php

    r41648 r41720  
    152152         */
    153153        public function test_constructor_deferred_changeset_uuid() {
     154                wp_set_current_user( self::$admin_user_id );
     155                $other_admin_user_id = $this->factory()->user->create( array( 'role' => 'admin' ) );
     156
    154157                $data = array(
    155158                        'blogname' => array(
    … …  
    157160                        ),
    158161                );
    159                 $uuid = wp_generate_uuid4();
     162
     163                $uuid1 = wp_generate_uuid4();
     164                $this->factory()->post->create( array(
     165                        'post_type' => 'customize_changeset',
     166                        'post_name' => $uuid1,
     167                        'post_status' => 'draft',
     168                        'post_content' => wp_json_encode( $data ),
     169                        'post_author' => get_current_user_id(),
     170                        'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ),
     171                ) );
     172
     173                /*
     174                 * Create a changeset for another user that is newer to ensure that it is the one that gets returned,
     175                 * as in non-branching mode there should only be one pending changeset at a time.
     176                 */
     177                $uuid2 = wp_generate_uuid4();
    160178                $post_id = $this->factory()->post->create( array(
    161179                        'post_type' => 'customize_changeset',
    162                         'post_name' => $uuid,
     180                        'post_name' => $uuid2,
    163181                        'post_status' => 'draft',
    164182                        'post_content' => wp_json_encode( $data ),
    165                 ) );
     183                        'post_author' => $other_admin_user_id,
     184                        'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-1 day' ) ),
     185                ) );
     186
    166187                $wp_customize = new WP_Customize_Manager( array(
    167188                        'changeset_uuid' => false, // Cause UUID to be deferred.
    168189                        'branching' => false, // To cause drafted changeset to be autoloaded.
    169190                ) );
    170                 $this->assertEquals( $uuid, $wp_customize->changeset_uuid() );
     191                $this->assertEquals( $uuid2, $wp_customize->changeset_uuid() );
    171192                $this->assertEquals( $post_id, $wp_customize->changeset_post_id() );
     193
     194                $wp_customize = new WP_Customize_Manager( array(
     195                        'changeset_uuid' => false, // Cause UUID to be deferred.
     196                        'branching' => true, // To cause no drafted changeset to be autoloaded.
     197                ) );
     198                $this->assertNotContains( $wp_customize->changeset_uuid(), array( $uuid1, $uuid2 ) );
     199                $this->assertEmpty( $wp_customize->changeset_post_id() );
    172200        }
    173201
Note: See TracChangeset for help on using the changeset viewer.