Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/geodirectory/geodirectory.php
+++ b/geodirectory/geodirectory.php
@@ -11,7 +11,7 @@
* Plugin Name: GeoDirectory
* Plugin URI: https://wpgeodirectory.com/
* Description: GeoDirectory - Business Directory Plugin for WordPress.
- * Version: 2.8.207
+ * Version: 2.8.208
* Author: AyeCode - WP Business Directory Plugins
* Author URI: https://wpgeodirectory.com
* Text Domain: geodirectory
@@ -34,7 +34,7 @@
*
* @var string
*/
- public $version = '2.8.207';
+ public $version = '2.8.208';
/**
* GeoDirectory instance.
--- a/geodirectory/includes/admin/settings/functions.php
+++ b/geodirectory/includes/admin/settings/functions.php
@@ -54,8 +54,14 @@
return false;
}
- $options = get_option( 'geodir_settings' );
- if ( empty( $options ) ) {
+ // A missing option returns the default array, so false means the stored settings could not
+ // be read (e.g. they failed to unserialize). Never save over settings we could not read.
+ $options = get_option( 'geodir_settings', array() );
+ if ( false === $options ) {
+ return false;
+ }
+
+ if ( ! is_array( $options ) ) {
$options = array();
}
@@ -90,8 +96,13 @@
return false;
}
- $options = get_option( 'geodir_settings' );
- if ( empty( $options ) ) {
+ // False means the stored settings could not be read. See geodir_update_option().
+ $options = get_option( 'geodir_settings', array() );
+ if ( false === $options ) {
+ return false;
+ }
+
+ if ( ! is_array( $options ) ) {
$options = array();
}
@@ -119,13 +130,12 @@
* @return array GD settings
*/
function geodir_get_settings() {
- $settings = get_option( 'geodir_settings' );
+ $settings = get_option( 'geodir_settings', array() );
- if ( empty( $settings ) ) {
- // Update old settings with new single option.
+ // Settings that are missing or could not be read are treated as empty for this request only.
+ // Reading must never save: an empty array written here would replace the real settings.
+ if ( ! is_array( $settings ) ) {
$settings = array();
-
- update_option( 'geodir_settings', $settings );
}
return apply_filters( 'geodir_get_settings', $settings );
--- a/geodirectory/includes/business-hours-functions.php
+++ b/geodirectory/includes/business-hours-functions.php
@@ -959,24 +959,36 @@
* @return string $value Sanitize business hours.
*/
function geodir_sanitize_business_hours_value( $value, $gd_post, $custom_field, $post_id, $post, $update ) {
- if ( ! empty( $value ) && ! is_array( $value ) ) {
- $value = stripslashes_deep( $value );
- $country = '';
-
- if ( strpos( $value, '"UTC"' ) === false || strpos( $value, '"Timezone"' ) === false ) {
- if ( ! empty( $gd_post['country'] ) ) {
- $country = $gd_post['country'];
- } elseif ( GeoDir_Post_types::supports( $post->post_type, 'location' ) ) {
- $country = geodir_get_post_meta( $post_id, 'country', true );
- } else {
- $country = geodir_get_option( 'default_location_country' );
- }
- }
+ if ( empty( $value ) ) {
+ return '';
+ }
- // Always rebuild the schema from validated parts to prevent malicious input.
- $value = geodir_business_hours_sanitize_schema( $value, $country );
+ if ( is_array( $value ) ) {
+ $value = implode( ',', array_filter( array_map( function( $_value ) {
+ return is_scalar( $_value ) ? (string) $_value : '';
+ }, $value ) ) );
}
- return $value;
+
+ // Only a string can hold a valid business hours value.
+ if ( empty( $value ) || ! is_scalar( $value ) || is_bool( $value ) ) {
+ return '';
+ }
+
+ $value = stripslashes( $value );
+ $country = '';
+
+ if ( strpos( $value, '"UTC"' ) === false || strpos( $value, '"Timezone"' ) === false ) {
+ if ( ! empty( $gd_post['country'] ) ) {
+ $country = $gd_post['country'];
+ } elseif ( GeoDir_Post_types::supports( $post->post_type, 'location' ) ) {
+ $country = geodir_get_post_meta( $post_id, 'country', true );
+ } else {
+ $country = geodir_get_option( 'default_location_country' );
+ }
+ }
+
+ // Always rebuild the schema from validated parts to prevent malicious input.
+ return geodir_business_hours_sanitize_schema( $value, $country );
}
add_filter( 'geodir_custom_field_value_business_hours', 'geodir_sanitize_business_hours_value', 10, 6 );
--- a/geodirectory/includes/class-geodir-fast-ajax.php
+++ b/geodirectory/includes/class-geodir-fast-ajax.php
@@ -15,6 +15,13 @@
class GeoDir_Fast_AJAX {
/**
+ * Locale used to load the GeoDirectory translations.
+ *
+ * @var string
+ */
+ private static $textdomain_locale = '';
+
+ /**
* Init.
*/
public static function init() {
@@ -28,6 +35,9 @@
add_filter( 'option_active_plugins', array( __CLASS__, 'allowed_plugins' ), 11, 1 );
+ // Remember the locale GeoDirectory loaded its translations with (on plugins_loaded priority 10).
+ add_action( 'plugins_loaded', array( __CLASS__, 'set_textdomain_locale' ), 11 );
+
if ( ! empty( $_REQUEST['gd-no-auth'] ) ) {
// Don't needs authentication (faster).
add_action( 'plugins_loaded', array( __CLASS__, 'do_gd_ajax' ), 999 );
@@ -76,6 +86,14 @@
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
if ( $action ) {
+ // Reload translations if other plugins (eg: TranslatePress) changed the request's language after they were loaded.
+ if ( self::get_textdomain_locale() !== self::$textdomain_locale ) {
+ GeoDir()->load_textdomain();
+ }
+
+ // TranslatePress applies its gettext translations on wp_loaded, which never fires on GD Fast AJAX.
+ self::translatepress_gettext();
+
self::gd_ajax_headers();
do_action( 'geodir_ajax_' . $action );
wp_die();
@@ -86,6 +104,50 @@
}
}
+ /**
+ * Store the locale used to load the GeoDirectory translations.
+ *
+ * @since 2.8.208
+ */
+ public static function set_textdomain_locale() {
+ self::$textdomain_locale = self::get_textdomain_locale();
+ }
+
+ /**
+ * Get the current locale for the GeoDirectory translations.
+ *
+ * @since 2.8.208
+ *
+ * @return string
+ */
+ public static function get_textdomain_locale() {
+ /** This filter is documented in geodirectory.php */
+ return apply_filters( 'plugin_locale', determine_locale(), 'geodirectory' );
+ }
+
+ /**
+ * Apply TranslatePress gettext translations (eg: category names translated in TranslatePress).
+ *
+ * TranslatePress adds its gettext filters on wp_loaded for frontend AJAX requests, but
+ * GD Fast AJAX finishes before wp_loaded, so apply them before the AJAX action runs.
+ *
+ * @since 2.8.208
+ */
+ private static function translatepress_gettext() {
+ if ( did_action( 'wp_loaded' ) || ! class_exists( 'TRP_Translate_Press' ) ) {
+ return;
+ }
+
+ $trp = TRP_Translate_Press::get_trp_instance();
+ $gettext_manager = $trp ? $trp->get_component( 'gettext_manager' ) : null;
+
+ if ( $gettext_manager && has_action( 'wp_loaded', array( $gettext_manager, 'apply_gettext_filter' ) ) ) {
+ remove_action( 'wp_loaded', array( $gettext_manager, 'apply_gettext_filter' ) );
+
+ $gettext_manager->apply_gettext_filter();
+ }
+ }
+
/**
* Send headers for GD Ajax Requests.
*
--- a/geodirectory/includes/class-geodir-post-data.php
+++ b/geodirectory/includes/class-geodir-post-data.php
@@ -489,7 +489,13 @@
$gd_post_value = null;
}
- $gd_post_value = apply_filters( "geodir_custom_field_value_{$cf->field_type}", $gd_post_value, $gd_post, $cf, $post_id, $post, $update );
+ if ( has_filter( "geodir_custom_field_value_{$cf->field_type}" ) ) {
+ $gd_post_value = apply_filters( "geodir_custom_field_value_{$cf->field_type}", $gd_post_value, $gd_post, $cf, $post_id, $post, $update );
+ } else {
+ // No sanitize callback registered for this field type, so never store the raw input.
+ $gd_post_value = geodir_sanitize_custom_field_value_fallback( $gd_post_value, $cf );
+ }
+
if ( is_array( $gd_post_value ) ) {
$gd_post_value = ! empty( $gd_post_value ) ? implode( ',', $gd_post_value ) : '';
}
--- a/geodirectory/includes/custom-fields/output-filter-functions.php
+++ b/geodirectory/includes/custom-fields/output-filter-functions.php
@@ -19,11 +19,7 @@
function geodir_predefined_custom_field_output_twitter_feed($html,$location,$cf){
global $gd_post;
-
if (isset($gd_post->{$cf['htmlvar_name']}) && $gd_post->{$cf['htmlvar_name']} != '' ):
-
- $class = ($cf['htmlvar_name'] == 'geodir_timing') ? "geodir-i-time" : "geodir-i-text";
-
$field_icon = geodir_field_icon_proccess($cf);
if (strpos($field_icon, 'http') !== false) {
$field_icon_af = '';
@@ -38,7 +34,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return esc_attr( strip_tags( $x_username ) );
+ return esc_html( strip_tags( $x_username ) );
}
$value = '<a class="twitter-timeline" data-height="600" data-dnt="true" href="' . esc_url( 'https://x.com/' . $x_username ) . '">' . wp_sprintf( __( 'Tweets by %s', 'geodirectory' ), esc_html( $x_username ) ) . '</a> <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>';
@@ -107,7 +103,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return $value;
+ return geodir_clean( $value );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $_distance;
@@ -330,7 +326,7 @@
$address_fields = geodir_post_meta_address_fields( $gd_post->post_type );
if ( ! empty( $value ) && ! empty( $address_fields ) && isset( $address_fields[ $htmlvar_name ] ) ) {
- $value = geodir_post_address( $value, $htmlvar_name, $gd_post );
+ $value = geodir_post_address( geodir_clean( $value ), $htmlvar_name, $gd_post );
}
}
@@ -349,7 +345,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return $value;
+ return geodir_sanitize_custom_field_raw_output( $value, $cf );
}
$value = apply_filters( 'geodir_custom_field_output_field_value', $value, $location, $cf, $gd_post );
@@ -433,8 +429,8 @@
if ( ! empty( $gd_post->latitude ) && ! empty( $gd_post->longitude ) ) {
$label = trim( $cf['frontend_title'] );
- $latitude = $gd_post->latitude;
- $longitude = $gd_post->longitude;
+ $latitude = geodir_sanitize_latlon( $gd_post->latitude, 'lat' );
+ $longitude = geodir_sanitize_latlon( $gd_post->longitude );
$field_icon = geodir_field_icon_proccess( $cf );
$output = geodir_field_output_process( $output );
@@ -525,7 +521,7 @@
$field_icon = '';
}
- $value = $gd_post->{$htmlvar_name};
+ $value = geodir_clean( $gd_post->{$htmlvar_name} );
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
@@ -601,7 +597,7 @@
$field_icon = '';
}
- $value = $gd_post->{$htmlvar_name};
+ $value = absint( $gd_post->{$htmlvar_name} );
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
--- a/geodirectory/includes/custom-fields/output-functions.php
+++ b/geodirectory/includes/custom-fields/output-functions.php
@@ -101,7 +101,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return $gd_post->{$html_var};
+ return geodir_clean( stripslashes( $gd_post->{$html_var} ) );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $html_val;
@@ -198,7 +198,7 @@
} else {
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return stripslashes( $cf['frontend_title'] );
+ return geodir_clean( stripslashes( $cf['frontend_title'] ) );
}
$html = '<h2 class="'.$fieldset_class.'">'. stripslashes( __($cf['frontend_title'], 'geodirectory') ) . '</h2>';
@@ -330,7 +330,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return $gd_post->{$cf['htmlvar_name']};
+ return esc_html( stripslashes( $gd_post->{$cf['htmlvar_name']} ) );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $website;
@@ -464,7 +464,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return $raw_value;
+ return geodir_clean( $raw_value );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $value;
@@ -581,8 +581,8 @@
}
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- // Database value.
- return $gd_post->{$html_var};
+ // Database value. Time value never contains html.
+ return geodir_clean( stripslashes( $gd_post->{$html_var} ) );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $value;
@@ -708,7 +708,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return $gd_post->{$html_var};
+ return geodir_clean( stripslashes( $gd_post->{$html_var} ) );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return $value;
@@ -842,7 +842,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return $value;
+ return geodir_clean( $value );
}
if ( isset( $cf['data_type'] ) && ( $cf['data_type'] == 'INT' || $cf['data_type'] == 'FLOAT' || $cf['data_type'] == 'DECIMAL' ) && isset( $cf['extra_fields'] ) && $cf['extra_fields'] ) {
@@ -1009,7 +1009,7 @@
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return stripslashes_deep( $gd_post->{$cf['htmlvar_name']} );
+ return geodir_clean( stripslashes_deep( $gd_post->{$cf['htmlvar_name']} ) );
} elseif ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
return stripslashes_deep( $html_val );
@@ -1118,7 +1118,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return stripslashes( $gd_post->{$cf['htmlvar_name']} );
+ return geodir_clean( stripslashes( $gd_post->{$cf['htmlvar_name']} ) );
}
if (!empty($cf['option_values'])) {
@@ -1267,7 +1267,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return stripslashes( $gd_post->{$cf['htmlvar_name']} );
+ return geodir_clean( stripslashes( $gd_post->{$cf['htmlvar_name']} ) );
}
$field_values = explode(',', trim($gd_post->{$cf['htmlvar_name']}, ","));
@@ -1619,7 +1619,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- $value_raw = ( isset( $gd_post->{$html_var} ) ? stripslashes_deep( $gd_post->{$html_var} ) : '' );
+ $value_raw = ( isset( $gd_post->{$html_var} ) && is_scalar( $gd_post->{$html_var} ) ? esc_html( stripslashes( $gd_post->{$html_var} ) ) : '' );
return apply_filters( 'geodir_cf_file_output_value_raw', $value_raw, $files, $location, $cf, $output );
}
@@ -1890,7 +1890,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return $is_protected ? '' : stripslashes( $gd_post->{$html_var} );
+ return $is_protected ? '' : geodir_sanitize_custom_field_raw_output( stripslashes( $gd_post->{$html_var} ), $cf );
}
if( $design_style ){
@@ -1909,7 +1909,17 @@
if ( $output == '' || isset( $output['icon'] ) ) $html .= '</span>';
if ( $output == '' || isset( $output['value'] ) ) {
- $value = $is_protected ? '' : geodir_kses_safe_aui_attributes( stripslashes( $gd_post->{$html_var} ) );
+ $value = $is_protected ? '' : stripslashes( $gd_post->{$html_var} );
+
+ if ( $value ) {
+ if ( $html_var == 'post_content' && ! empty( $gd_post->post_author ) && user_can( (int) $gd_post->post_author, 'unfiltered_html' ) ) {
+ // Author is allowed to save unfiltered HTML (WordPress capability), so keep content as saved.
+ $value = geodir_kses_safe_aui_attributes( $value );
+ } else {
+ $allowed_html = geodir_custom_field_kses_allowed_html( $cf, $value, $gd_post );
+ $value = geodir_sanitize_html_field( $value, $allowed_html );
+ }
+ }
$gd_skip_the_content = true; // Set global variable to prevent looping on some themes/plugins.
$content = '';
@@ -1927,7 +1937,7 @@
$value = $wp_embed->autoembed( $value );
if ( $matterport ) {
- $value = str_replace('sandbox="allow-scripts"','sandbox="allow-scripts allow-same-origin"', $value);
+ $value = str_replace( 'sandbox="allow-scripts"','sandbox="allow-scripts allow-same-origin"', $value );
}
}
@@ -2086,12 +2096,19 @@
$field_icon = '';
}
+ $value = stripslashes( $gd_post->{$cf['htmlvar_name']} );
+
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
// Database value.
- return stripslashes( $gd_post->{$cf['htmlvar_name']} );
+ return geodir_sanitize_custom_field_raw_output( $value, $cf );
}
- $value = wpautop( do_shortcode( geodir_kses_safe_aui_attributes( stripslashes( $gd_post->{$cf['htmlvar_name']} ) ) ) );
+ if ( $value ) {
+ $allowed_html = geodir_custom_field_kses_allowed_html( $cf, $value, $gd_post );
+ $value = geodir_sanitize_html_field( $value, $allowed_html );
+ }
+
+ $value = wpautop( do_shortcode( $value ) );
if ( ! empty( $output ) && isset( $output['strip'] ) ) {
// Stripped value.
@@ -2241,7 +2258,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return $field_value;
+ return geodir_clean( $field_value );
}
$links = array();
@@ -2519,25 +2536,25 @@
$address_fields = array();
if ( isset( $gd_post->post_title ) ) {
- $address_fields['post_title'] = '<span itemprop="placeName">' . $gd_post->post_title . '</span>';
+ $address_fields['post_title'] = '<span itemprop="placeName">' . geodir_clean( stripslashes( $gd_post->post_title ) ) . '</span>';
}
if ( $show_street_in_address && isset( $gd_post->street ) && $gd_post->street ) {
- $address_fields['street'] = '<span itemprop="streetAddress">' . $gd_post->street . '</span>';
+ $address_fields['street'] = '<span itemprop="streetAddress">' . geodir_clean( stripslashes( $gd_post->street ) ) . '</span>';
}
if ( $show_street2_in_address && isset( $gd_post->street2 ) && $gd_post->street2 ) {
- $address_fields['street2'] = '<span itemprop="streetAddress2">' . $gd_post->street2. '</span>';
+ $address_fields['street2'] = '<span itemprop="streetAddress2">' . geodir_clean( stripslashes( $gd_post->street2 ) ). '</span>';
}
if ( $show_city_in_address && isset( $gd_post->city ) && $gd_post->city ) {
- $address_fields['city'] = '<span itemprop="addressLocality">' . $gd_post->city. '</span>';
+ $address_fields['city'] = '<span itemprop="addressLocality">' . geodir_clean( stripslashes( $gd_post->city ) ) . '</span>';
}
if ($show_region_in_address && isset( $gd_post->region ) && $gd_post->region ) {
- $address_fields['region'] = '<span itemprop="addressRegion">' . $gd_post->region . '</span>';
+ $address_fields['region'] = '<span itemprop="addressRegion">' . geodir_clean( stripslashes( $gd_post->region ) ) . '</span>';
}
if ( $show_zip_in_address && isset( $gd_post->zip ) && $gd_post->zip ) {
- $address_fields['zip'] = '<span itemprop="postalCode">' . $gd_post->zip . '</span>';
+ $address_fields['zip'] = '<span itemprop="postalCode">' . geodir_clean( stripslashes( $gd_post->zip ) ) . '</span>';
}
if ($show_country_in_address && isset( $gd_post->country ) && $gd_post->country ) {
- $address_fields['country'] = '<span itemprop="addressCountry">' . __( $gd_post->country, 'geodirectory' ) . '</span>';
+ $address_fields['country'] = '<span itemprop="addressCountry">' . geodir_clean( __( stripslashes( $gd_post->country ), 'geodirectory' ) ) . '</span>';
}
if ( isset( $gd_post->latitude ) && $gd_post->latitude ) {
$address_fields['latitude'] = '<span itemprop="addressLatitude">' . geodir_sanitize_latlon( $gd_post->latitude, 'lat' ) . '</span>';
@@ -2612,15 +2629,9 @@
return $html;
}
- // Database value.
- if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- $address_fields = str_replace( "<br>", "", $address_fields );
- return stripslashes( wp_strip_all_tags( $address_fields, true ) );
- }
-
- // Stripped value.
- if ( ! empty( $output ) && isset( $output['strip'] ) ) {
- $address_fields = str_replace( "<br>", ",", $address_fields );
+ // Database / Stripped value.
+ if ( ! empty( $output ) && ( isset( $output['raw'] ) || isset( $output['strip'] ) ) ) {
+ $address_fields = str_replace( array( ",<br>", "<br>" ), array( ",", "," ), $address_fields );
return stripslashes( wp_strip_all_tags( $address_fields, true ) );
}
@@ -2809,7 +2820,7 @@
// Database value.
if ( ! empty( $output ) && isset( $output['raw'] ) ) {
- return $value;
+ return geodir_clean( $value );
}
$extra_class = $location == 'owntab' || strpos($cf['css_class'], 'gd-bh-expanded') !== false ? ' gd-bh-expanded' : ' gd-bh-toggled';
--- a/geodirectory/includes/post-functions.php
+++ b/geodirectory/includes/post-functions.php
@@ -2135,8 +2135,14 @@
* @return string $value Sanitized email.
*/
function geodir_validate_custom_field_value_email( $value, $gd_post, $custom_field, $post_id, $post, $update ) {
- if ( $value != '' && is_scalar( $value ) ) {
- $value = geodir_sanitize_email( wp_unslash( $value ), 'save' );
+ if ( is_array( $value ) ) {
+ // Email field holds a single value. Sanitize every element so an array can't bypass sanitization.
+ $value = array_filter( array_map( function( $_value ) {
+ return is_scalar( $_value ) ? geodir_sanitize_email( wp_unslash( $_value ), 'save' ) : '';
+ }, $value ) );
+ $value = ! empty( $value ) ? implode( ',', $value ) : '';
+ } elseif ( $value != '' ) {
+ $value = is_scalar( $value ) ? geodir_sanitize_email( wp_unslash( $value ), 'save' ) : '';
}
return $value;
@@ -2144,6 +2150,83 @@
add_filter( 'geodir_custom_field_value_email', 'geodir_validate_custom_field_value_email', 10, 6 );
/**
+ * Sanitize time value.
+ *
+ * Time field stores a single plain text value (ex: 10:30). The value is not
+ * reformatted so imported values (ex: "10:30 am") are kept as they are, but
+ * HTML tags are always removed.
+ *
+ * @since 2.8.208
+ *
+ * @param string $value Field value.
+ * @param object $gd_post GeoDirectory post object.
+ * @param object $custom_field Custom field.
+ * @param int $post_id Post id.
+ * @param object $post Post.
+ * @param string $update Update.
+ * @return string $value Sanitized time.
+ */
+function geodir_validate_custom_field_value_time( $value, $gd_post, $custom_field, $post_id, $post, $update ) {
+ if ( $value === null || $value === '' ) {
+ return $value;
+ }
+
+ // Time field holds a single value.
+ if ( is_array( $value ) ) {
+ $value = ! empty( $value ) ? reset( $value ) : '';
+ }
+
+ return is_scalar( $value ) ? geodir_clean( (string) $value ) : '';
+}
+add_filter( 'geodir_custom_field_value_time', 'geodir_validate_custom_field_value_time', 10, 6 );
+
+/**
+ * Fallback sanitization for custom field types that don't register their
+ * own "geodir_custom_field_value_{$field_type}" sanitize callback.
+ *
+ * @since 2.8.208
+ *
+ * @param mixed $value Field value.
+ * @param object $custom_field Custom field.
+ * @return mixed Sanitized value.
+ */
+function geodir_sanitize_custom_field_value_fallback( $value, $custom_field ) {
+ if ( $value === null || $value === '' ) {
+ return $value;
+ }
+
+ $field_type = ! empty( $custom_field->field_type ) ? $custom_field->field_type : '';
+
+ // Slashes are not removed here, the save loop runs stripslashes_deep() after this.
+ if ( in_array( $field_type, array( 'file', 'images' ) ) ) {
+ // File strings contain urls which may have encoded octets, so only strip tags.
+ $callback = function( $_value ) {
+ return is_scalar( $_value ) ? wp_strip_all_tags( (string) $_value ) : '';
+ };
+ } else {
+ $callback = function( $_value ) {
+ return is_scalar( $_value ) ? geodir_clean( $_value ) : '';
+ };
+ }
+
+ if ( is_array( $value ) ) {
+ $value = array_map( $callback, $value );
+ } else {
+ $value = call_user_func( $callback, $value );
+ }
+
+ /**
+ * Filters the fallback sanitized custom field value.
+ *
+ * @since 2.8.208
+ *
+ * @param mixed $value Sanitized value.
+ * @param object $custom_field Custom field.
+ */
+ return apply_filters( 'geodir_sanitize_custom_field_value_fallback', $value, $custom_field );
+}
+
+/**
* Sanitize url value.
*
* @since 2.3.99
@@ -2184,55 +2267,10 @@
*/
function geodir_validate_custom_field_value_textarea( $value, $gd_post, $custom_field, $post_id, $post, $update ) {
if ( $value != '' ) {
- $html = false;
- // Post content & video contains html/embed code.
- if ( $custom_field->field_type == 'html' || $custom_field->htmlvar_name == 'post_content' || $custom_field->htmlvar_name == 'video' ) {
- $html = true;
- } else {
- // Check if textarea field has html/embed enabled.
- $extra_fields = ! empty( $custom_field->extra_fields ) ? stripslashes_deep( maybe_unserialize( $custom_field->extra_fields ) ) : NULL;
- if ( is_array( $extra_fields ) && ( ! empty( $extra_fields['advanced_editor'] ) || ! empty( $extra_fields['embed'] ) ) ) {
- $html = true;
- }
- }
+ $html = geodir_custom_field_allows_html( $custom_field );
if ( $html ) {
- $allowed_html = wp_kses_allowed_html( 'post' );
-
- if ( is_array( $allowed_html ) ) {
- // <iframe>
- if ( ! isset( $allowed_html['iframe'] ) ) {
- $allowed_html['iframe'] = array(
- 'class' => true,
- 'id' => true,
- 'src' => true,
- 'width' => true,
- 'height' => true,
- 'frameborder' => true,
- 'marginwidth' => true,
- 'marginheight' => true,
- 'scrolling' => true,
- 'style' => true,
- 'title' => true,
- 'allow' => true,
- 'allowfullscreen' => true,
- 'data-*' => true,
- );
- }
- }
-
- /**
- * Filters the HTML that is allowed for a given field.
- *
- * @since 2.0.0.68
- *
- * @param array[]|string $allowed_html Allowed html tags.
- * @param object $custom_field Custom field.
- * @param string $value Field value.
- * @param object $gd_post GeoDirectory post object.
- * @param string $context_type Context name.
- */
- $allowed_html = apply_filters( 'geodir_custom_field_kses_allowed_html', $allowed_html, $custom_field, $value, $gd_post );
+ $allowed_html = geodir_custom_field_kses_allowed_html( $custom_field, $value, $gd_post );
if ( is_array( $value ) ) {
$value = array_map( function( $value ) use ( $allowed_html ) {
@@ -2262,6 +2300,142 @@
add_filter( 'geodir_custom_field_value_textarea', 'geodir_validate_custom_field_value_textarea', 10, 6 );
/**
+ * Check whether a custom field is allowed to contain HTML.
+ *
+ * HTML fields, post content, video and textarea fields with advanced editor
+ * or embed enabled can contain html/embed code.
+ *
+ * @since 2.8.208
+ *
+ * @param object|array $custom_field Custom field.
+ * @return bool True if field can contain HTML.
+ */
+function geodir_custom_field_allows_html( $custom_field ) {
+ $custom_field = is_array( $custom_field ) ? (object) $custom_field : $custom_field;
+
+ if ( ! is_object( $custom_field ) ) {
+ return false;
+ }
+
+ $field_type = ! empty( $custom_field->field_type ) ? $custom_field->field_type : ( ! empty( $custom_field->type ) ? $custom_field->type : '' );
+ $htmlvar_name = ! empty( $custom_field->htmlvar_name ) ? $custom_field->htmlvar_name : '';
+
+ // Post content & video contains html/embed code.
+ if ( $field_type == 'html' || $htmlvar_name == 'post_content' || $htmlvar_name == 'video' ) {
+ return true;
+ }
+
+ // Check if textarea field has html/embed enabled.
+ if ( $field_type == 'textarea' && ! empty( $custom_field->extra_fields ) ) {
+ $extra_fields = is_array( $custom_field->extra_fields ) ? $custom_field->extra_fields : stripslashes_deep( maybe_unserialize( $custom_field->extra_fields ) );
+
+ if ( is_array( $extra_fields ) && ( ! empty( $extra_fields['advanced_editor'] ) || ! empty( $extra_fields['embed'] ) ) ) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Get the HTML allowed for a custom field that can contain HTML.
+ *
+ * @since 2.8.208
+ *
+ * @param object|array $custom_field Custom field.
+ * @param string $value Field value.
+ * @param array|object $gd_post GeoDirectory post object.
+ * @return array[]|string Allowed html tags.
+ */
+function geodir_custom_field_kses_allowed_html( $custom_field, $value = '', $gd_post = array() ) {
+ $custom_field = is_array( $custom_field ) ? (object) $custom_field : $custom_field;
+
+ $allowed_html = wp_kses_allowed_html( 'post' );
+
+ if ( is_array( $allowed_html ) ) {
+ // <iframe>
+ if ( ! isset( $allowed_html['iframe'] ) ) {
+ $allowed_html['iframe'] = array(
+ 'class' => true,
+ 'id' => true,
+ 'src' => true,
+ 'width' => true,
+ 'height' => true,
+ 'frameborder' => true,
+ 'marginwidth' => true,
+ 'marginheight' => true,
+ 'scrolling' => true,
+ 'style' => true,
+ 'title' => true,
+ 'allow' => true,
+ 'allowfullscreen' => true,
+ 'data-*' => true,
+ );
+ }
+ }
+
+ /**
+ * Filters the HTML that is allowed for a given field.
+ *
+ * @since 2.0.0.68
+ *
+ * @param array[]|string $allowed_html Allowed html tags.
+ * @param object $custom_field Custom field.
+ * @param string $value Field value.
+ * @param object $gd_post GeoDirectory post object.
+ * @param string $context_type Context name.
+ */
+ return apply_filters( 'geodir_custom_field_kses_allowed_html', $allowed_html, $custom_field, $value, $gd_post );
+}
+
+/**
+ * Sanitize a custom field value displayed with "value (saved in database)" output.
+ *
+ * The raw database value is printed on the page, so escape it. Fields that
+ * can contain HTML are filtered with the same allowed html used on save,
+ * all other field values are escaped as plain text.
+ *
+ * @since 2.8.208
+ *
+ * @param string $value Raw output value.
+ * @param object|array $custom_field Custom field.
+ * @return string Safe output value.
+ */
+function geodir_sanitize_custom_field_raw_output( $value, $custom_field ) {
+ if ( ! is_scalar( $value ) ) {
+ return '';
+ }
+
+ $raw_value = $value;
+ $value = (string) $value;
+
+ if ( $value !== '' ) {
+ $_custom_field = is_array( $custom_field ) ? (object) $custom_field : $custom_field;
+ $htmlvar_name = is_object( $_custom_field ) && ! empty( $_custom_field->htmlvar_name ) ? $_custom_field->htmlvar_name : '';
+
+ if ( $htmlvar_name == 'post_content' || geodir_custom_field_allows_html( $_custom_field ) ) {
+ $value = wp_kses( $value, geodir_custom_field_kses_allowed_html( $_custom_field, $value ) );
+ $value = geodir_kses_safe_embed_attributes( $value );
+ $value = geodir_kses_safe_aui_attributes( $value );
+ $value = geodir_kses_safe_lity_attributes( $value );
+ } else {
+ $value = esc_html( $value );
+ }
+ }
+
+ /**
+ * Filters the sanitized raw output value of a custom field.
+ *
+ * @since 2.8.208
+ *
+ * @param string $value Safe output value.
+ * @param string $raw_value Raw output value.
+ * @param object|array $custom_field Custom field.
+ */
+ return apply_filters( 'geodir_sanitize_custom_field_raw_output', $value, $raw_value, $custom_field );
+}
+
+/**
* Get the post meta advance custom fields.
*
* @since 2.0.0.86
--- a/geodirectory/includes/widgets/class-geodir-widget-search.php
+++ b/geodirectory/includes/widgets/class-geodir-widget-search.php
@@ -313,9 +313,14 @@
geodir_get_search_post_type(); // set the post type
}
- // maybe remove advanced search main fields
- if( !empty($instance['show']) && 'main-no-advanced' === $instance['show']){
- remove_action( 'geodir_before_search_form', 'geodir_search_add_to_main', 0 );
+ // Maybe remove advanced search main fields for this form only.
+ $main_fields_priority = false;
+ if ( ! empty( $instance['show'] ) && 'main-no-advanced' === $instance['show'] ) {
+ $main_fields_priority = has_action( 'geodir_before_search_form', 'geodir_search_add_to_main' );
+
+ if ( false !== $main_fields_priority ) {
+ remove_action( 'geodir_before_search_form', 'geodir_search_add_to_main', $main_fields_priority );
+ }
}
// Set if the cpt selector, search, near should be hidden
@@ -457,6 +462,11 @@
echo geodir_get_template_html( $template_params['template'], $template_params['template_args'], $template_params['template_path'], $template_params['default_path'] );
+ // Restore advanced search main fields so other search forms on the page still show them.
+ if ( false !== $main_fields_priority ) {
+ add_action( 'geodir_before_search_form', 'geodir_search_add_to_main', $main_fields_priority );
+ }
+
// After outputing the search reset the CPT
global $geodir_search_post_type;
$geodir_search_post_type = '';
--- a/geodirectory/vendor/ayecode/wp-super-duper/sd-functions.php
+++ b/geodirectory/vendor/ayecode/wp-super-duper/sd-functions.php
@@ -3405,6 +3405,9 @@
if ( isset( $output_condition['message'] ) ) {
$content = $output_condition['message'] != '' ? __( stripslashes( $output_condition['message'] ), 'ayecode-connect' ) : $output_condition['message'];
+ // Sanitize the message to prevent XSS.
+ $content = is_scalar( $content ) ? wp_kses_post( (string) $content ) : '';
+
if ( ! empty( $output_condition['message_type'] ) ) {
$content = aui()->alert( array(
'type'=> $output_condition['message_type'],
--- a/geodirectory/vendor/ayecode/wp-super-duper/sd-plugin.php
+++ b/geodirectory/vendor/ayecode/wp-super-duper/sd-plugin.php
@@ -5,7 +5,7 @@
* @wordpress-plugin
* Plugin Name: Super Duper - Examples
* Description: This is a Hello World test plugin for WP Super Duper Class.
- * Version: 1.2.38
+ * Version: 1.2.39
* Author: AyeCode
* Author URI: https://ayecode.io
* Text Domain: super-duper
--- a/geodirectory/vendor/ayecode/wp-super-duper/wp-super-duper.php
+++ b/geodirectory/vendor/ayecode/wp-super-duper/wp-super-duper.php
@@ -5,7 +5,7 @@
if ( ! class_exists( 'WP_Super_Duper' ) ) {
- define( 'SUPER_DUPER_VER', '1.2.38' );
+ define( 'SUPER_DUPER_VER', '1.2.39' );
/**
* A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
--- a/geodirectory/vendor/composer/installed.php
+++ b/geodirectory/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'ayecode/geodirectory',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'cce5f76307203940aaff8e1b81b72a26baf29645',
+ 'reference' => 'b2f80d2538d97033e0e037464bfd5ad6408f8159',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -22,7 +22,7 @@
'ayecode/geodirectory' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'cce5f76307203940aaff8e1b81b72a26baf29645',
+ 'reference' => 'b2f80d2538d97033e0e037464bfd5ad6408f8159',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -65,9 +65,9 @@
'dev_requirement' => false,
),
'ayecode/wp-super-duper' => array(
- 'pretty_version' => '1.2.38',
- 'version' => '1.2.38.0',
- 'reference' => '270cee3b08b837b99fa62fd9fe1edbef087f5af8',
+ 'pretty_version' => '1.2.39',
+ 'version' => '1.2.39.0',
+ 'reference' => 'b9b03cf784ab3d655e2015bef3c9b447ef07a283',
'type' => 'library',
'install_path' => __DIR__ . '/../ayecode/wp-super-duper',
'aliases' => array(),