| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* LP_Meta_Box_Duration_Attribute |
| 5 |
* |
| 6 |
* @author tungnx |
| 7 |
* @version 1.0.0 |
| 8 |
* @since 4.0.0 |
| 9 |
*/ |
| 10 |
class LP_Meta_Box_Extra_Faq_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 |
$faqs = $this->meta_value( $thepostid ); |
| 27 |
?> |
| 28 |
|
| 29 |
<div class="form-field lp_course_faq_meta_box"> |
| 30 |
<label for="_lp_key_features"><?php echo wp_kses_post( $this->label ); ?></label> |
| 31 |
<div class="lp_course_faq_meta_box__content"> |
| 32 |
<input type="hidden" name="<?php echo esc_attr( $this->id ) ?>" value=""> |
| 33 |
<div class="lp_course_faq_meta_box__fields"> |
| 34 |
<?php if ( is_array( $faqs ) && ! empty( $faqs[0][0] ) ) : ?> |
| 35 |
<?php foreach ( $faqs as $key => $faq ) : ?> |
| 36 |
<div class="lp_course_faq_meta_box__field"> |
| 37 |
<label> |
| 38 |
<span><?php esc_attr_e( 'Title', 'learnpress' ); ?></span> |
| 39 |
<input type="text" name="_lp_faqs_question[]" value="<?php echo esc_attr( $faq[0] ); ?>"> |
| 40 |
</label> |
| 41 |
<label> |
| 42 |
<span><?php esc_attr_e( 'Content', 'learnpress' ); ?></span> |
| 43 |
<textarea name="_lp_faqs_answer[]"><?php echo wp_kses_post( $faq[1] ); ?></textarea> |
| 44 |
</label> |
| 45 |
<a href="#" class="delete"></a> |
| 46 |
<span class="sort"></span> |
| 47 |
</div> |
| 48 |
<?php endforeach; ?> |
| 49 |
<?php endif; ?> |
| 50 |
</div> |
| 51 |
|
| 52 |
<a href="#" class="button button-primary lp_course_faq_meta_box__add" |
| 53 |
data-add=" |
| 54 |
<?php |
| 55 |
echo esc_attr( |
| 56 |
'<div class="lp_course_faq_meta_box__field"> |
| 57 |
<label> |
| 58 |
<span>' . esc_attr__( 'Title', 'learnpress' ) . '</span> |
| 59 |
<input type="text" name="_lp_faqs_question[]" value=""> |
| 60 |
</label> |
| 61 |
<label> |
| 62 |
<span>' . esc_attr__( 'Content', 'learnpress' ) . '</span> |
| 63 |
<textarea name="_lp_faqs_answer[]"></textarea> |
| 64 |
</label> |
| 65 |
<a href="#" class="delete"></a> |
| 66 |
<span class="sort"></span> |
| 67 |
</div>' |
| 68 |
); |
| 69 |
?> |
| 70 |
"><?php esc_html_e( '+ Add more', 'learnpress' ); ?> |
| 71 |
</a> |
| 72 |
</div> |
| 73 |
</div> |
| 74 |
|
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
public function save( $post_id ) { |
| 79 |
$faqs_question = LP_Request::get_param( '_lp_faqs_question', [], 'html' ); |
| 80 |
$faqs_answer = LP_Request::get_param( '_lp_faqs_answer', [], 'html' ); |
| 81 |
|
| 82 |
$faqs = array(); |
| 83 |
if ( ! empty( $faqs_question ) ) { |
| 84 |
$faqs_question_size = count( $faqs_question ); |
| 85 |
|
| 86 |
for ( $i = 0; $i < $faqs_question_size; $i ++ ) { |
| 87 |
if ( ! empty( $faqs_question[ $i ] ) ) { |
| 88 |
$faqs[] = array( $faqs_question[ $i ], $faqs_answer[ $i ] ); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
update_post_meta( $post_id, $this->id, $faqs ); |
| 94 |
} |
| 95 |
} |
| 96 |
|