Skip to content

Commit 068f900

Browse files
committed
v4.2.0: Sync with pro version - update copyright to 2026, refresh i18n files, apply PHPCS formatting
1 parent 8df4e2b commit 068f900

7 files changed

Lines changed: 399 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[![Required PHP](https://img.shields.io/wordpress/plugin/required-php/better-search?style=flat-square)](https://wordpress.org/plugins/better-search/)
99
[![Active installs](https://img.shields.io/wordpress/plugin/installs/better-search?style=flat-square)](https://wordpress.org/plugins/better-search/)
1010

11-
__Requires:__ 6.5
11+
__Requires:__ 6.6
1212

13-
__Tested up to:__ 6.8
13+
__Tested up to:__ 6.9
1414

1515
__License:__ [GPL-2.0+](https://www.gnu.org/licenses/gpl-2.0.html)
1616

better-search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Plugin Name: Better Search
1414
* Plugin URI: https://webberzone.com/plugins/better-search/
1515
* Description: Replace the default WordPress search with a contextual search. Search results are sorted by relevancy ensuring a better visitor search experience.
16-
* Version: 4.2.2-beta1
16+
* Version: 4.2.2
1717
* Author: WebberZone
1818
* Author URI: https://webberzone.com/
1919
* Text Domain: better-search
@@ -34,7 +34,7 @@
3434
*
3535
* @since 2.9.3
3636
*/
37-
define( 'BETTER_SEARCH_VERSION', '4.2.2-beta1' );
37+
define( 'BETTER_SEARCH_VERSION', '4.2.2' );
3838
}
3939

4040
if ( ! defined( 'BETTER_SEARCH_PLUGIN_DIR' ) ) {

includes/util/class-cache.php

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,98 @@ public static function get_keys() {
111111
}
112112

113113
/**
114-
* Get the meta key based on a list of parameters.
114+
* Get the cache key based on a list of parameters.
115115
*
116116
* @since 3.3.0
117117
*
118118
* @param mixed $attr Array of attributes typically.
119119
* @param string $context Context of the cache key to be set.
120120
* @return string Cache meta key
121121
*/
122-
public static function get_key( $attr, $context = 'query' ) {
122+
public static function get_key( $attr, $context = 'query' ): string {
123+
$args = (array) $attr;
123124

124-
$key = sprintf( 'bs_cache_%1$s_%2$s', md5( wp_json_encode( $attr ) ), $context );
125+
static $setting_types = null;
126+
if ( null === $setting_types ) {
127+
$setting_types = function_exists( 'bsearch_get_registered_settings_types' ) ? bsearch_get_registered_settings_types() : array();
128+
}
129+
130+
// Remove args that don't affect query results.
131+
$exclude_keys = array(
132+
'echo',
133+
'extra_class',
134+
'heading',
135+
'is_block',
136+
'is_manual',
137+
'is_shortcode',
138+
'is_widget',
139+
'other_attributes',
140+
);
141+
142+
foreach ( $exclude_keys as $key ) {
143+
unset( $args[ $key ] );
144+
}
145+
146+
// Remove any keys ending in _header or _desc, or with type 'header'.
147+
foreach ( $args as $key => $value ) {
148+
if ( '_header' === substr( $key, -7 ) || '_desc' === substr( $key, -5 ) ) {
149+
unset( $args[ $key ] );
150+
continue;
151+
}
152+
153+
if ( isset( $setting_types[ $key ] ) && 'header' === $setting_types[ $key ] ) {
154+
unset( $args[ $key ] );
155+
}
156+
}
157+
158+
// Define categories of types for normalization.
159+
$id_array_types = array( 'postids', 'numbercsv', 'taxonomies' );
160+
$string_array_types = array( 'posttypes', 'csv', 'multicheck' );
161+
$numeric_types = array( 'number', 'checkbox', 'select', 'radio', 'radiodesc' );
162+
163+
// Process arguments based on their registered types.
164+
foreach ( $args as $key => $value ) {
165+
$type = $setting_types[ $key ] ?? '';
166+
167+
if ( in_array( $type, $numeric_types, true ) && is_numeric( $value ) ) {
168+
$args[ $key ] = (int) $value;
169+
} elseif ( in_array( $type, $id_array_types, true ) ) {
170+
$args[ $key ] = is_array( $value ) ? $value : wp_parse_id_list( $value );
171+
$args[ $key ] = array_unique( array_map( 'absint', $args[ $key ] ) );
172+
$args[ $key ] = array_filter( $args[ $key ] );
173+
sort( $args[ $key ] );
174+
if ( empty( $args[ $key ] ) ) {
175+
unset( $args[ $key ] );
176+
}
177+
} elseif ( in_array( $type, $string_array_types, true ) ) {
178+
if ( is_string( $value ) && strpos( $value, '=' ) !== false ) {
179+
parse_str( $value, $parsed );
180+
$value = array_keys( $parsed );
181+
} elseif ( is_string( $value ) ) {
182+
$value = explode( ',', $value );
183+
}
184+
$args[ $key ] = is_array( $value ) ? $value : array( $value );
185+
$args[ $key ] = array_unique( array_map( 'strval', $args[ $key ] ) );
186+
$args[ $key ] = array_filter( $args[ $key ] );
187+
sort( $args[ $key ] );
188+
if ( empty( $args[ $key ] ) ) {
189+
unset( $args[ $key ] );
190+
}
191+
}
192+
}
193+
194+
// Sort top-level arguments.
195+
ksort( $args );
196+
197+
// Remove any remaining empty strings or null values.
198+
foreach ( $args as $key => $value ) {
199+
if ( '' === $value || null === $value ) {
200+
unset( $args[ $key ] );
201+
}
202+
}
125203

126-
return $key;
204+
// Generate cache key.
205+
return sprintf( 'bs_cache_%1$s_%2$s', md5( wp_json_encode( $args ) ), $context );
127206
}
128207

129208
/**

0 commit comments

Comments
 (0)