ensure( 'stats' ); add_action( 'plugins_loaded', array( static::class, 'activate_stats_module_if_connected' ) ); } } /** * Make Stats available to the module controller when Jetpack is not installed. * * @param array $modules Available standalone module slugs. * @return array */ public static function add_stats_module( $modules ) { $modules[] = 'stats'; return array_values( array_unique( $modules ) ); } /** * Activate Stats for a connected standalone Premium Analytics site. * * @return void */ public static function activate_stats_module_if_connected() { if ( ( new Connection_Manager() )->is_connected() ) { self::activate_stats_module(); } } /** * Activate Stats in standalone mode without redirecting or ending the request. * * @return void */ public static function activate_stats_module() { // When Jetpack is active, respect its Stats module setting. if ( static::is_jetpack_plugin_active() ) { return; } ( new Modules() )->activate( 'stats', false, false ); } /** * Whether the Jetpack plugin is active and owns the Stats module setting. * * @return bool */ protected static function is_jetpack_plugin_active() { return class_exists( 'Jetpack' ); } }