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
<?php
class Papi_Property_Editor extends Papi_Property {
protected function add_mce_buttons() {
for ( $i = 0; $i < 4; $i++ ) {
$num = $i === 0 ? '' : '_' . ( $i + 1 );
add_filter( 'mce_buttons' . $num, [$this, 'mce_buttons'] );
}
}
public function format_value( $value, $slug, $post_id ) {
return is_admin() ? $value : apply_filters( 'the_content', $value );
}
public function get_default_settings() {
return [
'mce_buttons' => [],
'mce_buttons_2' => [],
'mce_buttons_3' => [],
'mce_buttons_4' => [],
'media_buttons' => true,
'teeny' => false,
'drag_drop_upload' => true
];
}
public function mce_buttons( array $buttons = [] ) {
if ( $new = papi_to_array( $this->get_setting( current_filter(), [] ) ) ) {
return $new;
}
return $buttons;
}
public function html() {
$value = $this->get_value();
$value = html_entity_decode( $value );
$id = str_replace(
'[',
'',
str_replace( ']', '', $this->html_name() )
) . '-' . uniqid();
$this->add_mce_buttons();
wp_editor( $value, $id, [
'textarea_name' => $this->html_name(),
'media_buttons' => $this->get_setting( 'media_buttons', true ),
'teeny' => $this->get_setting( 'teeny', false ),
'drag_drop_upload' => $this->get_setting( 'drag_drop_upload', true ),
] );
$this->reove_mce_buttons();
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
add_filter( 'mce_external_plugins', '__return_empty_array' );
}
}
protected function reove_mce_buttons() {
for ( $i = 0; $i < 4; $i++ ) {
$num = $i === 0 ? '' : '_' . ( $i + 1 );
remove_filter( 'mce_buttons' . $num, [$this, 'mce_buttons'] );
}
}
}