Move default autosuggest selectors definition so they can be filtered. #2181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
The autosuggest feature is automatically added to these selectors
.ep-autosuggest, input[type="search"], .search-field
. These are defined in the JavaScript file, and cannot be changed by the user. This PR moves the definition of the default selectors into the script localization so that they can be changed by filtering thedefaultSelectors
option with the existingep_autosuggest_options
filter.It also adds a
ep_autosuggest_default_selectors
filter just for the default selectors.Alternate Designs
In #2168 @johnbillion suggested a
selectors
option, which could take precedence over theselector
option if it was present. I opted to just put the default selectors into adefaultSelectors
option to avoid potential ambiguity betweenselector
andselectors
, and possible confusion due to what would be the absence of an existingselectors
option in the values that are being filtered.Another approach could have been to implement the filter in JavaScript, since that's where the original value was, but I opted for putting them inside the PHP filter since that PHP filter was already established as being available to change some selector behaviour.
Benefits
The most obvious use case would be to stop the plugin adding Autosuggest to all search inputs, by removing the
input[type="search"]
selector using:or
The existence of an additional filter specifically for selectors enables removing default selectors with just:
Possible Drawbacks
In the event that a user has used the
ep_autosuggest_options
filter in such a way that does not pass through thedefaultSelectors
option, autosuggest would no longer be added to the default selectors.Verification Process
ep-autosuggest
class itself, no autosuggest functionality should be present in the search widget.Checklist:
Applicable Issues
Addresses #2168.
Changelog Entry
Allows changing or removing the default selectors used for autosuggest by filtering the
defaultSelectors
option in theep_autosuggest_options
filter.