WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 years ago

#28403 closed defect (bug) (fixed)

Multiple wp_editor's with different settings

Reported by: madeinua Owned by: azaozz
Milestone: 4.5 Priority: normal
Severity: normal Version: 3.9.1
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

Hello,

I found a bug in when using multiple wp_editor's with different settings.

Sample:

wp_editor('', 'field_1', array(
 'textarea_name' => 'field_1',
 'tinymce'       => true,
 'default_editor' => 'tinymce'
 )
);

wp_editor('', 'field_2', array(
 'textarea_name' => 'field_2',
 'tinymce'       => false,
 'default_editor' => 'html'
 )
);

Result: I see tinymce editor for 2nd editor
Excepted result: should be html editor for 2nd editor

Conjecture:

you have the following code in WP:

if ( 'html' === $default_editor ) {
  add_filter('the_editor_content', 'wp_htmledit_pre');
  $switch_class = 'html-active';
} else {
  add_filter('the_editor_content', 'wp_richedit_pre');
  $switch_class = 'tmce-active';
}

For the first editor (field_1) system creates filter add_filter('the_editor_content', 'wp_richedit_pre');

but we don't need it for the 2nd editor (field_2). But he has already been initialized and will be applied for both editors when calling apply_filter('the_editor_content',...). So, please apply filters only to necessary editors which have related settings, not to everyone.

Attachments (1)

28403.patch (661 bytes) - added by marcochiesi 5 years ago.

Download all attachments as: .zip

Change History (8)

#1 @marcochiesi
5 years ago

  • Keywords has-patch added

I encountered this same bug today (on 4.0). The editor content filters should be removed after the editor is displayed, so that they will not affect the following instances.

This can be fixed by adding the following at the end of the "editor" method

	remove_filter('the_editor_content', 'wp_htmledit_pre');
	remove_filter('the_editor_content', 'wp_richedit_pre');

@marcochiesi
5 years ago

#2 @marcochiesi
5 years ago

Just added a patch file with a few conditions on filter removals.

#3 @marcochiesi
5 years ago

  • Keywords dev-feedback added

#4 @chriscct7
4 years ago

  • Keywords needs-refresh added

#5 @marcochiesi
4 years ago

Should I send an updated patch?

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

#6 @azaozz
3 years ago

  • Keywords dev-feedback needs-refresh removed
  • Milestone changed from Awaiting Review to 4.5

Most of this was fixed in 4.3. Both 'wp_htmledit_pre and 'wp_richedit_pre were deprecated in favor of format_for_editor. However we should still remove the filtering after it runs in case the next editor instance on the same page doesn't need it.

#7 @azaozz
3 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 36062:

Editor: remove the format_for_editor filter from the_editor_content after it runs as the next editor instance on the same page may not need it.

Props marcochiesi, azaozz.
Fixes #28403.

Note: See TracTickets for help on using tickets.