| 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_Radio_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 |
if ( empty( $this->id ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$field = $this->extra; |
| 31 |
$field['id'] = $this->id; |
| 32 |
$field['default'] = $this->default; |
| 33 |
$field['description'] = $this->description; |
| 34 |
$field['label'] = $this->label; |
| 35 |
|
| 36 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select'; |
| 37 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 38 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 39 |
$field['default'] = ( ! $this->meta_value( $thepostid ) && isset( $field['default'] ) ) ? $field['default'] : $this->meta_value( $thepostid ); |
| 40 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default']; |
| 41 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 42 |
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; |
| 43 |
|
| 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 |
|
| 46 |
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { |
| 47 |
learn_press_quick_tip( $field['description'] ); |
| 48 |
} |
| 49 |
|
| 50 |
echo '<ul class="lp-radios-field-meta-box">'; |
| 51 |
|
| 52 |
foreach ( $field['options'] as $key => $value ) { |
| 53 |
echo '<li><label><input |
| 54 |
name="' . esc_attr( $field['name'] ) . '" |
| 55 |
value="' . esc_attr( $key ) . '" |
| 56 |
type="radio" |
| 57 |
class="' . esc_attr( $field['class'] ) . '" |
| 58 |
style="' . esc_attr( $field['style'] ) . '" |
| 59 |
' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' |
| 60 |
/> ' . ( $value ) . '</label> |
| 61 |
</li>'; |
| 62 |
} |
| 63 |
echo '</ul>'; |
| 64 |
|
| 65 |
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { |
| 66 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 67 |
} |
| 68 |
|
| 69 |
echo '</fieldset>'; |
| 70 |
} |
| 71 |
|
| 72 |
public function save( $post_id ) { |
| 73 |
$value = ! empty( $_POST[ $this->id ] ) ? wp_unslash( $_POST[ $this->id ] ) : ''; |
| 74 |
|
| 75 |
update_post_meta( $post_id, $this->id, $value ); |
| 76 |
} |
| 77 |
} |
| 78 |
|