|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Carbon_Fields\Field; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* WYSIWYG rich text area field class. |
|
7
|
|
|
*/ |
|
8
|
|
|
class Rich_Text_Field extends Textarea_Field { |
|
9
|
|
|
protected $lazyload = true; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Admin initialization actions. |
|
13
|
|
|
*/ |
|
14
|
|
|
public function admin_init() { |
|
15
|
|
|
add_action( 'admin_footer', array( get_class( $this ), 'editor_init' ) ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Display the editor. |
|
20
|
|
|
* |
|
21
|
|
|
* Instead of enqueueing all required scripts and stylesheets and setting up TinyMCE, |
|
22
|
|
|
* wp_editor() automatically enqueues and sets up everything. |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function editor_init() { |
|
25
|
|
|
?> |
|
26
|
|
|
<div style="display:none;"> |
|
27
|
|
|
<?php |
|
28
|
|
|
$settings = array( |
|
29
|
|
|
'tinymce' => array( |
|
30
|
|
|
'resize' => true, |
|
31
|
|
|
'wp_autoresize_on' => true, |
|
32
|
|
|
), |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
add_filter( 'user_can_richedit', '__return_true' ); |
|
36
|
|
|
wp_editor( '', 'carbon_settings', $settings ); |
|
37
|
|
|
remove_filter( 'user_can_richedit', '__return_true' ); |
|
38
|
|
|
?> |
|
39
|
|
|
</div> |
|
40
|
|
|
<?php |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Returns an array that holds the field data, suitable for JSON representation. |
|
45
|
|
|
* |
|
46
|
|
|
* @param bool $load Should the value be loaded from the database or use the value from the current instance. |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
public function to_json( $load ) { |
|
50
|
|
|
$field_data = parent::to_json( $load ); |
|
51
|
|
|
|
|
52
|
|
|
$rich_editing = ( get_user_option( 'rich_editing' ) === 'true' ); |
|
53
|
|
|
$field_data = array_merge( $field_data, array( |
|
54
|
|
|
'rich_editing' => $rich_editing, |
|
55
|
|
|
) ); |
|
56
|
|
|
|
|
57
|
|
|
return $field_data; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|