Skip to content

Commit

Permalink
fix: active logger flag for PRO users
Browse files Browse the repository at this point in the history
Since the logger flag is connected with UI in plugins, the users will see the true state.
  • Loading branch information
Soare-Robert-Daniel committed May 14, 2024
1 parent 3f6c925 commit b8d9977
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class Loader {
/**
* Holds registered products.
*
* @var array The products which use the SDK.
* @var array<Product> The products which use the SDK.
*/
private static $products = [];
/**
Expand Down Expand Up @@ -353,7 +353,7 @@ public static function get_modules() {
/**
* Get all products using the SDK.
*
* @return array Products available.
* @return array<Product> Products available.
*/
public static function get_products() {
return self::$products;
Expand Down
33 changes: 14 additions & 19 deletions src/Modules/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function send_log() {

/**
* Load telemetry.
*
*
* @return void
*/
public function load_telemetry() {
Expand All @@ -198,35 +198,35 @@ public function load_telemetry() {
$all_products = Loader::get_products();
$all_products[ $this->product->get_slug() ] = $this->product; // Add current product to the list of products to check for telemetry.

// Register telemetry params for eligible products.
foreach ( $all_products as $product_slug => $product ) {
// Ignore pro products.

// Ignore PRO products.
if ( false !== strstr( $product_slug, 'pro' ) ) {
continue;
}

$default = 'no';
$pro_slug = $product->get_pro_slug();
$logger_key = $product->get_key() . '_logger_flag';

if ( ! $product->is_wordpress_available() ) {
$default = 'yes';
} else {
$pro_slug = $product->get_pro_slug();
// If the product is not available in the WordPress store, or it's PRO version is installed, activate the logger if it was not initialized -- Pro users are opted in by default.
if ( ! $product->is_wordpress_available() || ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) ) {
$logger_flag = get_option( $logger_key );

if ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) {
$default = 'yes';
if ( false === $logger_flag ) {
update_option( $logger_key, 'yes' );
}
}

if ( 'yes' === get_option( $product->get_key() . '_logger_flag', $default ) ) {
if ( 'yes' === get_option( $product->get_key() . '_logger_flag', 'no' ) ) {

$main_slug = explode( '-', $product_slug );
$main_slug = $main_slug[0];
$pro_slug = $product->get_pro_slug();
$track_hash = Licenser::create_license_hash( str_replace( '-', '_', ! empty( $pro_slug ) ? $pro_slug : $product_slug ) );

// Check if product was already tracked.
$active_telemetry = false;
foreach ( $products_with_telemetry as &$product_with_telemetry ) {
foreach ( $products_with_telemetry as $product_with_telemetry ) {
if ( $product_with_telemetry['slug'] === $main_slug ) {
$active_telemetry = true;
break;
Expand All @@ -236,7 +236,7 @@ public function load_telemetry() {
if ( $active_telemetry ) {
continue;
}

$products_with_telemetry[] = array(
'slug' => $main_slug,
'trackHash' => $track_hash ? $track_hash : 'free',
Expand All @@ -251,7 +251,6 @@ public function load_telemetry() {
return;
}


$tracking_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'tracking' );
if ( ! empty( $tracking_handler ) ) {
do_action( 'themeisle_sdk_dependency_enqueue_script', 'tracking' );
Expand All @@ -268,10 +267,6 @@ public function load_telemetry() {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( $e->getMessage() ); // phpcs:ignore
}
} catch ( \Error $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( $e->getMessage() ); // phpcs:ignore
}
} finally {
return;
}
Expand Down

0 comments on commit b8d9977

Please sign in to comment.