diff --git a/README.md b/README.md index a1c0f0a..42c7509 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ do_action( 'stellarwp/telemetry/optin', '{stellar_slug}', [ 'plugin_slug' => 'th ## Saving Opt-In Status on a Settings Page When implementing the library, settings should be available for site administrators to change their opt-in status at any time. The value passed to `set_status()` should be a boolean. +When a user want's to opt in, call the `Opt_In_Subscriber::opt_in` method instead of `Status::set_status` to ensure that the site is registered with the telemetry server. + ```php add_action( 'admin_init', 'save_opt_in_setting_field' ); @@ -168,11 +170,16 @@ public function save_opt_in_setting_field() { // Get an instance of the Status class. $Status = Config::get_container()->get( Status::class ); + $opt_in = Config::get_container()->get( Opt_In_Subscriber::class ); // Get the value submitted on the settings page as a boolean. $value = filter_input( INPUT_POST, 'opt-in-status', FILTER_VALIDATE_BOOL ); - $Status->set_status( $value ); + if ( $value ) { + $opt_in->opt_in( '{stellar_slug}' ); + } else { + $Status->set_status( $value ); + } } ```