| @@ -53,19 +53,11 @@ | ||
| 53 | 53 | if ( ! empty( $instance['title'] ) ) { |
| 54 | 54 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - // Deprecated since v2.5.8. Retained for backward compatibility. | |
| 58 | 57 | if ( isset( $args['widget_id'] ) ) { |
| 59 | - $instance['deprecated_uid'] = md5( $args['widget_id'] ); | |
| 58 | + $instance['uid'] = md5( $args['widget_id'] ); | |
| 60 | 59 | } |
| 61 | - | |
| 62 | - // If popup is enabled and type is video, force theme to popup | |
| 63 | - if ( isset( $instance['popup'] ) && ! empty( $instance['popup'] ) ) { | |
| 64 | - if ( isset( $instance['type'] ) && 'video' == $instance['type'] ) { | |
| 65 | - $instance['theme'] = 'popup'; | |
| 66 | - } | |
| 67 | - } | |
| 68 | 60 | |
| 69 | 61 | echo ayg_build_gallery( $instance ); |
| 70 | 62 | |
| 71 | 63 | echo $args['after_widget']; |
| @@ -79,30 +71,32 @@ | ||
| 79 | 71 | * @param array $old_instance The previous instance of values before the update. |
| 80 | 72 | */ |
| 81 | 73 | public function update( $new_instance, $old_instance ) { |
| 82 | 74 | $instance = array(); |
| 75 | + | |
| 83 | 76 | $instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
| 84 | 77 | |
| 85 | 78 | $fields = ayg_get_editor_fields(); |
| 86 | 79 | |
| 87 | - foreach ( $fields as $section ) { | |
| 88 | - foreach ( $section['fields'] as $field ) { | |
| 89 | - $name = $field['name']; | |
| 80 | + foreach ( $fields as $key => $value ) { | |
| 81 | + foreach ( $value['fields'] as $field ) { | |
| 82 | + $field_name = $field['name']; | |
| 83 | + $field_type = $field['type']; | |
| 90 | 84 | |
| 91 | - if ( 'checkbox' === $field['type'] ) { | |
| 92 | - $instance[ $name ] = ! empty( $new_instance[ $name ] ) ? 1 : 0; | |
| 93 | - } elseif ( ! isset( $new_instance[ $name ] ) ) { | |
| 94 | - continue; | |
| 95 | - } elseif ( 'select' === $field['type'] && isset( $field['options'] ) ) { | |
| 96 | - $raw = sanitize_text_field( $new_instance[ $name ] ); | |
| 97 | - $instance[ $name ] = array_key_exists( $raw, $field['options'] ) ? $raw : sanitize_text_field( $field['value'] ); | |
| 85 | + if ( 'number' == $field_type ) { | |
| 86 | + if ( ! empty( $new_instance[ $field_name ] ) ) { | |
| 87 | + $instance[ $field_name ] = false === strpos( $new_instance[ $field_name ], '.' ) ? (int) $new_instance[ $field_name ] : (float) $new_instance[ $field_name ]; | |
| 88 | + } else { | |
| 89 | + $instance[ $field_name ] = 0; | |
| 90 | + } | |
| 91 | + } elseif ( 'checkbox' == $field_type ) { | |
| 92 | + $instance[ $field_name ] = isset( $new_instance[ $field_name ] ) ? (int) $new_instance[ $field_name ] : 0; | |
| 98 | 93 | } else { |
| 99 | - $sanitize_callback = ! empty( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : 'sanitize_text_field'; | |
| 100 | - $instance[ $name ] = call_user_func( $sanitize_callback, $new_instance[ $name ] ); | |
| 94 | + $instance[ $field_name ] = ! empty( $new_instance[ $field_name ] ) ? sanitize_text_field( $new_instance[ $field_name ] ) : ''; | |
| 101 | 95 | } |
| 102 | 96 | } |
| 103 | 97 | } |
| 104 | - | |
| 98 | + | |
| 105 | 99 | return $instance; |
| 106 | 100 | } |
| 107 | 101 | |
| 108 | 102 | /** |