| @@ -20,14 +20,18 @@ | ||
| 20 | 20 | * Hooked to admin_init for proper WordPress lifecycle integration |
| 21 | 21 | * Only loads after WordPress, plugins, and themes are fully loaded |
| 22 | 22 | */ |
| 23 | 23 | function metasync_init_analytics() { |
| 24 | - // Only initialize in admin area (excludes AJAX and REST API requests) | |
| 24 | + // Initialize the consent-gated PostHog dispatcher in every request context | |
| 25 | + // so REST, MCP, cron, and admin events share one central gate. | |
| 26 | + Metasync_PostHog::get_instance(); | |
| 27 | + | |
| 28 | + // GA4's browser integration remains limited to MetaSync admin screens. | |
| 25 | 29 | if (is_admin() && !wp_doing_ajax() && !defined('REST_REQUEST')) { |
| 26 | 30 | Metasync_GA4::get_instance(); |
| 27 | 31 | } |
| 28 | 32 | } |
| 29 | -add_action('admin_init', 'metasync_init_analytics', 10); | |
| 33 | +add_action('init', 'metasync_init_analytics', 1); | |
| 30 | 34 | |
| 31 | 35 | /** |
| 32 | 36 | * Initialize API Backoff System |
| 33 | 37 | * Hooked to init for proper WordPress lifecycle integration |
| @@ -61,8 +65,38 @@ | ||
| 61 | 65 | Metasync_Review_Notice::get_instance(); |
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | add_action('init', 'metasync_init_review_notice'); |
| 69 | + | |
| 70 | +/** | |
| 71 | + * Initialize Analytics Consent Notice | |
| 72 | + * Asks existing installs to opt in to usage analytics; re-shows every | |
| 73 | + * 10 days while consent stays off. | |
| 74 | + */ | |
| 75 | +function metasync_init_analytics_consent_notice() { | |
| 76 | + if (metasync_is_non_metasync_admin_ajax()) { | |
| 77 | + return; | |
| 78 | + } | |
| 79 | + if (is_admin()) { | |
| 80 | + Metasync_Analytics_Consent_Notice::get_instance(); | |
| 81 | + } | |
| 82 | +} | |
| 83 | +add_action('init', 'metasync_init_analytics_consent_notice'); | |
| 84 | + | |
| 85 | +/** | |
| 86 | + * Initialize Host Blocking Check | |
| 87 | + * Owns the shared GET/POST reachability probe, its post-activation + weekly crons, | |
| 88 | + * and the warning notice. Initialised unconditionally (not gated on is_admin) because | |
| 89 | + * the cron callbacks must be registered on WP-Cron requests, where is_admin() is false. | |
| 90 | + * @since 2.8.x | |
| 91 | + */ | |
| 92 | +function metasync_init_host_blocking_check() { | |
| 93 | + if (metasync_is_non_metasync_admin_ajax()) { | |
| 94 | + return; | |
| 95 | + } | |
| 96 | + Metasync_Host_Blocking_Check::get_instance(); | |
| 97 | +} | |
| 98 | +add_action('plugins_loaded', 'metasync_init_host_blocking_check'); | |
| 65 | 99 | |
| 66 | 100 | /** |
| 67 | 101 | * Global convenience function to get active JWT token |
| 68 | 102 | * Can be called from anywhere in WordPress (themes, other plugins, etc.) |