Make WordPress Core


Ignore:
Timestamp:
09/21/2017 11:03:06 PM (7 years ago)
Author:
westonruter
Message:

Customize: Introduce extensible code editor Customizer control for CodeMirror.

  • Adds WP_Customize_Code_Editor_Control and wp.customize.CodeEditorControl().
  • Control respects user preference for syntax highlighting, showing a textarea when user opts out.
  • Code editor control takes the ad hoc code for Additional CSS and makes it reusable and extensible, for Additional CSS in core and plugins to use (such as Jetpack).
  • Replace settings arg in wp_enqueue_code_editor() with separate args for codemirror, csslint, jshint, and htmlhint.
  • Prefix codemirror script and style handles with wp- to prevent collisions, as also the object is exported as wp.CodeMirror in JS.
  • Reduce indent size in Customizer code editor instances and Custom HTML widget to use tab size of 2 instead of 4 to save on space.

See #12423, #38707, #35395.
Fixes #41897.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r41376 r41558  
    31263126 *     Args.
    31273127 *
    3128  *     @type string   $type     The MIME type of the file to be edited.
    3129  *     @type string   $file     Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
    3130  *     @type array    $settings Settings to merge on top of defaults which derive from `$type` or `$file` args.
    3131  *     @type WP_Theme $theme    Theme being edited when on theme editor.
    3132  *     @type string   $plugin   Plugin being edited when on plugin editor.
     3128 *     @type string   $type       The MIME type of the file to be edited.
     3129 *     @type string   $file       Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
     3130 *     @type WP_Theme $theme      Theme being edited when on theme editor.
     3131 *     @type string   $plugin     Plugin being edited when on plugin editor.
     3132 *     @type array    $codemirror Additional CodeMirror setting overrides.
     3133 *     @type array    $csslint    CSSLint rule overrides.
     3134 *     @type array    $jshint     JSHint rule overrides.
     3135 *     @type array    $htmlhint   JSHint rule overrides.
    31333136 * }
    31343137 * @returns array|false Settings for the enqueued code editor, or false if the editor was not enqueued .
     
    34093412
    34103413    // Let settings supplied via args override any defaults.
    3411     if ( isset( $args['settings'] ) ) {
    3412         foreach ( $args['settings'] as $key => $value ) {
    3413             $settings[ $key ] = array_merge(
    3414                 $settings[ $key ],
    3415                 $value
    3416             );
    3417         }
     3414    foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) {
     3415        $settings[ $key ] = array_merge(
     3416            $settings[ $key ],
     3417            $value
     3418        );
    34183419    }
    34193420
     
    34293430     *     Args passed when calling `wp_enqueue_code_editor()`.
    34303431     *
    3431      *     @type string   $type     The MIME type of the file to be edited.
    3432      *     @type string   $file     Filename being edited.
    3433      *     @type array    $settings Settings to merge on top of defaults which derive from `$type` or `$file` args.
    3434      *     @type WP_Theme $theme    Theme being edited when on theme editor.
    3435      *     @type string   $plugin   Plugin being edited when on plugin editor.
     3432     *     @type string   $type       The MIME type of the file to be edited.
     3433     *     @type string   $file       Filename being edited.
     3434     *     @type WP_Theme $theme      Theme being edited when on theme editor.
     3435     *     @type string   $plugin     Plugin being edited when on plugin editor.
     3436     *     @type array    $codemirror Additional CodeMirror setting overrides.
     3437     *     @type array    $csslint    CSSLint rule overrides.
     3438     *     @type array    $jshint     JSHint rule overrides.
     3439     *     @type array    $htmlhint   JSHint rule overrides.
    34363440     * }
    34373441     */
     
    34443448    wp_enqueue_script( 'code-editor' );
    34453449    wp_enqueue_style( 'code-editor' );
    3446 
    3447     wp_enqueue_script( 'codemirror' );
    3448     wp_enqueue_style( 'codemirror' );
    34493450
    34503451    if ( isset( $settings['codemirror']['mode'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.