From 0857b13f053c452ddcc5b699d0850c40c7396189 Mon Sep 17 00:00:00 2001 From: Ajay D'Souza Date: Wed, 11 Dec 2024 21:28:04 +0000 Subject: [PATCH] Attempt to fix quotes --- better-search.php | 7 +++++-- includes/class-better-search-core-query.php | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/better-search.php b/better-search.php index f814c09..f993e68 100644 --- a/better-search.php +++ b/better-search.php @@ -10,10 +10,11 @@ * @copyright 2009-2025 Ajay D'Souza * * @wordpress-plugin - * Plugin Name: Better Search + * Plugin Name: Better Search Pro * Plugin URI: https://webberzone.com/plugins/better-search/ * Description: Replace the default WordPress search with a contextual search. Search results are sorted by relevancy ensuring a better visitor search experience. - * Version: 4.0.3 + * Version: 4.0.4-beta1 + * Update URI: https://api.freemius.com * Author: WebberZone * Author URI: https://webberzone.com/ * Text Domain: better-search @@ -21,6 +22,8 @@ * License URI: https://www.gnu.org/licenses/gpl-2.0.txt * Domain Path: /languages * GitHub Plugin URI: https://github.com/WebberZone/better-search/ + * + * @fs_premium_only /includes/pro/ */ namespace WebberZone\Better_Search; diff --git a/includes/class-better-search-core-query.php b/includes/class-better-search-core-query.php index 4d3d5d0..7e0be03 100644 --- a/includes/class-better-search-core-query.php +++ b/includes/class-better-search-core-query.php @@ -541,7 +541,7 @@ public function get_match_sql( $search_query, $args = array() ) { $weight_title = $args['weight_title'] ?? bsearch_get_option( 'weight_title' ); $weight_content = $args['weight_content'] ?? bsearch_get_option( 'weight_content' ); $boolean_mode = $this->is_boolean_mode ? ' IN BOOLEAN MODE' : ''; - $search_query = wp_specialchars_decode( $search_query ); + $search_query = wp_specialchars_decode( $search_query, ENT_QUOTES ); $field_score = ''; @@ -549,11 +549,9 @@ public function get_match_sql( $search_query, $args = array() ) { if ( $this->use_fulltext ) { // Prepare the query once and use it with prepared arguments. $field_score = $wpdb->prepare( - "(MATCH({$wpdb->posts}.post_title) AGAINST (%s {$boolean_mode}) * %d) + " . // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared - "(MATCH({$wpdb->posts}.post_content) AGAINST (%s {$boolean_mode}) * %d)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $search_query, + "(MATCH({$wpdb->posts}.post_title) AGAINST ('{$search_query}' {$boolean_mode}) * %d) + " . // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + "(MATCH({$wpdb->posts}.post_content) AGAINST ('{$search_query}' {$boolean_mode}) * %d)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $weight_title, - $search_query, $weight_content ); } @@ -753,6 +751,8 @@ public function posts_search( $where, $query ) { } foreach ( (array) $search_terms as $term ) { + $term = str_replace( array( "'", '"', '"', '\+', '\-' ), '', $term ); + // If there is an $exclusion_prefix, terms prefixed with it should be excluded. $exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix ); if ( $exclude ) { @@ -775,6 +775,7 @@ public function posts_search( $where, $query ) { // Let's do a LIKE search for all other fields. $searchand = ''; foreach ( (array) $search_terms as $term ) { + $term = str_replace( array( "'", '"', '"', '\+', '\-' ), '', $term ); $clause = array(); // If there is an $exclusion_prefix, terms prefixed with it should be excluded.