| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\WordPress\Settings\Options; |
| 4 |
|
| 5 |
use Depicter\WordPress\Settings\Options\OptionAbstract; |
| 6 |
|
| 7 |
class CodeEditor extends OptionAbstract |
| 8 |
{ |
| 9 |
public $view = 'code-editor'; |
| 10 |
|
| 11 |
public function __construct($section, $args = []) |
| 12 |
{ |
| 13 |
add_action('admin_enqueue_scripts', [$this, 'enqueue']); |
| 14 |
|
| 15 |
parent::__construct($section, $args); |
| 16 |
} |
| 17 |
|
| 18 |
public function enqueue() |
| 19 |
{ |
| 20 |
wp_enqueue_script('wp-theme-plugin-editor'); |
| 21 |
wp_enqueue_style('wp-codemirror'); |
| 22 |
|
| 23 |
$settings_name = str_replace('-', '_', $this->get_id_attribute()); |
| 24 |
|
| 25 |
wp_localize_script('jquery', $settings_name, wp_enqueue_code_editor(['type' => $this->get_arg('editor_type', 'text/html')])); |
| 26 |
|
| 27 |
wp_add_inline_script('wp-theme-plugin-editor', 'jQuery(function($){ wp.codeEditor.initialize($("#'.$this->get_id_attribute().'"), '.$settings_name.'); });'); |
| 28 |
} |
| 29 |
|
| 30 |
public function sanitize($value) |
| 31 |
{ |
| 32 |
return $value; |
| 33 |
} |
| 34 |
} |
| 35 |
|