Telemetry::register_tec_telemetry_plugins( bool|null $opted = null )
Register and opt in/out the plugins that are hooked into tec_telemetry_slugs.
Contents
This keeps all TEC plugins in sync and only requires one optin modal response.
Parameters
- $opted
-
(bool|null) (Optional) Whether to opt in or out. If null, will calculate based on existing status.
Default value: null
Return
(void)
Source
File: src/Common/Telemetry/Telemetry.php
public function register_tec_telemetry_plugins( $opted = NULL ) {
// Let's reduce the amount this triggers.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
global $pagenow;
// Only run on the plugins page, or when we're manually setting an opt-in!
if ( $pagenow !== 'plugins.php' && is_null( $opted ) ) {
return;
}
$tec_slugs = self::get_tec_telemetry_slugs();
// We've got no other plugins?
if ( empty( $tec_slugs ) ) {
return;
}
// Check for cached slugs.
$cached_slugs = tribe( 'cache' )['tec_telemetry_slugs'] ?? null;
// We have already run and the slug list hasn't changed since then. Or we are manually running.
if ( is_null( $opted ) && ! empty( $cached_slugs ) && $cached_slugs == $tec_slugs ) {
return;
}
// No cached slugs, or the list has changed, or we're running manually - so (re)set the cached value.
tribe( 'cache' )['tec_telemetry_slugs'] = $tec_slugs;
// In case we're not specifically passed a status...
$new_opted = $this->calculate_optin_status( $opted );
$status = Config::get_container()->get( Status::class );
foreach ( $tec_slugs as $slug => $path ) {
// Register each plugin with the already instantiated library.
Config::add_stellar_slug( $slug, $path );
$status->add_plugin( $slug, $new_opted, $path );
if ( $new_opted ) {
$status->set_status( $new_opted, $slug );
}
// If we're manually opting in/out, don't show the modal(s).
if ( ! is_null( $opted ) ) {
/*
* If we originally opted out, there will be no registration token,
* so we have to do this to get Telemetry to *register* the site -
* else it will never send updates!
*/
$status = Config::get_container()->get( Status::class );
if ( empty( $status->get_token() ) && ! empty( $opted ) ) {
$opt_in_subscriber = Config::get_container()->get( Opt_In_Subscriber::class );
$opt_in_subscriber->initialize_optin_option();
$this->normalize_optin_status();
}
}
$show_modal = static::calculate_modal_status();
static::disable_modal( $slug, $show_modal );
}
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |