WordPress.org

Make WordPress Core

Changeset 41245


Ignore:
Timestamp:
08/13/2017 05:24:14 AM (10 months ago)
Author:
westonruter
Message:

Widgets: Fix extensibility of Text widgets so that JS logic will initialize on subclassed widgets.

Amends [40631].
See #35243.
Fixes #41540.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/widgets/text-widgets.js

    r41132 r41245  
    55
    66    var component = {
    7         dismissedPointers: []
     7        dismissedPointers: [],
     8        idBases: [ 'text' ]
    89    };
    910
     
    358359
    359360        idBase = widgetForm.find( '> .id_base' ).val();
    360         if ( 'text' !== idBase ) {
     361        if ( -1 === component.idBases.indexOf( idBase ) ) {
    361362            return;
    362363        }
     
    425426
    426427        idBase = widgetForm.find( '> .widget-control-actions > .id_base' ).val();
    427         if ( 'text' !== idBase ) {
     428        if ( -1 === component.idBases.indexOf( idBase ) ) {
    428429            return;
    429430        }
     
    462463
    463464        idBase = widgetForm.find( '> .id_base' ).val();
    464         if ( 'text' !== idBase ) {
     465        if ( -1 === component.idBases.indexOf( idBase ) ) {
    465466            return;
    466467        }
  • trunk/src/wp-includes/widgets/class-wp-widget-text.php

    r41162 r41245  
    5656        $this->registered = true;
    5757
     58        wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
     59
    5860        // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
    5961        add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
    6062
    6163        // Note that the widgets component in the customizer will also do the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
    62         add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
     64        add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) );
    6365    }
    6466
     
    377379     *
    378380     * @since 4.8.0
    379      */
    380     public function render_control_template_scripts() {
     381     * @since 4.9.0 The method is now static.
     382     */
     383    public static function render_control_template_scripts() {
    381384        $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    382385        ?>
  • trunk/tests/phpunit/tests/widgets/text-widget.php

    r41134 r41245  
    6565
    6666        $this->assertEquals( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
    67         $this->assertEquals( 10, has_action( 'admin_footer-widgets.php', array( $widget, 'render_control_template_scripts' ) ) );
     67        $this->assertEquals( 10, has_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) ) );
     68        $this->assertContains( 'wp.textWidgets.idBases.push( "text" );', wp_scripts()->registered['text-widgets']->extra['after'] );
    6869    }
    6970
     
    746747     */
    747748    function test_render_control_template_scripts() {
    748         $widget = new WP_Widget_Text();
    749 
    750         ob_start();
    751         $widget->render_control_template_scripts();
     749        ob_start();
     750        WP_Widget_Text::render_control_template_scripts();
    752751        $output = ob_get_clean();
    753752
Note: See TracChangeset for help on using the changeset viewer.