Completed
Pull Request — master (#986)
by Rami
20:36
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/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
-        global $current_user;
26
+	// Hide subscription notices permanently.
27
+	if ( ! empty( $_GET['_give_hide_license_notices_permanently'] ) ) {
28
+		global $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
-        global $current_user;
50
+	// Hide subscription notices shortly.
51
+	if ( ! empty( $_GET['_give_hide_license_notices_shortly'] ) ) {
52
+		global $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
-    global $give_options;
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
+	global $give_options;
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/EDD_SL_Plugin_Updater.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -13,330 +13,330 @@
 block discarded – undo
13 13
  * @version 1.6
14 14
  */
15 15
 class EDD_SL_Plugin_Updater {
16
-    private $api_url   = '';
17
-    private $api_data  = array();
18
-    private $name      = '';
19
-    private $slug      = '';
20
-
21
-    /**
22
-     * Class constructor.
23
-     *
24
-     * @uses plugin_basename()
25
-     * @uses hook()
26
-     *
27
-     * @param string  $_api_url     The URL pointing to the custom API endpoint.
28
-     * @param string  $_plugin_file Path to the plugin file.
29
-     * @param array   $_api_data    Optional data to send with API calls.
30
-     * @return void
31
-     */
32
-    function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
33
-        $this->api_url  = trailingslashit( $_api_url );
34
-        $this->api_data = $_api_data;
35
-        $this->name     = plugin_basename( $_plugin_file );
36
-        $this->slug     = basename( $_plugin_file, '.php' );
37
-        $this->version  = $_api_data['version'];
38
-
39
-        // Set up hooks.
40
-        $this->init();
41
-        add_action( 'admin_init', array( $this, 'show_changelog' ) );
42
-    }
43
-
44
-    /**
45
-     * Set up WordPress filters to hook into WP's update process.
46
-     *
47
-     * @uses add_filter()
48
-     *
49
-     * @return void
50
-     */
51
-    public function init() {
16
+	private $api_url   = '';
17
+	private $api_data  = array();
18
+	private $name      = '';
19
+	private $slug      = '';
20
+
21
+	/**
22
+	 * Class constructor.
23
+	 *
24
+	 * @uses plugin_basename()
25
+	 * @uses hook()
26
+	 *
27
+	 * @param string  $_api_url     The URL pointing to the custom API endpoint.
28
+	 * @param string  $_plugin_file Path to the plugin file.
29
+	 * @param array   $_api_data    Optional data to send with API calls.
30
+	 * @return void
31
+	 */
32
+	function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
33
+		$this->api_url  = trailingslashit( $_api_url );
34
+		$this->api_data = $_api_data;
35
+		$this->name     = plugin_basename( $_plugin_file );
36
+		$this->slug     = basename( $_plugin_file, '.php' );
37
+		$this->version  = $_api_data['version'];
38
+
39
+		// Set up hooks.
40
+		$this->init();
41
+		add_action( 'admin_init', array( $this, 'show_changelog' ) );
42
+	}
43
+
44
+	/**
45
+	 * Set up WordPress filters to hook into WP's update process.
46
+	 *
47
+	 * @uses add_filter()
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function init() {
52 52
 
53
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
54
-        add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
53
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
54
+		add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
55 55
 
56
-        add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
57
-    }
56
+		add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
57
+	}
58 58
 
59
-    /**
60
-     * Check for Updates at the defined API endpoint and modify the update array.
61
-     *
62
-     * This function dives into the update API just when WordPress creates its update array,
63
-     * then adds a custom API call and injects the custom plugin data retrieved from the API.
64
-     * It is reassembled from parts of the native WordPress plugin update code.
65
-     * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
66
-     *
67
-     * @uses api_request()
68
-     *
69
-     * @param array   $_transient_data Update array build by WordPress.
70
-     * @return array Modified update array with custom plugin data.
71
-     */
72
-    function check_update( $_transient_data ) {
59
+	/**
60
+	 * Check for Updates at the defined API endpoint and modify the update array.
61
+	 *
62
+	 * This function dives into the update API just when WordPress creates its update array,
63
+	 * then adds a custom API call and injects the custom plugin data retrieved from the API.
64
+	 * It is reassembled from parts of the native WordPress plugin update code.
65
+	 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
66
+	 *
67
+	 * @uses api_request()
68
+	 *
69
+	 * @param array   $_transient_data Update array build by WordPress.
70
+	 * @return array Modified update array with custom plugin data.
71
+	 */
72
+	function check_update( $_transient_data ) {
73 73
 
74
-        global $pagenow;
74
+		global $pagenow;
75 75
 
76
-        if( ! is_object( $_transient_data ) ) {
77
-            $_transient_data = new stdClass;
78
-        }
76
+		if( ! is_object( $_transient_data ) ) {
77
+			$_transient_data = new stdClass;
78
+		}
79 79
 
80
-        if( 'plugins.php' == $pagenow && is_multisite() ) {
81
-            return $_transient_data;
82
-        }
80
+		if( 'plugins.php' == $pagenow && is_multisite() ) {
81
+			return $_transient_data;
82
+		}
83 83
 
84
-        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
84
+		if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
85 85
 
86
-            $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
86
+			$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
87 87
 
88
-            if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
88
+			if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
89 89
 
90
-                $this->did_check = true;
90
+				$this->did_check = true;
91 91
 
92
-                if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
92
+				if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
93 93
 
94
-                    $_transient_data->response[ $this->name ] = $version_info;
94
+					$_transient_data->response[ $this->name ] = $version_info;
95 95
 
96
-                }
96
+				}
97 97
 
98
-                $_transient_data->last_checked = time();
99
-                $_transient_data->checked[ $this->name ] = $this->version;
98
+				$_transient_data->last_checked = time();
99
+				$_transient_data->checked[ $this->name ] = $this->version;
100 100
 
101
-            }
101
+			}
102 102
 
103
-        }
103
+		}
104 104
 
