Completed
Pull Request — master (#1201)
by Ravinder
23:20
created
give.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -358,9 +358,9 @@
 block discarded – undo
358 358
 			require_once GIVE_PLUGIN_DIR . 'includes/emails/template.php';
359 359
 			require_once GIVE_PLUGIN_DIR . 'includes/emails/actions.php';
360 360
 
361
-            if( defined( 'WP_CLI' ) && WP_CLI ) {
362
-                require_once GIVE_PLUGIN_DIR . 'includes/class-give-cli-commands.php';
363
-            }
361
+			if( defined( 'WP_CLI' ) && WP_CLI ) {
362
+				require_once GIVE_PLUGIN_DIR . 'includes/class-give-cli-commands.php';
363
+			}
364 364
 
365 365
 			if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
366 366
 
Please login to merge, or discard this patch.
includes/template-functions.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -45,22 +45,22 @@  discard block
 block discarded – undo
45 45
  * @param string $default_path  Default path. Default is empty.
46 46
  */
47 47
 function give_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
48
-    if ( ! empty( $args ) && is_array( $args ) ) {
49
-        extract( $args );
50
-    }
48
+	if ( ! empty( $args ) && is_array( $args ) ) {
49
+		extract( $args );
50
+	}
51 51
 
52
-    $template_names = array( $template_name . '.php' );
52
+	$template_names = array( $template_name . '.php' );
53 53
 
54
-    $located = give_locate_template( $template_names, $template_path, $default_path );
54
+	$located = give_locate_template( $template_names, $template_path, $default_path );
55 55
 
56
-    if ( ! file_exists( $located ) ) {
56
+	if ( ! file_exists( $located ) ) {
57 57
 		/* translators: %s: the template */
58
-        give_output_error( sprintf( __( 'The %s template was not found.', 'give' ), $located ), true );
59
-        return;
60
-    }
58
+		give_output_error( sprintf( __( 'The %s template was not found.', 'give' ), $located ), true );
59
+		return;
60
+	}
61 61
 
62
-    // Allow 3rd party plugin filter template file from their plugin.
63
-    $located = apply_filters( 'give_get_template', $located, $template_name, $args, $template_path, $default_path );
62
+	// Allow 3rd party plugin filter template file from their plugin.
63
+	$located = apply_filters( 'give_get_template', $located, $template_name, $args, $template_path, $default_path );
64 64
 
65 65
 	/**
66 66
 	 * Fires in give template, before the file is included.
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 	 * @param string $located       Template file filter by 3rd party plugin.
75 75
 	 * @param array  $args          Passed arguments.
76 76
 	 */
77
-    do_action( 'give_before_template_part', $template_name, $template_path, $located, $args );
77
+	do_action( 'give_before_template_part', $template_name, $template_path, $located, $args );
78 78
 
79
-    include( $located );
79
+	include( $located );
80 80
 
81 81
 	/**
82 82
 	 * Fires in give template, after the file is included.
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @param string $located       Template file filter by 3rd party plugin.
91 91
 	 * @param array  $args          Passed arguments.
92 92
 	 */
93
-    do_action( 'give_after_template_part', $template_name, $template_path, $located, $args );
93
+	do_action( 'give_after_template_part', $template_name, $template_path, $located, $args );
94 94
 }
95 95
 
96 96
 /**
Please login to merge, or discard this patch.
includes/login-register.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -33,20 +33,20 @@  discard block
 block discarded – undo
33 33
 		$login_redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url());
34 34
 	}
35 35
 
36
-    if ( empty( $logout_redirect ) ) {
37
-        $logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() );
38
-    }
36
+	if ( empty( $logout_redirect ) ) {
37
+		$logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() );
38
+	}
39 39
 
40 40
 
41
-    // Add user_logout action to logout url.
42
-    $logout_redirect = add_query_arg(
43
-        array(
44
-            'give_action'       => 'user_logout',
45
-            'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ),
46
-            'give_logout_redirect' => urlencode( $logout_redirect )
47
-        ),
48
-        home_url('/')
49
-    );
41
+	// Add user_logout action to logout url.
42
+	$logout_redirect = add_query_arg(
43
+		array(
44
+			'give_action'       => 'user_logout',
45
+			'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ),
46
+			'give_logout_redirect' => urlencode( $logout_redirect )
47
+		),
48
+		home_url('/')
49
+	);
50 50
 
51 51
 	$give_login_redirect = $login_redirect;
52 52
 	$give_logout_redirect = $logout_redirect;
@@ -136,31 +136,31 @@  discard block
 block discarded – undo
136 136
  * @return void
137 137
  */
138 138
 function give_process_user_logout( $data ) {
139
-    if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) {
139
+	if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) {
140 140
 
141
-        // Prevent occurring of any custom action on wp_logout.
142
-        remove_all_actions( 'wp_logout' );
141
+		// Prevent occurring of any custom action on wp_logout.
142
+		remove_all_actions( 'wp_logout' );
143 143
 
144 144
 		/**
145 145
 		 * Fires before processing user logout.
146 146
 		 *
147 147
 		 * @since 1.0
148 148
 		 */
149
-        do_action( 'give_before_user_logout' );
149
+		do_action( 'give_before_user_logout' );
150 150
 
151
-        // Logout user.
152
-        wp_logout();
151
+		// Logout user.
152
+		wp_logout();
153 153
 
154 154
 		/**
155 155
 		 * Fires after processing user logout.
156 156
 		 *
157 157
 		 * @since 1.0
158 158
 		 */
159
-        do_action( 'give_after_user_logout' );
159
+		do_action( 'give_after_user_logout' );
160 160
 
161
-        wp_redirect( $data['give_logout_redirect'] );
162
-        give_die();
163
-    }
161
+		wp_redirect( $data['give_logout_redirect'] );
162
+		give_die();
163
+	}
164 164
 }
165 165
 
166 166
 add_action( 'give_user_logout', 'give_process_user_logout' );
Please login to merge, or discard this patch.
includes/class-give-customer.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
 
715 715
 	/**
716 716
 	 * Decrease/Increase a customer's lifetime value.
717
-     *
718
-     * This function will update donation stat on basis of current amount and new amount donation difference.
719
-     * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat.
720
-     *
717
+	 *
718
+	 * This function will update donation stat on basis of current amount and new amount donation difference.
719
+	 * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat.
720
+	 *
721 721
 	 * @since  1.0
722
-     * @access public
722
+	 * @access public
723 723
 	 *
724 724
 	 * @param  float $curr_amount Current Donation amount.
725 725
 	 * @param  float $new_amount  New (changed) Donation amount.
@@ -727,35 +727,35 @@  discard block
 block discarded – undo
727 727
 	 * @return mixed              If successful, the new donation stat value, otherwise false.
728 728
 	 */
