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 af5584d..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. @@ -314,12 +314,33 @@ 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 ); + return; + } } /**