get_route(), '/' ); if ( 0 === strpos( $route, SXANL_REST_NS ) && SXANL_REST_NS . '/geojson' !== $route ) { do_action( 'litespeed_control_set_nocache', 'sentrixa-analytics dynamic API' ); if ( ! headers_sent() ) { nocache_headers(); header( 'X-LiteSpeed-Cache-Control: no-cache' ); } } return $result; } /** * On a version bump, purge the page cache once so no stale API response * (or dashboard HTML) survives the upgrade. */ public function purge_page_cache_on_upgrade() { if ( get_option( 'sxanl_plugin_version' ) === SXANL_VERSION ) { return; } do_action( 'litespeed_purge_all' ); if ( function_exists( 'wp_cache_flush' ) ) { wp_cache_flush(); } update_option( 'sxanl_plugin_version', SXANL_VERSION, false ); } /** * Grant the read capability to administrators + editors, once. */ public function grant_caps_once() { if ( get_option( 'sxanl_caps_granted' ) ) { return; } foreach ( array( 'administrator', 'editor' ) as $role_name ) { $role = get_role( $role_name ); if ( $role ) { $role->add_cap( 'view_sentrixa_analytics' ); } } update_option( 'sxanl_caps_granted', 1, false ); } /** * Enqueue the beacon on the front end (never in admin, feeds, or REST). */ public function enqueue_beacon() { if ( is_admin() || is_feed() || is_preview() ) { return; } if ( ! SXANL_Settings::get( 'tracking_enabled' ) ) { return; } if ( is_user_logged_in() && ! SXANL_Settings::get( 'track_admins' ) && current_user_can( 'edit_posts' ) ) { return; } wp_enqueue_script( 'sentrixa-analytics-beacon', SXANL_URL . 'assets/js/beacon.js', array(), SXANL_VERSION, true ); wp_localize_script( 'sentrixa-analytics-beacon', 'SXANL_BEACON', array( 'hit' => esc_url_raw( rest_url( SXANL_REST_NS . '/hit' ) ), 'engage' => 1, ) ); } /** * No-JS fallback: a 1x1 image whose src is the pixel endpoint. * Wrapped in