[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/customize/ -> class-wp-customize-code-editor-control.php (source)

   1  <?php
   2  /**
   3   * Customize API: WP_Customize_Code_Editor_Control class
   4   *
   5   * @package WordPress
   6   * @subpackage Customize
   7   * @since 4.9.0
   8   */
   9  
  10  /**
  11   * Customize Code Editor Control class.
  12   *
  13   * @since 4.9.0
  14   *
  15   * @see WP_Customize_Control
  16   */
  17  class WP_Customize_Code_Editor_Control extends WP_Customize_Control {
  18  
  19      /**
  20       * Customize control type.
  21       *
  22       * @since 4.9.0
  23       * @var string
  24       */
  25      public $type = 'code_editor';
  26  
  27      /**
  28       * Type of code that is being edited.
  29       *
  30       * @since 4.9.0
  31       * @var string
  32       */
  33      public $code_type = '';
  34  
  35      /**
  36       * Code editor settings.
  37       *
  38       * @see wp_enqueue_code_editor()
  39       * @since 4.9.0
  40       * @var array|false
  41       */
  42      public $editor_settings = array();
  43  
  44      /**
  45       * Enqueue control related scripts/styles.
  46       *
  47       * @since 4.9.0
  48       */
  49  	public function enqueue() {
  50          $this->editor_settings = wp_enqueue_code_editor(
  51              array_merge(
  52                  array(
  53                      'type'       => $this->code_type,
  54                      'codemirror' => array(
  55                          'indentUnit' => 2,
  56                          'tabSize'    => 2,
  57                      ),
  58                  ),
  59                  $this->editor_settings
  60              )
  61          );
  62      }
  63  
  64      /**
  65       * Refresh the parameters passed to the JavaScript via JSON.
  66       *
  67       * @since 4.9.0
  68       * @see WP_Customize_Control::json()
  69       *
  70       * @return array Array of parameters passed to the JavaScript.
  71       */
  72  	public function json() {
  73          $json                    = parent::json();
  74          $json['editor_settings'] = $this->editor_settings;
  75          $json['input_attrs']     = $this->input_attrs;
  76          return $json;
  77      }
  78  
  79      /**
  80       * Don't render the control content from PHP, as it's rendered via JS on load.
  81       *
  82       * @since 4.9.0
  83       */
  84  	public function render_content() {}
  85  
  86      /**
  87       * Render a JS template for control display.
  88       *
  89       * @since 4.9.0
  90       */
  91  	public function content_template() {
  92          ?>
  93          <# var elementIdPrefix = 'el' + String( Math.random() ); #>
  94          <# if ( data.label ) { #>
  95              <label for="{{ elementIdPrefix }}_editor" class="customize-control-title">
  96                  {{ data.label }}
  97              </label>
  98          <# } #>
  99          <# if ( data.description ) { #>
 100              <span class="description customize-control-description">{{{ data.description }}}</span>
 101          <# } #>
 102          <div class="customize-control-notifications-container"></div>
 103          <textarea id="{{ elementIdPrefix }}_editor"
 104              <# _.each( _.extend( { 'class': 'code' }, data.input_attrs ), function( value, key ) { #>
 105                  {{{ key }}}="{{ value }}"
 106              <# }); #>
 107              ></textarea>
 108          <?php
 109      }
 110  }


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1