Skip to content

Commit

Permalink
Add get_contexts_method
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy committed Mar 26, 2024
1 parent 4a432f5 commit cb384dd
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions includes/classes/Feature/Autosuggest/Autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function mapping( $mapping ) {
* @return array
*/
public function set_fuzziness( $fuzziness, $search_fields, $args ) {
if ( Utils\is_integrated_request( $this->slug, [ 'public' ] ) && ! empty( $args['s'] ) ) {
if ( Utils\is_integrated_request( $this->slug, $this->get_contexts() ) && ! empty( $args['s'] ) ) {
return 'auto';
}
return $fuzziness;
Expand All @@ -195,7 +195,7 @@ public function set_fuzziness( $fuzziness, $search_fields, $args ) {
* @return array $query adjusted ES Query arguments
*/
public function adjust_fuzzy_fields( $query, $post_type, $args ) {
if ( ! Utils\is_integrated_request( $this->slug, [ 'public', 'ajax' ] ) || empty( $args['s'] ) ) {
if ( ! Utils\is_integrated_request( $this->slug, $this->get_contexts() ) || empty( $args['s'] ) ) {
return $query;
}

Expand Down Expand Up @@ -926,4 +926,22 @@ public function delete_cached_query() {
'ElasticPress 4.7.0'
);
}

/**
* Get the contexts where autosuggest is used.
*
* @since 5.1.0
* @return array
*/
protected function get_contexts() : array {
/**
* Filter contexts where autosuggest is used.
*
* @hook ep_autosuggest_contexts
* @since 5.1.0
* @param {array} $contexts Contexts where autosuggest is used
* @return {array} New contexts
*/
return apply_filters( 'ep_autosuggest_contexts', [ 'public', 'ajax' ] );
}
}

0 comments on commit cb384dd

Please sign in to comment.