Skip to content

Commit

Permalink
Fix static key and only send the new user data if it is set on the us…
Browse files Browse the repository at this point in the history
…er level
  • Loading branch information
enejb committed Mar 9, 2018
1 parent 8632994 commit 445566c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion _inc/lib/class.jetpack-user-event-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Jetpack_User_Event_Tracking {

private static $_cache = array();
private static $KEY = 'jetpack_event_tracking';
public static $KEY = 'jetpack_event_tracking';

static function is_enabled( $user_id ) {
if ( isset( self::$_cache[ $user_id ] ) ) {
Expand All @@ -17,6 +17,15 @@ static function is_enabled( $user_id ) {
return (bool) $user_tracking;
}

static function has_value( $user_id ) {
$user_tracking = get_user_meta( $user_id, self::$KEY, true );
if ( is_numeric( $user_tracking ) ) {
self::$_cache[ $user_id ] = (bool) $user_tracking;
return true;
}
return false;
}

static function is_disabled( $user_id ) {
return ! self::is_enabled( $user_id );
}
Expand Down
7 changes: 4 additions & 3 deletions sync/class.jetpack-sync-module-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function expand_user( $user ) {
}
}
jetpack_require_lib( 'class.jetpack-user-event-tracking' );
$user->jetpack_tracking_enabled = Jetpack_User_Event_Tracking::is_enabled( $user->ID );

if ( Jetpack_User_Event_Tracking::has_value( $user->ID ) ) {
$user->jetpack_tracking_enabled = Jetpack_User_Event_Tracking::is_enabled( $user->ID );
}
return $user;
}

Expand Down Expand Up @@ -289,7 +290,7 @@ function maybe_save_user_meta( $meta_id, $user_id, $meta_key, $value ) {
}

jetpack_require_lib( 'class.jetpack-user-event-tracking' );
if ( $meta_key === Jetpack_User_Event_Tracking::KEY ) {
if ( $meta_key === Jetpack_User_Event_Tracking::$KEY ) {
$this->add_flags( $user_id, array( 'tracking_opt_out_changed' => true ) );
}

Expand Down
1 change: 1 addition & 0 deletions tests/php/sync/test_class.jetpack-sync-callables.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function test_sync_callable_whitelist() {
'site_icon_url' => Jetpack_Sync_Functions::site_icon_url(),
'shortcodes' => Jetpack_Sync_Functions::get_shortcodes(),
'roles' => Jetpack_Sync_Functions::roles(),
'default_user_event_tracking' => Jetpack_Sync_Functions::get_default_user_tracking_value()
);

if ( function_exists( 'wp_cache_is_enabled' ) ) {
Expand Down

0 comments on commit 445566c

Please sign in to comment.