[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 * 69 * @see WP_Customize_Control::json() 70 * 71 * @return array Array of parameters passed to the JavaScript. 72 */ 73 public function json() { 74 $json = parent::json(); 75 $json['editor_settings'] = $this->editor_settings; 76 $json['input_attrs'] = $this->input_attrs; 77 return $json; 78 } 79 80 /** 81 * Don't render the control content from PHP, as it's rendered via JS on load. 82 * 83 * @since 4.9.0 84 */ 85 public function render_content() {} 86 87 /** 88 * Render a JS template for control display. 89 * 90 * @since 4.9.0 91 */ 92 public function content_template() { 93 ?> 94 <# var elementIdPrefix = 'el' + String( Math.random() ); #> 95 <# if ( data.label ) { #> 96 <label for="{{ elementIdPrefix }}_editor" class="customize-control-title"> 97 {{ data.label }} 98 </label> 99 <# } #> 100 <# if ( data.description ) { #> 101 <span class="description customize-control-description">{{{ data.description }}}</span> 102 <# } #> 103 <div class="customize-control-notifications-container"></div> 104 <textarea id="{{ elementIdPrefix }}_editor" 105 <# _.each( _.extend( { 'class': 'code' }, data.input_attrs ), function( value, key ) { #> 106 {{{ key }}}="{{ value }}" 107 <# }); #> 108 ></textarea> 109 <?php 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |