PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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
← All changes | inc/admin/views/meta-boxes/fields/text.php +44 -18 4.2.04.4.8 View file →
@@ -11,13 +11,12 @@
11 11
12 12 /**
13 13 * Constructor.
14 14 *
15 - * @param string $id
16 15 * @param string $label
17 16 * @param string $description
18 - * @param mixed $default
19 - * @param array $extra
17 + * @param mixed $default
18 + * @param array $extra
20 19 */
21 20 public function __construct( $label = '', $description = '', $default = '', $extra = array() ) {
22 21 parent::__construct( $label, $description, $default, $extra );
23 22 }
@@ -31,8 +30,9 @@
31 30 $placeholder = $extra['placeholder'] ?? '';
32 31 $class = ! empty( $extra['class'] ) ? 'class="' . esc_attr( $extra['class'] ) . '"' : '';
33 32 $style = ! empty( $extra['style'] ) ? 'style="' . esc_attr( $extra['style'] ) . '"' : '';
34 33 $wrapper_class = ! empty( $extra['wrapper_class'] ) ? esc_attr( $extra['wrapper_class'] ) : '';
34 + $wrapper_attr = $extra['wrapper_attr'] ?? [];
35 35
36 36 $meta_exists = LP_Database::getInstance()->check_key_postmeta_exists( $thepostid, $this->id );
37 37 $meta = get_post_meta( $thepostid, $this->id, true );
38 38 $value = $meta_exists ? $meta : ( $this->default ?? '' );
@@ -47,16 +47,37 @@
47 47 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
48 48 }
49 49 }
50 50
51 - echo '<div class="form-field ' . esc_attr( $this->id . '_field ' . $wrapper_class ) . '">
52 - <label for="' . esc_attr( $this->id ) . '">' . wp_kses_post( $this->label ) . '</label>';
51 + $dependency_check = $extra['dependency'] ?? [];
52 + if ( ! empty( $dependency_check ) ) {
53 + if ( $dependency_check['is_disable'] ) {
54 + $wrapper_class .= ' lp-option-disabled';
55 + }
53 56
54 - echo '<input type="' . esc_attr( $type_input ) . '" ' . $class . ' ' . $style . ' name="' . $this->id . '" id="' . $this->id . '" value="' . $value . '" placeholder="' . esc_attr( $placeholder ) . '" ' . implode(
55 - ' ',
56 - $custom_attributes
57 - ) . ' /> ';
57 + $wrapper_attr[] = 'data-dependency=' . $dependency_check['name'];
58 + }
58 59
60 + printf(
61 + '<div class="form-field %s" %s><label for="%s">%s</label>',
62 + esc_attr( $this->id . '_field ' . $wrapper_class ),
63 + esc_attr( implode( ' ', $wrapper_attr ) ),
64 + esc_attr( $this->id ),
65 + wp_kses_post( $this->label )
66 + );
67 +
68 + printf(
69 + '<input type="%s" %s %s name="%s" id="%s" value="%s" placeholder="%s" %s />',
70 + esc_attr( $type_input ),
71 + $class,
72 + $style,
73 + $this->id,
74 + $this->id,
75 + $value,
76 + esc_attr( $placeholder ),
77 + implode( ' ', $custom_attributes )
78 + );
79 +
59 80 if ( ! empty( $this->description ) ) {
60 81 echo '<p class="description">';
61 82 echo '<span>' . wp_kses_post( $this->description ) . '</span>';
62 83
@@ -69,21 +90,26 @@
69 90 }
70 91
71 92 public function save( $post_id ) {
72 93 $type_input = $this->extra['type_input'] ?? 'text';
73 - $meta_value = isset( $_POST[ $this->id ] ) ? wp_unslash( $_POST[ $this->id ] ) : $this->default;
94 + $meta_value = LP_Request::get_param( $this->id, $this->default ?? '', 'text', 'post' );
74 95
75 96 if ( $meta_value !== '' && $type_input === 'number' ) {
76 - $step = isset( $this->extra['custom_attributes']['step'] ) ? $this->extra['custom_attributes']['step'] : '';
77 -
78 - if ( floatval( $step ) !== 1 ) {
79 - $meta_value = floatval( $meta_value );
80 - } else {
81 - $meta_value = absint( $meta_value );
97 + $meta_value = (float) $meta_value;
98 + if ( isset( $this->extra['custom_attributes']['max'] ) ) {
99 + $value_max = (float) $this->extra['custom_attributes']['max'];
100 + if ( $meta_value > $value_max ) {
101 + $meta_value = $value_max;
102 + }
103 + } elseif ( isset( $this->extra['custom_attributes']['min'] ) ) {
104 + $value_min = (float) $this->extra['custom_attributes']['min'];
105 + if ( $meta_value < $value_min ) {
106 + $meta_value = $value_min;
107 + }
82 108 }
83 - } else {
84 - $meta_value = LP_Helper::sanitize_params_submitted( $meta_value );
85 109 }
86 110
87 111 update_post_meta( $post_id, $this->id, $meta_value );
112 +
113 + return $meta_value;
88 114 }
89 115 }