load_dependencies(); $this->init_components(); } /** * Load required plugin files. */ private function load_dependencies() { require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-settings.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-rollback.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-exclusions.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-environment.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-diagnostics.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-bloat.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-images.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-assets.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-cache.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-database.php'; require_once AWVB_PLUGIN_DIR . 'includes/class-awvb-optimizer.php'; // Integrations require_once AWVB_PLUGIN_DIR . 'integrations/class-awvb-woocommerce.php'; require_once AWVB_PLUGIN_DIR . 'integrations/class-awvb-elementor.php'; require_once AWVB_PLUGIN_DIR . 'integrations/class-awvb-cache-plugins.php'; // Admin if ( is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { require_once AWVB_PLUGIN_DIR . 'admin/class-awvb-admin.php'; } } /** * Instantiate modules and register hooks. */ private function init_components() { $this->settings = new AWVB_Settings(); $this->rollback = new AWVB_Rollback( $this->settings ); $this->exclusions = new AWVB_Exclusions( $this->settings ); // Register settings hooks. $this->add_action( 'admin_init', $this->settings, 'register_settings' ); // Check for Emergency Safe Mode bypass parameter (?awvb_safe_mode=1) $this->add_action( 'init', $this->rollback, 'check_emergency_bypass' ); // Integrations new AWVB_WooCommerce( $this->exclusions ); new AWVB_Elementor( $this->exclusions ); new AWVB_Cache_Plugins(); // Admin hooks if ( is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { $this->admin = new AWVB_Admin( $this->settings, $this->rollback ); $this->add_action( 'admin_menu', $this->admin, 'add_admin_menu' ); $this->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_admin_assets' ); $this->add_action( 'admin_bar_menu', $this->admin, 'add_admin_bar_node', 100 ); // AJAX actions (prefixed awvb_) $this->add_action( 'wp_ajax_awvb_save_settings', $this->admin, 'ajax_save_settings' ); $this->add_action( 'wp_ajax_awvb_apply_preset', $this->admin, 'ajax_apply_preset' ); $this->add_action( 'wp_ajax_awvb_restore_backup', $this->admin, 'ajax_restore_backup' ); $this->add_action( 'wp_ajax_awvb_clean_transients', $this->admin, 'ajax_clean_transients' ); $this->add_action( 'wp_ajax_awvb_purge_cache', $this->admin, 'ajax_purge_cache' ); } // Public & Frontend Optimizations $this->optimizer = new AWVB_Optimizer( $this->settings, $this->exclusions ); $this->optimizer->init( $this ); } /** * Add a new action to the collection. * * @param string $hook WordPress action hook. * @param object $component Target object. * @param string $callback Target callback function name. * @param int $priority Optional. Priority. Default 10. * @param int $accepted_args Optional. Accepted args. Default 1. */ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->actions[] = array( 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ); } /** * Add a new filter to the collection. * * @param string $hook WordPress filter hook. * @param object $component Target object. * @param string $callback Target callback function name. * @param int $priority Optional. Priority. Default 10. * @param int $accepted_args Optional. Accepted args. Default 1. */ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->filters[] = array( 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ); } /** * Execute all hooks with WordPress. */ public function run() { foreach ( $this->filters as $hook ) { add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); } foreach ( $this->actions as $hook ) { add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); } } }