729 729
 	public function update_donation_value( $curr_amount, $new_amount ) {
730
-        /**
731
-         * Payment total difference value can be:
732
-         *  zero   (in case amount not change)
733
-         *  or -ve (in case amount decrease)
734
-         *  or +ve (in case amount increase)
735
-         */
736
-        $payment_total_diff = $new_amount - $curr_amount;
737
-
738
-        // We do not need to update donation stat if donation did not change.
739
-        if( ! $payment_total_diff ) {
740
-            return false;
741
-        }
742
-
743
-
744
-        if( $payment_total_diff > 0 ) {
745
-            $this->increase_value( $payment_total_diff );
746
-        } else {
747
-            // Pass payment total difference as +ve value to decrease amount from user lifetime stat.
748
-            $this->decrease_value( -$payment_total_diff );
749
-        }
750
-
751
-        return $this->purchase_value;
730
+		/**
731
+		 * Payment total difference value can be:
732
+		 *  zero   (in case amount not change)
733
+		 *  or -ve (in case amount decrease)
734
+		 *  or +ve (in case amount increase)
735
+		 */
736
+		$payment_total_diff = $new_amount - $curr_amount;
737
+
738
+		// We do not need to update donation stat if donation did not change.
739
+		if( ! $payment_total_diff ) {
740
+			return false;
741
+		}
742
+
743
+
744
+		if( $payment_total_diff > 0 ) {
745
+			$this->increase_value( $payment_total_diff );
746
+		} else {
747
+			// Pass payment total difference as +ve value to decrease amount from user lifetime stat.
748
+			$this->decrease_value( -$payment_total_diff );
749
+		}
750
+
751
+		return $this->purchase_value;
752 752
 	}
753 753
 
754 754
 	/**
755 755
 	 * Get the parsed notes for a customer as an array.
756 756
 	 *
757 757
 	 * @since  1.0
758
-     * @access public
758
+	 * @access public
759 759
 	 *
760 760
 	 * @param  int $length The number of notes to get.
761 761
 	 * @param  int $paged  What note to start at.
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 	 * Get the total number of notes we have after parsing.
781 781
 	 *
782 782
 	 * @since  1.0
783
-     * @access public
783
+	 * @access public
784 784
 	 *
785 785
 	 * @return int The number of notes for the customer.
786 786
 	 */
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 	 * Add a note for the customer.
798 798
 	 *
799 799
 	 * @since  1.0
800
-     * @access public
800
+	 * @access public
801 801
 	 *
802 802
 	 * @param  string $note   The note to add. Default is empty.
803 803
 	 *
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 	 * Get the notes column for the customer
857 857
 	 *
858 858
 	 * @since  1.0
859
-     * @access private
859
+	 * @access private
860 860
 	 *
861 861
 	 * @return string The Notes for the customer, non-parsed.
862 862
 	 */
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 * Sanitize the data for update/create
935 935
 	 *
936 936
 	 * @since  1.0
937
-     * @access private
937
+	 * @access private
938 938
 	 *
939 939
 	 * @param  array $data The data to sanitize.
940 940
 	 *
Please login to merge, or discard this patch.
includes/admin/admin-actions.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -23,52 +23,52 @@
 block discarded – undo
23 23
  */
