wp_enqueue_code_editor( array $args )
Enqueue assets needed by the code editor for the given settings.
Description
See also
Parameters
- $args
-
(array) (Required) Args.
-
'type'
(string) The MIME type of the file to be edited. -
'file'
(string) Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to$typeparam. -
'theme'
(WP_Theme) Theme being edited when on theme editor. -
'plugin'
(string) Plugin being edited when on plugin editor. -
'codemirror'
(array) Additional CodeMirror setting overrides. -
'csslint'
(array) CSSLint rule overrides. -
'jshint'
(array) JSHint rule overrides. -
'htmlhint'
(array) HTMLHint rule overrides.
-
'type'
Return
(array|false) Settings for the enqueued code editor, or false if the editor was not enqueued.
Source
File: wp-includes/general-template.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' );
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
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor