From 8f4af2b32c9b9ccef5d9aec1f5bd9811b0a94cba Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 14 Oct 2019 15:28:51 +0200 Subject: [PATCH] Tracks: use filter instead of relying on Jetpack class See https://github.com/Automattic/jetpack/pull/13698#discussion_r334453278 --- class.jetpack.php | 8 +++++++- packages/tracking/src/Tracking.php | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/class.jetpack.php b/class.jetpack.php index 6175a15262e7f..1d6f48317fe05 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -6938,7 +6938,13 @@ public static function get_calypso_env() { * Will return true if a user has clicked to register, or is already connected. */ public static function jetpack_tos_agreed() { - return Jetpack_Options::get_option( 'tos_agreed' ) || self::is_active_and_not_development_mode(); + $tos_agreed = Jetpack_Options::get_option( 'tos_agreed' ) || self::is_active_and_not_development_mode(); + + if ( $tos_agreed ) { + add_filter( 'jetpack_tos_agreed', '__return_true' ); + } + + return $tos_agreed; } /** diff --git a/packages/tracking/src/Tracking.php b/packages/tracking/src/Tracking.php index 7aa14761b8f93..98fc97115eae1 100644 --- a/packages/tracking/src/Tracking.php +++ b/packages/tracking/src/Tracking.php @@ -102,7 +102,16 @@ public function tracks_record_event( $user, $event_name, $properties = array(), } // Don't track users who have opted out or not agreed to our TOS, or are not running an active Jetpack. - if ( ! \Jetpack::jetpack_tos_agreed() ) { + if ( + /** + * Filter whether ToS were accepted on this site. + * + * @since 7.9.0 + * + * @param bool $tos_agreed Was ToS accepted for this site. Defaults to false. + */ + apply_filters( 'jetpack_tos_agreed', false ) + ) { return false; }