| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Field: code_editor |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Field_code_editor' ) ) { |
| 11 |
class ADMINIFY_Field_code_editor extends ADMINIFY_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$default_settings = array( |
| 20 |
'tabSize' => 2, |
| 21 |
'lineNumbers' => true, |
| 22 |
'theme' => 'default', |
| 23 |
'mode' => 'htmlmixed', |
| 24 |
); |
| 25 |
|
| 26 |
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array(); |
| 27 |
$settings = wp_parse_args( $settings, $default_settings ); |
| 28 |
|
| 29 |
echo wp_kses_post( $this->field_before() ); |
| 30 |
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes() .' data-editor="'. esc_attr( wp_json_encode( $settings ) ) .'">'. esc_textarea( $this->value ) .'</textarea>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- field_attributes() escapes each attribute via esc_attr() |
| 31 |
echo wp_kses_post( $this->field_after() ); |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
public function enqueue() { |
| 36 |
|
| 37 |
$page = ( ! empty( $_GET[ 'page' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'page' ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. |
| 38 |
|
| 39 |
// Do not loads CodeMirror in revslider page. |
| 40 |
if ( in_array( $page, array( 'revslider' ) ) ) { return; } |
| 41 |
|
| 42 |
// Use WordPress core's bundled CodeMirror instead of shipping our own copy. |
| 43 |
// wp_enqueue_code_editor() registers `code-editor` + `wp-codemirror` (with |
| 44 |
// the common language modes) and exposes window.wp.CodeMirror. |
| 45 |
if ( function_exists( 'wp_enqueue_code_editor' ) ) { |
| 46 |
wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); |
| 47 |
wp_enqueue_script( 'wp-codemirror' ); |
| 48 |
wp_enqueue_style( 'wp-codemirror' ); |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
} |
| 55 |
|