Completed
Pull Request — master (#1055)
by Rami
19:01
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/class-give-cli-commands.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * @subcommand	donors
327 327
 	 */
328 328
 	public function donors( $args, $assoc_args ) {
329
-	    global $wp_query;
329
+		global $wp_query;
330 330
 		$donor_id    = isset( $assoc_args ) && array_key_exists( 'id', $assoc_args )      ? absint( $assoc_args['id'] ) : false;
331 331
 		$email       = isset( $assoc_args ) && array_key_exists( 'email', $assoc_args )   ? $assoc_args['email']        : false;
332 332
 		$name        = isset( $assoc_args ) && array_key_exists( 'name', $assoc_args )    ? $assoc_args['name']         : '';
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @subcommand	donations
493 493
 	 */
494 494
 	public function donations( $args, $assoc_args ) {
495
-	    global $wp_query;
495
+		global $wp_query;
496 496
 		$number = isset( $assoc_args ) && array_key_exists( 'number', $assoc_args ) ? $assoc_args['number'] : 10;
497 497
 
498 498
 		// Cache previous number query var.
@@ -716,9 +716,9 @@  discard block
 block discarded – undo
716 716
 	 * @return	mixed
717 717
 	 */
718 718
 	private function color_message( $heading, $message = '', $colon = true, $color = 'g' ) {
719
-	    // Add colon.
720
-	    if ( $colon ) {
721
-	        $heading = $heading . ': ';
719
+		// Add colon.
720
+		if ( $colon ) {
721
+			$heading = $heading . ': ';
722 722
 		}
723 723
 		return WP_CLI::colorize( "%{$color}" . $heading . '%n' ) . $message;
724 724
 	}
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/admin/payments/actions.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	// Retrieve the payment ID
38 38
 	$payment_id = absint( $data['give_payment_id'] );
39 39
 
40
-    /* @var Give_Payment $payment */
40
+	/* @var Give_Payment $payment */
41 41
 	$payment    = new Give_Payment( $payment_id );
42 42
 
43 43
 	// Retrieve existing payment meta
@@ -160,23 +160,23 @@  discard block
 block discarded – undo
160 160
 
161 161
 		if ( 'publish' == $status ) {
162 162
 
163
-            // Reduce previous user donation count and amount.
164
-            $previous_customer->decrease_purchase_count();
165
-            $previous_customer->decrease_value( $curr_total );
163
+			// Reduce previous user donation count and amount.
164
+			$previous_customer->decrease_purchase_count();
165
+			$previous_customer->decrease_value( $curr_total );
166 166
 
167
-            // If donation was completed adjust stats of new customers.
168
-            $customer->increase_purchase_count();
167
+			// If donation was completed adjust stats of new customers.
168
+			$customer->increase_purchase_count();
169 169
 			$customer->increase_value( $new_total );
170 170
 		}
171 171
 
172 172
 		$payment->customer_id = $customer->id;
173 173
 	} else{
174 174
 
175
-	    if( 'publish' === $status ){
176
-            // Update user donation stat.
177
-            $customer->update_donation_value( $curr_total, $new_total );
178
-        }
179
-    }
175
+		if( 'publish' === $status ){
176
+			// Update user donation stat.
177
+			$customer->update_donation_value( $curr_total, $new_total );
178
+		}
179
+	}
180 180
 
181 181
 	// Set new meta values
182 182
 	$payment->user_id    = $customer->user_id;
@@ -217,76 +217,76 @@  discard block
 block discarded – undo
217 217
 
218 218
 	$payment->save();
219 219
 
220
-    // Get new give form ID.
221
-    $new_form_id = absint( $data['forms'] );
222
-    $current_form_id = absint( $payment->get_meta( '_give_payment_form_id' ) );
220
+	// Get new give form ID.
221
+	$new_form_id = absint( $data['forms'] );
222
+	$current_form_id = absint( $payment->get_meta( '_give_payment_form_id' ) );
223 223
 
224
-    // We are adding payment transfer code in last to remove any conflict with above functionality.
225
-    // For example: above code will automatically handle form stat (increase/decrease) when payment status changes.
226
-    /* Check if user want to transfer current payment to new give form id. */
227
-    if( $new_form_id != $current_form_id  ) {
224
+	// We are adding payment transfer code in last to remove any conflict with above functionality.
225
+	// For example: above code will automatically handle form stat (increase/decrease) when payment status changes.
226
+	/* Check if user want to transfer current payment to new give form id. */
227
+	if( $new_form_id != $current_form_id  ) {
228 228
 
229
-        // Get new give form title.
230
-        $new_form_title = get_the_title( $new_form_id );
229
+		// Get new give form title.
230
+		$new_form_title = get_the_title( $new_form_id );
231 231
 
232
-        // Update new give form data in payment data.
233
-        $payment_meta = $payment->get_meta();
234
-        $payment_meta['form_title'] = $new_form_title;
235
-        $payment_meta['form_id']    = $new_form_id;
232
+		// Update new give form data in payment data.
233
+		$payment_meta = $payment->get_meta();
234
+		$payment_meta['form_title'] = $new_form_title;
235
+		$payment_meta['form_id']    = $new_form_id;
236 236
 
237
-        // Update price id post meta data for set donation form.
238
-        if( ! give_has_variable_prices( $new_form_id ) ) {
239
-            $payment_meta['price_id'] = '';
240
-        }
237
+		// Update price id post meta data for set donation form.
238
+		if( ! give_has_variable_prices( $new_form_id ) ) {
239
+			$payment_meta['price_id'] = '';
240
+		}
241 241
 
242
-        // Update payment give form meta data.
243
-        $payment->update_meta( '_give_payment_form_id', $new_form_id );
244
-        $payment->update_meta( '_give_payment_form_title', $new_form_title );
245
-        $payment->update_meta( '_give_payment_meta', $payment_meta );
242
+		// Update payment give form meta data.
243
+		$payment->update_meta( '_give_payment_form_id', $new_form_id );
244
+		$payment->update_meta( '_give_payment_form_title', $new_form_title );
245
+		$payment->update_meta( '_give_payment_meta', $payment_meta );
246 246
 
247
-        // Update price id payment metadata.
248
-        if( ! give_has_variable_prices( $new_form_id ) ) {
249
-            $payment->update_meta( '_give_payment_price_id', '' );
250
-        }
247
+		// Update price id payment metadata.
248
+		if( ! give_has_variable_prices( $new_form_id ) ) {
249
+			$payment->update_meta( '_give_payment_price_id', '' );
250
+		}
251 251
 
252 252
 
253
-        // If donation was completed, adjust stats of forms
254
-        if ( 'publish' == $status ) {
253
+		// If donation was completed, adjust stats of forms
254
+		if ( 'publish' == $status ) {
255 255
 
256
-            // Decrease sale of old give form. For other payment status 
257
-            $current_form = new Give_Donate_Form( $current_form_id );
258
-            $current_form->decrease_sales();
259
-            $current_form->decrease_earnings( $curr_total );
256
+			// Decrease sale of old give form. For other payment status 
257
+			$current_form = new Give_Donate_Form( $current_form_id );
258
+			$current_form->decrease_sales();
259
+			$current_form->decrease_earnings( $curr_total );
260 260
             
261
-            // Increase sale of new give form.
262
-            $new_form = new Give_Donate_Form($new_form_id);
263
-            $new_form->increase_sales();
264
-            $new_form->increase_earnings($new_total);
265
-        }
261
+			// Increase sale of new give form.
262
+			$new_form = new Give_Donate_Form($new_form_id);
263
+			$new_form->increase_sales();
264
+			$new_form->increase_earnings($new_total);
265
+		}
266 266
 
267
-        // Re setup payment to update new meta value in object.
268
-        $payment->update_payment_setup( $payment->ID );
269
-    }
267
+		// Re setup payment to update new meta value in object.
268
+		$payment->update_payment_setup( $payment->ID );
269
+	}
270 270
 
271
-    // Update price id if current form is variable form.
272
-    if( ! empty( $data['give-variable-price'] ) && give_has_variable_prices( $payment->form_id ) ) {
271
+	// Update price id if current form is variable form.
272
+	if( ! empty( $data['give-variable-price'] ) && give_has_variable_prices( $payment->form_id ) ) {
273 273
 
274
-        // Get payment meta data.
275
-        $payment_meta = $payment->get_meta();
274
+		// Get payment meta data.
275
+		$payment_meta = $payment->get_meta();
276 276
 
277
-        // Set payment id to empty string if variable price id is negative ( i.e. custom amount feature enabled ).
278
-        $data['give-variable-price'] = ( 'custom' === $data['give-variable-price'] ) ? 'custom' : ( 0 < $data['give-variable-price'] ) ? $data['give-variable-price'] : '';
277
+		// Set payment id to empty string if variable price id is negative ( i.e. custom amount feature enabled ).
278
+		$data['give-variable-price'] = ( 'custom' === $data['give-variable-price'] ) ? 'custom' : ( 0 < $data['give-variable-price'] ) ? $data['give-variable-price'] : '';
279 279
 
280
-        // Update payment meta data.
281
-        $payment_meta['price_id'] = $data['give-variable-price'];
280
+		// Update payment meta data.
281
+		$payment_meta['price_id'] = $data['give-variable-price'];
282 282
 
283
-        // Update payment give form meta data.
284
-        $payment->update_meta( '_give_payment_price_id', $data['give-variable-price'] );
285
-        $payment->update_meta( '_give_payment_meta', $payment_meta );
283
+		// Update payment give form meta data.
284
+		$payment->update_meta( '_give_payment_price_id', $data['give-variable-price'] );
285
+		$payment->update_meta( '_give_payment_meta', $payment_meta );
286 286
 
287
-        // Re setup payment to update new meta value in object.
288
-        $payment->update_payment_setup( $payment->ID );
289
-    }
287
+		// Re setup payment to update new meta value in object.
288
+		$payment->update_payment_setup( $payment->ID );
289
+	}
290 290
 
291 291
 	/**
292 292
 	 * Fires after updating edited donation.
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
@@ -1169,26 +1169,26 @@  discard block
 block discarded – undo
1169 1169
  * @return void
1170 1170
  */
1171 1171
 function give_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1172
-    /* @var CMB2_Types $field_type_object*/
1172
+	/* @var CMB2_Types $field_type_object*/
1173 1173
 
1174
-    $id                   = $field_type_object->field->args['id'];
1174
+	$id                   = $field_type_object->field->args['id'];
1175 1175
 	$field_description    = $field_type_object->field->args['desc'];
1176 1176
 	$license              = $field_type_object->field->args['options']['license'];
1177
-    $license_key          = $escaped_value;
1178
-    $is_license_key       = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1179
-    $is_valid_license     = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1180
-    $shortname            = $field_type_object->field->args['options']['shortname'];
1177
+	$license_key          = $escaped_value;
1178
+	$is_license_key       = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1179
+	$is_valid_license     = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1180
+	$shortname            = $field_type_object->field->args['options']['shortname'];
1181 1181
 	$field_classes        = 'regular-text give-license-field';
1182 1182
 	$type                 = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1183
-    $custom_html          = '';
1184
-    $value                = $escaped_value;
1185
-    $messages             = array();
1186
-    $class                = '';
1187
-    $account_page_link    = $field_type_object->field->args['options']['account_url'];
1188
-    $checkout_page_link   = $field_type_object->field->args['options']['checkout_url'];
1189
-    $addon_name           = $field_type_object->field->args['options']['item_name'];
1190
-    $license_status       = null;
1191
-    $is_in_subscription   = null;
1183
+	$custom_html          = '';
1184
+	$value                = $escaped_value;
1185
+	$messages             = array();
1186
+	$class                = '';
1187
+	$account_page_link    = $field_type_object->field->args['options']['account_url'];
1188
+	$checkout_page_link   = $field_type_object->field->args['options']['checkout_url'];
1189
+	$addon_name           = $field_type_object->field->args['options']['item_name'];
1190
+	$license_status       = null;
1191
+	$is_in_subscription   = null;
1192 1192
 
1193 1193
 	// By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1194 1194
 	// To combat that check if status is set to error or not, if yes then set $is_license_key to false.
@@ -1197,142 +1197,142 @@  discard block
 block discarded – undo
1197 1197
 	}
1198 1198
 
1199 1199
 
1200
-    // Check if current license is part of subscription or not.
1201
-    $subscriptions = get_option( 'give_subscriptions' );
1202
-
1203
-    if( $is_license_key && $subscriptions ) {
1204
-        foreach ( $subscriptions as $subscription ) {
1205
-            if( in_array( $license_key, $subscription['licenses'] ) ) {
1206
-                $is_in_subscription = $subscription['id'];
1207
-                break;
1208
-            }
1209
-        }
1210
-    }
1211
-
1212
-
1213
-    if( $is_license_key ) {
1214
-        if( $is_in_subscription ) {
1215
-            $subscription_expires = strtotime( $subscriptions[$is_in_subscription]['expires'] );
1216
-            $subscription_status  = __( 'renew', 'give' );
1217
-
1218
-            if( ( 'active' !== $subscriptions[$is_in_subscription]['status'] ) ){
1219
-                $subscription_status = __( 'expire', 'give' );
1220
-            }
1221
-
1222
-            if( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1223
-                $messages[] = sprintf(
1224
-                    __( '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' ),
1225
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1226
-                    $subscriptions[$is_in_subscription]['payment_id'],
1227
-                    $checkout_page_link . '?edd_license_key=' . $subscriptions[$is_in_subscription]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1228
-                );
1229
-                $license_status = 'license-expired';
1230
-            } elseif( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1231
-                $messages[] = sprintf(
1232
-                    __( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s in %s.', 'give' ),
1233
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1234
-                    $subscriptions[$is_in_subscription]['payment_id'],
1235
-                    $subscription_status,
1236
-                    human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[$is_in_subscription]['expires'] ) )
1237
-                );
1238
-                $license_status = 'license-expires-soon';
1239
-            } else {
1240
-                $messages[] = sprintf(
1241
-                    __( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s on %s.', 'give' ),
1242
-                    urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1243
-                    $subscriptions[$is_in_subscription]['payment_id'],
1244
-                    $subscription_status,
1245
-                    date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[$is_in_subscription]['expires'], current_time( 'timestamp' ) ) )
1246
-                );
1247
-                $license_status = 'license-expiration-date';
1248
-            }
1249
-
1250
-
1251
-        } elseif ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1252
-
1253
-            // activate_license 'invalid' on anything other than valid, so if there was an error capture it
1254
-            switch(   $license->error ) {
1255
-                case 'expired' :
1200
+	// Check if current license is part of subscription or not.
1201
+	$subscriptions = get_option( 'give_subscriptions' );
1202
+
1203
+	if( $is_license_key && $subscriptions ) {
1204
+		foreach ( $subscriptions as $subscription ) {
1205
+			if( in_array( $license_key, $subscription['licenses'] ) ) {
1206
+				$is_in_subscription = $subscription['id'];
1207
+				break;
1208
+			}
1209
+		}
1210
+	}
1211
+
1212
+
1213
+	if( $is_license_key ) {
1214
+		if( $is_in_subscription ) {
1215
+			$subscription_expires = strtotime( $subscriptions[$is_in_subscription]['expires'] );
1216
+			$subscription_status  = __( 'renew', 'give' );
1217
+
1218
+			if( ( 'active' !== $subscriptions[$is_in_subscription]['status'] ) ){
1219
+				$subscription_status = __( 'expire', 'give' );
1220
+			}
1221
+
1222
+			if( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1223
+				$messages[] = sprintf(
1224
+					__( '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' ),
1225
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1226
+					$subscriptions[$is_in_subscription]['payment_id'],
1227
+					$checkout_page_link . '?edd_license_key=' . $subscriptions[$is_in_subscription]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1228
+				);
1229
+				$license_status = 'license-expired';
1230
+			} elseif( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1231
+				$messages[] = sprintf(
1232
+					__( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s in %s.', 'give' ),
1233
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1234
+					$subscriptions[$is_in_subscription]['payment_id'],
1235
+					$subscription_status,
1236
+					human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[$is_in_subscription]['expires'] ) )
1237
+				);
1238
+				$license_status = 'license-expires-soon';
1239
+			} else {
1240
+				$messages[] = sprintf(
1241
+					__( 'Your subscription (<a href="%s" target="_blank">#%d</a>) will %s on %s.', 'give' ),
1242
+					urldecode( $subscriptions[$is_in_subscription]['invoice_url'] ),
1243
+					$subscriptions[$is_in_subscription]['payment_id'],
1244
+					$subscription_status,
1245
+					date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[$is_in_subscription]['expires'], current_time( 'timestamp' ) ) )
1246
+				);
1247
+				$license_status = 'license-expiration-date';
1248
+			}
1249
+
1250
+
1251
+		} elseif ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1252
+
1253
+			// activate_license 'invalid' on anything other than valid, so if there was an error capture it
1254
+			switch(   $license->error ) {
1255
+				case 'expired' :
1256 1256
 					error_log(print_r( $license->error, true) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log');
1257
-                    $class = $license->error;
1258
-                    $messages[] = sprintf(
1259
-                        __( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1260
-                        date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1261
-                        $checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1262
-                    );
1263
-                    $license_status = 'license-' . $class;
1264
-                    break;
1265
-
1266
-                case 'missing' :
1267
-                    $class = $license->error;
1268
-                    $messages[] = sprintf(
1269
-                        __( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1270
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1271
-                    );
1272
-                    $license_status = 'license-' . $class;
1273
-                    break;
1274
-
1275
-                case 'invalid' :
1276
-                    $class = $license->error;
1277
-                    $messages[] = sprintf(
1278
-                        __( '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' ),
1279
-                        $addon_name,
1280
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1281
-                    );
1282
-                    $license_status = 'license-' . $class;
1283
-                    break;
1284
-
1285
-                case 'site_inactive' :
1286
-                    $class = $license->error;
1287
-                    $messages[] = sprintf(
1288
-                        __( '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' ),
1289
-                        $addon_name,
1290
-                        $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1291
-                    );
1292
-                    $license_status = 'license-' . $class;
1293
-                    break;
1294
-
1295
-                case 'item_name_mismatch' :
1296
-                    $class = $license->error;
1297
-                    $messages[] = sprintf( __( 'This license %s does not belong to %s.', 'give' ), $value, $addon_name );
1298
-                    $license_status = 'license-' . $class;
1299
-                    break;
1300
-
1301
-                case 'no_activations_left':
1302
-                    $class = $license->error;
1303
-                    $messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1304
-                    $license_status = 'license-' . $class;
1305
-                    break;
1306
-            }
1307
-        } else {
1308
-            switch( $license->license ) {
1309
-                case 'valid' :
1310
-                default:
1311
-                    $class = 'valid';
1312
-                    $now        = current_time( 'timestamp' );
1313
-                    $expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1314
-
1315
-                    if( 'lifetime' === $license->expires ) {
1316
-                        $messages[] = __( 'License key never expires.', 'give' );
1317
-                        $license_status = 'license-lifetime-notice';
1318
-                    } elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1319
-                        $messages[] = sprintf(
1320
-                            __( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1321
-                            date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1322
-                            $checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1323
-                        );
1324
-                        $license_status = 'license-expires-soon';
1325
-                    } else {
1326
-                        $messages[] = sprintf(
1327
-                            __( 'Your license key expires on %s.', 'give' ),
1328
-                            date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1329
-                        );
1330
-                        $license_status = 'license-expiration-date';
1331
-                    }
1332
-                    break;
1333
-            }
1334
-        }
1335
-    } else{
1257
+					$class = $license->error;
1258
+					$messages[] = sprintf(
1259
+						__( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1260
+						date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1261
+						$checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1262
+					);
1263
+					$license_status = 'license-' . $class;
1264
+					break;
1265
+
1266
+				case 'missing' :
1267
+					$class = $license->error;
1268
+					$messages[] = sprintf(
1269
+						__( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1270
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1271
+					);
1272
+					$license_status = 'license-' . $class;
1273
+					break;
1274
+
1275
+				case 'invalid' :
1276
+					$class = $license->error;
1277
+					$messages[] = sprintf(
1278
+						__( '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' ),
1279
+						$addon_name,
1280
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1281
+					);
1282
+					$license_status = 'license-' . $class;
1283
+					break;
1284
+
1285
+				case 'site_inactive' :
1286
+					$class = $license->error;
1287
+					$messages[] = sprintf(
1288
+						__( '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' ),
1289
+						$addon_name,
1290
+						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1291
+					);
1292
+					$license_status = 'license-' . $class;
1293
+					break;
1294
+
1295
+				case 'item_name_mismatch' :
1296
+					$class = $license->error;
1297
+					$messages[] = sprintf( __( 'This license %s does not belong to %s.', 'give' ), $value, $addon_name );
1298
+					$license_status = 'license-' . $class;
1299
+					break;
1300
+
1301
+				case 'no_activations_left':
1302
+					$class = $license->error;
1303
+					$messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1304
+					$license_status = 'license-' . $class;
1305
+					break;
1306
+			}
1307
+		} else {
1308
+			switch( $license->license ) {
1309
+				case 'valid' :
1310
+				default:
1311
+					$class = 'valid';
1312
+					$now        = current_time( 'timestamp' );
1313
+					$expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1314
+
1315
+					if( 'lifetime' === $license->expires ) {
1316
+						$messages[] = __( 'License key never expires.', 'give' );
1317
+						$license_status = 'license-lifetime-notice';
1318
+					} elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1319
+						$messages[] = sprintf(
1320
+							__( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1321
+							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1322
+							$checkout_page_link . '?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1323
+						);
1324
+						$license_status = 'license-expires-soon';
1325
+					} else {
1326
+						$messages[] = sprintf(
1327
+							__( 'Your license key expires on %s.', 'give' ),
1328
+							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1329
+						);
1330
+						$license_status = 'license-expiration-date';
1331
+					}
1332
+					break;
1333
+			}
1334
+		}
1335
+	} else{
1336 1336
 		$class = 'empty';
1337 1337
 		$messages[] = sprintf(
1338 1338
 			__( 'To receive updates, please enter your valid %s license key.', 'give' ),
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
 	}
1343 1343
 
1344 1344
 
1345
-    // Add class for input field if license is active.
1345
+	// Add class for input field if license is active.
1346 1346
 	if ( $is_valid_license ) {
1347 1347
 		$field_classes .= ' give-license-active';
1348 1348
 	}
@@ -1355,12 +1355,12 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
 	// If license is active so show deactivate button
1357 1357
 	if ( $is_valid_license ) {
1358
-        // Get input filed html.
1359
-        $input_field_html = $field_type_object->input( array(
1360
-            'class' => $field_classes,
1361
-            'type'  => $type,
1362
-            'readonly' => 'readonly',
1363
-        ) );
1358
+		// Get input filed html.
1359
+		$input_field_html = $field_type_object->input( array(
1360
+			'class' => $field_classes,
1361
+			'type'  => $type,
1362
+			'readonly' => 'readonly',
1363
+		) );
1364 1364
 
1365 1365
 		$custom_html = '<input type="submit" class="button-secondary give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1366 1366
 	}
@@ -1368,27 +1368,27 @@  discard block
 block discarded – undo
1368 1368
 	// Field description.
1369 1369
 	$custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1370 1370
 
1371
-    // If no messages found then inform user that to get updated in future register yourself.
1372
-    if ( empty( $messages ) ) {
1373
-        $messages[] = apply_filters( "{$shortname}_default_addon_notice", esc_html__( 'To receive updates, please enter your valid Software Licensing license key.', 'give' ) );
1374
-    }
1371
+	// If no messages found then inform user that to get updated in future register yourself.
1372
+	if ( empty( $messages ) ) {
1373
+		$messages[] = apply_filters( "{$shortname}_default_addon_notice", esc_html__( 'To receive updates, please enter your valid Software Licensing license key.', 'give' ) );
1374
+	}
1375 1375
 
1376
-    foreach( $messages as $message ) {
1377
-        $custom_html .= '<div class="give-license-notice give-' . $license_status . '">';
1378
-        $custom_html .= '<p>' . $message . '</p>';
1379
-        $custom_html .= '</div>';
1380
-    }
1376
+	foreach( $messages as $message ) {
1377
+		$custom_html .= '<div class="give-license-notice give-' . $license_status . '">';
1378
+		$custom_html .= '<p>' . $message . '</p>';
1379
+		$custom_html .= '</div>';
1380
+	}
1381 1381
 
1382 1382
 
1383 1383
 
1384
-    // Field html.
1385
-    $custom_html = apply_filters('give_license_key_field_html', $input_field_html.$custom_html, $field_type_object );
1384
+	// Field html.
1385
+	$custom_html = apply_filters('give_license_key_field_html', $input_field_html.$custom_html, $field_type_object );
1386 1386
 
1387
-    // Nonce.
1387
+	// Nonce.
1388 1388
 	wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1389 1389
 
1390
-    // Print field html.
1391
-    echo '<div>' . $custom_html . '</div>';
1390
+	// Print field html.
1391
+	echo '<div>' . $custom_html . '</div>';
1392 1392
 }
1393 1393
 
1394 1394
 
Please login to merge, or discard this patch.
includes/payments/class-give-payment.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 					//Find a match between price_id and level_id
1051 1051
 					//First verify array keys exists THEN make the match
1052 1052
 					if ( ( isset( $args['price_id'] ) && isset( $price['_give_id']['level_id'] ) )
1053
-					     && $args['price_id'] == $price['_give_id']['level_id']
1053
+						 && $args['price_id'] == $price['_give_id']['level_id']
1054 1054
 					) {
1055 1055
 						$item_price = $price['_give_amount'];
1056 1056
 					}
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 	 * Add a note to a payment
1304 1304
 	 *
1305 1305
 	 * @since  1.5
1306
-     * @access public
1306
+	 * @access public
1307 1307
 	 *
1308 1308
 	 * @param  string $note The note to add
1309 1309
 	 *
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
 	 * Set or update the total for a payment.
1399 1399
 	 *
1400 1400
 	 * @since  1.5
1401
-     * @access private
1401
+	 * @access private
1402 1402
 	 *
1403 1403
 	 * @return void
1404 1404
 	 */
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 	 * Set the payment status and run any status specific changes necessary.
1411 1411
 	 *
1412 1412
 	 * @since  1.5
1413
-     * @access public
1413
+	 * @access public
1414 1414
 	 *
1415 1415
 	 * @param  string $status The status to set the payment to.
1416 1416
 	 *
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/EDD_SL_Plugin_Updater.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -15,326 +15,326 @@
 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
-     * @global $pagenow
66
-     *
67
-     * @param array   $_transient_data Update array build by WordPress.
68
-     * @return array Modified update array with custom plugin data.
69
-     */
70
-    function check_update( $_transient_data ) {
45
+	 * @return void
46
+	 */
47
+	public function init() {
71 48
 
72
-        global $pagenow;
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 );
73 51
 
74
-        if( ! is_object( $_transient_data ) ) {
75
-            $_transient_data = new stdClass;
76
-        }
52
+		add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
53
+	}
77 54
 
78
-        if( 'plugins.php' == $pagenow && is_multisite() ) {
79
-            return $_transient_data;
80
-        }
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
+	 * @global $pagenow
66
+	 *
67
+	 * @param array   $_transient_data Update array build by WordPress.
68
+	 * @return array Modified update array with custom plugin data.
69
+	 */
70
+	function check_update( $_transient_data ) {
81 71
 
82
-        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
72
+		global $pagenow;
83 73
 
84
-            $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
74
+		if( ! is_object( $_transient_data ) ) {
75
+			$_transient_data = new stdClass;
76
+		}
85 77
 
86
-            if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
78
+		if( 'plugins.php' == $pagenow && is_multisite() ) {
79
+			return $_transient_data;
80
+		}
87 81
 
88
-                $this->did_check = true;
82
+		if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
89 83
 
90
-                if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
84
+			$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
91 85
 
92
-                    $_transient_data->response[ $this->name ] = $version_info;
86
+			if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
93 87
 
94
-                }
88
+				$this->did_check = true;
95 89
 
96
-                $_transient_data->last_checked = time();
97
-                $_transient_data->checked[ $this->name ] = $this->version;
90
+				if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
98 91
 
99
-            }
92
+					$_transient_data->response[ $this->name ] = $version_info;
100 93
 
101
-        }
94
+				}
102 95
 
103
-        return $_transient_data;
104
-    }
96
+				$_transient_data->last_checked = time();
97
+				$_transient_data->checked[ $this->name ] = $this->version;
105 98
 
106
-    /**
107
-     * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
108
-     *
109
-     * @param string  $file
110
-     * @param array   $plugin
111
-     */
112
-    public function show_update_notification( $file, $plugin ) {
99
+			}
113 100
 
114
-        if( ! current_user_can( 'update_plugins' ) ) {
115
-            return;
116
-        }
101
+		}
117 102
 
118
-        if( ! is_multisite() ) {
119
-            return;
120
-        }
103
+		return $_transient_data;
104
+	}
121 105
 
122
-        if ( $this->name != $file ) {
123
-            return;
124
-        }
106
+	/**
107
+	 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
108
+	 *
109
+	 * @param string  $file
110
+	 * @param array   $plugin
111
+	 */
112
+	public function show_update_notification( $file, $plugin ) {
125 113
 
126
-        // Remove our filter on the site transient
127
-        remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
114
+		if( ! current_user_can( 'update_plugins' ) ) {
115
+			return;
116
+		}
128 117
 
129
-        $update_cache = get_site_transient( 'update_plugins' );
118
+		if( ! is_multisite() ) {
119
+			return;
120
+		}
130 121
 
131
-        if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
122
+		if ( $this->name != $file ) {
123
+			return;
124
+		}
132 125
 
133
-            $cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
134
-            $version_info = get_transient( $cache_key );
126
+		// Remove our filter on the site transient
127
+		remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
135 128
 
136
-            if( false === $version_info ) {
129
+		$update_cache = get_site_transient( 'update_plugins' );
137 130
 
138
-                $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
131
+		if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
139 132
 
140
-                set_transient( $cache_key, $version_info, 3600 );
141
-            }
133
+			$cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
134
+			$version_info = get_transient( $cache_key );
142 135
 
136
+			if( false === $version_info ) {
143 137
 
144
-            if( ! is_object( $version_info ) ) {
145
-                return;
146
-            }
138
+				$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
147 139
 
148
-            if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
140
+				set_transient( $cache_key, $version_info, 3600 );
141
+			}
149 142
 
150
-                $update_cache->response[ $this->name ] = $version_info;
151 143
 
152
-            }
144
+			if( ! is_object( $version_info ) ) {
145
+				return;
146
+			}
153 147
 