24 24
 function give_hide_subscription_notices() {
25 25
 
26
-    // Hide subscription notices permanently.
27
-    if ( ! empty( $_GET['_give_hide_license_notices_permanently'] ) ) {
28
-        $current_user = wp_get_current_user();
26
+	// Hide subscription notices permanently.
27
+	if ( ! empty( $_GET['_give_hide_license_notices_permanently'] ) ) {
28
+		$current_user = wp_get_current_user();
29 29
 
30
-        // check previously disabled notice ids.
31
-        $already_dismiss_notices = ( $already_dismiss_notices = get_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', true ) )
32
-            ? $already_dismiss_notices
33
-            : array();
30
+		// check previously disabled notice ids.
31
+		$already_dismiss_notices = ( $already_dismiss_notices = get_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', true ) )
32
+			? $already_dismiss_notices
33
+			: array();
34 34
 
35
-        // Get notice id.
36
-        $notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_permanently'] );
35
+		// Get notice id.
36
+		$notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_permanently'] );
37 37
 
38
-        if( ! in_array( $notice_id, $already_dismiss_notices ) ) {
39
-            $already_dismiss_notices[] = $notice_id;
40
-        }
38
+		if( ! in_array( $notice_id, $already_dismiss_notices ) ) {
39
+			$already_dismiss_notices[] = $notice_id;
40
+		}
41 41
 
42
-        // Store subscription ids.
43
-        update_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', $already_dismiss_notices );
42
+		// Store subscription ids.
43
+		update_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', $already_dismiss_notices );
44 44
 
45
-        // Redirect user.
46
-        wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_permanently', $_SERVER['REQUEST_URI'] ) );
47
-        exit();
48
-    }
45
+		// Redirect user.
46
+		wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_permanently', $_SERVER['REQUEST_URI'] ) );
47
+		exit();
48
+	}
49 49
 
50
-    // Hide subscription notices shortly.
51
-    if ( ! empty( $_GET['_give_hide_license_notices_shortly'] ) ) {
52
-        $current_user = wp_get_current_user();
50
+	// Hide subscription notices shortly.
51
+	if ( ! empty( $_GET['_give_hide_license_notices_shortly'] ) ) {
52
+		$current_user = wp_get_current_user();
53 53
 
54
-        // Get notice id.
55
-        $notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_shortly'] );
54
+		// Get notice id.
55
+		$notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_shortly'] );
56 56
 
57
-        // Transient key name.
58
-        $transient_key = "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}";
57
+		// Transient key name.
58
+		$transient_key = "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}";
59 59
 
60
-        if( get_transient( $transient_key ) ) {
61
-            return;
62
-        }
60
+		if( get_transient( $transient_key ) ) {
61
+			return;
62
+		}
63 63
 
64 64
 
65
-        // Hide notice for 24 hours.
66
-        set_transient( $transient_key, true, 24 * HOUR_IN_SECONDS );
65
+		// Hide notice for 24 hours.
66
+		set_transient( $transient_key, true, 24 * HOUR_IN_SECONDS );
67 67
 
68
-        // Redirect user.
69
-        wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_shortly', $_SERVER['REQUEST_URI'] ) );
70
-        exit();
71
-    }
68
+		// Redirect user.
69
+		wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_shortly', $_SERVER['REQUEST_URI'] ) );
70
+		exit();
71
+	}
72 72
 }
73 73
 
74 74
 add_action( 'admin_init', 'give_hide_subscription_notices' );
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/upgrades/upgrade-functions.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -411,83 +411,83 @@
 block discarded – undo
411 411
  * @since 1.7
412 412
  */
413 413
 function give_upgrade_addon_license_data(){
414
-    $give_options = give_get_settings();
415
-
416
-    $api_url = 'https://givewp.com/give-sl-api/';
417
-
418
-    // Get addons license key.
419
-    $addons = array();
420
-    foreach ( $give_options as $key => $value ) {
421
-        if( false !== strpos( $key, '_license_key' ) ) {
422
-            $addons[$key] = $value;
423
-        }
424
-    }
425
-
426
-    // Bailout: We do not have any addon license data to upgrade.
427
-    if( empty( $addons ) ) {
428
-        return false;
429
-    }
414
+	$give_options = give_get_settings();
415
+
416
+	$api_url = 'https://givewp.com/give-sl-api/';
417
+
418
+	// Get addons license key.
419
+	$addons = array();
420
+	foreach ( $give_options as $key => $value ) {
421
+		if( false !== strpos( $key, '_license_key' ) ) {
422
+			$addons[$key] = $value;
423
+		}
424
+	}
425
+
426
+	// Bailout: We do not have any addon license data to upgrade.
427
+	if( empty( $addons ) ) {
428
+		return false;
429
+	}
430 430
     
431
-    foreach ( $addons as $key => $addon_license ) {
432
-
433
-        // Get addon shortname.
434
-        $shortname = str_replace( '_license_key', '', $key );
435
-
436
-        // Addon license option name.
437
-        $addon_license_option_name = $shortname . '_license_active';
438
-
439
-        // bailout if license is empty.
440
-        if( empty( $addon_license ) ) {
441
-            delete_option( $addon_license_option_name );
442
-            continue;
443
-        }
444
-
445
-        // Get addon name.
446
-        $addon_name = array();
447
-        $addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
448
-        foreach ( $addon_name_parts as $name_part ) {
449
-
450
-            // Fix addon name
451
-            switch ( $name_part ) {
452
-                case 'authorizenet' :
453
-                    $name_part = 'authorize.net';
454
-                    break;
455
-            }
456
-
457
-            $addon_name[] = ucfirst( $name_part );
458
-        }
459
-
460
-        $addon_name = implode( ' ', $addon_name );
461
-
462
-        // Data to send to the API
463
-        $api_params = array(
464
-            'edd_action' => 'activate_license', //never change from "edd_" to "give_"!
465
-            'license'    => $addon_license,
466
-            'item_name'  => urlencode( $addon_name ),
467
-            'url'        => home_url()
468
-        );
469
-
470
-        // Call the API
471
-        $response = wp_remote_post(
472
-            $api_url,
473
-            array(
474
-                'timeout'   => 15,
475
-                'sslverify' => false,
476
-                'body'      => $api_params
477
-            )
478
-        );
479
-
480
-        // Make sure there are no errors
481
-        if ( is_wp_error( $response ) ) {
482
-            delete_option( $addon_license_option_name );
483
-            continue;
484
-        }
485
-
486
-        // Tell WordPress to look for updates
487
-        set_site_transient( 'update_plugins', null );
488
-
489
-        // Decode license data
490
-        $license_data = json_decode( wp_remote_retrieve_body( $response ) );
491
-        update_option( $addon_license_option_name, $license_data );
492
-    }
431
+	foreach ( $addons as $key => $addon_license ) {
432
+
433
+		// Get addon shortname.
434
+		$shortname = str_replace( '_license_key', '', $key );
435
+
436
+		// Addon license option name.
437
+		$addon_license_option_name = $shortname . '_license_active';
438
+
439
+		// bailout if license is empty.
440
+		if( empty( $addon_license ) ) {
441
+			delete_option( $addon_license_option_name );
442
+			continue;
443
+		}
444
+
445
+		// Get addon name.
446
+		$addon_name = array();
447
+		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
448
+		foreach ( $addon_name_parts as $name_part ) {
449
+
450
+			// Fix addon name
451
+			switch ( $name_part ) {
452
+				case 'authorizenet' :
453
+					$name_part = 'authorize.net';
454
+					break;
455
+			}
456
+
457
+			$addon_name[] = ucfirst( $name_part );
458
+		}
459
+
460
+		$addon_name = implode( ' ', $addon_name );
461
+
462
+		// Data to send to the API
463
+		$api_params = array(
464
+			'edd_action' => 'activate_license', //never change from "edd_" to "give_"!
465
+			'license'    => $addon_license,
466
+			'item_name'  => urlencode( $addon_name ),
467
+			'url'        => home_url()
468
+		);
469
+
470
+		// Call the API
471
+		$response = wp_remote_post(
472
+			$api_url,
473
+			array(
474
+				'timeout'   => 15,
475
+				'sslverify' => false,
476
+				'body'      => $api_params
477
+			)
478
+		);
479
+
480
+		// Make sure there are no errors
481
+		if ( is_wp_error( $response ) ) {
482
+			delete_option( $addon_license_option_name );
483
+			continue;
484
+		}
485
+
486
+		// Tell WordPress to look for updates
487
+		set_site_transient( 'update_plugins', null );
488
+
489
+		// Decode license data
490
+		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
491
+		update_option( $addon_license_option_name, $license_data );
492
+	}
493 493
 }
494 494
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/reporting/class-donor-reports-table.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -173,8 +173,8 @@
 block discarded – undo
173 173
 
174 174
 			case 'num_purchases' :
175 175
 				$value = '<a href="' .
176
-				         admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $item['email'] )
177
-				         ) . '">' . esc_html( $item['num_purchases'] ) . '</a>';
176
+						 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $item['email'] )
177
+						 ) . '">' . esc_html( $item['num_purchases'] ) . '</a>';
178 178
 				break;
179 179
 
180 180
 			case 'amount_spent' :
Please login to merge, or discard this patch.
includes/admin/EDD_SL_Plugin_Updater.php 1 patch
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -15,324 +15,324 @@
 block discarded – undo
15 15
  * @version 1.6
16 16
  */
