Skip to content

Commit

Permalink
flip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lezama committed Mar 9, 2018
1 parent 9eeffd8 commit 1dccdce
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions _inc/lib/class.jetpack-user-event-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,38 @@

class Jetpack_User_Event_Tracking {

private static $_memorize_setting = array();
const KEY = 'jetpack_event_tracking_opted_out';
private static $_cache = array();
const KEY = 'jetpack_event_tracking';

static function is_enabled( $user_id ) {
return ! self::is_disabled( $user_id );
}

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

return (bool) $user_tracking;
if ( ! is_numeric( $user_tracking ) ) {
$user_tracking = self::default_value();
}
$default = self::default_value();
self::$_memorize_setting[ $user_id ] = (bool) $default;
self::$_cache[ $user_id ] = (bool) $user_tracking;
return (bool) $user_tracking();
}

return (bool) self::default_value();
static function is_disabled( $user_id ) {
return ! self::is_enabled( $user_id );
}

static function disable( $user_id ) {
// user opted out
self::set( $user_id, 1 );
self::set( $user_id, 0 );
}

static function enable( $user_id ) {
// user opted in
self::set( $user_id, 0 );
self::set( $user_id, 1 );
}

static private function set( $user_id, $value ) {
self::$_memorize_setting[ $user_id ] = (bool) $value;
if ( ! add_user_meta( $user_id, self::KEY, $value, true ) ) {
update_user_meta( $user_id, self::KEY, $value );
}
self::$_cache[ $user_id ] = (bool) $value;
update_user_meta( $user_id, self::KEY, $value );
}

static function default_value() {
Expand All @@ -50,6 +44,6 @@ static function default_value() {
*
* @param bool Default to false. (user tracking enabled)
*/
return apply_filters( 'jetpack_user_event_tracking_opt_out', false );
return apply_filters( 'jetpack_event_tracking', true );
}
}

0 comments on commit 1dccdce

Please sign in to comment.