diff --git a/package.json b/package.json index 12e8dc17ac..83b97dfadd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tribe-common", - "version": "5.2.4", + "version": "6.6.6", "repository": "git@github.com:the-events-calendar/tribe-common.git", "_resourcepath": "src/resources", "_domainPath": "lang", diff --git a/src/Common/Telemetry/Provider.php b/src/Common/Telemetry/Provider.php index 70cee9cb6d..ce03f2efdd 100644 --- a/src/Common/Telemetry/Provider.php +++ b/src/Common/Telemetry/Provider.php @@ -66,6 +66,10 @@ public function add_filters() { add_filter( 'stellarwp/telemetry/event-tickets/optin_args', [ $this, 'filter_et_optin_args' ], 10 ); add_filter( 'stellarwp/telemetry/exit_interview_args', [ $this, 'filter_exit_interview_args' ] ); add_filter( 'http_request_args', [ $this, 'filter_telemetry_http_request_args' ], 10, 2 ); + + /* Prefixed filters - should be 'tec' but best to grab it to be sure. */ + $prefix = Telemetry::get_hook_prefix(); + add_filter( "stellarwp/telemetry/{$prefix}/send_data_args", [ $this, 'filter_data_args' ] ); } /** @@ -245,4 +249,8 @@ public function filter_exit_interview_args( $args ) { public function maybe_enqueue_admin_modal_assets(): void { $this->container->make( Asset_Subscriber::class )->maybe_enqueue_admin_assets(); } + + public function filter_data_args( $args ) { + return $this->container->make( Telemetry::class )->filter_data_args( $args ); + } } diff --git a/src/Common/Telemetry/Telemetry.php b/src/Common/Telemetry/Telemetry.php index 14cf6a6a1d..0227700a4f 100644 --- a/src/Common/Telemetry/Telemetry.php +++ b/src/Common/Telemetry/Telemetry.php @@ -191,6 +191,17 @@ public static function clean_up(): void { } } + /** + * Get the hook prefix we are using. + * + * @since TBD + * + * @return string The hook prefix. Note there is no trailing slash! + */ + public static function get_hook_prefix(): string { + return self::$hook_prefix; + } + /** * Get the slug of the plugin. * @@ -457,7 +468,10 @@ public static function get_tec_telemetry_slugs() { * * @param array $slugs An array of plugins in the format ['plugin_slug' => 'plugin_path'] */ - return apply_filters( 'tec_telemetry_slugs', [] ); + $slugs = apply_filters( 'tec_telemetry_slugs', [] ); + + // Remove any potential duplicates. + return array_unique( $slugs, SORT_STRING ); } /** @@ -651,4 +665,108 @@ public static function disable_modal( $slug, $enable = false ) { $option_slug = Config::get_container()->get( Opt_In_Template::class )->get_option_name( $slug ); update_option( $option_slug, $enable ); } + + /** + * Filters the data arguments for TEC plugins. + * + * @since TBD + * + * @param array $args The array of data arguments to filter. + * + * @return array $args The array of filtered data arguments. + */ + public function filter_data_args( $args ): array { + // We only want to mess with the data block. + $telemetry = json_decode( $args['telemetry'], true ); + + $changed = $this->add_licenses( $telemetry ); + + if ( tribe_is_truthy( $changed ) ) { + $args['telemetry'] = wp_json_encode( $telemetry ); + } + + /** + * Allows overriding the data arguments for TEC plugins. + * + * @since TBD + * + * @param array $args The data arguments to filter. + * + * @return array $args The filtered data arguments. + */ + return apply_filters( 'tec_telemetry_data_arguments', $args ); + } + + /** + * Add premium plugin licenses to the telemetry data. + * + * @since TBD + * + * @param object $telemetry_by_reference The telemetry data object. + * + * @return bool If the data has changed. + */ + protected function add_licenses( &$telemetry_by_reference ): bool { + // No data sent, bail safely. + if ( empty( $telemetry_by_reference ) ) { + return false; + } + + $telemetry = $telemetry_by_reference; + // We don't need the path info for this. + $tec_slugs = array_keys( self::get_tec_telemetry_slugs() ); + // Remove parent slugs - they don't have licenses. + $tec_slugs = array_diff( $tec_slugs, self::$base_parent_slugs ); + // Nothing to add, bail safely. + if ( empty( $tec_slugs ) ) { + return false; + } + + if ( ! isset( $telemetry['stellar_licenses'] ) ) { + // Set up if it doesn't exist. + $telemetry['stellar_licenses'] = []; + } elseif ( ! is_array( $telemetry['stellar_licenses'] ) ) { + // Make sure it's an array if it does exist. + $telemetry['stellar_licenses'] = (array) $telemetry['stellar_licenses']; + } + // Grab all the options, cached. + $options = wp_load_alloptions(); + // Filter out everything but our license keys. + $options = array_filter( + $options, + static function ( $key ) { + return str_starts_with( $key, 'pue_install_key_' ); + }, + ARRAY_FILTER_USE_KEY + ); + + // No keys found. + if ( empty( $options ) ) { + return false; + } + + foreach ( $options as $slug => $key ) { + $slug = str_replace( 'pue_install_key_', '', $slug ); + $slug = str_replace( '-', '_', $slug ); + /** + * Filter the license slug. + * This allows for some plugins that use older nomenclature (like Filter Bar) to add a more "modern" slug. + * + * @since TBD + * + * @param string $slug The stored license slug. + */ + $slug = apply_filters( 'tec_telemetry_license_slug_' . $slug, $slug ); + $telemetry['stellar_licenses'][ $slug ] = $key; + } + + if ( ! empty( $telemetry['stellar_licenses'] ) ) { + // Update telemetry to hold the new modifications. + $telemetry_by_reference = $telemetry; + return true; + } + + // Fallback - no changes. + return false; + } } diff --git a/src/Tribe/Main.php b/src/Tribe/Main.php index ef1f071fc6..4fd861173e 100644 --- a/src/Tribe/Main.php +++ b/src/Tribe/Main.php @@ -18,7 +18,7 @@ class Tribe__Main { const OPTIONNAME = 'tribe_events_calendar_options'; const OPTIONNAMENETWORK = 'tribe_events_calendar_network_options'; const FEED_URL = 'https://theeventscalendar.com/feed/'; - const VERSION = '5.2.4'; + const VERSION = '6.6.6'; protected $plugin_context; protected $plugin_context_class; diff --git a/tribe-common.php b/tribe-common.php index fede468c50..bc9b3a364a 100644 --- a/tribe-common.php +++ b/tribe-common.php @@ -1,13 +1,13 @@