17 17
 class EDD_SL_Plugin_Updater {
18
-    private $api_url   = '';
19
-    private $api_data  = array();
20
-    private $name      = '';
21
-    private $slug      = '';
22
-
23
-    /**
24
-     * Class constructor.
25
-     *
26
-     * @param string  $_api_url     The URL pointing to the custom API endpoint.
27
-     * @param string  $_plugin_file Path to the plugin file.
28
-     * @param array   $_api_data    Optional data to send with API calls.
29
-     */
30
-    function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
31
-        $this->api_url  = trailingslashit( $_api_url );
32
-        $this->api_data = $_api_data;
33
-        $this->name     = plugin_basename( $_plugin_file );
34
-        $this->slug     = basename( $_plugin_file, '.php' );
35
-        $this->version  = $_api_data['version'];
36
-
37
-        // Set up hooks.
38
-        $this->init();
39
-        add_action( 'admin_init', array( $this, 'show_changelog' ) );
40
-    }
41
-
42
-    /**
43
-     * Set up WordPress filters to hook into WP's update process.
44
-     *
45
-     * @return void
46
-     */
47
-    public function init() {
48
-
49
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
50
-        add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
51
-
52
-        add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
53
-    }
54
-
55
-    /**
56
-     * Check for Updates at the defined API endpoint and modify the update array.
57
-     *
58
-     * This function dives into the update API just when WordPress creates its update array,
59
-     * then adds a custom API call and injects the custom plugin data retrieved from the API.
60
-     * It is reassembled from parts of the native WordPress plugin update code.
61
-     * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
62
-     *
63
-     * @uses api_request()
18
+	private $api_url   = '';
19
+	private $api_data  = array();
20
+	private $name      = '';
21
+	private $slug      = '';
22
+
23
+	/**
24
+	 * Class constructor.
25
+	 *
26
+	 * @param string  $_api_url     The URL pointing to the custom API endpoint.
27
+	 * @param string  $_plugin_file Path to the plugin file.
28
+	 * @param array   $_api_data    Optional data to send with API calls.
29
+	 */
30
+	function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
31
+		$this->api_url  = trailingslashit( $_api_url );
32
+		$this->api_data = $_api_data;
33
+		$this->name     = plugin_basename( $_plugin_file );
34
+		$this->slug     = basename( $_plugin_file, '.php' );
35
+		$this->version  = $_api_data['version'];
36
+
37
+		// Set up hooks.
38
+		$this->init();
39
+		add_action( 'admin_init', array( $this, 'show_changelog' ) );
40
+	}
41
+
42
+	/**
43
+	 * Set up WordPress filters to hook into WP's update process.
64 44
 	 *
65
-     * @param array   $_transient_data Update array build by WordPress.
66
-     * @return array Modified update array with custom plugin data.
67
-     */
68
-    function check_update( $_transient_data ) {
45
+	 * @return void
46
+	 */
47
+	public function init() {
69 48
 
70
-        $screen = get_current_screen();
49
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
50
+		add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
71 51
 
72
-        if( ! is_object( $_transient_data ) ) {
73
-            $_transient_data = new stdClass;
74
-        }
52
+		add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
53
+	}
75 54
 
76
-        if( 'plugins.php' == $screen->parent_file && is_multisite() ) {
77
-            return $_transient_data;
78
-        }
55
+	/**
56
+	 * Check for Updates at the defined API endpoint and modify the update array.
57
+	 *
58
+	 * This function dives into the update API just when WordPress creates its update array,
59
+	 * then adds a custom API call and injects the custom plugin data retrieved from the API.
60
+	 * It is reassembled from parts of the native WordPress plugin update code.
61
+	 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
62
+	 *
63
+	 * @uses api_request()
64
+	 *
65
+	 * @param array   $_transient_data Update array build by WordPress.
66
+	 * @return array Modified update array with custom plugin data.
67
+	 */
68
+	function check_update( $_transient_data ) {
79 69
 
80
-        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
70
+		$screen = get_current_screen();
81 71
 
82
-            $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
72
+		if( ! is_object( $_transient_data ) ) {
73
+			$_transient_data = new stdClass;
74
+		}
83 75
 
84
-            if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
76
+		if( 'plugins.php' == $screen->parent_file && is_multisite() ) {
77
+			return $_transient_data;
78
+		}
85 79
 
86
-                $this->did_check = true;
80
+		if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
87 81
 
88
-                if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
82
+			$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
89 83
 
90
-                    $_transient_data->response[ $this->name ] = $version_info;
84
+			if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
91 85
 
92
-                }
86
+				$this->did_check = true;
93 87
 
94
-                $_transient_data->last_checked = time();
95
-                $_transient_data->checked[ $this->name ] = $this->version;
88
+				if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
96 89
 
97
-            }
90
+					$_transient_data->response[ $this->name ] = $version_info;
98 91
 
99
-        }
92
+				}
100 93
 
101
-        return $_transient_data;
102
-    }
94
+				$_transient_data->last_checked = time();
95
+				$_transient_data->checked[ $this->name ] = $this->version;
103 96
 
104
-    /**
105
-     * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
106
-     *
107
-     * @param string  $file
108
-     * @param array   $plugin
109
-     */
110
-    public function show_update_notification( $file, $plugin ) {
97
+			}
111 98
 
112
-        if( ! current_user_can( 'update_plugins' ) ) {
113
-            return;
114
-        }
99
+		}
100
+
101
+		return $_transient_data;
102
+	}
103
+
104
+	/**
105
+	 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
106
+	 *
107
+	 * @param string  $file
108
+	 * @param array   $plugin
109
+	 */
110
+	public function show_update_notification( $file, $plugin ) {
111
+
112
+		if( ! current_user_can( 'update_plugins' ) ) {
113
+			return;
114
+		}
115 115
 
116
-        if( ! is_multisite() ) {
117
-            return;
118
-        }
116
+		if( ! is_multisite() ) {
117
+			return;
118
+		}
119 119
 
120
-        if ( $this->name != $file ) {
121
-            return;
122
-        }
120
+		if ( $this->name != $file ) {
121
+			return;
122
+		}
123 123
 
124
-        // Remove our filter on the site transient
125
-        remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
124
+		// Remove our filter on the site transient
125
+		remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
126 126
 
127
-        $update_cache = get_site_transient( 'update_plugins' );
127
+		$update_cache = get_site_transient( 'update_plugins' );
128 128
 
129
-        if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
129
+		if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
130 130
 
131
-            $cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
132
-            $version_info = get_transient( $cache_key );
131
+			$cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
132
+			$version_info = get_transient( $cache_key );
133 133
 
134
-            if( false === $version_info ) {
134
+			if( false === $version_info ) {
135 135
 
136
-                $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
136
+				$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
137 137
 
138
-                set_transient( $cache_key, $version_info, 3600 );
139
-            }
138
+				set_transient( $cache_key, $version_info, 3600 );
139
+			}
140 140
 
141 141
 
142
-            if( ! is_object( $version_info ) ) {
143
-                return;
144
-            }
142
+			if( ! is_object( $version_info ) ) {
143
+				return;
144
+			}
145 145
 
146
-            if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
146
+			if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
147 147
 
148
-                $update_cache->response[ $this->name ] = $version_info;
148
+				$update_cache->response[ $this->name ] = $version_info;
149 149
 
150
-            }
150
+			}
151 151
 