154
-            $update_cache->last_checked = time();
155
-            $update_cache->checked[ $this->name ] = $this->version;
148
+			if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
156 149
 
157
-            set_site_transient( 'update_plugins', $update_cache );
150
+				$update_cache->response[ $this->name ] = $version_info;
158 151
 
159
-        } else {
152
+			}
160 153
 
161
-            $version_info = $update_cache->response[ $this->name ];
154
+			$update_cache->last_checked = time();
155
+			$update_cache->checked[ $this->name ] = $this->version;
162 156
 
163
-        }
157
+			set_site_transient( 'update_plugins', $update_cache );
164 158
 
165
-        // Restore our filter
166
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
159
+		} else {
167 160
 
168
-        if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
161
+			$version_info = $update_cache->response[ $this->name ];
169 162
 
170
-            // build a plugin list row, with update notification
171
-            $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
172
-            echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
163
+		}
173 164
 
174
-            $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' );
165
+		// Restore our filter
166
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
175 167
 
176
-            if ( empty( $version_info->download_link ) ) {
177
-                printf(
168
+		if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
169
+
170
+			// build a plugin list row, with update notification
171
+			$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
172
+			echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
173
+
174
+			$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' );
175
+
176
+			if ( empty( $version_info->download_link ) ) {
177
+				printf(
178 178
 					/* translators: 1: name 2: changelog URL 3: version */
179
-                    __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
180
-                    esc_html( $version_info->name ),
181
-                    esc_url( $changelog_link ),
182
-                    esc_html( $version_info->new_version )
183
-                );
184
-            } else {
185
-                printf(
179
+					__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
180
+					esc_html( $version_info->name ),
181
+					esc_url( $changelog_link ),
182
+					esc_html( $version_info->new_version )
183
+				);
184
+			} else {
185
+				printf(
186 186
 					/* translators: 1: name 2: changelog URL 3: version 4: update URL */
187
-                    __( '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' ),
188
-                    esc_html( $version_info->name ),
189
-                    esc_url( $changelog_link ),
190
-                    esc_html( $version_info->new_version ),
191
-                    esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
192
-                );
193
-            }
194
-
195
-            echo '</div></td></tr>';
196
-        }
197
-    }
198
-
199
-
200
-    /**
201
-     * Updates information on the "View version x.x details" page with custom data.
202
-     *
203
-     * @uses api_request()
204
-     *
205
-     * @param mixed   $_data
206
-     * @param string  $_action
207
-     * @param object  $_args
208
-     * @return object $_data
209
-     */
210
-    function plugins_api_filter( $_data, $_action = '', $_args = null ) {
211
-
212
-
213
-        if ( $_action != 'plugin_information' ) {
214
-
215
-            return $_data;
216
-
217
-        }
218
-
219
-        if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
220
-
221
-            return $_data;
222
-
223
-        }
224
-
225
-        $to_send = array(
226
-            'slug'   => $this->slug,
227
-            'is_ssl' => is_ssl(),
228
-            'fields' => array(
229
-                'banners' => false, // These will be supported soon hopefully
230
-                'reviews' => false
231
-            )
232
-        );
233
-
234
-        $api_response = $this->api_request( 'plugin_information', $to_send );
235
-
236
-        if ( false !== $api_response ) {
237
-            $_data = $api_response;
238
-        }
239
-
240
-        return $_data;
241
-    }
242
-
243
-
244
-    /**
245
-     * Disable SSL verification in order to prevent download update failures
246
-     *
247
-     * @param array   $args
248
-     * @param string  $url
249
-     * @return object $array
250
-     */
251
-    function http_request_args( $args, $url ) {
252
-        // If it is an https request and we are performing a package download, disable ssl verification
253
-        if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
254
-            $args['sslverify'] = false;
255
-        }
256
-        return $args;
257
-    }
258
-
259
-    /**
260
-     * Calls the API and, if successfull, returns the object delivered by the API.
261
-     *
262
-     * @uses get_bloginfo()
263
-     * @uses wp_remote_post()
264
-     * @uses is_wp_error()
265
-     *
266
-     * @param string  $_action The requested action.
267
-     * @param array   $_data   Parameters for the API action.
268
-     * @return false||object
269
-     */
270
-    private function api_request( $_action, $_data ) {
271
-
272
-        $data = array_merge( $this->api_data, $_data );
273
-
274
-        if ( $data['slug'] != $this->slug ) {
275
-            return;
187
+					__( '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' ),
188
+					esc_html( $version_info->name ),
189
+					esc_url( $changelog_link ),
190
+					esc_html( $version_info->new_version ),
191
+					esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
192
+				);
193
+			}
194
+
195
+			echo '</div></td></tr>';
276 196
 		}
