WordPress Performance at Lightning Speed. Advanced optimization with Brotli compression, smart caching, and cat-like speed bursts that dash past the competition. - Brotli and Gzip compression with configurable levels - WP Rocket-inspired smart caching - Bandwidth monitoring - Automatic optimization - Performance status dashboard Includes build.sh and .distignore for WordPress-installable release ZIPs.
536 lines
15 KiB
PHP
536 lines
15 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: TigerStyle Dash
|
|
* Plugin URI: https://tigerstyle.com/plugins/dash
|
|
* Description: WordPress Performance at Lightning Speed. Advanced optimization with Brotli compression, smart caching, and cat-like speed bursts that dash past the competition.
|
|
* Version: 1.0.0
|
|
* Author: TigerStyle Development
|
|
* Author URI: https://tigerstyle.com
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: tigerstyle-dash
|
|
* Domain Path: /languages
|
|
* Requires at least: 5.0
|
|
* Tested up to: 6.8
|
|
* Requires PHP: 7.4
|
|
* Network: false
|
|
*
|
|
* @package TigerStyleDash
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Define plugin constants
|
|
define('TIGERSTYLE_DASH_VERSION', '1.0.0');
|
|
define('TIGERSTYLE_DASH_PATH', plugin_dir_path(__FILE__));
|
|
define('TIGERSTYLE_DASH_URL', plugin_dir_url(__FILE__));
|
|
define('TIGERSTYLE_DASH_BASENAME', plugin_basename(__FILE__));
|
|
define('TIGERSTYLE_DASH_FILE', __FILE__);
|
|
|
|
/**
|
|
* Main TigerStyle Dash Plugin Class
|
|
*
|
|
* Lightning-fast WordPress performance optimization
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
final class TigerStyle_Dash {
|
|
|
|
/**
|
|
* Plugin instance
|
|
*
|
|
* @var TigerStyle_Dash
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Performance engine
|
|
*
|
|
* @var TigerStyle_Dash_Performance
|
|
*/
|
|
private $performance;
|
|
|
|
/**
|
|
* Admin interface
|
|
*
|
|
* @var TigerStyle_Dash_Admin
|
|
*/
|
|
private $admin;
|
|
|
|
/**
|
|
* Cache manager
|
|
*
|
|
* @var TigerStyle_Dash_Cache
|
|
*/
|
|
private $cache;
|
|
|
|
/**
|
|
* Analytics tracker
|
|
*
|
|
* @var TigerStyle_Dash_Analytics
|
|
*/
|
|
private $analytics;
|
|
|
|
/**
|
|
* CDN manager
|
|
*
|
|
* @var TigerStyle_Dash_CDN
|
|
*/
|
|
private $cdn;
|
|
|
|
/**
|
|
* Get plugin instance (Singleton pattern)
|
|
*
|
|
* @return TigerStyle_Dash
|
|
*/
|
|
public static function instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor - Initialize the plugin
|
|
*/
|
|
private function __construct() {
|
|
$this->init_hooks();
|
|
$this->load_dependencies();
|
|
$this->init_components();
|
|
}
|
|
|
|
/**
|
|
* Prevent cloning
|
|
*/
|
|
private function __clone() {}
|
|
|
|
/**
|
|
* Prevent unserialization
|
|
*/
|
|
public function __wakeup() {}
|
|
|
|
/**
|
|
* Initialize WordPress hooks
|
|
*/
|
|
private function init_hooks() {
|
|
// Activation and deactivation hooks
|
|
register_activation_hook(__FILE__, [$this, 'activate']);
|
|
register_deactivation_hook(__FILE__, [$this, 'deactivate']);
|
|
|
|
// Plugin lifecycle hooks
|
|
add_action('plugins_loaded', [$this, 'loaded'], 10);
|
|
add_action('init', [$this, 'init'], 10);
|
|
add_action('wp_loaded', [$this, 'wp_loaded'], 10);
|
|
|
|
// Load text domain for translations
|
|
add_action('plugins_loaded', [$this, 'load_textdomain']);
|
|
|
|
// Admin hooks
|
|
if (is_admin()) {
|
|
add_action('admin_init', [$this, 'init_admin']);
|
|
add_action('admin_menu', [$this, 'add_admin_menu']);
|
|
}
|
|
|
|
// Performance hooks - high priority for early execution
|
|
add_action('template_redirect', [$this, 'init_performance'], 1);
|
|
|
|
// AJAX hooks for admin interface
|
|
add_action('wp_ajax_tigerstyle_dash_analyze', [$this, 'ajax_analyze_performance']);
|
|
add_action('wp_ajax_tigerstyle_dash_clear_cache', [$this, 'ajax_clear_cache']);
|
|
}
|
|
|
|
/**
|
|
* Load plugin dependencies
|
|
*/
|
|
private function load_dependencies() {
|
|
// Core performance classes
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-performance.php';
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-cache.php';
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-compression.php';
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-cdn.php';
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-analytics.php';
|
|
|
|
// Admin classes (only in admin)
|
|
if (is_admin()) {
|
|
require_once TIGERSTYLE_DASH_PATH . 'includes/class-admin.php';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin components
|
|
*/
|
|
private function init_components() {
|
|
// Initialize cache manager first
|
|
$this->cache = new TigerStyle_Dash_Cache();
|
|
|
|
// Initialize performance engine
|
|
$this->performance = TigerStyle_Dash_Performance::instance();
|
|
|
|
// Initialize CDN manager
|
|
$this->cdn = TigerStyle_Dash_CDN::instance();
|
|
|
|
// Initialize analytics
|
|
$this->analytics = new TigerStyle_Dash_Analytics($this);
|
|
|
|
// Initialize admin interface (admin only)
|
|
if (is_admin()) {
|
|
$this->admin = new TigerStyle_Dash_Admin($this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plugin activation hook
|
|
*/
|
|
public function activate() {
|
|
// Check system requirements
|
|
$this->check_requirements();
|
|
|
|
// Create cache directories
|
|
$this->create_cache_directories();
|
|
|
|
// Set default options
|
|
$this->set_default_options();
|
|
|
|
// Schedule cache cleanup
|
|
if (!wp_next_scheduled('tigerstyle_dash_cache_cleanup')) {
|
|
wp_schedule_event(time(), 'daily', 'tigerstyle_dash_cache_cleanup');
|
|
}
|
|
|
|
// Set activation flag
|
|
update_option('tigerstyle_dash_activated', time());
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation hook
|
|
*/
|
|
public function deactivate() {
|
|
// Clear scheduled events
|
|
wp_clear_scheduled_hook('tigerstyle_dash_cache_cleanup');
|
|
wp_clear_scheduled_hook('tigerstyle_dash_cache_warm');
|
|
|
|
// Clear transients
|
|
delete_transient('tigerstyle_dash_performance_stats');
|
|
delete_transient('tigerstyle_dash_cache_analysis');
|
|
}
|
|
|
|
/**
|
|
* Check system requirements
|
|
*/
|
|
private function check_requirements() {
|
|
// Check PHP version
|
|
if (version_compare(PHP_VERSION, '7.4', '<')) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
wp_die(__('TigerStyle Dash requires PHP 7.4 or higher.', 'tigerstyle-dash'));
|
|
}
|
|
|
|
// Check WordPress version
|
|
if (version_compare(get_bloginfo('version'), '5.0', '<')) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
wp_die(__('TigerStyle Dash requires WordPress 5.0 or higher.', 'tigerstyle-dash'));
|
|
}
|
|
|
|
// Check required PHP extensions
|
|
$required_extensions = ['zlib', 'json'];
|
|
foreach ($required_extensions as $extension) {
|
|
if (!extension_loaded($extension)) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
wp_die(sprintf(__('TigerStyle Dash requires the %s PHP extension.', 'tigerstyle-dash'), $extension));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create cache directories
|
|
*/
|
|
private function create_cache_directories() {
|
|
$upload_dir = wp_upload_dir();
|
|
$cache_dir = $upload_dir['basedir'] . '/tigerstyle-dash-cache';
|
|
|
|
if (!file_exists($cache_dir)) {
|
|
wp_mkdir_p($cache_dir);
|
|
|
|
// Create .htaccess for security
|
|
$htaccess_content = "# TigerStyle Dash Cache Security\n";
|
|
$htaccess_content .= "Order Allow,Deny\n";
|
|
$htaccess_content .= "Allow from all\n";
|
|
$htaccess_content .= "<Files ~ \"\\.(php|phtml|php3|php4|php5|pl|py|jsp|asp|sh|cgi)$\">\n";
|
|
$htaccess_content .= " deny from all\n";
|
|
$htaccess_content .= "</Files>\n";
|
|
|
|
file_put_contents($cache_dir . '/.htaccess', $htaccess_content);
|
|
|
|
// Create index.php for additional security
|
|
file_put_contents($cache_dir . '/index.php', '<?php // Silence is golden');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set default plugin options
|
|
*/
|
|
private function set_default_options() {
|
|
$default_options = [
|
|
'tigerstyle_dash_version' => TIGERSTYLE_DASH_VERSION,
|
|
'tigerstyle_dash_compression_enabled' => true,
|
|
'tigerstyle_dash_compression_method' => 'auto',
|
|
'tigerstyle_dash_compression_level' => 6,
|
|
'tigerstyle_dash_cache_enabled' => true,
|
|
'tigerstyle_dash_cache_ttl' => 3600, // 1 hour
|
|
'tigerstyle_dash_analytics_enabled' => true
|
|
];
|
|
|
|
foreach ($default_options as $option_name => $option_value) {
|
|
if (get_option($option_name) === false) {
|
|
add_option($option_name, $option_value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add admin menu
|
|
*/
|
|
public function add_admin_menu() {
|
|
add_menu_page(
|
|
__('TigerStyle Dash', 'tigerstyle-dash'),
|
|
__('Dash Performance', 'tigerstyle-dash'),
|
|
'manage_options',
|
|
'tigerstyle-dash',
|
|
[$this->admin, 'render_main_page'],
|
|
'dashicons-performance',
|
|
30
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Initialize performance engine
|
|
*/
|
|
public function init_performance() {
|
|
if ($this->performance) {
|
|
$this->performance->init_compression();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* AJAX handler for performance analysis
|
|
*/
|
|
public function ajax_analyze_performance() {
|
|
check_ajax_referer('tigerstyle_dash_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Insufficient permissions');
|
|
}
|
|
|
|
$analysis = $this->analytics->analyze_site_performance();
|
|
wp_send_json_success($analysis);
|
|
}
|
|
|
|
/**
|
|
* AJAX handler for cache clearing
|
|
*/
|
|
public function ajax_clear_cache() {
|
|
check_ajax_referer('tigerstyle_dash_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Insufficient permissions');
|
|
}
|
|
|
|
$this->cache->clear_all_cache();
|
|
wp_send_json_success(['message' => __('Cache cleared successfully!', 'tigerstyle-dash')]);
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin after all plugins loaded
|
|
*/
|
|
public function loaded() {
|
|
// Check if we need to run upgrades
|
|
$installed_version = get_option('tigerstyle_dash_version');
|
|
if (version_compare($installed_version, TIGERSTYLE_DASH_VERSION, '<')) {
|
|
$this->upgrade($installed_version);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin on WordPress init
|
|
*/
|
|
public function init() {
|
|
// Initialize any global functionality
|
|
}
|
|
|
|
/**
|
|
* Initialize when WordPress is fully loaded
|
|
*/
|
|
public function wp_loaded() {
|
|
// Initialize components that need WordPress to be fully loaded
|
|
}
|
|
|
|
/**
|
|
* Load plugin text domain for translations
|
|
*/
|
|
public function load_textdomain() {
|
|
load_plugin_textdomain(
|
|
'tigerstyle-dash',
|
|
false,
|
|
dirname(plugin_basename(__FILE__)) . '/languages'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Initialize admin component
|
|
*/
|
|
public function init_admin() {
|
|
if (!$this->admin && current_user_can('manage_options')) {
|
|
$this->admin = new TigerStyle_Dash_Admin($this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle plugin upgrades
|
|
*
|
|
* @param string $installed_version Currently installed version
|
|
*/
|
|
private function upgrade($installed_version) {
|
|
// Run upgrade routines based on version
|
|
if (version_compare($installed_version, '1.0.0', '<')) {
|
|
// Upgrade to 1.0.0
|
|
$this->create_cache_directories();
|
|
}
|
|
|
|
// Update version
|
|
update_option('tigerstyle_dash_version', TIGERSTYLE_DASH_VERSION);
|
|
}
|
|
|
|
/**
|
|
* Get performance engine
|
|
*
|
|
* @return TigerStyle_Dash_Performance
|
|
*/
|
|
public function get_performance() {
|
|
return $this->performance;
|
|
}
|
|
|
|
/**
|
|
* Get cache manager
|
|
*
|
|
* @return TigerStyle_Dash_Cache
|
|
*/
|
|
public function get_cache() {
|
|
return $this->cache;
|
|
}
|
|
|
|
/**
|
|
* Get analytics tracker
|
|
*
|
|
* @return TigerStyle_Dash_Analytics
|
|
*/
|
|
public function get_analytics() {
|
|
return $this->analytics;
|
|
}
|
|
|
|
/**
|
|
* Get CDN manager
|
|
*
|
|
* @return TigerStyle_Dash_CDN
|
|
*/
|
|
public function get_cdn() {
|
|
return $this->cdn;
|
|
}
|
|
|
|
/**
|
|
* Get admin component
|
|
*
|
|
* @return TigerStyle_Dash_Admin|null
|
|
*/
|
|
public function get_admin() {
|
|
return $this->admin;
|
|
}
|
|
|
|
/**
|
|
* Get plugin version
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_version() {
|
|
return TIGERSTYLE_DASH_VERSION;
|
|
}
|
|
|
|
/**
|
|
* Plugin cleanup on uninstall
|
|
*/
|
|
public static function uninstall() {
|
|
// Only run if explicitly uninstalling
|
|
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
|
return;
|
|
}
|
|
|
|
// Remove all plugin data if user chooses to
|
|
$remove_data = get_option('tigerstyle_dash_remove_data_on_uninstall', false);
|
|
|
|
if ($remove_data) {
|
|
// Remove options
|
|
delete_option('tigerstyle_dash_version');
|
|
delete_option('tigerstyle_dash_compression_enabled');
|
|
delete_option('tigerstyle_dash_compression_method');
|
|
delete_option('tigerstyle_dash_compression_level');
|
|
delete_option('tigerstyle_dash_cache_enabled');
|
|
delete_option('tigerstyle_dash_cache_ttl');
|
|
delete_option('tigerstyle_dash_analytics_enabled');
|
|
delete_option('tigerstyle_dash_activated');
|
|
delete_option('tigerstyle_dash_remove_data_on_uninstall');
|
|
|
|
// Remove CDN settings
|
|
delete_option('tigerstyle_dash_cdn_settings');
|
|
delete_option('tigerstyle_dash_cdn_files_served');
|
|
delete_option('tigerstyle_dash_cdn_bandwidth_saved');
|
|
|
|
// Remove cache directory
|
|
$upload_dir = wp_upload_dir();
|
|
$cache_dir = $upload_dir['basedir'] . '/tigerstyle-dash-cache';
|
|
|
|
if (file_exists($cache_dir)) {
|
|
// Recursively delete directory
|
|
$files = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($cache_dir, RecursiveDirectoryIterator::SKIP_DOTS),
|
|
RecursiveIteratorIterator::CHILD_FIRST
|
|
);
|
|
|
|
foreach ($files as $file) {
|
|
if ($file->isDir()) {
|
|
rmdir($file->getRealPath());
|
|
} else {
|
|
unlink($file->getRealPath());
|
|
}
|
|
}
|
|
|
|
rmdir($cache_dir);
|
|
}
|
|
|
|
// Clear scheduled events
|
|
wp_clear_scheduled_hook('tigerstyle_dash_cache_cleanup');
|
|
wp_clear_scheduled_hook('tigerstyle_dash_cache_warm');
|
|
|
|
// Clear transients
|
|
delete_transient('tigerstyle_dash_performance_stats');
|
|
delete_transient('tigerstyle_dash_cache_analysis');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize the plugin
|
|
*
|
|
* @return TigerStyle_Dash
|
|
*/
|
|
function tigerstyle_dash() {
|
|
return TigerStyle_Dash::instance();
|
|
}
|
|
|
|
// Start the plugin
|
|
tigerstyle_dash();
|
|
|
|
/**
|
|
* Plugin cleanup on uninstall
|
|
*/
|
|
register_uninstall_hook(__FILE__, array('TigerStyle_Dash', 'uninstall'));
|