105
-        return $_transient_data;
106
-    }
105
+		return $_transient_data;
106
+	}
107 107
 
108
-    /**
109
-     * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
110
-     *
111
-     * @param string  $file
112
-     * @param array   $plugin
113
-     */
114
-    public function show_update_notification( $file, $plugin ) {
108
+	/**
109
+	 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
110
+	 *
111
+	 * @param string  $file
112
+	 * @param array   $plugin
113
+	 */
114
+	public function show_update_notification( $file, $plugin ) {
115 115
 
116
-        if( ! current_user_can( 'update_plugins' ) ) {
117
-            return;
118
-        }
116
+		if( ! current_user_can( 'update_plugins' ) ) {
117
+			return;
118
+		}
119 119
 
120
-        if( ! is_multisite() ) {
121
-            return;
122
-        }
120
+		if( ! is_multisite() ) {
121
+			return;
122
+		}
123 123
 
124
-        if ( $this->name != $file ) {
125
-            return;
126
-        }
124
+		if ( $this->name != $file ) {
125
+			return;
126
+		}
127 127
 
128
-        // Remove our filter on the site transient
129
-        remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
128
+		// Remove our filter on the site transient
129
+		remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
130 130
 
131
-        $update_cache = get_site_transient( 'update_plugins' );
131
+		$update_cache = get_site_transient( 'update_plugins' );
132 132
 
133
-        if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
133
+		if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
134 134
 
135
-            $cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
136
-            $version_info = get_transient( $cache_key );
135
+			$cache_key    = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' );
136
+			$version_info = get_transient( $cache_key );
137 137
 
138
-            if( false === $version_info ) {
138
+			if( false === $version_info ) {
139 139
 
140
-                $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
140
+				$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
141 141
 
142
-                set_transient( $cache_key, $version_info, 3600 );
143
-            }
142
+				set_transient( $cache_key, $version_info, 3600 );
143
+			}
144 144
 
145 145
 
146
-            if( ! is_object( $version_info ) ) {
147
-                return;
148
-            }
146
+			if( ! is_object( $version_info ) ) {
147
+				return;
148
+			}
149 149
 
150
-            if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
150
+			if( version_compare( $this->version, $version_info->new_version, '<' ) ) {
151 151
 
152
-                $update_cache->response[ $this->name ] = $version_info;
152
+				$update_cache->response[ $this->name ] = $version_info;
153 153
 
154
-            }
154
+			}
155 155
 
156
-            $update_cache->last_checked = time();
157
-            $update_cache->checked[ $this->name ] = $this->version;
156
+			$update_cache->last_checked = time();
157
+			$update_cache->checked[ $this->name ] = $this->version;
158 158
 
159
-            set_site_transient( 'update_plugins', $update_cache );
159
+			set_site_transient( 'update_plugins', $update_cache );
160 160
 
161
-        } else {
161
+		} else {
162 162
 
163
-            $version_info = $update_cache->response[ $this->name ];
163
+			$version_info = $update_cache->response[ $this->name ];
164 164
 
165
-        }
165
+		}
166 166
 
167
-        // Restore our filter
168
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
167
+		// Restore our filter
168
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
169 169
 
170
-        if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
170
+		if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
171 171
 
