Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#20264 closed defect (bug) (invalid)

WP_Editor unexpected behavior/bug when used in widget

Reported by: niklasbr's profile niklasbr Owned by:
Milestone: Priority: normal
Severity: major Version: 3.3.1
Component: TinyMCE Keywords:
Focuses: Cc:

Description

Creating a bare bones widget using the wp_editor() function only returns a non-functioning editor (a few times no editor at all). Using the setting teeny => true results in a javascript error where wp_editor will try to load /wp-includes/js/tinymce/themes/simple/editor_template.js (which does not exist).

A demo video of this behavior can be found here: https://vimeo.com/38863361

This is the demo code:

add_action('widgets_init', 'my_widgets_add');
function my_widgets_add() {
    register_widget('my_wysiwyg_widget');
}
class my_wysiwyg_widget extends \WP_Widget {
    function __construct() {
        $widget_ops = array('classname' => 'my_wysiwyg_widget', 'description' => __('My WYSIWYG Widget'));
        $control_ops = array('width' => 650, 'height' => 350);
        parent::__construct(false, __("My WYSIWYG Widget"), $widget_ops, $control_ops);
    }
    
    function form() {
        // Create a TinyMCE editor
        wp_editor('content',
            $editor_id = "unique_id_goes_here", 
            $settings = array(
            'textarea_name' => "unique_name_goes_here",
            'textarea_rows' => 7,
            teeny => false));
    }
    
    function update($new_instance, $old_instance) {
        // Save data later
        $instance = $old_instance;
        return $instance;
    }
    
    function widget($args, $instance) {
        // print later
    }    
}

Change History (7)

#1 @niklasbr
12 years ago

  • Summary changed from WP_Editor to WP_Editor unexpected behavior/bug when used in widget

#2 @ocean90
12 years ago

Related: #20181

#3 @toscho
12 years ago

  • Cc info@… added

#4 @azaozz
12 years ago

Unfortunately TinyMCE cannot be moved in the DOM once it's initialized. That makes it impossible to use wp_editor() directly in a widget.

Was thinking to add another method to wp_editor() that would make it work in two steps:

  • first enqueue scripts and output the hidden html for the dialogs (all that goes at the bottom of the page),
  • second output the html around the editor and some JS to initialize it, leaving out the actual init call so it can be initialized on bemand.

That would make it possible to add the editor with ajax too.

#5 @onetarek
11 years ago

TinyMCE Editor is not shown in given height. I set the 'textarea_rows'=>15, but it is showing only 5 always. I set the CSS height 600px , then it is showing same also.

#6 @westonruter
10 years ago

  • Cc weston@… added

#7 @azaozz
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

The error when setting 'teeny' => true no longer happens as TinyMCE 4.x doesn't have separate "simple" theme.

Note: See TracTickets for help on using tickets.