@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __construct() { |
43 | 43 | |
44 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
44 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service'); |
|
45 | 45 | |
46 | - add_action( 'admin_init', array( $this, 'wl_load_plugin' ) ); |
|
46 | + add_action('admin_init', array($this, 'wl_load_plugin')); |
|
47 | 47 | /** |
48 | 48 | * Filter: wl_feature__enable__notices. |
49 | 49 | * |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | * @return bool |
53 | 53 | * @since 3.27.6 |
54 | 54 | */ |
55 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
56 | - add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) ); |
|
55 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
56 | + add_action('admin_notices', array($this, 'wl_key_update_notice')); |
|
57 | 57 | } |
58 | 58 | |
59 | - $this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' ); |
|
59 | + $this->ttl_cache_service = new Ttl_Cache('key-validation-notification'); |
|
60 | 60 | |
61 | 61 | } |
62 | 62 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @return WP_Error|array The response or WP_Error on failure. |
69 | 69 | * @since 3.9.0 |
70 | 70 | */ |
71 | - public function get_account_info( $key ) { |
|
71 | + public function get_account_info($key) { |
|
72 | 72 | |
73 | - $this->log->debug( 'Validating key...' ); |
|
73 | + $this->log->debug('Validating key...'); |
|
74 | 74 | |
75 | 75 | $response = Default_Api_Service::get_instance()->get( |
76 | 76 | '/accounts/info', |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * This action is fired when the key is validated. |
85 | 85 | * @param $response \Wordlift\Api\Response |
86 | 86 | */ |
87 | - do_action( 'wl_key_validation_response', $response ); |
|
87 | + do_action('wl_key_validation_response', $response); |
|
88 | 88 | |
89 | 89 | return $response->get_response(); |
90 | 90 | } |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - public function is_key_valid( $key ) { |
|
99 | + public function is_key_valid($key) { |
|
100 | 100 | |
101 | - $response = $this->get_account_info( $key ); |
|
101 | + $response = $this->get_account_info($key); |
|
102 | 102 | |
103 | - if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) { |
|
103 | + if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | - $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
106 | + $res_body = json_decode(wp_remote_retrieve_body($response), true); |
|
107 | 107 | |
108 | 108 | $url = $res_body['url']; |
109 | 109 | |
110 | 110 | // Considering that production URL may be filtered. |
111 | - $home_url = get_option( 'home' ); |
|
112 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
113 | - if ( $url === null || $url === $site_url ) { |
|
111 | + $home_url = get_option('home'); |
|
112 | + $site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url)); |
|
113 | + if ($url === null || $url === $site_url) { |
|
114 | 114 | return true; |
115 | 115 | } |
116 | 116 | |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | ob_clean(); |
129 | 129 | |
130 | 130 | // Check if we have a key. |
131 | - if ( ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
132 | - wp_send_json_error( 'The key parameter is required.' ); |
|
131 | + if ( ! isset($_POST['key'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
132 | + wp_send_json_error('The key parameter is required.'); |
|
133 | 133 | } |
134 | 134 | |
135 | - $response = $this->get_account_info( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
135 | + $response = $this->get_account_info(sanitize_text_field(wp_unslash((string) $_POST['key']))); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
136 | 136 | |
137 | 137 | // If we got an error, return invalid. |
138 | - if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) { |
|
138 | + if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) { |
|
139 | 139 | wp_send_json_success( |
140 | 140 | array( |
141 | 141 | 'valid' => false, |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - $res_body = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
149 | + $res_body = json_decode(wp_remote_retrieve_body($response), true); |
|
150 | 150 | |
151 | 151 | // The URL stored in WLS. If this is the initial install the URL may be null. |
152 | 152 | $url = $res_body['url']; |
153 | 153 | |
154 | 154 | // Considering that production URL may be filtered. |
155 | - $home_url = get_option( 'home' ); |
|
156 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
155 | + $home_url = get_option('home'); |
|
156 | + $site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url)); |
|
157 | 157 | |
158 | 158 | // If the URL isn't set or matches, then it's valid. |
159 | - if ( $url === null || $url === $site_url ) { |
|
159 | + if ($url === null || $url === $site_url) { |
|
160 | 160 | // Invalidate the cache key |
161 | - $this->ttl_cache_service->delete( 'is_key_valid' ); |
|
161 | + $this->ttl_cache_service->delete('is_key_valid'); |
|
162 | 162 | wp_send_json_success( |
163 | 163 | array( |
164 | 164 | 'valid' => true, |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // If the URL doesn't match it means that this key has been configured elsewhere already. |
171 | - if ( $url !== $site_url ) { |
|
172 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
171 | + if ($url !== $site_url) { |
|
172 | + Wordlift_Configuration_Service::get_instance()->set_key(''); |
|
173 | 173 | wp_send_json_success( |
174 | 174 | array( |
175 | 175 | 'valid' => false, |
176 | - 'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ), |
|
176 | + 'message' => __('The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift'), |
|
177 | 177 | ) |
178 | 178 | ); |
179 | 179 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | wp_send_json_success( |
183 | 183 | array( |
184 | 184 | 'valid' => false, |
185 | - 'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ), |
|
185 | + 'message' => __('An error occurred, please contact us at [email protected]', 'wordlift'), |
|
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | } |
@@ -192,15 +192,15 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function wl_load_plugin() { |
194 | 194 | |
195 | - $wl_blog_url = get_option( '_wl_blog_url' ); |
|
196 | - $home_url = get_option( 'home' ); |
|
195 | + $wl_blog_url = get_option('_wl_blog_url'); |
|
196 | + $home_url = get_option('home'); |
|
197 | 197 | |
198 | - if ( ! $wl_blog_url ) { |
|
199 | - update_option( '_wl_blog_url', $home_url, true ); |
|
200 | - } elseif ( $wl_blog_url !== $home_url ) { |
|
201 | - update_option( '_wl_blog_url', $home_url, true ); |
|
202 | - Wordlift_Configuration_Service::get_instance()->set_key( '' ); |
|
203 | - set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 ); |
|
198 | + if ( ! $wl_blog_url) { |
|
199 | + update_option('_wl_blog_url', $home_url, true); |
|
200 | + } elseif ($wl_blog_url !== $home_url) { |
|
201 | + update_option('_wl_blog_url', $home_url, true); |
|
202 | + Wordlift_Configuration_Service::get_instance()->set_key(''); |
|
203 | + set_transient('wl-key-error-msg', __("Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift'), 10); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | } |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | * This function is hooked to the `admin_notices` to show admin notification. |
210 | 210 | */ |
211 | 211 | public function wl_key_update_notice() { |
212 | - if ( get_transient( 'wl-key-error-msg' ) ) { |
|
212 | + if (get_transient('wl-key-error-msg')) { |
|
213 | 213 | ?> |
214 | 214 | <div class="updated notice is-dismissible error"> |
215 | - <p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p> |
|
215 | + <p><?php esc_html(get_transient('wl-key-error-msg')); ?></p> |
|
216 | 216 | </div> |
217 | 217 | <?php |
218 | 218 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | use Wordlift\Api\Default_Api_Service; |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | */ |
137 | 137 | protected function __construct() { |
138 | 138 | |
139 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
139 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
140 | 140 | |
141 | 141 | // Sync some configuration properties when key is validated. |
142 | - add_action( 'wl_key_validation_response', array( $this, 'sync' ) ); |
|
142 | + add_action('wl_key_validation_response', array($this, 'sync')); |
|
143 | 143 | |
144 | 144 | } |
145 | 145 | |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function sync( $response ) { |
|
152 | - if ( ! $response->is_success() ) { |
|
151 | + public function sync($response) { |
|
152 | + if ( ! $response->is_success()) { |
|
153 | 153 | return; |
154 | 154 | } |
155 | - $data = json_decode( $response->get_body(), true ); |
|
156 | - if ( ! is_array( $data ) || ! array_key_exists( 'networkDatasetId', $data ) ) { |
|
155 | + $data = json_decode($response->get_body(), true); |
|
156 | + if ( ! is_array($data) || ! array_key_exists('networkDatasetId', $data)) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | - $this->set_network_dataset_ids( $data['networkDatasetId'] ); |
|
159 | + $this->set_network_dataset_ids($data['networkDatasetId']); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public static function get_instance() { |
179 | 179 | |
180 | - if ( ! isset( self::$instance ) ) { |
|
180 | + if ( ! isset(self::$instance)) { |
|
181 | 181 | self::$instance = new self(); |
182 | 182 | } |
183 | 183 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @return mixed The configuration value or the default value if not found. |
196 | 196 | * @since 3.6.0 |
197 | 197 | */ |
198 | - private function get( $option, $key, $default = '' ) { |
|
198 | + private function get($option, $key, $default = '') { |
|
199 | 199 | |
200 | - $options = get_option( $option, array() ); |
|
200 | + $options = get_option($option, array()); |
|
201 | 201 | |
202 | - return isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
202 | + return isset($options[$key]) ? $options[$key] : $default; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @since 3.9.0 |
213 | 213 | */ |
214 | - private function set( $option, $key, $value ) { |
|
214 | + private function set($option, $key, $value) { |
|
215 | 215 | |
216 | - $values = get_option( $option ); |
|
217 | - $values = isset( $values ) ? $values : array(); |
|
218 | - $values[ $key ] = $value; |
|
219 | - update_option( $option, $values ); |
|
216 | + $values = get_option($option); |
|
217 | + $values = isset($values) ? $values : array(); |
|
218 | + $values[$key] = $value; |
|
219 | + update_option($option, $values); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_entity_base_path() { |
230 | 230 | |
231 | - return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' ); |
|
231 | + return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @since 3.9.0 |
240 | 240 | */ |
241 | - public function set_entity_base_path( $value ) { |
|
241 | + public function set_entity_base_path($value) { |
|
242 | 242 | |
243 | - $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value ); |
|
243 | + $this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value); |
|
244 | 244 | |
245 | 245 | } |
246 | 246 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function is_skip_wizard() { |
254 | 254 | |
255 | - return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false ); |
|
255 | + return $this->get('wl_general_settings', self::SKIP_WIZARD, false); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @since 3.9.0 |
264 | 264 | */ |
265 | - public function set_skip_wizard( $value ) { |
|
265 | + public function set_skip_wizard($value) { |
|
266 | 266 | |
267 | - $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value ); |
|
267 | + $this->set('wl_general_settings', self::SKIP_WIZARD, true === $value); |
|
268 | 268 | |
269 | 269 | } |
270 | 270 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function get_key() { |
278 | 278 | |
279 | - return $this->get( 'wl_general_settings', self::KEY, '' ); |
|
279 | + return $this->get('wl_general_settings', self::KEY, ''); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @since 3.9.0 |
288 | 288 | */ |
289 | - public function set_key( $value ) { |
|
289 | + public function set_key($value) { |
|
290 | 290 | |
291 | - $this->set( 'wl_general_settings', self::KEY, $value ); |
|
291 | + $this->set('wl_general_settings', self::KEY, $value); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | public function get_language_code() { |
303 | 303 | |
304 | 304 | $language = get_locale(); |
305 | - if ( ! $language ) { |
|
305 | + if ( ! $language) { |
|
306 | 306 | return 'en'; |
307 | 307 | } |
308 | 308 | |
309 | - return substr( $language, 0, 2 ); |
|
309 | + return substr($language, 0, 2); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @since 3.9.0 |
323 | 323 | */ |
324 | - public function set_language_code( $value ) { |
|
324 | + public function set_language_code($value) { |
|
325 | 325 | |
326 | - $this->set( 'wl_general_settings', self::LANGUAGE, $value ); |
|
326 | + $this->set('wl_general_settings', self::LANGUAGE, $value); |
|
327 | 327 | |
328 | 328 | } |
329 | 329 | |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @since 3.19.0 |
336 | 336 | */ |
337 | - public function set_diagnostic_preferences( $value ) { |
|
337 | + public function set_diagnostic_preferences($value) { |
|
338 | 338 | |
339 | - $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value ); |
|
339 | + $this->set('wl_general_settings', self::SEND_DIAGNOSTIC, $value); |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public function get_diagnostic_preferences() { |
349 | 349 | |
350 | - return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' ); |
|
350 | + return $this->get('wl_general_settings', self::SEND_DIAGNOSTIC, 'no'); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | */ |
359 | 359 | public function get_country_code() { |
360 | 360 | |
361 | - return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' ); |
|
361 | + return $this->get('wl_general_settings', self::COUNTRY_CODE, 'us'); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @since 3.18.0 |
370 | 370 | */ |
371 | - public function set_country_code( $value ) { |
|
371 | + public function set_country_code($value) { |
|
372 | 372 | |
373 | - $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value ); |
|
373 | + $this->set('wl_general_settings', self::COUNTRY_CODE, $value); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | */ |
386 | 386 | public function get_publisher_id() { |
387 | 387 | |
388 | - return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null ); |
|
388 | + return $this->get('wl_general_settings', self::PUBLISHER_ID, null); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | * |
396 | 396 | * @since 3.9.0 |
397 | 397 | */ |
398 | - public function set_publisher_id( $value ) { |
|
398 | + public function set_publisher_id($value) { |
|
399 | 399 | |
400 | - $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value ); |
|
400 | + $this->set('wl_general_settings', self::PUBLISHER_ID, $value); |
|
401 | 401 | |
402 | 402 | } |
403 | 403 | |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | */ |
411 | 411 | public function get_dataset_uri() { |
412 | 412 | |
413 | - if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
414 | - return $this->get( 'wl_advanced_settings', self::DATASET_URI, null ); |
|
413 | + if (apply_filters('wl_feature__enable__dataset', true)) { |
|
414 | + return $this->get('wl_advanced_settings', self::DATASET_URI, null); |
|
415 | 415 | } else { |
416 | 416 | return null; |
417 | 417 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | * |
425 | 425 | * @since 3.10.0 |
426 | 426 | */ |
427 | - public function set_dataset_uri( $value ) { |
|
427 | + public function set_dataset_uri($value) { |
|
428 | 428 | |
429 | - $this->set( 'wl_advanced_settings', self::DATASET_URI, $value ); |
|
429 | + $this->set('wl_advanced_settings', self::DATASET_URI, $value); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function get_package_type() { |
439 | 439 | |
440 | - return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null ); |
|
440 | + return $this->get('wl_advanced_settings', self::PACKAGE_TYPE, null); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | * |
448 | 448 | * @since 3.20.0 |
449 | 449 | */ |
450 | - public function set_package_type( $value ) { |
|
451 | - $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value ); |
|
450 | + public function set_package_type($value) { |
|
451 | + $this->set('wl_advanced_settings', self::PACKAGE_TYPE, $value); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -463,11 +463,11 @@ discard block |
||
463 | 463 | * @param array $old_value The old settings. |
464 | 464 | * @param array $new_value The new settings. |
465 | 465 | */ |
466 | - public function update_key( $old_value, $new_value ) { |
|
466 | + public function update_key($old_value, $new_value) { |
|
467 | 467 | |
468 | 468 | // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
469 | 469 | // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
470 | - $new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
470 | + $new_key = isset($new_value['key']) ? $new_value['key'] : ''; |
|
471 | 471 | |
472 | 472 | // If the key hasn't changed, don't do anything. |
473 | 473 | // WARN The 'update_option' hook is fired only if the new and old value are not equal. |
@@ -476,14 +476,14 @@ discard block |
||
476 | 476 | // } |
477 | 477 | |
478 | 478 | // If the key is empty, empty the dataset URI. |
479 | - if ( '' === $new_key ) { |
|
480 | - $this->set_dataset_uri( '' ); |
|
479 | + if ('' === $new_key) { |
|
480 | + $this->set_dataset_uri(''); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | // make the request to the remote server. |
484 | - $this->get_remote_dataset_uri( $new_key ); |
|
484 | + $this->get_remote_dataset_uri($new_key); |
|
485 | 485 | |
486 | - do_action( 'wl_key_updated' ); |
|
486 | + do_action('wl_key_updated'); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 | |
@@ -499,15 +499,15 @@ discard block |
||
499 | 499 | * |
500 | 500 | * @since 3.17.0 send the site URL and get the dataset URI. |
501 | 501 | */ |
502 | - public function get_remote_dataset_uri( $key ) { |
|
502 | + public function get_remote_dataset_uri($key) { |
|
503 | 503 | |
504 | - $this->log->trace( 'Getting the remote dataset URI and package type...' ); |
|
504 | + $this->log->trace('Getting the remote dataset URI and package type...'); |
|
505 | 505 | |
506 | - if ( empty( $key ) ) { |
|
507 | - $this->log->warn( 'Key set to empty value.' ); |
|
506 | + if (empty($key)) { |
|
507 | + $this->log->warn('Key set to empty value.'); |
|
508 | 508 | |
509 | - $this->set_dataset_uri( '' ); |
|
510 | - $this->set_package_type( null ); |
|
509 | + $this->set_dataset_uri(''); |
|
510 | + $this->set_package_type(null); |
|
511 | 511 | |
512 | 512 | return; |
513 | 513 | } |
@@ -521,15 +521,15 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @since 3.20.0 |
523 | 523 | */ |
524 | - $home_url = get_option( 'home' ); |
|
525 | - $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) ); |
|
524 | + $home_url = get_option('home'); |
|
525 | + $site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url)); |
|
526 | 526 | |
527 | 527 | // Build the URL. |
528 | 528 | $url = '/accounts' |
529 | - . '?key=' . rawurlencode( $key ) |
|
530 | - . '&url=' . rawurlencode( $site_url ) |
|
531 | - . '&country=' . $this->get_country_code() |
|
532 | - . '&language=' . $this->get_language_code(); |
|
529 | + . '?key='.rawurlencode($key) |
|
530 | + . '&url='.rawurlencode($site_url) |
|
531 | + . '&country='.$this->get_country_code() |
|
532 | + . '&language='.$this->get_language_code(); |
|
533 | 533 | |
534 | 534 | $api_service = Default_Api_Service::get_instance(); |
535 | 535 | /** |
@@ -539,32 +539,32 @@ discard block |
||
539 | 539 | $headers = array( |
540 | 540 | 'Authorization' => "Key $key", |
541 | 541 | ); |
542 | - $response = $api_service->request( 'PUT', $url, $headers )->get_response(); |
|
542 | + $response = $api_service->request('PUT', $url, $headers)->get_response(); |
|
543 | 543 | |
544 | 544 | // The response is an error. |
545 | - if ( is_wp_error( $response ) ) { |
|
546 | - $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() ); |
|
545 | + if (is_wp_error($response)) { |
|
546 | + $this->log->error('An error occurred setting the dataset URI: '.$response->get_error_message()); |
|
547 | 547 | |
548 | - $this->set_dataset_uri( '' ); |
|
549 | - $this->set_package_type( null ); |
|
548 | + $this->set_dataset_uri(''); |
|
549 | + $this->set_package_type(null); |
|
550 | 550 | |
551 | 551 | return; |
552 | 552 | } |
553 | 553 | |
554 | 554 | // The response is not OK. |
555 | - if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
555 | + if ( ! is_array($response) || 200 !== (int) $response['response']['code']) { |
|
556 | 556 | $base_url = $api_service->get_base_url(); |
557 | 557 | |
558 | - if ( ! is_array( $response ) ) { |
|
558 | + if ( ! is_array($response)) { |
|
559 | 559 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
560 | - $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) ); |
|
560 | + $this->log->error("Unexpected response when opening URL $base_url$url: ".var_export($response, true)); |
|
561 | 561 | } else { |
562 | 562 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
563 | - $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) ); |
|
563 | + $this->log->error("Unexpected status code when opening URL $base_url$url: ".$response['response']['code']."\n".var_export($response, true)); |
|
564 | 564 | } |
565 | 565 | |
566 | - $this->set_dataset_uri( '' ); |
|
567 | - $this->set_package_type( null ); |
|
566 | + $this->set_dataset_uri(''); |
|
567 | + $this->set_package_type(null); |
|
568 | 568 | |
569 | 569 | return; |
570 | 570 | } |
@@ -574,20 +574,20 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @since 3.20.0 |
576 | 576 | */ |
577 | - $json = json_decode( $response['body'] ); |
|
577 | + $json = json_decode($response['body']); |
|
578 | 578 | /** |
579 | 579 | * @since 3.27.7 |
580 | 580 | * Remove the trailing slash returned from the new platform api. |
581 | 581 | */ |
582 | 582 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
583 | - $dataset_uri = untrailingslashit( $json->datasetURI ); |
|
583 | + $dataset_uri = untrailingslashit($json->datasetURI); |
|
584 | 584 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
585 | - $package_type = isset( $json->packageType ) ? $json->packageType : null; |
|
585 | + $package_type = isset($json->packageType) ? $json->packageType : null; |
|
586 | 586 | |
587 | - $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." ); |
|
587 | + $this->log->info("Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..."); |
|
588 | 588 | |
589 | - $this->set_dataset_uri( $dataset_uri ); |
|
590 | - $this->set_package_type( $package_type ); |
|
589 | + $this->set_dataset_uri($dataset_uri); |
|
590 | + $this->set_package_type($package_type); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -604,20 +604,20 @@ discard block |
||
604 | 604 | * @return mixed The same value in the $value parameter |
605 | 605 | * @since 3.12.0 |
606 | 606 | */ |
607 | - public function maybe_update_dataset_uri( $value, $old_value ) { |
|
607 | + public function maybe_update_dataset_uri($value, $old_value) { |
|
608 | 608 | |
609 | 609 | // Check the old key value and the new one. Here we're only handling the |
610 | 610 | // case where the key hasn't changed and the dataset URI isn't set. The |
611 | 611 | // other case, i.e. a new key is inserted, is handled at `update_key`. |
612 | - $old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
613 | - $new_key = isset( $value['key'] ) ? $value['key'] : ''; |
|
612 | + $old_key = isset($old_value['key']) ? $old_value['key'] : ''; |
|
613 | + $new_key = isset($value['key']) ? $value['key'] : ''; |
|
614 | 614 | |
615 | 615 | $dataset_uri = $this->get_dataset_uri(); |
616 | 616 | |
617 | - if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) { |
|
617 | + if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) { |
|
618 | 618 | |
619 | 619 | // make the request to the remote server to try to get the dataset uri. |
620 | - $this->get_remote_dataset_uri( $new_key ); |
|
620 | + $this->get_remote_dataset_uri($new_key); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | return $value; |
@@ -631,9 +631,9 @@ discard block |
||
631 | 631 | * @return string The API URI. |
632 | 632 | * @since 3.11.0 |
633 | 633 | */ |
634 | - public function get_accounts_by_key_dataset_uri( $key ) { |
|
634 | + public function get_accounts_by_key_dataset_uri($key) { |
|
635 | 635 | |
636 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
636 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri"; |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | */ |
645 | 645 | public function get_accounts() { |
646 | 646 | |
647 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts'; |
|
647 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'accounts'; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public function is_link_by_default() { |
657 | 657 | |
658 | - return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' ); |
|
658 | + return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes'); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | * |
666 | 666 | * @since 3.13.0 |
667 | 667 | */ |
668 | - public function set_link_by_default( $value ) { |
|
668 | + public function set_link_by_default($value) { |
|
669 | 669 | |
670 | - $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' ); |
|
670 | + $this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no'); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | * @since 3.21.0 |
678 | 678 | */ |
679 | 679 | public function is_analytics_enable() { |
680 | - return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' ); |
|
680 | + return 'yes' === $this->get('wl_analytics_settings', self::ANALYTICS_ENABLE, 'no'); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -687,9 +687,9 @@ discard block |
||
687 | 687 | * |
688 | 688 | * @since 3.21.0 |
689 | 689 | */ |
690 | - public function set_is_analytics_enable( $value ) { |
|
690 | + public function set_is_analytics_enable($value) { |
|
691 | 691 | |
692 | - $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' ); |
|
692 | + $this->set('wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no'); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | * @since 3.21.0 |
700 | 700 | */ |
701 | 701 | public function get_analytics_entity_uri_dimension() { |
702 | - return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 ); |
|
702 | + return (int) $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | * @since 3.21.0 |
710 | 710 | */ |
711 | 711 | public function get_analytics_entity_type_dimension() { |
712 | - return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 ); |
|
712 | + return $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | /** |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | */ |
721 | 721 | public function get_autocomplete_url() { |
722 | 722 | |
723 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete'; |
|
723 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'autocomplete'; |
|
724 | 724 | |
725 | 725 | } |
726 | 726 | |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | */ |
733 | 733 | public function get_deactivation_feedback_url() { |
734 | 734 | |
735 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks'; |
|
735 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'feedbacks'; |
|
736 | 736 | |
737 | 737 | } |
738 | 738 | |
@@ -748,11 +748,11 @@ discard block |
||
748 | 748 | } |
749 | 749 | |
750 | 750 | public function get_network_dataset_ids() { |
751 | - return $this->get( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, array() ); |
|
751 | + return $this->get('wl_advanced_settings', self::NETWORK_DATASET_IDS, array()); |
|
752 | 752 | } |
753 | 753 | |
754 | - public function set_network_dataset_ids( $network_dataset_ids ) { |
|
755 | - $this->set( 'wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids ); |
|
754 | + public function set_network_dataset_ids($network_dataset_ids) { |
|
755 | + $this->set('wl_advanced_settings', self::NETWORK_DATASET_IDS, $network_dataset_ids); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | } |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * @param Default_Api_Service $api_service |
32 | 32 | * @param Cache $cache_service |
33 | 33 | */ |
34 | - public function __construct( $api_service, $cache_service ) { |
|
34 | + public function __construct($api_service, $cache_service) { |
|
35 | 35 | |
36 | 36 | $this->api_service = $api_service; |
37 | 37 | |
38 | 38 | $this->cache_service = $cache_service; |
39 | 39 | |
40 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
40 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param $tag \WP_Term |
49 | 49 | */ |
50 | - public function get_entities( $tag ) { |
|
50 | + public function get_entities($tag) { |
|
51 | 51 | |
52 | 52 | $cache_key = $tag->term_id; |
53 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
54 | - if ( false !== $cache_result ) { |
|
53 | + $cache_result = $this->cache_service->get($cache_key); |
|
54 | + if (false !== $cache_result) { |
|
55 | 55 | return $cache_result; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // send the request. |
59 | 59 | $tag_name = $tag->name; |
60 | 60 | |
61 | - $entities = $this->get_entities_by_search_query( $tag_name ); |
|
61 | + $entities = $this->get_entities_by_search_query($tag_name); |
|
62 | 62 | |
63 | - if ( ! $entities ) { |
|
63 | + if ( ! $entities) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - $this->cache_service->put( $cache_key, $entities ); |
|
67 | + $this->cache_service->put($cache_key, $entities); |
|
68 | 68 | |
69 | 69 | return $entities; |
70 | 70 | |
@@ -77,47 +77,47 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return bool|string |
79 | 79 | */ |
80 | - public static function format_entity_url( $entity_url ) { |
|
81 | - $result = wp_parse_url( $entity_url ); |
|
82 | - if ( ! $result ) { |
|
80 | + public static function format_entity_url($entity_url) { |
|
81 | + $result = wp_parse_url($entity_url); |
|
82 | + if ( ! $result) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | - if ( ! array_key_exists( 'scheme', $result ) |
|
86 | - || ! array_key_exists( 'host', $result ) |
|
87 | - || ! array_key_exists( 'path', $result ) ) { |
|
85 | + if ( ! array_key_exists('scheme', $result) |
|
86 | + || ! array_key_exists('host', $result) |
|
87 | + || ! array_key_exists('path', $result)) { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | |
91 | - return $result['scheme'] . '/' . $result['host'] . $result['path']; |
|
91 | + return $result['scheme'].'/'.$result['host'].$result['path']; |
|
92 | 92 | } |
93 | 93 | |
94 | - private function get_meta( $entity_url ) { |
|
94 | + private function get_meta($entity_url) { |
|
95 | 95 | |
96 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
96 | + $cache_results = $this->cache_service->get($entity_url); |
|
97 | 97 | |
98 | - if ( false !== $cache_results ) { |
|
98 | + if (false !== $cache_results) { |
|
99 | 99 | return $cache_results; |
100 | 100 | } |
101 | 101 | |
102 | - $formatted_url = self::format_entity_url( $entity_url ); |
|
102 | + $formatted_url = self::format_entity_url($entity_url); |
|
103 | 103 | |
104 | - if ( ! $formatted_url ) { |
|
104 | + if ( ! $formatted_url) { |
|
105 | 105 | return array(); |
106 | 106 | } |
107 | 107 | |
108 | - $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
108 | + $meta_url = 'https://api.wordlift.io/id/'.$formatted_url; |
|
109 | 109 | |
110 | - $response = wp_remote_get( $meta_url ); |
|
110 | + $response = wp_remote_get($meta_url); |
|
111 | 111 | |
112 | - if ( is_wp_error( $response ) |
|
113 | - || ! isset( $response['response']['code'] ) |
|
114 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
112 | + if (is_wp_error($response) |
|
113 | + || ! isset($response['response']['code']) |
|
114 | + || 2 !== (int) $response['response']['code'] / 100) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - if ( ! is_wp_error( $response ) ) { |
|
119 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
120 | - $this->cache_service->put( $entity_url, $meta ); |
|
118 | + if ( ! is_wp_error($response)) { |
|
119 | + $meta = json_decode(wp_remote_retrieve_body($response), true); |
|
120 | + $this->cache_service->put($entity_url, $meta); |
|
121 | 121 | |
122 | 122 | return $meta; |
123 | 123 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | |
127 | 127 | } |
128 | 128 | |
129 | - private function get_meta_for_entities( $entities ) { |
|
129 | + private function get_meta_for_entities($entities) { |
|
130 | 130 | |
131 | 131 | $filtered_entities = array(); |
132 | - foreach ( $entities as $entity ) { |
|
132 | + foreach ($entities as $entity) { |
|
133 | 133 | $entity['meta'] = array(); |
134 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
135 | - if ( $meta ) { |
|
136 | - $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
134 | + $meta = $this->get_meta($entity['entityId']); |
|
135 | + if ($meta) { |
|
136 | + $meta = Default_Entity_List::compact_jsonld($meta); |
|
137 | 137 | $entity['meta'] = $meta; |
138 | 138 | $filtered_entities[] = $entity; |
139 | 139 | } |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - public function get_entities_by_search_query( $tag_name ) { |
|
151 | + public function get_entities_by_search_query($tag_name) { |
|
152 | 152 | $response = $this->api_service->request( |
153 | 153 | 'POST', |
154 | 154 | '/analysis/single', |
155 | - array( 'Content-Type' => 'application/json' ), |
|
155 | + array('Content-Type' => 'application/json'), |
|
156 | 156 | wp_json_encode( |
157 | 157 | array( |
158 | 158 | 'content' => $tag_name, |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | ) |
165 | 165 | ); |
166 | 166 | |
167 | - if ( ! $response->is_success() ) { |
|
167 | + if ( ! $response->is_success()) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $response = json_decode( $response->get_body(), true ); |
|
171 | + $response = json_decode($response->get_body(), true); |
|
172 | 172 | |
173 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
173 | + if ( ! array_key_exists('entities', $response)) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
177 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
177 | + $entities = $this->get_meta_for_entities($response['entities']); |
|
178 | 178 | |
179 | 179 | return $entities; |
180 | 180 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function get_scope() { |
183 | 183 | $service = \Wordlift_Configuration_Service::get_instance(); |
184 | 184 | |
185 | - return count( $service->get_network_dataset_ids() ) > 0 ? 'network-only' : 'cloud'; |
|
185 | + return count($service->get_network_dataset_ids()) > 0 ? 'network-only' : 'cloud'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |