diff --git a/includes/classes/class-add-listing.php b/includes/classes/class-add-listing.php index 2c392c2f83..066af00946 100644 --- a/includes/classes/class-add-listing.php +++ b/includes/classes/class-add-listing.php @@ -542,10 +542,6 @@ public static function filter_empty_meta_data( $meta_data ) { return false; } - if ( is_numeric( $value ) && $value == 0 ) { - return false; - } - return true; }, ARRAY_FILTER_USE_BOTH ); diff --git a/includes/classes/class-submission-controller.php b/includes/classes/class-submission-controller.php index e06ffff2ee..d652fe05f5 100644 --- a/includes/classes/class-submission-controller.php +++ b/includes/classes/class-submission-controller.php @@ -510,10 +510,6 @@ protected static function filter_empty_meta_data( $meta_data ) { return false; } - if ( is_numeric( $value ) && $value == 0 ) { - return false; - } - return true; }, ARRAY_FILTER_USE_BOTH ); diff --git a/includes/fields/class-directorist-number-field.php b/includes/fields/class-directorist-number-field.php index 85919772cf..8fabdb9d2f 100644 --- a/includes/fields/class-directorist-number-field.php +++ b/includes/fields/class-directorist-number-field.php @@ -34,6 +34,10 @@ public function validate( $posted_data ) { } public function sanitize( $posted_data ) { + if ( $this->is_value_empty( $posted_data ) ) { + return ''; + } + return round( (float) $this->get_value( $posted_data ), 2 ); } } diff --git a/includes/helper-functions.php b/includes/helper-functions.php index 57b3da23c1..bc0cb6587e 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -4628,10 +4628,6 @@ function directorist_filter_listing_empty_metadata( $meta_data ) { return false; } - if ( is_numeric( $value ) && $value == 0 ) { - return false; - } - return true; }, ARRAY_FILTER_USE_BOTH ); diff --git a/includes/model/Listings.php b/includes/model/Listings.php index 17a3ac4636..5a925fb6e5 100644 --- a/includes/model/Listings.php +++ b/includes/model/Listings.php @@ -997,8 +997,12 @@ public function parse_search_query_args() { if ( isset( $_REQUEST['custom_field'] ) ) { // Multi-dimensional array, sanitized inside - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $custom_fields = array_filter( wp_unslash( $_REQUEST['custom_field'] ) ); + $custom_fields = array_filter( + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + wp_unslash( $_REQUEST['custom_field'] ), static function( $value ) { + return is_array( $value ) ? ! empty( $value ) : null !== $value && '' !== $value; + } + ); foreach ( $custom_fields as $key => $values ) { $key = sanitize_text_field( $key ); diff --git a/includes/model/SearchForm.php b/includes/model/SearchForm.php index ce6d259af7..4fa8efa3e0 100644 --- a/includes/model/SearchForm.php +++ b/includes/model/SearchForm.php @@ -732,7 +732,7 @@ public function field_template( $field_data ) { $field_data['lazy_load'] = false; if ( $this->is_custom_field( $field_data ) ) { - if ( ! empty( $_REQUEST['custom_field'][$key] ) ) { + if ( isset( $_REQUEST['custom_field'][$key] ) ) { $value = is_array( $_REQUEST['custom_field'][$key] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['custom_field'][$key] ) ) : sanitize_text_field( wp_unslash( $_REQUEST['custom_field'][$key] ) ); } else { $value = '';