@@ -694,7 +694,7 @@ |
||
694 | 694 | if( |
695 | 695 | empty( $this->license ) |
696 | 696 | && ! $this->__is_notice_dismissed( 'general' ) |
697 | - && empty( $showed_invalid_message ) |
|
697 | + && empty( $showed_invalid_message ) |
|
698 | 698 | ) { |
699 | 699 | $messages['general'] = sprintf( |
700 | 700 | __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
17 | -if ( ! class_exists( 'Give_License' ) ) : |
|
17 | +if ( ! class_exists('Give_License')) : |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Give_License Class |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @var string |
105 | 105 | */ |
106 | - private $api_url = 'https://givewp.com/edd-sl-api/'; |
|
106 | + private $api_url = 'https://givewp.com/edd-sl-api/'; |
|
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Account URL |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @var null|string |
115 | 115 | */ |
116 | - private $account_url = 'https://givewp.com/my-account/'; |
|
116 | + private $account_url = 'https://givewp.com/my-account/'; |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Ccheckout URL |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | * @param string $_checkout_url |
143 | 143 | * @param string $_account_url |
144 | 144 | */ |
145 | - public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null ) { |
|
145 | + public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null) { |
|
146 | 146 | $give_options = give_get_settings(); |
147 | 147 | |
148 | 148 | $this->file = $_file; |
149 | 149 | $this->item_name = $_item_name; |
150 | - $this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); |
|
150 | + $this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); |
|
151 | 151 | $this->version = $_version; |
152 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
153 | - $this->license_data = get_option( $this->item_shortname . '_license_active' ); |
|
152 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
153 | + $this->license_data = get_option($this->item_shortname.'_license_active'); |
|
154 | 154 | $this->author = $_author; |
155 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
156 | - $this->checkout_url = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url; |
|
157 | - $this->account_url = is_null( $_account_url ) ? $this->account_url : $_account_url; |
|
155 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
156 | + $this->checkout_url = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url; |
|
157 | + $this->account_url = is_null($_account_url) ? $this->account_url : $_account_url; |
|
158 | 158 | |
159 | 159 | // Setup hooks |
160 | 160 | $this->includes(); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return void |
174 | 174 | */ |
175 | 175 | private function includes() { |
176 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
176 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
177 | 177 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
178 | 178 | } |
179 | 179 | } |
@@ -191,26 +191,26 @@ discard block |
||
191 | 191 | private function hooks() { |
192 | 192 | |
193 | 193 | // Register settings |
194 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
194 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
195 | 195 | |
196 | 196 | // Activate license key on settings save |
197 | - add_action( 'admin_init', array( $this, 'activate_license' ) ); |
|
197 | + add_action('admin_init', array($this, 'activate_license')); |
|
198 | 198 | |
199 | 199 | // Deactivate license key |
200 | - add_action( 'admin_init', array( $this, 'deactivate_license' ) ); |
|
200 | + add_action('admin_init', array($this, 'deactivate_license')); |
|
201 | 201 | |
202 | 202 | // Updater |
203 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
203 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
204 | 204 | |
205 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
205 | + add_action('admin_notices', array($this, 'notices')); |
|
206 | 206 | |
207 | 207 | // Check license weekly. |
208 | - add_action( 'give_weekly_scheduled_events', array( $this, 'weekly_license_check' ) ); |
|
209 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_license_check' ) ); |
|
208 | + add_action('give_weekly_scheduled_events', array($this, 'weekly_license_check')); |
|
209 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_license_check')); |
|
210 | 210 | |
211 | 211 | // Check subscription weekly. |
212 | - add_action( 'give_weekly_scheduled_events', array( $this, 'weekly_subscription_check' ) ); |
|
213 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_subscription_check' ) ); |
|
212 | + add_action('give_weekly_scheduled_events', array($this, 'weekly_subscription_check')); |
|
213 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_subscription_check')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function auto_updater() { |
225 | 225 | |
226 | - if ( ! $this->is_valid_license() ) { |
|
226 | + if ( ! $this->is_valid_license()) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | |
@@ -252,16 +252,16 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return array License settings. |
254 | 254 | */ |
255 | - public function settings( $settings ) { |
|
255 | + public function settings($settings) { |
|
256 | 256 | |
257 | 257 | $give_license_settings = array( |
258 | 258 | array( |
259 | 259 | 'name' => $this->item_name, |
260 | - 'id' => $this->item_shortname . '_license_key', |
|
260 | + 'id' => $this->item_shortname.'_license_key', |
|
261 | 261 | 'desc' => '', |
262 | 262 | 'type' => 'license_key', |
263 | 263 | 'options' => array( |
264 | - 'license' => get_option( $this->item_shortname . '_license_active' ), |
|
264 | + 'license' => get_option($this->item_shortname.'_license_active'), |
|
265 | 265 | 'shortname' => $this->item_shortname, |
266 | 266 | 'item_name' => $this->item_name, |
267 | 267 | 'api_url' => $this->api_url, |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | ) |
273 | 273 | ); |
274 | 274 | |
275 | - return array_merge( $settings, $give_license_settings ); |
|
275 | + return array_merge($settings, $give_license_settings); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -287,18 +287,18 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return array License settings content. |
289 | 289 | */ |
290 | - public function license_settings_content( $settings ) { |
|
290 | + public function license_settings_content($settings) { |
|
291 | 291 | |
292 | 292 | $give_license_settings = array( |
293 | 293 | array( |
294 | - 'name' => esc_html__( 'Add-on Licenses', 'give' ), |
|
294 | + 'name' => esc_html__('Add-on Licenses', 'give'), |
|
295 | 295 | 'desc' => '<hr>', |
296 | 296 | 'type' => 'give_title', |
297 | 297 | 'id' => 'give_title' |
298 | 298 | ), |
299 | 299 | ); |
300 | 300 | |
301 | - return array_merge( $settings, $give_license_settings ); |
|
301 | + return array_merge($settings, $give_license_settings); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -313,37 +313,37 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function activate_license() { |
315 | 315 | // Bailout: Check if license key set of not. |
316 | - if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
316 | + if ( ! isset($_POST[$this->item_shortname.'_license_key'])) { |
|
317 | 317 | return; |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Security check. |
321 | - if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) { |
|
321 | + if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) { |
|
322 | 322 | |
323 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
323 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
324 | 324 | |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Check if user have correct permissions. |
328 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
328 | + if ( ! current_user_can('manage_give_settings')) { |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Allow third party addon developers to handle license activation. |
333 | - if( $this->__is_third_party_addon() ){ |
|
334 | - do_action( 'give_activate_license', $this ); |
|
333 | + if ($this->__is_third_party_addon()) { |
|
334 | + do_action('give_activate_license', $this); |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // Delete previous license setting if a empty license key submitted. |
339 | - if ( empty( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
340 | - delete_option( $this->item_shortname . '_license_active' ); |
|
339 | + if (empty($_POST[$this->item_shortname.'_license_key'])) { |
|
340 | + delete_option($this->item_shortname.'_license_active'); |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Do not simultaneously activate any addon if user want to deactivate any addon. |
345 | - foreach ( $_POST as $key => $value ) { |
|
346 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
345 | + foreach ($_POST as $key => $value) { |
|
346 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
347 | 347 | // Don't activate a key when deactivating a different key |
348 | 348 | return; |
349 | 349 | } |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | |
352 | 352 | |
353 | 353 | // Check if plugin previously installed. |
354 | - if ( $this->is_valid_license() ) { |
|
354 | + if ($this->is_valid_license()) { |
|
355 | 355 | return; |
356 | 356 | } |
357 | 357 | |
358 | 358 | // Get license key. |
359 | - $license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
359 | + $license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
360 | 360 | |
361 | 361 | // Bailout. |
362 | - if( empty( $license ) ) { |
|
362 | + if (empty($license)) { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $api_params = array( |
371 | 371 | 'edd_action' => 'activate_license', //never change from "edd_" to "give_"! |
372 | 372 | 'license' => $license, |
373 | - 'item_name' => urlencode( $this->item_name ), |
|
373 | + 'item_name' => urlencode($this->item_name), |
|
374 | 374 | 'url' => home_url() |
375 | 375 | ); |
376 | 376 | |
@@ -385,16 +385,16 @@ discard block |
||
385 | 385 | ); |
386 | 386 | |
387 | 387 | // Make sure there are no errors |
388 | - if ( is_wp_error( $response ) ) { |
|
388 | + if (is_wp_error($response)) { |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | // Tell WordPress to look for updates |
393 | - set_site_transient( 'update_plugins', null ); |
|
393 | + set_site_transient('update_plugins', null); |
|
394 | 394 | |
395 | 395 | // Decode license data |
396 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
397 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
396 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
397 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
398 | 398 | |
399 | 399 | // Check subscription for license key and store this to db (if any). |
400 | 400 | $this->__single_subscription_check(); |
@@ -412,34 +412,34 @@ discard block |
||
412 | 412 | */ |
413 | 413 | public function deactivate_license() { |
414 | 414 | |
415 | - if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
415 | + if ( ! isset($_POST[$this->item_shortname.'_license_key'])) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) { |
|
419 | + if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) { |
|
420 | 420 | |
421 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
421 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
425 | + if ( ! current_user_can('manage_give_settings')) { |
|
426 | 426 | return; |
427 | 427 | } |
428 | 428 | |
429 | 429 | // Allow third party add-on developers to handle license deactivation. |
430 | - if( $this->__is_third_party_addon() ){ |
|
431 | - do_action( 'give_deactivate_license', $this ); |
|
430 | + if ($this->__is_third_party_addon()) { |
|
431 | + do_action('give_deactivate_license', $this); |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // Run on deactivate button press |
436 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
436 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
437 | 437 | |
438 | 438 | // Data to send to the API |
439 | 439 | $api_params = array( |
440 | 440 | 'edd_action' => 'deactivate_license', //never change from "edd_" to "give_"! |
441 | 441 | 'license' => $this->license, |
442 | - 'item_name' => urlencode( $this->item_name ), |
|
442 | + 'item_name' => urlencode($this->item_name), |
|
443 | 443 | 'url' => home_url() |
444 | 444 | ); |
445 | 445 | |
@@ -454,15 +454,15 @@ discard block |
||
454 | 454 | ); |
455 | 455 | |
456 | 456 | // Make sure there are no errors |
457 | - if ( is_wp_error( $response ) ) { |
|
457 | + if (is_wp_error($response)) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Decode the license data |
462 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
462 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
463 | 463 | |
464 | 464 | // Remove license data. |
465 | - delete_option( $this->item_shortname . '_license_active' ); |
|
465 | + delete_option($this->item_shortname.'_license_active'); |
|
466 | 466 | |
467 | 467 | // Remove license key from subscriptions if exist. |
468 | 468 | $this->__remove_license_key_from_subscriptions(); |
@@ -479,18 +479,18 @@ discard block |
||
479 | 479 | */ |
480 | 480 | public function weekly_license_check() { |
481 | 481 | |
482 | - if( ! empty( $_POST['give_settings'] ) ) { |
|
482 | + if ( ! empty($_POST['give_settings'])) { |
|
483 | 483 | // Don't fire when saving settings |
484 | 484 | return false; |
485 | 485 | } |
486 | 486 | |
487 | - if( empty( $this->license ) ) { |
|
487 | + if (empty($this->license)) { |
|
488 | 488 | return false; |
489 | 489 | } |
490 | 490 | |
491 | 491 | // Allow third party add-on developers to handle their license check. |
492 | - if( $this->__is_third_party_addon() ){ |
|
493 | - do_action( 'give_weekly_license_check', $this ); |
|
492 | + if ($this->__is_third_party_addon()) { |
|
493 | + do_action('give_weekly_license_check', $this); |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | $api_params = array( |
499 | 499 | 'edd_action'=> 'check_license', |
500 | 500 | 'license' => $this->license, |
501 | - 'item_name' => urlencode( $this->item_name ), |
|
501 | + 'item_name' => urlencode($this->item_name), |
|
502 | 502 | 'url' => home_url() |
503 | 503 | ); |
504 | 504 | |
@@ -513,12 +513,12 @@ discard block |
||
513 | 513 | ); |
514 | 514 | |
515 | 515 | // Make sure the response came back okay. |
516 | - if ( is_wp_error( $response ) ) { |
|
516 | + if (is_wp_error($response)) { |
|
517 | 517 | return false; |
518 | 518 | } |
519 | 519 | |
520 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
521 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
520 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
521 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -531,24 +531,24 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public function weekly_subscription_check() { |
533 | 533 | |
534 | - if( ! empty( $_POST['give_settings'] ) ) { |
|
534 | + if ( ! empty($_POST['give_settings'])) { |
|
535 | 535 | // Don't fire when saving settings |
536 | 536 | return false; |
537 | 537 | } |
538 | 538 | |
539 | 539 | // Remove old subscription data. |
540 | - if( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp' , 1 ) ){ |
|
541 | - delete_option( 'give_subscriptions' ); |
|
542 | - update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp' , 1 ) ) ); |
|
540 | + if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) { |
|
541 | + delete_option('give_subscriptions'); |
|
542 | + update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1))); |
|
543 | 543 | } |
544 | 544 | |
545 | - if( empty( $this->license ) ) { |
|
545 | + if (empty($this->license)) { |
|
546 | 546 | return false; |
547 | 547 | } |
548 | 548 | |
549 | 549 | // Allow third party add-on developers to handle their subscription check. |
550 | - if( $this->__is_third_party_addon() ){ |
|
551 | - do_action( 'give_weekly_subscription_check', $this ); |
|
550 | + if ($this->__is_third_party_addon()) { |
|
551 | + do_action('give_weekly_subscription_check', $this); |
|
552 | 552 | return false; |
553 | 553 | } |
554 | 554 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | // This is a custom feature to check subscriptions. |
563 | 563 | 'edd_action'=> 'check_subscription', |
564 | 564 | 'license' => $this->license, |
565 | - 'item_name' => urlencode( $this->item_name ), |
|
565 | + 'item_name' => urlencode($this->item_name), |
|
566 | 566 | 'url' => home_url() |
567 | 567 | ); |
568 | 568 | |
@@ -577,27 +577,27 @@ discard block |
||
577 | 577 | ); |
578 | 578 | |
579 | 579 | // Make sure the response came back okay. |
580 | - if ( is_wp_error( $response ) ) { |
|
580 | + if (is_wp_error($response)) { |
|
581 | 581 | return false; |
582 | 582 | } |
583 | 583 | |
584 | - $subscription_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
584 | + $subscription_data = json_decode(wp_remote_retrieve_body($response), true); |
|
585 | 585 | |
586 | - if( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
587 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
586 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
587 | + $subscriptions = get_option('give_subscriptions', array()); |
|
588 | 588 | |
589 | 589 | // Update subscription data only if subscription does not exist already. |
590 | - if( ! array_key_exists( $subscription_data['id'], $subscriptions ) ) { |
|
591 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
592 | - $subscriptions[ $subscription_data['id'] ]['licenses'] = array(); |
|
590 | + if ( ! array_key_exists($subscription_data['id'], $subscriptions)) { |
|
591 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
592 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | // Store licenses for subscription. |
596 | - if( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
597 | - $subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license; |
|
596 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
597 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
598 | 598 | } |
599 | 599 | |
600 | - update_option( 'give_subscriptions', $subscriptions ); |
|
600 | + update_option('give_subscriptions', $subscriptions); |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | |
@@ -611,11 +611,11 @@ discard block |
||
611 | 611 | */ |
612 | 612 | private function __single_subscription_check() { |
613 | 613 | // Do not fire if license key is not set. |
614 | - if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
614 | + if ( ! isset($_POST[$this->item_shortname.'_license_key'])) { |
|
615 | 615 | return false; |
616 | 616 | } |
617 | 617 | |
618 | - if( empty( $this->license ) ) { |
|
618 | + if (empty($this->license)) { |
|
619 | 619 | return false; |
620 | 620 | } |
621 | 621 | |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | // This is a custom feature to check subscriptions. |
627 | 627 | 'edd_action'=> 'check_subscription', |
628 | 628 | 'license' => $this->license, |
629 | - 'item_name' => urlencode( $this->item_name ), |
|
629 | + 'item_name' => urlencode($this->item_name), |
|
630 | 630 | 'url' => home_url() |
631 | 631 | ); |
632 | 632 | |
@@ -641,27 +641,27 @@ discard block |
||
641 | 641 | ); |
642 | 642 | |
643 | 643 | // Make sure the response came back okay. |
644 | - if ( is_wp_error( $response ) ) { |
|
644 | + if (is_wp_error($response)) { |
|
645 | 645 | return false; |
646 | 646 | } |
647 | 647 | |
648 | - $subscription_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
648 | + $subscription_data = json_decode(wp_remote_retrieve_body($response), true); |
|
649 | 649 | |
650 | - if( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
651 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
650 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
651 | + $subscriptions = get_option('give_subscriptions', array()); |
|
652 | 652 | |
653 | 653 | // Update subscription data only if subscription does not exist already. |
654 | - if( ! array_key_exists( $subscription_data['id'], $subscriptions ) ) { |
|
655 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
656 | - $subscriptions[ $subscription_data['id'] ]['licenses'] = array(); |
|
654 | + if ( ! array_key_exists($subscription_data['id'], $subscriptions)) { |
|
655 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
656 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // Store licenses for subscription. |
660 | - if( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
661 | - $subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license; |
|
660 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
661 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
662 | 662 | } |
663 | 663 | |
664 | - update_option( 'give_subscriptions', $subscriptions ); |
|
664 | + update_option('give_subscriptions', $subscriptions); |
|
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
@@ -674,12 +674,12 @@ discard block |
||
674 | 674 | * @return void |
675 | 675 | */ |
676 | 676 | public function notices() { |
677 | - if( ! current_user_can( 'manage_give_settings' ) ) { |
|
677 | + if ( ! current_user_can('manage_give_settings')) { |
|
678 | 678 | return; |
679 | 679 | } |
680 | 680 | |
681 | 681 | // Do not show licenses notices on license tab. |
682 | - if( 'licenses' === give_get_current_setting_tab() ) { |
|
682 | + if ('licenses' === give_get_current_setting_tab()) { |
|
683 | 683 | return; |
684 | 684 | } |
685 | 685 | |
@@ -688,93 +688,93 @@ discard block |
||
688 | 688 | static $addon_license_key_in_subscriptions; |
689 | 689 | |
690 | 690 | // Set default value. |
691 | - $addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array(); |
|
691 | + $addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array(); |
|
692 | 692 | $messages = array(); |
693 | 693 | |
694 | - if( |
|
695 | - empty( $this->license ) |
|
696 | - && ! $this->__is_notice_dismissed( 'general' ) |
|
697 | - && empty( $showed_invalid_message ) |
|
694 | + if ( |
|
695 | + empty($this->license) |
|
696 | + && ! $this->__is_notice_dismissed('general') |
|
697 | + && empty($showed_invalid_message) |
|
698 | 698 | ) { |
699 | 699 | $messages['general'] = sprintf( |
700 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
701 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
700 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
701 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
702 | 702 | ); |
703 | 703 | $showed_invalid_message = true; |
704 | 704 | |
705 | 705 | } |
706 | 706 | |
707 | 707 | // Get subscriptions. |
708 | - $subscriptions = get_option( 'give_subscriptions' ); |
|
708 | + $subscriptions = get_option('give_subscriptions'); |
|
709 | 709 | |
710 | 710 | // Show subscription messages. |
711 | - if( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) { |
|
711 | + if ( ! empty($subscriptions) && ! $showed_subscriptions_message) { |
|
712 | 712 | |
713 | - foreach ( $subscriptions as $subscription ) { |
|
713 | + foreach ($subscriptions as $subscription) { |
|
714 | 714 | // Subscription expires timestamp. |
715 | - $subscription_expires = strtotime( $subscription['expires'] ); |
|
715 | + $subscription_expires = strtotime($subscription['expires']); |
|
716 | 716 | |
717 | 717 | // Start showing subscriptions message before one week of renewal date. |
718 | - if( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) { |
|
718 | + if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) { |
|
719 | 719 | continue; |
720 | 720 | } |
721 | 721 | |
722 | 722 | // Check if subscription message already exist in messages. |
723 | - if( array_key_exists( $subscription['id'], $messages ) ) { |
|
723 | + if (array_key_exists($subscription['id'], $messages)) { |
|
724 | 724 | continue; |
725 | 725 | } |
726 | 726 | |
727 | - if( ( ! $this->__is_notice_dismissed( $subscription['id'] ) && 'active' !== $subscription['status'] ) ) { |
|
727 | + if (( ! $this->__is_notice_dismissed($subscription['id']) && 'active' !== $subscription['status'])) { |
|
728 | 728 | |
729 | - if( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) {// Check if license already expired. |
|
729 | + if (strtotime($subscription['expires']) < current_time('timestamp', 1)) {// Check if license already expired. |
|
730 | 730 | $messages[$subscription['id']] = sprintf( |
731 | - __( 'Your Give add-on license expired for payment <a href="%s" target="_blank">#%d</a>. <a href="%s" target="_blank">Click to renew an existing license</a> or <a href="%s">Click here if already renewed</a>.', 'give' ), |
|
732 | - urldecode( $subscription['invoice_url'] ), |
|
731 | + __('Your Give add-on license expired for payment <a href="%s" target="_blank">#%d</a>. <a href="%s" target="_blank">Click to renew an existing license</a> or <a href="%s">Click here if already renewed</a>.', 'give'), |
|
732 | + urldecode($subscription['invoice_url']), |
|
733 | 733 | $subscription['payment_id'], |
734 | 734 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
735 | - esc_url( add_query_arg( '_give_hide_license_notices_permanently', $subscription['id'], $_SERVER['REQUEST_URI'] ) ) |
|
735 | + esc_url(add_query_arg('_give_hide_license_notices_permanently', $subscription['id'], $_SERVER['REQUEST_URI'])) |
|
736 | 736 | ); |
737 | - }else{ |
|
737 | + } else { |
|
738 | 738 | $messages[$subscription['id']] = sprintf( |
739 | - __( 'Your Give add-on license will expire in %s for payment <a href="%s" target="_blank">#%d</a>. <a href="%s" target="_blank">Click to renew an existing license</a> or <a href="%s">Click here if already renewed</a>.', 'give' ), |
|
740 | - human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |
|
741 | - urldecode( $subscription['invoice_url'] ), |
|
739 | + __('Your Give add-on license will expire in %s for payment <a href="%s" target="_blank">#%d</a>. <a href="%s" target="_blank">Click to renew an existing license</a> or <a href="%s">Click here if already renewed</a>.', 'give'), |
|
740 | + human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])), |
|
741 | + urldecode($subscription['invoice_url']), |
|
742 | 742 | $subscription['payment_id'], |
743 | 743 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
744 | - esc_url( add_query_arg( '_give_hide_license_notices_permanently', $subscription['id'], $_SERVER['REQUEST_URI'] ) ) |
|
744 | + esc_url(add_query_arg('_give_hide_license_notices_permanently', $subscription['id'], $_SERVER['REQUEST_URI'])) |
|
745 | 745 | ); |
746 | 746 | } |
747 | 747 | } |
748 | 748 | |
749 | 749 | // Stop validation for these license keys. |
750 | - $addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] ); |
|
750 | + $addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']); |
|
751 | 751 | } |
752 | 752 | $showed_subscriptions_message = true; |
753 | 753 | } |
754 | 754 | |
755 | 755 | // Show non subscription addon messages. |
756 | - if( |
|
757 | - ! in_array( $this->license, $addon_license_key_in_subscriptions ) |
|
758 | - && ! $this->__is_notice_dismissed( 'general' ) |
|
756 | + if ( |
|
757 | + ! in_array($this->license, $addon_license_key_in_subscriptions) |
|
758 | + && ! $this->__is_notice_dismissed('general') |
|
759 | 759 | && ! $this->is_valid_license() |
760 | - && empty( $showed_invalid_message ) |
|
760 | + && empty($showed_invalid_message) |
|
761 | 761 | ) { |
762 | 762 | |
763 | 763 | $messages['general'] = sprintf( |
764 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
765 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
764 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
765 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
766 | 766 | ); |
767 | 767 | $showed_invalid_message = true; |
768 | 768 | |
769 | 769 | } |
770 | 770 | |
771 | 771 | // Print messages. |
772 | - if( ! empty( $messages ) ) { |
|
773 | - foreach( $messages as $notice_id => $message ) { |
|
772 | + if ( ! empty($messages)) { |
|
773 | + foreach ($messages as $notice_id => $message) { |
|
774 | 774 | |
775 | 775 | echo sprintf( |
776 | 776 | '<div class="notice notice-error is-dismissible give-license-notice" data-dismiss-notice-shortly="%1$s"><p>%2$s</p></div>', |
777 | - esc_url( add_query_arg( '_give_hide_license_notices_shortly', $notice_id, $_SERVER['REQUEST_URI'] ) ), |
|
777 | + esc_url(add_query_arg('_give_hide_license_notices_shortly', $notice_id, $_SERVER['REQUEST_URI'])), |
|
778 | 778 | $message |
779 | 779 | ); |
780 | 780 | } |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * @return bool |
791 | 791 | */ |
792 | 792 | public function is_valid_license() { |
793 | - if( apply_filters( 'give_is_valid_license' , ( is_object( $this->license_data ) && ! empty( $this->license_data ) && property_exists( $this->license_data, 'license' )&& 'valid' === $this->license_data->license ) ) ) { |
|
793 | + if (apply_filters('give_is_valid_license', (is_object($this->license_data) && ! empty($this->license_data) && property_exists($this->license_data, 'license') && 'valid' === $this->license_data->license))) { |
|
794 | 794 | return true; |
795 | 795 | } |
796 | 796 | |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | * @return bool |
807 | 807 | */ |
808 | 808 | private function __is_third_party_addon() { |
809 | - return ( false === strpos( $this->api_url, 'givewp.com/' ) ); |
|
809 | + return (false === strpos($this->api_url, 'givewp.com/')); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -820,26 +820,26 @@ discard block |
||
820 | 820 | * |
821 | 821 | * @return void|bool |
822 | 822 | */ |
823 | - private function __remove_license_key_from_subscriptions(){ |
|
824 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
823 | + private function __remove_license_key_from_subscriptions() { |
|
824 | + $subscriptions = get_option('give_subscriptions', array()); |
|
825 | 825 | |
826 | 826 | // Bailout. |
827 | - if( empty( $this->license ) ) { |
|
827 | + if (empty($this->license)) { |
|
828 | 828 | return false; |
829 | 829 | } |
830 | 830 | |
831 | - if( ! empty( $subscriptions ) ) { |
|
832 | - foreach ( $subscriptions as $subscription_id => $subscription ) { |
|
833 | - $license_index = array_search( $this->license, $subscription['licenses'] ); |
|
834 | - if( false !== $license_index ) { |
|
831 | + if ( ! empty($subscriptions)) { |
|
832 | + foreach ($subscriptions as $subscription_id => $subscription) { |
|
833 | + $license_index = array_search($this->license, $subscription['licenses']); |
|
834 | + if (false !== $license_index) { |
|
835 | 835 | // Remove license key. |
836 | - unset( $subscriptions[ $subscription_id ]['licenses'][$license_index] ); |
|
836 | + unset($subscriptions[$subscription_id]['licenses'][$license_index]); |
|
837 | 837 | |
838 | 838 | // Rearrange license keys. |
839 | - $subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] ); |
|
839 | + $subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']); |
|
840 | 840 | |
841 | 841 | // Update subscription information. |
842 | - update_option( 'give_subscriptions', $subscriptions ); |
|
842 | + update_option('give_subscriptions', $subscriptions); |
|
843 | 843 | break; |
844 | 844 | } |
845 | 845 | } |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | * |
855 | 855 | * @return void |
856 | 856 | */ |
857 | - private function __remove_license_notices_show_blocker(){ |
|
857 | + private function __remove_license_notices_show_blocker() { |
|
858 | 858 | global $wpdb; |
859 | 859 | |
860 | 860 | // Delete permanent notice blocker. |
@@ -892,21 +892,21 @@ discard block |
||
892 | 892 | * |
893 | 893 | * @return bool |
894 | 894 | */ |
895 | - private function __is_notice_dismissed( $notice_id ){ |
|
895 | + private function __is_notice_dismissed($notice_id) { |
|
896 | 896 | $current_user = wp_get_current_user(); |
897 | 897 | $is_notice_dismissed = false; |
898 | 898 | |
899 | 899 | // Ge is notice dismissed permanently. |
900 | - $already_dismiss_notices = ( $already_dismiss_notices = get_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', true ) ) |
|
900 | + $already_dismiss_notices = ($already_dismiss_notices = get_user_meta($current_user->ID, '_give_hide_license_notices_permanently', true)) |
|
901 | 901 | ? $already_dismiss_notices |
902 | 902 | : array(); |
903 | 903 | |
904 | 904 | |
905 | - if( |
|
906 | - in_array( $notice_id, $already_dismiss_notices ) |
|
907 | - || Give_Cache::get( "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}", true ) |
|
905 | + if ( |
|
906 | + in_array($notice_id, $already_dismiss_notices) |
|
907 | + || Give_Cache::get("_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}", true) |
|
908 | 908 | ) { |
909 | - $is_notice_dismissed = true; |
|
909 | + $is_notice_dismissed = true; |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | return $is_notice_dismissed; |
@@ -734,7 +734,7 @@ |
||
734 | 734 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
735 | 735 | esc_url( add_query_arg( '_give_hide_license_notices_permanently', $subscription['id'], $_SERVER['REQUEST_URI'] ) ) |
736 | 736 | ); |
737 | - }else{ |
|
737 | + } else{ |
|
738 | 738 | $messages[$subscription['id']] = sprintf( |
739 | 739 | __( 'Your Give add-on license will expire in %s for payment <a href="%s" target="_blank">#%d</a>. <a href="%s" target="_blank">Click to renew an existing license</a> or <a href="%s">Click here if already renewed</a>.', 'give' ), |
740 | 740 | human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |