# wp_enqueue_code_editor()

URL: https://chugunov.pro/api-wordpress/functions/wp_enqueue_code_editor/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.9.0.

## Сигнатура

```php
wp_enqueue_code_editor( array $args ): array|false
```

## Описание

[See also](#see-also)
- [wp_enqueue_editor()](https://developer.wordpress.org/reference/functions/wp_enqueue_editor/)

- [wp_get_code_editor_settings()](https://developer.wordpress.org/reference/functions/wp_get_code_editor_settings/)

- [_WP_Editors::parse_settings()](https://developer.wordpress.org/reference/classes/_WP_Editors/parse_settings/)

## Параметры

- `$args` `array` — обязательный. Аргументы.
  
  type stringMIME-тип редактируемого файла.
  
  file stringИмя редактируемого файла. Расширение используется для определения типа. Может быть передано как альтернатива параметру $type.
  
  theme WP_ThemeTheme, редактируемая в редакторе файлов темы.
  
  plugin stringПлагин, редактируемый в редакторе файлов плагина.
  
  codemirror arrayДополнительные переопределения настроек CodeMirror.
  
  csslint arrayПереопределения правил CSSLint.
  
  jshint arrayПереопределения правил JSHint.
  
  htmlhint arrayПереопределения правил HTMLHint.

## Возвращаемое значение

`array|false`

## Исходный код

Файл: `wp-includes/general-template.php:4039`

```php
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;
}
```

## История изменений

- 4.9.0 — Introduced.

## Связанные

Использует: [`wp_get_code_editor_settings`](https://chugunov.pro/api-wordpress/functions/wp_get_code_editor_settings/), [`wp_add_inline_script`](https://chugunov.pro/api-wordpress/functions/wp_add_inline_script/), [`wp_get_current_user`](https://chugunov.pro/api-wordpress/functions/wp_get_current_user/), [`wp_json_encode`](https://chugunov.pro/api-wordpress/functions/wp_json_encode/), [`current_user_can`](https://chugunov.pro/api-wordpress/functions/current_user_can/), [`is_user_logged_in`](https://chugunov.pro/api-wordpress/functions/is_user_logged_in/), [`wp_enqueue_script`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_script/), [`wp_enqueue_style`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_style/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/).
Используется в: `WP_Widget_Custom_HTML::enqueue_admin_scripts`, `WP_Customize_Code_Editor_Control::enqueue`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor/
