WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#33421 closed defect (bug) (worksforme)

wp_editor with custom editor_id not working

Reported by: abadahenno Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.4
Component: TinyMCE Keywords: reporter-feedback
Focuses: javascript, administration Cc:
PR Number:

Description

When give editor id like my-form[myeditor] form wp_editor doesn`t work and text editor (Html tags) only shown not also visual editor

$settings = array( 'media_buttons' => false );
wp_editor(wpautop(stripslashes( $options['message'])), 'my-form[myeditor]',$settings );

Attachments (1)

Screenshot from 2016-04-29 22-27-49.png (126.1 KB) - added by LewisCowles 4 years ago.
Screenshot of error in chrome console

Download all attachments as: .zip

Change History (7)

#1 @azaozz
4 years ago

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

Duplicate of #26778. The $editor_id cannot contain square braces (or other characters that don't work in jQuery selectors). A warning about this was added in #27601 one and a half years ago.

If you need to use square braces in the textarea name, please see the inline docs: https://core.trac.wordpress.org/browser/tags/4.3/src/wp-includes/class-wp-editor.php#L46.

Also, it's not recommended to run the initial text through wpautop(). This is done automatically when needed (i.e. if another plugin hasn't disabled it).

The above example would be:

$settings = array( 'media_buttons' => false, 'textarea_name' => 'my-form[myeditor]' );
wp_editor( stripslashes( $options['message'] ), 'my-editor-id', $settings );

#2 @LewisCowles
4 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

I'm sure this bug is about more than square braces. I have the same error, without curly braces in 4.5, with code that worked in 4.4...

<?php wp_editor( wpautop(stripslashes($post->post_content)), 'content', ['media_buttons'=>false,'textarea_name'=>'content','dfw'=>true,'tiny_mce'=>true,'drag_drop_upload'=>true] ); ?>

This code exists within my view, $post is sent to the view, and I can confirm that the textarea has the post's content, but the wp_editor has JS errors (i'll add an attachment also for this)

@LewisCowles
4 years ago

Screenshot of error in chrome console

#3 @LewisCowles
4 years ago

OS: Ubuntu 16.04
Browser: Google Chrome (official google repo's stable) Version 50.0.2661.94 (64-bit), problem also persists in Firefox from 16.04 repo's v46.0, and Opera v36.0.2130.65 (yet to test in windows)

Confirmed Windows 10 64-bit
Google Chrome 49.0.2623.112 (Official Build) m (32-bit)
Mozilla Firefox 45.0.1 and 46.0
Internet Explorer Edge (latest)

WordPress Version 4.5 (for some reason it's not a listed version in the select box)

Last edited 4 years ago by LewisCowles (previous) (diff)

#4 @LewisCowles
4 years ago

Also enabling editor in custom post type definition and disabling call to wp_editor seems to work. It does make the CPT edit post screen look absolutely terrible, but at least it works. I've implemented this as a for-now fix for my plugin, but I'd really like it if wp_editor worked or was deprecated. Or to hear from other plugin authors about any work-around for the apparent breakage.

#5 @azaozz
4 years ago

  • Keywords reporter-feedback added

Don't think this error has anything to do with the editor. There is no coerce anywhere in there.

Looks like this may be an error in the media modal (media-audiovideo.js or media-editor.js) most likely caused by wrong loading order. Perhaps look at the call trace on the first error, and open a new ticket if you can reliably reproduce it with all plugins disabled and a default theme.

Leaving this open for now, waiting for more feedback.

#6 @LewisCowles
4 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

Hi,

A Bit confused. How would one set about custom calling wp_editor in a stock theme with *all* plugins disabled?

The editor works when used as-is included for posts and pages. Neither the original ticket or this addendum are about built-in post or page editing.

For some plugins using wp_editor is considered necessary to make a screen flow better. In my case with additional content after the title.

The process is simple; I've turned off the built in editor through post type capabilities, and created a new editor, with the code posted above, which from November to the release of 4.5 worked, it was exactly what I expected and what the codex described behaviour to be.

I Know the editor works if I use the standard post content, but as advertised on the codex the wp_editor function should allow me to create a tinymce fed from any source (I just happen to have used the post content).

Strangely enough turning off jetpack, then re-enabling has made the code work again, so I'll close, but it does seem strange that an automattic authored plugin would break other plugins.

Note: See TracTickets for help on using tickets.