152
-            $update_cache->last_checked = time();
153
-            $update_cache->checked[ $this->name ] = $this->version;
152
+			$update_cache->last_checked = time();
153
+			$update_cache->checked[ $this->name ] = $this->version;
154 154
 
155
-            set_site_transient( 'update_plugins', $update_cache );
155
+			set_site_transient( 'update_plugins', $update_cache );
156 156
 
157
-        } else {
157
+		} else {
158 158
 
159
-            $version_info = $update_cache->response[ $this->name ];
159
+			$version_info = $update_cache->response[ $this->name ];
160 160
 
161
-        }
161
+		}
162 162
 
163
-        // Restore our filter
164
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
163
+		// Restore our filter
164
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
165 165
 
166
-        if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
166
+		if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
167 167
 
168
-            // build a plugin list row, with update notification
169
-            $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
170
-            echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
168
+			// build a plugin list row, with update notification
169
+			$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
170
+			echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
171 171
 
172
-            $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
172
+			$changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
173 173
 
174
-            if ( empty( $version_info->download_link ) ) {
175
-                printf(
174
+			if ( empty( $version_info->download_link ) ) {
175
+				printf(
176 176
 					/* translators: 1: name 2: changelog URL 3: version */
177
-                    __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
178
-                    esc_html( $version_info->name ),
179
-                    esc_url( $changelog_link ),
180
-                    esc_html( $version_info->new_version )
181
-                );
182
-            } else {
183
-                printf(
177
+					__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
178
+					esc_html( $version_info->name ),
179
+					esc_url( $changelog_link ),
180
+					esc_html( $version_info->new_version )
181
+				);
182
+			} else {
183
+				printf(
184 184
 					/* translators: 1: name 2: changelog URL 3: version 4: update URL */
185
-                    __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give' ),
186
-                    esc_html( $version_info->name ),
187
-                    esc_url( $changelog_link ),
188
-                    esc_html( $version_info->new_version ),
189
-                    esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
190
-                );
191
-            }
192
-
193
-            echo '</div></td></tr>';
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * Updates information on the "View version x.x details" page with custom data.
200
-     *
201
-     * @uses api_request()
202
-     *
203
-     * @param mixed   $_data
204
-     * @param string  $_action
205
-     * @param object  $_args
206
-     * @return object $_data
207
-     */
208
-    function plugins_api_filter( $_data, $_action = '', $_args = null ) {
209
-
210
-
211
-        if ( $_action != 'plugin_information' ) {
212
-
213
-            return $_data;
214
-
215
-        }
216
-
217
-        if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
218
-
219
-            return $_data;
220
-
221
-        }
222
-
223
-        $to_send = array(
224
-            'slug'   => $this->slug,
225
-            'is_ssl' => is_ssl(),
226
-            'fields' => array(
227
-                'banners' => false, // These will be supported soon hopefully
228
-                'reviews' => false
229
-            )
230
-        );
231
-
232
-        $api_response = $this->api_request( 'plugin_information', $to_send );
233
-
234
-        if ( false !== $api_response ) {
235
-            $_data = $api_response;
236
-        }
237
-
238
-        return $_data;
239
-    }
240
-
241
-
242
-    /**
243
-     * Disable SSL verification in order to prevent download update failures
244
-     *
245
-     * @param array   $args
246
-     * @param string  $url
247
-     * @return object $array
248
-     */
249
-    function http_request_args( $args, $url ) {
250
-        // If it is an https request and we are performing a package download, disable ssl verification
251
-        if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
252
-            $args['sslverify'] = false;
253
-        }
254
-        return $args;
255
-    }
256
-
257
-    /**
258
-     * Calls the API and, if successfull, returns the object delivered by the API.
259
-     *
260
-     * @uses get_bloginfo()
261
-     * @uses wp_remote_post()
262
-     * @uses is_wp_error()
263
-     *
264
-     * @param string  $_action The requested action.
265
-     * @param array   $_data   Parameters for the API action.
266
-     * @return false||object
267
-     */
268
-    private function api_request( $_action, $_data ) {
269
-
270
-        $data = array_merge( $this->api_data, $_data );
271
-
272
-        if ( $data['slug'] != $this->slug ) {
273
-            return;
185
+					__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give' ),
186
+					esc_html( $version_info->name ),
187
+					esc_url( $changelog_link ),
188
+					esc_html( $version_info->new_version ),
189
+					esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
190
+				);
191
+			}
192
+
193
+			echo '</div></td></tr>';
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * Updates information on the "View version x.x details" page with custom data.
200
+	 *
201
+	 * @uses api_request()
202
+	 *
203
+	 * @param mixed   $_data
204
+	 * @param string  $_action
205
+	 * @param object  $_args
206
+	 * @return object $_data
207
+	 */
208
+	function plugins_api_filter( $_data, $_action = '', $_args = null ) {
209
+
210
+
211
+		if ( $_action != 'plugin_information' ) {
212
+
213
+			return $_data;
214
+
215
+		}
216
+
217
+		if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
218
+
219
+			return $_data;
220
+
221
+		}
222
+
223
+		$to_send = array(
224
+			'slug'   => $this->slug,
225
+			'is_ssl' => is_ssl(),
226
+			'fields' => array(
227
+				'banners' => false, // These will be supported soon hopefully
228
+				'reviews' => false
229
+			)
230
+		);
231
+
232
+		$api_response = $this->api_request( 'plugin_information', $to_send );
233
+
234
+		if ( false !== $api_response ) {
235
+			$_data = $api_response;
236
+		}
237
+
238
+		return $_data;
239
+	}
240
+
241
+
242
+	/**
243
+	 * Disable SSL verification in order to prevent download update failures
244
+	 *
245
+	 * @param array   $args
246
+	 * @param string  $url
247
+	 * @return object $array
248
+	 */
249
+	function http_request_args( $args, $url ) {
250
+		// If it is an https request and we are performing a package download, disable ssl verification
251
+		if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
252
+			$args['sslverify'] = false;
253
+		}
254
+		return $args;
255
+	}
256
+
257
+	/**
258
+	 * Calls the API and, if successfull, returns the object delivered by the API.
259
+	 *
260
+	 * @uses get_bloginfo()
261
+	 * @uses wp_remote_post()
262
+	 * @uses is_wp_error()
263
+	 *
264
+	 * @param string  $_action The requested action.
265
+	 * @param array   $_data   Parameters for the API action.
266
+	 * @return false||object
267
+	 */
268
+	private function api_request( $_action, $_data ) {
269
+
270
+		$data = array_merge( $this->api_data, $_data );
271
+
272
+		if ( $data['slug'] != $this->slug ) {
273
+			return;
274 274
 		}
275 275
 
276
-        if ( empty( $data['license'] ) ) {
277
-            return;
276
+		if ( empty( $data['license'] ) ) {
277
+			return;
278 278
 		}
279 279
 
280
-        if( $this->api_url == home_url() ) {
281
-            return false; // Don't allow a plugin to ping itself
282
-        }
280
+		if( $this->api_url == home_url() ) {
281
+			return false; // Don't allow a plugin to ping itself
282
+		}
283 283
 
284
-        $api_params = array(
285
-            'edd_action' => 'get_version',
286
-            'license'    => $data['license'],
287
-            'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
288
-            'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
289
-            'slug'       => $data['slug'],
290
-            'author'     => $data['author'],
291
-            'url'        => home_url()
292
-        );
284
+		$api_params = array(
285
+			'edd_action' => 'get_version',
286
+			'license'    => $data['license'],
287
+			'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
288
+			'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
289
+			'slug'       => $data['slug'],
290
+			'author'     => $data['author'],
291
+			'url'        => home_url()
292
+		);
293 293
 
294
-        $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
294
+		$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
295 295
 
296
-        if ( ! is_wp_error( $request ) ) {
297
-            $request = json_decode( wp_remote_retrieve_body( $request ) );
298
-        }
296
+		if ( ! is_wp_error( $request ) ) {
297
+			$request = json_decode( wp_remote_retrieve_body( $request ) );
298
+		}
299 299
 
300
-        if ( $request && isset( $request->sections ) ) {
301
-            $request->sections = maybe_unserialize( $request->sections );
302
-        } else {
303
-            $request = false;
304
-        }
300
+		if ( $request && isset( $request->sections ) ) {
301
+			$request->sections = maybe_unserialize( $request->sections );
302
+		} else {
303
+			$request = false;
304
+		}
305 305
 
306
-        return $request;
307
-    }
306
+		return $request;
307
+	}
308 308
 
