| @@ -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 | } |
| @@ -32,17 +32,17 @@ | ||
| 32 | 32 | $field['default'] = $this->default; |
| 33 | 33 | $field['description'] = $this->description; |
| 34 | 34 | $field['label'] = $this->label; |
| 35 | 35 | |
| 36 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short'; | |
| 37 | - $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; | |
| 38 | - $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; | |
| 36 | + $field['class'] = $field['class'] ?? 'short'; | |
| 37 | + $field['style'] = $field['style'] ?? ''; | |
| 38 | + $field['wrapper_class'] = $field['wrapper_class'] ?? ''; | |
| 39 | 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']; | |
| 40 | + $field['value'] = $field['value'] ?? $field['default']; | |
| 41 | + $field['name'] = $field['name'] ?? $field['id']; | |
| 42 | 42 | $field['mime_type'] = isset( $field['mime_type'] ) ? implode( ',', $field['mime_type'] ) : ''; |
| 43 | - $field['multil'] = ( isset( $field['multil'] ) && $field['multil'] ) ? true : false; | |
| 44 | - $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; | |
| 43 | + $field['multil'] = isset( $field['multil'] ) && $field['multil']; | |
| 44 | + $field['desc_tip'] = $field['desc_tip'] ?? false; | |
| 45 | 45 | |
| 46 | 46 | // Custom attribute handling |
| 47 | 47 | $custom_attributes = array(); |
| 48 | 48 | |
| @@ -60,10 +60,12 @@ | ||
| 60 | 60 | $custom_attributes |
| 61 | 61 | ) . '>'; |
| 62 | 62 | echo '<ul class="lp-meta-box__file_list">'; |
| 63 | 63 | |
| 64 | + $value = (array) $field['value']; | |
| 64 | 65 | if ( ! empty( $field['value'] ) ) { |
| 65 | - foreach ( (array) $field['value'] as $attachment_id ) { | |
| 66 | + $value = array_map( 'absint', $value ); | |
| 67 | + foreach ( $value as $attachment_id ) { | |
| 66 | 68 | $url = wp_get_attachment_url( $attachment_id ); |
| 67 | 69 | |
| 68 | 70 | if ( $url ) { |
| 69 | 71 | $check_file = wp_check_filetype( $url ); |
| @@ -68,15 +70,10 @@ | ||
| 68 | 70 | if ( $url ) { |
| 69 | 71 | $check_file = wp_check_filetype( $url ); |
| 70 | 72 | |
| 71 | 73 | echo '<li class="lp-meta-box__file_list-item image" data-attachment_id="' . $attachment_id . '">'; |
| 72 | - | |
| 73 | - if ( in_array( $check_file['ext'], array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif' ), true ) ) { | |
| 74 | - echo wp_get_attachment_image( $attachment_id, 'thumbnail' ); | |
| 75 | - } else { | |
| 76 | - echo '<img class="is_file" src="' . wp_mime_type_icon( $check_file['type'] ) . '" />'; | |
| 77 | - echo '<span>' . wp_basename( get_attached_file( $attachment_id ) ) . '</span>'; | |
| 78 | - } | |
| 74 | + echo sprintf( '<img class="is_file" src="%s" />', wp_mime_type_icon( $check_file['type'] ) ); | |
| 75 | + echo sprintf( '<span>%s</span>', wp_basename( get_attached_file( $attachment_id ) ) ); | |
| 79 | 76 | echo '<ul class="actions"><li><a href="#" class="delete"></a></li></ul>'; |
| 80 | 77 | echo '</li>'; |
| 81 | 78 | } |
| 82 | 79 | } |
| @@ -95,13 +92,22 @@ | ||
| 95 | 92 | echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 96 | 93 | } |
| 97 | 94 | echo '</div>'; |
| 98 | 95 | echo '</div>'; |
| 99 | - | |
| 100 | 96 | } |
| 101 | 97 | |
| 102 | 98 | public function save( $post_id ) { |
| 103 | - $value = ! empty( $_POST[ $this->id ] ) ? wp_unslash( array_filter( explode( ',', $_POST[ $this->id ] ) ) ) : ''; | |
| 99 | + $value = LP_Request::get_param( $this->id ); | |
| 100 | + if ( ! empty( $value ) ) { | |
| 101 | + $value = explode( ',', $value ); | |
| 102 | + if ( ! empty( $value ) ) { | |
| 103 | + $value = array_map( 'absint', $value ); | |
| 104 | + } | |
| 105 | + } else { | |
| 106 | + $value = $this->default ?? ''; | |
| 107 | + } | |
| 104 | 108 | |
| 105 | 109 | update_post_meta( $post_id, $this->id, $value ); |
| 110 | + | |
| 111 | + return $value; | |
| 106 | 112 | } |
| 107 | 113 | } |