Apparently, a lot of us have been using wp_editor incorrectly and didn’t even know it. As of the WordPress version 3.9, you will receive an error if you are still using it this way:
| /** | |
| * This is how NOT to do it | |
| **/ | |
| // Codex usage: | |
| wp_editor( $content, $editor_id, $settings = array() ); | |
| // Example of inproper use (in a widget) | |
| wp_editor( ‘content’, $this->get_field_id( ‘content’ ) ); | |
| // Example of inproper use elsewhere | |
| // Change settings_field_name[content] to the correct settings field and field name | |
| wp_editor( ‘content’, ‘settings_field_name[content]’ ) ); |
The actual method is to place your field id in the textarea_name argument in the settings paramenter, like this:
| /** | |
| * This is the correct method of using wp_editor() | |
| **/ | |
| // Codex usage: | |
| wp_editor( $content, $editor_id, $settings = array() ); | |
| // Example of proper use in a widget | |
| wp_editor( ‘content’, ‘content’, array( ‘textarea_name’ => $this->get_field_id( ‘content’ ), ) ); | |
| // Alternate method when get_field_id is not available (options page or other) | |
| // Change settings_field_name[content] to the correct settings field and field name | |
| wp_editor( ‘content’, ‘content’, array( ‘textarea_name’ => ‘settings_field_name[content]’ ), ) ); |
It’s an easy fix, one that I’ve already seen a few plugins make since WordPress 3.9 was released. See the codex for more information on using wp_editor().
Update February 26, 2015: The code above originally showed the error using the Widget API get_field_id(), I’ve updated this to show how it might be used in/correctly elsewhere in WordPress.
Leave a Reply