register_integrations(); // Load active integrations immediately since we're already at init priority 20 // The init hook at priority 15 would have already fired $this->load_active_integrations_once(); } /** * Register all available integrations. * * @since 1.0.0 */ protected function register_integrations() { // Check if premium is enabled $is_premium_enabled = ACTLOGPRO_Premium_Helper::is_premium_enabled(); // Note: WooCommerce and Yoast integrations are now premium-only features // They are registered by the premium plugin via the actlogpro_register_integrations hook // Allow other integrations to be registered (including from premium plugins) // Premium plugins can override the registrations above do_action('actlogpro_register_integrations', $this); } /** * Register an integration. * * @since 1.0.0 * @param string $id The integration ID. * @param string $class_name The integration class name. * @param string $file_name The integration file name. */ public function register_integration($id, $class_name, $file_name) { $this->integrations[$id] = array( 'class_name' => $class_name, 'file_name' => $file_name ); } /** * Load all active integrations. * * @since 1.0.0 */ protected function load_active_integrations() { // Make sure plugin.php is loaded for is_plugin_active function if (!function_exists('is_plugin_active')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } // Get active integrations from options $active_integrations = get_option('actlogpro_active_integrations', array()); $updated_active_integrations = array(); $integrations_changed = false; // Check if premium is enabled $is_premium_enabled = ACTLOGPRO_Premium_Helper::is_premium_enabled(); // Note: Premium integrations (WooCommerce, Yoast) are now auto-activated // by the premium plugin itself, not by the free plugin // Loop through registered integrations foreach ($this->integrations as $id => $integration) { // Check if integration is active in options if (!in_array($id, $active_integrations)) { continue; } // Check for integration in its own directory first $file_path = ACTLOGPRO_PLUGIN_DIR . 'integrations/' . $id . '/' . 'class-alp-' . $id . '-integration.php'; // If not found, check if the file_name is an absolute path or relative if (!file_exists($file_path)) { if (strpos($integration['file_name'], '/') !== false && file_exists($integration['file_name'])) { // It's an absolute path (from premium plugin) $file_path = $integration['file_name']; } else { // It's a relative path, use main integrations directory $file_path = ACTLOGPRO_PLUGIN_DIR . 'integrations/' . $integration['file_name']; } } // Load the integration file if it exists if (file_exists($file_path)) { require_once $file_path; // Initialize the integration $class_name = $integration['class_name']; if (class_exists($class_name)) { // Pass true since this integration is marked as active and we're loading it new $class_name(true); $updated_active_integrations[] = $id; } } else { // Integration file doesn't exist, so it shouldn't be active $integrations_changed = true; } } // Update active integrations if any were changed if ($integrations_changed) { update_option('actlogpro_active_integrations', $active_integrations); } } /** * Load active integrations only once to prevent duplicates. * * @since 1.0.0 */ public function load_active_integrations_once() { static $loaded = false; if ($loaded) { return; } $this->load_active_integrations(); $loaded = true; } /** * Get all registered integrations. * * @since 1.0.0 * @return array The array of registered integrations. */ public function get_integrations() { $integration_objects = array(); $active_integrations = get_option('actlogpro_active_integrations', array()); // Loop through registered integrations foreach ($this->integrations as $id => $integration) { // Load the integration file if not already loaded $file_path = ACTLOGPRO_PLUGIN_DIR . 'integrations/' . $integration['file_name']; if (file_exists($file_path) && !class_exists($integration['class_name'])) { require_once $file_path; } // Initialize the integration object for info purposes only (no hook registration) $class_name = $integration['class_name']; if (class_exists($class_name)) { // Check if this integration is marked as active in settings $is_marked_active = in_array($id, $active_integrations); // Create instance for info display purposes only - no hooks $integration_objects[$id] = new $class_name(false); // Manually set the marked active status for display purposes $reflection = new ReflectionClass($integration_objects[$id]); $property = $reflection->getProperty('is_marked_active'); $property->setAccessible(true); $property->setValue($integration_objects[$id], $is_marked_active); } } return $integration_objects; } /** * Get all available integrations with their status. * * @since 1.0.0 * @return array The array of available integrations with their status. */ public function get_available_integrations() { $available_integrations = array(); $integrations = $this->get_integrations(); foreach ($integrations as $id => $integration) { $available_integrations[$id] = array( 'id' => $integration->get_id(), 'name' => $integration->get_name(), 'description' => $integration->get_description(), 'is_active' => $integration->is_active(), 'plugin_dependency' => $integration->get_plugin_dependency() ); } return $available_integrations; } }