uld_load Whether the class should load/run. */ return apply_filters( 'tec_telemetry_migration_should_load', true ); } /** * Detect if the user has opted in to Freemius and auto-opt them in to Telemetry. * * @since 5.1.0 */ public function migrate_existing_opt_in(): void { // Let's reduce the amount this triggers. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( ! $this->should_load() ) { return; } $fs_active_plugins = get_option( self::$key_fs_active_plugins ); // Clean up our list. $this->remove_inactive_plugins( $fs_active_plugins ); // Bail if none of our plugins are present. if ( ! count( $this->our_plugins ) ) { return; } $this->auto_opt_in(); // Remove us from fs_active_plugins. $this->handle_fs_active_plugins( $fs_active_plugins ); } /** * Filters our list of plugins to only the ones Freemius shows as active * * @since 5.1.0 * * @param Object $fs_active_plugins The stored list of active plugins from Freemius. */ private function remove_inactive_plugins( $fs_active_plugins ): void { $freemius_plugins = ! empty( $fs_active_plugins->plugins ) ? (array) $fs_active_plugins->plugins : []; foreach ( $this->our_plugins as $plugin ) { if ( ! isset( $freemius_plugins[ $plugin ] ) ) { unset( $this->our_plugins[ $plugin ] ); } } } /** * Handles our entries in the fs_active_plugins option. * Removes them from the Freemius option and stores a backup of the original. * * @since 5.1.0 * * @param Object $fs_active_plugins * @return void */ private function handle_fs_active_plugins( $fs_active_plugins ): void { // Store a backup of the original option. update_option( self::$fs_plugins_slug, $fs_active_plugins ); foreach ( $this->our_plugins as $plugin ) { $plugin .= '/common/vendor/freemius'; unset( $fs_active_plugins->plugins[ $plugin ] ); if ( ! empty( $fs_active_plugins->newest->sdk_path ) && $fs_active_plugins->newest->sdk_path === $plugin ) { unset( $fs_active_plugins->newest ); } } // Update the Freemius option in the database with our edits. update_option( self::$key_fs_active_plugins, $fs_active_plugins ); } /** * Opts the user in to Telemetry. * * @since 5.1.0 * */ public function auto_opt_in() { $opt_in = $this->is_opted_in(); $opt_in_subscriber = Config::get_container()->get( Opt_In_Subscriber::class ); $telemetry = tribe( Telemetry::class ); $slug = Telemetry::get_stellar_slug(); $opt_in_subscriber->opt_in( $slug ); $telemetry->register_tec_telemetry_plugins( $opt_in ); /** * Allows plugins to hook in and perform actions (like display a notice) when * the user is automatically opted in to Telemetry. * * We also use this to trigger the actual auto-opt-in at the default priority. * * @since 5.1.0 */ do_action( 'tec_telemetry_auto_opt_in' ); // Disable the modal on all migrations. $telemetry::disable_modal( $slug, 0 ); } }