Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/business-directory-plugin/business-directory-plugin.php
+++ b/business-directory-plugin/business-directory-plugin.php
@@ -3,7 +3,7 @@
* Plugin Name: Business Directory Plugin
* Plugin URI: https://businessdirectoryplugin.com
* Description: Provides the ability to maintain a free or paid business directory on your WordPress powered site.
- * Version: 6.4.25
+ * Version: 6.4.26
* Author: Business Directory Team
* Author URI: https://businessdirectoryplugin.com
* Text Domain: business-directory-plugin
--- a/business-directory-plugin/includes/class-query-integration.php
+++ b/business-directory-plugin/includes/class-query-integration.php
@@ -222,7 +222,7 @@
$field = explode( ' ', $orderby )[0];
- return $this->get_space_replace( $field, $query->get( 'order', 'ASC' ) );
+ return $this->get_space_replace_orderby( $field, $query->get( 'order', 'ASC' ), $this->is_numeric_orderby( $query, $field ) );
}
/**
@@ -513,8 +513,9 @@
return $orderby;
}
- $sname = str_replace( 'field-', '', $sort->option );
- $qn = '';
+ $sname = str_replace( 'field-', '', $sort->option );
+ $qn = '';
+ $numeric_sort = false;
switch ( $sname ) {
case 'user_login':
@@ -544,15 +545,14 @@
break;
}
- if ( $qn !== $orderby && $field->is_numeric() ) {
- $qn .= ' +0';
- }
+ $numeric_sort = $field->is_numeric();
break;
}
if ( $qn && $qn !== $orderby ) {
- $orderby = $orderby . ( $orderby ? ', ' : '' ) . $this->get_space_replace( $qn, $sort->order );
+ $order_by_field = $this->get_space_replace_orderby( $qn, $sort->order, $numeric_sort );
+ $orderby = $orderby . ( $orderby ? ', ' : '' ) . $order_by_field;
}
return $orderby;
@@ -569,7 +569,46 @@
* @return string
*/
private function get_space_replace( $field, $order ) {
- return "REPLACE( {$field}, ' ', '' ) " . ' ' . $order;
+ return $this->get_space_replace_orderby( $field, $order );
+ }
+
+ /**
+ * Return the space removal orderby string for the given field and order.
+ *
+ * @since 6.4.26
+ *
+ * @param string $field The field to remove spaces from.
+ * @param string $order The order to apply.
+ * @param bool $numeric_sort Whether to cast the value for numeric sorting.
+ *
+ * @return string
+ */
+ private function get_space_replace_orderby( $field, $order, $numeric_sort = false ) {
+ $space_replace = "REPLACE( {$field}, ' ', '' )";
+
+ if ( $numeric_sort ) {
+ return "( {$space_replace} + 0 ) " . $order;
+ }
+
+ return $space_replace . ' ' . $order;
+ }
+
+ /**
+ * Determine whether a default orderby expression should sort numerically.
+ *
+ * @since 6.4.26
+ *
+ * @param WP_Query $query The current query object.
+ * @param string $field The SQL field or expression being ordered.
+ *
+ * @return bool
+ */
+ private function is_numeric_orderby( $query, $field ) {
+ $orderby = (string) $query->get( 'orderby' );
+ $is_rating = false !== stripos( $orderby, 'rating' ) || false !== stripos( $field, 'rating' );
+ $is_numeric = in_array( $orderby, array( 'meta_value_num' ), true ) || $is_rating || false !== strpos( $field, '+0' ) || false !== stripos( $field, 'cast(' );
+
+ return (bool) apply_filters( 'wpbdp_is_numeric_orderby', $is_numeric, $orderby, $field, $query );
}
/**
--- a/business-directory-plugin/includes/class-wpbdp.php
+++ b/business-directory-plugin/includes/class-wpbdp.php
@@ -57,7 +57,7 @@
}
private function setup_constants() {
- define( 'WPBDP_VERSION', '6.4.25' );
+ define( 'WPBDP_VERSION', '6.4.26' );
define( 'WPBDP_PATH', wp_normalize_path( plugin_dir_path( WPBDP_PLUGIN_FILE ) ) );
define( 'WPBDP_INC', trailingslashit( WPBDP_PATH . 'includes' ) );
--- a/business-directory-plugin/includes/fields/class-fieldtypes-checkbox.php
+++ b/business-directory-plugin/includes/fields/class-fieldtypes-checkbox.php
@@ -283,7 +283,7 @@
'_wpbdp[fields][' . $field->get_id() . ']'
);
- $pattern = '(' . implode( '|', $query ) . '){1}([tab]{0,1})';
+ $pattern = '(^|t)(' . implode( '|', $query ) . ')(t|$)';
$search_res['where'] = $wpdb->prepare( "{$alias}.meta_value REGEXP %s", $pattern );
return $search_res;
--- a/business-directory-plugin/includes/fields/class-fieldtypes-image.php
+++ b/business-directory-plugin/includes/fields/class-fieldtypes-image.php
@@ -84,17 +84,20 @@
$value = is_array( $value ) ? $value : array( $value );
+ $image_id = ! empty( $value[0] ) ? absint( $value[0] ) : 0;
+ $caption = $value[1] ?? '';
+
$html = '';
$html .= sprintf(
'<input type="hidden" name="listingfields[%d][0]" value="%s" />',
$field->get_id(),
- $value[0]
+ esc_attr( $image_id )
);
- $html .= '<div class="preview wpbdp-image"' . ( empty( $value[0] ) ? ' style="display: none;"' : '' ) . '>';
- if ( ! empty( $value[0] ) ) {
+ $html .= '<div class="preview wpbdp-image"' . ( empty( $image_id ) ? ' style="display: none;"' : '' ) . '>';
+ if ( ! empty( $image_id ) ) {
$html .= '<div class="wpbdp-image-img">';
- $html .= wp_get_attachment_image( $value[0], 'wpbdp-thumb', false );
+ $html .= wp_get_attachment_image( $image_id, 'wpbdp-thumb', false );
$html .= '</div>';
}
@@ -103,7 +106,7 @@
$html .= sprintf(
'<label for="wpbdp-field-%1$d-caption" style="display:none;">Image Caption:</label><input id="wpbdp-field-%1$d-caption" type="text" name="listingfields[%1$d][1]" value="%2$s" placeholder="Image caption or description">',
$field->get_id(),
- ! empty( $value[1] ) ? $value[1] : ''
+ esc_attr( $caption )
);
$html .= sprintf(
@@ -175,7 +178,7 @@
admin_url( 'admin-ajax.php' )
);
- $html .= '<div class="wpbdp-upload-widget"' . ( ! empty( $value[0] ) ? ' style="display: none;"' : '' ) . '>';
+ $html .= '<div class="wpbdp-upload-widget"' . ( ! empty( $image_id ) ? ' style="display: none;"' : '' ) . '>';
$html .= sprintf(
'<iframe class="wpbdp-upload-iframe" name="upload-iframe-%d" id="wpbdp-upload-iframe-%d" src="%s" scrolling="no" seamless="seamless" border="0" frameborder="0"></iframe>',
esc_attr( $field->get_id() ),
@@ -244,7 +247,7 @@
$html .= '<a href="' . esc_url( $img[0] ) . '" target="_blank" rel="noopener" ' . ( wpbdp_get_option( 'use-thickbox' ) ? 'class="thickbox" data-lightbox="wpbdpgal" rel="wpbdpgal"' : '' ) . '>';
$html .= wp_get_attachment_image( $img_id, $img_size, false, array( 'alt' => $caption ? $caption : esc_attr( $field->get_label() ) ) );
$html .= '</a>';
- $html .= $field->data( 'display_caption' ) ? '<br />' . $caption : '';
+ $html .= $field->data( 'display_caption' ) ? '<br />' . esc_html( $caption ) : '';
$html .= '</div>';
return $html;
@@ -476,9 +479,17 @@
return array( '', '' );
}
- $image = trim( sanitize_text_field( is_array( $input ) ? $input[0] : $input ) );
- $caption = trim( is_array( $input ) ? sanitize_text_field( $input[1] ) : '' );
+ if ( is_array( $input ) ) {
+ $image_raw = $input[0] ?? '';
+ $caption_raw = $input[1] ?? '';
+ } else {
+ $image_raw = $input;
+ $caption_raw = '';
+ }
+
+ $image = absint( is_scalar( $image_raw ) ? $image_raw : '' );
+ $caption = trim( sanitize_text_field( is_scalar( $caption_raw ) ? $caption_raw : '' ) );
- return array( $image, $caption );
+ return array( $image ? (string) $image : '', $caption );
}
}
--- a/business-directory-plugin/includes/fields/class-fieldtypes-select.php
+++ b/business-directory-plugin/includes/fields/class-fieldtypes-select.php
@@ -466,7 +466,7 @@
'_wpbdp[fields][' . $field->get_id() . ']'
);
- $pattern = '(' . implode( '|', $query ) . '){1}([tab]{0,1})';
+ $pattern = '(^|t)(' . implode( '|', $query ) . ')(t|$)';
$search_res['where'] = $wpdb->prepare( "{$alias}.meta_value REGEXP %s", $pattern );
return $search_res;
--- a/business-directory-plugin/includes/fields/class-form-field.php
+++ b/business-directory-plugin/includes/fields/class-form-field.php
@@ -498,6 +498,11 @@
public function validate( $value, &$errors = null ) {
$errors = ! is_array( $errors ) ? array() : $errors;
+ // Private fields are hidden from non-admins, so they must not block submit.
+ if ( $this->has_display_flag( 'private' ) && ! wpbdp_user_is_admin() ) {
+ return true;
+ }
+
$validation_api = WPBDP_FieldValidation::instance();
if ( ! $this->is_required() && $this->type->is_empty_value( $value ) ) {
@@ -718,6 +723,11 @@
return $res;
}
+ // Admin-only fields are not visible to non-admins, so they cannot be required.
+ if ( $this->has_display_flag( 'private' ) && $this->is_required() ) {
+ $this->set_validators( array_values( array_diff( $this->validators, array( 'required' ) ) ) );
+ }
+
$data = array();
$data['label'] = $this->label;
@@ -942,16 +952,21 @@
}
if ( is_string( $term_ ) ) {
- $tt_ids = $wpdb->get_col(
- $wpdb->prepare(
- "SELECT DISTINCT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} tt JOIN {$wpdb->terms} t ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.name LIKE '%%%s%%'",
- $tax,
- htmlspecialchars( $term_, ENT_QUOTES, $charset )
+ $tt_ids = array_merge(
+ $tt_ids,
+ $wpdb->get_col(
+ $wpdb->prepare(
+ "SELECT DISTINCT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} tt JOIN {$wpdb->terms} t ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.name LIKE '%%%s%%'",
+ $tax,
+ htmlspecialchars( $term_, ENT_QUOTES, $charset )
+ )
)
);
}
}
+ $tt_ids = array_values( array_unique( array_map( 'intval', $tt_ids ) ) );
+
if ( $tt_ids ) {
list( $alias, $reused ) = $search->join_alias( $wpdb->term_relationships );
--- a/business-directory-plugin/includes/helpers/class-field-display-list.php
+++ b/business-directory-plugin/includes/helpers/class-field-display-list.php
@@ -269,7 +269,18 @@
);
if ( ! $field ) {
- return WPBDP_Form_Field_Type::field_label_display_wrapper( __( 'Address', 'business-directory-plugin' ), $atts );
+ $fallback = $this->get_address_label_fallback_item();
+ if ( ! $fallback ) {
+ return WPBDP_Form_Field_Type::field_label_display_wrapper( __( 'Address', 'business-directory-plugin' ), $atts );
+ }
+
+ if ( $fallback->field->has_display_flag( 'nolabel' ) ) {
+ return '';
+ }
+
+ $atts['field'] = $fallback->field;
+
+ return WPBDP_Form_Field_Type::field_label_display_wrapper( $fallback->label, $atts );
}
if ( $field->has_display_flag( 'nolabel' ) ) {
@@ -281,6 +292,33 @@
return WPBDP_Form_Field_Type::field_label_display_wrapper( $this->t_address->label, $atts );
}
+ /**
+ * Find the first address-component field with a value when street Address is missing.
+ *
+ * @since 6.4.26
+ *
+ * @return _WPBDP_Lightweight_Field_Display_Item|null
+ */
+ private function get_address_label_fallback_item() {
+ foreach ( array( 'address2', 'city', 'state', 'country', 'zip' ) as $tag ) {
+ $item = $this->{'t_' . $tag};
+ if ( empty( $item->field ) ) {
+ continue;
+ }
+
+ $value = $item->value;
+ if ( is_array( $value ) ) {
+ $value = $value['zip'] ?? '';
+ }
+
+ if ( '' !== trim( (string) $value ) ) {
+ return $item;
+ }
+ }
+
+ return null;
+ }
+
public function helper__author() {
$listing = wpbdp_get_listing( $this->listing_id );
$author = $listing->get_author_meta( 'display_name' );
--- a/business-directory-plugin/includes/models/form-fields-validation.php
+++ b/business-directory-plugin/includes/models/form-fields-validation.php
@@ -261,6 +261,13 @@
return;
}
+ // Tag-associated textfields convert comma-separated input to an array.
+ if ( is_array( $value ) ) {
+ $value = implode( ' ', $value );
+ }
+
+ $value = (string) $value;
+
$no_html_text = preg_replace( '/(<[^>]+>)/i', '', $value );
$input_array = preg_split( '/[s,]+/', $no_html_text );
--- a/business-directory-plugin/templates/admin/form-fields-addoredit.tpl.php
+++ b/business-directory-plugin/templates/admin/form-fields-addoredit.tpl.php
@@ -148,7 +148,7 @@
</label>
</td>
</tr>
- <tr>
+ <tr id="wpbdp_required_field">
<th scope="row">
<label> <?php esc_html_e( 'Is field required?', 'business-directory-plugin' ); ?></label>
</th>
--- a/business-directory-plugin/templates/excerpt_content.tpl.php
+++ b/business-directory-plugin/templates/excerpt_content.tpl.php
@@ -5,15 +5,20 @@
<div class="listing-details<?php echo esc_attr( $images->thumbnail ? '' : ' wpbdp-no-thumb' ); ?>">
<?php foreach ( $fields->not( 'social' ) as $field ) : ?>
<?php
- $address = array( 'address', 'address2', 'city', 'state', 'country', 'zip' );
- if ( in_array( $field->tag, $address ) ) :
- if ( empty( $skip_address ) && $field->html ) :
- $skip_address = $address;
- ?>
+ $address = array( 'address', 'address2', 'city', 'state', 'country', 'zip' );
+ $has_street = ! empty( $fields->t_address->value );
+ if ( in_array( $field->tag, $address, true ) ) :
+ if ( $has_street ) :
+ if ( empty( $skip_address ) && $field->html ) :
+ $skip_address = $address;
+ ?>
<div class="address-info wpbdp-field-display wpbdp-field wpbdp-field-value">
<?php echo wp_kses_post( $fields->_h_address_label ); ?>
<div><?php echo wp_kses_post( $fields->_h_address ); ?></div>
</div>
+ <?php endif; ?>
+ <?php elseif ( $field->html ) : ?>
+ <?php echo $field->html; // phpcs:ignore WordPress.Security.EscapeOutput ?>
<?php endif; ?>
<?php else : ?>
<?php echo $field->html; // phpcs:ignore WordPress.Security.EscapeOutput ?>