wppaste
WordPress

_WP_Editors::editor( string $content, string $editor_id, array $settings = array() )

Since
3.3.0
Source
wp-includes/class-wp-editor.php:159
Outputs the HTML for a single instance of the editor.

Compatibility

WordPress
since 3.3.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$contentstring
Initial content for the editor.
$editor_idstring
HTML ID for the textarea and TinyMCE and Quicktags instances.
Should not contain square brackets.
$settingsarrayoptional
See _WP_Editors::parse_settings() for description.Default: array()

Performance profile

How much work a call to _WP_Editors::editor() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
121–193

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 281.

Plugin surface
5 hooks

Third-party callbacks on 'media_buttons', 'the_editor', 'the_editor_content' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 36 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _WP_Editors::editor() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$set && empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"121–150::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html"125–162::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"125–154::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"127–156::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"129–166::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html"129–166::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html"131–168::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"131–160::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons) && $default_editor !== "tinymce"133–144::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"133–170::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"135–172::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html"135–172::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
24 further outcomes, up to 193 instructions
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons)137–156::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons) && $default_editor !== "tinymce"137–148::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons) && $default_editor !== "tinymce"139–142::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"139–176::parse_settings(), esc_attr(), esc_attr(), current_user_can(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !empty($buttons) && !has_filter() && $default_editor === "tinymce"141–160::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons)141–160::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"142–167::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons)143–154::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons) && $default_editor !== "tinymce"143–146::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !empty($buttons) && !has_filter() && $default_editor === "tinymce"145–156::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html"146–179::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"146–171::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !empty($buttons) && !has_filter() && $default_editor === "tinymce"147–158::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && $default_editor !== "html" && !empty($buttons)147–158::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"148–173::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"150–183::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html"150–183::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
!$set && empty($set) && current_user_can() && !empty($buttons) && !has_filter() && $default_editor === "tinymce"151–162::parse_settings(), esc_attr(), esc_attr(), current_user_can(), wp_print_styles(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html"152–185::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html" && $default_editor !== "tinymce"152–177::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"154–187::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"156–189::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && $default_editor !== "html"156–189::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), stripos(), printf(), ::editor_settings()
empty($set) && current_user_can() && !has_filter() && $default_editor === "tinymce"160–193::parse_settings(), esc_attr(), esc_attr(), current_user_can(), function_exists(), do_action(), esc_attr(), apply_filters(), add_filter(), apply_filters(), remove_filter(), has_filter(), has_filter(), stripos(), printf(), ::editor_settings()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev280121–193291 fewer instruction than PHP 8.5
8.5281121–19329
8.4281121–193295 fewer instructions than PHP 8.3
8.3286123–19829
8.2286123–19829
8.1286123–198294 fewer instructions than PHP 7.4
7.4290123–20029

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 5

5 hooks fire while _WP_Editors::editor() runs, in this order:

  1. do_action( media_buttons )actionline 240 (+81 into the body)

    Fires after the default media button(s) are displayed.

  2. apply_filters( the_editor )filterline 267 (+108 into the body)

    Filters the HTML markup output that displays the editor.

  3. apply_filters( the_editor_content )filterline 289 (+130 into the body)

    Filters the default editor content.

  4. apply_filters( htmledit_pre )filterline 299 (+140 into the body)

    Filters the text before it is formatted for the HTML editor.

  5. apply_filters( richedit_pre )filterline 302 (+143 into the body)

    Filters text returned for the rich text editor.

Uses · 14

Show all 14

Used by · 1

Source code

	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 "Code" editor tab.				if ( 'html' !== $default_editor ) {					$default_editor = 'tinymce';				}				$tmce_active = ( 'html' === $default_editor ) ? ' aria-pressed="true"' : '';				$html_active = ( 'html' === $default_editor ) ? '' : ' aria-pressed="true"'; 				$buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce"' . $html_active . ' 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"' . $tmce_active . ' class="wp-switch-editor switch-html"' .					' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Code', 'Name for the Code editor tab (formerly Text)' ) . "</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'.

Changelog

Introduced in 3.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-editor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.