@@ -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 |
@@ -177,37 +177,37 @@ discard block |
||
177 | 177 | ) { |
178 | 178 | |
179 | 179 | // Only load in wp-admin. |
180 | - if ( ! is_admin() ) { |
|
180 | + if ( ! is_admin()) { |
|
181 | 181 | return; |
182 | 182 | } |
183 | 183 | |
184 | - if ( is_numeric( $_item_id ) ) { |
|
185 | - $this->item_id = absint( $_item_id ); |
|
184 | + if (is_numeric($_item_id)) { |
|
185 | + $this->item_id = absint($_item_id); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | $give_options = give_get_settings(); |
189 | 189 | |
190 | 190 | $this->file = $_file; |
191 | 191 | $this->item_name = $_item_name; |
192 | - $this->item_shortname = self::get_short_name( $this->item_name ); |
|
192 | + $this->item_shortname = self::get_short_name($this->item_name); |
|
193 | 193 | $this->version = $_version; |
194 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
195 | - $this->license_data = __give_get_active_license_info( $this->item_shortname ); |
|
194 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
195 | + $this->license_data = __give_get_active_license_info($this->item_shortname); |
|
196 | 196 | $this->author = $_author; |
197 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
198 | - $this->checkout_url = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url; |
|
199 | - $this->account_url = is_null( $_account_url ) ? $this->account_url : $_account_url; |
|
197 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
198 | + $this->checkout_url = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url; |
|
199 | + $this->account_url = is_null($_account_url) ? $this->account_url : $_account_url; |
|
200 | 200 | $this->auto_updater_obj = null; |
201 | 201 | |
202 | 202 | // Add Setting for Give Add-on activation status. |
203 | - $is_addon_activated = get_option( 'give_is_addon_activated' ); |
|
204 | - if ( ! $is_addon_activated && is_object( $this ) ) { |
|
205 | - update_option( 'give_is_addon_activated', true, false ); |
|
206 | - Give_Cache::set( 'give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS ); |
|
203 | + $is_addon_activated = get_option('give_is_addon_activated'); |
|
204 | + if ( ! $is_addon_activated && is_object($this)) { |
|
205 | + update_option('give_is_addon_activated', true, false); |
|
206 | + Give_Cache::set('give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | // Add plugin to registered licenses list. |
210 | - array_push( self::$licensed_addons, plugin_basename( $this->file ) ); |
|
210 | + array_push(self::$licensed_addons, plugin_basename($this->file)); |
|
211 | 211 | |
212 | 212 | // Setup hooks |
213 | 213 | $this->includes(); |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public static function get_short_name( $plugin_name ) { |
|
230 | - $plugin_name = trim( str_replace( 'Give - ', '', $plugin_name ) ); |
|
231 | - $plugin_name = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $plugin_name ) ) ); |
|
229 | + public static function get_short_name($plugin_name) { |
|
230 | + $plugin_name = trim(str_replace('Give - ', '', $plugin_name)); |
|
231 | + $plugin_name = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($plugin_name))); |
|
232 | 232 | |
233 | 233 | return $plugin_name; |
234 | 234 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | private function includes() { |
247 | 247 | |
248 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
248 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
249 | 249 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
250 | 250 | } |
251 | 251 | } |
@@ -263,28 +263,28 @@ discard block |
||
263 | 263 | private function hooks() { |
264 | 264 | |
265 | 265 | // Register settings. |
266 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
266 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
267 | 267 | |
268 | 268 | // Activate license key on settings save. |
269 | - add_action( 'admin_init', array( $this, 'activate_license' ), 10 ); |
|
269 | + add_action('admin_init', array($this, 'activate_license'), 10); |
|
270 | 270 | |
271 | 271 | // Deactivate license key. |
272 | - add_action( 'admin_init', array( $this, 'deactivate_license' ), 11 ); |
|
272 | + add_action('admin_init', array($this, 'deactivate_license'), 11); |
|
273 | 273 | |
274 | 274 | // Updater. |
275 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
276 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
275 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
276 | + add_action('admin_notices', array($this, 'notices')); |
|
277 | 277 | |
278 | 278 | // Check license weekly. |
279 | - Give_Cron::add_weekly_event( array( $this, 'weekly_license_check' ) ); |
|
279 | + Give_Cron::add_weekly_event(array($this, 'weekly_license_check')); |
|
280 | 280 | |
281 | 281 | // Check subscription weekly. |
282 | - Give_Cron::add_weekly_event( array( $this, 'weekly_subscription_check' ) ); |
|
282 | + Give_Cron::add_weekly_event(array($this, 'weekly_subscription_check')); |
|
283 | 283 | |
284 | 284 | // Show addon notice on plugin page. |
285 | - $plugin_name = explode( 'plugins/', $this->file ); |
|
286 | - $plugin_name = end( $plugin_name ); |
|
287 | - add_action( "after_plugin_row_{$plugin_name}", array( $this, 'plugin_page_notices' ), 10, 3 ); |
|
285 | + $plugin_name = explode('plugins/', $this->file); |
|
286 | + $plugin_name = end($plugin_name); |
|
287 | + add_action("after_plugin_row_{$plugin_name}", array($this, 'plugin_page_notices'), 10, 3); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function auto_updater() { |
301 | 301 | |
302 | - if ( ! empty( $this->item_id ) ) { |
|
302 | + if ( ! empty($this->item_id)) { |
|
303 | 303 | $args['item_id'] = $this->item_id; |
304 | 304 | } else { |
305 | 305 | $args['item_name'] = $this->item_name; |
@@ -330,16 +330,16 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @return array License settings. |
332 | 332 | */ |
333 | - public function settings( $settings ) { |
|
333 | + public function settings($settings) { |
|
334 | 334 | |
335 | 335 | $give_license_settings = array( |
336 | 336 | array( |
337 | 337 | 'name' => $this->item_name, |
338 | - 'id' => $this->item_shortname . '_license_key', |
|
338 | + 'id' => $this->item_shortname.'_license_key', |
|
339 | 339 | 'desc' => '', |
340 | 340 | 'type' => 'license_key', |
341 | 341 | 'options' => array( |
342 | - 'license' => get_option( $this->item_shortname . '_license_active' ), |
|
342 | + 'license' => get_option($this->item_shortname.'_license_active'), |
|
343 | 343 | 'shortname' => $this->item_shortname, |
344 | 344 | 'item_name' => $this->item_name, |
345 | 345 | 'api_url' => $this->api_url, |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | ), |
351 | 351 | ); |
352 | 352 | |
353 | - return array_merge( $settings, $give_license_settings ); |
|
353 | + return array_merge($settings, $give_license_settings); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -365,18 +365,18 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @return array License settings content. |
367 | 367 | */ |
368 | - public function license_settings_content( $settings ) { |
|
368 | + public function license_settings_content($settings) { |
|
369 | 369 | |
370 | 370 | $give_license_settings = array( |
371 | 371 | array( |
372 | - 'name' => __( 'Add-on Licenses', 'give' ), |
|
372 | + 'name' => __('Add-on Licenses', 'give'), |
|
373 | 373 | 'desc' => '<hr>', |
374 | 374 | 'type' => 'give_title', |
375 | 375 | 'id' => 'give_title', |
376 | 376 | ), |
377 | 377 | ); |
378 | 378 | |
379 | - return array_merge( $settings, $give_license_settings ); |
|
379 | + return array_merge($settings, $give_license_settings); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -391,62 +391,62 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function activate_license() { |
393 | 393 | // Bailout. |
394 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
394 | + if ( ! $this->__is_user_can_edit_license()) { |
|
395 | 395 | return; |
396 | 396 | } |
397 | 397 | |
398 | 398 | // Allow third party addon developers to handle license activation. |
399 | - if ( $this->__is_third_party_addon() ) { |
|
400 | - do_action( 'give_activate_license', $this ); |
|
399 | + if ($this->__is_third_party_addon()) { |
|
400 | + do_action('give_activate_license', $this); |
|
401 | 401 | |
402 | 402 | return; |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Delete previous license setting if a empty license key submitted. |
406 | - if ( empty( $_POST[ "{$this->item_shortname}_license_key" ] ) ) { |
|
406 | + if (empty($_POST["{$this->item_shortname}_license_key"])) { |
|
407 | 407 | $this->unset_license(); |
408 | 408 | |
409 | 409 | return; |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Do not simultaneously activate add-ons if the user want to deactivate a specific add-on. |
413 | - if ( $this->is_deactivating_license() ) { |
|
413 | + if ($this->is_deactivating_license()) { |
|
414 | 414 | return; |
415 | 415 | } |
416 | 416 | |
417 | 417 | // Check if plugin previously installed. |
418 | - if ( $this->is_valid_license() ) { |
|
418 | + if ($this->is_valid_license()) { |
|
419 | 419 | return; |
420 | 420 | } |
421 | 421 | |
422 | 422 | // Get license key. |
423 | - $this->license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
423 | + $this->license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
424 | 424 | |
425 | 425 | // Delete previous license key from subscription if previously added. |
426 | 426 | $this->__remove_license_key_from_subscriptions(); |
427 | 427 | |
428 | 428 | // Make sure there are no api errors. |
429 | - if ( ! ( $license_data = $this->get_license_info( 'activate_license' ) ) ) { |
|
429 | + if ( ! ($license_data = $this->get_license_info('activate_license'))) { |
|
430 | 430 | return; |
431 | 431 | } |
432 | 432 | |
433 | 433 | // Make sure license is valid. |
434 | 434 | // return because admin will want to activate license again. |
435 | - if ( ! $this->is_license( $license_data ) ) { |
|
435 | + if ( ! $this->is_license($license_data)) { |
|
436 | 436 | // Add license key. |
437 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
437 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
438 | 438 | |
439 | 439 | return; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Tell WordPress to look for updates. |
443 | - set_site_transient( 'update_plugins', null ); |
|
443 | + set_site_transient('update_plugins', null); |
|
444 | 444 | |
445 | 445 | // Add license data. |
446 | - update_option( "{$this->item_shortname}_license_active", $license_data, false ); |
|
446 | + update_option("{$this->item_shortname}_license_active", $license_data, false); |
|
447 | 447 | |
448 | 448 | // Add license key. |
449 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
449 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
450 | 450 | |
451 | 451 | // Check subscription for license key and store this to db (if any). |
452 | 452 | $this->__single_subscription_check(); |
@@ -464,19 +464,19 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function deactivate_license() { |
466 | 466 | // Bailout. |
467 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
467 | + if ( ! $this->__is_user_can_edit_license()) { |
|
468 | 468 | return; |
469 | 469 | } |
470 | 470 | |
471 | 471 | // Allow third party add-on developers to handle license deactivation. |
472 | - if ( $this->__is_third_party_addon() ) { |
|
473 | - do_action( 'give_deactivate_license', $this ); |
|
472 | + if ($this->__is_third_party_addon()) { |
|
473 | + do_action('give_deactivate_license', $this); |
|
474 | 474 | |
475 | 475 | return; |
476 | 476 | } |
477 | 477 | |
478 | 478 | // Run on deactivate button press. |
479 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
479 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
480 | 480 | $this->unset_license(); |
481 | 481 | } |
482 | 482 | } |
@@ -492,30 +492,30 @@ discard block |
||
492 | 492 | public function weekly_license_check() { |
493 | 493 | |
494 | 494 | if ( |
495 | - ! empty( $_POST['give_settings'] ) || |
|
496 | - empty( $this->license ) |
|
495 | + ! empty($_POST['give_settings']) || |
|
496 | + empty($this->license) |
|
497 | 497 | ) { |
498 | 498 | return; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // Allow third party add-on developers to handle their license check. |
502 | - if ( $this->__is_third_party_addon() ) { |
|
503 | - do_action( 'give_weekly_license_check', $this ); |
|
502 | + if ($this->__is_third_party_addon()) { |
|
503 | + do_action('give_weekly_license_check', $this); |
|
504 | 504 | |
505 | 505 | return; |
506 | 506 | } |
507 | 507 | |
508 | 508 | // Make sure there are no api errors. |
509 | - if ( ! ( $license_data = $this->get_license_info( 'check_license' ) ) ) { |
|
509 | + if ( ! ($license_data = $this->get_license_info('check_license'))) { |
|
510 | 510 | return; |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Bailout. |
514 | - if ( ! $this->is_license( $license_data ) ) { |
|
514 | + if ( ! $this->is_license($license_data)) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | |
518 | - update_option( $this->item_shortname . '_license_active', $license_data, false ); |
|
518 | + update_option($this->item_shortname.'_license_active', $license_data, false); |
|
519 | 519 | |
520 | 520 | return; |
521 | 521 | } |
@@ -531,21 +531,21 @@ discard block |
||
531 | 531 | public function weekly_subscription_check() { |
532 | 532 | // Bailout. |
533 | 533 | if ( |
534 | - ! empty( $_POST['give_settings'] ) |
|
535 | - || empty( $this->license ) |
|
534 | + ! empty($_POST['give_settings']) |
|
535 | + || empty($this->license) |
|
536 | 536 | ) { |
537 | 537 | return; |
538 | 538 | } |
539 | 539 | |
540 | 540 | // Remove old subscription data. |
541 | - if ( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp', 1 ) ) { |
|
542 | - delete_option( 'give_subscriptions' ); |
|
543 | - update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp', 1 ) ), false ); |
|
541 | + if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) { |
|
542 | + delete_option('give_subscriptions'); |
|
543 | + update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1)), false); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | // Allow third party add-on developers to handle their subscription check. |
547 | - if ( $this->__is_third_party_addon() ) { |
|
548 | - do_action( 'give_weekly_subscription_check', $this ); |
|
547 | + if ($this->__is_third_party_addon()) { |
|
548 | + do_action('give_weekly_subscription_check', $this); |
|
549 | 549 | |
550 | 550 | return; |
551 | 551 | } |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | * @return void |
563 | 563 | */ |
564 | 564 | private function __single_subscription_check() { |
565 | - if ( empty( $this->license ) ) { |
|
565 | + if (empty($this->license)) { |
|
566 | 566 | return; |
567 | 567 | } |
568 | 568 | |
@@ -573,26 +573,26 @@ discard block |
||
573 | 573 | * By default edd software licensing api does not have api to check subscription. |
574 | 574 | * This is a custom feature to check subscriptions. |
575 | 575 | */ |
576 | - $subscription_data = $this->get_license_info( 'check_subscription', true ); |
|
576 | + $subscription_data = $this->get_license_info('check_subscription', true); |
|
577 | 577 | |
578 | - if ( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
578 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
579 | 579 | |
580 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
580 | + $subscriptions = get_option('give_subscriptions', array()); |
|
581 | 581 | |
582 | 582 | // Update subscription data only if subscription does not exist already. |
583 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
583 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
584 | 584 | |
585 | 585 | // Initiate default set of license for subscription. |
586 | - if ( ! isset( $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
587 | - $subscriptions[ $subscription_data['id'] ]['licenses'] = array(); |
|
586 | + if ( ! isset($subscriptions[$subscription_data['id']]['licenses'])) { |
|
587 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | // Store licenses for subscription. |
591 | - if ( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
592 | - $subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license; |
|
591 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
592 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
593 | 593 | } |
594 | 594 | |
595 | - update_option( 'give_subscriptions', $subscriptions, false ); |
|
595 | + update_option('give_subscriptions', $subscriptions, false); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
@@ -606,12 +606,12 @@ discard block |
||
606 | 606 | */ |
607 | 607 | public function notices() { |
608 | 608 | |
609 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
609 | + if ( ! current_user_can('manage_give_settings')) { |
|
610 | 610 | return; |
611 | 611 | } |
612 | 612 | |
613 | 613 | // Do not show licenses notices on license tab. |
614 | - if ( 'licenses' === give_get_current_setting_tab() ) { |
|
614 | + if ('licenses' === give_get_current_setting_tab()) { |
|
615 | 615 | return; |
616 | 616 | } |
617 | 617 | |
@@ -620,17 +620,17 @@ discard block |
||
620 | 620 | static $addon_license_key_in_subscriptions; |
621 | 621 | |
622 | 622 | // Set default value. |
623 | - $addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array(); |
|
623 | + $addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array(); |
|
624 | 624 | $messages = array(); |
625 | 625 | |
626 | 626 | // Check whether admin has Give Add-on activated since 24 hours? |
627 | - $is_license_notice_hidden = Give_Cache::get( 'give_cache_hide_license_notice_after_activation' ); |
|
627 | + $is_license_notice_hidden = Give_Cache::get('give_cache_hide_license_notice_after_activation'); |
|
628 | 628 | |
629 | 629 | // Display Invalid License notice, if its more than 24 hours since first Give Add-on activation. |
630 | 630 | if ( |
631 | - empty( $this->license ) |
|
632 | - && empty( $showed_invalid_message ) |
|
633 | - && ( false === $is_license_notice_hidden ) |
|
631 | + empty($this->license) |
|
632 | + && empty($showed_invalid_message) |
|
633 | + && (false === $is_license_notice_hidden) |
|
634 | 634 | ) { |
635 | 635 | |
636 | 636 | Give()->notices->register_notice( |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | 'id' => 'give-invalid-license', |
639 | 639 | 'type' => 'error', |
640 | 640 | 'description' => sprintf( |
641 | - __( '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' ), |
|
642 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
641 | + __('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'), |
|
642 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
643 | 643 | ), |
644 | 644 | 'dismissible_type' => 'user', |
645 | 645 | 'dismiss_interval' => 'shortly', |
@@ -651,39 +651,39 @@ discard block |
||
651 | 651 | } |
652 | 652 | |
653 | 653 | // Get subscriptions. |
654 | - $subscriptions = get_option( 'give_subscriptions' ); |
|
654 | + $subscriptions = get_option('give_subscriptions'); |
|
655 | 655 | |
656 | 656 | // Show subscription messages. |
657 | - if ( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) { |
|
657 | + if ( ! empty($subscriptions) && ! $showed_subscriptions_message) { |
|
658 | 658 | |
659 | - foreach ( $subscriptions as $subscription ) { |
|
659 | + foreach ($subscriptions as $subscription) { |
|
660 | 660 | // Subscription expires timestamp. |
661 | - $subscription_expires = strtotime( $subscription['expires'] ); |
|
661 | + $subscription_expires = strtotime($subscription['expires']); |
|
662 | 662 | |
663 | 663 | // Start showing subscriptions message before one week of renewal date. |
664 | - if ( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) { |
|
664 | + if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) { |
|
665 | 665 | continue; |
666 | 666 | } |
667 | 667 | |
668 | 668 | // Check if subscription message already exist in messages. |
669 | - if ( array_key_exists( $subscription['id'], $messages ) ) { |
|
669 | + if (array_key_exists($subscription['id'], $messages)) { |
|
670 | 670 | continue; |
671 | 671 | } |
672 | 672 | |
673 | 673 | // Check if license already expired. |
674 | - if ( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) { |
|
674 | + if (strtotime($subscription['expires']) < current_time('timestamp', 1)) { |
|
675 | 675 | Give()->notices->register_notice( |
676 | 676 | array( |
677 | 677 | 'id' => "give-expired-subscription-{$subscription['id']}", |
678 | 678 | 'type' => 'error', |
679 | 679 | 'description' => sprintf( |
680 | - __( 'Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give' ), |
|
681 | - urldecode( $subscription['invoice_url'] ), |
|
680 | + __('Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give'), |
|
681 | + urldecode($subscription['invoice_url']), |
|
682 | 682 | $subscription['payment_id'], |
683 | 683 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
684 | 684 | Give()->notices->get_dismiss_link( |
685 | 685 | array( |
686 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
686 | + 'title' => __('Click here if already renewed', 'give'), |
|
687 | 687 | 'dismissible_type' => 'user', |
688 | 688 | 'dismiss_interval' => 'permanent', |
689 | 689 | ) |
@@ -699,14 +699,14 @@ discard block |
||
699 | 699 | 'id' => "give-expires-subscription-{$subscription['id']}", |
700 | 700 | 'type' => 'error', |
701 | 701 | 'description' => sprintf( |
702 | - __( 'Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give' ), |
|
703 | - human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |
|
704 | - urldecode( $subscription['invoice_url'] ), |
|
702 | + __('Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give'), |
|
703 | + human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])), |
|
704 | + urldecode($subscription['invoice_url']), |
|
705 | 705 | $subscription['payment_id'], |
706 | 706 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
707 | 707 | Give()->notices->get_dismiss_link( |
708 | 708 | array( |
709 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
709 | + 'title' => __('Click here if already renewed', 'give'), |
|
710 | 710 | 'dismissible_type' => 'user', |
711 | 711 | 'dismiss_interval' => 'permanent', |
712 | 712 | ) |
@@ -719,16 +719,16 @@ discard block |
||
719 | 719 | } |
720 | 720 | |
721 | 721 | // Stop validation for these license keys. |
722 | - $addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] ); |
|
722 | + $addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']); |
|
723 | 723 | }// End foreach(). |
724 | 724 | $showed_subscriptions_message = true; |
725 | 725 | }// End if(). |
726 | 726 | |
727 | 727 | // Show Non Subscription Give Add-on messages. |
728 | 728 | if ( |
729 | - ! in_array( $this->license, $addon_license_key_in_subscriptions ) |
|
730 | - && ! empty( $this->license ) |
|
731 | - && empty( $showed_invalid_message ) |
|
729 | + ! in_array($this->license, $addon_license_key_in_subscriptions) |
|
730 | + && ! empty($this->license) |
|
731 | + && empty($showed_invalid_message) |
|
732 | 732 | && ! $this->is_valid_license() |
733 | 733 | ) { |
734 | 734 | |
@@ -737,8 +737,8 @@ discard block |
||
737 | 737 | 'id' => 'give-invalid-license', |
738 | 738 | 'type' => 'error', |
739 | 739 | 'description' => sprintf( |
740 | - __( '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' ), |
|
741 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
740 | + __('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'), |
|
741 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
742 | 742 | ), |
743 | 743 | 'dismissible_type' => 'user', |
744 | 744 | 'dismiss_interval' => 'shortly', |
@@ -760,10 +760,10 @@ discard block |
||
760 | 760 | * |
761 | 761 | * @return bool |
762 | 762 | */ |
763 | - public function is_valid_license( $licence_data = null ) { |
|
764 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
763 | + public function is_valid_license($licence_data = null) { |
|
764 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
765 | 765 | |
766 | - if ( apply_filters( 'give_is_valid_license', ( $this->is_license( $license_data ) && 'valid' === $license_data->license ) ) ) { |
|
766 | + if (apply_filters('give_is_valid_license', ($this->is_license($license_data) && 'valid' === $license_data->license))) { |
|
767 | 767 | return true; |
768 | 768 | } |
769 | 769 | |
@@ -781,10 +781,10 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @return bool |
783 | 783 | */ |
784 | - public function is_license( $licence_data = null ) { |
|
785 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
784 | + public function is_license($licence_data = null) { |
|
785 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
786 | 786 | |
787 | - if ( apply_filters( 'give_is_license', ( is_object( $license_data ) && ! empty( $license_data ) && property_exists( $license_data, 'license' ) ) ) ) { |
|
787 | + if (apply_filters('give_is_license', (is_object($license_data) && ! empty($license_data) && property_exists($license_data, 'license')))) { |
|
788 | 788 | return true; |
789 | 789 | } |
790 | 790 | |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | * @return bool |
801 | 801 | */ |
802 | 802 | private function __is_third_party_addon() { |
803 | - return ( false === strpos( $this->api_url, 'givewp.com/' ) ); |
|
803 | + return (false === strpos($this->api_url, 'givewp.com/')); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
@@ -815,25 +815,25 @@ discard block |
||
815 | 815 | * @return bool |
816 | 816 | */ |
817 | 817 | private function __remove_license_key_from_subscriptions() { |
818 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
818 | + $subscriptions = get_option('give_subscriptions', array()); |
|
819 | 819 | |
820 | 820 | // Bailout. |
821 | - if ( empty( $this->license ) ) { |
|
821 | + if (empty($this->license)) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | |
825 | - if ( ! empty( $subscriptions ) ) { |
|
826 | - foreach ( $subscriptions as $subscription_id => $subscription ) { |
|
827 | - $license_index = array_search( $this->license, $subscription['licenses'] ); |
|
828 | - if ( false !== $license_index ) { |
|
825 | + if ( ! empty($subscriptions)) { |
|
826 | + foreach ($subscriptions as $subscription_id => $subscription) { |
|
827 | + $license_index = array_search($this->license, $subscription['licenses']); |
|
828 | + if (false !== $license_index) { |
|
829 | 829 | // Remove license key. |
830 | - unset( $subscriptions[ $subscription_id ]['licenses'][ $license_index ] ); |
|
830 | + unset($subscriptions[$subscription_id]['licenses'][$license_index]); |
|
831 | 831 | |
832 | 832 | // Rearrange license keys. |
833 | - $subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] ); |
|
833 | + $subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']); |
|
834 | 834 | |
835 | 835 | // Update subscription information. |
836 | - update_option( 'give_subscriptions', $subscriptions, false ); |
|
836 | + update_option('give_subscriptions', $subscriptions, false); |
|
837 | 837 | break; |
838 | 838 | } |
839 | 839 | } |
@@ -849,17 +849,17 @@ discard block |
||
849 | 849 | * |
850 | 850 | * @return bool |
851 | 851 | */ |
852 | - public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
|
852 | + public function plugin_page_notices($plugin_file, $plugin_data, $status) { |
|
853 | 853 | // Bailout. |
854 | - if ( $this->is_valid_license() ) { |
|
854 | + if ($this->is_valid_license()) { |
|
855 | 855 | return false; |
856 | 856 | } |
857 | 857 | |
858 | 858 | $update_notice_wrap = '<tr class="give-addon-notice-tr active"><td colspan="3" class="colspanchange"><div class="notice inline notice-warning notice-alt give-invalid-license"><p><span class="dashicons dashicons-info"></span> %s</p></div></td></tr>'; |
859 | 859 | $message = $this->license_state_message(); |
860 | 860 | |
861 | - if ( ! empty( $message['message'] ) ) { |
|
862 | - echo sprintf( $update_notice_wrap, $message['message'] ); |
|
861 | + if ( ! empty($message['message'])) { |
|
862 | + echo sprintf($update_notice_wrap, $message['message']); |
|
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
@@ -874,11 +874,11 @@ discard block |
||
874 | 874 | public function license_state_message() { |
875 | 875 | $message_data = array(); |
876 | 876 | |
877 | - if ( ! $this->is_valid_license() ) { |
|
877 | + if ( ! $this->is_valid_license()) { |
|
878 | 878 | |
879 | 879 | $message_data['message'] = sprintf( |
880 | 880 | 'Please <a href="%1$s">activate your license</a> to receive updates and support for the %2$s add-on.', |
881 | - esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) ), |
|
881 | + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')), |
|
882 | 882 | $this->item_name |
883 | 883 | ); |
884 | 884 | } |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | // Bailout. |
899 | 899 | if ( |
900 | 900 | ! Give_Admin_Settings::verify_nonce() |
901 | - || ! current_user_can( 'manage_give_settings' ) |
|
901 | + || ! current_user_can('manage_give_settings') |
|
902 | 902 | || 'licenses' !== give_get_current_setting_tab() |
903 | 903 | ) { |
904 | 904 | return false; |
@@ -906,10 +906,10 @@ discard block |
||
906 | 906 | |
907 | 907 | // Security check. |
908 | 908 | if ( |
909 | - isset( $_POST[ $this->item_shortname . '_license_key-nonce' ] ) |
|
910 | - && ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) |
|
909 | + isset($_POST[$this->item_shortname.'_license_key-nonce']) |
|
910 | + && ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce') |
|
911 | 911 | ) { |
912 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
912 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
913 | 913 | } |
914 | 914 | |
915 | 915 | return true; |
@@ -927,9 +927,9 @@ discard block |
||
927 | 927 | * |
928 | 928 | * @return mixed |
929 | 929 | */ |
930 | - public function get_license_info( $edd_action = '', $response_in_array = false ) { |
|
930 | + public function get_license_info($edd_action = '', $response_in_array = false) { |
|
931 | 931 | |
932 | - if ( empty( $edd_action ) ) { |
|
932 | + if (empty($edd_action)) { |
|
933 | 933 | return false; |
934 | 934 | } |
935 | 935 | |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | $api_params = array( |
938 | 938 | 'edd_action' => $edd_action, // never change from "edd_" to "give_"! |
939 | 939 | 'license' => $this->license, |
940 | - 'item_name' => urlencode( $this->item_name ), |
|
940 | + 'item_name' => urlencode($this->item_name), |
|
941 | 941 | 'url' => home_url(), |
942 | 942 | ); |
943 | 943 | |
@@ -952,11 +952,11 @@ discard block |
||
952 | 952 | ); |
953 | 953 | |
954 | 954 | // Make sure there are no errors. |
955 | - if ( is_wp_error( $response ) ) { |
|
955 | + if (is_wp_error($response)) { |
|
956 | 956 | return false; |
957 | 957 | } |
958 | 958 | |
959 | - return json_decode( wp_remote_retrieve_body( $response ), $response_in_array ); |
|
959 | + return json_decode(wp_remote_retrieve_body($response), $response_in_array); |
|
960 | 960 | } |
961 | 961 | |
962 | 962 | |
@@ -972,9 +972,9 @@ discard block |
||
972 | 972 | $this->__remove_license_key_from_subscriptions(); |
973 | 973 | |
974 | 974 | // Remove license from database. |
975 | - delete_option( "{$this->item_shortname}_license_active" ); |
|
976 | - give_delete_option( "{$this->item_shortname}_license_key" ); |
|
977 | - unset( $_POST[ "{$this->item_shortname}_license_key" ] ); |
|
975 | + delete_option("{$this->item_shortname}_license_active"); |
|
976 | + give_delete_option("{$this->item_shortname}_license_key"); |
|
977 | + unset($_POST["{$this->item_shortname}_license_key"]); |
|
978 | 978 | |
979 | 979 | // Unset license param. |
980 | 980 | $this->license = ''; |
@@ -992,8 +992,8 @@ discard block |
||
992 | 992 | private function is_deactivating_license() { |
993 | 993 | $status = false; |
994 | 994 | |
995 | - foreach ( $_POST as $key => $value ) { |
|
996 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
995 | + foreach ($_POST as $key => $value) { |
|
996 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
997 | 997 | $status = true; |
998 | 998 | break; |
999 | 999 | } |