wppaste
WordPress

wp_enqueue_code_editor( array $args ): array|false

Since
4.9.0
Source
wp-includes/general-template.php:4244
Enqueues assets needed by the code editor for the given settings.

Compatibility

WordPress
since 4.9.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

$argsarray
Args.
  • $typestring

    The MIME type of the file to be edited.
  • $filestring

    Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to $type param.
  • $themeWP_Theme

    Theme being edited when on the theme file editor.
  • $pluginstring

    Plugin being edited when on the plugin file editor.
  • $codemirrorarray

    Additional CodeMirror setting overrides.
  • $csslintarray

    CSSLint rule overrides.
  • $jshintarray

    JSHint rule overrides.
  • $htmlhintarray

    HTMLHint rule overrides.

Return value

array|false
Settings for the enqueued code editor, or false if the editor was not enqueued.

Performance profile

How much work a call to wp_enqueue_code_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
10–89

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

Plugin surface
1 hook

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

Called by
2

2 places 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 query, option, cache, serialize 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 · 11 distinct outcomes

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

WhenInstructionsCalls it makes
is_user_logged_in()10is_user_logged_in(), wp_get_current_user()
!is_user_logged_in() && empty($settings)11–13is_user_logged_in(), wp_get_code_editor_settings()
is_user_logged_in() && empty($settings)16–18is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings()
!is_user_logged_in() && !empty($settings)37–82is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_json_encode(), wp_add_inline_script(), do_action()
is_user_logged_in() && !empty($settings)42–87is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_json_encode(), wp_add_inline_script(), do_action()
!is_user_logged_in() && !empty($settings) && isset($value) && !empty($value)50–84is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action()
is_user_logged_in() && !empty($settings) && isset($value) && !empty($value)55–89is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action()
!is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) && current_user_can()57–77is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_json_encode(), wp_add_inline_script(), do_action()
!is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) && !current_user_can()61–81is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action()
is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) && current_user_can()62–82is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_json_encode(), wp_add_inline_script(), do_action()
is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) && !current_user_can()66–86is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11010–8925
8.511010–8925
8.411010–89251 fewer instruction than PHP 8.3
8.311110–9025
8.211110–90251 more instruction than PHP 8.1
8.111010–9125
7.411010–9125

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 · 1

One hook fires while wp_enqueue_code_editor() runs, in this order:

  1. do_action( wp_enqueue_code_editor )actionline 4307 (+63 into the body)

    Fires when scripts and styles are enqueued for the code editor.

Uses · 9

Used by · 2

Source code

function wp_enqueue_code_editor( $args ) {	if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {		return false;	} 	$settings = wp_get_code_editor_settings( $args ); 	if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {		return false;	} 	wp_enqueue_script( 'code-editor' );	wp_enqueue_style( 'code-editor' ); 	if ( isset( $settings['codemirror']['mode'] ) ) {		$mode = $settings['codemirror']['mode'];		if ( is_string( $mode ) ) {			$mode = array(				'name' => $mode,			);		} 		if ( ! empty( $settings['codemirror']['lint'] ) ) {			switch ( $mode['name'] ) {				case 'css':				case 'text/css':				case 'text/x-scss':				case 'text/x-less':					wp_enqueue_script( 'csslint' );					break;				case 'htmlmixed':				case 'text/html':				case 'php':				case 'application/x-httpd-php':				case 'text/x-php':					wp_enqueue_script( 'htmlhint' );					wp_enqueue_script( 'csslint' );					if ( ! current_user_can( 'unfiltered_html' ) ) {						wp_enqueue_script( 'htmlhint-kses' );					}					break;				case 'javascript':				case 'application/ecmascript':				case 'application/json':				case 'application/javascript':				case 'application/ld+json':				case 'text/typescript':				case 'application/typescript':					wp_enqueue_script( 'jsonlint' );					break;			}		}	} 	wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) ); 	/**	 * Fires when scripts and styles are enqueued for the code editor.	 *	 * @since 4.9.0	 *	 * @param array $settings Settings for the enqueued code editor.	 */	do_action( 'wp_enqueue_code_editor', $settings ); 	return $settings;}

Changelog

Introduced in 4.9.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 7.1.0 tag, from src/wp-includes/general-template.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.