309
-    public function show_changelog() {
309
+	public function show_changelog() {
310 310
 
311 311
 
312
-        if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
313
-            return;
314
-        }
312
+		if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
313
+			return;
314
+		}
315 315
 
316
-        if( empty( $_REQUEST['plugin'] ) ) {
317
-            return;
318
-        }
316
+		if( empty( $_REQUEST['plugin'] ) ) {
317
+			return;
318
+		}
319 319
 
320
-        if( empty( $_REQUEST['slug'] ) ) {
321
-            return;
322
-        }
320
+		if( empty( $_REQUEST['slug'] ) ) {
321
+			return;
322
+		}
323 323
 
324
-        if( ! current_user_can( 'update_plugins' ) ) {
325
-            wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
326
-        }
324
+		if( ! current_user_can( 'update_plugins' ) ) {
325
+			wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
326
+		}
327 327
 
328
-        $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
328
+		$response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
329 329
 
330
-        if( $response && isset( $response->sections['changelog'] ) ) {
331
-            echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
332
-        }
330
+		if( $response && isset( $response->sections['changelog'] ) ) {
331
+			echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
332
+		}
333 333
 
334 334
 
335
-        exit;
336
-    }
335
+		exit;
336
+	}
337 337
 
338 338
 }
Please login to merge, or discard this patch.
includes/admin/class-give-settings.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -1196,26 +1196,26 @@  discard block
 block discarded – undo
1196 1196
  * @return void
1197 1197
  */
1198 1198
 function give_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1199
-    /* @var CMB2_Types $field_type_object*/
1199
+	/* @var CMB2_Types $field_type_object*/
1200 1200
 
1201
-    $id                   = $field_type_object->field->args['id'];
1201
+	$id                   = $field_type_object->field->args['id'];
1202 1202
 	$field_description    = $field_type_object->field->args['desc'];
1203 1203
 	$license              = $field_type_object->field->args['options']['license'];
1204
-    $license_key          = $escaped_value;
1205
-    $is_license_key       = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1206
-    $is_valid_license     = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1207
-    $shortname            = $field_type_object->field->args['options']['shortname'];
1204
+	$license_key          = $escaped_value;
1205
+	$is_license_key       = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1206
+	$is_valid_license     = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1207
+	$shortname            = $field_type_object->field->args['options']['shortname'];
1208 1208
 	$field_classes        = 'regular-text give-license-field';
1209 1209
 	$type                 = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1210
-    $custom_html          = '';
1211
-    $value                = $escaped_value;
1212
-    $messages             = array();
1213
-    $class                = '';
1214
-    $account_page_link    = $field_type_object->field->args['options']['account_url'];
1215
-    $checkout_page_link   = $field_type_object->field->args['options']['checkout_url'];
1216
-    $addon_name           = $field_type_object->field->args['options']['item_name'];
1217
-    $license_status       = null;
1218
-    $is_in_subscription   = null;
1210
+	$custom_html          = '';
1211
+	$value                = $escaped_value;
1212
+	$messages             = array();
1213
+	$class                = '';
1214
+	$account_page_link    = $field_type_object->field->args['options']['account_url'];
1215
+	$checkout_page_link   = $field_type_object->field->args['options']['checkout_url'];
1216
+	$addon_name           = $field_type_object->field->args['options']['item_name'];
1217
+	$license_status       = null;
1218
+	$is_in_subscription   = null;
1219 1219
 
1220 1220
 	// By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1221 1221
 	// To combat that check if status is set to error or not, if yes then set $is_license_key to false.
@@ -1224,142 +1224,142 @@  discard block
 block discarded – undo
1224 1224
 	}
1225 1225
 
1226 1226
 
