O3PO_RewriteRules
in package
Schedule and recover O-3PO rewrite rules.
Tags
Table of Contents
Constants
- LAST_404_REFRESH_TRIGGER_OPTION : mixed = 'o3po_rewrite_rules_last_404_trigger'
- REFRESH_404_LOCK_OPTION : mixed = 'o3po_rewrite_rules_404_lock'
- REFRESH_404_LOCK_TIMEOUT_SECONDS : mixed = 60
- REFRESH_PENDING_OPTION : mixed = 'o3po_rewrite_rules_refresh_pending'
- REWRITE_404_RATE_LIMIT_SECONDS : mixed = 600
- REWRITE_RULE_REGEX_DELIMITER : mixed = "\x01"
Methods
- flush_on_deactivation() : mixed
- Flush all rewrite rules after plugin deactivation.
- refresh_if_needed() : mixed
- Refresh rewrite rules once all endpoints and post types have registered.
- schedule_refresh() : mixed
- Schedule a rewrite refresh for the next request.
- schedule_refresh_on_endpoint_404() : mixed
- Schedule a rate-limited refresh after a 404 for one of this plugin's endpoints.
- clear_option_cache() : mixed
- Clear cached option values before a fresh database-backed read.
- contains_case_insensitive() : bool
- Check a route slug against configured values without case sensitivity.
- get_endpoint_query_vars() : array<string|int, mixed>
- Get the query vars used to identify O3PO endpoint requests.
- get_normalized_request_path() : string|false
- Get the request path without the site's home path prefix.
- get_root_endpoint_slugs() : array<string|int, mixed>
- Get the root-level routes configured by O3PO.
- has_rewrite_rule_for_publication_path() : bool
- Check whether a matching stored rewrite rule targets a publication type.
- is_o3po_endpoint_request() : bool
- Determine whether a 404 request targets one of O3PO's routes.
- release_refresh_lock() : mixed
- Release the refresh lock only if it is still owned by this request.
- replace_stale_refresh_lock() : bool
- Atomically replace a stale 404 refresh lock.
- rewrite_rule_targets_publication_type() : bool
- Check whether a rewrite query targets a custom publication type.
Constants
LAST_404_REFRESH_TRIGGER_OPTION
public
mixed
LAST_404_REFRESH_TRIGGER_OPTION
= 'o3po_rewrite_rules_last_404_trigger'
REFRESH_404_LOCK_OPTION
public
mixed
REFRESH_404_LOCK_OPTION
= 'o3po_rewrite_rules_404_lock'
REFRESH_404_LOCK_TIMEOUT_SECONDS
public
mixed
REFRESH_404_LOCK_TIMEOUT_SECONDS
= 60
REFRESH_PENDING_OPTION
public
mixed
REFRESH_PENDING_OPTION
= 'o3po_rewrite_rules_refresh_pending'
REWRITE_404_RATE_LIMIT_SECONDS
public
mixed
REWRITE_404_RATE_LIMIT_SECONDS
= 600
REWRITE_RULE_REGEX_DELIMITER
public
mixed
REWRITE_RULE_REGEX_DELIMITER
= "\x01"
Methods
flush_on_deactivation()
Flush all rewrite rules after plugin deactivation.
public
static flush_on_deactivation() : mixed
Tags
refresh_if_needed()
Refresh rewrite rules once all endpoints and post types have registered.
public
static refresh_if_needed() : mixed
To be added to the 'wp_loaded' action. A refresh queued on 'template_redirect' runs on the next request; it does not change the 404 response that caused it.
Tags
schedule_refresh()
Schedule a rewrite refresh for the next request.
public
static schedule_refresh() : mixed
Tags
schedule_refresh_on_endpoint_404()
Schedule a rate-limited refresh after a 404 for one of this plugin's endpoints.
public
static schedule_refresh_on_endpoint_404() : mixed
To be added to the 'template_redirect' action.
Tags
clear_option_cache()
Clear cached option values before a fresh database-backed read.
private
static clear_option_cache(string $option_name) : mixed
Parameters
- $option_name : string
-
The option to invalidate.
Tags
contains_case_insensitive()
Check a route slug against configured values without case sensitivity.
private
static contains_case_insensitive(string $value, array<string|int, mixed> $values) : bool
Parameters
- $value : string
-
The route slug from the request.
- $values : array<string|int, mixed>
-
Configured route slugs.
Tags
Return values
bool —Whether the route slug matches.
get_endpoint_query_vars()
Get the query vars used to identify O3PO endpoint requests.
private
static get_endpoint_query_vars(O3PO_Settings $settings) : array<string|int, mixed>
Parameters
- $settings : O3PO_Settings
-
The plugin settings.
Tags
Return values
array<string|int, mixed> —The O3PO endpoint query vars.
get_normalized_request_path()
Get the request path without the site's home path prefix.
private
static get_normalized_request_path() : string|false
Tags
Return values
string|false —The normalized request path, or false when unavailable.
get_root_endpoint_slugs()
Get the root-level routes configured by O3PO.
private
static get_root_endpoint_slugs(O3PO_Settings $settings) : array<string|int, mixed>
Parameters
- $settings : O3PO_Settings
-
The plugin settings.
Tags
Return values
array<string|int, mixed> —The root-level endpoint slugs.
has_rewrite_rule_for_publication_path()
Check whether a matching stored rewrite rule targets a publication type.
private
static has_rewrite_rule_for_publication_path(string $publication_query_var, string $request_path) : bool
Parameters
- $publication_query_var : string
-
The publication type's query var.
- $request_path : string
-
The request path.
Tags
Return values
bool —Whether a stored rewrite rule matches the request path.
is_o3po_endpoint_request()
Determine whether a 404 request targets one of O3PO's routes.
private
static is_o3po_endpoint_request(array<string|int, mixed> $query_vars) : bool
Query vars catch recognized routes. The URI fallback also catches endpoint URLs whose rewrite rule is missing and therefore was not parsed.
Parameters
- $query_vars : array<string|int, mixed>
-
Parsed WordPress query variables.
Tags
Return values
bool —Whether the request targets an O3PO endpoint or publication route.
release_refresh_lock()
Release the refresh lock only if it is still owned by this request.
private
static release_refresh_lock(int $lock_time) : mixed
Parameters
- $lock_time : int
-
The timestamp stored by this request.
Tags
replace_stale_refresh_lock()
Atomically replace a stale 404 refresh lock.
private
static replace_stale_refresh_lock(int $stale_lock_time, int $new_lock_time) : bool
Parameters
- $stale_lock_time : int
-
The timestamp currently stored in the lock.
- $new_lock_time : int
-
The timestamp to store for this request.
Tags
Return values
bool —Whether the stale lock was replaced.
rewrite_rule_targets_publication_type()
Check whether a rewrite query targets a custom publication type.
private
static rewrite_rule_targets_publication_type(string $query, string $publication_query_var) : bool
Parameters
- $query : string
-
The stored rewrite query.
- $publication_query_var : string
-
The publication type's query var.
Tags
Return values
bool —Whether the query targets the publication type.