e in tribe_options but since that could get out of sync, * we always display the status from TEC\Common\StellarWP\Telemetry\Opt_In\Status directly. * * @since 6.1.0 * * @param mixed $value The value of the attribute. * @param string $id The field object id. * * @return mixed $value */ public function filter_tribe_field_opt_in_status( $value, $id ) { if ( 'opt-in-status' !== $id ) { return $value; } // Trigger this before we try use the value. tribe( Common_Telemetry::class )->normalize_optin_status(); // We don't care what the value stored in tribe_options is - give us Telemetry's Opt_In\Status value. $status = Config::get_container()->get( Status::class ); $value = $status->get() === $status::STATUS_ACTIVE; return $value; } /** * Adds The Events Calendar to the list of plugins * to be opted in/out alongside tribe-common. * * @since 6.1.0 * * @param array $slugs The default array of slugs in the format [ 'plugin_slug' => 'plugin_path' ] * * @see \TEC\Common\Telemetry\Telemetry::get_tec_telemetry_slugs() * * @return array $slugs The same array with The Events Calendar added to it. */ public function filter_tec_telemetry_slugs( $slugs ) { $dir = TEC::instance()->plugin_dir; $slugs[ static::$plugin_slug ] = $dir . static::$plugin_path; return array_unique( $slugs, SORT_STRING ); } /** * Determines if we are on a TEC admin page except the post edit page. * * @since 6.1.0 * * @return boolean */ public static function is_tec_admin_page(): bool { $current_screen = get_current_screen(); $helper = \Tribe__Admin__Helpers::instance(); // If we are not on a tec post-type admin screen, bail. if ( ! $helper->is_post_type_screen( TEC::POSTTYPE ) ) { return false; } // If we are on a post edit screen, bail. if ( $current_screen instanceof \WP_Screen && tribe_get_request_var( 'action' ) === 'edit' ) { return false; } // If we are on a new post screen, bail. if ( $current_screen instanceof \WP_Screen && $current_screen->action === 'add' ) { return false; } /** * Filter to determine if we are on a TEC admin page. * Allows other classes to hook in and modify the return value. * * @since 6.13.0 * * @param bool $is_tec_admin_page Whether we are on a TEC admin page. */ return (bool) apply_filters( 'tec_telemetry_is_tec_admin_page', true ); } /** * Outputs the hook that renders the Telemetry action on all TEC admin pages. * * @since 6.1.0 * @since 6.8.2 We are bailing on events list page. */ public function inject_modal_link() { if ( ! static::is_tec_admin_page() ) { return; } $current_screen = get_current_screen(); // The save action would perform a POST request against edit.php. So WP would assume we are editing a post throwing an error! if ( isset( $current_screen->id ) && $current_screen->id === 'edit-tribe_events' ) { return; } // Don't double-dip on the action. if ( did_action( 'tec_telemetry_modal' ) ) { return; } // 'the-events-calendar' $telemetry_slug = substr( basename( TRIBE_EVENTS_FILE ), 0, -4 ); $show = tribe( Common_Telemetry::class )->calculate_modal_status(); if ( ! $show ) { return; } /** * Fires to trigger the modal content on admin pages. * * * @since 6.1.0 */ do_action( 'tec_telemetry_modal', $telemetry_slug ); } /** * Update our option and the stellar option when the user opts in/out via the TEC admin. * * @since 6.1.0 * * @param bool $saved_value The option value */ public function save_opt_in_setting_field( $saved_value ): void { $saved_value = tribe_is_truthy( $saved_value ); // Get the currently saved value. $option = tribe_get_option( 'opt-in-status', false ); // Gotta catch them all. tribe( Common_Telemetry::class )->register_tec_telemetry_plugins( $saved_value ); if ( $saved_value && $option !== $saved_value ) { // If changing the value, blow away the expiration datetime so we send updates on next shutdown. delete_option( 'stellarwp_telemetry_last_send' ); $telemetry_data = get_option( 'stellarwp_telemetry' ); if ( empty( $telemetry_data['token'] ) ) { // Force and Opt-in to be done, as we don't have a token yet. $opt_in_subscriber = Config::get_container()->get( Opt_In_Subscriber::class ); $opt_in_subscriber->opt_in( static::$plugin_slug ); } } } }