From 953bd7202a52d99ed2ecd1e7243c09bf1c8cf52d Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Fri, 26 Jan 2024 13:06:25 -0500 Subject: [PATCH] Clarify docs about toggling opt-in status via a Settings page. Fixes #109. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 ); + } } ```