|
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
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Defines if the rich text field should be loaded only when scrolled into view |
|
12
|
|
|
* |
|
13
|
|
|
* @var boolean |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $lazyload = true; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritDoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public static function field_type_activated() { |
|
21
|
|
|
add_action( 'in_admin_header', array( get_class(), 'editor_init' ) ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Display the editor. |
|
26
|
|
|
* |
|
27
|
|
|
* Instead of enqueueing all required scripts and stylesheets and setting up TinyMCE, |
|
28
|
|
|
* wp_editor() automatically enqueues and sets up everything. |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function editor_init() { |
|
31
|
|
|
?> |
|
32
|
|
|
<div style="display:none;"> |
|
33
|
|
|
<?php |
|
34
|
|
|
$settings = array( |
|
35
|
|
|
'tinymce' => array( |
|
36
|
|
|
'resize' => true, |
|
37
|
|
|
'wp_autoresize_on' => true, |
|
38
|
|
|
), |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
add_filter( 'user_can_richedit', '__return_true' ); |
|
42
|
|
|
wp_editor( '', 'carbon_settings', $settings ); |
|
43
|
|
|
remove_filter( 'user_can_richedit', '__return_true' ); |
|
44
|
|
|
?> |
|
45
|
|
|
</div> |
|
46
|
|
|
<?php |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Display Upload Image Button |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function upload_image_button_html() { |
|
54
|
|
|
$upload_image_button = '<a href="#" class="button insert-media add_media" data-editor="<%- id %>" title="Add Media"> |
|
55
|
|
|
<span class="wp-media-buttons-icon"></span> Add Media |
|
56
|
|
|
</a>'; |
|
57
|
|
|
echo apply_filters( 'crb_upload_image_button_html', $upload_image_button, $this->base_name ); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns an array that holds the field data, suitable for JSON representation. |
|
62
|
|
|
* |
|
63
|
|
|
* @param bool $load Should the value be loaded from the database or use the value from the current instance. |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function to_json( $load ) { |
|
67
|
|
|
$field_data = parent::to_json( $load ); |
|
68
|
|
|
|
|
69
|
|
|
ob_start(); |
|
70
|
|
|
remove_action( 'media_buttons', 'media_buttons' ); |
|
71
|
|
|
|
|
72
|
|
|
$this->upload_image_button_html(); |
|
73
|
|
|
|
|
74
|
|
|
do_action( 'media_buttons' ); |
|
75
|
|
|
|
|
76
|
|
|
add_action( 'media_buttons', 'media_buttons' ); |
|
77
|
|
|
|
|
78
|
|
|
$media_buttons = apply_filters( 'crb_media_buttons_html', ob_get_clean(), $this->base_name ); |
|
79
|
|
|
|
|
80
|
|
|
$field_data = array_merge( $field_data, array( |
|
81
|
|
|
'rich_editing' => user_can_richedit(), |
|
82
|
|
|
'media_buttons' => $media_buttons, |
|
83
|
|
|
) ); |
|
84
|
|
|
|
|
85
|
|
|
return $field_data; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|