← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Logger.php
+25
-24
3.10.13
→
3.11.10
View file →
| @@ -78,15 +78,21 @@ | ||
| 78 | 78 | public function setup_actions() { |
| 79 | 79 | if ( ! $this->is_logger_active() ) { |
| 80 | 80 | return; |
| 81 | 81 | } |
| 82 | + | |
| 83 | + add_action( | |
| 84 | + 'admin_enqueue_scripts', | |
| 85 | + function() { | |
| 86 | + if ( ! apply_filters( 'themeisle_sdk_enable_telemetry', false ) ) { | |
| 87 | + return; | |
| 88 | + } | |
| 82 | 89 | |
| 83 | - $can_load_telemetry = apply_filters( 'themeisle_sdk_enable_telemetry', false ); | |
| 90 | + $this->load_telemetry(); | |
| 91 | + }, | |
| 92 | + PHP_INT_MAX | |
| 93 | + ); | |
| 84 | 94 | |
| 85 | - if ( $can_load_telemetry ) { | |
| 86 | - add_action( 'admin_enqueue_scripts', array( $this, 'load_telemetry' ) ); | |
| 87 | - } | |
| 88 | - | |
| 89 | 95 | $action_key = $this->product->get_key() . '_log_activity'; |
| 90 | 96 | if ( ! wp_next_scheduled( $action_key ) ) { |
| 91 | 97 | wp_schedule_single_event( time() + ( wp_rand( 1, 24 ) * 3600 ), $action_key ); |
| 92 | 98 | } |
| @@ -187,9 +193,9 @@ | ||
| 187 | 193 | } |
| 188 | 194 | |
| 189 | 195 | /** |
| 190 | 196 | * Load telemetry. |
| 191 | - * | |
| 197 | + * | |
| 192 | 198 | * @return void |
| 193 | 199 | */ |
| 194 | 200 | public function load_telemetry() { |
| 195 | 201 | // See which products have telemetry enabled. |
| @@ -197,37 +203,37 @@ | ||
| 197 | 203 | $products_with_telemetry = array(); |
| 198 | 204 | $all_products = Loader::get_products(); |
| 199 | 205 | $all_products[ $this->product->get_slug() ] = $this->product; // Add current product to the list of products to check for telemetry. |
| 200 | 206 | |
| 207 | + // Register telemetry params for eligible products. | |
| 201 | 208 | foreach ( $all_products as $product_slug => $product ) { |
| 202 | - | |
| 203 | - // Ignore pro products. | |
| 209 | + | |
| 210 | + // Ignore PRO products. | |
| 204 | 211 | if ( false !== strstr( $product_slug, 'pro' ) ) { |
| 205 | 212 | continue; |
| 206 | 213 | } |
| 207 | 214 | |
| 208 | - $default = 'no'; | |
| 215 | + $pro_slug = $product->get_pro_slug(); | |
| 216 | + $logger_key = $product->get_key() . '_logger_flag'; | |
| 209 | 217 | |
| 210 | - if ( ! $product->is_wordpress_available() ) { | |
| 211 | - $default = 'yes'; | |
| 212 | - } else { | |
| 213 | - $pro_slug = $product->get_pro_slug(); | |
| 218 | + // 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. | |
| 219 | + if ( ! $product->is_wordpress_available() || ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) ) { | |
| 220 | + $logger_flag = get_option( $logger_key ); | |
| 214 | 221 | |
| 215 | - if ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) { | |
| 216 | - $default = 'yes'; | |
| 222 | + if ( false === $logger_flag ) { | |
| 223 | + update_option( $logger_key, 'yes' ); | |
| 217 | 224 | } |
| 218 | 225 | } |
| 219 | 226 | |
| 220 | - if ( 'yes' === get_option( $product->get_key() . '_logger_flag', $default ) ) { | |
| 227 | + if ( 'yes' === get_option( $product->get_key() . '_logger_flag', 'no' ) ) { | |
| 221 | 228 | |
| 222 | 229 | $main_slug = explode( '-', $product_slug ); |
| 223 | 230 | $main_slug = $main_slug[0]; |
| 224 | - $pro_slug = $product->get_pro_slug(); | |
| 225 | 231 | $track_hash = Licenser::create_license_hash( str_replace( '-', '_', ! empty( $pro_slug ) ? $pro_slug : $product_slug ) ); |
| 226 | 232 | |
| 227 | 233 | // Check if product was already tracked. |
| 228 | 234 | $active_telemetry = false; |
| 229 | - foreach ( $products_with_telemetry as &$product_with_telemetry ) { | |
| 235 | + foreach ( $products_with_telemetry as $product_with_telemetry ) { | |
| 230 | 236 | if ( $product_with_telemetry['slug'] === $main_slug ) { |
| 231 | 237 | $active_telemetry = true; |
| 232 | 238 | break; |
| 233 | 239 | } |
| @@ -235,9 +241,9 @@ | ||
| 235 | 241 | |
| 236 | 242 | if ( $active_telemetry ) { |
| 237 | 243 | continue; |
| 238 | 244 | } |
| 239 | - | |
| 245 | + | |
| 240 | 246 | $products_with_telemetry[] = array( |
| 241 | 247 | 'slug' => $main_slug, |
| 242 | 248 | 'trackHash' => $track_hash ? $track_hash : 'free', |
| 243 | 249 | 'consent' => true, |
| @@ -250,9 +256,8 @@ | ||
| 250 | 256 | if ( 0 === count( $products_with_telemetry ) ) { |
| 251 | 257 | return; |
| 252 | 258 | } |
| 253 | 259 | |
| 254 | - | |
| 255 | 260 | $tracking_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'tracking' ); |
| 256 | 261 | if ( ! empty( $tracking_handler ) ) { |
| 257 | 262 | do_action( 'themeisle_sdk_dependency_enqueue_script', 'tracking' ); |
| 258 | 263 | wp_localize_script( |
| @@ -264,12 +269,8 @@ | ||
| 264 | 269 | ) |
| 265 | 270 | ); |
| 266 | 271 | } |
| 267 | 272 | } catch ( \Exception $e ) { |
| 268 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { | |
| 269 | - error_log( $e->getMessage() ); // phpcs:ignore | |
| 270 | - } | |
| 271 | - } catch ( \Error $e ) { | |
| 272 | 273 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { |
| 273 | 274 | error_log( $e->getMessage() ); // phpcs:ignore |
| 274 | 275 | } |
| 275 | 276 | } finally { |