| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* LP_Meta_Box_WP_Editor_Field |
| 5 |
* |
| 6 |
* @author Nhamdv |
| 7 |
* @version 1.0.0 |
| 8 |
* @since 4.1.3 |
| 9 |
*/ |
| 10 |
class LP_Meta_Box_WP_Editor_Field extends LP_Meta_Box_Field { |
| 11 |
|
| 12 |
/** |
| 13 |
* Constructor. |
| 14 |
* |
| 15 |
* @param string $id |
| 16 |
* @param string $label |
| 17 |
* @param string $description |
| 18 |
* @param mixed $default |
| 19 |
* @param array $extra |
| 20 |
*/ |
| 21 |
public function __construct( $label = '', $description = '', $default = '', $extra = array() ) { |
| 22 |
parent::__construct( $label, $description, $default, $extra ); |
| 23 |
} |
| 24 |
|
| 25 |
public function output( $thepostid ) { |
| 26 |
wp_enqueue_editor(); |
| 27 |
|
| 28 |
if ( empty( $this->id ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$extra = $this->extra; |
| 33 |
$wrapper_class = ! empty( $extra['wrapper_class'] ) ? esc_attr( $extra['wrapper_class'] ) : ''; |
| 34 |
|
| 35 |
$meta = $this->meta_value( $thepostid ); |
| 36 |
$value = ! $meta && ! empty( $this->default ) ? $this->default : $meta; |
| 37 |
$value = $extra['value'] ?? $value; |
| 38 |
$desc_tip = $extra['desc_tip'] ?? ''; |
| 39 |
|
| 40 |
printf( |
| 41 |
'<div class="lp-meta-box__wp-editor form-field %s"><label for="%s">%s</label>', |
| 42 |
esc_attr( $this->id . '_field ' . $wrapper_class ), |
| 43 |
esc_attr( $this->id ), |
| 44 |
wp_kses_post( $this->label ) |
| 45 |
); |
| 46 |
|
| 47 |
wp_editor( |
| 48 |
$value, |
| 49 |
sanitize_key( $this->id ), |
| 50 |
array( |
| 51 |
'textarea_rows' => 10, |
| 52 |
'editor_class' => 'lp-meta-box__wp-editor__textarea', |
| 53 |
'textarea_name' => $this->id, |
| 54 |
) |
| 55 |
); |
| 56 |
|
| 57 |
if ( ! empty( $this->description ) ) { |
| 58 |
echo '<p class="description">'; |
| 59 |
echo '<span>' . wp_kses_post( $this->description ) . '</span>'; |
| 60 |
|
| 61 |
if ( ! empty( $desc_tip ) ) { |
| 62 |
learn_press_quick_tip( $desc_tip ); |
| 63 |
} |
| 64 |
echo '</p>'; |
| 65 |
} |
| 66 |
echo '</div>'; |
| 67 |
} |
| 68 |
|
| 69 |
public function save( $post_id ) { |
| 70 |
$meta_value = LP_Request::get_param( $this->id, $this->default ?? '', 'html' ); |
| 71 |
|
| 72 |
update_post_meta( $post_id, $this->id, $meta_value ); |
| 73 |
|
| 74 |
return $meta_value; |
| 75 |
} |
| 76 |
} |
| 77 |
|