Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tribe-common",
"version": "5.1.11",
"version": "6.6.6",
"repository": "git@github.com:the-events-calendar/tribe-common.git",
"_resourcepath": "src/resources",
"_domainPath": "lang",
Expand Down
8 changes: 8 additions & 0 deletions src/Common/Telemetry/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function add_filters() {
add_filter( 'stellarwp/telemetry/optin_args', [ $this, 'filter_optin_args' ] );
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' ] );
}

/**
Expand Down Expand Up @@ -177,4 +181,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 ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Commenting.FunctionComment.Missing
Missing doc comment for function filter_data_args()

return $this->container->make( Telemetry::class )->filter_data_args( $args );
}
}
129 changes: 127 additions & 2 deletions src/Common/Telemetry/Telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class Telemetry {
];

/**
* Path to main pugin file
* Path to main plugin file
*
* @since 5.1.0
*
Expand Down Expand Up @@ -190,6 +190,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;
}

public static function get_plugin_slug() {
if ( empty( self::$plugin_slug ) ) {
self::$plugin_slug = self::get_parent_plugin_slug();
Expand Down Expand Up @@ -447,7 +458,10 @@ public static function get_tec_telemetry_slugs() {
*
* @param array<string,string> $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 );
}

/**
Expand Down Expand Up @@ -639,4 +653,115 @@ 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<string,mixed> $args The array of data arguments to filter.
*
* @return array<string,mixed> $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 );

list( $changed, $telemetry ) = $this->add_licenses( $telemetry );

if ( tribe_is_truthy( $changed ) ) {
$args['telemetry'] = json_encode( $telemetry );
}

/**
* Allows overriding the data arguments for TEC plugins.
*
* @since TBD
*
* @param array<string,mixed> $args The data arguments to filter.
*
* @return array<string,mixed> $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 The telemetry data object.
*
* @return array<bool,object> and array in the format:
* [
* bool $changed If the data has changed.
* obj $telemetry The (potentially modified) telemetry data object.
* ]
*/
protected function add_licenses( $telemetry ) {
// No data sent, bail safely.
if ( empty( $telemetry ) ){
return [ false, $telemetry ];
}

// 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, $telemetry ];
}

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,
function( $key ) {
return str_starts_with( $key, "pue_install_key_");
Comment thread
Camwyn marked this conversation as resolved.
Outdated
Comment thread
Camwyn marked this conversation as resolved.
Outdated
},
ARRAY_FILTER_USE_KEY
);

// No keys found.
if ( empty( $options ) ) {
return [ false, $telemetry ];
}

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'] ) ) {
// return changed data set and flag.
return [ true, $telemetry ];
}

// Fallback - no changes.
return [ false, $telemetry ];
}
Comment thread
Camwyn marked this conversation as resolved.
Outdated
}
2 changes: 1 addition & 1 deletion src/Tribe/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Tribe__Main {
const OPTIONNAME = 'tribe_events_calendar_options';
const OPTIONNAMENETWORK = 'tribe_events_calendar_network_options';

const VERSION = '5.1.11';
const VERSION = '6.6.6';

const FEED_URL = 'https://theeventscalendar.com/feed/';

Expand Down
2 changes: 1 addition & 1 deletion tribe-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Commenting.FileComment.WrongStyle
You must use "/**" style comments for a file comment

Plugin Name: Tribe Common
Description: An event settings framework for managing shared options
Version: 5.1.11
Version: 6.6.6
Author: The Events Calendar
Author URI: http://evnt.is/1x
Text Domain: tribe-common
Expand Down