Make WordPress Core


Ignore:
Timestamp:
09/21/2017 11:03:06 PM (9 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/class-wp-customize-manager.php

    r41550 r41558  
    214214
    215215        /**
    216          * Code Editor Settings for Custom CSS.
    217          *
    218          * This variable contains the settings returned by `wp_enqueue_code_editor()` which are then later output
    219          * to the client in `WP_Customize_Manager::customize_pane_settings()`. A value of false means that the
    220          * Custom CSS section or control was removed, or that the Syntax Highlighting user pref was turned off.
    221          *
    222          * @see wp_enqueue_code_editor()
    223          * @see WP_Customize_Manager::enqueue_control_scripts()
    224          * @see WP_Customize_Manager::customize_pane_settings()
    225          * @since 4.9.0
    226          * @var array|false
    227          */
    228         private $_custom_css_code_editor_settings = false;
    229 
    230         /**
    231216         * Constructor.
    232217         *
    … …  
    292277                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
    293278                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
     279                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-code-editor-control.php' );
    294280                require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' );
    295281                require_once( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' );
    … …  
    33383324                        $control->enqueue();
    33393325                }
    3340 
    3341                 if ( $this->get_section( 'custom_css' ) && $this->get_control( 'custom_css' ) ) {
    3342                         $this->_custom_css_code_editor_settings = wp_enqueue_code_editor( array(
    3343                                 'type' => 'text/css',
    3344                         ) );
    3345                 }
    33463326        }
    33473327
    … …  
    36003580                                'stylesheet' => $this->get_stylesheet(),
    36013581                                'active'     => $this->is_theme_active(),
    3602                         ),
    3603                         'customCss' => array(
    3604                                 'codeEditor' => $this->_custom_css_code_editor_settings,
    36053582                        ),
    36063583                        'url'      => array(
    … …  
    37373714                $this->register_control_type( 'WP_Customize_Site_Icon_Control' );
    37383715                $this->register_control_type( 'WP_Customize_Theme_Control' );
     3716                $this->register_control_type( 'WP_Customize_Code_Editor_Control' );
    37393717
    37403718                /* Themes */
    … …  
    42404218                $this->add_setting( $custom_css_setting );
    42414219
    4242                 $this->add_control( 'custom_css', array(
    4243                         'type'     => 'textarea',
     4220                $this->add_control( new WP_Customize_Code_Editor_Control( $this, 'custom_css', array(
    42444221                        'section'  => 'custom_css',
    42454222                        'settings' => array( 'default' => $custom_css_setting->id ),
    4246                         'input_attrs' => array(
    4247                                 'class' => 'code', // Ensures contents displayed as LTR instead of RTL.
    4248                         ),
    4249                 ) );
     4223                        'code_type' => 'text/css',
     4224                ) ) );
    42504225        }
    42514226
Note: See TracChangeset for help on using the changeset viewer.