Editor.php
100 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customizer Control: editor. |
| 4 | * |
| 5 | * Creates a TinyMCE textarea. |
| 6 | * |
| 7 | * @package kirki-framework/control-editor |
| 8 | * @copyright Copyright (c) 2023, Themeum |
| 9 | * @license https://opensource.org/licenses/MIT |
| 10 | * @since 1.0 |
| 11 | */ |
| 12 | |
| 13 | namespace Kirki\Control; |
| 14 | |
| 15 | use Kirki\Control\Base; |
| 16 | use Kirki\URL; |
| 17 | |
| 18 | /** |
| 19 | * A TinyMCE control. |
| 20 | * |
| 21 | * @since 1.0 |
| 22 | */ |
| 23 | class Editor extends Base { |
| 24 | |
| 25 | /** |
| 26 | * The control type. |
| 27 | * |
| 28 | * @access public |
| 29 | * @since 1.0 |
| 30 | * @var string |
| 31 | */ |
| 32 | public $type = 'kirki-editor'; |
| 33 | |
| 34 | /** |
| 35 | * The version. Used in scripts & styles for cache-busting. |
| 36 | * |
| 37 | * @static |
| 38 | * @access public |
| 39 | * @since 1.0 |
| 40 | * @var string |
| 41 | */ |
| 42 | public static $control_ver = '1.0'; |
| 43 | |
| 44 | /** |
| 45 | * Args to pass to TinyMCE. |
| 46 | * |
| 47 | * @access public |
| 48 | * @since 1.0 |
| 49 | * @var bool |
| 50 | */ |
| 51 | public $choices = []; |
| 52 | |
| 53 | /** |
| 54 | * Enqueue control related scripts/styles. |
| 55 | * |
| 56 | * @access public |
| 57 | * @since 1.0 |
| 58 | * @return void |
| 59 | */ |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Refresh the parameters passed to the JavaScript via JSON. |
| 64 | * |
| 65 | * @access public |
| 66 | * @since 1.0 |
| 67 | * @return void |
| 68 | */ |
| 69 | public function to_json() { |
| 70 | parent::to_json(); |
| 71 | $this->json['choices'] = $this->choices; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * An Underscore (JS) template for this control's content (but not its container). |
| 76 | * |
| 77 | * Class variables for this control class are available in the `data` JS object; |
| 78 | * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
| 79 | * |
| 80 | * The actual editor is added from the \Kirki\Field\Editor class. |
| 81 | * All this template contains is a button that triggers the global editor on/off |
| 82 | * and a hidden textarea element that is used to mirror save the options. |
| 83 | * |
| 84 | * @see WP_Customize_Control::print_template() |
| 85 | * |
| 86 | * @access protected |
| 87 | * @since 1.0 |
| 88 | * @return void |
| 89 | */ |
| 90 | protected function content_template() { |
| 91 | ?> |
| 92 | <label> |
| 93 | <# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #> |
| 94 | <# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #> |
| 95 | </label> |
| 96 | <textarea id="kirki-editor-{{{ data.id.replace( '[', '' ).replace( ']', '' ) }}}" {{{ data.inputAttrs }}} {{{ data.link }}}>{{ data.value }}</textarea> |
| 97 | <?php |
| 98 | } |
| 99 | } |
| 100 |