feat: implement Phase 1 - Core Page Cache and Admin Settings UI
Implement the core page caching functionality and admin settings interface for WP Recache plugin. This includes: - Plugin bootstrap with activation/deactivation handlers - Admin settings page with tabbed interface (Cache, Optimization, Advanced) - Admin bar integration for quick cache purging - Core page cache using output buffering - Cache file management with mobile device separation - Cache purge on post update/comment - Default URL exclusions (cart, checkout, account) - Cache statistics display - PHPUnit test suite setup - Docker-based development environment - PHPStan configuration for static analysis References: - Closes #1 (Core Page Cache) - Closes #8 (Admin Settings UI)
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin activation handler.
|
||||
*
|
||||
* @package WP_Recache
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class WP_Recache_Activator {
|
||||
|
||||
/**
|
||||
* Run activation routines.
|
||||
*/
|
||||
public static function activate() {
|
||||
self::create_cache_directory();
|
||||
self::set_default_options();
|
||||
self::create_advanced_cache();
|
||||
self::flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create cache directory.
|
||||
*/
|
||||
private static function create_cache_directory() {
|
||||
if (!is_dir(WP_RECACHE_CACHE_PATH)) {
|
||||
wp_mkdir_p(WP_RECACHE_CACHE_PATH);
|
||||
}
|
||||
|
||||
$htaccess = WP_RECACHE_CACHE_PATH . '.htaccess';
|
||||
if (!file_exists($htaccess)) {
|
||||
file_put_contents($htaccess, "Deny from all\n");
|
||||
}
|
||||
|
||||
$index = WP_RECACHE_CACHE_PATH . 'index.php';
|
||||
if (!file_exists($index)) {
|
||||
file_put_contents($index, '<?php // Silence is golden.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default options.
|
||||
*/
|
||||
private static function set_default_options() {
|
||||
$defaults = [
|
||||
'cache_enabled' => true,
|
||||
'separate_mobile_cache' => false,
|
||||
'exclude_urls' => ['/cart', '/checkout', '/my-account'],
|
||||
'minify_css' => false,
|
||||
'minify_js' => false,
|
||||
'lazyload_images' => false,
|
||||
'preload_enabled' => false,
|
||||
];
|
||||
|
||||
foreach ($defaults as $key => $value) {
|
||||
if (get_option("wp_recache_{$key}") === false) {
|
||||
add_option("wp_recache_{$key}", $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create advanced-cache.php drop-in.
|
||||
*/
|
||||
private static function create_advanced_cache() {
|
||||
$advanced_cache = WP_CONTENT_DIR . '/advanced-cache.php';
|
||||
|
||||
if (file_exists($advanced_cache)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = '<?php
|
||||
/**
|
||||
* WP Recache advanced cache.
|
||||
*
|
||||
* This file is automatically generated by WP Recache.
|
||||
* Do not edit this file manually.
|
||||
*/
|
||||
|
||||
defined(\'ABSPATH\') || exit;
|
||||
|
||||
if (file_exists(WP_CONTENT_DIR . \'/wp-recache-cache.php\')) {
|
||||
require_once WP_CONTENT_DIR . \'/wp-recache-cache.php\';
|
||||
}
|
||||
';
|
||||
|
||||
file_put_contents($advanced_cache, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush rewrite rules.
|
||||
*/
|
||||
private static function flush_rewrite_rules() {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user