Completed
Push — milestone/2_0/react-ui ( 35fe12...40eae7 )
by
unknown
02:52
created

Rich_Text_Field::to_json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 2
rs 9.6666
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( 'admin_print_footer_scripts', 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 id="carbon-fields-rich-text-media-buttons">
46
				<?php
47
				remove_action( 'media_buttons', 'media_buttons' );
48
				do_action( 'media_buttons' );
49
				add_action( 'media_buttons', 'media_buttons' );
50
				?>
51
			</div>
52
		</div>
53
		<?php
54
	}
55
56
	/**
57
	 * Returns an array that holds the field data, suitable for JSON representation.
58
	 *
59
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
60
	 * @return array
61
	 */
62
	public function to_json( $load ) {
63
		$field_data = parent::to_json( $load );
64
65
		$field_data = array_merge( $field_data, array(
66
			'rich_editing' => user_can_richedit(),
67
		) );
68
69
		return $field_data;
70
	}
71
}
72