PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.14
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Logger.php +43 -44 4.0.43.10.14 View file →
@@ -54,10 +54,10 @@
54 54 * @return Logger Module object.
55 55 */
56 56 public function load( $product ) {
57 57 $this->product = $product;
58 - add_action( 'wp_loaded', array( $this, 'setup_actions' ) );
59 - add_action( 'admin_init', array( $this, 'setup_notification' ) );
58 + $this->setup_notification();
59 + $this->setup_actions();
60 60 return $this;
61 61 }
62 62
63 63 /**
@@ -63,12 +63,14 @@
63 63 /**
64 64 * Setup notification on admin.
65 65 */
66 66 public function setup_notification() {
67 - if ( $this->is_logger_active() ) {
67 + if ( ! $this->product->is_wordpress_available() ) {
68 68 return;
69 69 }
70 +
70 71 add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ] );
72 +
71 73 }
72 74
73 75 /**
74 76 * Setup tracking actions.
@@ -76,20 +78,15 @@
76 78 public function setup_actions() {
77 79 if ( ! $this->is_logger_active() ) {
78 80 return;
79 81 }
80 - add_action(
81 - 'admin_enqueue_scripts',
82 - function() {
83 - if ( ! apply_filters( 'themeisle_sdk_enable_telemetry', false ) ) {
84 - return;
85 - }
86 82
87 - $this->load_telemetry();
88 - },
89 - PHP_INT_MAX
90 - );
83 + $can_load_telemetry = apply_filters( 'themeisle_sdk_enable_telemetry', false );
91 84
85 + if ( $can_load_telemetry ) {
86 + add_action( 'admin_enqueue_scripts', array( $this, 'load_telemetry' ) );
87 + }
88 +
92 89 $action_key = $this->product->get_key() . '_log_activity';
93 90 if ( ! wp_next_scheduled( $action_key ) ) {
94 91 wp_schedule_single_event( time() + ( wp_rand( 1, 24 ) * 3600 ), $action_key );
95 92 }
@@ -101,28 +98,26 @@
101 98 *
102 99 * @return bool Is logger active?
103 100 */
104 101 private function is_logger_active() {
105 - if ( apply_filters( 'themeisle_sdk_disable_telemetry', false ) ) {
106 - return false;
107 - }
108 102 $default = 'no';
109 103
110 104 if ( ! $this->product->is_wordpress_available() ) {
111 105 $default = 'yes';
112 106 } else {
113 - $all_products = Loader::get_products();
114 - foreach ( $all_products as $product ) {
115 - if ( $product->requires_license() ) {
107 + $pro_slug = $this->product->get_pro_slug();
108 +
109 + if ( ! empty( $pro_slug ) ) {
110 + $all_products = Loader::get_products();
111 + if ( isset( $all_products[ $pro_slug ] ) ) {
116 112 $default = 'yes';
117 - break;
118 113 }
119 114 }
120 115 }
121 116
122 -
123 117 return ( get_option( $this->product->get_key() . '_logger_flag', $default ) === 'yes' );
124 118 }
119 +
125 120 /**
126 121 * Add notification to queue.
127 122 *
128 123 * @param array $all_notifications Previous notification.
@@ -177,17 +172,16 @@
177 172 'method' => 'POST',
178 173 'timeout' => 3,
179 174 'redirection' => 5,
180 175 'body' => array(
181 - 'site' => get_site_url(),
182 - 'slug' => $this->product->get_slug(),
183 - 'version' => $this->product->get_version(),
184 - 'wp_version' => $wp_version,
185 - 'install_time' => $this->product->get_install_time(),
186 - 'locale' => get_locale(),
187 - 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
188 - 'environment' => $environment,
189 - 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
176 + 'site' => get_site_url(),
177 + 'slug' => $this->product->get_slug(),
178 + 'version' => $this->product->get_version(),
179 + 'wp_version' => $wp_version,
180 + 'locale' => get_locale(),
181 + 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
182 + 'environment' => $environment,
183 + 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
190 184 ),
191 185 )
192 186 );
193 187 }
@@ -193,9 +187,9 @@
193 187 }
194 188
195 189 /**
196 190 * Load telemetry.
197 - *
191 + *
198 192 * @return void
199 193 */
200 194 public function load_telemetry() {
201 195 // See which products have telemetry enabled.
@@ -203,37 +197,37 @@
203 197 $products_with_telemetry = array();
204 198 $all_products = Loader::get_products();
205 199 $all_products[ $this->product->get_slug() ] = $this->product; // Add current product to the list of products to check for telemetry.
206 200
207 - // Register telemetry params for eligible products.
208 201 foreach ( $all_products as $product_slug => $product ) {
209 -
210 - // Ignore PRO products.
202 +
203 + // Ignore pro products.
211 204 if ( false !== strstr( $product_slug, 'pro' ) ) {
212 205 continue;
213 206 }
214 207
215 - $pro_slug = $product->get_pro_slug();
216 - $logger_key = $product->get_key() . '_logger_flag';
208 + $default = 'no';
217 209
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 );
210 + if ( ! $product->is_wordpress_available() ) {
211 + $default = 'yes';
212 + } else {
213 + $pro_slug = $product->get_pro_slug();
221 214
222 - if ( false === $logger_flag ) {
223 - update_option( $logger_key, 'yes' );
215 + if ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) {
216 + $default = 'yes';
224 217 }
225 218 }
226 219
227 - if ( 'yes' === get_option( $product->get_key() . '_logger_flag', 'no' ) ) {
220 + if ( 'yes' === get_option( $product->get_key() . '_logger_flag', $default ) ) {
228 221
229 222 $main_slug = explode( '-', $product_slug );
230 223 $main_slug = $main_slug[0];
224 + $pro_slug = $product->get_pro_slug();
231 225 $track_hash = Licenser::create_license_hash( str_replace( '-', '_', ! empty( $pro_slug ) ? $pro_slug : $product_slug ) );
232 226
233 227 // Check if product was already tracked.
234 228 $active_telemetry = false;
235 - foreach ( $products_with_telemetry as $product_with_telemetry ) {
229 + foreach ( $products_with_telemetry as &$product_with_telemetry ) {
236 230 if ( $product_with_telemetry['slug'] === $main_slug ) {
237 231 $active_telemetry = true;
238 232 break;
239 233 }
@@ -241,9 +235,9 @@
241 235
242 236 if ( $active_telemetry ) {
243 237 continue;
244 238 }
245 -
239 +
246 240 $products_with_telemetry[] = array(
247 241 'slug' => $main_slug,
248 242 'trackHash' => $track_hash ? $track_hash : 'free',
249 243 'consent' => true,
@@ -256,8 +250,9 @@
256 250 if ( 0 === count( $products_with_telemetry ) ) {
257 251 return;
258 252 }
259 253
254 +
260 255 $tracking_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'tracking' );
261 256 if ( ! empty( $tracking_handler ) ) {
262 257 do_action( 'themeisle_sdk_dependency_enqueue_script', 'tracking' );
263 258 wp_localize_script(
@@ -269,8 +264,12 @@
269 264 )
270 265 );
271 266 }
272 267 } 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 ) {
273 272 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
274 273 error_log( $e->getMessage() ); // phpcs:ignore
275 274 }
276 275 } finally {