Make WordPress Core


Ignore:
Timestamp:
11/21/2015 02:51:57 AM (9 years ago)
Author:
westonruter
Message:

Customize: Ensure that a setting (especially a multidimensional one) can still be previewed when the post value to preview is set after preview() is invoked.

  • Introduce customize_post_value_set_{$setting_id} and customize_post_value_set actions which are done when WP_Customize_Manager::set_post_value() is called.
  • Clear the preview_applied flag for aggregated multidimensional settings when a post value is set. This ensures the new value is used instead of a previously-cached previewed value.
  • Move $is_preview property from subclasses to WP_Customize_Setting parent class.
  • Deferred preview: Ensure that when preview() short-circuits due to not being applicable that it will be called again later when the post value is set.
  • Populate post value for updated-widget with the (unsanitized) JS-value in WP_Customize_Widgets::call_widget_update() so that value will be properly sanitized when accessed in WP_Customize_Manager::post_value().

Includes unit tests with assertions to check the reported issues and validate the fixes.

Fixes defect introduced in [35007].
See #32103.
Fixes #34738.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/widgets.php

    r35242 r35724  
    292292        $this->assertFalse( $this->manager->get_panel( 'widgets' )->active() );
    293293    }
     294
     295    /**
     296     * @ticket 34738
     297     * @see WP_Customize_Widgets::call_widget_update()
     298     */
     299    function test_call_widget_update() {
     300
     301        $widget_number = 2;
     302        $widget_id = "search-{$widget_number}";
     303        $setting_id = "widget_search[{$widget_number}]";
     304        $instance = array(
     305            'title' => 'Buscar',
     306        );
     307
     308        $_POST = wp_slash( array(
     309            'action' => 'update-widget',
     310            'wp_customize' => 'on',
     311            'nonce' => wp_create_nonce( 'update-widget' ),
     312            'theme' => $this->manager->get_stylesheet(),
     313            'customized' => '{}',
     314            'widget-search' => array(
     315                2 => $instance,
     316            ),
     317            'widget-id' => $widget_id,
     318            'id_base' => 'search',
     319            'widget-width' => '250',
     320            'widget-height' => '200',
     321            'widget_number' => strval( $widget_number ),
     322            'multi_number' => '',
     323            'add_new' => '',
     324        ) );
     325
     326        $this->do_customize_boot_actions();
     327
     328        $this->assertArrayNotHasKey( $setting_id, $this->manager->unsanitized_post_values() );
     329        $result = $this->manager->widgets->call_widget_update( $widget_id );
     330
     331        $this->assertInternalType( 'array', $result );
     332        $this->assertArrayHasKey( 'instance', $result );
     333        $this->assertArrayHasKey( 'form', $result );
     334        $this->assertEquals( $instance, $result['instance'] );
     335        $this->assertContains( sprintf( 'value="%s"', esc_attr( $instance['title'] ) ), $result['form'] );
     336
     337        $post_values = $this->manager->unsanitized_post_values();
     338        $this->assertArrayHasKey( $setting_id, $post_values );
     339        $post_value = $post_values[ $setting_id ];
     340        $this->assertInternalType( 'array', $post_value );
     341        $this->assertArrayHasKey( 'title', $post_value );
     342        $this->assertArrayHasKey( 'encoded_serialized_instance', $post_value );
     343        $this->assertArrayHasKey( 'instance_hash_key', $post_value );
     344        $this->assertArrayHasKey( 'is_widget_customizer_js_value', $post_value );
     345        $this->assertEquals( $post_value, $this->manager->widgets->sanitize_widget_js_instance( $instance ) );
     346    }
    294347}
Note: See TracChangeset for help on using the changeset viewer.