diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7f1e6..51d93ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `WP 404 Caching` will be documented in this file. +## 1.0.2 + +- Fixed issue with Feature_Manager setup +- Added `wp_404_caching_enabled` filter to allow disabling the cache + ## 1.0.1 - Initial release diff --git a/README.md b/README.md index 7f2dd0f..145819e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A WordPress plugin to provide full page caching for 404 pages, improving perform - **Contributors**: alleyinteractive - **Tags**: alleyinteractive, wp-404-caching -- **Stable tag**: 1.0.1 +- **Stable tag**: 1.0.2 ## Requirements - SSL enabled on the website. @@ -58,6 +58,9 @@ add_filter( 'wp_404_caching_cache_time', function( $cache_time ) { add_filter( 'wp_404_caching_stale_cache_time', function( $stale_cache_time ) { return 2 * DAY_IN_SECONDS; // Set stale cache time to 2 days. } ); + +// Programmatically bypass the cache. +add_filter( 'wp_404_caching_enabled', '__return_false' ); ``` ## Changelog diff --git a/src/class-wp-404-caching.php b/src/class-wp-404-caching.php deleted file mode 100644 index 9a94163..0000000 --- a/src/class-wp-404-caching.php +++ /dev/null @@ -1,25 +0,0 @@ - [], - ] - ); - } -} diff --git a/src/features/class-full-page-cache-404.php b/src/features/class-full-page-cache-404.php index 8af28ca..93ee09c 100644 --- a/src/features/class-full-page-cache-404.php +++ b/src/features/class-full-page-cache-404.php @@ -101,6 +101,10 @@ public function boot(): void { return; } + if ( ! apply_filters( 'wp_404_caching_enabled', true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + return; + } + // Return 404 page cache on template_redirect. add_action( 'template_redirect', [ self::class, 'action__template_redirect' ], 1 ); diff --git a/wp-404-caching.php b/wp-404-caching.php index a0b3940..4e5dabf 100644 --- a/wp-404-caching.php +++ b/wp-404-caching.php @@ -3,7 +3,7 @@ * Plugin Name: WP 404 Caching * Plugin URI: https://github.com/alleyinteractive/wp-404-caching * Description: Full Page Cache for WordPress 404s - * Version: 1.0.1 + * Version: 1.0.2 * Author: Alley * Author URI: https://github.com/alleyinteractive/wp-404-caching * Requires at least: 6.3 @@ -17,6 +17,9 @@ namespace Alley\WP\WP_404_Caching; +use Composer\InstalledVersions; +use function add_action; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -32,8 +35,8 @@ // to see if the Composer dependencies have been installed in a parent // folder. This is useful for when the plugin is loaded as a Composer // dependency in a larger project. - if ( ! class_exists( \Composer\InstalledVersions::class ) ) { - \add_action( + if ( ! class_exists( InstalledVersions::class ) ) { + add_action( 'admin_notices', function () { ?> @@ -61,7 +64,7 @@ function () { function main(): void { // This should be an array with keys set to feature classnames and arguments. $features = [ - // Add initial features here. + 'Alley\WP\WP_404_Caching\Features\Full_Page_Cache_404' => [], ]; $features = apply_filters( 'wp_404_caching_features', $features ); Feature_Manager::add_features( $features );