Inspector implements Standard_Service, Registerable
Inspector service for monitoring and caching WooCommerce product queries.
This service inspects WooCommerce product queries to cache query variables and provide integration data for the filters system. It monitors main queries that are not already processed by the filters system to avoid conflicts.
Interfaces, Classes and Traits
- Standard_Service
- Registerable
Table of Contents
- TRANSIENT_PREFIX = 'wc_filters_query_'
- Prefix for transient keys used to cache query variables.
- TRANSIENT_TTL = MINUTE_IN_SECONDS
- Time-to-live for cached query variables in seconds.
- delete_all_cached_query_vars() : int
- Deletes all cached query variables transients generated by this class.
- inspect_query() : void
- Inspects a WooCommerce product query and caches its variables.
- maybe_set_query_vars() : void
- Sets query vars if they are available.
- process_query_vars() : void
- Processes query variables programmatically without inspection checks.
- register() : void
- Registers the inspector service with WordPress hooks.
- generate_transient_key() : string
- Generates a unique transient key based on query variables.
- get_query_key_without_prefix() : string
- Removes the transient prefix from a key to get the raw hash.
Constants
TRANSIENT_PREFIX
Prefix for transient keys used to cache query variables.
public
mixed
TRANSIENT_PREFIX
= 'wc_filters_query_'
TRANSIENT_TTL
Time-to-live for cached query variables in seconds.
public
mixed
TRANSIENT_TTL
= MINUTE_IN_SECONDS
Methods
delete_all_cached_query_vars()
Deletes all cached query variables transients generated by this class.
public
static delete_all_cached_query_vars() : int
This method queries the database to find all transients with the class prefix and deletes them. It handles both regular transients and timeout transients.
Return values
int —The number of transients deleted.
inspect_query()
Inspects a WooCommerce product query and caches its variables.
public
inspect_query(WP_Query $query, WC_Query $instance) : void
This method analyzes product queries to determine if they should be inspected and cached. It only processes main queries that are not admin queries and haven't already been processed by the filters system.
Parameters
- $query : WP_Query
-
The WordPress query object.
- $instance : WC_Query
-
The WooCommerce query instance.
Return values
void —maybe_set_query_vars()
Sets query vars if they are available.
public
maybe_set_query_vars(WP_REST_Request $request, Search_Api $api) : void
Parameters
- $request : WP_REST_Request
-
The REST request object.
- $api : Search_Api
-
The Search_Api instance.
Return values
void —process_query_vars()
Processes query variables programmatically without inspection checks.
public
static process_query_vars(array<string|int, mixed> $query_vars) : void
This static method replicates the core functionality of inspect_query without the should_inspect checks, allowing the query caching logic to be triggered programmatically from other parts of the codebase.
Parameters
- $query_vars : array<string|int, mixed>
-
The query variables to process and cache.
Return values
void —register()
Registers the inspector service with WordPress hooks.
public
register() : void
Return values
void —generate_transient_key()
Generates a unique transient key based on query variables.
protected
static generate_transient_key(array<string|int, mixed> $query_vars) : string
Creates a hash of the serialized query variables to use as a cache key. The query variables are sorted to ensure consistent hashing regardless of the order they were originally set.
Parameters
- $query_vars : array<string|int, mixed>
-
The query variables to hash.
Return values
string —The generated transient key with prefix.
get_query_key_without_prefix()
Removes the transient prefix from a key to get the raw hash.
private
static get_query_key_without_prefix(string $key) : string
Parameters
- $key : string
-
The full transient key with prefix.
Return values
string —The key without the transient prefix.