_WP_Editors::editor( string $content, string $editor_id, array $settings = array() )
Outputs the HTML for a single instance of the editor.
Parameters
-
$content
string Required -
Initial content for the editor.
-
$editor_id
string Required -
HTML ID for the textarea and TinyMCE and Quicktags instances.
Should not contain square brackets. -
$settings
array Optional -
See _WP_Editors::parse_settings() for description.
More Arguments from _WP_Editors::parse_settings( ... $settings )
Array of editor arguments.
wpautop
boolWhether to use wpautop() . Default true.media_buttons
boolWhether to show the Add Media/other media buttons.default_editor
stringWhen both TinyMCE and Quicktags are used, set which editor is shown on page load. Default empty.drag_drop_upload
boolWhether to enable drag & drop on the editor uploading. Default false.
Requires the media modal.textarea_name
stringGive the textarea a unique name here. Square brackets can be used here. Default $editor_id.textarea_rows
intNumber rows in the editor textarea. Default 20.tabindex
string|intTabindex value to use. Default empty.tabfocus_elements
stringThe previous and next element ID to move the focus to when pressing the Tab key in TinyMCE. Default':prev,:next'
.editor_css
stringIntended for extra styles for both Visual and Text editors.
Should include<style>
tags, and can use "scoped". Default empty.editor_class
stringExtra classes to add to the editor textarea element. Default empty.teeny
boolWhether to output the minimal editor config. Examples include Press This and the Comment editor. Default false.dfw
boolDeprecated in 4.1. Unused.tinymce
bool|arrayWhether to load TinyMCE. Can be used to pass settings directly to TinyMCE using an array. Default true.quicktags
bool|arrayWhether to load Quicktags. Can be used to pass settings directly to Quicktags using an array. Default true.
Default:
array()
Source
File: wp-includes/class-wp-editor.php
.
View all references
public static function editor( $content, $editor_id, $settings = array() ) {
$set = self::parse_settings( $editor_id, $settings );
$editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
$default_editor = 'html';
$buttons = '';
$autocomplete = '';
$editor_id_attr = esc_attr( $editor_id );
if ( $set['drag_drop_upload'] ) {
self::$drag_drop_upload = true;
}
if ( ! empty( $set['editor_height'] ) ) {
$height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
} else {
$height = ' rows="' . (int) $set['textarea_rows'] . '"';
}
if ( ! current_user_can( 'upload_files' ) ) {
$set['media_buttons'] = false;
}
if ( self::$this_tinymce ) {
$autocomplete = ' autocomplete="off"';
if ( self::$this_quicktags ) {
$default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
// 'html' is used for the "Text" editor tab.
if ( 'html' !== $default_editor ) {
$default_editor = 'tinymce';
}
$buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' .
' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Visual', 'Name for the Visual editor tab' ) . "</button>\n";
$buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' .
' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
} else {
$default_editor = 'tinymce';
}
}
$switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
$wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
if ( $set['_content_editor_dfw'] ) {
$wrap_class .= ' has-dfw';
}
echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
if ( self::$editor_buttons_css ) {
wp_print_styles( 'editor-buttons' );
self::$editor_buttons_css = false;
}
if ( ! empty( $set['editor_css'] ) ) {
echo $set['editor_css'] . "\n";
}
if ( ! empty( $buttons ) || $set['media_buttons'] ) {
echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
if ( $set['media_buttons'] ) {
self::$has_medialib = true;
if ( ! function_exists( 'media_buttons' ) ) {
require ABSPATH . 'wp-admin/includes/media.php';
}
echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
/**
* Fires after the default media button(s) are displayed.
*
* @since 2.5.0
*
* @param string $editor_id Unique editor identifier, e.g. 'content'.
*/
do_action( 'media_buttons', $editor_id );
echo "</div>\n";
}
echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
echo "</div>\n";
}
$quicktags_toolbar = '';
if ( self::$this_quicktags ) {
if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && 'post' === $GLOBALS['current_screen']->base ) {
$toolbar_id = 'ed_toolbar';
} else {
$toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
}
$quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar hide-if-no-js"></div>';
}
/**
* Filters the HTML markup output that displays the editor.
*
* @since 2.1.0
*
* @param string $output Editor's HTML markup.
*/
$the_editor = apply_filters(
'the_editor',
'<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
$quicktags_toolbar .
'<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
'id="' . $editor_id_attr . '">%s</textarea></div>'
);
// Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat).
if ( self::$this_tinymce ) {
add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
}
/**
* Filters the default editor content.
*
* @since 2.1.0
*
* @param string $content Default editor content.
* @param string $default_editor The default editor for the current user.
* Either 'html' or 'tinymce'.
*/
$content = apply_filters( 'the_editor_content', $content, $default_editor );
// Remove the filter as the next editor on the same page may not need it.
if ( self::$this_tinymce ) {
remove_filter( 'the_editor_content', 'format_for_editor' );
}
// Back-compat for the `htmledit_pre` and `richedit_pre` filters.
if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
/** This filter is documented in wp-includes/deprecated.php */
$content = apply_filters_deprecated( 'htmledit_pre', array( $content ), '4.3.0', 'format_for_editor' );
} elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
/** This filter is documented in wp-includes/deprecated.php */
$content = apply_filters_deprecated( 'richedit_pre', array( $content ), '4.3.0', 'format_for_editor' );
}
if ( false !== stripos( $content, 'textarea' ) ) {
$content = preg_replace( '%</textarea%i', '</textarea', $content );
}
printf( $the_editor, $content );
echo "\n</div>\n\n";
self::editor_settings( $editor_id, $set );
}
Hooks
-
apply_filters( 'htmledit_pre',
string $output ) -
Filters the text before it is formatted for the HTML editor.
-
do_action( 'media_buttons',
string $editor_id ) -
Fires after the default media button(s) are displayed.
-
apply_filters( 'richedit_pre',
string $output ) -
Filters text returned for the rich text editor.
-
apply_filters( 'the_editor',
string $output ) -
Filters the HTML markup output that displays the editor.
-
apply_filters( 'the_editor_content',
string $content ,string $default_editor ) -
Filters the default editor content.
Changelog
Version | Description |
---|---|
3.3.0 | Introduced. |