197
+	}
198
+
199
+
200
+	/**
201
+	 * Updates information on the "View version x.x details" page with custom data.
202
+	 *
203
+	 * @uses api_request()
204
+	 *
205
+	 * @param mixed   $_data
206
+	 * @param string  $_action
207
+	 * @param object  $_args
208
+	 * @return object $_data
209
+	 */
210
+	function plugins_api_filter( $_data, $_action = '', $_args = null ) {
211
+
212
+
213
+		if ( $_action != 'plugin_information' ) {
214
+
215
+			return $_data;
277 216
 
278
-        if ( empty( $data['license'] ) ) {
279
-            return;
280 217
 		}
281 218
 
282
-        if( $this->api_url == home_url() ) {
283
-            return false; // Don't allow a plugin to ping itself
284
-        }
219
+		if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
285 220
 
286
-        $api_params = array(
287
-            'edd_action' => 'get_version',
288
-            'license'    => $data['license'],
289
-            'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
290
-            'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
291
-            'slug'       => $data['slug'],
292
-            'author'     => $data['author'],
293
-            'url'        => home_url()
294
-        );
221
+			return $_data;
295 222
 
296
-        $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
223
+		}
297 224
 
298
-        if ( ! is_wp_error( $request ) ) {
299
-            $request = json_decode( wp_remote_retrieve_body( $request ) );
300
-        }
225
+		$to_send = array(
226
+			'slug'   => $this->slug,
227
+			'is_ssl' => is_ssl(),
228
+			'fields' => array(
229
+				'banners' => false, // These will be supported soon hopefully
230
+				'reviews' => false
231
+			)
232
+		);
301 233
 
302
-        if ( $request && isset( $request->sections ) ) {
303
-            $request->sections = maybe_unserialize( $request->sections );
304
-        } else {
305
-            $request = false;
306
-        }
234
+		$api_response = $this->api_request( 'plugin_information', $to_send );
307 235
 
308
-        return $request;
309
-    }
236
+		if ( false !== $api_response ) {
237
+			$_data = $api_response;
238
+		}
310 239
 
