Make WordPress Core

Opened 10 years ago

Closed 8 years ago

#28403 closed defect (bug) (fixed)

Multiple wp_editor's with different settings

Reported by: madeinua's profile madeinua Owned by: azaozz's profile 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 10 years ago.

Download all attachments as: .zip

Change History (8)

#1 @marcochiesi
10 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
10 years ago

#2 @marcochiesi
10 years ago

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

#3 @marcochiesi
9 years ago

  • Keywords dev-feedback added

#4 @chriscct7
8 years ago

  • Keywords needs-refresh added

#5 @marcochiesi
8 years ago

Should I send an updated patch?

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

#6 @azaozz
8 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
8 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.