opticore/includes/class-activator.php
Ahmadreza b30ae5d70e ♻️ refactor: Complete code restructuring - Clean architecture implementation
Massive refactoring to improve code organization, maintainability,
and follow SOLID principles. Main plugin file reduced by 80%!

🏗️ New Architecture:
Created 4 new specialized classes following Single Responsibility Principle:

1️⃣ class-admin.php (118 lines)
   - Admin menu management
   - Settings registration
   - Admin scripts/styles enqueuing
   - Settings link on plugins page

2️⃣ class-ajax-handler.php (105 lines)
   - Clear cache AJAX
   - Optimize database AJAX
   - Export settings AJAX
   - Create cache directory AJAX

3️⃣ class-frontend-optimizer.php (237 lines)
   - Disable Emojis (complete)
   - Disable Dashicons (complete)
   - Disable Embeds (complete)
   - Remove Query Strings
   - Enable GZIP Compression

4️⃣ class-activator.php (68 lines)
   - Plugin activation logic
   - Plugin deactivation logic
   - Default settings setup
   - Cache directory creation

📊 Impact:
- opticore.php: 583 → 160 lines (-423 lines, -73%)
- Better separation of concerns
- Easier to maintain and test
- Each class has single responsibility
- Cleaner code organization

🎯 Main Plugin File Now:
- Only orchestration/initialization
- Loads dependencies
- Initializes components
- Delegates to specialized classes

 Benefits:
-  SOLID principles applied
-  Single Responsibility Principle
-  Better code organization
-  Easier to test
-  Easier to extend
-  More maintainable
-  Professional structure

All functionality remains identical - this is pure refactoring
with no changes to features or behavior.
2025-11-01 15:52:41 +03:30

73 lines
1.8 KiB
PHP

<?php
/**
* Activator
* Handles plugin activation and deactivation
*
* @package OptiCore
*/
if (!defined('ABSPATH')) {
exit;
}
class OptiCore_Activator {
/**
* Activate plugin
*/
public static function activate() {
// Set default options
$default_options = array(
'enable_cache' => true,
'enable_minify_css' => true,
'enable_minify_js' => true,
'enable_lazy_load' => true,
'enable_image_optimization' => true,
'enable_database_optimization' => false,
'enable_gzip_compression' => true,
'remove_query_strings' => true,
'disable_emojis' => true,
'disable_embeds' => true,
);
add_option('opticore_settings', $default_options);
// Create cache directory
$cache_dir = WP_CONTENT_DIR . '/cache/opticore';
if (!file_exists($cache_dir)) {
wp_mkdir_p($cache_dir);
}
// Schedule database optimization
if (!wp_next_scheduled('opticore_database_optimization')) {
wp_schedule_event(time(), 'weekly', 'opticore_database_optimization');
}
}
/**
* Deactivate plugin
*/
public static function deactivate() {
// Clear scheduled events
wp_clear_scheduled_hook('opticore_database_optimization');
// Clear cache
self::clear_cache();
}
/**
* Clear cache
*/
private static function clear_cache() {
$cache_dir = WP_CONTENT_DIR . '/cache/opticore';
if (file_exists($cache_dir)) {
$files = glob($cache_dir . '/*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
}
}