← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Logger.php
+23
-37
4.0.7
→
3.11.10
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,8 +78,9 @@ | ||
| 76 | 78 | public function setup_actions() { |
| 77 | 79 | if ( ! $this->is_logger_active() ) { |
| 78 | 80 | return; |
| 79 | 81 | } |
| 82 | + | |
| 80 | 83 | add_action( |
| 81 | 84 | 'admin_enqueue_scripts', |
| 82 | 85 | function() { |
| 83 | 86 | if ( ! apply_filters( 'themeisle_sdk_enable_telemetry', false ) ) { |
| @@ -85,9 +88,9 @@ | ||
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | $this->load_telemetry(); |
| 88 | 91 | }, |
| 89 | - PHP_INT_MAX | |
| 92 | + PHP_INT_MAX | |
| 90 | 93 | ); |
| 91 | 94 | |
| 92 | 95 | $action_key = $this->product->get_key() . '_log_activity'; |
| 93 | 96 | if ( ! wp_next_scheduled( $action_key ) ) { |
| @@ -101,42 +104,26 @@ | ||
| 101 | 104 | * |
| 102 | 105 | * @return bool Is logger active? |
| 103 | 106 | */ |
| 104 | 107 | private function is_logger_active() { |
| 105 | - return self::is_logging_active( $this->product ); | |
| 106 | - } | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * Check if the logging consent is granted for a product. | |
| 110 | - * | |
| 111 | - * Shared with the other telemetry modules (e.g. the crash reporter) so the | |
| 112 | - * consent semantics live in a single place. | |
| 113 | - * | |
| 114 | - * @param \ThemeisleSDK\Product $product Product to check. | |
| 115 | - * | |
| 116 | - * @return bool Is logging active for the product? | |
| 117 | - */ | |
| 118 | - public static function is_logging_active( $product ) { | |
| 119 | - if ( apply_filters( 'themeisle_sdk_disable_telemetry', false ) ) { | |
| 120 | - return false; | |
| 121 | - } | |
| 122 | 108 | $default = 'no'; |
| 123 | 109 | |
| 124 | - if ( ! $product->is_wordpress_available() ) { | |
| 110 | + if ( ! $this->product->is_wordpress_available() ) { | |
| 125 | 111 | $default = 'yes'; |
| 126 | 112 | } else { |
| 127 | - $all_products = Loader::get_products(); | |
| 128 | - foreach ( $all_products as $registered_product ) { | |
| 129 | - if ( $registered_product->requires_license() ) { | |
| 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 ] ) ) { | |
| 130 | 118 | $default = 'yes'; |
| 131 | - break; | |
| 132 | 119 | } |
| 133 | 120 | } |
| 134 | 121 | } |
| 135 | 122 | |
| 123 | + return ( get_option( $this->product->get_key() . '_logger_flag', $default ) === 'yes' ); | |
| 124 | + } | |
| 136 | 125 | |
| 137 | - return ( get_option( $product->get_key() . '_logger_flag', $default ) === 'yes' ); | |
| 138 | - } | |
| 139 | 126 | /** |
| 140 | 127 | * Add notification to queue. |
| 141 | 128 | * |
| 142 | 129 | * @param array $all_notifications Previous notification. |
| @@ -191,17 +178,16 @@ | ||
| 191 | 178 | 'method' => 'POST', |
| 192 | 179 | 'timeout' => 3, |
| 193 | 180 | 'redirection' => 5, |
| 194 | 181 | 'body' => array( |
| 195 | - 'site' => get_site_url(), | |
| 196 | - 'slug' => $this->product->get_slug(), | |
| 197 | - 'version' => $this->product->get_version(), | |
| 198 | - 'wp_version' => $wp_version, | |
| 199 | - 'install_time' => $this->product->get_install_time(), | |
| 200 | - 'locale' => get_locale(), | |
| 201 | - 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ), | |
| 202 | - 'environment' => $environment, | |
| 203 | - 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ), | |
| 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', '' ), | |
| 204 | 190 | ), |
| 205 | 191 | ) |
| 206 | 192 | ); |
| 207 | 193 | } |