Completed
Push — master ( 1a2d71...dc62d3 )
by Devin
19:39
created
includes/gateways/functions.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
 	// Default, built-in gateways
25 25
 	$gateways = array(
26 26
 		'paypal' => array(
27
-			'admin_label'    => esc_html__( 'PayPal Standard', 'give' ),
28
-			'checkout_label' => esc_html__( 'PayPal', 'give' ),
27
+			'admin_label'    => esc_html__('PayPal Standard', 'give'),
28
+			'checkout_label' => esc_html__('PayPal', 'give'),
29 29
 		),
30 30
 		'manual' => array(
31
-			'admin_label'    => esc_html__( 'Test Payment', 'give' ),
32
-			'checkout_label' => esc_html__( 'Test Payment', 'give' )
31
+			'admin_label'    => esc_html__('Test Payment', 'give'),
32
+			'checkout_label' => esc_html__('Test Payment', 'give')
33 33
 		),
34 34
 	);
35 35
 
36
-	return apply_filters( 'give_payment_gateways', $gateways );
36
+	return apply_filters('give_payment_gateways', $gateways);
37 37
 
38 38
 }
39 39
 
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
 
48 48
 	$gateways = give_get_payment_gateways();
49 49
 
50
-	$enabled = isset( $_POST['gateways'] ) ? $_POST['gateways'] : give_get_option( 'gateways' );
50
+	$enabled = isset($_POST['gateways']) ? $_POST['gateways'] : give_get_option('gateways');
51 51
 
52 52
 	$gateway_list = array();
53 53
 
54
-	foreach ( $gateways as $key => $gateway ) {
55
-		if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
56
-			$gateway_list[ $key ] = $gateway;
54
+	foreach ($gateways as $key => $gateway) {
55
+		if (isset($enabled[$key]) && $enabled[$key] == 1) {
56
+			$gateway_list[$key] = $gateway;
57 57
 		}
58 58
 	}
59 59
 
60 60
 	// Set order of payment gateway in list.
61
-	$gateway_list = give_get_ordered_payment_gateways( $gateway_list );
61
+	$gateway_list = give_get_ordered_payment_gateways($gateway_list);
62 62
 
63
-	return apply_filters( 'give_enabled_payment_gateways', $gateway_list );
63
+	return apply_filters('give_enabled_payment_gateways', $gateway_list);
64 64
 }
65 65
 
66 66
 /**
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
  *
73 73
  * @return boolean true if enabled, false otherwise
74 74
  */
