From 76fe5eb284505dd819ea7d1985342a3eb43ad953 Mon Sep 17 00:00:00 2001 From: Anthony Thorne Date: Tue, 18 Nov 2025 16:41:31 +1000 Subject: [PATCH 1/2] Add filter for custom frontend tracking conditions Add `admin_session_recording_should_load_frontend` filter to enable complex programmatic logic for frontend tracking (runs after UI paths). Useful for conditions based on query params, user meta, or other dynamic factors that can't be configured via the settings UI. --- admin-session-recording.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/admin-session-recording.php b/admin-session-recording.php index af5584d..853bd8a 100644 --- a/admin-session-recording.php +++ b/admin-session-recording.php @@ -314,12 +314,32 @@ public function maybe_add_frontend_tracking_scripts(): void { $current_path = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ), PHP_URL_PATH ); $frontend_paths = $this->options['frontend_paths']; + // First, check UI-configured paths (user-friendly, simple cases). foreach ( $frontend_paths as $path_config ) { if ( $this->path_matches( $current_path, $path_config['path'], $path_config['match_type'] ) ) { $this->output_tracking_scripts( false ); - break; + return; } } + + /** + * Filter to allow custom programmatic logic for enabling frontend tracking scripts. + * + * This filter runs after checking UI-configured paths, allowing for complex + * programmatic conditions that can't be expressed as simple path patterns. + * Examples: query parameters, user meta, custom post types, dynamic conditions. + * + * @param bool $should_load Whether to load tracking scripts for this path (default: false). + * @param string $current_path The current URL path. + * @param array $options The plugin options. + * + * @return bool True to load tracking scripts, false otherwise. + */ + $should_load = apply_filters( 'admin_session_recording_should_load_frontend', false, $current_path, $this->options ); + + if ( $should_load ) { + $this->output_tracking_scripts( false ); + } } /** From 8c33da1c586369cebdb835611816708e655b0e59 Mon Sep 17 00:00:00 2001 From: Anthony Thorne Date: Wed, 19 Nov 2025 14:57:12 +1000 Subject: [PATCH 2/2] Increment version number and add a changelog --- CHANGELOG.md | 15 +++++++++++++++ admin-session-recording.php | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a5ae792 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +## Changelog + +All notable changes to this project will be documented in this file. + +### 0.1.1 - 2025-11-19 + +- Added: Filter `admin_session_recording_should_load_frontend` to allow programmatic enabling of frontend tracking scripts after UI-configured path checks. + +### 0.1.0 - 2025-09-17 + +- Initial plugin release with: + - Admin settings page + - Hotjar and Microsoft Clarity support + - Role-based admin tracking + - Optional frontend tracking with path matching (contains/starts_with/ends_with/regex) diff --git a/admin-session-recording.php b/admin-session-recording.php index 853bd8a..aa2b6ff 100644 --- a/admin-session-recording.php +++ b/admin-session-recording.php @@ -3,7 +3,7 @@ * Plugin Name: Admin Session Recording * Plugin URI: https://github.com/TheCodeCompany/admin-session-recording * Description: Allows Hotjar and Microsoft Clarity to be enabled within the admin area, with front-end being optional. - * Version: 0.1.0 + * Version: 0.1.1 * Author: The Code Company * Author URI: https://thecode.co * License: ISC @@ -20,7 +20,7 @@ } // Define plugin version. -define( 'ADMIN_SESSION_RECORDING_VERSION', '0.1.0' ); +define( 'ADMIN_SESSION_RECORDING_VERSION', '0.1.1' ); /** * Main plugin class. @@ -339,6 +339,7 @@ public function maybe_add_frontend_tracking_scripts(): void { if ( $should_load ) { $this->output_tracking_scripts( false ); + return; } }