Completed
Push — milestone/2_0/react-ui ( 665a98...35fe12 )
by
unknown
02:44
created

Rich_Text_Field::admin_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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>
46
		<?php
47
	}
48
49
	/**
50
	 * Returns an array that holds the field data, suitable for JSON representation.
51
	 *
52
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
53
	 * @return array
54
	 */
55
	public function to_json( $load ) {
56
		$field_data = parent::to_json( $load );
57
58
		$field_data = array_merge( $field_data, array(
59
			'rich_editing' => user_can_richedit(),
60
		) );
61
62
		return $field_data;
63
	}
64
}
65