PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.3
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / views / meta-boxes / fields / select.php

select.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9.3, at inc/admin/views/meta-boxes/fields/select.php

138 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * LP_Meta_Box_Duration_Attribute
5 *
6 * @author Nhamdv
7 * @version 1.0.0
8 * @since 4.0.0
9 */
10 class LP_Meta_Box_Select_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 meta_value( $thepostid ) {
26 $multil_meta = isset( $this->extra['multil_meta'] ) ? $this->extra['multil_meta'] : false;
27 return $multil_meta ? get_post_meta( $thepostid, $this->id, false ) : get_post_meta( $thepostid, $this->id, true );
28 }
29
30 public function output( $thepostid ) {
31 if ( empty( $this->id ) ) {
32 return;
33 }
34
35 $field = $this->extra;
36 $field['id'] = $this->id;
37 $field['default'] = $this->default;
38 $field['description'] = $this->description;
39 $field['label'] = $this->label;
40
41 $field['multil_meta'] = isset( $field['multil_meta'] ) ? $field['multil_meta'] : false;
42 $meta = $this->meta_value( $thepostid );
43
44 $default = ( ! $meta && isset( $field['default'] ) ) ? $field['default'] : $meta;
45
46 $field = wp_parse_args(
47 $field,
48 array(
49 'class' => 'select',
50 'style' => '',
51 'wrapper_class' => '', // Use "lp-select-2" for select2.
52 'value' => isset( $field['value'] ) ? $field['value'] : $default,
53 'name' => $field['id'],
54 'desc_tip' => false,
55 'multiple' => false,
56 'custom_attributes' => array(),
57 )
58 );
59
60 $label_attributes = array(
61 'for' => $field['id'],
62 );
63
64 $field_attributes = (array) $field['custom_attributes'];
65 $field_attributes['style'] = $field['style'];
66 $field_attributes['id'] = $field['id'];
67 $field_attributes['name'] = $field['multiple'] ? $field['name'] . '[]' : $field['name'];
68 $field_attributes['class'] = $field['class'];
69
70 if ( $field['multiple'] ) {
71 $field['wrapper_class'] = 'lp-select-2';
72 $field_attributes['multiple'] = true;
73 }
74
75 $tooltip = ! empty( $field['description'] ) && false !== $field['desc_tip'] ? $field['description'] : '';
76 $description = ! empty( $field['description'] ) && false === $field['desc_tip'] ? $field['description'] : '';
77 ?>
78
79 <p class="form-field <?php echo esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ); ?>" <?php echo $this->condition ? $this->condition : ''; ?>>
80 <label for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo wp_kses_post( $field['label'] ); ?></label>
81 <select <?php echo lp_implode_html_attributes( $field_attributes ); ?>>
82 <?php
83 foreach ( $field['options'] as $key => $value ) {
84 echo '<option value="' . esc_attr( $key ) . '"' . ( is_array( $field['value'] ) ? selected( in_array( (string) $key, $field['value'], true ), true ) : selected( $key, $field['value'], false ) ) . '>' . esc_html( $value ) . '</option>';
85 }
86 ?>
87 </select>
88 <?php
89 if ( ! empty( $field['description'] ) ) {
90 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
91
92 if ( ! empty( $field['desc_tip'] ) ) {
93 learn_press_quick_tip( $field['desc_tip'] );
94 }
95 }
96 ?>
97 </p>
98 <?php
99 }
100
101 public function save( $post_id ) {
102 $multil_meta = isset( $this->extra['multil_meta'] ) ? $this->extra['multil_meta'] : false;
103
104 if ( ! isset( $_POST[ $this->id ] ) ) {
105 return;
106 }
107
108 if ( $multil_meta ) {
109 $get_values = get_post_meta( $post_id, $this->id, false ) ?? array();
110 $new_values = isset( $_POST[ $this->id ] ) ? (array) wp_unslash( $_POST[ $this->id ] ) : array();
111
112 $array_get_values = ! empty( $get_values ) ? array_values( $get_values ) : array();
113 $array_new_values = ! empty( $new_values ) ? array_values( $new_values ) : array();
114
115 $del_val = array_diff( $array_get_values, $array_new_values );
116 $new_val = array_diff( $array_new_values, $array_get_values );
117
118 foreach ( $del_val as $level_id ) {
119 delete_post_meta( $post_id, $this->id, $level_id );
120 }
121
122 foreach ( $new_val as $level_id ) {
123 add_post_meta( $post_id, $this->id, $level_id, false );
124 }
125 } else {
126 $value = ! empty( $_POST[ $this->id ] ) ? sanitize_text_field( wp_unslash( $_POST[ $this->id ] ) ) : '';
127
128 $multilple = ! empty( $this->extra['multiple'] ) ? true : false;
129
130 if ( $multilple ) {
131 $value = ! empty( $_POST[ $this->id ] ) ? LP_Helper::sanitize_params_submitted( $_POST[ $this->id ] ) : array();
132 }
133
134 update_post_meta( $post_id, $this->id, $value );
135 }
136 }
137 }
138