Completed
Push — master ( aef4f4...2809c8 )
by Devin
8s
created
includes/admin/customers/customer-actions.php 1 patch
Spacing   +128 added lines, -128 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
 
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return array $output Response messages
25 25
  */
26
-function give_edit_customer( $args ) {
26
+function give_edit_customer($args) {
27 27
 	
28
-	$customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' );
28
+	$customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments');
29 29
 
30
-	if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
31
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ) );
30
+	if ( ! is_admin() || ! current_user_can($customer_edit_role)) {
31
+		wp_die(__('You do not have permission to edit this donor.', 'give'));
32 32
 	}
33 33
 
34
-	if ( empty( $args ) ) {
34
+	if (empty($args)) {
35 35
 		return;
36 36
 	}
37 37
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	$customer_id   = (int) $args['customerinfo']['id'];
40 40
 	$nonce         = $args['_wpnonce'];
41 41
 
42
-	if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) {
43
-		wp_die( __( 'Cheatin\' eh?!', 'give' ) );
42
+	if ( ! wp_verify_nonce($nonce, 'edit-customer')) {
43
+		wp_die(__('Cheatin\' eh?!', 'give'));
44 44
 	}
45 45
 
46
-	$customer = new Give_Customer( $customer_id );
47
-	if ( empty( $customer->id ) ) {
46
+	$customer = new Give_Customer($customer_id);
47
+	if (empty($customer->id)) {
48 48
 		return false;
49 49
 	}
50 50
 
@@ -54,23 +54,23 @@  discard block
 block discarded – undo
54 54
 		'user_id' => 0
55 55
 	);
56 56
 
57
-	$customer_info = wp_parse_args( $customer_info, $defaults );
57
+	$customer_info = wp_parse_args($customer_info, $defaults);
58 58
 
59
-	if ( ! is_email( $customer_info['email'] ) ) {
60
-		give_set_error( 'give-invalid-email', __( 'Please enter a valid email address.', 'give' ) );
59
+	if ( ! is_email($customer_info['email'])) {
60
+		give_set_error('give-invalid-email', __('Please enter a valid email address.', 'give'));
61 61
 	}
62 62
 
63
-	if ( (int) $customer_info['user_id'] != (int) $customer->user_id ) {
63
+	if ((int) $customer_info['user_id'] != (int) $customer->user_id) {
64 64
 
65 65
 		// Make sure we don't already have this user attached to a customer
66
-		if ( ! empty( $customer_info['user_id'] ) && false !== Give()->customers->get_customer_by( 'user_id', $customer_info['user_id'] ) ) {
67
-			give_set_error( 'give-invalid-customer-user_id', sprintf( __( 'The User ID %d is already associated with a different donor.', 'give' ), $customer_info['user_id'] ) );
66
+		if ( ! empty($customer_info['user_id']) && false !== Give()->customers->get_customer_by('user_id', $customer_info['user_id'])) {
67
+			give_set_error('give-invalid-customer-user_id', sprintf(__('The User ID %d is already associated with a different donor.', 'give'), $customer_info['user_id']));
68 68
 		}
69 69
 
70 70
 		// Make sure it's actually a user
71
-		$user = get_user_by( 'id', $customer_info['user_id'] );
72
-		if ( ! empty( $customer_info['user_id'] ) && false === $user ) {
73
-			give_set_error( 'give-invalid-user_id', sprintf( __( 'The User ID %d does not exist. Please assign an existing user.', 'give' ), $customer_info['user_id'] ) );
71
+		$user = get_user_by('id', $customer_info['user_id']);
72
+		if ( ! empty($customer_info['user_id']) && false === $user) {
73
+			give_set_error('give-invalid-user_id', sprintf(__('The User ID %d does not exist. Please assign an existing user.', 'give'), $customer_info['user_id']));
74 74
 		}
75 75
 
76 76
 	}
@@ -78,82 +78,82 @@  discard block
 block discarded – undo
78 78
 	// Record this for later
79 79
 	$previous_user_id = $customer->user_id;
80 80
 
81
-	if ( give_get_errors() ) {
81
+	if (give_get_errors()) {
82 82
 		return;
83 83
 	}
84 84
 
85 85
 	// Setup the customer address, if present
86 86
 	$address = array();
87
-	if ( intval( $customer_info['user_id'] ) > 0 ) {
87
+	if (intval($customer_info['user_id']) > 0) {
88 88
 
89
-		$current_address = get_user_meta( $customer_info['user_id'], '_give_user_address', true );
89
+		$current_address = get_user_meta($customer_info['user_id'], '_give_user_address', true);
90 90
 
91
-		if ( false === $current_address ) {
92
-			$address['line1']   = isset( $customer_info['line1'] ) ? $customer_info['line1'] : '';
93
-			$address['line2']   = isset( $customer_info['line2'] ) ? $customer_info['line2'] : '';
94
-			$address['city']    = isset( $customer_info['city'] ) ? $customer_info['city'] : '';
95
-			$address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : '';
96
-			$address['zip']     = isset( $customer_info['zip'] ) ? $customer_info['zip'] : '';
97
-			$address['state']   = isset( $customer_info['state'] ) ? $customer_info['state'] : '';
91
+		if (false === $current_address) {
92
+			$address['line1']   = isset($customer_info['line1']) ? $customer_info['line1'] : '';
93
+			$address['line2']   = isset($customer_info['line2']) ? $customer_info['line2'] : '';
94
+			$address['city']    = isset($customer_info['city']) ? $customer_info['city'] : '';
95
+			$address['country'] = isset($customer_info['country']) ? $customer_info['country'] : '';
96
+			$address['zip']     = isset($customer_info['zip']) ? $customer_info['zip'] : '';
97
+			$address['state']   = isset($customer_info['state']) ? $customer_info['state'] : '';
98 98
 		} else {
99
-			$current_address    = wp_parse_args( $current_address, array(
99
+			$current_address    = wp_parse_args($current_address, array(
100 100
 				'line1',
101 101
 				'line2',
102 102
 				'city',
103 103
 				'zip',
104 104
 				'state',
105 105
 				'country'
106
-			) );
107
-			$address['line1']   = isset( $customer_info['line1'] ) ? $customer_info['line1'] : $current_address['line1'];
108
-			$address['line2']   = isset( $customer_info['line2'] ) ? $customer_info['line2'] : $current_address['line2'];
109
-			$address['city']    = isset( $customer_info['city'] ) ? $customer_info['city'] : $current_address['city'];
110
-			$address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : $current_address['country'];
111
-			$address['zip']     = isset( $customer_info['zip'] ) ? $customer_info['zip'] : $current_address['zip'];
112
-			$address['state']   = isset( $customer_info['state'] ) ? $customer_info['state'] : $current_address['state'];
106
+			));
107
+			$address['line1']   = isset($customer_info['line1']) ? $customer_info['line1'] : $current_address['line1'];
108
+			$address['line2']   = isset($customer_info['line2']) ? $customer_info['line2'] : $current_address['line2'];
109
+			$address['city']    = isset($customer_info['city']) ? $customer_info['city'] : $current_address['city'];
110
+			$address['country'] = isset($customer_info['country']) ? $customer_info['country'] : $current_address['country'];
111
+			$address['zip']     = isset($customer_info['zip']) ? $customer_info['zip'] : $current_address['zip'];
112
+			$address['state']   = isset($customer_info['state']) ? $customer_info['state'] : $current_address['state'];
113 113
 		}
114 114
 
115 115
 	}
116 116
 
117 117
 	// Sanitize the inputs
118 118
 	$customer_data            = array();
119
-	$customer_data['name']    = strip_tags( stripslashes( $customer_info['name'] ) );
119
+	$customer_data['name']    = strip_tags(stripslashes($customer_info['name']));
120 120
 	$customer_data['email']   = $customer_info['email'];
121 121
 	$customer_data['user_id'] = $customer_info['user_id'];
122 122
 
123
-	$customer_data = apply_filters( 'give_edit_customer_info', $customer_data, $customer_id );
124
-	$address       = apply_filters( 'give_edit_customer_address', $address, $customer_id );
123
+	$customer_data = apply_filters('give_edit_customer_info', $customer_data, $customer_id);
124
+	$address       = apply_filters('give_edit_customer_address', $address, $customer_id);
125 125
 
126
-	$customer_data = array_map( 'sanitize_text_field', $customer_data );
127
-	$address       = array_map( 'sanitize_text_field', $address );
126
+	$customer_data = array_map('sanitize_text_field', $customer_data);
127
+	$address       = array_map('sanitize_text_field', $address);
128 128
 
129
-	do_action( 'give_pre_edit_customer', $customer_id, $customer_data, $address );
129
+	do_action('give_pre_edit_customer', $customer_id, $customer_data, $address);
130 130
 
131 131
 	$output         = array();
132 132
 	$previous_email = $customer->email;
133 133
 
134
-	if ( $customer->update( $customer_data ) ) {
134
+	if ($customer->update($customer_data)) {
135 135
 
136
-		if ( ! empty( $customer->user_id ) && $customer->user_id > 0 ) {
137
-			update_user_meta( $customer->user_id, '_give_user_address', $address );
136
+		if ( ! empty($customer->user_id) && $customer->user_id > 0) {
137
+			update_user_meta($customer->user_id, '_give_user_address', $address);
138 138
 		}
139 139
 
140 140
 		// Update some payment meta if we need to
141
-		$payments_array = explode( ',', $customer->payment_ids );
141
+		$payments_array = explode(',', $customer->payment_ids);
142 142
 
143
-		if ( $customer->email != $previous_email ) {
144
-			foreach ( $payments_array as $payment_id ) {
145
-				give_update_payment_meta( $payment_id, 'email', $customer->email );
143
+		if ($customer->email != $previous_email) {
144
+			foreach ($payments_array as $payment_id) {
145
+				give_update_payment_meta($payment_id, 'email', $customer->email);
146 146
 			}
147 147
 		}
148 148
 
149
-		if ( $customer->user_id != $previous_user_id ) {
150
-			foreach ( $payments_array as $payment_id ) {
151
-				give_update_payment_meta( $payment_id, '_give_payment_user_id', $customer->user_id );
149
+		if ($customer->user_id != $previous_user_id) {
150
+			foreach ($payments_array as $payment_id) {
151
+				give_update_payment_meta($payment_id, '_give_payment_user_id', $customer->user_id);
152 152
 			}
153 153
 		}
154 154
 
155 155
 		$output['success']       = true;
156
-		$customer_data           = array_merge( $customer_data, $address );
156
+		$customer_data           = array_merge($customer_data, $address);
157 157
 		$output['customer_info'] = $customer_data;
158 158
 
159 159
 	} else {
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 
163 163
 	}
164 164
 
165
-	do_action( 'give_post_edit_customer', $customer_id, $customer_data );
165
+	do_action('give_post_edit_customer', $customer_id, $customer_data);
166 166
 
167
-	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
168
-		header( 'Content-Type: application/json' );
169
-		echo json_encode( $output );
167
+	if (defined('DOING_AJAX') && DOING_AJAX) {
168
+		header('Content-Type: application/json');
169
+		echo json_encode($output);
170 170
 		wp_die();
171 171
 	}
172 172
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 
175 175
 }
176 176
 
177
-add_action( 'give_edit-customer', 'give_edit_customer', 10, 1 );
177
+add_action('give_edit-customer', 'give_edit_customer', 10, 1);
178 178
 
179 179
 /**
180 180
  * Save a customer note being added
@@ -185,53 +185,53 @@  discard block
 block discarded – undo
185 185
  *
186 186
  * @return int         The Note ID that was saved, or 0 if nothing was saved
187 187
  */
188
-function give_customer_save_note( $args ) {
188
+function give_customer_save_note($args) {
189 189
 
190
-	$customer_view_role = apply_filters( 'give_view_customers_role', 'view_give_reports' );
190
+	$customer_view_role = apply_filters('give_view_customers_role', 'view_give_reports');
191 191
 
192
-	if ( ! is_admin() || ! current_user_can( $customer_view_role ) ) {
193
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ) );
192
+	if ( ! is_admin() || ! current_user_can($customer_view_role)) {
193
+		wp_die(__('You do not have permission to edit this donor.', 'give'));
194 194
 	}
195 195
 
196
-	if ( empty( $args ) ) {
196
+	if (empty($args)) {
197 197
 		return;
198 198
 	}
199 199
 
200
-	$customer_note = trim( sanitize_text_field( $args['customer_note'] ) );
200
+	$customer_note = trim(sanitize_text_field($args['customer_note']));
201 201
 	$customer_id   = (int) $args['customer_id'];
202 202
 	$nonce         = $args['add_customer_note_nonce'];
203 203
 
204
-	if ( ! wp_verify_nonce( $nonce, 'add-customer-note' ) ) {
205
-		wp_die( __( 'Cheatin\' eh?!', 'give' ) );
204
+	if ( ! wp_verify_nonce($nonce, 'add-customer-note')) {
205
+		wp_die(__('Cheatin\' eh?!', 'give'));
206 206
 	}
207 207
 
208
-	if ( empty( $customer_note ) ) {
209
-		give_set_error( 'empty-customer-note', __( 'A note is required', 'give' ) );
208
+	if (empty($customer_note)) {
209
+		give_set_error('empty-customer-note', __('A note is required', 'give'));
210 210
 	}
211 211
 
212
-	if ( give_get_errors() ) {
212
+	if (give_get_errors()) {
213 213
 		return;
214 214
 	}
215 215
 
216
-	$customer = new Give_Customer( $customer_id );
217
-	$new_note = $customer->add_note( $customer_note );
216
+	$customer = new Give_Customer($customer_id);
217
+	$new_note = $customer->add_note($customer_note);
218 218
 
219
-	do_action( 'give_pre_insert_customer_note', $customer_id, $new_note );
219
+	do_action('give_pre_insert_customer_note', $customer_id, $new_note);
220 220
 
221
-	if ( ! empty( $new_note ) && ! empty( $customer->id ) ) {
221
+	if ( ! empty($new_note) && ! empty($customer->id)) {
222 222
 
223 223
 		ob_start();
224 224
 		?>
225 225
 		<div class="customer-note-wrapper dashboard-comment-wrap comment-item">
226 226
 			<span class="note-content-wrap">
227
-				<?php echo stripslashes( $new_note ); ?>
227
+				<?php echo stripslashes($new_note); ?>
228 228
 			</span>
229 229
 		</div>
230 230
 		<?php
231 231
 		$output = ob_get_contents();
232 232
 		ob_end_clean();
233 233
 
234
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
234
+		if (defined('DOING_AJAX') && DOING_AJAX) {
235 235
 			echo $output;
236 236
 			exit;
237 237
 		}
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 
245 245
 }
246 246
 
247
-add_action( 'give_add-customer-note', 'give_customer_save_note', 10, 1 );
247
+add_action('give_add-customer-note', 'give_customer_save_note', 10, 1);
248 248
 
249 249
 /**
250 250
  * Delete a customer
@@ -255,87 +255,87 @@  discard block
 block discarded – undo
255 255
  *
256 256
  * @return int Whether it was a successful deletion
257 257
  */
258
-function give_customer_delete( $args ) {
258
+function give_customer_delete($args) {
259 259
 
260
-	$customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' );
260
+	$customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments');
261 261
 
262
-	if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
263
-		wp_die( __( 'You do not have permission to delete donors.', 'give' ) );
262
+	if ( ! is_admin() || ! current_user_can($customer_edit_role)) {
263
+		wp_die(__('You do not have permission to delete donors.', 'give'));
264 264
 	}
265 265
 
266
-	if ( empty( $args ) ) {
266
+	if (empty($args)) {
267 267
 		return;
268 268
 	}
269 269
 
270 270
 	$customer_id = (int) $args['customer_id'];
271
-	$confirm     = ! empty( $args['give-customer-delete-confirm'] ) ? true : false;
272
-	$remove_data = ! empty( $args['give-customer-delete-records'] ) ? true : false;
271
+	$confirm     = ! empty($args['give-customer-delete-confirm']) ? true : false;
272
+	$remove_data = ! empty($args['give-customer-delete-records']) ? true : false;
273 273
 	$nonce       = $args['_wpnonce'];
274 274
 
275
-	if ( ! wp_verify_nonce( $nonce, 'delete-customer' ) ) {
276
-		wp_die( __( 'Cheatin\' eh?!', 'give' ) );
275
+	if ( ! wp_verify_nonce($nonce, 'delete-customer')) {
276
+		wp_die(__('Cheatin\' eh?!', 'give'));
277 277
 	}
278 278
 
279
-	if ( ! $confirm ) {
280
-		give_set_error( 'customer-delete-no-confirm', __( 'Please confirm you want to delete this donor', 'give' ) );
279
+	if ( ! $confirm) {
280
+		give_set_error('customer-delete-no-confirm', __('Please confirm you want to delete this donor', 'give'));
281 281
 	}
282 282
 
283
-	if ( give_get_errors() ) {
284
-		wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id ) );
283
+	if (give_get_errors()) {
284
+		wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer_id));
285 285
 		exit;
286 286
 	}
287 287
 
288
-	$customer = new Give_Customer( $customer_id );
288
+	$customer = new Give_Customer($customer_id);
289 289
 
290
-	do_action( 'give_pre_delete_customer', $customer_id, $confirm, $remove_data );
290
+	do_action('give_pre_delete_customer', $customer_id, $confirm, $remove_data);
291 291
 
292 292
 	$success = false;
293 293
 
294
-	if ( $customer->id > 0 ) {
294
+	if ($customer->id > 0) {
295 295
 
296
-		$payments_array = explode( ',', $customer->payment_ids );
297
-		$success        = Give()->customers->delete( $customer->id );
296
+		$payments_array = explode(',', $customer->payment_ids);
297
+		$success        = Give()->customers->delete($customer->id);
298 298
 
299
-		if ( $success ) {
299
+		if ($success) {
300 300
 
301
-			if ( $remove_data ) {
301
+			if ($remove_data) {
302 302
 
303 303
 				// Remove all payments, logs, etc
304
-				foreach ( $payments_array as $payment_id ) {
305
-					give_delete_purchase( $payment_id );
304
+				foreach ($payments_array as $payment_id) {
305
+					give_delete_purchase($payment_id);
306 306
 				}
307 307
 
308 308
 			} else {
309 309
 
310 310
 				// Just set the payments to customer_id of 0
311
-				foreach ( $payments_array as $payment_id ) {
312
-					give_update_payment_meta( $payment_id, '_give_payment_customer_id', 0 );
311
+				foreach ($payments_array as $payment_id) {
312
+					give_update_payment_meta($payment_id, '_give_payment_customer_id', 0);
313 313
 				}
314 314
 
315 315
 			}
316 316
 
317
-			$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted' );
317
+			$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted');
318 318
 
319 319
 		} else {
320 320
 
321
-			give_set_error( 'give-donor-delete-failed', __( 'Error deleting donor', 'give' ) );
322
-			$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $customer_id );
321
+			give_set_error('give-donor-delete-failed', __('Error deleting donor', 'give'));
322
+			$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$customer_id);
323 323
 
324 324
 		}
325 325
 
326 326
 	} else {
327 327
 
328
-		give_set_error( 'give-customer-delete-invalid-id', __( 'Invalid Donor ID', 'give' ) );
329
-		$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors' );
328
+		give_set_error('give-customer-delete-invalid-id', __('Invalid Donor ID', 'give'));
329
+		$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors');
330 330
 
331 331
 	}
332 332
 
333
-	wp_redirect( $redirect );
333
+	wp_redirect($redirect);
334 334
 	exit;
335 335
 
336 336
 }
337 337
 
338
-add_action( 'give_delete-customer', 'give_customer_delete', 10, 1 );
338
+add_action('give_delete-customer', 'give_customer_delete', 10, 1);
339 339
 
340 340
 /**
341 341
  * Disconnect a user ID from a donor
@@ -346,39 +346,39 @@  discard block
 block discarded – undo
346 346
  *
347 347
  * @return bool        If the disconnect was successful
348 348
  */
349
-function give_disconnect_customer_user_id( $args ) {
349
+function give_disconnect_customer_user_id($args) {
350 350
 
351
-	$customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' );
351
+	$customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments');
352 352
 
353
-	if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
354
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ) );
353
+	if ( ! is_admin() || ! current_user_can($customer_edit_role)) {
354
+		wp_die(__('You do not have permission to edit this donor.', 'give'));
355 355
 	}
356 356
 
357
-	if ( empty( $args ) ) {
357
+	if (empty($args)) {
358 358
 		return;
359 359
 	}
360 360
 
361 361
 	$customer_id = (int) $args['customer_id'];
362 362
 	$nonce       = $args['_wpnonce'];
363 363
 
364
-	if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) {
365
-		wp_die( __( 'Cheatin\' eh?!', 'give' ) );
364
+	if ( ! wp_verify_nonce($nonce, 'edit-customer')) {
365
+		wp_die(__('Cheatin\' eh?!', 'give'));
366 366
 	}
367 367
 
368
-	$customer = new Give_Customer( $customer_id );
369
-	if ( empty( $customer->id ) ) {
368
+	$customer = new Give_Customer($customer_id);
369
+	if (empty($customer->id)) {
370 370
 		return false;
371 371
 	}
372 372
 
373
-	do_action( 'give_pre_customer_disconnect_user_id', $customer_id, $customer->user_id );
373
+	do_action('give_pre_customer_disconnect_user_id', $customer_id, $customer->user_id);
374 374
 
375
-	$customer_args = array( 'user_id' => 0 );
375
+	$customer_args = array('user_id' => 0);
376 376
 
377
-	if ( $customer->update( $customer_args ) ) {
377
+	if ($customer->update($customer_args)) {
378 378
 		global $wpdb;
379 379
 
380
-		if ( ! empty( $customer->payment_ids ) ) {
381
-			$wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )" );
380
+		if ( ! empty($customer->payment_ids)) {
381
+			$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )");
382 382
 		}
383 383
 
384 384
 		$output['success'] = true;
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
 	} else {
387 387
 
388 388
 		$output['success'] = false;
389
-		give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor', 'give' ) );
389
+		give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor', 'give'));
390 390
 	}
391 391
 
392
-	do_action( 'give_post_customer_disconnect_user_id', $customer_id );
392
+	do_action('give_post_customer_disconnect_user_id', $customer_id);
393 393
 
394
-	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
395
-		header( 'Content-Type: application/json' );
396
-		echo json_encode( $output );
394
+	if (defined('DOING_AJAX') && DOING_AJAX) {
395
+		header('Content-Type: application/json');
396
+		echo json_encode($output);
397 397
 		wp_die();
398 398
 	}
399 399
 
@@ -401,4 +401,4 @@  discard block
 block discarded – undo
401 401
 
402 402
 }
403 403
 
404
-add_action( 'give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1 );
404
+add_action('give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1);
Please login to merge, or discard this patch.
includes/admin/upgrades/upgrade-functions.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 // Exit if accessed directly
16
-if ( ! defined( 'ABSPATH' ) ) {
16
+if ( ! defined('ABSPATH')) {
17 17
 	exit;
18 18
 }
19 19
 
@@ -25,18 +25,18 @@  discard block
 block discarded – undo
25 25
  */
26 26
 function give_show_upgrade_notices() {
27 27
 
28
-	if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-upgrades' ) {
28
+	if (isset($_GET['page']) && $_GET['page'] == 'give-upgrades') {
29 29
 		return;
30 30
 	} // Don't show notices on the upgrades page
31 31
 
32
-	$give_version = get_option( 'give_version' );
32
+	$give_version = get_option('give_version');
33 33
 
34
-	if ( ! $give_version ) {
34
+	if ( ! $give_version) {
35 35
 		// 1.0 is the first version to use this option so we must add it
36 36
 		$give_version = '1.0';
37 37
 	}
38 38
 
39
-	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
39
+	$give_version = preg_replace('/[^0-9.].*/', '', $give_version);
40 40
 
41 41
 	/*
42 42
 	 *  NOTICE:
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 
49 49
 	//v1.3.2 Upgrades
50
-	if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) {
50
+	if (version_compare($give_version, '1.3.2', '<') || ! give_has_upgrade_completed('upgrade_give_payment_customer_id')) {
51 51
 		printf(
52
-			'<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
53
-			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) )
52
+			'<div class="updated"><p>'.__('Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>',
53
+			esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id'))
54 54
 		);
55 55
 	}
56 56
 
57 57
 	//v1.3.4 Upgrades //ensure the user has gone through 1.3.4
58
-	if ( version_compare( $give_version, '1.3.4', '<' ) || ( ! give_has_upgrade_completed( 'upgrade_give_offline_status' ) && give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) ) {
58
+	if (version_compare($give_version, '1.3.4', '<') || ( ! give_has_upgrade_completed('upgrade_give_offline_status') && give_has_upgrade_completed('upgrade_give_payment_customer_id'))) {
59 59
 		printf(
60
-			'<div class="updated"><p>' . __( 'Give needs to upgrade the transaction database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
61
-			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) )
60
+			'<div class="updated"><p>'.__('Give needs to upgrade the transaction database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>',
61
+			esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status'))
62 62
 		);
63 63
 	}
64 64
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
 }
70 70
 
71
-add_action( 'admin_notices', 'give_show_upgrade_notices' );
71
+add_action('admin_notices', 'give_show_upgrade_notices');
72 72
 
73 73
 /**
74 74
  * Triggers all upgrade functions
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function give_trigger_upgrades() {
82 82
 
83
-	if ( ! current_user_can( 'manage_give_settings' ) ) {
84
-		wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
83
+	if ( ! current_user_can('manage_give_settings')) {
84
+		wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403));
85 85
 	}
86 86
 
87
-	$give_version = get_option( 'give_version' );
87
+	$give_version = get_option('give_version');
88 88
 
89
-	if ( ! $give_version ) {
89
+	if ( ! $give_version) {
90 90
 		// 1.0 is the first version to use this option so we must add it
91 91
 		$give_version = '1.0';
92
-		add_option( 'give_version', $give_version );
92
+		add_option('give_version', $give_version);
93 93
 	}
94 94
 
95
-	update_option( 'give_version', GIVE_VERSION );
95
+	update_option('give_version', GIVE_VERSION);
96 96
 
97
-	if ( DOING_AJAX ) {
98
-		die( 'complete' );
97
+	if (DOING_AJAX) {
98
+		die('complete');
99 99
 	} // Let AJAX know that the upgrade is complete
100 100
 }
101 101
 
102
-add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' );
102
+add_action('wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades');
103 103
 
104 104
 /**
105 105
  * Check if the upgrade routine has been run for a specific action
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
  *
111 111
  * @return bool                   If the action has been added to the completed actions array
112 112
  */
113
-function give_has_upgrade_completed( $upgrade_action = '' ) {
113
+function give_has_upgrade_completed($upgrade_action = '') {
114 114
 
115
-	if ( empty( $upgrade_action ) ) {
115
+	if (empty($upgrade_action)) {
116 116
 		return false;
117 117
 	}
118 118
 
119 119
 	$completed_upgrades = give_get_completed_upgrades();
120 120
 
121
-	return in_array( $upgrade_action, $completed_upgrades );
121
+	return in_array($upgrade_action, $completed_upgrades);
122 122
 
123 123
 }
124 124
 
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
  *
132 132
  * @return bool                   If the function was successfully added
133 133
  */
134
-function give_set_upgrade_complete( $upgrade_action = '' ) {
134
+function give_set_upgrade_complete($upgrade_action = '') {
135 135
 
136
-	if ( empty( $upgrade_action ) ) {
136
+	if (empty($upgrade_action)) {
137 137
 		return false;
138 138
 	}
139 139
 
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	$completed_upgrades[] = $upgrade_action;
142 142
 
143 143
 	// Remove any blanks, and only show uniques
144
-	$completed_upgrades = array_unique( array_values( $completed_upgrades ) );
144
+	$completed_upgrades = array_unique(array_values($completed_upgrades));
145 145
 
146
-	return update_option( 'give_completed_upgrades', $completed_upgrades );
146
+	return update_option('give_completed_upgrades', $completed_upgrades);
147 147
 }
148 148
 
149 149
 /**
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
  */
155 155
 function give_get_completed_upgrades() {
156 156
 
157
-	$completed_upgrades = get_option( 'give_completed_upgrades' );
157
+	$completed_upgrades = get_option('give_completed_upgrades');
158 158
 
159
-	if ( false === $completed_upgrades ) {
159
+	if (false === $completed_upgrades) {
160 160
 		$completed_upgrades = array();
161 161
 	}
162 162
 
@@ -175,30 +175,30 @@  discard block
 block discarded – undo
175 175
  */
176 176
 function give_v132_upgrade_give_payment_customer_id() {
177 177
 	global $wpdb;
178
-	if ( ! current_user_can( 'manage_give_settings' ) ) {
179
-		wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
178
+	if ( ! current_user_can('manage_give_settings')) {
179
+		wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403));
180 180
 	}
181 181
 
182
-	ignore_user_abort( true );
182
+	ignore_user_abort(true);
183 183
 
184
-	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
185
-		@set_time_limit( 0 );
184
+	if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) {
185
+		@set_time_limit(0);
186 186
 	}
187 187
 
188 188
 	//UPDATE DB METAKEYS
189 189
 	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
190
-	$query = $wpdb->query( $sql );
190
+	$query = $wpdb->query($sql);
191 191
 
192
-	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
193
-	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
194
-	delete_option( 'give_doing_upgrade' );
195
-	wp_redirect( admin_url() );
192
+	update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION));
193
+	give_set_upgrade_complete('upgrade_give_payment_customer_id');
194
+	delete_option('give_doing_upgrade');
195
+	wp_redirect(admin_url());
196 196
 	exit;
197 197
 
198 198
 
199 199
 }
200 200
 
201
-add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' );
201
+add_action('give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id');
202 202
 
203 203
 /**
204 204
  * Upgrades the Offline Status
@@ -212,14 +212,14 @@  discard block
 block discarded – undo
212 212
 
213 213
 	global $wpdb;
214 214
 
215
-	if ( ! current_user_can( 'manage_give_settings' ) ) {
216
-		wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
215
+	if ( ! current_user_can('manage_give_settings')) {
216
+		wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403));
217 217
 	}
218 218
 
219
-	ignore_user_abort( true );
219
+	ignore_user_abort(true);
220 220
 
221
-	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
222
-		@set_time_limit( 0 );
221
+	if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) {
222
+		@set_time_limit(0);
223 223
 	}
224 224
 
225 225
 	// Get abandoned offline payments
@@ -229,35 +229,35 @@  discard block
 block discarded – undo
229 229
 	$where .= "AND ( p.post_status = 'abandoned' )";
230 230
 	$where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
231 231
 
232
-	$sql            = $select . $join . $where;
233
-	$found_payments = $wpdb->get_col( $sql );
232
+	$sql            = $select.$join.$where;
233
+	$found_payments = $wpdb->get_col($sql);
234 234
 
235 235
 
236
-	foreach ( $found_payments as $payment ) {
236
+	foreach ($found_payments as $payment) {
237 237
 
238 238
 		//Only change ones marked abandoned since our release last week
239 239
 		//because the admin may have marked some abandoned themselves
240
-		$modified_time = get_post_modified_time( 'U', false, $payment );
240
+		$modified_time = get_post_modified_time('U', false, $payment);
241 241
 
242 242
 		//1450124863 =  12/10/2015 20:42:25
243
-		if ( $modified_time >= 1450124863 ) {
243
+		if ($modified_time >= 1450124863) {
244 244
 
245
-			give_update_payment_status( $payment, 'pending' );
245
+			give_update_payment_status($payment, 'pending');
246 246
 
247 247
 		}
248 248
 
249 249
 	}
250 250
 
251
-	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
252
-	give_set_upgrade_complete( 'upgrade_give_offline_status' );
253
-	delete_option( 'give_doing_upgrade' );
254
-	wp_redirect( admin_url() );
251
+	update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION));
252
+	give_set_upgrade_complete('upgrade_give_offline_status');
253
+	delete_option('give_doing_upgrade');
254
+	wp_redirect(admin_url());
255 255
 	exit;
256 256
 
257 257
 
258 258
 }
259 259
 
260
-add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' );
260
+add_action('give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status');
261 261
 
262 262
 
263 263
 /**
@@ -269,17 +269,17 @@  discard block
 block discarded – undo
269 269
  */
270 270
 function give_v152_cleanup_users() {
271 271
 
272
-	$give_version = get_option( 'give_version' );
272
+	$give_version = get_option('give_version');
273 273
 
274
-	if ( ! $give_version ) {
274
+	if ( ! $give_version) {
275 275
 		// 1.0 is the first version to use this option so we must add it
276 276
 		$give_version = '1.0';
277 277
 	}
278 278
 
279
-	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
279
+	$give_version = preg_replace('/[^0-9.].*/', '', $give_version);
280 280
 
281 281
 	//v1.5.2 Upgrades
282
-	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
282
+	if (version_compare($give_version, '1.5.2', '<') || ! give_has_upgrade_completed('upgrade_give_user_caps_cleanup')) {
283 283
 
284 284
 		//Delete all caps with "ss"
285 285
 		//Also delete all unused "campaign" roles
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
 		);
327 327
 	
328 328
 		global $wp_roles;
329
-		foreach ( $delete_caps as $cap ) {
330
-			foreach ( array_keys( $wp_roles->roles ) as $role ) {
331
-				$wp_roles->remove_cap( $role, $cap );
329
+		foreach ($delete_caps as $cap) {
330
+			foreach (array_keys($wp_roles->roles) as $role) {
331
+				$wp_roles->remove_cap($role, $cap);
332 332
 			}
333 333
 		}
334 334
 	
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
 		$roles->add_caps();
339 339
 		
340 340
 		//The Update Ran
341
-		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
342
-		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
343
-		delete_option( 'give_doing_upgrade' );
341
+		update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION));
342
+		give_set_upgrade_complete('upgrade_give_user_caps_cleanup');
343
+		delete_option('give_doing_upgrade');
344 344
 
345 345
 	}
346 346
 
347 347
 }
348 348
 
349
-add_action( 'admin_init', 'give_v152_cleanup_users' );
350 349
\ No newline at end of file
350
+add_action('admin_init', 'give_v152_cleanup_users');
351 351
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/payments/actions.php 1 patch
Spacing   +96 added lines, -96 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
 
@@ -26,106 +26,106 @@  discard block
 block discarded – undo
26 26
  * @return      void
27 27
  *
28 28
  */
29
-function give_update_payment_details( $data ) {
29
+function give_update_payment_details($data) {
30 30
 
31
-	if ( ! current_user_can( 'edit_give_payments', $data['give_payment_id'] ) ) {
32
-		wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
31
+	if ( ! current_user_can('edit_give_payments', $data['give_payment_id'])) {
32
+		wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
33 33
 	}
34 34
 
35
-	check_admin_referer( 'give_update_payment_details_nonce' );
35
+	check_admin_referer('give_update_payment_details_nonce');
36 36
 
37 37
 	// Retrieve the payment ID
38
-	$payment_id = absint( $data['give_payment_id'] );
39
-	$payment    = new Give_Payment( $payment_id );
38
+	$payment_id = absint($data['give_payment_id']);
39
+	$payment    = new Give_Payment($payment_id);
40 40
 
41 41
 	// Retrieve existing payment meta
42 42
 	$meta      = $payment->get_meta();
43 43
 	$user_info = $payment->user_info;
44 44
 
45 45
 	$status = $data['give-payment-status'];
46
-	$date   = sanitize_text_field( $data['give-payment-date'] );
47
-	$hour   = sanitize_text_field( $data['give-payment-time-hour'] );
46
+	$date   = sanitize_text_field($data['give-payment-date']);
47
+	$hour   = sanitize_text_field($data['give-payment-time-hour']);
48 48
 
49 49
 	// Restrict to our high and low
50
-	if ( $hour > 23 ) {
50
+	if ($hour > 23) {
51 51
 		$hour = 23;
52
-	} elseif ( $hour < 0 ) {
52
+	} elseif ($hour < 0) {
53 53
 		$hour = 00;
54 54
 	}
55 55
 
56
-	$minute = sanitize_text_field( $data['give-payment-time-min'] );
56
+	$minute = sanitize_text_field($data['give-payment-time-min']);
57 57
 
58 58
 	// Restrict to our high and low
59
-	if ( $minute > 59 ) {
59
+	if ($minute > 59) {
60 60
 		$minute = 59;
61
-	} elseif ( $minute < 0 ) {
61
+	} elseif ($minute < 0) {
62 62
 		$minute = 00;
63 63
 	}
64 64
 
65
-	$address = array_map( 'trim', $data['give-payment-address'][0] );
65
+	$address = array_map('trim', $data['give-payment-address'][0]);
66 66
 
67
-	$curr_total = give_sanitize_amount( $payment->total );
68
-	$new_total  = give_sanitize_amount( $_POST['give-payment-total'] );
69
-	$date       = date( 'Y-m-d', strtotime( $date ) ) . ' ' . $hour . ':' . $minute . ':00';
67
+	$curr_total = give_sanitize_amount($payment->total);
68
+	$new_total  = give_sanitize_amount($_POST['give-payment-total']);
69
+	$date       = date('Y-m-d', strtotime($date)).' '.$hour.':'.$minute.':00';
70 70
 
71
-	$curr_customer_id = sanitize_text_field( $data['give-current-customer'] );
72
-	$new_customer_id  = sanitize_text_field( $data['customer-id'] );
71
+	$curr_customer_id = sanitize_text_field($data['give-current-customer']);
72
+	$new_customer_id  = sanitize_text_field($data['customer-id']);
73 73
 
74
-	do_action( 'give_update_edited_purchase', $payment_id );
74
+	do_action('give_update_edited_purchase', $payment_id);
75 75
 
76 76
 	$payment->date = $date;
77 77
 	$updated       = $payment->save();
78 78
 
79
-	if ( 0 === $updated ) {
80
-		wp_die( esc_attr__( 'Error Updating Payment', 'give' ), esc_attr__( 'Error', 'give' ), array( 'response' => 400 ) );
79
+	if (0 === $updated) {
80
+		wp_die(esc_attr__('Error Updating Payment', 'give'), esc_attr__('Error', 'give'), array('response' => 400));
81 81
 	}
82 82
 
83 83
 	$customer_changed = false;
84 84
 
85
-	if ( isset( $data['give-new-customer'] ) && $data['give-new-customer'] == '1' ) {
85
+	if (isset($data['give-new-customer']) && $data['give-new-customer'] == '1') {
86 86
 
87
-		$email = isset( $data['give-new-customer-email'] ) ? sanitize_text_field( $data['give-new-customer-email'] ) : '';
88
-		$names = isset( $data['give-new-customer-name'] ) ? sanitize_text_field( $data['give-new-customer-name'] ) : '';
87
+		$email = isset($data['give-new-customer-email']) ? sanitize_text_field($data['give-new-customer-email']) : '';
88
+		$names = isset($data['give-new-customer-name']) ? sanitize_text_field($data['give-new-customer-name']) : '';
89 89
 
90
-		if ( empty( $email ) || empty( $names ) ) {
91
-			wp_die( esc_attr__( 'New Customers require a name and email address', 'give' ) );
90
+		if (empty($email) || empty($names)) {
91
+			wp_die(esc_attr__('New Customers require a name and email address', 'give'));
92 92
 		}
93 93
 
94
-		$customer = new Give_Customer( $email );
95
-		if ( empty( $customer->id ) ) {
96
-			$customer_data = array( 'name' => $names, 'email' => $email );
97
-			$user_id       = email_exists( $email );
98
-			if ( false !== $user_id ) {
94
+		$customer = new Give_Customer($email);
95
+		if (empty($customer->id)) {
96
+			$customer_data = array('name' => $names, 'email' => $email);
97
+			$user_id       = email_exists($email);
98
+			if (false !== $user_id) {
99 99
 				$customer_data['user_id'] = $user_id;
100 100
 			}
101 101
 
102
-			if ( ! $customer->create( $customer_data ) ) {
102
+			if ( ! $customer->create($customer_data)) {
103 103
 				// Failed to crete the new donor, assume the previous donor
104 104
 				$customer_changed = false;
105
-				$customer         = new Give_Customer( $curr_customer_id );
106
-				give_set_error( 'give-payment-new-customer-fail', __( 'Error creating new donor', 'give' ) );
105
+				$customer         = new Give_Customer($curr_customer_id);
106
+				give_set_error('give-payment-new-customer-fail', __('Error creating new donor', 'give'));
107 107
 			}
108 108
 		}
109 109
 
110 110
 		$new_customer_id = $customer->id;
111 111
 
112
-		$previous_customer = new Give_Customer( $curr_customer_id );
112
+		$previous_customer = new Give_Customer($curr_customer_id);
113 113
 
114 114
 		$customer_changed = true;
115 115
 
116
-	} elseif ( $curr_customer_id !== $new_customer_id ) {
116
+	} elseif ($curr_customer_id !== $new_customer_id) {
117 117
 
118
-		$customer = new Give_Customer( $new_customer_id );
118
+		$customer = new Give_Customer($new_customer_id);
119 119
 		$email    = $customer->email;
120 120
 		$names    = $customer->name;
121 121
 
122
-		$previous_customer = new Give_Customer( $curr_customer_id );
122
+		$previous_customer = new Give_Customer($curr_customer_id);
123 123
 
124 124
 		$customer_changed = true;
125 125
 
126 126
 	} else {
127 127
 
128
-		$customer = new Give_Customer( $curr_customer_id );
128
+		$customer = new Give_Customer($curr_customer_id);
129 129
 		$email    = $customer->email;
130 130
 		$names    = $customer->name;
131 131
 
@@ -133,29 +133,29 @@  discard block
 block discarded – undo
133 133
 
134 134
 
135 135
 	// Setup first and last name from input values
136
-	$names      = explode( ' ', $names );
137
-	$first_name = ! empty( $names[0] ) ? $names[0] : '';
136
+	$names      = explode(' ', $names);
137
+	$first_name = ! empty($names[0]) ? $names[0] : '';
138 138
 	$last_name  = '';
139
-	if ( ! empty( $names[1] ) ) {
140
-		unset( $names[0] );
141
-		$last_name = implode( ' ', $names );
139
+	if ( ! empty($names[1])) {
140
+		unset($names[0]);
141
+		$last_name = implode(' ', $names);
142 142
 	}
143 143
 
144 144
 
145
-	if ( $customer_changed ) {
145
+	if ($customer_changed) {
146 146
 
147 147
 		// Remove the stats and payment from the previous customer and attach it to the new customer
148
-		$previous_customer->remove_payment( $payment_id, false );
149
-		$customer->attach_payment( $payment_id, false );
148
+		$previous_customer->remove_payment($payment_id, false);
149
+		$customer->attach_payment($payment_id, false);
150 150
 
151 151
 		// If purchase was completed and not ever refunded, adjust stats of customers
152
-		if ( 'revoked' == $status || 'publish' == $status ) {
152
+		if ('revoked' == $status || 'publish' == $status) {
153 153
 
154 154
 			$previous_customer->decrease_purchase_count();
155
-			$previous_customer->decrease_value( $new_total );
155
+			$previous_customer->decrease_value($new_total);
156 156
 
157 157
 			$customer->increase_purchase_count();
158
-			$customer->increase_value( $new_total );
158
+			$customer->increase_value($new_total);
159 159
 		}
160 160
 
161 161
 		$payment->customer_id = $customer->id;
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 
172 172
 
173 173
 	// Check for payment notes
174
-	if ( ! empty( $data['give-payment-note'] ) ) {
174
+	if ( ! empty($data['give-payment-note'])) {
175 175
 
176
-		$note = wp_kses( $data['give-payment-note'], array() );
177
-		give_insert_payment_note( $payment_id, $note );
176
+		$note = wp_kses($data['give-payment-note'], array());
177
+		give_insert_payment_note($payment_id, $note);
178 178
 
179 179
 	}
180 180
 
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 	$payment->status = $status;
183 183
 
184 184
 	// Adjust total store earnings if the payment total has been changed
185
-	if ( $new_total !== $curr_total && ( 'publish' == $status || 'revoked' == $status ) ) {
185
+	if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) {
186 186
 
187
-		if ( $new_total > $curr_total ) {
187
+		if ($new_total > $curr_total) {
188 188
 			// Increase if our new total is higher
189 189
 			$difference = $new_total - $curr_total;
190
-			give_increase_total_earnings( $difference );
190
+			give_increase_total_earnings($difference);
191 191
 
192
-		} elseif ( $curr_total > $new_total ) {
192
+		} elseif ($curr_total > $new_total) {
193 193
 			// Decrease if our new total is lower
194 194
 			$difference = $curr_total - $new_total;
195
-			give_decrease_total_earnings( $difference );
195
+			give_decrease_total_earnings($difference);
196 196
 
197 197
 		}
198 198
 
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 
201 201
 	$payment->save();
202 202
 
203
-	do_action( 'give_updated_edited_purchase', $payment_id );
203
+	do_action('give_updated_edited_purchase', $payment_id);
204 204
 
205
-	wp_safe_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id=' . $payment_id ) );
205
+	wp_safe_redirect(admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id='.$payment_id));
206 206
 	exit;
207 207
 }
208 208
 
209
-add_action( 'give_update_payment_details', 'give_update_payment_details' );
209
+add_action('give_update_payment_details', 'give_update_payment_details');
210 210
 
211 211
 /**
212 212
  * Trigger a Purchase Deletion
@@ -217,48 +217,48 @@  discard block
 block discarded – undo
217 217
  *
218 218
  * @return void
219 219
  */
220
-function give_trigger_purchase_delete( $data ) {
221
-	if ( wp_verify_nonce( $data['_wpnonce'], 'give_payment_nonce' ) ) {
220
+function give_trigger_purchase_delete($data) {
221
+	if (wp_verify_nonce($data['_wpnonce'], 'give_payment_nonce')) {
222 222
 
223
-		$payment_id = absint( $data['purchase_id'] );
223
+		$payment_id = absint($data['purchase_id']);
224 224
 
225
-		if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) {
226
-			wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
225
+		if ( ! current_user_can('edit_give_payments', $payment_id)) {
226
+			wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
227 227
 		}
228 228
 
229
-		give_delete_purchase( $payment_id );
230
-		wp_redirect( admin_url( '/edit.php?post_type=give_forms&page=give-payment-history&give-message=payment_deleted' ) );
229
+		give_delete_purchase($payment_id);
230
+		wp_redirect(admin_url('/edit.php?post_type=give_forms&page=give-payment-history&give-message=payment_deleted'));
231 231
 		give_die();
232 232
 	}
233 233
 }
234 234
 
235
-add_action( 'give_delete_payment', 'give_trigger_purchase_delete' );
235
+add_action('give_delete_payment', 'give_trigger_purchase_delete');
236 236
 
237 237
 /**
238 238
  * AJAX Store Payment Note
239 239
  */
240 240
 function give_ajax_store_payment_note() {
241 241
 
242
-	$payment_id = absint( $_POST['payment_id'] );
243
-	$note       = wp_kses( $_POST['note'], array() );
242
+	$payment_id = absint($_POST['payment_id']);
243
+	$note       = wp_kses($_POST['note'], array());
244 244
 
245
-	if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) {
246
-		wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
245
+	if ( ! current_user_can('edit_give_payments', $payment_id)) {
246
+		wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
247 247
 	}
248 248
 
249
-	if ( empty( $payment_id ) ) {
250
-		die( '-1' );
249
+	if (empty($payment_id)) {
250
+		die('-1');
251 251
 	}
252 252
 
253
-	if ( empty( $note ) ) {
254
-		die( '-1' );
253
+	if (empty($note)) {
254
+		die('-1');
255 255
 	}
256 256
 
257
-	$note_id = give_insert_payment_note( $payment_id, $note );
258
-	die( give_get_payment_note_html( $note_id ) );
257
+	$note_id = give_insert_payment_note($payment_id, $note);
258
+	die(give_get_payment_note_html($note_id));
259 259
 }
260 260
 
261
-add_action( 'wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note' );
261
+add_action('wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note');
262 262
 
263 263
 /**
264 264
  * Triggers a payment note deletion without ajax
@@ -269,24 +269,24 @@  discard block
 block discarded – undo
269 269
  *
270 270
  * @return void
271 271
  */
272
-function give_trigger_payment_note_deletion( $data ) {
272
+function give_trigger_payment_note_deletion($data) {
273 273
 
274
-	if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_delete_payment_note_' . $data['note_id'] ) ) {
274
+	if ( ! wp_verify_nonce($data['_wpnonce'], 'give_delete_payment_note_'.$data['note_id'])) {
275 275
 		return;
276 276
 	}
277 277
 
278
-	if ( ! current_user_can( 'edit_give_payments', $data['payment_id'] ) ) {
279
-		wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
278
+	if ( ! current_user_can('edit_give_payments', $data['payment_id'])) {
279
+		wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
280 280
 	}
281 281
 
282
-	$edit_order_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-note-deleted&id=' . absint( $data['payment_id'] ) );
282
+	$edit_order_url = admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-note-deleted&id='.absint($data['payment_id']));
283 283
 
284
-	give_delete_payment_note( $data['note_id'], $data['payment_id'] );
284
+	give_delete_payment_note($data['note_id'], $data['payment_id']);
285 285
 
286
-	wp_redirect( $edit_order_url );
286
+	wp_redirect($edit_order_url);
287 287
 }
288 288
 
289
-add_action( 'give_delete_payment_note', 'give_trigger_payment_note_deletion' );
289
+add_action('give_delete_payment_note', 'give_trigger_payment_note_deletion');
290 290
 
291 291
 /**
292 292
  * Delete a payment note deletion with ajax
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
  */
300 300
 function give_ajax_delete_payment_note() {
301 301
 
302
-	if ( ! current_user_can( 'edit_give_payments', $_POST['payment_id'] ) ) {
303
-		wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
302
+	if ( ! current_user_can('edit_give_payments', $_POST['payment_id'])) {
303
+		wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
304 304
 	}
305 305
 
306
-	if ( give_delete_payment_note( $_POST['note_id'], $_POST['payment_id'] ) ) {
307
-		die( '1' );
306
+	if (give_delete_payment_note($_POST['note_id'], $_POST['payment_id'])) {
307
+		die('1');
308 308
 	} else {
309
-		die( '-1' );
309
+		die('-1');
310 310
 	}
311 311
 
312 312
 }
313 313
 
314
-add_action( 'wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note' );
315 314
\ No newline at end of file
315
+add_action('wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note');
316 316
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/reporting/pdf-reports.php 1 patch
Spacing   +144 added lines, -144 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
 
@@ -25,75 +25,75 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * @uses   give_pdf
27 27
  */
28
-function give_generate_pdf( $data ) {
28
+function give_generate_pdf($data) {
29 29
 
30
-	if ( ! current_user_can( 'view_give_reports' ) ) {
31
-		wp_die( __( 'You do not have permission to generate PDF sales reports.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
30
+	if ( ! current_user_can('view_give_reports')) {
31
+		wp_die(__('You do not have permission to generate PDF sales reports.', 'give'), __('Error', 'give'), array('response' => 403));
32 32
 	}
33 33
 
34
-	if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'give_generate_pdf' ) ) {
35
-		wp_die( __( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
34
+	if ( ! wp_verify_nonce($_GET['_wpnonce'], 'give_generate_pdf')) {
35
+		wp_die(__('Nonce verification failed', 'give'), __('Error', 'give'), array('response' => 403));
36 36
 	}
37 37
 
38
-	require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php';
39
-	require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/give_pdf.php';
38
+	require_once GIVE_PLUGIN_DIR.'/includes/libraries/fpdf/fpdf.php';
39
+	require_once GIVE_PLUGIN_DIR.'/includes/libraries/fpdf/give_pdf.php';
40 40
 
41
-	$daterange = date_i18n( get_option( 'date_format' ), mktime( 0, 0, 0, 1, 1, date( 'Y' ) ) ) . ' ' . utf8_decode( __( 'to', 'give' ) ) . ' ' . date_i18n( get_option( 'date_format' ) );
41
+	$daterange = date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))).' '.utf8_decode(__('to', 'give')).' '.date_i18n(get_option('date_format'));
42 42
 
43 43
 	$pdf = new give_pdf();
44
-	$pdf->AddPage( 'L', 'A4' );
44
+	$pdf->AddPage('L', 'A4');
45 45
 
46
-	$pdf->SetTitle( utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ) );
47
-	$pdf->SetAuthor( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
48
-	$pdf->SetCreator( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
46
+	$pdf->SetTitle(utf8_decode(__('Donation report for the current year for all forms', 'give')));
47
+	$pdf->SetAuthor(utf8_decode(__('Give - Democratizing Generosity', 'give')));
48
+	$pdf->SetCreator(utf8_decode(__('Give - Democratizing Generosity', 'give')));
49 49
 
50
-	$pdf->Image( GIVE_PLUGIN_URL . 'assets/images/give-logo-small.png', 247, 8 );
50
+	$pdf->Image(GIVE_PLUGIN_URL.'assets/images/give-logo-small.png', 247, 8);
51 51
 
52
-	$pdf->SetMargins( 8, 8, 8 );
53
-	$pdf->SetX( 8 );
52
+	$pdf->SetMargins(8, 8, 8);
53
+	$pdf->SetX(8);
54 54
 
55
-	$pdf->SetFont( 'Helvetica', '', 16 );
56
-	$pdf->SetTextColor( 50, 50, 50 );
57
-	$pdf->Cell( 0, 3, utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ), 0, 2, 'L', false );
55
+	$pdf->SetFont('Helvetica', '', 16);
56
+	$pdf->SetTextColor(50, 50, 50);
57
+	$pdf->Cell(0, 3, utf8_decode(__('Donation report for the current year for all forms', 'give')), 0, 2, 'L', false);
58 58
 
59
-	$pdf->SetFont( 'Helvetica', '', 13 );
59
+	$pdf->SetFont('Helvetica', '', 13);
60 60
 	$pdf->Ln();
61
-	$pdf->SetTextColor( 150, 150, 150 );
62
-	$pdf->Cell( 0, 6, utf8_decode( __( 'Date Range: ', 'give' ) ) . $daterange, 0, 2, 'L', false );
61
+	$pdf->SetTextColor(150, 150, 150);
62
+	$pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'give')).$daterange, 0, 2, 'L', false);
63 63
 	$pdf->Ln();
64
-	$pdf->SetTextColor( 50, 50, 50 );
65
-	$pdf->SetFont( 'Helvetica', '', 14 );
66
-	$pdf->Cell( 0, 10, utf8_decode( __( 'Table View', 'give' ) ), 0, 2, 'L', false );
67
-	$pdf->SetFont( 'Helvetica', '', 12 );
64
+	$pdf->SetTextColor(50, 50, 50);
65
+	$pdf->SetFont('Helvetica', '', 14);
66
+	$pdf->Cell(0, 10, utf8_decode(__('Table View', 'give')), 0, 2, 'L', false);
67
+	$pdf->SetFont('Helvetica', '', 12);
68 68
 
69
-	$pdf->SetFillColor( 238, 238, 238 );
70
-	$pdf->Cell( 70, 6, utf8_decode( __( 'Form Name', 'give' ) ), 1, 0, 'L', true );
71
-	$pdf->Cell( 30, 6, utf8_decode( __( 'Price', 'give' ) ), 1, 0, 'L', true );
72
-	$pdf->Cell( 50, 6, utf8_decode( __( 'Categories', 'give' ) ), 1, 0, 'L', true );
73
-	$pdf->Cell( 50, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true );
74
-	$pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true );
75
-	$pdf->Cell( 35, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true );
69
+	$pdf->SetFillColor(238, 238, 238);
70
+	$pdf->Cell(70, 6, utf8_decode(__('Form Name', 'give')), 1, 0, 'L', true);
71
+	$pdf->Cell(30, 6, utf8_decode(__('Price', 'give')), 1, 0, 'L', true);
72
+	$pdf->Cell(50, 6, utf8_decode(__('Categories', 'give')), 1, 0, 'L', true);
73
+	$pdf->Cell(50, 6, utf8_decode(__('Tags', 'give')), 1, 0, 'L', true);
74
+	$pdf->Cell(45, 6, utf8_decode(__('Number of Donations', 'give')), 1, 0, 'L', true);
75
+	$pdf->Cell(35, 6, utf8_decode(__('Income to Date', 'give')), 1, 1, 'L', true);
76 76
 
77
-	$year       = date( 'Y' );
78
-	$give_forms = get_posts( array( 'post_type' => 'give_forms', 'year' => $year, 'posts_per_page' => - 1 ) );
77
+	$year       = date('Y');
78
+	$give_forms = get_posts(array('post_type' => 'give_forms', 'year' => $year, 'posts_per_page' => -1));
79 79
 
80
-	if ( $give_forms ):
81
-		$pdf->SetWidths( array( 70, 30, 50, 50, 45, 35 ) );
80
+	if ($give_forms):
81
+		$pdf->SetWidths(array(70, 30, 50, 50, 45, 35));
82 82
 
83
-		foreach ( $give_forms as $form ):
84
-			$pdf->SetFillColor( 255, 255, 255 );
83
+		foreach ($give_forms as $form):
84
+			$pdf->SetFillColor(255, 255, 255);
85 85
 
86 86
 			$title = $form->post_title;
87 87
 
88
-			if ( give_has_variable_prices( $form->ID ) ) {
88
+			if (give_has_variable_prices($form->ID)) {
89 89
 
90
-				$prices = give_get_variable_prices( $form->ID );
90
+				$prices = give_get_variable_prices($form->ID);
91 91
 
92 92
 				$first = $prices[0]['_give_amount'];
93
-				$last  = array_pop( $prices );
93
+				$last  = array_pop($prices);
94 94
 				$last  = $last['_give_amount'];
95 95
 
96
-				if ( $first < $last ) {
96
+				if ($first < $last) {
97 97
 					$min = $first;
98 98
 					$max = $last;
99 99
 				} else {
@@ -101,51 +101,51 @@  discard block
 block discarded – undo
101 101
 					$max = $first;
102 102
 				}
103 103
 
104
-				$price = html_entity_decode( give_currency_filter( give_format_amount( $min ) ) . ' - ' . give_currency_filter( give_format_amount( $max ) ) );
104
+				$price = html_entity_decode(give_currency_filter(give_format_amount($min)).' - '.give_currency_filter(give_format_amount($max)));
105 105
 			} else {
106
-				$price = html_entity_decode( give_currency_filter( give_get_form_price( $form->ID ) ) );
106
+				$price = html_entity_decode(give_currency_filter(give_get_form_price($form->ID)));
107 107
 			}
108 108
 
109
-			$categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' );
110
-			$categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
109
+			$categories = get_the_term_list($form->ID, 'give_forms_category', '', ', ', '');
110
+			$categories = ! is_wp_error($categories) ? strip_tags($categories) : '';
111 111
 
112
-			$tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' );
113
-			$tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
112
+			$tags = get_the_term_list($form->ID, 'give_forms_tag', '', ', ', '');
113
+			$tags = ! is_wp_error($tags) ? strip_tags($tags) : '';
114 114
 
115
-			$sales    = give_get_form_sales_stats( $form->ID );
116
-			$link     = get_permalink( $form->ID );
117
-			$earnings = html_entity_decode( give_currency_filter( give_get_form_earnings_stats( $form->ID ) ) );
115
+			$sales    = give_get_form_sales_stats($form->ID);
116
+			$link     = get_permalink($form->ID);
117
+			$earnings = html_entity_decode(give_currency_filter(give_get_form_earnings_stats($form->ID)));
118 118
 
119
-			if ( function_exists( 'iconv' ) ) {
119
+			if (function_exists('iconv')) {
120 120
 				// Ensure characters like euro; are properly converted.
121
-				$price    = iconv( 'UTF-8', 'windows-1252', utf8_encode( $price ) );
122
-				$earnings = iconv( 'UTF-8', 'windows-1252', utf8_encode( $earnings ) );
121
+				$price    = iconv('UTF-8', 'windows-1252', utf8_encode($price));
122
+				$earnings = iconv('UTF-8', 'windows-1252', utf8_encode($earnings));
123 123
 			}
124 124
 
125
-			$pdf->Row( array( $title, $price, $categories, $tags, $sales, $earnings ) );
125
+			$pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings));
126 126
 		endforeach;
127 127
 	else:
128
-		$pdf->SetWidths( array( 280 ) );
129
-		$title = utf8_decode( sprintf( __( 'No %s found.', 'give' ), give_get_forms_label_plural() ) );
130
-		$pdf->Row( array( $title ) );
128
+		$pdf->SetWidths(array(280));
129
+		$title = utf8_decode(sprintf(__('No %s found.', 'give'), give_get_forms_label_plural()));
130
+		$pdf->Row(array($title));
131 131
 	endif;
132 132
 
133 133
 	$pdf->Ln();
134
-	$pdf->SetTextColor( 50, 50, 50 );
135
-	$pdf->SetFont( 'Helvetica', '', 14 );
136
-	$pdf->Cell( 0, 10, utf8_decode( __( 'Graph View', 'give' ) ), 0, 2, 'L', false );
137
-	$pdf->SetFont( 'Helvetica', '', 12 );
138
-
139
-	$image = html_entity_decode( urldecode( give_draw_chart_image() ) );
140
-	$image = str_replace( ' ', '%20', $image );
141
-
142
-	$pdf->SetX( 25 );
143
-	$pdf->Image( $image . '&file=.png' );
144
-	$pdf->Ln( 7 );
145
-	$pdf->Output( apply_filters( 'give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n( 'Y-m-d' ) ) . '.pdf', 'D' );
134
+	$pdf->SetTextColor(50, 50, 50);
135
+	$pdf->SetFont('Helvetica', '', 14);
136
+	$pdf->Cell(0, 10, utf8_decode(__('Graph View', 'give')), 0, 2, 'L', false);
137
+	$pdf->SetFont('Helvetica', '', 12);
138
+
139
+	$image = html_entity_decode(urldecode(give_draw_chart_image()));
140
+	$image = str_replace(' ', '%20', $image);
141
+
142
+	$pdf->SetX(25);
143
+	$pdf->Image($image.'&file=.png');
144
+	$pdf->Ln(7);
145
+	$pdf->Output(apply_filters('give_sales_earnings_pdf_export_filename', 'give-report-'.date_i18n('Y-m-d')).'.pdf', 'D');
146 146
 }
147 147
 
148
-add_action( 'give_generate_pdf', 'give_generate_pdf' );
148
+add_action('give_generate_pdf', 'give_generate_pdf');
149 149
 
150 150
 /**
151 151
  * Draws Chart for PDF Report
@@ -162,38 +162,38 @@  discard block
 block discarded – undo
162 162
  * @return string $chart->getUrl() URL for the Google Chart
163 163
  */
164 164
 function give_draw_chart_image() {
165
-	require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
166
-	require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
167
-	require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
165
+	require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/GoogleChart.php';
166
+	require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
167
+	require_once GIVE_PLUGIN_DIR.'/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
168 168
 
169
-	$chart = new GoogleChart( 'lc', 900, 330 );
169
+	$chart = new GoogleChart('lc', 900, 330);
170 170
 
171 171
 	$i        = 1;
172 172
 	$earnings = "";
173 173
 	$sales    = "";
174 174
 
175
-	while ( $i <= 12 ) :
176
-		$earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ",";
177
-		$sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ",";
178
-		$i ++;
175
+	while ($i <= 12) :
176
+		$earnings .= give_get_earnings_by_date(null, $i, date('Y')).",";
177
+		$sales .= give_get_sales_by_date(null, $i, date('Y')).",";
178
+		$i++;
179 179
 	endwhile;
180 180
 
181
-	$earnings_array = explode( ",", $earnings );
182
-	$sales_array    = explode( ",", $sales );
181
+	$earnings_array = explode(",", $earnings);
182
+	$sales_array    = explode(",", $sales);
183 183
 
184 184
 	$i = 0;
185
-	while ( $i <= 11 ) {
186
-		if ( empty( $sales_array[ $i ] ) ) {
187
-			$sales_array[ $i ] = 0;
185
+	while ($i <= 11) {
186
+		if (empty($sales_array[$i])) {
187
+			$sales_array[$i] = 0;
188 188
 		}
189
-		$i ++;
189
+		$i++;
190 190
 	}
191 191
 
192 192
 	$min_earnings   = 0;
193
-	$max_earnings   = max( $earnings_array );
194
-	$earnings_scale = round( $max_earnings, - 1 );
193
+	$max_earnings   = max($earnings_array);
194
+	$earnings_scale = round($max_earnings, - 1);
195 195
 
196
-	$data = new GoogleChartData( array(
196
+	$data = new GoogleChartData(array(
197 197
 		$earnings_array[0],
198 198
 		$earnings_array[1],
199 199
 		$earnings_array[2],
@@ -206,25 +206,25 @@  discard block
 block discarded – undo
206 206
 		$earnings_array[9],
207 207
 		$earnings_array[10],
208 208
 		$earnings_array[11]
209
-	) );
209
+	));
210 210
 
211
-	$data->setLegend( __( 'Income', 'give' ) );
212
-	$data->setColor( '1b58a3' );
213
-	$chart->addData( $data );
211
+	$data->setLegend(__('Income', 'give'));
212
+	$data->setColor('1b58a3');
213
+	$chart->addData($data);
214 214
 
215
-	$shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
216
-	$shape_marker->setColor( '000000' );
217
-	$shape_marker->setSize( 7 );
218
-	$shape_marker->setBorder( 2 );
219
-	$shape_marker->setData( $data );
220
-	$chart->addMarker( $shape_marker );
215
+	$shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
216
+	$shape_marker->setColor('000000');
217
+	$shape_marker->setSize(7);
218
+	$shape_marker->setBorder(2);
219
+	$shape_marker->setData($data);
220
+	$chart->addMarker($shape_marker);
221 221
 
222
-	$value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
223
-	$value_marker->setColor( '000000' );
224
-	$value_marker->setData( $data );
225
-	$chart->addMarker( $value_marker );
222
+	$value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
223
+	$value_marker->setColor('000000');
224
+	$value_marker->setData($data);
225
+	$chart->addMarker($value_marker);
226 226
 
227
-	$data = new GoogleChartData( array(
227
+	$data = new GoogleChartData(array(
228 228
 		$sales_array[0],
229 229
 		$sales_array[1],
230 230
 		$sales_array[2],
@@ -237,46 +237,46 @@  discard block
 block discarded – undo
237 237
 		$sales_array[9],
238 238
 		$sales_array[10],
239 239
 		$sales_array[11]
240
-	) );
241
-	$data->setLegend( __( 'Donations', 'give' ) );
242
-	$data->setColor( 'ff6c1c' );
243
-	$chart->addData( $data );
244
-
245
-	$chart->setTitle( __( 'Donations by Month for all Give Forms', 'give' ), '336699', 18 );
246
-
247
-	$chart->setScale( 0, $max_earnings );
248
-
249
-	$y_axis = new GoogleChartAxis( 'y' );
250
-	$y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) );
251
-	$chart->addAxis( $y_axis );
252
-
253
-	$x_axis = new GoogleChartAxis( 'x' );
254
-	$x_axis->setTickMarks( 5 );
255
-	$x_axis->setLabels( array(
256
-		__( 'Jan', 'give' ),
257
-		__( 'Feb', 'give' ),
258
-		__( 'Mar', 'give' ),
259
-		__( 'Apr', 'give' ),
260
-		__( 'May', 'give' ),
261
-		__( 'June', 'give' ),
262
-		__( 'July', 'give' ),
263
-		__( 'Aug', 'give' ),
264
-		__( 'Sept', 'give' ),
265
-		__( 'Oct', 'give' ),
266
-		__( 'Nov', 'give' ),
267
-		__( 'Dec', 'give' )
268
-	) );
269
-	$chart->addAxis( $x_axis );
270
-
271
-	$shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
272
-	$shape_marker->setSize( 6 );
273
-	$shape_marker->setBorder( 2 );
274
-	$shape_marker->setData( $data );
275
-	$chart->addMarker( $shape_marker );
276
-
277
-	$value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
278
-	$value_marker->setData( $data );
279
-	$chart->addMarker( $value_marker );
240
+	));
241
+	$data->setLegend(__('Donations', 'give'));
242
+	$data->setColor('ff6c1c');
243
+	$chart->addData($data);
244
+
245
+	$chart->setTitle(__('Donations by Month for all Give Forms', 'give'), '336699', 18);
246
+
247
+	$chart->setScale(0, $max_earnings);
248
+
249
+	$y_axis = new GoogleChartAxis('y');
250
+	$y_axis->setDrawTickMarks(true)->setLabels(array(0, $max_earnings));
251
+	$chart->addAxis($y_axis);
252
+
253
+	$x_axis = new GoogleChartAxis('x');
254
+	$x_axis->setTickMarks(5);
255
+	$x_axis->setLabels(array(
256
+		__('Jan', 'give'),
257
+		__('Feb', 'give'),
258
+		__('Mar', 'give'),
259
+		__('Apr', 'give'),
260
+		__('May', 'give'),
261
+		__('June', 'give'),
262
+		__('July', 'give'),
263
+		__('Aug', 'give'),
264
+		__('Sept', 'give'),
265
+		__('Oct', 'give'),
266
+		__('Nov', 'give'),
267
+		__('Dec', 'give')
268
+	));
269
+	$chart->addAxis($x_axis);
270
+
271
+	$shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
272
+	$shape_marker->setSize(6);
273
+	$shape_marker->setBorder(2);
274
+	$shape_marker->setData($data);
275
+	$chart->addMarker($shape_marker);
276
+
277
+	$value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
278
+	$value_marker->setData($data);
279
+	$chart->addMarker($value_marker);
280 280
 
281 281
 	return $chart->getUrl();
282 282
 }
Please login to merge, or discard this patch.
includes/emails/actions.php 1 patch
Spacing   +18 added lines, -18 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
 
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return void
25 25
  */
26
-function give_trigger_donation_receipt( $payment_id ) {
26
+function give_trigger_donation_receipt($payment_id) {
27 27
 	// Make sure we don't send a purchase receipt while editing a payment
28
-	if ( isset( $_POST['give-action'] ) && 'edit_payment' == $_POST['give-action'] ) {
28
+	if (isset($_POST['give-action']) && 'edit_payment' == $_POST['give-action']) {
29 29
 		return;
30 30
 	}
31 31
 
32 32
 	// Send email
33
-	give_email_donation_receipt( $payment_id );
33
+	give_email_donation_receipt($payment_id);
34 34
 }
35 35
 
36
-add_action( 'give_complete_purchase', 'give_trigger_donation_receipt', 999, 1 );
36
+add_action('give_complete_purchase', 'give_trigger_donation_receipt', 999, 1);
37 37
 
38 38
 /**
39 39
  * Resend the Email Purchase Receipt. (This can be done from the Payment History page)
@@ -44,29 +44,29 @@  discard block
 block discarded – undo
44 44
  *
45 45
  * @return void
46 46
  */
47
-function give_resend_donation_receipt( $data ) {
47
+function give_resend_donation_receipt($data) {
48 48
 
49
-	$purchase_id = absint( $data['purchase_id'] );
49
+	$purchase_id = absint($data['purchase_id']);
50 50
 
51
-	if ( empty( $purchase_id ) ) {
51
+	if (empty($purchase_id)) {
52 52
 		return;
53 53
 	}
54 54
 
55
-	if ( ! current_user_can( 'edit_give_payments', $purchase_id ) ) {
56
-		wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
55
+	if ( ! current_user_can('edit_give_payments', $purchase_id)) {
56
+		wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403));
57 57
 	}
58 58
 
59
-	give_email_donation_receipt( $purchase_id, false );
59
+	give_email_donation_receipt($purchase_id, false);
60 60
 
61
-	wp_redirect( add_query_arg( array(
61
+	wp_redirect(add_query_arg(array(
62 62
 		'give-message' => 'email_sent',
63 63
 		'give-action'  => false,
64 64
 		'purchase_id'  => false
65
-	) ) );
65
+	)));
66 66
 	exit;
67 67
 }
68 68
 
69
-add_action( 'give_email_links', 'give_resend_donation_receipt' );
69
+add_action('give_email_links', 'give_resend_donation_receipt');
70 70
 
71 71
 /**
72 72
  * Trigger the sending of a Test Email
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
  *
78 78
  * @return void
79 79
  */
80
-function give_send_test_email( $data ) {
81
-	if ( ! wp_verify_nonce( $data['_wpnonce'], 'give-test-email' ) ) {
80
+function give_send_test_email($data) {
81
+	if ( ! wp_verify_nonce($data['_wpnonce'], 'give-test-email')) {
82 82
 		return;
83 83
 	}
84 84
 
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	give_email_test_donation_receipt();
87 87
 
88 88
 	// Remove the test email query arg
89
-	wp_redirect( remove_query_arg( 'give_action' ) );
89
+	wp_redirect(remove_query_arg('give_action'));
90 90
 	exit;
91 91
 }
92 92
 
93
-add_action( 'give_send_test_email', 'give_send_test_email' );
93
+add_action('give_send_test_email', 'give_send_test_email');
Please login to merge, or discard this patch.