wppaste
WordPress

wp_get_code_editor_settings( array $args ): array|false

Since
5.0.0
Source
wp-includes/general-template.php:4105
Generates and returns code editor settings.

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.
  • $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 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
28–130

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

Plugin surface
1 hook

Third-party callbacks on 'wp_code_editor_settings' 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 callbacksapply_filters()called directly

Further down the call graph this can also reach query. That is 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.

WhenInstructionsCalls it makes
!isset($args) && !$type28–60wp_array_slice_assoc(), apply_filters()
!isset($args) && !$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can()33–38current_user_can(), wp_array_slice_assoc(), apply_filters()
!$type34–66basename(), wp_array_slice_assoc(), apply_filters()
!isset($args) && $type35–40mode(), wp_array_slice_assoc(), apply_filters()
!$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can()39–44basename(), current_user_can(), wp_array_slice_assoc(), apply_filters()
!isset($args) && !$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can()40–45current_user_can(), wp_kses_allowed_html(), wp_array_slice_assoc(), apply_filters()
$type41–46basename(), mode(), wp_array_slice_assoc(), apply_filters()
!$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can()46–51basename(), current_user_can(), wp_kses_allowed_html(), wp_array_slice_assoc(), apply_filters()
wp_get_mime_types() && !$type49–130basename(), pathinfo(), strtolower(), wp_get_mime_types(), wp_array_slice_assoc(), apply_filters()
wp_get_mime_types() && !$type && $type !== "text/x-diff" && $type === "text/html" && current_user_can()54–106basename(), pathinfo(), strtolower(), wp_get_mime_types(), current_user_can(), wp_array_slice_assoc(), apply_filters()
wp_get_mime_types() && $type56–108basename(), pathinfo(), strtolower(), wp_get_mime_types(), mode(), wp_array_slice_assoc(), apply_filters()
wp_get_mime_types() && !$type && $type !== "text/x-diff" && $type === "text/html" && !current_user_can()61–113basename(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev25628–13058
8.525628–13058
8.425628–1305815 fewer instructions than PHP 8.3
8.327128–14258
8.227128–14258
8.127128–14258
7.427128–14258

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:

  1. apply_filters( wp_code_editor_settings )filterline 4441 (+336 into the body)

    Filters settings that are passed into the code editor.

Uses · 6

Used by · 1

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(			// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>.			'boss'     => true,			'curly'    => true,			'eqeqeq'   => true,			'eqnull'   => true,			'es3'      => true,			'expr'     => true,			'immed'    => true,			'noarg'    => true,			'nonbsp'   => true,			'onevar'   => true,			'quotmark' => 'single',			'trailing' => true,			'undef'    => true,			'unused'   => true, 			'browser'  => true, 			'globals'  => array(				'_'        => false,				'Backbone' => false,				'jQuery'   => false,				'JSON'     => false,				'wp'       => 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,			'space-tab-mixed-disabled' => 'tab',			'attr-unsafe-chars'        => true,		),	); 	$type = '';	if ( isset( $args['type'] ) ) {		$type = $args['type']; 		// Remap MIME types to ones that CodeMirror modes will recognize.		if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {			$type = 'text/x-diff';		}

Changelog

Introduced in 5.0.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/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.