Skip to content

Commit

Permalink
Update code to work with PR #9003 so we save this setting by user
Browse files Browse the repository at this point in the history
  • Loading branch information
eliorivero committed Mar 23, 2018
1 parent f12abe0 commit 1366fea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 4 additions & 4 deletions _inc/client/privacy/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Privacy extends React.Component {
active: false,
};

togglePrivacy = () => this.props.toggleTracking( this.props.getOptionValue( 'disable_tracking' ) );
togglePrivacy = () => this.props.toggleTracking( this.props.getOptionValue( 'jetpack_event_tracking' ) );

render() {
const {
Expand Down Expand Up @@ -85,8 +85,8 @@ class Privacy extends React.Component {
<p>
<ModuleToggle
compact
activated={ getOptionValue( 'disable_tracking' ) }
toggling={ isSavingAnyOption( 'disable_tracking' ) }
activated={ getOptionValue( 'jetpack_event_tracking' ) }
toggling={ isSavingAnyOption( 'jetpack_event_tracking' ) }
toggleModule={ this.togglePrivacy }>
{ __( 'Send usage statistics to help us improve our products.' ) }
</ModuleToggle>
Expand Down Expand Up @@ -116,6 +116,6 @@ export default connect(
settings: getSettings( state ),
} ),
{
toggleTracking: isEnabled => updateSettings( { disable_tracking: ! isEnabled } ),
toggleTracking: isEnabled => updateSettings( { jetpack_event_tracking: ! isEnabled } ),
}
)( moduleSettingsForm( Privacy ) );
4 changes: 2 additions & 2 deletions _inc/lib/class.core-rest-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,8 @@ public static function get_updateable_data_list( $selector = '' ) {
'jp_group' => 'settings',
),

// Show welcome for newly purchased plan
'disable_tracking' => array(
// Whether user allows usage statistics.
'jetpack_event_tracking' => array(
'description' => 'Disables event tracking.',
'type' => 'boolean',
'default' => 0,
Expand Down
13 changes: 12 additions & 1 deletion _inc/lib/core-api/class.jetpack-core-api-module-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ public function get_all_options() {
);
break;

case 'jetpack_event_tracking':
jetpack_require_lib( 'class.jetpack-user-event-tracking' );
$response[ $setting ] = Jetpack_User_Event_Tracking::is_enabled( get_current_user_id() );
break;

default:
$response[ $setting ] = Jetpack_Core_Json_Api_Endpoints::cast_value( get_option( $setting ), $settings[ $setting ] );
break;
Expand Down Expand Up @@ -950,8 +955,14 @@ public function update_data( $request ) {
}
break;

case 'jetpack_event_tracking':
jetpack_require_lib( 'class.jetpack-user-event-tracking' );
$updated = $value
? Jetpack_User_Event_Tracking::enable( get_current_user_id() )
: Jetpack_User_Event_Tracking::disable( get_current_user_id() );
break;

case 'show_welcome_for_new_plan':
case 'disable_tracking':
// If option value was the same, consider it done.
$updated = get_option( $option ) !== $value ? update_option( $option, (bool) $value ) : true;
break;
Expand Down

0 comments on commit 1366fea

Please sign in to comment.