| 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 |
echo '<div class="lp-meta-box__wp-editor form-field ' . esc_attr( $this->id . '_field ' . $wrapper_class ) . '"> |
| 41 |
<label for="' . esc_attr( $this->id ) . '">' . wp_kses_post( $this->label ) . '</label>'; |
| 42 |
|
| 43 |
echo wp_editor( |
| 44 |
$value, |
| 45 |
$this->id, |
| 46 |
array( |
| 47 |
'textarea_rows' => 10, |
| 48 |
'editor_class' => 'lp-meta-box__wp-editor__textarea', |
| 49 |
) |
| 50 |
); |
| 51 |
|
| 52 |
if ( ! empty( $this->description ) ) { |
| 53 |
echo '<p class="description">'; |
| 54 |
echo '<span>' . wp_kses_post( $this->description ) . '</span>'; |
| 55 |
|
| 56 |
if ( ! empty( $desc_tip ) ) { |
| 57 |
learn_press_quick_tip( $desc_tip ); |
| 58 |
} |
| 59 |
echo '</p>'; |
| 60 |
} |
| 61 |
echo '</div>'; |
| 62 |
} |
| 63 |
|
| 64 |
public function save( $post_id ) { |
| 65 |
$meta_value = isset( $_POST[ $this->id ] ) ? wpautop( wp_unslash( $_POST[ $this->id ] ) ) : $this->default; |
| 66 |
|
| 67 |
update_post_meta( $post_id, $this->id, $meta_value ); |
| 68 |
} |
| 69 |
} |
| 70 |
|