'wordpress-plugin', 'utm_medium' => 'plugin', 'utm_campaign' => $campaign, ], $url); } define('ADVOCATE_LOOP_WOO_MIN_EXT_API', 1); /** * Autoloader scoped to this add-on's namespace subtree. Stacks with core's * autoloader; declines anything outside AdvocateLoop\WooCommerce\. */ spl_autoload_register(function ($class) { $prefix = 'AdvocateLoop\\WooCommerce\\'; $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { return; } $relative = substr($class, $len); $file = ADVOCATE_LOOP_WOO_DIR . 'includes/WooCommerce/' . str_replace('\\', '/', $relative) . '.php'; if (file_exists($file)) { require $file; } }); /** * Safe accessor for this add-on's settings section in the AdvocateLoop core. */ function advocate_loop_woo_settings(): array { if (!function_exists('advocate_loop_get_settings')) { return []; } try { $settings = advocate_loop_get_settings('woocommerce'); return is_array($settings) ? $settings : []; } catch (\Throwable $e) { // Defensive breadcrumb only — never breaks the site, just records why // defaults were used. Gated on WP_DEBUG so nothing is written in normal // production environments. if (defined('WP_DEBUG') && WP_DEBUG) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- debug-only diagnostic, guarded by WP_DEBUG. error_log('AdvocateLoop for WooCommerce: settings read failed (' . $e->getMessage() . '); using defaults.'); } return []; } } function advocate_loop_woo_core_compatible(): bool { return function_exists('advocate_loop_get_settings') && defined('ADVOCATE_LOOP_EXT_API') && ADVOCATE_LOOP_EXT_API >= ADVOCATE_LOOP_WOO_MIN_EXT_API; } /** * Register the WooCommerce tab and platform provider into the core registry. */ add_action('advocate_loop_register_extensions', function () { if (!advocate_loop_woo_core_compatible()) { return; } \AdvocateLoop\Admin\Extensions::register_tab([ 'id' => 'woocommerce', 'label' => __('WooCommerce', 'advocateloop-for-woocommerce'), 'priority' => 20, 'icon' => '', 'render' => function () { include ADVOCATE_LOOP_WOO_DIR . 'includes/views/tab-woocommerce.php'; }, ]); // Upgrade tracking to the 'woocommerce' platform when WooCommerce is // active and the integration has not been disabled in settings. \AdvocateLoop\Admin\Extensions::register_platform('woocommerce', function () { if (!class_exists('WooCommerce')) { return false; } $woo = advocate_loop_woo_settings(); return !(isset($woo['enabled']) && !$woo['enabled']); }, 20); }); /** * Boot the integration. Runs after core's default-priority plugins_loaded * handler (advocate_loop_init at priority 10) so the core helpers, registry, * and ADVOCATE_LOOP_EXT_API constant are all defined. */ add_action('plugins_loaded', function () { if (!advocate_loop_woo_core_compatible()) { add_action('admin_notices', function () { if (!current_user_can('activate_plugins')) { return; } echo '
'; echo esc_html__('AdvocateLoop for WooCommerce needs the AdvocateLoop plugin (a compatible version) to be installed and active. Please install or update AdvocateLoop.', 'advocateloop-for-woocommerce'); echo '