311
-    public function show_changelog() {
240
+		return $_data;
241
+	}
312 242
 
313 243
 
314
-        if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
315
-            return;
316
-        }
244
+	/**
245
+	 * Disable SSL verification in order to prevent download update failures
246
+	 *
247
+	 * @param array   $args
248
+	 * @param string  $url
249
+	 * @return object $array
250
+	 */
251
+	function http_request_args( $args, $url ) {
252
+		// If it is an https request and we are performing a package download, disable ssl verification
253
+		if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
254
+			$args['sslverify'] = false;
255
+		}
256
+		return $args;
257
+	}
258
+
259
+	/**
260
+	 * Calls the API and, if successfull, returns the object delivered by the API.
261
+	 *
262
+	 * @uses get_bloginfo()
263
+	 * @uses wp_remote_post()
264
+	 * @uses is_wp_error()
265
+	 *
266
+	 * @param string  $_action The requested action.
267
+	 * @param array   $_data   Parameters for the API action.
268
+	 * @return false||object
269
+	 */
270
+	private function api_request( $_action, $_data ) {
271
+
272
+		$data = array_merge( $this->api_data, $_data );
273
+
274
+		if ( $data['slug'] != $this->slug ) {
275
+			return;
276
+		}
277
+
278
+		if ( empty( $data['license'] ) ) {
279
+			return;
280
+		}
281
+
282
+		if( $this->api_url == home_url() ) {
283
+			return false; // Don't allow a plugin to ping itself
284
+		}
285
+
286
+		$api_params = array(
287
+			'edd_action' => 'get_version',
288
+			'license'    => $data['license'],
289
+			'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
290
+			'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
291
+			'slug'       => $data['slug'],
292
+			'author'     => $data['author'],
293
+			'url'        => home_url()
294
+		);
295
+
296
+		$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
317 297
 
318
-        if( empty( $_REQUEST['plugin'] ) ) {
319
-            return;
320
-        }
298
+		if ( ! is_wp_error( $request ) ) {
299
+			$request = json_decode( wp_remote_retrieve_body( $request ) );
300
+		}
301
+
302
+		if ( $request && isset( $request->sections ) ) {
303
+			$request->sections = maybe_unserialize( $request->sections );
304
+		} else {
305
+			$request = false;
306
+		}
307
+
308
+		return $request;
309
+	}
321 310
 
322
-        if( empty( $_REQUEST['slug'] ) ) {
323
-            return;
324
-        }
311
+	public function show_changelog() {
325 312
 
326
-        if( ! current_user_can( 'update_plugins' ) ) {
327
-            wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
328
-        }
329 313
 
330
-        $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
314
+		if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
315
+			return;
316
+		}
317
+
318
+		if( empty( $_REQUEST['plugin'] ) ) {
319
+			return;
320
+		}
331 321
 
332
-        if( $response && isset( $response->sections['changelog'] ) ) {
333
-            echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
334
-        }
322
+		if( empty( $_REQUEST['slug'] ) ) {
323
+			return;
324
+		}
325
+
326
+		if( ! current_user_can( 'update_plugins' ) ) {
327
+			wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
328
+		}
329
+
330
+		$response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
331
+
332
+		if( $response && isset( $response->sections['changelog'] ) ) {
333
+			echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
334
+		}
335 335
 
336 336
 
337
-        exit;
338
-    }
337
+		exit;
338
+	}
339 339
 
340 340
 }
Please login to merge, or discard this patch.