diff --git src/wp-admin/js/widgets/text-widgets.js src/wp-admin/js/widgets/text-widgets.js
index 692a0642c9..bb19f2ffb2 100644
|
|
wp.textWidgets = ( function( $ ) { |
4 | 4 | 'use strict'; |
5 | 5 | |
6 | 6 | var component = { |
7 | | dismissedPointers: [] |
| 7 | dismissedPointers: [], |
| 8 | idBases: [ 'text' ] |
8 | 9 | }; |
9 | 10 | |
10 | 11 | /** |
… |
… |
wp.textWidgets = ( function( $ ) { |
357 | 358 | widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen. |
358 | 359 | |
359 | 360 | idBase = widgetForm.find( '> .id_base' ).val(); |
360 | | if ( 'text' !== idBase ) { |
| 361 | if ( -1 === component.idBases.indexOf( idBase ) ) { |
361 | 362 | return; |
362 | 363 | } |
363 | 364 | |
… |
… |
wp.textWidgets = ( function( $ ) { |
424 | 425 | } |
425 | 426 | |
426 | 427 | idBase = widgetForm.find( '> .widget-control-actions > .id_base' ).val(); |
427 | | if ( 'text' !== idBase ) { |
| 428 | if ( -1 === component.idBases.indexOf( idBase ) ) { |
428 | 429 | return; |
429 | 430 | } |
430 | 431 | |
… |
… |
wp.textWidgets = ( function( $ ) { |
461 | 462 | widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); |
462 | 463 | |
463 | 464 | idBase = widgetForm.find( '> .id_base' ).val(); |
464 | | if ( 'text' !== idBase ) { |
| 465 | if ( -1 === component.idBases.indexOf( idBase ) ) { |
465 | 466 | return; |
466 | 467 | } |
467 | 468 | |
diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
index c28ed1f317..b996595585 100644
|
|
class WP_Widget_Text extends WP_Widget { |
55 | 55 | } |
56 | 56 | $this->registered = true; |
57 | 57 | |
| 58 | wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) ); |
| 59 | |
58 | 60 | // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts(). |
59 | 61 | add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) ); |
60 | 62 | |
61 | 63 | // 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' ) ); |
63 | 65 | } |
64 | 66 | |
65 | 67 | /** |
… |
… |
class WP_Widget_Text extends WP_Widget { |
376 | 378 | * Render form template scripts. |
377 | 379 | * |
378 | 380 | * @since 4.8.0 |
| 381 | * @since 4.8.2 The method is now static. |
379 | 382 | */ |
380 | | public function render_control_template_scripts() { |
| 383 | static public function render_control_template_scripts() { |
381 | 384 | $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
382 | 385 | ?> |
383 | 386 | <script type="text/html" id="tmpl-widget-text-control-fields"> |
diff --git tests/phpunit/tests/widgets/text-widget.php tests/phpunit/tests/widgets/text-widget.php
index 41aadb6af7..6c7ec1f102 100644
|
|
class Test_WP_Widget_Text extends WP_UnitTestCase { |
64 | 64 | $widget->_register(); |
65 | 65 | |
66 | 66 | $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'] ); |
68 | 69 | } |
69 | 70 | |
70 | 71 | /** |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
745 | 746 | * @covers WP_Widget_Text::render_control_template_scripts |
746 | 747 | */ |
747 | 748 | function test_render_control_template_scripts() { |
748 | | $widget = new WP_Widget_Text(); |
749 | | |
750 | 749 | ob_start(); |
751 | | $widget->render_control_template_scripts(); |
| 750 | WP_Widget_Text::render_control_template_scripts(); |
752 | 751 | $output = ob_get_clean(); |
753 | 752 | |
754 | 753 | $this->assertContains( '<script type="text/html" id="tmpl-widget-text-control-fields">', $output ); |