| @@ -14,10 +14,10 @@ | ||
| 14 | 14 | * |
| 15 | 15 | * @param string $id |
| 16 | 16 | * @param string $label |
| 17 | 17 | * @param string $description |
| 18 | - * @param mixed $default | |
| 19 | - * @param array $extra | |
| 18 | + * @param mixed $default | |
| 19 | + * @param array $extra | |
| 20 | 20 | */ |
| 21 | 21 | public function __construct( $label = '', $description = '', $default = '', $extra = array() ) { |
| 22 | 22 | parent::__construct( $label, $description, $default, $extra ); |
| 23 | 23 | } |
| @@ -35,15 +35,31 @@ | ||
| 35 | 35 | |
| 36 | 36 | $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select'; |
| 37 | 37 | $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 38 | 38 | $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 39 | + $wrapper_attr = $field['wrapper_attr'] ?? []; | |
| 39 | 40 | $field['default'] = ( ! $this->meta_value( $thepostid ) && isset( $field['default'] ) ) ? $field['default'] : $this->meta_value( $thepostid ); |
| 40 | 41 | $field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default']; |
| 41 | 42 | $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 42 | 43 | $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; |
| 43 | 44 | |
| 44 | - echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" ' . $this->condition . '><h4>' . wp_kses_post( $field['label'] ) . '</h4>'; | |
| 45 | + $dependency_check = $this->extra['dependency'] ?? []; | |
| 46 | + if ( ! empty( $dependency_check ) ) { | |
| 47 | + if ( $dependency_check['is_disable'] ) { | |
| 48 | + $field['wrapper_class'] .= ' lp-option-disabled'; | |
| 49 | + } | |
| 45 | 50 | |
| 51 | + $wrapper_attr[] = 'data-dependency=' . $dependency_check['name']; | |
| 52 | + } | |
| 53 | + | |
| 54 | + printf( | |
| 55 | + '<fieldset class="form-field %s" %s><label for="%s">%s</label>', | |
| 56 | + esc_attr( $this->id . '_field ' . $field['wrapper_class'] ), | |
| 57 | + implode( ' ', $wrapper_attr ), | |
| 58 | + esc_attr( $this->id ), | |
| 59 | + wp_kses_post( $this->label ) | |
| 60 | + ); | |
| 61 | + | |
| 46 | 62 | if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { |
| 47 | 63 | learn_press_quick_tip( $field['description'] ); |
| 48 | 64 | } |
| 49 | 65 | |
| @@ -69,9 +85,10 @@ | ||
| 69 | 85 | echo '</fieldset>'; |
| 70 | 86 | } |
| 71 | 87 | |
| 72 | 88 | public function save( $post_id ) { |
| 73 | - $value = ! empty( $_POST[ $this->id ] ) ? wp_unslash( $_POST[ $this->id ] ) : ''; | |
| 89 | + $value = LP_Request::get_param( $this->id, $this->default ?? '' ); | |
| 90 | + update_post_meta( $post_id, $this->id, $value ); | |
| 74 | 91 | |
| 75 | - update_post_meta( $post_id, $this->id, $value ); | |
| 92 | + return $value; | |
| 76 | 93 | } |
| 77 | 94 | } |