wp_get_code_editor_settings( array $args ): array|false
- Since
- 5.0.0
- Source
wp-includes/general-template.php:4128
Compatibility
- WordPress
- since 5.0.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 code editor.
Performance profile
How much work a call to wp_get_code_editor_settings() 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
- Light
- Scaling
- Scales with input
- Instructions
- 63–162
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 305.
Third-party callbacks on 'wp_code_editor_settings' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, query, 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 · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_code_editor_settings() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$args && !isset($args) && !$type | 63–94 | str_ends_with(), includes_url(), add_query_arg(), wp_array_slice_assoc(), apply_filters() |
!$args && !isset($args) && !$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can() | 68–73 | str_ends_with(), includes_url(), add_query_arg(), current_user_can(), wp_array_slice_assoc(), apply_filters() |
!$args && !isset($args) && $type | 69–74 | str_ends_with(), includes_url(), add_query_arg(), mode(), wp_array_slice_assoc(), apply_filters() |
!$args && !$type | 69–100 | str_ends_with(), includes_url(), add_query_arg(), basename(), wp_array_slice_assoc(), apply_filters() |
!$args && !$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can() | 74–79 | str_ends_with(), includes_url(), add_query_arg(), basename(), current_user_can(), wp_array_slice_assoc(), apply_filters() |
!$args && !isset($args) && !$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can() | 75–80 | str_ends_with(), includes_url(), add_query_arg(), current_user_can(), wp_kses_allowed_html(), wp_array_slice_assoc(), apply_filters() |
!$args && $type | 75–80 | str_ends_with(), includes_url(), add_query_arg(), basename(), mode(), wp_array_slice_assoc(), apply_filters() |
!$args && !$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can() | 81–86 | str_ends_with(), includes_url(), add_query_arg(), basename(), current_user_can(), wp_kses_allowed_html(), wp_array_slice_assoc(), apply_filters() |
!$args && wp_get_mime_types() && !$type | 84–162 | str_ends_with(), includes_url(), add_query_arg(), basename(), pathinfo(), strtolower(), wp_get_mime_types(), wp_array_slice_assoc(), apply_filters() |
!$args && wp_get_mime_types() && !$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can() | 89–139 | str_ends_with(), includes_url(), add_query_arg(), basename(), pathinfo(), strtolower(), wp_get_mime_types(), current_user_can(), wp_array_slice_assoc(), apply_filters() |
!$args && wp_get_mime_types() && $type | 90–140 | str_ends_with(), includes_url(), add_query_arg(), basename(), pathinfo(), strtolower(), wp_get_mime_types(), mode(), wp_array_slice_assoc(), apply_filters() |
!$args && wp_get_mime_types() && !$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can() | 96–146 | str_ends_with(), includes_url(), add_query_arg(), basename(), pathinfo(), strtolower(), wp_get_mime_types(), current_user_can(), wp_kses_allowed_html(), wp_array_slice_assoc(), apply_filters() |
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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 305 | 63–162 | 60 | |
| 8.5 | 305 | 63–162 | 60 | |
| 8.4 | 305 | 63–162 | 60 | 15 fewer instructions than PHP 8.3 |
| 8.3 | 320 | 63–174 | 60 | |
| 8.2 | 320 | 63–174 | 60 | |
| 8.1 | 320 | 63–174 | 60 | |
| 7.4 | 320 | 63–174 | 60 |
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_get_code_editor_settings() runs, in this order:
- apply_filters( wp_code_editor_settings )filterline 4478 (+350 into the body)
Filters settings that are passed into the code editor.
Uses · 9
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- add_query_arg()Retrieves a modified URL query string.
- includes_url()Retrieves the URL to the includes directory.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- wp_get_mime_types()Retrieves the list of mime types and file extensions.
- current_user_can()Returns whether the current user has the specified capability.
- wp_kses_allowed_html()Returns an array of allowed HTML tags and attributes for a given context.
- wp_array_slice_assoc()Extracts a slice of an array, given a list of keys.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- wp_enqueue_code_editor()Enqueues assets needed by the code editor for the given settings.
Source code
function wp_get_code_editor_settings( $args ) { $settings = array( 'codemirror' => array( 'indentUnit' => 4, 'indentWithTabs' => true, 'inputStyle' => 'contenteditable', 'lineNumbers' => true, 'lineWrapping' => true, 'styleActiveLine' => true, 'continueComments' => true, 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete', 'Ctrl-/' => 'toggleComment', 'Cmd-/' => 'toggleComment', 'Alt-F' => 'findPersistent', 'Ctrl-F' => 'findPersistent', 'Cmd-F' => 'findPersistent', ), 'direction' => 'ltr', // Code is shown in LTR even in RTL languages. 'gutters' => array(), ), 'csslint' => array( 'errors' => true, // Parsing errors. 'box-model' => true, 'display-property-grouping' => true, 'duplicate-properties' => true, 'known-properties' => true, 'outline-none' => true, ), 'jshint' => array( 'esversion' => 11, 'module' => str_ends_with( $args['file'] ?? '', '.mjs' ), // This script module URL is intentionally referenced here instead of registering an espree script module // in wp_default_script_modules(). This is a first stab at a core-only private module. 'espreeModuleUrl' => add_query_arg( 'ver', '9.6.1', includes_url( 'js/codemirror/espree.min.js' ) ), // The following JSHint *linting rule* options are copied from // <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>. // Parsing-related options such as `esversion` (and, in other contexts, `es5`, `es3`, `module`, `strict`) // are honored by the Espree-based integration, but these linting-rule options are not interpreted by Espree // and are kept only for compatibility/documentation with the original JSHint configuration. 'boss' => true, 'curly' => true, 'eqeqeq' => true, 'eqnull' => true, 'expr' => true, 'immed' => true, 'noarg' => true, 'nonbsp' => true, 'quotmark' => 'single', 'undef' => true, 'unused' => true, 'browser' => true, 'globals' => array( '_' => false, 'Backbone' => false, 'jQuery' => false, 'JSON' => false, 'wp' => false, 'export' => false, 'module' => false, 'require' => false, 'WorkerGlobalScope' => false, 'self' => false, 'OffscreenCanvas' => false, 'Promise' => false, ), ), 'htmlhint' => array( 'tagname-lowercase' => true, 'attr-lowercase' => true, 'attr-value-double-quotes' => false, 'doctype-first' => false, 'tag-pair' => true, 'spec-char-escape' => true, 'id-unique' => true, 'src-not-empty' => true, 'attr-no-duplication' => true, 'alt-require' => true,Changelog
Introduced in 5.0.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 7.0.4 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.