-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwp_editor.php
107 lines (75 loc) · 2.8 KB
/
wp_editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: wp_editor
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'CSF_Field_wp_editor' ) ) {
class CSF_Field_wp_editor extends CSF_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$args = wp_parse_args( $this->field, array(
'tinymce' => true,
'quicktags' => true,
'media_buttons' => true,
'wpautop' => false,
'height' => '',
) );
$attributes = array(
'rows' => 10,
'class' => 'wp-editor-area',
'autocomplete' => 'off',
);
$editor_height = ( ! empty( $args['height'] ) ) ? ' style="height:'. esc_attr( $args['height'] ) .';"' : '';
$editor_settings = array(
'tinymce' => $args['tinymce'],
'quicktags' => $args['quicktags'],
'media_buttons' => $args['media_buttons'],
'wpautop' => $args['wpautop'],
);
echo $this->field_before();
echo ( csf_wp_editor_api() ) ? '<div class="csf-wp-editor" data-editor-settings="'. esc_attr( json_encode( $editor_settings ) ) .'">' : '';
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes( $attributes ) . $editor_height .'>'. $this->value .'</textarea>';
echo ( csf_wp_editor_api() ) ? '</div>' : '';
echo $this->field_after();
}
public function enqueue() {
if ( csf_wp_editor_api() && function_exists( 'wp_enqueue_editor' ) ) {
wp_enqueue_editor();
$this->setup_wp_editor_settings();
add_action( 'print_default_editor_scripts', array( $this, 'setup_wp_editor_media_buttons' ) );
}
}
// Setup wp editor media buttons
public function setup_wp_editor_media_buttons() {
if ( ! function_exists( 'media_buttons' ) ) {
return;
}
ob_start();
echo '<div class="wp-media-buttons">';
do_action( 'media_buttons' );
echo '</div>';
$media_buttons = ob_get_clean();
echo '<script type="text/javascript">';
echo 'var csf_media_buttons = '. json_encode( $media_buttons ) .';';
echo '</script>';
}
// Setup wp editor settings
public function setup_wp_editor_settings() {
if ( csf_wp_editor_api() && class_exists( '_WP_Editors') ) {
$defaults = apply_filters( 'csf_wp_editor', array(
'tinymce' => array(
'wp_skip_init' => true
),
) );
$setup = _WP_Editors::parse_settings( 'csf_wp_editor', $defaults );
_WP_Editors::editor_settings( 'csf_wp_editor', $setup );
}
}
}
}