75
-function give_is_gateway_active( $gateway ) {
75
+function give_is_gateway_active($gateway) {
76 76
 	$gateways = give_get_enabled_payment_gateways();
77 77
 
78
-	$ret = array_key_exists( $gateway, $gateways );
78
+	$ret = array_key_exists($gateway, $gateways);
79 79
 
80
-	return apply_filters( 'give_is_gateway_active', $ret, $gateway, $gateways );
80
+	return apply_filters('give_is_gateway_active', $ret, $gateway, $gateways);
81 81
 }
82 82
 
83 83
 /**
@@ -90,24 +90,24 @@  discard block
 block discarded – undo
90 90
  *
91 91
  * @return string Gateway ID
92 92
  */
93
-function give_get_default_gateway( $form_id ) {
93
+function give_get_default_gateway($form_id) {
94 94
 
95 95
 	global $give_options;
96 96
 
97
-	$default      = isset( $give_options['default_gateway'] ) && give_is_gateway_active( $give_options['default_gateway'] ) ? $give_options['default_gateway'] : 'paypal';
98
-	$form_default = get_post_meta( $form_id, '_give_default_gateway', true );
97
+	$default      = isset($give_options['default_gateway']) && give_is_gateway_active($give_options['default_gateway']) ? $give_options['default_gateway'] : 'paypal';
98
+	$form_default = get_post_meta($form_id, '_give_default_gateway', true);
99 99
 
100 100
 	//Single Form settings varies compared to the Global default settings
101
-	if ( ! empty( $form_default ) &&
101
+	if ( ! empty($form_default) &&
102 102
 	     $form_id !== null &&
103 103
 	     $default !== $form_default &&
104 104
 	     $form_default !== 'global' &&
105
-	     give_is_gateway_active( $form_default )
105
+	     give_is_gateway_active($form_default)
106 106
 	) {
107 107
 		$default = $form_default;
108 108
 	}
109 109
 
110
-	return apply_filters( 'give_default_gateway', $default );
110
+	return apply_filters('give_default_gateway', $default);
111 111
 }
112 112
 
113 113
 /**
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
  *
120 120
  * @return string Gateway admin label
121 121
  */
122
-function give_get_gateway_admin_label( $gateway ) {
122
+function give_get_gateway_admin_label($gateway) {
123 123
 	$gateways = give_get_enabled_payment_gateways();
124
-	$label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-	$payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+	$label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+	$payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-	if ( $gateway == 'manual' && $payment ) {
128
-		if ( give_get_payment_amount( $payment ) == 0 ) {
129
-			$label = esc_html__( 'Test Donation', 'give' );
127
+	if ($gateway == 'manual' && $payment) {
128
+		if (give_get_payment_amount($payment) == 0) {
129
+			$label = esc_html__('Test Donation', 'give');
130 130
 		}
131 131
 	}
132 132
 
133
-	return apply_filters( 'give_gateway_admin_label', $label, $gateway );
133
+	return apply_filters('give_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136 136
 /**
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
  *
143 143
  * @return string Checkout label for the gateway
144 144
  */
145
-function give_get_gateway_checkout_label( $gateway ) {
145
+function give_get_gateway_checkout_label($gateway) {
146 146
 	$gateways = give_get_enabled_payment_gateways();
147
-	$label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
147
+	$label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
148 148
 
149
-	if ( $gateway == 'manual' ) {
150
-		$label = esc_html__( 'Test Donation', 'give' );
149
+	if ($gateway == 'manual') {
150
+		$label = esc_html__('Test Donation', 'give');
151 151
 	}
152 152
 
153
-	return apply_filters( 'give_gateway_checkout_label', $label, $gateway );
153
+	return apply_filters('give_gateway_checkout_label', $label, $gateway);
154 154
 }
155 155
 
156 156
 /**
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
  *
163 163
  * @return array Options the gateway supports
164 164
  */
165
-function give_get_gateway_supports( $gateway ) {
165
+function give_get_gateway_supports($gateway) {
166 166
 	$gateways = give_get_enabled_payment_gateways();
167
-	$supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
167
+	$supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
168 168
 
169
-	return apply_filters( 'give_gateway_supports', $supports, $gateway );
169
+	return apply_filters('give_gateway_supports', $supports, $gateway);
170 170
 }
171 171
 
172 172
 /**
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
  *
180 180
  * @return void
181 181
  */
182
-function give_send_to_gateway( $gateway, $payment_data ) {
182
+function give_send_to_gateway($gateway, $payment_data) {
183 183
 
184
-	$payment_data['gateway_nonce'] = wp_create_nonce( 'give-gateway' );
184
+	$payment_data['gateway_nonce'] = wp_create_nonce('give-gateway');
185 185
 
186 186
 	// $gateway must match the ID used when registering the gateway
187
-	do_action( 'give_gateway_' . $gateway, $payment_data );
187
+	do_action('give_gateway_'.$gateway, $payment_data);
188 188
 }
189 189
 
190 190
 
@@ -201,32 +201,32 @@  discard block
 block discarded – undo
201 201
  *
202 202
  * @return string $enabled_gateway The slug of the gateway
203 203
  */
204
-function give_get_chosen_gateway( $form_id ) {
204
+function give_get_chosen_gateway($form_id) {
205 205
 	$gateways        = give_get_enabled_payment_gateways();
206
-	$request_form_id = isset( $_REQUEST['give_form_id'] ) ? $_REQUEST['give_form_id'] : 0;
207
-	if ( empty( $request_form_id ) ) {
208
-		$request_form_id = isset( $_REQUEST['form-id'] ) ? $_REQUEST['form-id'] : 0;
206
+	$request_form_id = isset($_REQUEST['give_form_id']) ? $_REQUEST['give_form_id'] : 0;
207
+	if (empty($request_form_id)) {
208
+		$request_form_id = isset($_REQUEST['form-id']) ? $_REQUEST['form-id'] : 0;
209 209
 	}
210
-	$chosen          = give_get_default_gateway( $form_id );
210
+	$chosen          = give_get_default_gateway($form_id);
211 211
 	$enabled_gateway = '';
212 212
 
213 213
 	//Take into account request Form ID args
214
-	if ( ! empty( $request_form_id ) && $form_id == $request_form_id ) {
215
-		$chosen = isset( $_REQUEST['payment-mode'] ) ? $_REQUEST['payment-mode'] : '';
214
+	if ( ! empty($request_form_id) && $form_id == $request_form_id) {
215
+		$chosen = isset($_REQUEST['payment-mode']) ? $_REQUEST['payment-mode'] : '';
216 216
 	}
217 217
 
218
-	if ( $chosen ) {
219
-		$enabled_gateway = urldecode( $chosen );
220
-	} else if ( count( $gateways ) >= 1 && ! $chosen ) {
221
-		foreach ( $gateways as $gateway_id => $gateway ):
218
+	if ($chosen) {
219
+		$enabled_gateway = urldecode($chosen);
220
+	} else if (count($gateways) >= 1 && ! $chosen) {
221
+		foreach ($gateways as $gateway_id => $gateway):
222 222
 			$enabled_gateway = $gateway_id;
223 223
 		endforeach;
224 224
 	} else {
225
-		$enabled_gateway = give_get_default_gateway( $form_id );
225
+		$enabled_gateway = give_get_default_gateway($form_id);
226 226
 	}
227 227
 
228 228
 
229
-	return apply_filters( 'give_chosen_gateway', $enabled_gateway );
229
+	return apply_filters('give_chosen_gateway', $enabled_gateway);
230 230
 }
231 231
 
232 232
 /**
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
  *
244 244
  * @return int ID of the new log entry
245 245
  */
246
-function give_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
247
-	return give_record_log( $title, $message, $parent, 'gateway_error' );
246
+function give_record_gateway_error($title = '', $message = '', $parent = 0) {
247
+	return give_record_log($title, $message, $parent, 'gateway_error');
248 248
 }
249 249
 
250 250
 /**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
  *
258 258
  * @return int
259 259
  */
260
-function give_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
260
+function give_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
261 261
 
262 262
 	$ret  = 0;
263 263
 	$args = array(
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 		'fields'      => 'ids'
270 270
 	);
271 271
 
272
-	$payments = new WP_Query( $args );
272
+	$payments = new WP_Query($args);
273 273
 
274
-	if ( $payments ) {
274
+	if ($payments) {
275 275
 		$ret = $payments->post_count;
276 276
 	}
277 277
 
@@ -288,27 +288,27 @@  discard block
 block discarded – undo
288 288
  *
289 289
  * @return array $gateways All the available gateways
290 290
  */
291
-function give_get_ordered_payment_gateways( $gateways ) {
291
+function give_get_ordered_payment_gateways($gateways) {
292 292
 
293 293
 	//  Get gateways setting.
294
-	$gateways_setting = isset( $_POST['gateways'] ) ? $_POST['gateways'] : give_get_option( 'gateways' );
294
+	$gateways_setting = isset($_POST['gateways']) ? $_POST['gateways'] : give_get_option('gateways');
295 295
 
296 296
 	// Return from here if we do not have gateways setting.
297
-	if ( empty( $gateways_setting ) ) {
297
+	if (empty($gateways_setting)) {
298 298
 		return $gateways;
299 299
 	}
300 300
 
301 301
 	// Reverse array to order payment gateways.
302
-	$gateways_setting = array_reverse( $gateways_setting );
302
+	$gateways_setting = array_reverse($gateways_setting);
303 303
 
304 304
 	// Reorder gateways array
305
-	foreach ( $gateways_setting as $gateway_key => $value ) {
305
+	foreach ($gateways_setting as $gateway_key => $value) {
306 306
 
307
-		$new_gateway_value = isset( $gateways[ $gateway_key ] ) ? $gateways[ $gateway_key ] : '';
308
-		unset( $gateways[ $gateway_key ] );
307
+		$new_gateway_value = isset($gateways[$gateway_key]) ? $gateways[$gateway_key] : '';
308
+		unset($gateways[$gateway_key]);
309 309
 
310
-		if ( ! empty( $new_gateway_value ) ) {
311
-			$gateways = array_merge( array( $gateway_key => $new_gateway_value ), $gateways );
310
+		if ( ! empty($new_gateway_value)) {
311
+			$gateways = array_merge(array($gateway_key => $new_gateway_value), $gateways);
312 312
 		}
313 313
 	}
314 314
 
@@ -319,5 +319,5 @@  discard block
 block discarded – undo
319 319
 	 *
320 320
 	 * @param array $gateways All the available gateways
321 321
 	 */
322
-	return apply_filters( 'give_payment_gateways_order', $gateways );
322
+	return apply_filters('give_payment_gateways_order', $gateways);
323 323
 }
Please login to merge, or discard this patch.