Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand All @@ -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 );
}
}
```

Expand Down