172
-            // build a plugin list row, with update notification
173
-            $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
174
-            echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
172
+			// build a plugin list row, with update notification
173
+			$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
174
+			echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
175 175
 
176
-            $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' );
176
+			$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' );
177 177
 
178
-            if ( empty( $version_info->download_link ) ) {
179
-                printf(
178
+			if ( empty( $version_info->download_link ) ) {
179
+				printf(
180 180
 					/* translators: 1: name 2: changelog URL 3: version */
181
-                    __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
182
-                    esc_html( $version_info->name ),
183
-                    esc_url( $changelog_link ),
184
-                    esc_html( $version_info->new_version )
185
-                );
186
-            } else {
187
-                printf(
181
+					__( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ),
182
+					esc_html( $version_info->name ),
183
+					esc_url( $changelog_link ),
184
+					esc_html( $version_info->new_version )
185
+				);
186
+			} else {
187
+				printf(
188 188
 					/* translators: 1: name 2: changelog URL 3: version 4: update URL */
189
-                    __( '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' ),
190
-                    esc_html( $version_info->name ),
191
-                    esc_url( $changelog_link ),
192
-                    esc_html( $version_info->new_version ),
193
-                    esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
194
-                );
195
-            }
196
-
197
-            echo '</div></td></tr>';
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * Updates information on the "View version x.x details" page with custom data.
204
-     *
205
-     * @uses api_request()
206
-     *
207
-     * @param mixed   $_data
208
-     * @param string  $_action
209
-     * @param object  $_args
210
-     * @return object $_data
211
-     */
212
-    function plugins_api_filter( $_data, $_action = '', $_args = null ) {
213
-
214
-
215
-        if ( $_action != 'plugin_information' ) {
216
-
217
-            return $_data;
218
-
219
-        }
220
-
221
-        if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
222
-
223
-            return $_data;
224
-
225
-        }
226
-
227
-        $to_send = array(
228
-            'slug'   => $this->slug,
229
-            'is_ssl' => is_ssl(),
230
-            'fields' => array(
231
-                'banners' => false, // These will be supported soon hopefully
232
-                'reviews' => false
233
-            )
234
-        );
235
-
236
-        $api_response = $this->api_request( 'plugin_information', $to_send );
237
-
238
-        if ( false !== $api_response ) {
239
-            $_data = $api_response;
240
-        }
241
-
242
-        return $_data;
243
-    }
244
-
245
-
246
-    /**
247
-     * Disable SSL verification in order to prevent download update failures
248
-     *
249
-     * @param array   $args
250
-     * @param string  $url
251
-     * @return object $array
252
-     */
253
-    function http_request_args( $args, $url ) {
254
-        // If it is an https request and we are performing a package download, disable ssl verification
255
-        if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
256
-            $args['sslverify'] = false;
257
-        }
258
-        return $args;
259
-    }
260
-
261
-    /**
262
-     * Calls the API and, if successfull, returns the object delivered by the API.
263
-     *
264
-     * @uses get_bloginfo()
265
-     * @uses wp_remote_post()
266
-     * @uses is_wp_error()
267
-     *
268
-     * @param string  $_action The requested action.
269
-     * @param array   $_data   Parameters for the API action.
270
-     * @return false||object
271
-     */
272
-    private function api_request( $_action, $_data ) {
273
-
274
-        global $wp_version;
275
-
276
-        $data = array_merge( $this->api_data, $_data );
277
-
278
-        if ( $data['slug'] != $this->slug )
279
-            return;
280
-
281
-        if ( empty( $data['license'] ) )
282
-            return;
283
-
284
-        if( $this->api_url == home_url() ) {
285
-            return false; // Don't allow a plugin to ping itself
286
-        }
287
-
288
-        $api_params = array(
289
-            'edd_action' => 'get_version',
290
-            'license'    => $data['license'],
291
-            'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
292
-            'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
293
-            'slug'       => $data['slug'],
294
-            'author'     => $data['author'],
295
-            'url'        => home_url()
296
-        );
189
+					__( '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' ),
190
+					esc_html( $version_info->name ),
191
+					esc_url( $changelog_link ),
192
+					esc_html( $version_info->new_version ),
193
+					esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
194
+				);
195
+			}
196
+
197
+			echo '</div></td></tr>';
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * Updates information on the "View version x.x details" page with custom data.
204
+	 *
205
+	 * @uses api_request()
206
+	 *
207
+	 * @param mixed   $_data
208
+	 * @param string  $_action
209
+	 * @param object  $_args
210
+	 * @return object $_data
211
+	 */
212
+	function plugins_api_filter( $_data, $_action = '', $_args = null ) {
213
+
214
+
215
+		if ( $_action != 'plugin_information' ) {
216
+
217
+			return $_data;
218
+
219
+		}
220
+
221
+		if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
222
+
223
+			return $_data;
224
+
225
+		}
226
+
227
+		$to_send = array(
228
+			'slug'   => $this->slug,
229
+			'is_ssl' => is_ssl(),
230
+			'fields' => array(
231
+				'banners' => false, // These will be supported soon hopefully
232
+				'reviews' => false
233
+			)
234
+		);
235
+
236
+		$api_response = $this->api_request( 'plugin_information', $to_send );
237
+
238
+		if ( false !== $api_response ) {
239
+			$_data = $api_response;
240
+		}
241
+
242
+		return $_data;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Disable SSL verification in order to prevent download update failures
248
+	 *
249
+	 * @param array   $args
250
+	 * @param string  $url
251
+	 * @return object $array
252
+	 */
253
+	function http_request_args( $args, $url ) {
254
+		// If it is an https request and we are performing a package download, disable ssl verification
255
+		if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
256
+			$args['sslverify'] = false;
257
+		}
258
+		return $args;
259
+	}
260
+
261
+	/**
262
+	 * Calls the API and, if successfull, returns the object delivered by the API.
263
+	 *
264
+	 * @uses get_bloginfo()
265
+	 * @uses wp_remote_post()
266
+	 * @uses is_wp_error()
267
+	 *
268
+	 * @param string  $_action The requested action.
269
+	 * @param array   $_data   Parameters for the API action.
270
+	 * @return false||object
271
+	 */
272
+	private function api_request( $_action, $_data ) {
273
+
274
+		global $wp_version;
275
+
276
+		$data = array_merge( $this->api_data, $_data );
277
+
278
+		if ( $data['slug'] != $this->slug )
279
+			return;
280
+
281
+		if ( empty( $data['license'] ) )
282
+			return;
283
+
284
+		if( $this->api_url == home_url() ) {
285
+			return false; // Don't allow a plugin to ping itself
286
+		}
287
+
288
+		$api_params = array(
289
+			'edd_action' => 'get_version',
290
+			'license'    => $data['license'],
291
+			'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
292
+			'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
293
+			'slug'       => $data['slug'],
294
+			'author'     => $data['author'],
295
+			'url'        => home_url()
296
+		);
297 297
 
298
-        $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
298
+		$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
299 299
 
300
-        if ( ! is_wp_error( $request ) ) {
301
-            $request = json_decode( wp_remote_retrieve_body( $request ) );
302
-        }
300
+		if ( ! is_wp_error( $request ) ) {
301
+			$request = json_decode( wp_remote_retrieve_body( $request ) );
302
+		}
303 303
 
304
-        if ( $request && isset( $request->sections ) ) {
305
-            $request->sections = maybe_unserialize( $request->sections );
306
-        } else {
307
-            $request = false;
308
-        }
304
+		if ( $request && isset( $request->sections ) ) {
305
+			$request->sections = maybe_unserialize( $request->sections );
306
+		} else {
307
+			$request = false;
308
+		}
309 309
 
310
-        return $request;
311
-    }
310
+		return $request;
311
+	}
312 312
 
