wp_enqueue_code_editor( array $args ): array|false
- Since
- 4.9.0
- Source
wp-includes/general-template.php:4014
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.
$typestringThe MIME type of the file to be edited.$filestringFilename to be edited. Extension is used to sniff the type. Can be supplied as alternative to$typeparam.$themeWP_ThemeTheme being edited when on the theme file editor.$pluginstringPlugin being edited when on the plugin file editor.$codemirrorarrayAdditional CodeMirror setting overrides.$csslintarrayCSSLint rule overrides.$jshintarrayJSHint rule overrides.$htmlhintarrayHTMLHint 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
- Scaling
- Constant
- Instructions
- 10–91
- Plugin surface
- 1 hook
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 115.
Third-party callbacks on 'wp_enqueue_code_editor' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_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 · 13 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.
| When | Instructions | Calls it makes |
|---|---|---|
is_user_logged_in() | 10 | is_user_logged_in(), wp_get_current_user() |
!is_user_logged_in() && empty($settings) | 11–13 | is_user_logged_in(), wp_get_code_editor_settings() |
is_user_logged_in() && empty($settings) | 16–18 | is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings() |
!is_user_logged_in() && !empty($settings) | 36–81 | is_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) | 41–86 | is_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–60 | is_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) | 52–86 | is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action() |
is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) | 55–65 | is_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) | 57–91 | is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), 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() | 59–79 | is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), 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() | 63–83 | is_user_logged_in(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), 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() | 64–84 | is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_json_encode(), wp_add_inline_script(), do_action() |
1 further outcome, up to 88 instructions
is_user_logged_in() && !empty($settings) && isset($value) && !empty($value) && !current_user_can() | 68–88 | is_user_logged_in(), wp_get_current_user(), wp_get_code_editor_settings(), wp_enqueue_script(), wp_enqueue_style(), wp_enqueue_script(), wp_enqueue_script(), wp_enqueue_script(), current_user_can(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 115 | 10–91 | 25 | |
| 8.5 | 115 | 10–91 | 25 | |
| 8.4 | 115 | 10–91 | 25 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 116 | 10–92 | 25 | |
| 8.2 | 116 | 10–92 | 25 | 1 more instruction than PHP 8.1 |
| 8.1 | 115 | 10–92 | 25 | |
| 7.4 | 115 | 10–92 | 25 |
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:
- do_action( wp_enqueue_code_editor )actionline 4079 (+65 into the body)
Fires when scripts and styles are enqueued for the code editor.
Uses · 9
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_get_current_user()Retrieves the current user object.
- wp_get_code_editor_settings()Generates and returns code editor settings.
- wp_enqueue_script()Enqueues a script.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- current_user_can()Returns whether the current user has the specified capability.
- wp_add_inline_script()Adds extra code to a registered script.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- do_action()Calls the callback functions that have been added to an action hook.
Used by · 2
- WP_Customize_Code_Editor_Control::enqueue()Enqueue control related scripts/styles.
- WP_Widget_Custom_HTML::enqueue_admin_scripts()Loads the required scripts and styles for the widget control.
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' ); wp_enqueue_script( 'jshint' ); 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( 'jshint' ); wp_enqueue_script( 'jsonlint' ); break; } } } wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); /** * 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.
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/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.