1227
-    // Check if current license is part of subscription or not.
1228
-    $subscriptions = get_option( 'give_subscriptions' );
1229
-
1230
-    if( $is_license_key && $subscriptions ) {
1231
-        foreach ( $subscriptions as $subscription ) {
1232
-            if( in_array( $license_key, $subscription['licenses'] ) ) {
1233
-                $is_in_subscription = $subscription['id'];
1234
-                break;
1235
-            }
1236
-        }
1237
-    }
1238
-
1239
-
1240
-    if( $is_license_key ) {
1241
-        if( $is_in_subscription ) {
1242
-            $subscription_expires = strtotime( $subscriptions[$is_in_subscription]['expires'] );
1243
-            $subscription_status  = esc_html__( 'renew', 'give' );
1244
-
1245
-            if( ( 'active' !== $subscriptions[$is_in_subscription]['status'] ) ){
1246
-                $subscription_status = esc_html__( 'expire', 'give' );
1247
-            }
1248
-
1249
-            if( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1250
-                $messages[] = sprintf(
1251
-                    __( 'Your subscription (<a href="%s" target="_blank">#%d</a>) expired. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>', 'give' ),
1252
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1253
-                    $subscriptions[$is_in_subscription]['payment_id'],
1254
-                    $checkout_page_link . '?edd_license_key=' . $subscriptions[$is_in_subscription]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1255
-                );
1256
-                $license_status = 'license-expired';
1257
-            } elseif( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1258
-                $messages[] = sprintf(
1259
-                    __( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s in %s.', 'give' ),
1260
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1261
-                    $subscriptions[$is_in_subscription]['payment_id'],
1262
-                    $subscription_status,
1263
-                    human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[$is_in_subscription]['expires'] ) )
1264
-                );
1265
-                $license_status = 'license-expires-soon';
1266
-            } else {
1267
-                $messages[] = sprintf(
1268
-                    __( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s on %s.', 'give' ),
1269
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1270
-                    $subscriptions[$is_in_subscription]['payment_id'],
1271
-                    $subscription_status,
1272
-                    date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[$is_in_subscription]['expires'], current_time( 'timestamp' ) ) )
1273
-                );
1274
-                $license_status = 'license-expiration-date';
1275
-            }
1276
-
1277
-
1278
-        } elseif ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1279
-
1280
-            // activate_license 'invalid' on anything other than valid, so if there was an error capture it
1281
-            switch(   $license->error ) {
1282
-                case 'expired' :
1227
+	// Check if current license is part of subscription or not.
1228
+	$subscriptions = get_option( 'give_subscriptions' );
1229
+
1230
+	if( $is_license_key && $subscriptions ) {
1231
+		foreach ( $subscriptions as $subscription ) {
1232
+			if( in_array( $license_key, $subscription['licenses'] ) ) {
1233
+				$is_in_subscription = $subscription['id'];
1234
+				break;
1235
+			}
1236
+		}
1237
+	}
1238
+
1239
+
1240
+	if( $is_license_key ) {
1241
+		if( $is_in_subscription ) {
1242
+			$subscription_expires = strtotime( $subscriptions[$is_in_subscription]['expires'] );
1243
+			$subscription_status  = esc_html__( 'renew', 'give' );
1244
+
1245
+			if( ( 'active' !== $subscriptions[$is_in_subscription]['status'] ) ){
1246
+				$subscription_status = esc_html__( 'expire', 'give' );
1247
+			}
1248
+
1249
+			if( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1250
+				$messages[] = sprintf(
1251
+					__( 'Your subscription (<a href="%s" target="_blank">#%d</a>) expired. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>', 'give' ),
1252
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1253
+					$subscriptions[$is_in_subscription]['payment_id'],
1254
+					$checkout_page_link . '?edd_license_key=' . $subscriptions[$is_in_subscription]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1255
+				);
1256
+				$license_status = 'license-expired';
1257
+			} elseif( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1258
+				$messages[] = sprintf(
1259
+					__( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s in %s.', 'give' ),
1260
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1261
+					$subscriptions[$is_in_subscription]['payment_id'],
1262
+					$subscription_status,
1263
+					human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[$is_in_subscription]['expires'] ) )
1264
+				);
1265
+				$license_status = 'license-expires-soon';
1266
+			} else {
1267
+				$messages[] = sprintf(
1268
+					__( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s on %s.', 'give' ),
1269
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1270
+					$subscriptions[$is_in_subscription]['payment_id'],
1271
+					$subscription_status,
1272
+					date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[$is_in_subscription]['expires'], current_time( 'timestamp' ) ) )
1273
+				);
1274
+				$license_status = 'license-expiration-date';
1275
+			}
1276
+
1277
+
1278
+		} elseif ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1279
+
1280
+			// activate_license 'invalid' on anything other than valid, so if there was an error capture it
1281
+			switch(   $license->error ) {
1282
+				case 'expired' :
1283 1283
 					error_log(print_r( $license->error, true) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log');
1284
-                    $class = $license->error;
1285
-                    $messages[] = sprintf(
1286
-                        __( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1287
-                        date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1288
-                        $checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1289
-                    );
1290
-                    $license_status = 'license-' . $class;
1291
-                    break;
1292
-
1293
-                case 'missing' :
1294
-                    $class = $license->error;
1295
-                    $messages[] = sprintf(
1296
-                        __( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1297
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1298
-                    );
1299
-                    $license_status = 'license-' . $class;
1300
-                    break;
1301
-
1302
-                case 'invalid' :
1303
-                    $class = $license->error;
1304
-                    $messages[] = sprintf(
1305
-                        __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1306
-                        $addon_name,
1307
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1308
-                    );
1309
-                    $license_status = 'license-' . $class;
1310
-                    break;
1311
-
1312
-                case 'site_inactive' :
1313
-                    $class = $license->error;
1314
-                    $messages[] = sprintf(
1315
-                        __( 'Your %s is not active for this URL. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1316
-                        $addon_name,
1317
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1318
-                    );
1319
-                    $license_status = 'license-' . $class;
1320
-                    break;
1321
-
1322
-                case 'item_name_mismatch' :
1323
-                    $class = $license->error;
1324
-                    $messages[] = sprintf( __( 'This license %s does not belong to %s.', 'give' ), $value, $addon_name );
1325
-                    $license_status = 'license-' . $class;
1326
-                    break;
1327
-
1328
-                case 'no_activations_left':
1329
-                    $class = $license->error;
1330
-                    $messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1331
-                    $license_status = 'license-' . $class;
1332
-                    break;
1333
-            }
1334
-        } else {
1335
-            switch( $license->license ) {
1336
-                case 'valid' :
1337
-                default:
1338
-                    $class = 'valid';
1339
-                    $now        = current_time( 'timestamp' );
1340
-                    $expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1341
-
1342
-                    if( 'lifetime' === $license->expires ) {
1343
-                        $messages[] = esc_html__( 'License key never expires.', 'give' );
1344
-                        $license_status = 'license-lifetime-notice';
1345
-                    } elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1346
-                        $messages[] = sprintf(
1347
-                            __( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1348
-                            date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1349
-                            $checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1350
-                        );
1351
-                        $license_status = 'license-expires-soon';
1352
-                    } else {
1353
-                        $messages[] = sprintf(
1354
-                            __( 'Your license key expires on %s.', 'give' ),
1355
-                            date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1356
-                        );
1357
-                        $license_status = 'license-expiration-date';
1358
-                    }
1359
-                    break;
1360
-            }
1361
-        }
1362
-    } else{
1284
+					$class = $license->error;
1285
+					$messages[] = sprintf(
1286
+						__( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1287
+						date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1288
+						$checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1289
+					);
1290
+					$license_status = 'license-' . $class;
1291
+					break;
1292
+
1293
+				case 'missing' :
1294
+					$class = $license->error;
1295
+					$messages[] = sprintf(
1296
+						__( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1297
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1298
+					);
1299
+					$license_status = 'license-' . $class;
1300
+					break;
1301
+
1302
+				case 'invalid' :
1303
+					$class = $license->error;
1304
+					$messages[] = sprintf(
1305
+						__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1306
+						$addon_name,
1307
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1308
+					);
1309
+					$license_status = 'license-' . $class;
1310
+					break;
1311
+
1312
+				case 'site_inactive' :
1313
+					$class = $license->error;
1314
+					$messages[] = sprintf(
1315
+						__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1316
+						$addon_name,
1317
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1318
+					);
1319
+					$license_status = 'license-' . $class;
1320
+					break;
1321
+
1322
+				case 'item_name_mismatch' :
1323
+					$class = $license->error;
1324
+					$messages[] = sprintf( __( 'This license %s does not belong to %s.', 'give' ), $value, $addon_name );
1325
+					$license_status = 'license-' . $class;
1326
+					break;
1327
+
1328
+				case 'no_activations_left':
1329
+					$class = $license->error;
1330
+					$messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1331
+					$license_status = 'license-' . $class;
1332
+					break;
1333
+			}
1334
+		} else {
1335
+			switch( $license->license ) {
1336
+				case 'valid' :
1337
+				default:
1338
+					$class = 'valid';
1339
+					$now        = current_time( 'timestamp' );
1340
+					$expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1341
+
1342
+					if( 'lifetime' === $license->expires ) {
1343
+						$messages[] = esc_html__( 'License key never expires.', 'give' );
1344
+						$license_status = 'license-lifetime-notice';
1345
+					} elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1346
+						$messages[] = sprintf(
1347
+							__( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1348
+							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1349
+							$checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1350
+						);
1351
+						$license_status = 'license-expires-soon';
1352
+					} else {
1353
+						$messages[] = sprintf(
1354
+							__( 'Your license key expires on %s.', 'give' ),
1355
+							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1356
+						);
1357
+						$license_status = 'license-expiration-date';
1358
+					}
1359
+					break;
1360
+			}
1361
+		}
1362
+	} else{
1363 1363
 		$class = 'empty';
1364 1364
 		$messages[] = sprintf(
1365 1365
 			__( 'To receive updates, please enter your valid %s license key.', 'give' ),
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
 	}
1370 1370
 
1371 1371
 
1372
-    // Add class for input field if license is active.
1372
+	// Add class for input field if license is active.
1373 1373
 	if ( $is_valid_license ) {
1374 1374
 		$field_classes .= ' give-license-active';
1375 1375
 	}
@@ -1382,12 +1382,12 @@  discard block
 block discarded – undo
1382 1382
 
1383 1383
 	// If license is active so show deactivate button
1384 1384
 	if ( $is_valid_license ) {
1385
-        // Get input filed html.
1386
-        $input_field_html = $field_type_object->input( array(
1387
-            'class' => $field_classes,
1388
-            'type'  => $type,
1389
-            'readonly' => 'readonly',
1390
-        ) );
1385
+		// Get input filed html.
1386
+		$input_field_html = $field_type_object->input( array(
1387
+			'class' => $field_classes,
1388
+			'type'  => $type,
1389
+			'readonly' => 'readonly',
1390
+		) );
1391 1391
 
1392 1392
 		$custom_html = '<input type="submit" class="button-secondary give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1393 1393
 	}
@@ -1395,27 +1395,27 @@  discard block
 block discarded – undo
1395 1395
 	// Field description.
1396 1396
 	$custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1397 1397
 
1398
-    // If no messages found then inform user that to get updated in future register yourself.
1399
-    if ( empty( $messages ) ) {
1400
-        $messages[] = apply_filters( "{$shortname}_default_addon_notice", esc_html__( 'To receive updates, please enter your valid Software Licensing license key.', 'give' ) );
1401
-    }
1398
+	// If no messages found then inform user that to get updated in future register yourself.
1399
+	if ( empty( $messages ) ) {
1400
+		$messages[] = apply_filters( "{$shortname}_default_addon_notice", esc_html__( 'To receive updates, please enter your valid Software Licensing license key.', 'give' ) );
1401
+	}
1402 1402
 
1403
-    foreach( $messages as $message ) {
1404
-        $custom_html .= '<div class="give-license-notice give-' . $license_status . '">';
1405
-        $custom_html .= '<p>' . $message . '</p>';
1406
-        $custom_html .= '</div>';
1407
-    }
1403
+	foreach( $messages as $message ) {
1404
+		$custom_html .= '<div class="give-license-notice give-' . $license_status . '">';
1405
+		$custom_html .= '<p>' . $message . '</p>';
1406
+		$custom_html .= '</div>';
1407
+	}
1408 1408
 
1409 1409
 
1410 1410
 
1411
-    // Field html.
1412
-    $custom_html = apply_filters('give_license_key_field_html', $input_field_html.$custom_html, $field_type_object );
1411
+	// Field html.
1412
+	$custom_html = apply_filters('give_license_key_field_html', $input_field_html.$custom_html, $field_type_object );
1413 1413
 
1414
-    // Nonce.
1414
+	// Nonce.
1415 1415
 	wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1416 1416
 
1417
-    // Print field html.
1418
-    echo '<div>' . $custom_html . '</div>';
1417
+	// Print field html.
1418
+	echo '<div>' . $custom_html . '</div>';
1419 1419
 }
1420 1420
 
1421 1421
 
Please login to merge, or discard this patch.