313
-    public function show_changelog() {
313
+	public function show_changelog() {
314 314
 
315 315
 
316
-        if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
317
-            return;
318
-        }
316
+		if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
317
+			return;
318
+		}
319 319
 
320
-        if( empty( $_REQUEST['plugin'] ) ) {
321
-            return;
322
-        }
323
-
324
-        if( empty( $_REQUEST['slug'] ) ) {
325
-            return;
326
-        }
327
-
328
-        if( ! current_user_can( 'update_plugins' ) ) {
329
-            wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
330
-        }
331
-
332
-        $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
333
-
334
-        if( $response && isset( $response->sections['changelog'] ) ) {
335
-            echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
336
-        }
337
-
338
-
339
-        exit;
340
-    }
320
+		if( empty( $_REQUEST['plugin'] ) ) {
321
+			return;
322
+		}
323
+
324
+		if( empty( $_REQUEST['slug'] ) ) {
325
+			return;
326
+		}
327
+
328
+		if( ! current_user_can( 'update_plugins' ) ) {
329
+			wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
330
+		}
331
+
332
+		$response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) );
333
+
334
+		if( $response && isset( $response->sections['changelog'] ) ) {
335
+			echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>';
336
+		}
337
+
338
+
339
+		exit;
340
+	}
341 341
 
342 342
 }
Please login to merge, or discard this patch.