includes/Edge/class-htaccess-handler.php
Htaccess_Handler class for the PerformanceOptimise plugin.
Class Htaccess_Handler
Class Htaccess_Handler
class Htaccess_HandlerConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
MARKER | private | \'wppo_rules\' | 33 |
MAX_RULE_LINE_LENGTH | private | 4096 | 44 |
FAILURE_TRANSIENT | private | \'wppo_htaccess_failure\' | 60 |
publicstatic update_rules()
public static function update_rules(bool=true $enable): boolUpdates the .htaccess rules based on plugin settings. Parameter Type Default Description $enablebool=true— Whether to enable or disable the rules.
Return: bool — True on success, false on failure.
publicstatic get_htaccess_path()
public static function get_htaccess_path(): stringResolve the absolute path to the site .htaccess file.
Return: string — Absolute .htaccess path, or empty string when unresolvable.
publicstatic has_rules()
public static function has_rules(): boolWhether the wppo_rules marker block is present in .htaccess.
Return: bool — True when the marker block exists.
publicstatic remove_rules()
public static function remove_rules(): boolRemove the wppo_rules marker block and clean backup artifacts.
Return: bool — True when no marker remains (or nothing to remove).
publicstatic cleanup_backup_artifacts()
public static function cleanup_backup_artifacts(): voidDelete the .htaccess backup sibling and orphaned tmp siblings.
Return: void.
publicstatic supports_htaccess()
public static function supports_htaccess(): boolWhether `.htaccess` writes are meaningful on this server.
Return: bool — True when an `.htaccess` write may proceed.
publicstatic get_failure_transient_key()
public static function get_failure_transient_key(): stringBlog-aware transient key for the persistent .htaccess failure flag.
Return: string — Transient key (blog-prefixed on multisite).
publicstatic has_htaccess_failure()
public static function has_htaccess_failure(): boolWhether a failed .htaccess write still needs attention.
Return: bool — True when a previous write failed and no success cleared it.
publicstatic flag_htaccess_failure()
public static function flag_htaccess_failure(): voidPersist the .htaccess failure flag so the notice survives page loads.
Return: void.
publicstatic clear_htaccess_failure()
public static function clear_htaccess_failure(): voidClear the persistent .htaccess failure flag after a verified write.
Return: void.
privatestatic sanitize_rules()
private static function sanitize_rules(array $rules): array|falseSanitize rule lines before an `.htaccess` write. Parameter Type Default Description $rulesarray— Raw rules lines.
Return: array|false — The rules unchanged when valid, false when rejected.
privatestatic normalize_rules()
private static function normalize_rules(array $rules): arrayNormalize a rules array for identical-content comparison. Parameter Type Default Description $rulesarray— Raw rules lines.
Return: array — Normalized rules lines.
privatestatic build_marker_block()
private static function build_marker_block(array $rules): stringSerialize a rules array into a full marker block. Parameter Type Default Description $rulesarray— Rules lines.
Return: string — Marker block, or empty string when there are no rules.
privatestatic splice_block()
private static function splice_block(string $current, string $new_block): stringSplice a marker block into full .htaccess contents. Parameter Type Default Description $currentstring— Current .htaccess contents. $new_blockstring— New marker block (empty string to remove).
Return: string — Updated .htaccess contents.
privatestatic verify_htaccess_contents()
private static function verify_htaccess_contents(string $contents, bool $expect_block): boolVerify .htaccess contents after a write. Parameter Type Default Description $contentsstring— Full .htaccess contents. $expect_blockbool— Whether a wppo block is expected.
Return: bool — True when valid.
privatestatic verify_after_write()
private static function verify_after_write(string $htaccess_file, $wp_filesystem, bool $expect_block): boolRe-read .htaccess and verify it after a legacy write. Parameter Type Default Description $htaccess_filestring— Absolute path to the .htaccess file. $wp_filesystemmixed— WP_Filesystem instance. $expect_blockbool— Whether a wppo block is expected.
Return: bool — True when valid or unverifiable.
privatestatic is_htaccess_write_allowed()
private static function is_htaccess_write_allowed(string $htaccess_file): boolWhether an .htaccess target may be written by the plugin. Parameter Type Default Description $htaccess_filestring— Absolute .htaccess path candidate.
Return: bool — True when the target may be written.
privatestatic atomic_write_verified()
private static function atomic_write_verified(string $htaccess_file, $wp_filesystem, array $rules): ?boolAtomically write .htaccess via temp file + rename with verification. Parameter Type Default Description $htaccess_filestring— Absolute path to the .htaccess file. $wp_filesystemmixed— WP_Filesystem instance. $rulesarray— Desired rules lines.
Return: bool|null — True on success, false on verified failure, null when atomic write is unsupported.
privatestatic read_existing_rules()
private static function read_existing_rules(string $htaccess_file, $wp_filesystem): ?arrayRead the existing wppo_rules block as a backup. Parameter Type Default Description $htaccess_filestring— Absolute path to the .htaccess file. $wp_filesystemmixed— WP_Filesystem instance.
Return: array|null — Existing rules, or null when unavailable.
publicstatic get_rules()
public static function get_rules(): arrayRetrieve the rules to be added to .htaccess.
Return: array — Array of rules.
Hooks
Hooks referenced in includes/Edge/class-htaccess-handler.php: Hook Type Line Notes wppo_litespeed_nextgen_rewritefilter 1159 @param ×1 wppo_litespeed_nextgen_rewritefilter 1176 @param ×1 wppo_htaccess_nextgen_rulesfilter 1228 @param ×1 wppo_htaccess_cache_vary_rulesfilter 1293 @param ×1 wppo_htaccess_rulesfilter 1316 @param ×1