diff --git a/src/wp-admin/js/widgets/text-widgets.js b/src/wp-admin/js/widgets/text-widgets.js index 3902aeddc0..7cf07513b7 100644 --- a/src/wp-admin/js/widgets/text-widgets.js +++ b/src/wp-admin/js/widgets/text-widgets.js @@ -81,7 +81,7 @@ wp.textWidgets = ( function( $ ) { // Sync input fields to hidden sync fields which actually get sent to the server. _.each( control.fields, function( fieldInput, fieldName ) { fieldInput.on( 'input change', function updateSyncField() { - var syncInput = control.syncContainer.find( 'input[type=hidden].' + fieldName ); + var syncInput = control.syncContainer.find( '.sync-input.' + fieldName ); if ( syncInput.val() !== fieldInput.val() ) { syncInput.val( fieldInput.val() ); syncInput.trigger( 'change' ); @@ -89,7 +89,7 @@ wp.textWidgets = ( function( $ ) { }); // Note that syncInput cannot be re-used because it will be destroyed with each widget-updated event. - fieldInput.val( control.syncContainer.find( 'input[type=hidden].' + fieldName ).val() ); + fieldInput.val( control.syncContainer.find( '.sync-input.' + fieldName ).val() ); }); }, @@ -145,11 +145,11 @@ wp.textWidgets = ( function( $ ) { var control = this, syncInput; if ( ! control.fields.title.is( document.activeElement ) ) { - syncInput = control.syncContainer.find( 'input[type=hidden].title' ); + syncInput = control.syncContainer.find( '.sync-input.title' ); control.fields.title.val( syncInput.val() ); } - syncInput = control.syncContainer.find( 'input[type=hidden].text' ); + syncInput = control.syncContainer.find( '.sync-input.text' ); if ( control.fields.text.is( ':visible' ) ) { if ( ! control.fields.text.is( document.activeElement ) ) { control.fields.text.val( syncInput.val() ); diff --git a/src/wp-includes/widgets/class-wp-widget-text.php b/src/wp-includes/widgets/class-wp-widget-text.php index ef9e349aa4..a79e0daa6c 100644 --- a/src/wp-includes/widgets/class-wp-widget-text.php +++ b/src/wp-includes/widgets/class-wp-widget-text.php @@ -332,6 +332,7 @@ class WP_Widget_Text extends WP_Widget { * @since 4.8.0 Form only contains hidden inputs which are synced with JS template. * @since 4.8.1 Restored original form to be displayed when in legacy mode. * @see WP_Widget_Visual_Text::render_control_template_scripts() + * @see _WP_Editors::editor() * * @param array $instance Current settings. * @return void @@ -346,10 +347,31 @@ class WP_Widget_Text extends WP_Widget { ); ?> is_legacy_instance( $instance ) ) : ?> - - - - + + + + +
diff --git a/tests/phpunit/tests/widgets/text-widget.php b/tests/phpunit/tests/widgets/text-widget.php
index 9bc6edcad4..f7e810fd04 100644
--- a/tests/phpunit/tests/widgets/text-widget.php
+++ b/tests/phpunit/tests/widgets/text-widget.php
@@ -447,7 +447,9 @@ class Test_WP_Widget_Text extends WP_UnitTestCase {
* @covers WP_Widget_Text::form
*/
function test_form() {
+ add_filter( 'user_can_richedit', '__return_true' );
$widget = new WP_Widget_Text();
+ $widget->_set( 2 );
$instance = array(
'title' => 'Title',
'text' => 'Text',
@@ -459,7 +461,7 @@ class Test_WP_Widget_Text extends WP_UnitTestCase {
$widget->form( $instance );
$form = ob_get_clean();
$this->assertContains( 'class="visual" type="hidden" value=""', $form );
- $this->assertNotContains( 'class="visual" type="hidden" value="on"', $form );
+ $this->assertNotContains( 'class="visual sync-input" type="hidden" value="on"', $form );
$instance = array(
'title' => 'Title',
@@ -470,8 +472,8 @@ class Test_WP_Widget_Text extends WP_UnitTestCase {
ob_start();
$widget->form( $instance );
$form = ob_get_clean();
- $this->assertContains( 'class="visual" type="hidden" value="on"', $form );
- $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
+ $this->assertContains( 'class="visual sync-input" type="hidden" value="on"', $form );
+ $this->assertNotContains( 'class="visual sync-input" type="hidden" value=""', $form );
$instance = array(
'title' => 'Title',
@@ -482,12 +484,12 @@ class Test_WP_Widget_Text extends WP_UnitTestCase {
ob_start();
$widget->form( $instance );
$form = ob_get_clean();
- $this->assertContains( 'class="visual" type="hidden" value="on"', $form );
- $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
+ $this->assertContains( 'class="visual sync-input" type="hidden" value="on"', $form );
+ $this->assertNotContains( 'class="visual sync-input" type="hidden" value=""', $form );
$instance = array(
'title' => 'Title',
- 'text' => 'Text',
+ 'text' => 'This is some HTML Code: <strong>BOLD!</strong>
',
'filter' => true,
'visual' => true,
);
@@ -495,8 +497,24 @@ class Test_WP_Widget_Text extends WP_UnitTestCase {
ob_start();
$widget->form( $instance );
$form = ob_get_clean();
- $this->assertContains( 'class="visual" type="hidden" value="on"', $form );
- $this->assertNotContains( 'class="visual" type="hidden" value=""', $form );
+ $this->assertContains( 'class="visual sync-input" type="hidden" value="on"', $form );
+ $this->assertContains( '<code><strong>BOLD!', $form );
+ $this->assertNotContains( 'class="visual sync-input" type="hidden" value=""', $form );
+
+ remove_filter( 'user_can_richedit', '__return_true' );
+ add_filter( 'user_can_richedit', '__return_false' );
+ $instance = array(
+ 'title' => 'Title',
+ 'text' => 'Evil:',
+ 'filter' => true,
+ 'visual' => true,
+ );
+ $this->assertFalse( $widget->is_legacy_instance( $instance ) );
+ ob_start();
+ $widget->form( $instance );
+ $form = ob_get_clean();
+ $this->assertNotContains( 'Evil:', $form );
+ $this->assertContains( 'Evil:</textarea>', $form );
}
/**