@@ -55,21 +55,19 @@ public function can_load( $product ) {
5555 */
5656 public function load ( $ product ) {
5757 $ this ->product = $ product ;
58- $ this -> setup_notification ( );
59- $ this -> setup_actions ( );
58+ add_action ( ' wp_loaded ' , array ( $ this , ' setup_actions ' ) );
59+ add_action ( ' admin_init ' , array ( $ this , ' setup_notification ' ) );
6060 return $ this ;
6161 }
6262
6363 /**
6464 * Setup notification on admin.
6565 */
6666 public function setup_notification () {
67- if ( ! $ this ->product -> is_wordpress_available () ) {
67+ if ( $ this ->is_logger_active () ) {
6868 return ;
6969 }
70-
7170 add_filter ( 'themeisle_sdk_registered_notifications ' , [ $ this , 'add_notification ' ] );
72-
7371 }
7472
7573 /**
@@ -79,7 +77,6 @@ public function setup_actions() {
7977 if ( ! $ this ->is_logger_active () ) {
8078 return ;
8179 }
82-
8380 add_action (
8481 'admin_enqueue_scripts ' ,
8582 function () {
@@ -89,7 +86,7 @@ function() {
8986
9087 $ this ->load_telemetry ();
9188 },
92- PHP_INT_MAX
89+ PHP_INT_MAX
9390 );
9491
9592 $ action_key = $ this ->product ->get_key () . '_log_activity ' ;
@@ -105,24 +102,26 @@ function() {
105102 * @return bool Is logger active?
106103 */
107104 private function is_logger_active () {
105+ if ( apply_filters ( 'themeisle_sdk_disable_telemetry ' , false ) ) {
106+ return false ;
107+ }
108108 $ default = 'no ' ;
109109
110110 if ( ! $ this ->product ->is_wordpress_available () ) {
111111 $ default = 'yes ' ;
112112 } else {
113- $ pro_slug = $ this ->product ->get_pro_slug ();
114-
115- if ( ! empty ( $ pro_slug ) ) {
116- $ all_products = Loader::get_products ();
117- if ( isset ( $ all_products [ $ pro_slug ] ) ) {
113+ $ all_products = Loader::get_products ();
114+ foreach ( $ all_products as $ product ) {
115+ if ( $ product ->requires_license () ) {
118116 $ default = 'yes ' ;
117+ break ;
119118 }
120119 }
121120 }
122121
122+
123123 return ( get_option ( $ this ->product ->get_key () . '_logger_flag ' , $ default ) === 'yes ' );
124124 }
125-
126125 /**
127126 * Add notification to queue.
128127 *
@@ -179,14 +178,15 @@ public function send_log() {
179178 'timeout ' => 3 ,
180179 'redirection ' => 5 ,
181180 'body ' => array (
182- 'site ' => get_site_url (),
183- 'slug ' => $ this ->product ->get_slug (),
184- 'version ' => $ this ->product ->get_version (),
185- 'wp_version ' => $ wp_version ,
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 ' , '' ),
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 ' , '' ),
190190 ),
191191 )
192192 );
0 commit comments