Test Failed
Push — master ( 5a5a1c...38b67b )
by Devin
15:58 queued 10:09
created
includes/admin/class-api-keys-table.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -254,8 +254,8 @@
 block discarded – undo
254 254
 		$args = array(
255 255
 		  'id' => 'give-api-user-search',
256 256
 		  'name' => 'user_id',
257
-        );
258
-        echo Give()->html->ajax_user_search($args); ?>
257
+		);
258
+		echo Give()->html->ajax_user_search($args); ?>
259 259
 		<?php submit_button( esc_html__( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?>
260 260
 		<?php
261 261
 		$give_api_is_bottom = true;
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@  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
 
17 17
 // Load WP_List_Table if not loaded
18
-if ( ! class_exists( 'WP_List_Table' ) ) {
19
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
18
+if ( ! class_exists('WP_List_Table')) {
19
+	require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
20 20
 }
21 21
 
22 22
 /**
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 		global $status, $page;
54 54
 
55 55
 		// Set parent defaults
56
-		parent::__construct( array(
57
-			'singular' => esc_html__( 'API Key', 'give' ),     // Singular name of the listed records
58
-			'plural'   => esc_html__( 'API Keys', 'give' ),    // Plural name of the listed records
59
-			'ajax'     => false,// Does this table support ajax?
60
-		) );
56
+		parent::__construct(array(
57
+			'singular' => esc_html__('API Key', 'give'), // Singular name of the listed records
58
+			'plural'   => esc_html__('API Keys', 'give'), // Plural name of the listed records
59
+			'ajax'     => false, // Does this table support ajax?
60
+		));
61 61
 
62 62
 		$this->query();
63 63
 	}
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return string Column Name
75 75
 	 */
76
-	public function column_default( $item, $column_name ) {
77
-		return $item[ $column_name ];
76
+	public function column_default($item, $column_name) {
77
+		return $item[$column_name];
78 78
 	}
79 79
 
80 80
 	/**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @return string Column Name
89 89
 	 */
90
-	public function column_key( $item ) {
91
-		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>';
90
+	public function column_key($item) {
91
+		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['key']).'"/>';
92 92
 	}
93 93
 
94 94
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @return string Column Name
103 103
 	 */
104
-	public function column_token( $item ) {
105
-		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>';
104
+	public function column_token($item) {
105
+		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['token']).'"/>';
106 106
 	}
107 107
 
108 108
 	/**
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @return string Column Name
117 117
 	 */
118
-	public function column_secret( $item ) {
119
-		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>';
118
+	public function column_secret($item) {
119
+		return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['secret']).'"/>';
120 120
 	}
121 121
 
122 122
 	/**
@@ -126,46 +126,46 @@  discard block
 block discarded – undo
126 126
 	 * @since  1.1
127 127
 	 * @return string
128 128
 	 */
129
-	public function column_user( $item ) {
129
+	public function column_user($item) {
130 130
 
131 131
 		$actions = array();
132 132
 
133
-		if ( apply_filters( 'give_api_log_requests', true ) ) {
133
+		if (apply_filters('give_api_log_requests', true)) {
134 134
 			$actions['view'] = sprintf(
135 135
 				'<a href="%s">%s</a>',
136
-				esc_url( add_query_arg( array(
136
+				esc_url(add_query_arg(array(
137 137
 					'section'   => 'api_requests',
138 138
 					'post_type' => 'give_forms',
139 139
 					'page'      => 'give-tools',
140 140
 					'tab'       => 'logs',
141 141
 					's'         => $item['email'],
142
-				), 'edit.php' ) ),
143
-				esc_html__( 'View API Log', 'give' )
142
+				), 'edit.php')),
143
+				esc_html__('View API Log', 'give')
144 144
 			);
145 145
 		}
146 146
 
147 147
 		$actions['reissue'] = sprintf(
148 148
 			'<a href="%s" class="give-regenerate-api-key">%s</a>',
149
-			esc_url( wp_nonce_url( add_query_arg( array(
149
+			esc_url(wp_nonce_url(add_query_arg(array(
150 150
 				'user_id'          => $item['id'],
151 151
 				'give_action'      => 'process_api_key',
152 152
 				'give_api_process' => 'regenerate',
153
-			) ), 'give-api-nonce' ) ),
154
-			esc_html__( 'Reissue', 'give' )
153
+			)), 'give-api-nonce')),
154
+			esc_html__('Reissue', 'give')
155 155
 		);
156
-		$actions['revoke']  = sprintf(
156
+		$actions['revoke'] = sprintf(
157 157
 			'<a href="%s" class="give-revoke-api-key give-delete">%s</a>',
158
-			esc_url( wp_nonce_url( add_query_arg( array(
158
+			esc_url(wp_nonce_url(add_query_arg(array(
159 159
 				'user_id'          => $item['id'],
160 160
 				'give_action'      => 'process_api_key',
161 161
 				'give_api_process' => 'revoke',
162
-			) ), 'give-api-nonce' ) ),
163
-			esc_html__( 'Revoke', 'give' )
162
+			)), 'give-api-nonce')),
163
+			esc_html__('Revoke', 'give')
164 164
 		);
165 165
 
166
-		$actions = apply_filters( 'give_api_row_actions', array_filter( $actions ) );
166
+		$actions = apply_filters('give_api_row_actions', array_filter($actions));
167 167
 
168
-		return sprintf( '%1$s %2$s', $item['user'], $this->row_actions( $actions ) );
168
+		return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions));
169 169
 	}
170 170
 
171 171
 	/**
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	 */
190 190
 	public function get_columns() {
191 191
 		$columns = array(
192
-			'user'   => esc_html__( 'Username', 'give' ),
193
-			'key'    => esc_html__( 'Public Key', 'give' ),
194
-			'token'  => esc_html__( 'Token', 'give' ),
195
-			'secret' => esc_html__( 'Secret Key', 'give' ),
192
+			'user'   => esc_html__('Username', 'give'),
193
+			'key'    => esc_html__('Public Key', 'give'),
194
+			'token'  => esc_html__('Token', 'give'),
195
+			'secret' => esc_html__('Secret Key', 'give'),
196 196
 		);
197 197
 
198 198
 		return $columns;
@@ -206,20 +206,20 @@  discard block
 block discarded – undo
206 206
 	 *
207 207
 	 * @param string $which
208 208
 	 */
209
-	protected function display_tablenav( $which ) {
210
-		if ( 'top' === $which ) {
211
-			wp_nonce_field( 'bulk-' . $this->_args['plural'] );
209
+	protected function display_tablenav($which) {
210
+		if ('top' === $which) {
211
+			wp_nonce_field('bulk-'.$this->_args['plural']);
212 212
 		}
213 213
 		?>
214
-		<div class="tablenav <?php echo esc_attr( $which ); ?>">
214
+		<div class="tablenav <?php echo esc_attr($which); ?>">
215 215
 
216 216
 			<div class="alignleft actions bulkactions">
217
-				<?php $this->bulk_actions( $which ); ?>
217
+				<?php $this->bulk_actions($which); ?>
218 218
 			</div>
219 219
 
220 220
 			<?php
221
-			$this->extra_tablenav( $which );
222
-			$this->pagination( $which );
221
+			$this->extra_tablenav($which);
222
+			$this->pagination($which);
223 223
 			?>
224 224
 
225 225
 			<br class="clear"/>
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return void
239 239
 	 */
240
-	function bulk_actions( $which = '' ) {
240
+	function bulk_actions($which = '') {
241 241
 		// These aren't really bulk actions but this outputs the markup in the right place.
242 242
 		static $give_api_is_bottom;
243 243
 
244
-		if ( $give_api_is_bottom ) {
244
+		if ($give_api_is_bottom) {
245 245
 			return;
246 246
 		}
247 247
 		?>
248 248
 		<input type="hidden" name="give_action" value="process_api_key"/>
249 249
 		<input type="hidden" name="give_api_process" value="generate"/>
250
-		<?php wp_nonce_field( 'give-api-nonce' );
250
+		<?php wp_nonce_field('give-api-nonce');
251 251
 		/**
252 252
 		 * API Key user search.
253 253
 		 */
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		  'name' => 'user_id',
257 257
         );
258 258
         echo Give()->html->ajax_user_search($args); ?>
259
-		<?php submit_button( esc_html__( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?>
259
+		<?php submit_button(esc_html__('Generate New API Keys', 'give'), 'secondary', 'submit', false); ?>
260 260
 		<?php
261 261
 		$give_api_is_bottom = true;
262 262
 	}
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	 * @return int Current page number
270 270
 	 */
271 271
 	public function get_paged() {
272
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
272
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
273 273
 	}
274 274
 
275 275
 	/**
@@ -280,21 +280,21 @@  discard block
 block discarded – undo
280 280
 	 * @return array
281 281
 	 */
282 282
 	public function query() {
283
-		$users = get_users( array(
283
+		$users = get_users(array(
284 284
 			'meta_value' => 'give_user_secret_key',
285 285
 			'number'     => $this->per_page,
286
-			'offset'     => $this->per_page * ( $this->get_paged() - 1 ),
287
-		) );
288
-		$keys  = array();
289
-
290
-		foreach ( $users as $user ) {
291
-			$keys[ $user->ID ]['id']    = $user->ID;
292
-			$keys[ $user->ID ]['email'] = $user->user_email;
293
-			$keys[ $user->ID ]['user']  = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>';
294
-
295
-			$keys[ $user->ID ]['key']    = Give()->api->get_user_public_key( $user->ID );
296
-			$keys[ $user->ID ]['secret'] = Give()->api->get_user_secret_key( $user->ID );
297
-			$keys[ $user->ID ]['token']  = Give()->api->get_token( $user->ID );
286
+			'offset'     => $this->per_page * ($this->get_paged() - 1),
287
+		));
288
+		$keys = array();
289
+
290
+		foreach ($users as $user) {
291
+			$keys[$user->ID]['id']    = $user->ID;
292
+			$keys[$user->ID]['email'] = $user->user_email;
293
+			$keys[$user->ID]['user']  = '<a href="'.add_query_arg('user_id', $user->ID, 'user-edit.php').'"><strong>'.$user->user_login.'</strong></a>';
294
+
295
+			$keys[$user->ID]['key']    = Give()->api->get_user_public_key($user->ID);
296
+			$keys[$user->ID]['secret'] = Give()->api->get_user_secret_key($user->ID);
297
+			$keys[$user->ID]['token']  = Give()->api->get_token($user->ID);
298 298
 		}
299 299
 
300 300
 		return $keys;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	public function total_items() {
312 312
 		global $wpdb;
313 313
 
314
-		if ( ! ( $total_items = Give_Cache::get( 'give_total_api_keys', true ) ) ) {
314
+		if ( ! ($total_items = Give_Cache::get('give_total_api_keys', true))) {
315 315
 			$total_items = $wpdb->get_var(
316 316
 				$wpdb->prepare(
317 317
 					"SELECT count(user_id)
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 				)
321 321
 			);
322 322
 
323
-			Give_Cache::set( 'give_total_api_keys', $total_items, HOUR_IN_SECONDS, true );
323
+			Give_Cache::set('give_total_api_keys', $total_items, HOUR_IN_SECONDS, true);
324 324
 		}
325 325
 
326 326
 		return $total_items;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 		$hidden   = array(); // No hidden columns
340 340
 		$sortable = array(); // Not sortable... for now
341 341
 
342
-		$this->_column_headers = array( $columns, $hidden, $sortable );
342
+		$this->_column_headers = array($columns, $hidden, $sortable);
343 343
 
344 344
 		$data = $this->query();
345 345
 
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
 
348 348
 		$this->items = $data;
349 349
 
350
-		$this->set_pagination_args( array(
350
+		$this->set_pagination_args(array(
351 351
 				'total_items' => $total_items,
352 352
 				'per_page'    => $this->per_page,
353
-				'total_pages' => ceil( $total_items / $this->per_page ),
353
+				'total_pages' => ceil($total_items / $this->per_page),
354 354
 			)
355 355
 		);
356 356
 	}
Please login to merge, or discard this patch.
includes/admin/tools/export/class-batch-export-forms.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -41,20 +41,20 @@  discard block
 block discarded – undo
41 41
 	public function csv_cols() {
42 42
 
43 43
 		$cols = array(
44
-			'ID'                      => __( 'ID', 'give' ),
45
-			'post_name'               => __( 'Slug', 'give' ),
46
-			'post_title'              => __( 'Name', 'give' ),
47
-			'post_date'               => __( 'Date Created', 'give' ),
48
-			'post_author'             => __( 'Author', 'give' ),
49
-			'post_content'            => __( 'Description', 'give' ),
50
-			'post_excerpt'            => __( 'Excerpt', 'give' ),
51
-			'post_status'             => __( 'Status', 'give' ),
52
-			'categories'              => __( 'Categories', 'give' ),
53
-			'tags'                    => __( 'Tags', 'give' ),
54
-			'give_price'              => __( 'Price', 'give' ),
55
-			'_thumbnail_id'           => __( 'Featured Image', 'give' ),
56
-			'_give_form_sales'        => __( 'Donations', 'give' ),
57
-			'_give_download_earnings' => __( 'Income', 'give' ),
44
+			'ID'                      => __('ID', 'give'),
45
+			'post_name'               => __('Slug', 'give'),
46
+			'post_title'              => __('Name', 'give'),
47
+			'post_date'               => __('Date Created', 'give'),
48
+			'post_author'             => __('Author', 'give'),
49
+			'post_content'            => __('Description', 'give'),
50
+			'post_excerpt'            => __('Excerpt', 'give'),
51
+			'post_status'             => __('Status', 'give'),
52
+			'categories'              => __('Categories', 'give'),
53
+			'tags'                    => __('Tags', 'give'),
54
+			'give_price'              => __('Price', 'give'),
55
+			'_thumbnail_id'           => __('Featured Image', 'give'),
56
+			'_give_form_sales'        => __('Donations', 'give'),
57
+			'_give_download_earnings' => __('Income', 'give'),
58 58
 		);
59 59
 
60 60
 		return $cols;
@@ -84,43 +84,43 @@  discard block
 block discarded – undo
84 84
 			'paged'          => $this->step
85 85
 		);
86 86
 
87
-		$forms = new WP_Query( $args );
87
+		$forms = new WP_Query($args);
88 88
 
89
-		if ( $forms->posts ) {
90
-			foreach ( $forms->posts as $form ) {
89
+		if ($forms->posts) {
90
+			foreach ($forms->posts as $form) {
91 91
 
92 92
 				$row = [];
93 93
 
94
-				foreach ( $this->csv_cols() as $key => $value ) {
94
+				foreach ($this->csv_cols() as $key => $value) {
95 95
 
96 96
 					// Setup default value/
97
-					$row[ $key ] = '';
97
+					$row[$key] = '';
98 98
 
99
-					if ( in_array( $key, $meta ) ) {
99
+					if (in_array($key, $meta)) {
100 100
 
101
-						switch ( $key ) {
101
+						switch ($key) {
102 102
 
103 103
 							case '_thumbnail_id' :
104 104
 
105
-								$image_id    = get_post_thumbnail_id( $form->ID );
106
-								$row[ $key ] = wp_get_attachment_url( $image_id );
105
+								$image_id    = get_post_thumbnail_id($form->ID);
106
+								$row[$key] = wp_get_attachment_url($image_id);
107 107
 
108 108
 								break;
109 109
 
110 110
 							case 'give_price' :
111 111
 
112
-								if ( give_has_variable_prices( $form->ID ) ) {
112
+								if (give_has_variable_prices($form->ID)) {
113 113
 
114 114
 									$prices = [];
115
-									foreach ( give_get_variable_prices( $form->ID ) as $price ) {
116
-										$prices[] = $price['name'] . ': ' . $price['amount'];
115
+									foreach (give_get_variable_prices($form->ID) as $price) {
116
+										$prices[] = $price['name'].': '.$price['amount'];
117 117
 									}
118 118
 
119
-									$row[ $key ] = implode( ' | ', $prices );
119
+									$row[$key] = implode(' | ', $prices);
120 120
 
121 121
 								} else {
122 122
 
123
-									$row[ $key ] = give_get_form_price( $form->ID );
123
+									$row[$key] = give_get_form_price($form->ID);
124 124
 
125 125
 								}
126 126
 
@@ -128,44 +128,44 @@  discard block
 block discarded – undo
128 128
 
129 129
 							default :
130 130
 
131
-								$row[ $key ] = give_get_meta( $form->ID, $key, TRUE );
131
+								$row[$key] = give_get_meta($form->ID, $key, TRUE);
132 132
 
133 133
 								break;
134 134
 
135 135
 						}
136 136
 
137
-					} elseif ( isset( $form->$key ) ) {
137
+					} elseif (isset($form->$key)) {
138 138
 
139
-						switch ( $key ) {
139
+						switch ($key) {
140 140
 
141 141
 							case 'post_author' :
142 142
 
143
-								$row[ $key ] = get_the_author_meta( 'user_login', $form->post_author );
143
+								$row[$key] = get_the_author_meta('user_login', $form->post_author);
144 144
 
145 145
 								break;
146 146
 
147 147
 							default :
148 148
 
149
-								$row[ $key ] = $form->$key;
149
+								$row[$key] = $form->$key;
150 150
 
151 151
 								break;
152 152
 						}
153 153
 
154
-					} elseif ( 'tags' == $key ) {
154
+					} elseif ('tags' == $key) {
155 155
 
156
-						$terms = get_the_terms( $form->ID, 'form_tag' );
157
-						if ( $terms ) {
158
-							$terms       = wp_list_pluck( $terms, 'name' );
159
-							$row[ $key ] = implode( ' | ', $terms );
156
+						$terms = get_the_terms($form->ID, 'form_tag');
157
+						if ($terms) {
158
+							$terms       = wp_list_pluck($terms, 'name');
159
+							$row[$key] = implode(' | ', $terms);
160 160
 						}
161 161
 
162 162
 
163
-					} elseif ( 'categories' == $key ) {
163
+					} elseif ('categories' == $key) {
164 164
 
165
-						$terms = get_the_terms( $form->ID, 'form_category' );
166
-						if ( $terms ) {
167
-							$terms       = wp_list_pluck( $terms, 'name' );
168
-							$row[ $key ] = implode( ' | ', $terms );
165
+						$terms = get_the_terms($form->ID, 'form_category');
166
+						if ($terms) {
167
+							$terms       = wp_list_pluck($terms, 'name');
168
+							$row[$key] = implode(' | ', $terms);
169 169
 						}
170 170
 
171 171
 					}
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 
177 177
 			}
178 178
 
179
-			$data = apply_filters( 'give_export_get_data', $data );
180
-			$data = apply_filters( "give_export_get_data_{$this->export_type}", $data );
179
+			$data = apply_filters('give_export_get_data', $data);
180
+			$data = apply_filters("give_export_get_data_{$this->export_type}", $data);
181 181
 
182 182
 			return $data;
183 183
 
@@ -197,20 +197,20 @@  discard block
 block discarded – undo
197 197
 
198 198
 		$args = array(
199 199
 			'post_type'      => 'give_forms',
200
-			'posts_per_page' => - 1,
200
+			'posts_per_page' => -1,
201 201
 			'post_status'    => 'any',
202 202
 			'fields'         => 'ids',
203 203
 		);
204 204
 
205
-		$forms  = new WP_Query( $args );
205
+		$forms = new WP_Query($args);
206 206
 		$total      = (int) $forms->post_count;
207 207
 		$percentage = 100;
208 208
 
209
-		if ( $total > 0 ) {
210
-			$percentage = ( ( 30 * $this->step ) / $total ) * 100;
209
+		if ($total > 0) {
210
+			$percentage = ((30 * $this->step) / $total) * 100;
211 211
 		}
212 212
 
213
-		if ( $percentage > 100 ) {
213
+		if ($percentage > 100) {
214 214
 			$percentage = 100;
215 215
 		}
216 216
 
Please login to merge, or discard this patch.
includes/api/class-give-api.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @access public
218 218
 	 * @since  1.1
219
-	 * @return array
219
+	 * @return string
220 220
 	 */
221 221
 	public function get_versions() {
222 222
 		return $this->versions;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 * @uses   Give_API::invalid_key()
303 303
 	 * @uses   Give_API::invalid_auth()
304 304
 	 * @since  1.1
305
-	 * @return bool
305
+	 * @return false|null
306 306
 	 */
307 307
 	private function validate_request() {
308 308
 		global $wp_query;
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 	 *
695 695
 	 * @param array $args Arguments to override defaults
696 696
 	 *
697
-	 * @return array $dates
697
+	 * @return integer|null $dates
698 698
 	 */
699 699
 	public function get_dates( $args = array() ) {
700 700
 		$dates = array();
Please login to merge, or discard this patch.
Spacing   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -141,27 +141,27 @@  discard block
 block discarded – undo
141 141
 			'v1' => 'GIVE_API_V1',
142 142
 		);
143 143
 
144
-		foreach ( $this->get_versions() as $version => $class ) {
145
-			require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php';
144
+		foreach ($this->get_versions() as $version => $class) {
145
+			require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php';
146 146
 		}
147 147
 
148
-		add_action( 'init', array( $this, 'add_endpoint' ) );
149
-		add_action( 'wp', array( $this, 'process_query' ), - 1 );
150
-		add_filter( 'query_vars', array( $this, 'query_vars' ) );
151
-		add_action( 'show_user_profile', array( $this, 'user_key_field' ) );
152
-		add_action( 'edit_user_profile', array( $this, 'user_key_field' ) );
153
-		add_action( 'personal_options_update', array( $this, 'generate_api_key' ) );
154
-		add_action( 'edit_user_profile_update', array( $this, 'generate_api_key' ) );
155
-		add_action( 'give_process_api_key', array( $this, 'process_api_key' ) );
148
+		add_action('init', array($this, 'add_endpoint'));
149
+		add_action('wp', array($this, 'process_query'), - 1);
150
+		add_filter('query_vars', array($this, 'query_vars'));
151
+		add_action('show_user_profile', array($this, 'user_key_field'));
152
+		add_action('edit_user_profile', array($this, 'user_key_field'));
153
+		add_action('personal_options_update', array($this, 'generate_api_key'));
154
+		add_action('edit_user_profile_update', array($this, 'generate_api_key'));
155
+		add_action('give_process_api_key', array($this, 'process_api_key'));
156 156
 
157 157
 		// Setup a backwards compatibility check for user API Keys
158
-		add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 );
158
+		add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4);
159 159
 
160 160
 		// Determine if JSON_PRETTY_PRINT is available
161
-		$this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
161
+		$this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null;
162 162
 
163 163
 		// Allow API request logging to be turned off
164
-		$this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests );
164
+		$this->log_requests = apply_filters('give_api_log_requests', $this->log_requests);
165 165
 
166 166
 		// Setup Give_Payment_Stats instance
167 167
 		$this->stats = new Give_Payment_Stats();
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return mixed
181 181
 	 */
182
-	public function __call( $name, $arguments ) {
182
+	public function __call($name, $arguments) {
183 183
 		$deprecated_function_arr = array(
184 184
 			'get_customers',
185 185
 		);
186 186
 
187
-		if ( in_array( $name, $deprecated_function_arr, true ) ) {
188
-			switch ( $name ) {
187
+		if (in_array($name, $deprecated_function_arr, true)) {
188
+			switch ($name) {
189 189
 				case 'get_customers':
190
-					$args = ! empty( $arguments[0] ) ? $arguments[0] : array();
190
+					$args = ! empty($arguments[0]) ? $arguments[0] : array();
191 191
 
192
-					return $this->get_donors( $args );
192
+					return $this->get_donors($args);
193 193
 			}
194 194
 		}
195 195
 	}
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	 * @since  1.1
203 203
 	 */
204 204
 	public function add_endpoint() {
205
-		add_rewrite_endpoint( 'give-api', EP_ALL );
205
+		add_rewrite_endpoint('give-api', EP_ALL);
206 206
 	}
207 207
 
208 208
 	/**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return string[] $vars New query vars
217 217
 	 */
218
-	public function query_vars( $vars ) {
218
+	public function query_vars($vars) {
219 219
 
220 220
 		$vars[] = 'token';
221 221
 		$vars[] = 'key';
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
 	 */
267 267
 	public function get_default_version() {
268 268
 
269
-		$version = get_option( 'give_default_api_version' );
269
+		$version = get_option('give_default_api_version');
270 270
 
271
-		if ( defined( 'GIVE_API_VERSION' ) ) {
271
+		if (defined('GIVE_API_VERSION')) {
272 272
 			$version = GIVE_API_VERSION;
273
-		} elseif ( ! $version ) {
273
+		} elseif ( ! $version) {
274 274
 			$version = 'v1';
275 275
 		}
276 276
 
@@ -291,14 +291,14 @@  discard block
 block discarded – undo
291 291
 
292 292
 		$version = $wp_query->query_vars['give-api'];
293 293
 
294
-		if ( strpos( $version, '/' ) ) {
294
+		if (strpos($version, '/')) {
295 295
 
296
-			$version = explode( '/', $version );
297
-			$version = strtolower( $version[0] );
296
+			$version = explode('/', $version);
297
+			$version = strtolower($version[0]);
298 298
 
299
-			$wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] );
299
+			$wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']);
300 300
 
301
-			if ( array_key_exists( $version, $this->versions ) ) {
301
+			if (array_key_exists($version, $this->versions)) {
302 302
 
303 303
 				$this->queried_version = $version;
304 304
 
@@ -334,16 +334,16 @@  discard block
 block discarded – undo
334 334
 		$this->override = false;
335 335
 
336 336
 		// Make sure we have both user and api key
337
-		if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] !== 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) {
337
+		if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] !== 'forms' || ! empty($wp_query->query_vars['token']))) {
338 338
 
339
-			if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) {
339
+			if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) {
340 340
 				$this->missing_auth();
341 341
 
342 342
 				return false;
343 343
 			}
344 344
 
345 345
 			// Retrieve the user by public API key and ensure they exist
346
-			if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) {
346
+			if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) {
347 347
 
348 348
 				$this->invalid_key();
349 349
 
@@ -351,11 +351,11 @@  discard block
 block discarded – undo
351 351
 
352 352
 			} else {
353 353
 
354
-				$token  = urldecode( $wp_query->query_vars['token'] );
355
-				$secret = $this->get_user_secret_key( $user );
356
-				$public = urldecode( $wp_query->query_vars['key'] );
354
+				$token  = urldecode($wp_query->query_vars['token']);
355
+				$secret = $this->get_user_secret_key($user);
356
+				$public = urldecode($wp_query->query_vars['key']);
357 357
 
358
-				if ( hash_equals( md5( $secret . $public ), $token ) ) {
358
+				if (hash_equals(md5($secret.$public), $token)) {
359 359
 					$this->is_valid_request = true;
360 360
 				} else {
361 361
 					$this->invalid_auth();
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 				}
365 365
 
366 366
 			}
367
-		} elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] === 'forms' ) {
367
+		} elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] === 'forms') {
368 368
 			$this->is_valid_request = true;
369
-			$wp_query->set( 'key', 'public' );
369
+			$wp_query->set('key', 'public');
370 370
 		}
371 371
 	}
372 372
 
@@ -382,25 +382,25 @@  discard block
 block discarded – undo
382 382
 	 *
383 383
 	 * @return bool if user ID is found, false otherwise
384 384
 	 */
385
-	public function get_user( $key = '' ) {
385
+	public function get_user($key = '') {
386 386
 		global $wpdb, $wp_query;
387 387
 
388
-		if ( empty( $key ) ) {
389
-			$key = urldecode( $wp_query->query_vars['key'] );
388
+		if (empty($key)) {
389
+			$key = urldecode($wp_query->query_vars['key']);
390 390
 		}
391 391
 
392
-		if ( empty( $key ) ) {
392
+		if (empty($key)) {
393 393
 			return false;
394 394
 		}
395 395
 
396
-		$user = Give_Cache::get( md5( 'give_api_user_' . $key ), true );
396
+		$user = Give_Cache::get(md5('give_api_user_'.$key), true);
397 397
 
398
-		if ( false === $user ) {
399
-			$user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) );
400
-			Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true );
398
+		if (false === $user) {
399
+			$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key));
400
+			Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true);
401 401
 		}
402 402
 
403
-		if ( $user != null ) {
403
+		if ($user != null) {
404 404
 			$this->user_id = $user;
405 405
 
406 406
 			return $user;
@@ -416,19 +416,19 @@  discard block
 block discarded – undo
416 416
 	 *
417 417
 	 * @return mixed|null|string
418 418
 	 */
419
-	public function get_user_public_key( $user_id = 0 ) {
419
+	public function get_user_public_key($user_id = 0) {
420 420
 		global $wpdb;
421 421
 
422
-		if ( empty( $user_id ) ) {
422
+		if (empty($user_id)) {
423 423
 			return '';
424 424
 		}
425 425
 
426
-		$cache_key       = md5( 'give_api_user_public_key' . $user_id );
427
-		$user_public_key = Give_Cache::get( $cache_key, true );
426
+		$cache_key       = md5('give_api_user_public_key'.$user_id);
427
+		$user_public_key = Give_Cache::get($cache_key, true);
428 428
 
429
-		if ( empty( $user_public_key ) ) {
430
-			$user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) );
431
-			Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true );
429
+		if (empty($user_public_key)) {
430
+			$user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id));
431
+			Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true);
432 432
 		}
433 433
 
434 434
 		return $user_public_key;
@@ -441,19 +441,19 @@  discard block
 block discarded – undo
441 441
 	 *
442 442
 	 * @return mixed|null|string
443 443
 	 */
444
-	public function get_user_secret_key( $user_id = 0 ) {
444
+	public function get_user_secret_key($user_id = 0) {
445 445
 		global $wpdb;
446 446
 
447
-		if ( empty( $user_id ) ) {
447
+		if (empty($user_id)) {
448 448
 			return '';
449 449
 		}
450 450
 
451
-		$cache_key       = md5( 'give_api_user_secret_key' . $user_id );
452
-		$user_secret_key = Give_Cache::get( $cache_key, true );
451
+		$cache_key       = md5('give_api_user_secret_key'.$user_id);
452
+		$user_secret_key = Give_Cache::get($cache_key, true);
453 453
 
454
-		if ( empty( $user_secret_key ) ) {
455
-			$user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) );
456
-			Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true );
454
+		if (empty($user_secret_key)) {
455
+			$user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id));
456
+			Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true);
457 457
 		}
458 458
 
459 459
 		return $user_secret_key;
@@ -469,10 +469,10 @@  discard block
 block discarded – undo
469 469
 	 */
470 470
 	private function missing_auth() {
471 471
 		$error          = array();
472
-		$error['error'] = __( 'You must specify both a token and API key.', 'give' );
472
+		$error['error'] = __('You must specify both a token and API key.', 'give');
473 473
 
474 474
 		$this->data = $error;
475
-		$this->output( 401 );
475
+		$this->output(401);
476 476
 	}
477 477
 
478 478
 	/**
@@ -486,10 +486,10 @@  discard block
 block discarded – undo
486 486
 	 */
487 487
 	private function invalid_auth() {
488 488
 		$error          = array();
489
-		$error['error'] = __( 'Your request could not be authenticated.', 'give' );
489
+		$error['error'] = __('Your request could not be authenticated.', 'give');
490 490
 
491 491
 		$this->data = $error;
492
-		$this->output( 403 );
492
+		$this->output(403);
493 493
 	}
494 494
 
495 495
 	/**
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	private function invalid_key() {
505 505
 		$error          = array();
506
-		$error['error'] = __( 'Invalid API key.', 'give' );
506
+		$error['error'] = __('Invalid API key.', 'give');
507 507
 
508 508
 		$this->data = $error;
509
-		$this->output( 403 );
509
+		$this->output(403);
510 510
 	}
511 511
 
512 512
 	/**
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 	 */
520 520
 	private function invalid_version() {
521 521
 		$error          = array();
522
-		$error['error'] = __( 'Invalid API version.', 'give' );
522
+		$error['error'] = __('Invalid API version.', 'give');
523 523
 
524 524
 		$this->data = $error;
525
-		$this->output( 404 );
525
+		$this->output(404);
526 526
 	}
527 527
 
528 528
 	/**
@@ -538,10 +538,10 @@  discard block
 block discarded – undo
538 538
 		global $wp_query;
539 539
 
540 540
 		// Start logging how long the request takes for logging
541
-		$before = microtime( true );
541
+		$before = microtime(true);
542 542
 
543 543
 		// Check for give-api var. Get out if not present
544
-		if ( empty( $wp_query->query_vars['give-api'] ) ) {
544
+		if (empty($wp_query->query_vars['give-api'])) {
545 545
 			return;
546 546
 		}
547 547
 
@@ -555,45 +555,45 @@  discard block
 block discarded – undo
555 555
 		$this->validate_request();
556 556
 
557 557
 		// Only proceed if no errors have been noted
558
-		if ( ! $this->is_valid_request ) {
558
+		if ( ! $this->is_valid_request) {
559 559
 			return;
560 560
 		}
561 561
 
562
-		if ( ! defined( 'GIVE_DOING_API' ) ) {
563
-			define( 'GIVE_DOING_API', true );
562
+		if ( ! defined('GIVE_DOING_API')) {
563
+			define('GIVE_DOING_API', true);
564 564
 		}
565 565
 
566 566
 		$data         = array();
567 567
 		$this->routes = new $this->versions[$this->get_queried_version()];
568 568
 		$this->routes->validate_request();
569 569
 
570
-		switch ( $this->endpoint ) :
570
+		switch ($this->endpoint) :
571 571
 
572 572
 			case 'stats' :
573 573
 
574
-				$data = $this->routes->get_stats( array(
575
-					'type'      => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null,
576
-					'form'      => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null,
577
-					'date'      => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null,
578
-					'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null,
579
-					'enddate'   => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null,
580
-				) );
574
+				$data = $this->routes->get_stats(array(
575
+					'type'      => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null,
576
+					'form'      => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null,
577
+					'date'      => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null,
578
+					'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null,
579
+					'enddate'   => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null,
580
+				));
581 581
 
582 582
 				break;
583 583
 
584 584
 			case 'forms' :
585 585
 
586
-				$form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null;
586
+				$form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null;
587 587
 
588
-				$data = $this->routes->get_forms( $form );
588
+				$data = $this->routes->get_forms($form);
589 589
 
590 590
 				break;
591 591
 
592 592
 			case 'donors' :
593 593
 
594
-				$donor = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null;
594
+				$donor = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null;
595 595
 
596
-				$data = $this->routes->get_donors( $donor );
596
+				$data = $this->routes->get_donors($donor);
597 597
 
598 598
 				break;
599 599
 
@@ -606,26 +606,26 @@  discard block
 block discarded – undo
606 606
 				 * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524)
607 607
 				 * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524)
608 608
 				 */
609
-				$data = $this->routes->get_recent_donations( array(
610
-					'id'        => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null,
611
-					'date'      => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null,
612
-					'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null,
613
-					'enddate'   => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null,
614
-				) );
609
+				$data = $this->routes->get_recent_donations(array(
610
+					'id'        => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null,
611
+					'date'      => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null,
612
+					'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null,
613
+					'enddate'   => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null,
614
+				));
615 615
 
616 616
 				break;
617 617
 
618 618
 		endswitch;
619 619
 
620 620
 		// Allow extensions to setup their own return data
621
-		$this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this );
621
+		$this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this);
622 622
 
623
-		$after                       = microtime( true );
624
-		$request_time                = ( $after - $before );
623
+		$after                       = microtime(true);
624
+		$request_time                = ($after - $before);
625 625
 		$this->data['request_speed'] = $request_time;
626 626
 
627 627
 		// Log this API request, if enabled. We log it here because we have access to errors.
628
-		$this->log_request( $this->data );
628
+		$this->log_request($this->data);
629 629
 
630 630
 		// Send out data to the output function
631 631
 		$this->output();
@@ -655,25 +655,25 @@  discard block
 block discarded – undo
655 655
 		global $wp_query;
656 656
 
657 657
 		// Whitelist our query options
658
-		$accepted = apply_filters( 'give_api_valid_query_modes', array(
658
+		$accepted = apply_filters('give_api_valid_query_modes', array(
659 659
 			'stats',
660 660
 			'forms',
661 661
 			'donors',
662 662
 			'donations',
663
-		) );
663
+		));
664 664
 
665
-		$query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null;
666
-		$query = str_replace( $this->queried_version . '/', '', $query );
665
+		$query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null;
666
+		$query = str_replace($this->queried_version.'/', '', $query);
667 667
 
668 668
 		$error = array();
669 669
 
670 670
 		// Make sure our query is valid
671
-		if ( ! in_array( $query, $accepted ) ) {
672
-			$error['error'] = __( 'Invalid query.', 'give' );
671
+		if ( ! in_array($query, $accepted)) {
672
+			$error['error'] = __('Invalid query.', 'give');
673 673
 
674 674
 			$this->data = $error;
675 675
 			// 400 is Bad Request
676
-			$this->output( 400 );
676
+			$this->output(400);
677 677
 		}
678 678
 
679 679
 		$this->endpoint = $query;
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 	public function get_paged() {
691 691
 		global $wp_query;
692 692
 
693
-		return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1;
693
+		return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1;
694 694
 	}
695 695
 
696 696
 
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
 	public function per_page() {
706 706
 		global $wp_query;
707 707
 
708
-		$per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10;
708
+		$per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10;
709 709
 
710
-		if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) {
710
+		if ($per_page < 0 && $this->get_query_mode() == 'donors') {
711 711
 			$per_page = 99999999;
712 712
 		} // End if().
713 713
 
714
-		return apply_filters( 'give_api_results_per_page', $per_page );
714
+		return apply_filters('give_api_results_per_page', $per_page);
715 715
 	}
716 716
 
717 717
 	/**
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 	 *
725 725
 	 * @return array $dates
726 726
 	 */
727
-	public function get_dates( $args = array() ) {
727
+	public function get_dates($args = array()) {
728 728
 		$dates = array();
729 729
 
730 730
 		$defaults = array(
@@ -735,60 +735,60 @@  discard block
 block discarded – undo
735 735
 			'enddate'   => null,
736 736
 		);
737 737
 
738
-		$args = wp_parse_args( $args, $defaults );
738
+		$args = wp_parse_args($args, $defaults);
739 739
 
740
-		$current_time = current_time( 'timestamp' );
740
+		$current_time = current_time('timestamp');
741 741
 
742
-		if ( 'range' === $args['date'] ) {
743
-			$startdate          = strtotime( $args['startdate'] );
744
-			$enddate            = strtotime( $args['enddate'] );
745
-			$dates['day_start'] = date( 'd', $startdate );
746
-			$dates['day_end']   = date( 'd', $enddate );
747
-			$dates['m_start']   = date( 'n', $startdate );
748
-			$dates['m_end']     = date( 'n', $enddate );
749
-			$dates['year']      = date( 'Y', $startdate );
750
-			$dates['year_end']  = date( 'Y', $enddate );
742
+		if ('range' === $args['date']) {
743
+			$startdate          = strtotime($args['startdate']);
744
+			$enddate            = strtotime($args['enddate']);
745
+			$dates['day_start'] = date('d', $startdate);
746
+			$dates['day_end']   = date('d', $enddate);
747
+			$dates['m_start']   = date('n', $startdate);
748
+			$dates['m_end']     = date('n', $enddate);
749
+			$dates['year']      = date('Y', $startdate);
750
+			$dates['year_end']  = date('Y', $enddate);
751 751
 		} else {
752 752
 			// Modify dates based on predefined ranges
753
-			switch ( $args['date'] ) :
753
+			switch ($args['date']) :
754 754
 
755 755
 				case 'this_month' :
756 756
 					$dates['day']     = null;
757
-					$dates['m_start'] = date( 'n', $current_time );
758
-					$dates['m_end']   = date( 'n', $current_time );
759
-					$dates['year']    = date( 'Y', $current_time );
757
+					$dates['m_start'] = date('n', $current_time);
758
+					$dates['m_end']   = date('n', $current_time);
759
+					$dates['year']    = date('Y', $current_time);
760 760
 					break;
761 761
 
762 762
 				case 'last_month' :
763 763
 					$dates['day']     = null;
764
-					$dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1;
764
+					$dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1;
765 765
 					$dates['m_end']   = $dates['m_start'];
766
-					$dates['year']    = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time );
766
+					$dates['year']    = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time);
767 767
 					break;
768 768
 
769 769
 				case 'today' :
770
-					$dates['day']     = date( 'd', $current_time );
771
-					$dates['m_start'] = date( 'n', $current_time );
772
-					$dates['m_end']   = date( 'n', $current_time );
773
-					$dates['year']    = date( 'Y', $current_time );
770
+					$dates['day']     = date('d', $current_time);
771
+					$dates['m_start'] = date('n', $current_time);
772
+					$dates['m_end']   = date('n', $current_time);
773
+					$dates['year']    = date('Y', $current_time);
774 774
 					break;
775 775
 
776 776
 				case 'yesterday' :
777 777
 
778
-					$year  = date( 'Y', $current_time );
779
-					$month = date( 'n', $current_time );
780
-					$day   = date( 'd', $current_time );
778
+					$year  = date('Y', $current_time);
779
+					$month = date('n', $current_time);
780
+					$day   = date('d', $current_time);
781 781
 
782
-					if ( $month == 1 && $day == 1 ) {
782
+					if ($month == 1 && $day == 1) {
783 783
 
784
-						$year  -= 1;
784
+						$year -= 1;
785 785
 						$month = 12;
786
-						$day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );
786
+						$day   = cal_days_in_month(CAL_GREGORIAN, $month, $year);
787 787
 
788
-					} elseif ( $month > 1 && $day == 1 ) {
788
+					} elseif ($month > 1 && $day == 1) {
789 789
 
790 790
 						$month -= 1;
791
-						$day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );
791
+						$day = cal_days_in_month(CAL_GREGORIAN, $month, $year);
792 792
 
793 793
 					} else {
794 794
 
@@ -804,65 +804,65 @@  discard block
 block discarded – undo
804 804
 					break;
805 805
 
806 806
 				case 'this_quarter' :
807
-					$month_now = date( 'n', $current_time );
807
+					$month_now = date('n', $current_time);
808 808
 
809 809
 					$dates['day'] = null;
810 810
 
811
-					if ( $month_now <= 3 ) {
811
+					if ($month_now <= 3) {
812 812
 
813 813
 						$dates['m_start'] = 1;
814 814
 						$dates['m_end']   = 3;
815
-						$dates['year']    = date( 'Y', $current_time );
815
+						$dates['year']    = date('Y', $current_time);
816 816
 
817
-					} elseif ( $month_now <= 6 ) {
817
+					} elseif ($month_now <= 6) {
818 818
 
819 819
 						$dates['m_start'] = 4;
820 820
 						$dates['m_end']   = 6;
821
-						$dates['year']    = date( 'Y', $current_time );
821
+						$dates['year']    = date('Y', $current_time);
822 822
 
823
-					} elseif ( $month_now <= 9 ) {
823
+					} elseif ($month_now <= 9) {
824 824
 
825 825
 						$dates['m_start'] = 7;
826 826
 						$dates['m_end']   = 9;
827
-						$dates['year']    = date( 'Y', $current_time );
827
+						$dates['year']    = date('Y', $current_time);
828 828
 
829 829
 					} else {
830 830
 
831 831
 						$dates['m_start'] = 10;
832 832
 						$dates['m_end']   = 12;
833
-						$dates['year']    = date( 'Y', $current_time );
833
+						$dates['year']    = date('Y', $current_time);
834 834
 
835 835
 					}
836 836
 					break;
837 837
 
838 838
 				case 'last_quarter' :
839
-					$month_now = date( 'n', $current_time );
839
+					$month_now = date('n', $current_time);
840 840
 
841 841
 					$dates['day'] = null;
842 842
 
843
-					if ( $month_now <= 3 ) {
843
+					if ($month_now <= 3) {
844 844
 
845 845
 						$dates['m_start'] = 10;
846 846
 						$dates['m_end']   = 12;
847
-						$dates['year']    = date( 'Y', $current_time ) - 1; // Previous year
847
+						$dates['year']    = date('Y', $current_time) - 1; // Previous year
848 848
 
849
-					} elseif ( $month_now <= 6 ) {
849
+					} elseif ($month_now <= 6) {
850 850
 
851 851
 						$dates['m_start'] = 1;
852 852
 						$dates['m_end']   = 3;
853
-						$dates['year']    = date( 'Y', $current_time );
853
+						$dates['year']    = date('Y', $current_time);
854 854
 
855
-					} elseif ( $month_now <= 9 ) {
855
+					} elseif ($month_now <= 9) {
856 856
 
857 857
 						$dates['m_start'] = 4;
858 858
 						$dates['m_end']   = 6;
859
-						$dates['year']    = date( 'Y', $current_time );
859
+						$dates['year']    = date('Y', $current_time);
860 860
 
861 861
 					} else {
862 862
 
863 863
 						$dates['m_start'] = 7;
864 864
 						$dates['m_end']   = 9;
865
-						$dates['year']    = date( 'Y', $current_time );
865
+						$dates['year']    = date('Y', $current_time);
866 866
 
867 867
 					}
868 868
 					break;
@@ -871,14 +871,14 @@  discard block
 block discarded – undo
871 871
 					$dates['day']     = null;
872 872
 					$dates['m_start'] = null;
873 873
 					$dates['m_end']   = null;
874
-					$dates['year']    = date( 'Y', $current_time );
874
+					$dates['year']    = date('Y', $current_time);
875 875
 					break;
876 876
 
877 877
 				case 'last_year' :
878 878
 					$dates['day']     = null;
879 879
 					$dates['m_start'] = null;
880 880
 					$dates['m_end']   = null;
881
-					$dates['year']    = date( 'Y', $current_time ) - 1;
881
+					$dates['year']    = date('Y', $current_time) - 1;
882 882
 					break;
883 883
 
884 884
 			endswitch;
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 		 *
892 892
 		 * @param array $dates The dates used for retrieving earnings.
893 893
 		 */
894
-		return apply_filters( 'give_api_stat_dates', $dates );
894
+		return apply_filters('give_api_stat_dates', $dates);
895 895
 	}
896 896
 
897 897
 	/**
@@ -905,84 +905,84 @@  discard block
 block discarded – undo
905 905
 	 *
906 906
 	 * @return array $donors Multidimensional array of the donors.
907 907
 	 */
908
-	public function get_donors( $donor = null ) {
908
+	public function get_donors($donor = null) {
909 909
 
910 910
 		$donors = array();
911 911
 		$error  = array();
912
-		if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) {
912
+		if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) {
913 913
 			return $donors;
914 914
 		}
915 915
 
916 916
 		$paged    = $this->get_paged();
917 917
 		$per_page = $this->per_page();
918
-		$offset   = $per_page * ( $paged - 1 );
918
+		$offset   = $per_page * ($paged - 1);
919 919
 
920
-		if ( is_numeric( $donor ) ) {
920
+		if (is_numeric($donor)) {
921 921
 			$field = 'id';
922 922
 		} else {
923 923
 			$field = 'email';
924 924
 		}
925 925
 
926
-		$donor_query = Give()->donors->get_donors( array(
926
+		$donor_query = Give()->donors->get_donors(array(
927 927
 			'number' => $per_page,
928 928
 			'offset' => $offset,
929 929
 			$field   => $donor,
930
-		) );
930
+		));
931 931
 		$donor_count = 0;
932 932
 
933
-		if ( $donor_query ) {
933
+		if ($donor_query) {
934 934
 
935
-			foreach ( $donor_query as $donor_obj ) {
935
+			foreach ($donor_query as $donor_obj) {
936 936
 
937
-				$names      = explode( ' ', $donor_obj->name );
938
-				$first_name = ! empty( $names[0] ) ? $names[0] : '';
937
+				$names      = explode(' ', $donor_obj->name);
938
+				$first_name = ! empty($names[0]) ? $names[0] : '';
939 939
 				$last_name  = '';
940
-				if ( ! empty( $names[1] ) ) {
941
-					unset( $names[0] );
942
-					$last_name = implode( ' ', $names );
940
+				if ( ! empty($names[1])) {
941
+					unset($names[0]);
942
+					$last_name = implode(' ', $names);
943 943
 				}
944 944
 
945
-				$donors['donors'][ $donor_count ]['info']['user_id']      = '';
946
-				$donors['donors'][ $donor_count ]['info']['username']     = '';
947
-				$donors['donors'][ $donor_count ]['info']['display_name'] = '';
948
-				$donors['donors'][ $donor_count ]['info']['donor_id']     = $donor_obj->id;
949
-				$donors['donors'][ $donor_count ]['info']['first_name']   = $first_name;
950
-				$donors['donors'][ $donor_count ]['info']['last_name']    = $last_name;
951
-				$donors['donors'][ $donor_count ]['info']['email']        = $donor_obj->email;
945
+				$donors['donors'][$donor_count]['info']['user_id']      = '';
946
+				$donors['donors'][$donor_count]['info']['username']     = '';
947
+				$donors['donors'][$donor_count]['info']['display_name'] = '';
948
+				$donors['donors'][$donor_count]['info']['donor_id']     = $donor_obj->id;
949
+				$donors['donors'][$donor_count]['info']['first_name']   = $first_name;
950
+				$donors['donors'][$donor_count]['info']['last_name']    = $last_name;
951
+				$donors['donors'][$donor_count]['info']['email']        = $donor_obj->email;
952 952
 
953
-				if ( ! empty( $donor_obj->user_id ) ) {
953
+				if ( ! empty($donor_obj->user_id)) {
954 954
 
955
-					$user_data = get_userdata( $donor_obj->user_id );
955
+					$user_data = get_userdata($donor_obj->user_id);
956 956
 
957 957
 					// Donor with registered account.
958
-					$donors['donors'][ $donor_count ]['info']['user_id']      = $donor_obj->user_id;
959
-					$donors['donors'][ $donor_count ]['info']['username']     = $user_data->user_login;
960
-					$donors['donors'][ $donor_count ]['info']['display_name'] = $user_data->display_name;
958
+					$donors['donors'][$donor_count]['info']['user_id']      = $donor_obj->user_id;
959
+					$donors['donors'][$donor_count]['info']['username']     = $user_data->user_login;
960
+					$donors['donors'][$donor_count]['info']['display_name'] = $user_data->display_name;
961 961
 
962 962
 				}
963 963
 
964
-				$donors['donors'][ $donor_count ]['stats']['total_donations'] = $donor_obj->purchase_count;
965
-				$donors['donors'][ $donor_count ]['stats']['total_spent']     = $donor_obj->purchase_value;
964
+				$donors['donors'][$donor_count]['stats']['total_donations'] = $donor_obj->purchase_count;
965
+				$donors['donors'][$donor_count]['stats']['total_spent']     = $donor_obj->purchase_value;
966 966
 
967 967
 				/** @var $donor \Give_Donor */
968
-				$donor = new Give_Donor( $donor_obj->id );
968
+				$donor = new Give_Donor($donor_obj->id);
969 969
 
970 970
 				// Get donor's addresses.
971
-				$donors['donors'][ $donor_count ]['address'] = $donor->address;
971
+				$donors['donors'][$donor_count]['address'] = $donor->address;
972 972
 
973
-				$donor_count ++;
973
+				$donor_count++;
974 974
 
975 975
 			}
976
-		} elseif ( $donor ) {
976
+		} elseif ($donor) {
977 977
 
978 978
 			$error['error'] = sprintf( /* translators: %s: donor */
979
-				__( 'Donor %s not found.', 'give' ), $donor );
979
+				__('Donor %s not found.', 'give'), $donor );
980 980
 
981 981
 			return $error;
982 982
 
983 983
 		} else {
984 984
 
985
-			$error['error'] = __( 'No donors found.', 'give' );
985
+			$error['error'] = __('No donors found.', 'give');
986 986
 
987 987
 			return $error;
988 988
 
@@ -1001,37 +1001,37 @@  discard block
 block discarded – undo
1001 1001
 	 *
1002 1002
 	 * @return array $donors Multidimensional array of the forms.
1003 1003
 	 */
1004
-	public function get_forms( $form = null ) {
1004
+	public function get_forms($form = null) {
1005 1005
 
1006 1006
 		$forms = array();
1007 1007
 		$error = array();
1008 1008
 
1009
-		if ( $form == null ) {
1009
+		if ($form == null) {
1010 1010
 			$forms['forms'] = array();
1011 1011
 
1012
-			$form_list = get_posts( array(
1012
+			$form_list = get_posts(array(
1013 1013
 				'post_type'        => 'give_forms',
1014 1014
 				'posts_per_page'   => $this->per_page(),
1015 1015
 				'suppress_filters' => true,
1016 1016
 				'paged'            => $this->get_paged(),
1017
-			) );
1017
+			));
1018 1018
 
1019
-			if ( $form_list ) {
1019
+			if ($form_list) {
1020 1020
 				$i = 0;
1021
-				foreach ( $form_list as $form_info ) {
1022
-					$forms['forms'][ $i ] = $this->get_form_data( $form_info );
1023
-					$i ++;
1021
+				foreach ($form_list as $form_info) {
1022
+					$forms['forms'][$i] = $this->get_form_data($form_info);
1023
+					$i++;
1024 1024
 				}
1025 1025
 			}
1026 1026
 		} else {
1027
-			if ( get_post_type( $form ) == 'give_forms' ) {
1028
-				$form_info = get_post( $form );
1027
+			if (get_post_type($form) == 'give_forms') {
1028
+				$form_info = get_post($form);
1029 1029
 
1030
-				$forms['forms'][0] = $this->get_form_data( $form_info );
1030
+				$forms['forms'][0] = $this->get_form_data($form_info);
1031 1031
 
1032 1032
 			} else {
1033 1033
 				$error['error'] = sprintf( /* translators: %s: form */
1034
-					__( 'Form %s not found.', 'give' ), $form );
1034
+					__('Form %s not found.', 'give'), $form );
1035 1035
 
1036 1036
 				return $error;
1037 1037
 			}
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 	 *
1050 1050
 	 * @return array                Array of post data to return back in the API.
1051 1051
 	 */
1052
-	private function get_form_data( $form_info ) {
1052
+	private function get_form_data($form_info) {
1053 1053
 
1054 1054
 		$form = array();
1055 1055
 
@@ -1059,60 +1059,60 @@  discard block
 block discarded – undo
1059 1059
 		$form['info']['create_date']   = $form_info->post_date;
1060 1060
 		$form['info']['modified_date'] = $form_info->post_modified;
1061 1061
 		$form['info']['status']        = $form_info->post_status;
1062
-		$form['info']['link']          = html_entity_decode( $form_info->guid );
1063
-		$form['info']['content']       = give_get_meta( $form_info->ID, '_give_form_content', true );
1064
-		$form['info']['thumbnail']     = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) );
1062
+		$form['info']['link']          = html_entity_decode($form_info->guid);
1063
+		$form['info']['content']       = give_get_meta($form_info->ID, '_give_form_content', true);
1064
+		$form['info']['thumbnail']     = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID));
1065 1065
 
1066
-		if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) {
1067
-			$form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' );
1068
-			$form['info']['tags']     = get_the_terms( $form_info, 'give_forms_tag' );
1066
+		if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) {
1067
+			$form['info']['category'] = get_the_terms($form_info, 'give_forms_category');
1068
+			$form['info']['tags']     = get_the_terms($form_info, 'give_forms_tag');
1069 1069
 		}
1070
-		if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) {
1071
-			$form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' );
1070
+		if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) {
1071
+			$form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag');
1072 1072
 		}
1073 1073
 
1074 1074
 		// Check whether any goal is to be achieved for the donation form.
1075
-		$goal_option = give_get_meta( $form_info->ID, '_give_goal_option', true );
1076
-		$goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true );
1077
-		if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) {
1078
-			$total_income                         = give_get_form_earnings_stats( $form_info->ID );
1079
-			$goal_percentage_completed            = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100;
1080
-			$form['goal']['amount']               = isset( $goal_amount ) ? $goal_amount : '';
1081
-			$form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : '';
1075
+		$goal_option = give_get_meta($form_info->ID, '_give_goal_option', true);
1076
+		$goal_amount = give_get_meta($form_info->ID, '_give_set_goal', true);
1077
+		if (give_is_setting_enabled($goal_option) && $goal_amount) {
1078
+			$total_income                         = give_get_form_earnings_stats($form_info->ID);
1079
+			$goal_percentage_completed            = ($total_income < $goal_amount) ? round(($total_income / $goal_amount) * 100, 2) : 100;
1080
+			$form['goal']['amount']               = isset($goal_amount) ? $goal_amount : '';
1081
+			$form['goal']['percentage_completed'] = isset($goal_percentage_completed) ? $goal_percentage_completed : '';
1082 1082
 		}
1083 1083
 
1084
-		if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) {
1085
-			$form['stats']['total']['donations']           = give_get_form_sales_stats( $form_info->ID );
1086
-			$form['stats']['total']['earnings']            = give_get_form_earnings_stats( $form_info->ID );
1087
-			$form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID );
1088
-			$form['stats']['monthly_average']['earnings']  = give_get_average_monthly_form_earnings( $form_info->ID );
1084
+		if (user_can($this->user_id, 'view_give_reports') || $this->override) {
1085
+			$form['stats']['total']['donations']           = give_get_form_sales_stats($form_info->ID);
1086
+			$form['stats']['total']['earnings']            = give_get_form_earnings_stats($form_info->ID);
1087
+			$form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID);
1088
+			$form['stats']['monthly_average']['earnings']  = give_get_average_monthly_form_earnings($form_info->ID);
1089 1089
 		}
1090 1090
 
1091 1091
 		$counter = 0;
1092
-		if ( give_has_variable_prices( $form_info->ID ) ) {
1093
-			foreach ( give_get_variable_prices( $form_info->ID ) as $price ) {
1094
-				$counter ++;
1092
+		if (give_has_variable_prices($form_info->ID)) {
1093
+			foreach (give_get_variable_prices($form_info->ID) as $price) {
1094
+				$counter++;
1095 1095
 				// multi-level item
1096
-				$level                                     = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter;
1097
-				$form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount'];
1096
+				$level                                     = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter;
1097
+				$form['pricing'][sanitize_key($level)] = $price['_give_amount'];
1098 1098
 
1099 1099
 			}
1100 1100
 		} else {
1101
-			$form['pricing']['amount'] = give_get_form_price( $form_info->ID );
1101
+			$form['pricing']['amount'] = give_get_form_price($form_info->ID);
1102 1102
 		}
1103 1103
 
1104
-		if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) {
1104
+		if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) {
1105 1105
 
1106 1106
 			/**
1107 1107
 			 * Fires when generating API sensitive data.
1108 1108
 			 *
1109 1109
 			 * @since 1.1
1110 1110
 			 */
1111
-			do_action( 'give_api_sensitive_data' );
1111
+			do_action('give_api_sensitive_data');
1112 1112
 
1113 1113
 		}
1114 1114
 
1115
-		return apply_filters( 'give_api_forms_form', $form );
1115
+		return apply_filters('give_api_forms_form', $form);
1116 1116
 
1117 1117
 	}
1118 1118
 
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
 	 *
1128 1128
 	 * @return array
1129 1129
 	 */
1130
-	public function get_stats( $args = array() ) {
1130
+	public function get_stats($args = array()) {
1131 1131
 		$defaults = array(
1132 1132
 			'type'      => null,
1133 1133
 			'form'      => null,
@@ -1136,9 +1136,9 @@  discard block
 block discarded – undo
1136 1136
 			'enddate'   => null,
1137 1137
 		);
1138 1138
 
1139
-		$args = wp_parse_args( $args, $defaults );
1139
+		$args = wp_parse_args($args, $defaults);
1140 1140
 
1141
-		$dates = $this->get_dates( $args );
1141
+		$dates = $this->get_dates($args);
1142 1142
 
1143 1143
 		$stats     = array();
1144 1144
 		$earnings  = array(
@@ -1149,40 +1149,40 @@  discard block
 block discarded – undo
1149 1149
 		);
1150 1150
 		$error     = array();
1151 1151
 
1152
-		if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) {
1152
+		if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) {
1153 1153
 			return $stats;
1154 1154
 		}
1155 1155
 
1156
-		if ( $args['type'] == 'donations' ) {
1156
+		if ($args['type'] == 'donations') {
1157 1157
 
1158
-			if ( $args['form'] == null ) {
1159
-				if ( $args['date'] == null ) {
1158
+			if ($args['form'] == null) {
1159
+				if ($args['date'] == null) {
1160 1160
 					$donations = $this->get_default_sales_stats();
1161
-				} elseif ( $args['date'] === 'range' ) {
1161
+				} elseif ($args['date'] === 'range') {
1162 1162
 					// Return donations for a date range.
1163 1163
 					// Ensure the end date is later than the start date.
1164
-					if ( $args['enddate'] < $args['startdate'] ) {
1165
-						$error['error'] = __( 'The end date must be later than the start date.', 'give' );
1164
+					if ($args['enddate'] < $args['startdate']) {
1165
+						$error['error'] = __('The end date must be later than the start date.', 'give');
1166 1166
 					}
1167 1167
 
1168 1168
 					// Ensure both the start and end date are specified
1169
-					if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) {
1170
-						$error['error'] = __( 'Invalid or no date range specified.', 'give' );
1169
+					if (empty($args['startdate']) || empty($args['enddate'])) {
1170
+						$error['error'] = __('Invalid or no date range specified.', 'give');
1171 1171
 					}
1172 1172
 
1173 1173
 					$total = 0;
1174 1174
 
1175 1175
 					// Loop through the years
1176 1176
 					$y = $dates['year'];
1177
-					while ( $y <= $dates['year_end'] ) :
1177
+					while ($y <= $dates['year_end']) :
1178 1178
 
1179
-						if ( $dates['year'] == $dates['year_end'] ) {
1179
+						if ($dates['year'] == $dates['year_end']) {
1180 1180
 							$month_start = $dates['m_start'];
1181 1181
 							$month_end   = $dates['m_end'];
1182
-						} elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) {
1182
+						} elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
1183 1183
 							$month_start = $dates['m_start'];
1184 1184
 							$month_end   = 12;
1185
-						} elseif ( $y == $dates['year_end'] ) {
1185
+						} elseif ($y == $dates['year_end']) {
1186 1186
 							$month_start = 1;
1187 1187
 							$month_end   = $dates['m_end'];
1188 1188
 						} else {
@@ -1191,116 +1191,116 @@  discard block
 block discarded – undo
1191 1191
 						}
1192 1192
 
1193 1193
 						$i = $month_start;
1194
-						while ( $i <= $month_end ) :
1194
+						while ($i <= $month_end) :
1195 1195
 
1196
-							if ( $i == $dates['m_start'] ) {
1196
+							if ($i == $dates['m_start']) {
1197 1197
 								$d = $dates['day_start'];
1198 1198
 							} else {
1199 1199
 								$d = 1;
1200 1200
 							}
1201 1201
 
1202
-							if ( $i == $dates['m_end'] ) {
1202
+							if ($i == $dates['m_end']) {
1203 1203
 								$num_of_days = $dates['day_end'];
1204 1204
 							} else {
1205
-								$num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y );
1205
+								$num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
1206 1206
 							}
1207 1207
 
1208
-							while ( $d <= $num_of_days ) :
1209
-								$sale_count = give_get_sales_by_date( $d, $i, $y );
1210
-								$date_key   = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) );
1211
-								if ( ! isset( $donations['sales'][ $date_key ] ) ) {
1212
-									$donations['sales'][ $date_key ] = 0;
1208
+							while ($d <= $num_of_days) :
1209
+								$sale_count = give_get_sales_by_date($d, $i, $y);
1210
+								$date_key   = date('Ymd', strtotime($y.'/'.$i.'/'.$d));
1211
+								if ( ! isset($donations['sales'][$date_key])) {
1212
+									$donations['sales'][$date_key] = 0;
1213 1213
 								}
1214
-								$donations['sales'][ $date_key ] += $sale_count;
1214
+								$donations['sales'][$date_key] += $sale_count;
1215 1215
 								$total                           += $sale_count;
1216
-								$d ++;
1216
+								$d++;
1217 1217
 							endwhile;
1218
-							$i ++;
1218
+							$i++;
1219 1219
 						endwhile;
1220 1220
 
1221
-						$y ++;
1221
+						$y++;
1222 1222
 					endwhile;
1223 1223
 
1224 1224
 					$donations['totals'] = $total;
1225 1225
 				} else {
1226
-					if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) {
1226
+					if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
1227 1227
 						$donations_count = 0;
1228 1228
 
1229 1229
 						// Loop through the months
1230 1230
 						$month = $dates['m_start'];
1231 1231
 
1232
-						while ( $month <= $dates['m_end'] ) :
1233
-							$donations_count += give_get_sales_by_date( null, $month, $dates['year'] );
1234
-							$month ++;
1232
+						while ($month <= $dates['m_end']) :
1233
+							$donations_count += give_get_sales_by_date(null, $month, $dates['year']);
1234
+							$month++;
1235 1235
 						endwhile;
1236 1236
 
1237
-						$donations['donations'][ $args['date'] ] = $donations_count;
1237
+						$donations['donations'][$args['date']] = $donations_count;
1238 1238
 					} else {
1239
-						$donations['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] );
1239
+						$donations['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']);
1240 1240
 					}
1241 1241
 				}// End if().
1242
-			} elseif ( $args['form'] == 'all' ) {
1243
-				$forms = get_posts( array(
1242
+			} elseif ($args['form'] == 'all') {
1243
+				$forms = get_posts(array(
1244 1244
 					'post_type' => 'give_forms',
1245 1245
 					'nopaging'  => true,
1246
-				) );
1247
-				$i     = 0;
1248
-				foreach ( $forms as $form_info ) {
1249
-					$donations['donations'][ $i ] = array(
1250
-						$form_info->post_name => give_get_form_sales_stats( $form_info->ID ),
1246
+				));
1247
+				$i = 0;
1248
+				foreach ($forms as $form_info) {
1249
+					$donations['donations'][$i] = array(
1250
+						$form_info->post_name => give_get_form_sales_stats($form_info->ID),
1251 1251
 					);
1252
-					$i ++;
1252
+					$i++;
1253 1253
 				}
1254 1254
 			} else {
1255
-				if ( get_post_type( $args['form'] ) == 'give_forms' ) {
1256
-					$form_info                 = get_post( $args['form'] );
1255
+				if (get_post_type($args['form']) == 'give_forms') {
1256
+					$form_info                 = get_post($args['form']);
1257 1257
 					$donations['donations'][0] = array(
1258
-						$form_info->post_name => give_get_form_sales_stats( $args['form'] ),
1258
+						$form_info->post_name => give_get_form_sales_stats($args['form']),
1259 1259
 					);
1260 1260
 				} else {
1261 1261
 					$error['error'] = sprintf( /* translators: %s: form */
1262
-						__( 'Form %s not found.', 'give' ), $args['form'] );
1262
+						__('Form %s not found.', 'give'), $args['form'] );
1263 1263
 				}
1264 1264
 			}// End if().
1265 1265
 
1266
-			if ( ! empty( $error ) ) {
1266
+			if ( ! empty($error)) {
1267 1267
 				return $error;
1268 1268
 			}
1269 1269
 
1270 1270
 			return $donations;
1271 1271
 
1272
-		} elseif ( $args['type'] == 'earnings' ) {
1273
-			if ( $args['form'] == null ) {
1274
-				if ( $args['date'] == null ) {
1272
+		} elseif ($args['type'] == 'earnings') {
1273
+			if ($args['form'] == null) {
1274
+				if ($args['date'] == null) {
1275 1275
 					$earnings = $this->get_default_earnings_stats();
1276
-				} elseif ( $args['date'] === 'range' ) {
1276
+				} elseif ($args['date'] === 'range') {
1277 1277
 					// Return sales for a date range
1278 1278
 					// Ensure the end date is later than the start date
1279
-					if ( $args['enddate'] < $args['startdate'] ) {
1280
-						$error['error'] = __( 'The end date must be later than the start date.', 'give' );
1279
+					if ($args['enddate'] < $args['startdate']) {
1280
+						$error['error'] = __('The end date must be later than the start date.', 'give');
1281 1281
 					}
1282 1282
 
1283 1283
 					// Ensure both the start and end date are specified
1284
-					if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) {
1285
-						$error['error'] = __( 'Invalid or no date range specified.', 'give' );
1284
+					if (empty($args['startdate']) || empty($args['enddate'])) {
1285
+						$error['error'] = __('Invalid or no date range specified.', 'give');
1286 1286
 					}
1287 1287
 
1288 1288
 					$total = (float) 0.00;
1289 1289
 
1290 1290
 					// Loop through the years
1291 1291
 					$y = $dates['year'];
1292
-					if ( ! isset( $earnings['earnings'] ) ) {
1292
+					if ( ! isset($earnings['earnings'])) {
1293 1293
 						$earnings['earnings'] = array();
1294 1294
 					}
1295
-					while ( $y <= $dates['year_end'] ) :
1295
+					while ($y <= $dates['year_end']) :
1296 1296
 
1297
-						if ( $dates['year'] == $dates['year_end'] ) {
1297
+						if ($dates['year'] == $dates['year_end']) {
1298 1298
 							$month_start = $dates['m_start'];
1299 1299
 							$month_end   = $dates['m_end'];
1300
-						} elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) {
1300
+						} elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
1301 1301
 							$month_start = $dates['m_start'];
1302 1302
 							$month_end   = 12;
1303
-						} elseif ( $y == $dates['year_end'] ) {
1303
+						} elseif ($y == $dates['year_end']) {
1304 1304
 							$month_start = 1;
1305 1305
 							$month_end   = $dates['m_end'];
1306 1306
 						} else {
@@ -1309,94 +1309,94 @@  discard block
 block discarded – undo
1309 1309
 						}
1310 1310
 
1311 1311
 						$i = $month_start;
1312
-						while ( $i <= $month_end ) :
1312
+						while ($i <= $month_end) :
1313 1313
 
1314
-							if ( $i == $dates['m_start'] ) {
1314
+							if ($i == $dates['m_start']) {
1315 1315
 								$d = $dates['day_start'];
1316 1316
 							} else {
1317 1317
 								$d = 1;
1318 1318
 							}
1319 1319
 
1320
-							if ( $i == $dates['m_end'] ) {
1320
+							if ($i == $dates['m_end']) {
1321 1321
 								$num_of_days = $dates['day_end'];
1322 1322
 							} else {
1323
-								$num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y );
1323
+								$num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
1324 1324
 							}
1325 1325
 
1326
-							while ( $d <= $num_of_days ) :
1327
-								$earnings_stat = give_get_earnings_by_date( $d, $i, $y );
1328
-								$date_key      = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) );
1329
-								if ( ! isset( $earnings['earnings'][ $date_key ] ) ) {
1330
-									$earnings['earnings'][ $date_key ] = 0;
1326
+							while ($d <= $num_of_days) :
1327
+								$earnings_stat = give_get_earnings_by_date($d, $i, $y);
1328
+								$date_key      = date('Ymd', strtotime($y.'/'.$i.'/'.$d));
1329
+								if ( ! isset($earnings['earnings'][$date_key])) {
1330
+									$earnings['earnings'][$date_key] = 0;
1331 1331
 								}
1332
-								$earnings['earnings'][ $date_key ] += $earnings_stat;
1332
+								$earnings['earnings'][$date_key] += $earnings_stat;
1333 1333
 								$total                             += $earnings_stat;
1334
-								$d ++;
1334
+								$d++;
1335 1335
 							endwhile;
1336 1336
 
1337
-							$i ++;
1337
+							$i++;
1338 1338
 						endwhile;
1339 1339
 
1340
-						$y ++;
1340
+						$y++;
1341 1341
 					endwhile;
1342 1342
 
1343 1343
 					$earnings['totals'] = $total;
1344 1344
 				} else {
1345
-					if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) {
1345
+					if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
1346 1346
 						$earnings_count = (float) 0.00;
1347 1347
 
1348 1348
 						// Loop through the months
1349 1349
 						$month = $dates['m_start'];
1350 1350
 
1351
-						while ( $month <= $dates['m_end'] ) :
1352
-							$earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] );
1353
-							$month ++;
1351
+						while ($month <= $dates['m_end']) :
1352
+							$earnings_count += give_get_earnings_by_date(null, $month, $dates['year']);
1353
+							$month++;
1354 1354
 						endwhile;
1355 1355
 
1356
-						$earnings['earnings'][ $args['date'] ] = $earnings_count;
1356
+						$earnings['earnings'][$args['date']] = $earnings_count;
1357 1357
 					} else {
1358
-						$earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] );
1358
+						$earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']);
1359 1359
 					}
1360 1360
 				}// End if().
1361
-			} elseif ( $args['form'] == 'all' ) {
1362
-				$forms = get_posts( array(
1361
+			} elseif ($args['form'] == 'all') {
1362
+				$forms = get_posts(array(
1363 1363
 					'post_type' => 'give_forms',
1364 1364
 					'nopaging'  => true,
1365
-				) );
1365
+				));
1366 1366
 
1367 1367
 				$i = 0;
1368
-				foreach ( $forms as $form_info ) {
1369
-					$earnings['earnings'][ $i ] = array(
1370
-						$form_info->post_name => give_get_form_earnings_stats( $form_info->ID ),
1368
+				foreach ($forms as $form_info) {
1369
+					$earnings['earnings'][$i] = array(
1370
+						$form_info->post_name => give_get_form_earnings_stats($form_info->ID),
1371 1371
 					);
1372
-					$i ++;
1372
+					$i++;
1373 1373
 				}
1374 1374
 			} else {
1375
-				if ( get_post_type( $args['form'] ) == 'give_forms' ) {
1376
-					$form_info               = get_post( $args['form'] );
1375
+				if (get_post_type($args['form']) == 'give_forms') {
1376
+					$form_info               = get_post($args['form']);
1377 1377
 					$earnings['earnings'][0] = array(
1378
-						$form_info->post_name => give_get_form_earnings_stats( $args['form'] ),
1378
+						$form_info->post_name => give_get_form_earnings_stats($args['form']),
1379 1379
 					);
1380 1380
 				} else {
1381 1381
 					$error['error'] = sprintf( /* translators: %s: form */
1382
-						__( 'Form %s not found.', 'give' ), $args['form'] );
1382
+						__('Form %s not found.', 'give'), $args['form'] );
1383 1383
 				}
1384 1384
 			}// End if().
1385 1385
 
1386
-			if ( ! empty( $error ) ) {
1386
+			if ( ! empty($error)) {
1387 1387
 				return $error;
1388 1388
 			}
1389 1389
 
1390 1390
 			return $earnings;
1391
-		} elseif ( $args['type'] == 'donors' ) {
1391
+		} elseif ($args['type'] == 'donors') {
1392 1392
 			$donors                             = new Give_DB_Donors();
1393 1393
 			$stats['donations']['total_donors'] = $donors->count();
1394 1394
 
1395 1395
 			return $stats;
1396 1396
 
1397
-		} elseif ( empty( $args['type'] ) ) {
1398
-			$stats = array_merge( $stats, $this->get_default_sales_stats() );
1399
-			$stats = array_merge( $stats, $this->get_default_earnings_stats() );
1397
+		} elseif (empty($args['type'])) {
1398
+			$stats = array_merge($stats, $this->get_default_sales_stats());
1399
+			$stats = array_merge($stats, $this->get_default_earnings_stats());
1400 1400
 
1401 1401
 			return array(
1402 1402
 				'stats' => $stats,
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
 	 *
1415 1415
 	 * @return array
1416 1416
 	 */
1417
-	public function get_recent_donations( $args = array() ) {
1417
+	public function get_recent_donations($args = array()) {
1418 1418
 		global $wp_query;
1419 1419
 
1420 1420
 		$defaults = array(
@@ -1424,33 +1424,33 @@  discard block
 block discarded – undo
1424 1424
 			'enddate'   => null,
1425 1425
 		);
1426 1426
 
1427
-		$args = wp_parse_args( $args, $defaults );
1427
+		$args = wp_parse_args($args, $defaults);
1428 1428
 
1429 1429
 		$donations = array();
1430 1430
 
1431
-		if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) {
1431
+		if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) {
1432 1432
 			return $donations;
1433 1433
 		}
1434 1434
 
1435
-		if ( isset( $wp_query->query_vars['id'] ) ) {
1435
+		if (isset($wp_query->query_vars['id'])) {
1436 1436
 			$query   = array();
1437
-			$query[] = new Give_Payment( $wp_query->query_vars['id'] );
1438
-		} elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) {
1437
+			$query[] = new Give_Payment($wp_query->query_vars['id']);
1438
+		} elseif (isset($wp_query->query_vars['purchasekey'])) {
1439 1439
 			$query   = array();
1440
-			$query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] );
1441
-		} elseif ( isset( $wp_query->query_vars['email'] ) ) {
1442
-			$args  = array(
1440
+			$query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
1441
+		} elseif (isset($wp_query->query_vars['email'])) {
1442
+			$args = array(
1443 1443
 				'fields'     => 'ids',
1444 1444
 				'meta_key'   => '_give_payment_donor_email',
1445 1445
 				'meta_value' => $wp_query->query_vars['email'],
1446 1446
 				'number'     => $this->per_page(),
1447 1447
 				'page'       => $this->get_paged(),
1448 1448
 			);
1449
-			$query = give_get_payments( $args );
1450
-		} elseif ( isset( $wp_query->query_vars['date'] ) ) {
1449
+			$query = give_get_payments($args);
1450
+		} elseif (isset($wp_query->query_vars['date'])) {
1451 1451
 
1452
-			$current_time = current_time( 'timestamp' );
1453
-			$dates        = $this->get_dates( $args );
1452
+			$current_time = current_time('timestamp');
1453
+			$dates        = $this->get_dates($args);
1454 1454
 			$start_date   = '';
1455 1455
 			$end_date     = '';
1456 1456
 
@@ -1463,27 +1463,27 @@  discard block
 block discarded – undo
1463 1463
 			 * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524)
1464 1464
 			 * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524)
1465 1465
 			 */
1466
-			switch ( $wp_query->query_vars['date'] ) {
1466
+			switch ($wp_query->query_vars['date']) {
1467 1467
 
1468 1468
 				case 'today':
1469 1469
 
1470 1470
 					// Set and Format Start and End Date to be date of today.
1471
-					$start_date = $end_date = date( 'Y/m/d', $current_time );
1471
+					$start_date = $end_date = date('Y/m/d', $current_time);
1472 1472
 
1473 1473
 					break;
1474 1474
 
1475 1475
 				case 'yesterday':
1476 1476
 
1477 1477
 					// Set and Format Start and End Date to be date of yesterday.
1478
-					$start_date = $end_date = date( 'Y/m', $current_time ) . '/' . ( date( 'd', $current_time ) - 1 );
1478
+					$start_date = $end_date = date('Y/m', $current_time).'/'.(date('d', $current_time) - 1);
1479 1479
 
1480 1480
 					break;
1481 1481
 
1482 1482
 				case 'range':
1483 1483
 
1484 1484
 					// Format Start Date and End Date for filtering payment based on date range.
1485
-					$start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start'];
1486
-					$end_date   = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end'];
1485
+					$start_date = $dates['year'].'/'.$dates['m_start'].'/'.$dates['day_start'];
1486
+					$end_date   = $dates['year_end'].'/'.$dates['m_end'].'/'.$dates['day_end'];
1487 1487
 
1488 1488
 					break;
1489 1489
 
@@ -1497,22 +1497,22 @@  discard block
 block discarded – undo
1497 1497
 				'page'       => $this->get_paged(),
1498 1498
 			);
1499 1499
 
1500
-			$query = give_get_payments( $args );
1500
+			$query = give_get_payments($args);
1501 1501
 		} else {
1502 1502
 			$args  = array(
1503 1503
 				'fields' => 'ids',
1504 1504
 				'number' => $this->per_page(),
1505 1505
 				'page'   => $this->get_paged(),
1506 1506
 			);
1507
-			$query = give_get_payments( $args );
1507
+			$query = give_get_payments($args);
1508 1508
 		}// End if().
1509 1509
 
1510
-		if ( $query ) {
1510
+		if ($query) {
1511 1511
 			$i = 0;
1512
-			foreach ( $query as $payment ) {
1512
+			foreach ($query as $payment) {
1513 1513
 
1514
-				if ( is_numeric( $payment ) ) {
1515
-					$payment      = new Give_Payment( $payment );
1514
+				if (is_numeric($payment)) {
1515
+					$payment      = new Give_Payment($payment);
1516 1516
 					$payment_meta = $payment->get_meta();
1517 1517
 					$user_info    = $payment->user_info;
1518 1518
 				}
@@ -1520,43 +1520,43 @@  discard block
 block discarded – undo
1520 1520
 				$payment_meta = $payment->get_meta();
1521 1521
 				$user_info    = $payment->user_info;
1522 1522
 
1523
-				$first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : '';
1524
-				$last_name  = isset( $user_info['last_name'] ) ? $user_info['last_name'] : '';
1525
-
1526
-				$donations['donations'][ $i ]['ID']             = $payment->number;
1527
-				$donations['donations'][ $i ]['transaction_id'] = $payment->transaction_id;
1528
-				$donations['donations'][ $i ]['key']            = $payment->key;
1529
-				$donations['donations'][ $i ]['total']          = $payment->total;
1530
-				$donations['donations'][ $i ]['status']         = give_get_payment_status( $payment, true );
1531
-				$donations['donations'][ $i ]['gateway']        = $payment->gateway;
1532
-				$donations['donations'][ $i ]['name']           = $first_name . ' ' . $last_name;
1533
-				$donations['donations'][ $i ]['fname']          = $first_name;
1534
-				$donations['donations'][ $i ]['lname']          = $last_name;
1535
-				$donations['donations'][ $i ]['email']          = $payment->email;
1536
-				$donations['donations'][ $i ]['date']           = $payment->date;
1537
-				$donations['donations'][ $i ]['payment_meta']   = array();
1538
-
1539
-				$form_id  = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta;
1540
-				$price    = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false;
1541
-				$price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null;
1542
-
1543
-				$donations['donations'][ $i ]['form']['id']    = $form_id;
1544
-				$donations['donations'][ $i ]['form']['name']  = get_the_title( $payment_meta['form_id'] );
1545
-				$donations['donations'][ $i ]['form']['price'] = $price;
1546
-
1547
-				if ( give_has_variable_prices( $form_id ) ) {
1548
-					if ( isset( $payment_meta['price_id'] ) ) {
1549
-						$price_name                                         = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID );
1550
-						$donations['donations'][ $i ]['form']['price_name'] = $price_name;
1551
-						$donations['donations'][ $i ]['form']['price_id']   = $price_id;
1552
-						$donations['donations'][ $i ]['form']['price']      = give_get_price_option_amount( $form_id, $price_id );
1523
+				$first_name = isset($user_info['first_name']) ? $user_info['first_name'] : '';
1524
+				$last_name  = isset($user_info['last_name']) ? $user_info['last_name'] : '';
1525
+
1526
+				$donations['donations'][$i]['ID']             = $payment->number;
1527
+				$donations['donations'][$i]['transaction_id'] = $payment->transaction_id;
1528
+				$donations['donations'][$i]['key']            = $payment->key;
1529
+				$donations['donations'][$i]['total']          = $payment->total;
1530
+				$donations['donations'][$i]['status']         = give_get_payment_status($payment, true);
1531
+				$donations['donations'][$i]['gateway']        = $payment->gateway;
1532
+				$donations['donations'][$i]['name']           = $first_name.' '.$last_name;
1533
+				$donations['donations'][$i]['fname']          = $first_name;
1534
+				$donations['donations'][$i]['lname']          = $last_name;
1535
+				$donations['donations'][$i]['email']          = $payment->email;
1536
+				$donations['donations'][$i]['date']           = $payment->date;
1537
+				$donations['donations'][$i]['payment_meta']   = array();
1538
+
1539
+				$form_id  = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
1540
+				$price    = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
1541
+				$price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
1542
+
1543
+				$donations['donations'][$i]['form']['id']    = $form_id;
1544
+				$donations['donations'][$i]['form']['name']  = get_the_title($payment_meta['form_id']);
1545
+				$donations['donations'][$i]['form']['price'] = $price;
1546
+
1547
+				if (give_has_variable_prices($form_id)) {
1548
+					if (isset($payment_meta['price_id'])) {
1549
+						$price_name                                         = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
1550
+						$donations['donations'][$i]['form']['price_name'] = $price_name;
1551
+						$donations['donations'][$i]['form']['price_id']   = $price_id;
1552
+						$donations['donations'][$i]['form']['price']      = give_get_price_option_amount($form_id, $price_id);
1553 1553
 
1554 1554
 					}
1555 1555
 				}
1556 1556
 
1557
-				if( ! empty( $payment_meta ) ) {
1557
+				if ( ! empty($payment_meta)) {
1558 1558
 					// Add custom meta to API
1559
-					foreach ( $payment_meta as $meta_key => $meta_value ) {
1559
+					foreach ($payment_meta as $meta_key => $meta_value) {
1560 1560
 
1561 1561
 						$exceptions = array(
1562 1562
 							'form_title',
@@ -1569,20 +1569,20 @@  discard block
 block discarded – undo
1569 1569
 						);
1570 1570
 
1571 1571
 						// Don't clutter up results with dupes
1572
-						if ( in_array( $meta_key, $exceptions ) ) {
1572
+						if (in_array($meta_key, $exceptions)) {
1573 1573
 							continue;
1574 1574
 						}
1575 1575
 
1576
-						$donations['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value;
1576
+						$donations['donations'][$i]['payment_meta'][$meta_key] = $meta_value;
1577 1577
 
1578 1578
 					}
1579 1579
 				}
1580 1580
 
1581
-				$i ++;
1581
+				$i++;
1582 1582
 			}// End foreach().
1583 1583
 		}// End if().
1584 1584
 
1585
-		return apply_filters( 'give_api_donations_endpoint', $donations );
1585
+		return apply_filters('give_api_donations_endpoint', $donations);
1586 1586
 	}
1587 1587
 
1588 1588
 	/**
@@ -1598,9 +1598,9 @@  discard block
 block discarded – undo
1598 1598
 	public function get_output_format() {
1599 1599
 		global $wp_query;
1600 1600
 
1601
-		$format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json';
1601
+		$format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json';
1602 1602
 
1603
-		return apply_filters( 'give_api_output_format', $format );
1603
+		return apply_filters('give_api_output_format', $format);
1604 1604
 	}
1605 1605
 
1606 1606
 
@@ -1616,8 +1616,8 @@  discard block
 block discarded – undo
1616 1616
 	 *
1617 1617
 	 * @return void
1618 1618
 	 */
1619
-	private function log_request( $data = array() ) {
1620
-		if ( ! $this->log_requests ) {
1619
+	private function log_request($data = array()) {
1620
+		if ( ! $this->log_requests) {
1621 1621
 			return;
1622 1622
 		}
1623 1623
 
@@ -1628,37 +1628,37 @@  discard block
 block discarded – undo
1628 1628
 
1629 1629
 		$query = array(
1630 1630
 			'give-api'    => $wp_query->query_vars['give-api'],
1631
-			'key'         => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null,
1632
-			'token'       => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null,
1633
-			'query'       => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null,
1634
-			'type'        => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null,
1635
-			'form'        => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null,
1636
-			'donor'       => isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null,
1637
-			'date'        => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null,
1638
-			'startdate'   => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null,
1639
-			'enddate'     => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null,
1640
-			'id'          => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null,
1641
-			'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null,
1642
-			'email'       => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null,
1631
+			'key'         => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null,
1632
+			'token'       => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null,
1633
+			'query'       => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null,
1634
+			'type'        => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null,
1635
+			'form'        => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null,
1636
+			'donor'       => isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null,
1637
+			'date'        => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null,
1638
+			'startdate'   => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null,
1639
+			'enddate'     => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null,
1640
+			'id'          => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null,
1641
+			'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null,
1642
+			'email'       => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null,
1643 1643
 		);
1644 1644
 
1645 1645
 		$log_data = array(
1646 1646
 			'log_type'     => 'api_request',
1647
-			'post_excerpt' => http_build_query( $query ),
1648
-			'post_content' => ! empty( $data['error'] ) ? $data['error'] : '',
1647
+			'post_excerpt' => http_build_query($query),
1648
+			'post_content' => ! empty($data['error']) ? $data['error'] : '',
1649 1649
 		);
1650 1650
 
1651 1651
 		$log_meta = array(
1652
-			'api_query'  => http_build_query( $query ),
1652
+			'api_query'  => http_build_query($query),
1653 1653
 			'request_ip' => give_get_ip(),
1654 1654
 			'user'       => $this->user_id,
1655
-			'key'        => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null,
1656
-			'token'      => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null,
1655
+			'key'        => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null,
1656
+			'token'      => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null,
1657 1657
 			'time'       => $data['request_speed'],
1658 1658
 			'version'    => $this->get_queried_version(),
1659 1659
 		);
1660 1660
 
1661
-		Give()->logs->insert_log( $log_data, $log_meta );
1661
+		Give()->logs->insert_log($log_data, $log_meta);
1662 1662
 	}
1663 1663
 
1664 1664
 
@@ -1682,11 +1682,11 @@  discard block
 block discarded – undo
1682 1682
 	 *
1683 1683
 	 * @param int       $status_code
1684 1684
 	 */
1685
-	public function output( $status_code = 200 ) {
1685
+	public function output($status_code = 200) {
1686 1686
 
1687 1687
 		$format = $this->get_output_format();
1688 1688
 
1689
-		status_header( $status_code );
1689
+		status_header($status_code);
1690 1690
 
1691 1691
 		/**
1692 1692
 		 * Fires before outputting the API.
@@ -1697,25 +1697,25 @@  discard block
 block discarded – undo
1697 1697
 		 * @param Give_API $this   The Give_API object.
1698 1698
 		 * @param string   $format Output format, XML or JSON. Default is JSON.
1699 1699
 		 */
1700
-		do_action( 'give_api_output_before', $this->data, $this, $format );
1700
+		do_action('give_api_output_before', $this->data, $this, $format);
1701 1701
 
1702
-		switch ( $format ) :
1702
+		switch ($format) :
1703 1703
 
1704 1704
 			case 'xml' :
1705 1705
 
1706
-				require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php';
1707
-				$xml = Array2XML::createXML( 'give', $this->data );
1706
+				require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php';
1707
+				$xml = Array2XML::createXML('give', $this->data);
1708 1708
 				echo $xml->saveXML();
1709 1709
 
1710 1710
 				break;
1711 1711
 
1712 1712
 			case 'json' :
1713 1713
 
1714
-				header( 'Content-Type: application/json' );
1715
-				if ( ! empty( $this->pretty_print ) ) {
1716
-					echo json_encode( $this->data, $this->pretty_print );
1714
+				header('Content-Type: application/json');
1715
+				if ( ! empty($this->pretty_print)) {
1716
+					echo json_encode($this->data, $this->pretty_print);
1717 1717
 				} else {
1718
-					echo json_encode( $this->data );
1718
+					echo json_encode($this->data);
1719 1719
 				}
1720 1720
 
1721 1721
 				break;
@@ -1730,7 +1730,7 @@  discard block
 block discarded – undo
1730 1730
 				 * @param array    $data Response data to return.
1731 1731
 				 * @param Give_API $this The Give_API object.
1732 1732
 				 */
1733
-				do_action( "give_api_output_{$format}", $this->data, $this );
1733
+				do_action("give_api_output_{$format}", $this->data, $this);
1734 1734
 
1735 1735
 				break;
1736 1736
 
@@ -1745,7 +1745,7 @@  discard block
 block discarded – undo
1745 1745
 		 * @param Give_API $this   The Give_API object.
1746 1746
 		 * @param string   $format Output format, XML or JSON. Default is JSON.
1747 1747
 		 */
1748
-		do_action( 'give_api_output_after', $this->data, $this, $format );
1748
+		do_action('give_api_output_after', $this->data, $this, $format);
1749 1749
 
1750 1750
 		give_die();
1751 1751
 	}
@@ -1762,41 +1762,41 @@  discard block
 block discarded – undo
1762 1762
 	 *
1763 1763
 	 * @return void
1764 1764
 	 */
1765
-	function user_key_field( $user ) {
1765
+	function user_key_field($user) {
1766 1766
 
1767
-		if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) {
1767
+		if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) {
1768 1768
 
1769
-			$user = get_userdata( $user->ID );
1769
+			$user = get_userdata($user->ID);
1770 1770
 			?>
1771 1771
 			<table class="form-table">
1772 1772
 				<tbody>
1773 1773
 				<tr>
1774 1774
 					<th>
1775
-						<?php _e( 'Give API Keys', 'give' ); ?>
1775
+						<?php _e('Give API Keys', 'give'); ?>
1776 1776
 					</th>
1777 1777
 					<td>
1778 1778
 						<?php
1779
-						$public_key = $this->get_user_public_key( $user->ID );
1780
-						$secret_key = $this->get_user_secret_key( $user->ID );
1779
+						$public_key = $this->get_user_public_key($user->ID);
1780
+						$secret_key = $this->get_user_secret_key($user->ID);
1781 1781
 						?>
1782
-						<?php if ( empty( $user->give_user_public_key ) ) { ?>
1782
+						<?php if (empty($user->give_user_public_key)) { ?>
1783 1783
 							<input name="give_set_api_key" type="checkbox" id="give_set_api_key" />
1784
-							<span class="description"><?php _e( 'Generate API Key', 'give' ); ?></span>
1784
+							<span class="description"><?php _e('Generate API Key', 'give'); ?></span>
1785 1785
 						<?php } else { ?>
1786
-							<strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?>
1786
+							<strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?>
1787 1787
 								&nbsp;</strong>
1788
-							<input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" />
1788
+							<input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>" />
1789 1789
 							<br />
1790
-							<strong style="display:inline-block; width: 125px;"><?php _e( 'Secret key:', 'give' ); ?>
1790
+							<strong style="display:inline-block; width: 125px;"><?php _e('Secret key:', 'give'); ?>
1791 1791
 								&nbsp;</strong>
1792
-							<input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>" />
1792
+							<input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>" />
1793 1793
 							<br />
1794
-							<strong style="display:inline-block; width: 125px;"><?php _e( 'Token:', 'give' ); ?>
1794
+							<strong style="display:inline-block; width: 125px;"><?php _e('Token:', 'give'); ?>
1795 1795
 								&nbsp;</strong>
1796
-							<input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>" />
1796
+							<input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>" />
1797 1797
 							<br />
1798 1798
 							<input name="give_revoke_api_key" type="checkbox" id="give_revoke_api_key" />
1799
-							<span class="description"><label for="give_revoke_api_key"><?php _e( 'Revoke API Keys', 'give' ); ?></label></span>
1799
+							<span class="description"><label for="give_revoke_api_key"><?php _e('Revoke API Keys', 'give'); ?></label></span>
1800 1800
 						<?php } ?>
1801 1801
 					</td>
1802 1802
 				</tr>
@@ -1815,61 +1815,61 @@  discard block
 block discarded – undo
1815 1815
 	 *
1816 1816
 	 * @return void
1817 1817
 	 */
1818
-	public function process_api_key( $args ) {
1818
+	public function process_api_key($args) {
1819 1819
 
1820
-		if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) {
1821
-			wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array(
1820
+		if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) {
1821
+			wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array(
1822 1822
 				'response' => 403,
1823
-			) );
1823
+			));
1824 1824
 		}
1825 1825
 
1826
-		if ( empty( $args['user_id'] ) ) {
1827
-			wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array(
1826
+		if (empty($args['user_id'])) {
1827
+			wp_die(__('User ID Required.', 'give'), __('Error', 'give'), array(
1828 1828
 				'response' => 401,
1829
-			) );
1829
+			));
1830 1830
 		}
1831 1831
 
1832
-		if ( is_numeric( $args['user_id'] ) ) {
1833
-			$user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id();
1832
+		if (is_numeric($args['user_id'])) {
1833
+			$user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id();
1834 1834
 		} else {
1835
-			$userdata = get_user_by( 'login', $args['user_id'] );
1835
+			$userdata = get_user_by('login', $args['user_id']);
1836 1836
 			$user_id  = $userdata->ID;
1837 1837
 		}
1838
-		$process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false;
1838
+		$process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false;
1839 1839
 
1840
-		if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) {
1841
-			wp_die( sprintf( /* translators: %s: process */
1842
-				__( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array(
1840
+		if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) {
1841
+			wp_die(sprintf( /* translators: %s: process */
1842
+				__('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array(
1843 1843
 				'response' => 403,
1844
-			) );
1845
-		} elseif ( ! current_user_can( 'manage_give_settings' ) ) {
1846
-			wp_die( sprintf( /* translators: %s: process */
1847
-				__( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array(
1844
+			));
1845
+		} elseif ( ! current_user_can('manage_give_settings')) {
1846
+			wp_die(sprintf( /* translators: %s: process */
1847
+				__('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array(
1848 1848
 				'response' => 403,
1849
-			) );
1849
+			));
1850 1850
 		}
1851 1851
 
1852
-		switch ( $process ) {
1852
+		switch ($process) {
1853 1853
 			case 'generate':
1854
-				if ( $this->generate_api_key( $user_id ) ) {
1855
-					Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) );
1856
-					wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) );
1854
+				if ($this->generate_api_key($user_id)) {
1855
+					Give_Cache::delete(Give_Cache::get_key('give_total_api_keys'));
1856
+					wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api'));
1857 1857
 					exit();
1858 1858
 				} else {
1859
-					wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) );
1859
+					wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api'));
1860 1860
 					exit();
1861 1861
 				}
1862 1862
 				break;
1863 1863
 			case 'regenerate':
1864
-				$this->generate_api_key( $user_id, true );
1865
-				Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) );
1866
-				wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) );
1864
+				$this->generate_api_key($user_id, true);
1865
+				Give_Cache::delete(Give_Cache::get_key('give_total_api_keys'));
1866
+				wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api'));
1867 1867
 				exit();
1868 1868
 				break;
1869 1869
 			case 'revoke':
1870
-				$this->revoke_api_key( $user_id );
1871
-				Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) );
1872
-				wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) );
1870
+				$this->revoke_api_key($user_id);
1871
+				Give_Cache::delete(Give_Cache::get_key('give_total_api_keys'));
1872
+				wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api'));
1873 1873
 				exit();
1874 1874
 				break;
1875 1875
 			default;
@@ -1888,59 +1888,59 @@  discard block
 block discarded – undo
1888 1888
 	 *
1889 1889
 	 * @return boolean True if (re)generated successfully, false otherwise.
1890 1890
 	 */
1891
-	public function generate_api_key( $user_id = 0, $regenerate = false ) {
1891
+	public function generate_api_key($user_id = 0, $regenerate = false) {
1892 1892
 
1893 1893
 		// Bail out, if user doesn't exists.
1894
-		if ( empty( $user_id ) ) {
1894
+		if (empty($user_id)) {
1895 1895
 			return false;
1896 1896
 		}
1897 1897
 
1898
-		$user = get_userdata( $user_id );
1898
+		$user = get_userdata($user_id);
1899 1899
 
1900 1900
 		// Bail Out, if user object doesn't exists.
1901
-		if ( ! $user ) {
1901
+		if ( ! $user) {
1902 1902
 			return false;
1903 1903
 		}
1904 1904
 
1905 1905
 		$new_public_key = '';
1906 1906
 		$new_secret_key = '';
1907 1907
 
1908
-		if( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) {
1908
+		if ( ! empty($_POST['from']) && 'profile' === $_POST['from']) {
1909 1909
 			// For User Profile Page.
1910
-			if( ! empty( $_POST['give_set_api_key'] ) ) {
1910
+			if ( ! empty($_POST['give_set_api_key'])) {
1911 1911
 				// Generate API Key from User Profile page.
1912
-				$new_public_key = $this->generate_public_key( $user->user_email );
1913
-				$new_secret_key = $this->generate_private_key( $user->ID );
1914
-			} elseif ( ! empty( $_POST['give_revoke_api_key'] ) ) {
1912
+				$new_public_key = $this->generate_public_key($user->user_email);
1913
+				$new_secret_key = $this->generate_private_key($user->ID);
1914
+			} elseif ( ! empty($_POST['give_revoke_api_key'])) {
1915 1915
 				// Revoke API Key from User Profile page.
1916
-				$this->revoke_api_key( $user->ID );
1916
+				$this->revoke_api_key($user->ID);
1917 1917
 			} else {
1918 1918
 				return false;
1919 1919
 			}
1920 1920
 		} else {
1921 1921
 			// For Tools > API page.
1922
-			$public_key = $this->get_user_public_key( $user_id );
1922
+			$public_key = $this->get_user_public_key($user_id);
1923 1923
 
1924
-			if ( empty( $public_key ) && ! $regenerate ) {
1924
+			if (empty($public_key) && ! $regenerate) {
1925 1925
 				// Generating API for first time.
1926
-				$new_public_key = $this->generate_public_key( $user->user_email );
1927
-				$new_secret_key = $this->generate_private_key( $user->ID );
1928
-			} elseif ( $public_key && $regenerate ) {
1926
+				$new_public_key = $this->generate_public_key($user->user_email);
1927
+				$new_secret_key = $this->generate_private_key($user->ID);
1928
+			} elseif ($public_key && $regenerate) {
1929 1929
 				// API Key already exists and Regenerating API Key.
1930
-				$this->revoke_api_key( $user->ID );
1931
-				$new_public_key = $this->generate_public_key( $user->user_email );
1932
-				$new_secret_key = $this->generate_private_key( $user->ID );
1933
-			} elseif ( ! empty( $public_key ) && ! $regenerate ) {
1930
+				$this->revoke_api_key($user->ID);
1931
+				$new_public_key = $this->generate_public_key($user->user_email);
1932
+				$new_secret_key = $this->generate_private_key($user->ID);
1933
+			} elseif ( ! empty($public_key) && ! $regenerate) {
1934 1934
 				// Doing nothing, when API Key exists but still try to generate again instead of regenerating.
1935 1935
 				return false;
1936 1936
 			} else {
1937 1937
 				// Revoke API Key.
1938
-				$this->revoke_api_key( $user->ID );
1938
+				$this->revoke_api_key($user->ID);
1939 1939
 			}
1940 1940
 		}
1941 1941
 
1942
-		update_user_meta( $user_id, $new_public_key, 'give_user_public_key' );
1943
-		update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' );
1942
+		update_user_meta($user_id, $new_public_key, 'give_user_public_key');
1943
+		update_user_meta($user_id, $new_secret_key, 'give_user_secret_key');
1944 1944
 
1945 1945
 		return true;
1946 1946
 	}
@@ -1955,26 +1955,26 @@  discard block
 block discarded – undo
1955 1955
 	 *
1956 1956
 	 * @return bool
1957 1957
 	 */
1958
-	public function revoke_api_key( $user_id = 0 ) {
1958
+	public function revoke_api_key($user_id = 0) {
1959 1959
 
1960
-		if ( empty( $user_id ) ) {
1960
+		if (empty($user_id)) {
1961 1961
 			return false;
1962 1962
 		}
1963 1963
 
1964
-		$user = get_userdata( $user_id );
1964
+		$user = get_userdata($user_id);
1965 1965
 
1966
-		if ( ! $user ) {
1966
+		if ( ! $user) {
1967 1967
 			return false;
1968 1968
 		}
1969 1969
 
1970
-		$public_key = $this->get_user_public_key( $user_id );
1971
-		$secret_key = $this->get_user_secret_key( $user_id );
1972
-		if ( ! empty( $public_key ) ) {
1973
-			Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) );
1974
-			Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) );
1975
-			Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) );
1976
-			delete_user_meta( $user_id, $public_key );
1977
-			delete_user_meta( $user_id, $secret_key );
1970
+		$public_key = $this->get_user_public_key($user_id);
1971
+		$secret_key = $this->get_user_secret_key($user_id);
1972
+		if ( ! empty($public_key)) {
1973
+			Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key)));
1974
+			Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id)));
1975
+			Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id)));
1976
+			delete_user_meta($user_id, $public_key);
1977
+			delete_user_meta($user_id, $secret_key);
1978 1978
 		} else {
1979 1979
 			return false;
1980 1980
 		}
@@ -1996,9 +1996,9 @@  discard block
 block discarded – undo
1996 1996
 	 *
1997 1997
 	 * @return string
1998 1998
 	 */
1999
-	private function generate_public_key( $user_email = '' ) {
2000
-		$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2001
-		$public   = hash( 'md5', $user_email . $auth_key . date( 'U' ) );
1999
+	private function generate_public_key($user_email = '') {
2000
+		$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2001
+		$public   = hash('md5', $user_email.$auth_key.date('U'));
2002 2002
 
2003 2003
 		return $public;
2004 2004
 	}
@@ -2013,9 +2013,9 @@  discard block
 block discarded – undo
2013 2013
 	 *
2014 2014
 	 * @return string
2015 2015
 	 */
2016
-	private function generate_private_key( $user_id = 0 ) {
2017
-		$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2018
-		$secret   = hash( 'md5', $user_id . $auth_key . date( 'U' ) );
2016
+	private function generate_private_key($user_id = 0) {
2017
+		$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2018
+		$secret   = hash('md5', $user_id.$auth_key.date('U'));
2019 2019
 
2020 2020
 		return $secret;
2021 2021
 	}
@@ -2030,8 +2030,8 @@  discard block
 block discarded – undo
2030 2030
 	 *
2031 2031
 	 * @return string
2032 2032
 	 */
2033
-	public function get_token( $user_id = 0 ) {
2034
-		return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) );
2033
+	public function get_token($user_id = 0) {
2034
+		return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id));
2035 2035
 	}
2036 2036
 
2037 2037
 	/**
@@ -2045,9 +2045,9 @@  discard block
 block discarded – undo
2045 2045
 
2046 2046
 		// Default sales return
2047 2047
 		$donations                               = array();
2048
-		$donations['donations']['today']         = $this->stats->get_sales( 0, 'today' );
2049
-		$donations['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' );
2050
-		$donations['donations']['last_month']    = $this->stats->get_sales( 0, 'last_month' );
2048
+		$donations['donations']['today']         = $this->stats->get_sales(0, 'today');
2049
+		$donations['donations']['current_month'] = $this->stats->get_sales(0, 'this_month');
2050
+		$donations['donations']['last_month']    = $this->stats->get_sales(0, 'last_month');
2051 2051
 		$donations['donations']['totals']        = give_get_total_donations();
2052 2052
 
2053 2053
 		return $donations;
@@ -2064,9 +2064,9 @@  discard block
 block discarded – undo
2064 2064
 
2065 2065
 		// Default earnings return
2066 2066
 		$earnings                              = array();
2067
-		$earnings['earnings']['today']         = $this->stats->get_earnings( 0, 'today' );
2068
-		$earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' );
2069
-		$earnings['earnings']['last_month']    = $this->stats->get_earnings( 0, 'last_month' );
2067
+		$earnings['earnings']['today']         = $this->stats->get_earnings(0, 'today');
2068
+		$earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month');
2069
+		$earnings['earnings']['last_month']    = $this->stats->get_earnings(0, 'last_month');
2070 2070
 		$earnings['earnings']['totals']        = give_get_total_earnings();
2071 2071
 
2072 2072
 		return $earnings;
@@ -2086,25 +2086,25 @@  discard block
 block discarded – undo
2086 2086
 	 *
2087 2087
 	 * @return string            The API key/secret for the user supplied
2088 2088
 	 */
2089
-	public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) {
2089
+	public function api_key_backwards_compat($check, $object_id, $meta_key, $single) {
2090 2090
 
2091
-		if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) {
2091
+		if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') {
2092 2092
 			return $check;
2093 2093
 		}
2094 2094
 
2095 2095
 		$return = $check;
2096 2096
 
2097
-		switch ( $meta_key ) {
2097
+		switch ($meta_key) {
2098 2098
 			case 'give_user_public_key':
2099
-				$return = Give()->api->get_user_public_key( $object_id );
2099
+				$return = Give()->api->get_user_public_key($object_id);
2100 2100
 				break;
2101 2101
 			case 'give_user_secret_key':
2102
-				$return = Give()->api->get_user_secret_key( $object_id );
2102
+				$return = Give()->api->get_user_secret_key($object_id);
2103 2103
 				break;
2104 2104
 		}
2105 2105
 
2106
-		if ( ! $single ) {
2107
-			$return = array( $return );
2106
+		if ( ! $single) {
2107
+			$return = array($return);
2108 2108
 		}
2109 2109
 
2110 2110
 		return $return;
Please login to merge, or discard this patch.
includes/class-give-license-handler.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		 * @access private
704 704
 		 * @since  1.7
705 705
 		 *
706
-		 * @return bool
706
+		 * @return false|null
707 707
 		 */
708 708
 		private function __remove_license_key_from_subscriptions() {
709 709
 			$subscriptions = get_option( 'give_subscriptions', array() );
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 		 * @param $plugin_data
737 737
 		 * @param $status
738 738
 		 *
739
-		 * @return bool
739
+		 * @return false|null
740 740
 		 */
741 741
 		public function plugin_page_notices( $plugin_file, $plugin_data, $status ) {
742 742
 			// Bailout.
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 		 *
759 759
 		 * @since  1.8.7
760 760
 		 * @access public
761
-		 * @return array
761
+		 * @return string
762 762
 		 */
763 763
 		public function license_state_message() {
764 764
 			$message_data = array();
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -10,11 +10,11 @@  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
 
17
-if ( ! class_exists( 'Give_License' ) ) :
17
+if ( ! class_exists('Give_License')) :
18 18
 
19 19
 	/**
20 20
 	 * Give_License Class
@@ -143,27 +143,27 @@  discard block
 block discarded – undo
143 143
 		 * @param string $_checkout_url
144 144
 		 * @param string $_account_url
145 145
 		 */
146
-		public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null ) {
146
+		public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null) {
147 147
 
148 148
 			$give_options = give_get_settings();
149 149
 
150 150
 			$this->file             = $_file;
151 151
 			$this->item_name        = $_item_name;
152
-			$this->item_shortname   = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) );
152
+			$this->item_shortname   = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name)));
153 153
 			$this->version          = $_version;
154
-			$this->license          = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : '';
155
-			$this->license_data     = get_option( $this->item_shortname . '_license_active' );
154
+			$this->license          = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : '';
155
+			$this->license_data     = get_option($this->item_shortname.'_license_active');
156 156
 			$this->author           = $_author;
157
-			$this->api_url          = is_null( $_api_url ) ? $this->api_url : $_api_url;
158
-			$this->checkout_url     = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url;
159
-			$this->account_url      = is_null( $_account_url ) ? $this->account_url : $_account_url;
157
+			$this->api_url          = is_null($_api_url) ? $this->api_url : $_api_url;
158
+			$this->checkout_url     = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url;
159
+			$this->account_url      = is_null($_account_url) ? $this->account_url : $_account_url;
160 160
 			$this->auto_updater_obj = null;
161 161
 
162 162
 			// Add Setting for Give Add-on activation status.
163
-			$is_addon_activated = get_option( 'give_is_addon_activated' );
164
-			if ( ! $is_addon_activated && is_object( $this ) && sizeof( $this ) > 0 ) {
165
-				update_option( 'give_is_addon_activated', true );
166
-				Give_Cache::set( 'give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS );
163
+			$is_addon_activated = get_option('give_is_addon_activated');
164
+			if ( ! $is_addon_activated && is_object($this) && sizeof($this) > 0) {
165
+				update_option('give_is_addon_activated', true);
166
+				Give_Cache::set('give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS);
167 167
 			}
168 168
 
169 169
 			// Setup hooks
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		 */
185 185
 		private function includes() {
186 186
 
187
-			if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
187
+			if ( ! class_exists('EDD_SL_Plugin_Updater')) {
188 188
 				require_once 'admin/EDD_SL_Plugin_Updater.php';
189 189
 			}
190 190
 		}
@@ -202,30 +202,30 @@  discard block
 block discarded – undo
202 202
 		private function hooks() {
203 203
 
204 204
 			// Register settings.
205
-			add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 );
205
+			add_filter('give_settings_licenses', array($this, 'settings'), 1);
206 206
 
207 207
 			// Activate license key on settings save.
208
-			add_action( 'admin_init', array( $this, 'activate_license' ), 10 );
208
+			add_action('admin_init', array($this, 'activate_license'), 10);
209 209
 
210 210
 			// Deactivate license key.
211
-			add_action( 'admin_init', array( $this, 'deactivate_license' ), 11 );
211
+			add_action('admin_init', array($this, 'deactivate_license'), 11);
212 212
 
213 213
 			// Updater.
214
-			add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
215
-			add_action( 'admin_notices', array( $this, 'notices' ) );
214
+			add_action('admin_init', array($this, 'auto_updater'), 0);
215
+			add_action('admin_notices', array($this, 'notices'));
216 216
 
217 217
 			// Check license weekly.
218
-			Give_Cron::add_weekly_event( array( $this, 'weekly_license_check' ) );
219
-			add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_license_check' ) );
218
+			Give_Cron::add_weekly_event(array($this, 'weekly_license_check'));
219
+			add_action('give_validate_license_when_site_migrated', array($this, 'weekly_license_check'));
220 220
 
221 221
 			// Check subscription weekly.
222
-			Give_Cron::add_weekly_event( array( $this, 'weekly_subscription_check' ) );
223
-			add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_subscription_check' ) );
222
+			Give_Cron::add_weekly_event(array($this, 'weekly_subscription_check'));
223
+			add_action('give_validate_license_when_site_migrated', array($this, 'weekly_subscription_check'));
224 224
 
225 225
 			// Show addon notice on plugin page.
226
-			$plugin_name = explode( 'plugins/', $this->file );
227
-			$plugin_name = end( $plugin_name );
228
-			add_action( "after_plugin_row_{$plugin_name}", array( $this, 'plugin_page_notices' ), 10, 3 );
226
+			$plugin_name = explode('plugins/', $this->file);
227
+			$plugin_name = end($plugin_name);
228
+			add_action("after_plugin_row_{$plugin_name}", array($this, 'plugin_page_notices'), 10, 3);
229 229
 
230 230
 		}
231 231
 
@@ -265,16 +265,16 @@  discard block
 block discarded – undo
265 265
 		 *
266 266
 		 * @return array           License settings.
267 267
 		 */
268
-		public function settings( $settings ) {
268
+		public function settings($settings) {
269 269
 
270 270
 			$give_license_settings = array(
271 271
 				array(
272 272
 					'name'    => $this->item_name,
273
-					'id'      => $this->item_shortname . '_license_key',
273
+					'id'      => $this->item_shortname.'_license_key',
274 274
 					'desc'    => '',
275 275
 					'type'    => 'license_key',
276 276
 					'options' => array(
277
-						'license'      => get_option( $this->item_shortname . '_license_active' ),
277
+						'license'      => get_option($this->item_shortname.'_license_active'),
278 278
 						'shortname'    => $this->item_shortname,
279 279
 						'item_name'    => $this->item_name,
280 280
 						'api_url'      => $this->api_url,
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				),
286 286
 			);
287 287
 
288
-			return array_merge( $settings, $give_license_settings );
288
+			return array_merge($settings, $give_license_settings);
289 289
 		}
290 290
 
291 291
 		/**
@@ -300,18 +300,18 @@  discard block
 block discarded – undo
300 300
 		 *
301 301
 		 * @return array           License settings content.
302 302
 		 */
303
-		public function license_settings_content( $settings ) {
303
+		public function license_settings_content($settings) {
304 304
 
305 305
 			$give_license_settings = array(
306 306
 				array(
307
-					'name' => __( 'Add-on Licenses', 'give' ),
307
+					'name' => __('Add-on Licenses', 'give'),
308 308
 					'desc' => '<hr>',
309 309
 					'type' => 'give_title',
310 310
 					'id'   => 'give_title',
311 311
 				),
312 312
 			);
313 313
 
314
-			return array_merge( $settings, $give_license_settings );
314
+			return array_merge($settings, $give_license_settings);
315 315
 		}
316 316
 
317 317
 		/**
@@ -326,62 +326,62 @@  discard block
 block discarded – undo
326 326
 		 */
327 327
 		public function activate_license() {
328 328
 			// Bailout.
329
-			if ( ! $this->__is_user_can_edit_license() ) {
329
+			if ( ! $this->__is_user_can_edit_license()) {
330 330
 				return;
331 331
 			}
332 332
 
333 333
 			// Allow third party addon developers to handle license activation.
334
-			if ( $this->__is_third_party_addon() ) {
335
-				do_action( 'give_activate_license', $this );
334
+			if ($this->__is_third_party_addon()) {
335
+				do_action('give_activate_license', $this);
336 336
 
337 337
 				return;
338 338
 			}
339 339
 
340 340
 			// Delete previous license setting if a empty license key submitted.
341
-			if ( empty( $_POST["{$this->item_shortname}_license_key"] ) ) {
341
+			if (empty($_POST["{$this->item_shortname}_license_key"])) {
342 342
 				$this->unset_license();
343 343
 
344 344
 				return;
345 345
 			}
346 346
 
347 347
 			// Do not simultaneously activate add-ons if the user want to deactivate a specific add-on.
348
-			if( $this->is_deactivating_license() ) {
348
+			if ($this->is_deactivating_license()) {
349 349
 				return;
350 350
 			}
351 351
 
352 352
 			// Check if plugin previously installed.
353
-			if ( $this->is_valid_license() ) {
353
+			if ($this->is_valid_license()) {
354 354
 				return;
355 355
 			}
356 356
 
357 357
 			// Get license key.
358
-			$this->license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] );
358
+			$this->license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']);
359 359
 
360 360
 			// Delete previous license key from subscription if previously added.
361 361
 			$this->__remove_license_key_from_subscriptions();
362 362
 
363 363
 			// Make sure there are no api errors.
364
-			if ( ! ( $license_data = $this->get_license_info( 'activate_license' ) ) ) {
364
+			if ( ! ($license_data = $this->get_license_info('activate_license'))) {
365 365
 				return;
366 366
 			}
367 367
 
368 368
 			// Make sure license is valid.
369 369
 			// return because admin will want to activate license again.
370
-			if ( ! $this->is_license( $license_data ) ) {
370
+			if ( ! $this->is_license($license_data)) {
371 371
 				// Add license key.
372
-				give_update_option( "{$this->item_shortname}_license_key", $this->license );
372
+				give_update_option("{$this->item_shortname}_license_key", $this->license);
373 373
 
374 374
 				return;
375 375
 			}
376 376
 
377 377
 			// Tell WordPress to look for updates.
378
-			set_site_transient( 'update_plugins', null );
378
+			set_site_transient('update_plugins', null);
379 379
 
380 380
 			// Add license data.
381
-			update_option( "{$this->item_shortname}_license_active", $license_data );
381
+			update_option("{$this->item_shortname}_license_active", $license_data);
382 382
 
383 383
 			// Add license key.
384
-			give_update_option( "{$this->item_shortname}_license_key", $this->license );
384
+			give_update_option("{$this->item_shortname}_license_key", $this->license);
385 385
 
386 386
 			// Check subscription for license key and store this to db (if any).
387 387
 			$this->__single_subscription_check();
@@ -399,19 +399,19 @@  discard block
 block discarded – undo
399 399
 		 */
400 400
 		public function deactivate_license() {
401 401
 			// Bailout.
402
-			if ( ! $this->__is_user_can_edit_license() ) {
402
+			if ( ! $this->__is_user_can_edit_license()) {
403 403
 				return;
404 404
 			}
405 405
 
406 406
 			// Allow third party add-on developers to handle license deactivation.
407
-			if ( $this->__is_third_party_addon() ) {
408
-				do_action( 'give_deactivate_license', $this );
407
+			if ($this->__is_third_party_addon()) {
408
+				do_action('give_deactivate_license', $this);
409 409
 
410 410
 				return;
411 411
 			}
412 412
 
413 413
 			// Run on deactivate button press.
414
-			if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) {
414
+			if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) {
415 415
 				$this->unset_license();
416 416
 			}
417 417
 		}
@@ -427,30 +427,30 @@  discard block
 block discarded – undo
427 427
 		public function weekly_license_check() {
428 428
 
429 429
 			if (
430
-				! empty( $_POST['give_settings'] ) ||
431
-				empty( $this->license )
430
+				! empty($_POST['give_settings']) ||
431
+				empty($this->license)
432 432
 			) {
433 433
 				return;
434 434
 			}
435 435
 
436 436
 			// Allow third party add-on developers to handle their license check.
437
-			if ( $this->__is_third_party_addon() ) {
438
-				do_action( 'give_weekly_license_check', $this );
437
+			if ($this->__is_third_party_addon()) {
438
+				do_action('give_weekly_license_check', $this);
439 439
 
440 440
 				return;
441 441
 			}
442 442
 
443 443
 			// Make sure there are no api errors.
444
-			if ( ! ( $license_data = $this->get_license_info( 'check_license' ) ) ) {
444
+			if ( ! ($license_data = $this->get_license_info('check_license'))) {
445 445
 				return;
446 446
 			}
447 447
 
448 448
 			// Bailout.
449
-			if ( ! $this->is_license( $license_data ) ) {
449
+			if ( ! $this->is_license($license_data)) {
450 450
 				return;
451 451
 			}
452 452
 
453
-			update_option( $this->item_shortname . '_license_active', $license_data );
453
+			update_option($this->item_shortname.'_license_active', $license_data);
454 454
 
455 455
 			return;
456 456
 		}
@@ -466,21 +466,21 @@  discard block
 block discarded – undo
466 466
 		public function weekly_subscription_check() {
467 467
 			// Bailout.
468 468
 			if (
469
-				! empty( $_POST['give_settings'] ) ||
470
-				empty( $this->license )
469
+				! empty($_POST['give_settings']) ||
470
+				empty($this->license)
471 471
 			) {
472 472
 				return;
473 473
 			}
474 474
 
475 475
 			// Remove old subscription data.
476
-			if ( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp', 1 ) ) {
477
-				delete_option( 'give_subscriptions' );
478
-				update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp', 1 ) ) );
476
+			if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) {
477
+				delete_option('give_subscriptions');
478
+				update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1)));
479 479
 			}
480 480
 
481 481
 			// Allow third party add-on developers to handle their subscription check.
482
-			if ( $this->__is_third_party_addon() ) {
483
-				do_action( 'give_weekly_subscription_check', $this );
482
+			if ($this->__is_third_party_addon()) {
483
+				do_action('give_weekly_subscription_check', $this);
484 484
 
485 485
 				return;
486 486
 			}
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		 * @return void
498 498
 		 */
499 499
 		private function __single_subscription_check() {
500
-			if ( empty( $this->license ) ) {
500
+			if (empty($this->license)) {
501 501
 				return;
502 502
 			}
503 503
 
@@ -508,26 +508,26 @@  discard block
 block discarded – undo
508 508
 			 * By default edd software licensing api does not have api to check subscription.
509 509
 			 * This is a custom feature to check subscriptions.
510 510
 			 */
511
-			$subscription_data = $this->get_license_info( 'check_subscription', true );
511
+			$subscription_data = $this->get_license_info('check_subscription', true);
512 512
 
513
-			if ( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) {
513
+			if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) {
514 514
 
515
-				$subscriptions = get_option( 'give_subscriptions', array() );
515
+				$subscriptions = get_option('give_subscriptions', array());
516 516
 
517 517
 				// Update subscription data only if subscription does not exist already.
518
-				$subscriptions[ $subscription_data['id'] ] = $subscription_data;
518
+				$subscriptions[$subscription_data['id']] = $subscription_data;
519 519
 
520 520
 				// Initiate default set of license for subscription.
521
-				if ( ! isset( $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) {
522
-					$subscriptions[ $subscription_data['id'] ]['licenses'] = array();
521
+				if ( ! isset($subscriptions[$subscription_data['id']]['licenses'])) {
522
+					$subscriptions[$subscription_data['id']]['licenses'] = array();
523 523
 				}
524 524
 
525 525
 				// Store licenses for subscription.
526
-				if ( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) {
527
-					$subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license;
526
+				if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) {
527
+					$subscriptions[$subscription_data['id']]['licenses'][] = $this->license;
528 528
 				}
529 529
 
530
-				update_option( 'give_subscriptions', $subscriptions );
530
+				update_option('give_subscriptions', $subscriptions);
531 531
 			}
532 532
 		}
533 533
 
@@ -541,12 +541,12 @@  discard block
 block discarded – undo
541 541
 		 */
542 542
 		public function notices() {
543 543
 
544
-			if ( ! current_user_can( 'manage_give_settings' ) ) {
544
+			if ( ! current_user_can('manage_give_settings')) {
545 545
 				return;
546 546
 			}
547 547
 
548 548
 			// Do not show licenses notices on license tab.
549
-			if ( 'licenses' === give_get_current_setting_tab() ) {
549
+			if ('licenses' === give_get_current_setting_tab()) {
550 550
 				return;
551 551
 			}
552 552
 
@@ -555,118 +555,118 @@  discard block
 block discarded – undo
555 555
 			static $addon_license_key_in_subscriptions;
556 556
 
557 557
 			// Set default value.
558
-			$addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array();
558
+			$addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array();
559 559
 			$messages                           = array();
560 560
 
561 561
 			// Check whether admin has Give Add-on activated since 24 hours?
562
-			$is_license_notice_hidden = Give_Cache::get( 'give_cache_hide_license_notice_after_activation' );
562
+			$is_license_notice_hidden = Give_Cache::get('give_cache_hide_license_notice_after_activation');
563 563
 
564 564
 			// Display Invalid License notice, if its more than 24 hours since first Give Add-on activation.
565 565
 			if (
566
-				empty( $this->license )
567
-				&& empty( $showed_invalid_message )
568
-				&& ( false === $is_license_notice_hidden )
566
+				empty($this->license)
567
+				&& empty($showed_invalid_message)
568
+				&& (false === $is_license_notice_hidden)
569 569
 			) {
570 570
 
571
-				Give()->notices->register_notice( array(
571
+				Give()->notices->register_notice(array(
572 572
 					'id'               => 'give-invalid-license',
573 573
 					'type'             => 'error',
574 574
 					'description'      => sprintf(
575
-						__( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ),
576
-						admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' )
575
+						__('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'),
576
+						admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')
577 577
 					),
578 578
 					'dismissible_type' => 'user',
579 579
 					'dismiss_interval' => 'shortly',
580
-				) );
580
+				));
581 581
 
582 582
 				$showed_invalid_message = true;
583 583
 
584 584
 			}
585 585
 
586 586
 			// Get subscriptions.
587
-			$subscriptions = get_option( 'give_subscriptions' );
587
+			$subscriptions = get_option('give_subscriptions');
588 588
 
589 589
 			// Show subscription messages.
590
-			if ( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) {
590
+			if ( ! empty($subscriptions) && ! $showed_subscriptions_message) {
591 591
 
592
-				foreach ( $subscriptions as $subscription ) {
592
+				foreach ($subscriptions as $subscription) {
593 593
 					// Subscription expires timestamp.
594
-					$subscription_expires = strtotime( $subscription['expires'] );
594
+					$subscription_expires = strtotime($subscription['expires']);
595 595
 
596 596
 					// Start showing subscriptions message before one week of renewal date.
597
-					if ( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) {
597
+					if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) {
598 598
 						continue;
599 599
 					}
600 600
 
601 601
 					// Check if subscription message already exist in messages.
602
-					if ( array_key_exists( $subscription['id'], $messages ) ) {
602
+					if (array_key_exists($subscription['id'], $messages)) {
603 603
 						continue;
604 604
 					}
605 605
 
606 606
 					// Check if license already expired.
607
-					if ( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) {
608
-						Give()->notices->register_notice( array(
607
+					if (strtotime($subscription['expires']) < current_time('timestamp', 1)) {
608
+						Give()->notices->register_notice(array(
609 609
 							'id'               => "give-expired-subscription-{$subscription['id']}",
610 610
 							'type'             => 'error',
611 611
 							'description'      => sprintf(
612
-								__( 'Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give' ),
613
-								urldecode( $subscription['invoice_url'] ),
612
+								__('Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give'),
613
+								urldecode($subscription['invoice_url']),
614 614
 								$subscription['payment_id'],
615 615
 								"{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired",
616
-								Give()->notices->get_dismiss_link( array(
617
-									'title'            => __( 'Click here if already renewed', 'give' ),
616
+								Give()->notices->get_dismiss_link(array(
617
+									'title'            => __('Click here if already renewed', 'give'),
618 618
 									'dismissible_type' => 'user',
619 619
 									'dismiss_interval' => 'permanent',
620
-								) )
620
+								))
621 621
 							),
622 622
 							'dismissible_type' => 'user',
623 623
 							'dismiss_interval' => 'shortly',
624
-						) );
624
+						));
625 625
 					} else {
626
-						Give()->notices->register_notice( array(
626
+						Give()->notices->register_notice(array(
627 627
 							'id'               => "give-expires-subscription-{$subscription['id']}",
628 628
 							'type'             => 'error',
629 629
 							'description'      => sprintf(
630
-								__( 'Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give' ),
631
-								human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ),
632
-								urldecode( $subscription['invoice_url'] ),
630
+								__('Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give'),
631
+								human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])),
632
+								urldecode($subscription['invoice_url']),
633 633
 								$subscription['payment_id'],
634 634
 								"{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired",
635
-								Give()->notices->get_dismiss_link( array(
636
-									'title'            => __( 'Click here if already renewed', 'give' ),
635
+								Give()->notices->get_dismiss_link(array(
636
+									'title'            => __('Click here if already renewed', 'give'),
637 637
 									'dismissible_type' => 'user',
638 638
 									'dismiss_interval' => 'permanent',
639
-								) )
639
+								))
640 640
 							),
641 641
 							'dismissible_type' => 'user',
642 642
 							'dismiss_interval' => 'shortly',
643
-						) );
643
+						));
644 644
 					}
645 645
 
646 646
 					// Stop validation for these license keys.
647
-					$addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] );
647
+					$addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']);
648 648
 				}// End foreach().
649 649
 				$showed_subscriptions_message = true;
650 650
 			}// End if().
651 651
 
652 652
 			// Show Non Subscription Give Add-on messages.
653 653
 			if (
654
-				! in_array( $this->license, $addon_license_key_in_subscriptions )
655
-				&& ! empty( $this->license )
656
-				&& empty( $showed_invalid_message )
654
+				! in_array($this->license, $addon_license_key_in_subscriptions)
655
+				&& ! empty($this->license)
656
+				&& empty($showed_invalid_message)
657 657
 				&& ! $this->is_valid_license()
658 658
 			) {
659 659
 
660
-				Give()->notices->register_notice( array(
660
+				Give()->notices->register_notice(array(
661 661
 					'id'               => 'give-invalid-license',
662 662
 					'type'             => 'error',
663 663
 					'description'      => sprintf(
664
-						__( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ),
665
-						admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' )
664
+						__('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'),
665
+						admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')
666 666
 					),
667 667
 					'dismissible_type' => 'user',
668 668
 					'dismiss_interval' => 'shortly',
669
-				) );
669
+				));
670 670
 
671 671
 				$showed_invalid_message = true;
672 672
 
@@ -683,10 +683,10 @@  discard block
 block discarded – undo
683 683
 		 *
684 684
 		 * @return bool
685 685
 		 */
686
-		public function is_valid_license( $licence_data = null ) {
687
-			$license_data = empty( $licence_data ) ? $this->license_data : $licence_data;
686
+		public function is_valid_license($licence_data = null) {
687
+			$license_data = empty($licence_data) ? $this->license_data : $licence_data;
688 688
 
689
-			if ( apply_filters( 'give_is_valid_license', ( $this->is_license( $license_data ) && 'valid' === $license_data->license ) ) ) {
689
+			if (apply_filters('give_is_valid_license', ($this->is_license($license_data) && 'valid' === $license_data->license))) {
690 690
 				return true;
691 691
 			}
692 692
 
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
 		 *
705 705
 		 * @return bool
706 706
 		 */
707
-		public function is_license( $licence_data = null ) {
708
-			$license_data = empty( $licence_data ) ? $this->license_data : $licence_data;
707
+		public function is_license($licence_data = null) {
708
+			$license_data = empty($licence_data) ? $this->license_data : $licence_data;
709 709
 
710
-			if ( apply_filters( 'give_is_license', ( is_object( $license_data ) && ! empty( $license_data ) && property_exists( $license_data, 'license' ) ) ) ) {
710
+			if (apply_filters('give_is_license', (is_object($license_data) && ! empty($license_data) && property_exists($license_data, 'license')))) {
711 711
 				return true;
712 712
 			}
713 713
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		 * @return bool
724 724
 		 */
725 725
 		private function __is_third_party_addon() {
726
-			return ( false === strpos( $this->api_url, 'givewp.com/' ) );
726
+			return (false === strpos($this->api_url, 'givewp.com/'));
727 727
 		}
728 728
 
729 729
 		/**
@@ -738,25 +738,25 @@  discard block
 block discarded – undo
738 738
 		 * @return bool
739 739
 		 */
740 740
 		private function __remove_license_key_from_subscriptions() {
741
-			$subscriptions = get_option( 'give_subscriptions', array() );
741
+			$subscriptions = get_option('give_subscriptions', array());
742 742
 
743 743
 			// Bailout.
744
-			if ( empty( $this->license ) ) {
744
+			if (empty($this->license)) {
745 745
 				return false;
746 746
 			}
747 747
 
748
-			if ( ! empty( $subscriptions ) ) {
749
-				foreach ( $subscriptions as $subscription_id => $subscription ) {
750
-					$license_index = array_search( $this->license, $subscription['licenses'] );
751
-					if ( false !== $license_index ) {
748
+			if ( ! empty($subscriptions)) {
749
+				foreach ($subscriptions as $subscription_id => $subscription) {
750
+					$license_index = array_search($this->license, $subscription['licenses']);
751
+					if (false !== $license_index) {
752 752
 						// Remove license key.
753
-						unset( $subscriptions[ $subscription_id ]['licenses'][ $license_index ] );
753
+						unset($subscriptions[$subscription_id]['licenses'][$license_index]);
754 754
 
755 755
 						// Rearrange license keys.
756
-						$subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] );
756
+						$subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']);
757 757
 
758 758
 						// Update subscription information.
759
-						update_option( 'give_subscriptions', $subscriptions );
759
+						update_option('give_subscriptions', $subscriptions);
760 760
 						break;
761 761
 					}
762 762
 				}
@@ -770,17 +770,17 @@  discard block
 block discarded – undo
770 770
 		 *
771 771
 		 * @return bool
772 772
 		 */
773
-		public function plugin_page_notices( $plugin_file, $plugin_data, $status ) {
773
+		public function plugin_page_notices($plugin_file, $plugin_data, $status) {
774 774
 			// Bailout.
775
-			if ( $this->is_valid_license() ) {
775
+			if ($this->is_valid_license()) {
776 776
 				return false;
777 777
 			}
778 778
 
779 779
 			$update_notice_wrap = '<tr class="give-addon-notice-tr active"><td colspan="3" class="colspanchange"><div class="notice inline notice-warning notice-alt give-invalid-license"><p><span class="dashicons dashicons-info"></span> %s</p></div></td></tr>';
780 780
 			$message            = $this->license_state_message();
781 781
 
782
-			if ( ! empty( $message['message'] ) ) {
783
-				echo sprintf( $update_notice_wrap, $message['message'] );
782
+			if ( ! empty($message['message'])) {
783
+				echo sprintf($update_notice_wrap, $message['message']);
784 784
 			}
785 785
 		}
786 786
 
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
 		public function license_state_message() {
796 796
 			$message_data = array();
797 797
 
798
-			if ( ! $this->is_valid_license() ) {
798
+			if ( ! $this->is_valid_license()) {
799 799
 
800 800
 				$message_data['message'] = sprintf(
801 801
 					'Please <a href="%1$s">activate your license</a> to receive updates and support for the %2$s add-on.',
802
-					esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) ),
802
+					esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')),
803 803
 					$this->item_name
804 804
 				);
805 805
 			}
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 			// Bailout.
819 819
 			if (
820 820
 				! Give_Admin_Settings::verify_nonce() ||
821
-				! current_user_can( 'manage_give_settings' ) ||
821
+				! current_user_can('manage_give_settings') ||
822 822
 				'licenses' !== give_get_current_setting_tab()
823 823
 			) {
824 824
 				return false;
@@ -826,10 +826,10 @@  discard block
 block discarded – undo
826 826
 
827 827
 			// Security check.
828 828
 			if (
829
-				isset( $_POST[ $this->item_shortname . '_license_key-nonce' ] ) &&
830
-				! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' )
829
+				isset($_POST[$this->item_shortname.'_license_key-nonce']) &&
830
+				! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')
831 831
 			) {
832
-				wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
832
+				wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403));
833 833
 			}
834 834
 
835 835
 			return true;
@@ -847,9 +847,9 @@  discard block
 block discarded – undo
847 847
 		 *
848 848
 		 * @return mixed
849 849
 		 */
850
-		public function get_license_info( $edd_action = '', $response_in_array = false ) {
850
+		public function get_license_info($edd_action = '', $response_in_array = false) {
851 851
 
852
-			if ( empty( $edd_action ) ) {
852
+			if (empty($edd_action)) {
853 853
 				return false;
854 854
 			}
855 855
 
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 			$api_params = array(
858 858
 				'edd_action' => $edd_action, // never change from "edd_" to "give_"!
859 859
 				'license'    => $this->license,
860
-				'item_name'  => urlencode( $this->item_name ),
860
+				'item_name'  => urlencode($this->item_name),
861 861
 				'url'        => home_url(),
862 862
 			);
863 863
 
@@ -872,11 +872,11 @@  discard block
 block discarded – undo
872 872
 			);
873 873
 
874 874
 			// Make sure there are no errors.
875
-			if ( is_wp_error( $response ) ) {
875
+			if (is_wp_error($response)) {
876 876
 				return false;
877 877
 			}
878 878
 
879
-			return json_decode( wp_remote_retrieve_body( $response ), $response_in_array );
879
+			return json_decode(wp_remote_retrieve_body($response), $response_in_array);
880 880
 		}
881 881
 
882 882
 
@@ -892,9 +892,9 @@  discard block
 block discarded – undo
892 892
 			$this->__remove_license_key_from_subscriptions();
893 893
 
894 894
 			// Remove license from database.
895
-			delete_option( "{$this->item_shortname}_license_active" );
896
-			give_delete_option( "{$this->item_shortname}_license_key" );
897
-			unset( $_POST["{$this->item_shortname}_license_key"] );
895
+			delete_option("{$this->item_shortname}_license_active");
896
+			give_delete_option("{$this->item_shortname}_license_key");
897
+			unset($_POST["{$this->item_shortname}_license_key"]);
898 898
 
899 899
 			// Unset license param.
900 900
 			$this->license = '';
@@ -912,8 +912,8 @@  discard block
 block discarded – undo
912 912
 		private function is_deactivating_license() {
913 913
 			$status = false;
914 914
 
915
-			foreach ( $_POST as $key => $value ) {
916
-				if ( false !== strpos( $key, 'license_key_deactivate' ) ) {
915
+			foreach ($_POST as $key => $value) {
916
+				if (false !== strpos($key, 'license_key_deactivate')) {
917 917
 					$status = true;
918 918
 					break;
919 919
 				}
Please login to merge, or discard this patch.
includes/payments/class-payment-stats.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param  $end_date   string|bool  The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month`
37 37
 	 * @param  $status     string|array The sale status(es) to count. Only valid when retrieving global stats
38 38
 	 *
39
-	 * @return float|int                Total amount of donations based on the passed arguments.
39
+	 * @return string                Total amount of donations based on the passed arguments.
40 40
 	 */
41 41
 	public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) {
42 42
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param  $end_date    string|bool The end date for which we'd like to filter the donations stats. If false, method will use the default end date of `this_month`.
84 84
 	 * @param  $gateway_id  string|bool The gateway to get earnings for such as 'paypal' or 'stripe'.
85 85
 	 *
86
-	 * @return float|int                Total amount of donations based on the passed arguments.
86
+	 * @return string                Total amount of donations based on the passed arguments.
87 87
 	 */
88 88
 	public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) {
89 89
 		$this->setup_dates( $start_date, $end_date );
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param  $end_date    string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month`
169 169
 	 * @param  $gateway_id  string|bool The gateway to get earnings for such as 'paypal' or 'stripe'
170 170
 	 *
171
-	 * @return float|int                Total amount of donations based on the passed arguments.
171
+	 * @return string                Total amount of donations based on the passed arguments.
172 172
 	 */
173 173
 	public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) {
174 174
 
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 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
 
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return float|int                Total amount of donations based on the passed arguments.
40 40
 	 */
41
-	public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) {
41
+	public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') {
42 42
 
43
-		$this->setup_dates( $start_date, $end_date );
43
+		$this->setup_dates($start_date, $end_date);
44 44
 
45 45
 		// Make sure start date is valid
46
-		if ( is_wp_error( $this->start_date ) ) {
46
+		if (is_wp_error($this->start_date)) {
47 47
 			return $this->start_date;
48 48
 		}
49 49
 
50 50
 		// Make sure end date is valid
51
-		if ( is_wp_error( $this->end_date ) ) {
51
+		if (is_wp_error($this->end_date)) {
52 52
 			return $this->end_date;
53 53
 		}
54 54
 
@@ -57,18 +57,18 @@  discard block
 block discarded – undo
57 57
 			'start_date' => $this->start_date,
58 58
 			'end_date'   => $this->end_date,
59 59
 			'fields'     => 'ids',
60
-			'number'     => - 1,
60
+			'number'     => -1,
61 61
 		);
62 62
 
63
-		if ( ! empty( $form_id ) ) {
63
+		if ( ! empty($form_id)) {
64 64
 			$args['give_forms'] = $form_id;
65 65
 		}
66 66
 
67 67
 		/* @var Give_Payments_Query $payments */
68
-		$payments = new Give_Payments_Query( $args );
68
+		$payments = new Give_Payments_Query($args);
69 69
 		$payments = $payments->get_payments();
70 70
 
71
-		return count( $payments );
71
+		return count($payments);
72 72
 	}
73 73
 
74 74
 
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @return float|int                Total amount of donations based on the passed arguments.
87 87
 	 */
88
-	public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) {
89
-		$this->setup_dates( $start_date, $end_date );
88
+	public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) {
89
+		$this->setup_dates($start_date, $end_date);
90 90
 
91 91
 		// Make sure start date is valid
92
-		if ( is_wp_error( $this->start_date ) ) {
92
+		if (is_wp_error($this->start_date)) {
93 93
 			return $this->start_date;
94 94
 		}
95 95
 
96 96
 		// Make sure end date is valid
97
-		if ( is_wp_error( $this->end_date ) ) {
97
+		if (is_wp_error($this->end_date)) {
98 98
 			return $this->end_date;
99 99
 		}
100 100
 
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 			'start_date' => $this->start_date,
105 105
 			'end_date'   => $this->end_date,
106 106
 			'fields'     => 'ids',
107
-			'number'     => - 1,
107
+			'number'     => -1,
108 108
 		);
109 109
 
110 110
 
111 111
 		// Filter by Gateway ID meta_key
112
-		if ( $gateway_id ) {
112
+		if ($gateway_id) {
113 113
 			$args['meta_query'][] = array(
114 114
 				'key'   => '_give_payment_gateway',
115 115
 				'value' => $gateway_id,
@@ -117,39 +117,39 @@  discard block
 block discarded – undo
117 117
 		}
118 118
 
119 119
 		// Filter by Gateway ID meta_key
120
-		if ( $form_id ) {
120
+		if ($form_id) {
121 121
 			$args['meta_query'][] = array(
122 122
 				'key'   => '_give_payment_form_id',
123 123
 				'value' => $form_id,
124 124
 			);
125 125
 		}
126 126
 
127
-		if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) {
127
+		if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) {
128 128
 			$args['meta_query']['relation'] = 'AND';
129 129
 		}
130 130
 
131
-		$args = apply_filters( 'give_stats_earnings_args', $args );
132
-		$key  = Give_Cache::get_key( 'give_stats', $args );
131
+		$args = apply_filters('give_stats_earnings_args', $args);
132
+		$key  = Give_Cache::get_key('give_stats', $args);
133 133
 
134 134
 		// Set transient for faster stats.
135
-		$earnings = Give_Cache::get( $key );
135
+		$earnings = Give_Cache::get($key);
136 136
 
137
-		if ( false === $earnings ) {
137
+		if (false === $earnings) {
138 138
 
139 139
 			$this->timestamp = false;
140
-			$payments        = new Give_Payments_Query( $args );
140
+			$payments        = new Give_Payments_Query($args);
141 141
 			$payments        = $payments->get_payments();
142 142
 			$earnings        = 0;
143 143
 
144
-			if ( ! empty( $payments ) ) {
145
-				foreach ( $payments as $payment ) {
146
-					$earnings += (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) );
144
+			if ( ! empty($payments)) {
145
+				foreach ($payments as $payment) {
146
+					$earnings += (float) give_donation_amount($payment->ID, array('type' => 'stats'));
147 147
 				}
148 148
 
149 149
 			}
150 150
 
151 151
 			// Cache the results for one hour.
152
-			Give_Cache::set( $key, give_sanitize_amount_for_db( $earnings ), 60 * 60 );
152
+			Give_Cache::set($key, give_sanitize_amount_for_db($earnings), 60 * 60);
153 153
 		}
154 154
 
155 155
 		/**
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 		 * @param  string|bool $end_date   Earning end date.
164 164
 		 * @param  string|bool $gateway_id Payment gateway id.
165 165
 		 */
166
-		$earnings = apply_filters( 'give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id );
166
+		$earnings = apply_filters('give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id);
167 167
 
168 168
 		//return earnings
169
-		return round( $earnings, give_get_price_decimals( $form_id ) );
169
+		return round($earnings, give_get_price_decimals($form_id));
170 170
 
171 171
 	}
172 172
 
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return float|int                Total amount of donations based on the passed arguments.
185 185
 	 */
186
-	public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) {
186
+	public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) {
187 187
 
188
-		$this->setup_dates( $start_date, $end_date );
188
+		$this->setup_dates($start_date, $end_date);
189 189
 
190 190
 		// Make sure start date is valid
191
-		if ( is_wp_error( $this->start_date ) ) {
191
+		if (is_wp_error($this->start_date)) {
192 192
 			return $this->start_date;
193 193
 		}
194 194
 
195 195
 		// Make sure end date is valid
196
-		if ( is_wp_error( $this->end_date ) ) {
196
+		if (is_wp_error($this->end_date)) {
197 197
 			return $this->end_date;
198 198
 		}
199 199
 
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
 			'start_date' => $this->start_date,
204 204
 			'end_date'   => $this->end_date,
205 205
 			'fields'     => 'ids',
206
-			'number'     => - 1,
206
+			'number'     => -1,
207 207
 		);
208 208
 
209 209
 
210 210
 		// Filter by Gateway ID meta_key
211
-		if ( $gateway_id ) {
211
+		if ($gateway_id) {
212 212
 			$args['meta_query'][] = array(
213 213
 				'key'   => '_give_payment_gateway',
214 214
 				'value' => $gateway_id,
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 		}
217 217
 
218 218
 		// Filter by Gateway ID meta_key
219
-		if ( $form_id ) {
219
+		if ($form_id) {
220 220
 			$args['meta_query'][] = array(
221 221
 				'key'   => '_give_payment_form_id',
222 222
 				'value' => $form_id,
223 223
 			);
224 224
 		}
225 225
 
226
-		if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) {
226
+		if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) {
227 227
 			$args['meta_query']['relation'] = 'AND';
228 228
 		}
229 229
 
230
-		$args = apply_filters( 'give_stats_earnings_args', $args );
231
-		$key  = Give_Cache::get_key( 'give_stats', $args );
230
+		$args = apply_filters('give_stats_earnings_args', $args);
231
+		$key  = Give_Cache::get_key('give_stats', $args);
232 232
 
233 233
 		//return earnings
234 234
 		return $key;
@@ -246,17 +246,17 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @return array       Best selling forms
248 248
 	 */
249
-	public function get_best_selling( $number = 10 ) {
249
+	public function get_best_selling($number = 10) {
250 250
 		global $wpdb;
251 251
 
252
-		$meta_table = __give_v20_bc_table_details( 'form' );
252
+		$meta_table = __give_v20_bc_table_details('form');
253 253
 
254
-		$give_forms = $wpdb->get_results( $wpdb->prepare(
254
+		$give_forms = $wpdb->get_results($wpdb->prepare(
255 255
 			"SELECT {$meta_table['column']['id']} as form_id, max(meta_value) as sales
256 256
 				FROM {$meta_table['name']} WHERE meta_key='_give_form_sales' AND meta_value > 0
257 257
 				GROUP BY meta_value+0
258 258
 				DESC LIMIT %d;", $number
259
-		) );
259
+		));
260 260
 
261 261
 		return $give_forms;
262 262
 	}
Please login to merge, or discard this patch.
includes/gateways/offline-donations.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -249,10 +249,10 @@
 block discarded – undo
249 249
 	$admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
250 250
 
251 251
 	$admin_message .= sprintf(
252
-		                  '<a href="%1$s">%2$s</a>',
253
-		                  admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
254
-		                  __( 'View Donation Details &raquo;', 'give' )
255
-	                  ) . "\n\n";
252
+						  '<a href="%1$s">%2$s</a>',
253
+						  admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
254
+						  __( 'View Donation Details &raquo;', 'give' )
255
+					  ) . "\n\n";
256 256
 
257 257
 	$admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
258 258
 	$admin_message = give_do_email_tags( $admin_message, $payment_id );
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -18,17 +18,17 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @return array
20 20
  */
21
-function give_offline_register_gateway( $gateways ) {
21
+function give_offline_register_gateway($gateways) {
22 22
 	// Format: ID => Name
23 23
 	$gateways['offline'] = array(
24
-		'admin_label'    => esc_attr__( 'Offline Donation', 'give' ),
25
-		'checkout_label' => esc_attr__( 'Offline Donation', 'give' ),
24
+		'admin_label'    => esc_attr__('Offline Donation', 'give'),
25
+		'checkout_label' => esc_attr__('Offline Donation', 'give'),
26 26
 	);
27 27
 
28 28
 	return $gateways;
29 29
 }
30 30
 
31
-add_filter( 'give_payment_gateways', 'give_offline_register_gateway', 1 );
31
+add_filter('give_payment_gateways', 'give_offline_register_gateway', 1);
32 32
 
33 33
 
34 34
 /**
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
  *
41 41
  * @return void
42 42
  */
43
-function give_offline_payment_cc_form( $form_id ) {
43
+function give_offline_payment_cc_form($form_id) {
44 44
 	// Get offline payment instruction.
45
-	$offline_instructions = give_get_offline_payment_instruction( $form_id, true );
45
+	$offline_instructions = give_get_offline_payment_instruction($form_id, true);
46 46
 
47 47
 	ob_start();
48 48
 
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param int $form_id Give form id.
55 55
 	 */
56
-	do_action( 'give_before_offline_info_fields', $form_id );
56
+	do_action('give_before_offline_info_fields', $form_id);
57 57
 	?>
58 58
     <fieldset id="give_offline_payment_info">
59
-		<?php echo stripslashes( $offline_instructions ); ?>
59
+		<?php echo stripslashes($offline_instructions); ?>
60 60
     </fieldset>
61 61
 	<?php
62 62
 	/**
@@ -66,35 +66,35 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @param int $form_id Give form id.
68 68
 	 */
69
-	do_action( 'give_after_offline_info_fields', $form_id );
69
+	do_action('give_after_offline_info_fields', $form_id);
70 70
 
71 71
 	echo ob_get_clean();
72 72
 }
73 73
 
74
-add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' );
74
+add_action('give_offline_cc_form', 'give_offline_payment_cc_form');
75 75
 
76 76
 /**
77 77
  * Give Offline Billing Field
78 78
  *
79 79
  * @param $form_id
80 80
  */
81
-function give_offline_billing_fields( $form_id ) {
81
+function give_offline_billing_fields($form_id) {
82 82
 	//Enable Default CC fields (billing info)
83
-	$post_offline_cc_fields        = give_get_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true );
84
-	$post_offline_customize_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
83
+	$post_offline_cc_fields        = give_get_meta($form_id, '_give_offline_donation_enable_billing_fields_single', true);
84
+	$post_offline_customize_option = give_get_meta($form_id, '_give_customize_offline_donations', true);
85 85
 
86
-	$global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' );
86
+	$global_offline_cc_fields = give_get_option('give_offline_donation_enable_billing_fields');
87 87
 
88 88
 	//Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options
89 89
 	if (
90
-		( give_is_setting_enabled( $post_offline_customize_option, 'global' ) && give_is_setting_enabled( $global_offline_cc_fields ) )
91
-		|| ( give_is_setting_enabled( $post_offline_customize_option, 'enabled' ) && give_is_setting_enabled( $post_offline_cc_fields ) )
90
+		(give_is_setting_enabled($post_offline_customize_option, 'global') && give_is_setting_enabled($global_offline_cc_fields))
91
+		|| (give_is_setting_enabled($post_offline_customize_option, 'enabled') && give_is_setting_enabled($post_offline_cc_fields))
92 92
 	) {
93
-		give_default_cc_address_fields( $form_id );
93
+		give_default_cc_address_fields($form_id);
94 94
 	}
95 95
 }
96 96
 
97
-add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 );
97
+add_action('give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1);
98 98
 
99 99
 /**
100 100
  * Process the payment
@@ -105,18 +105,18 @@  discard block
 block discarded – undo
105 105
  *
106 106
  * @return void
107 107
  */
108
-function give_offline_process_payment( $purchase_data ) {
108
+function give_offline_process_payment($purchase_data) {
109 109
 
110 110
 	// Setup the payment details.
111 111
 	$payment_data = array(
112 112
 		'price'           => $purchase_data['price'],
113 113
 		'give_form_title' => $purchase_data['post_data']['give-form-title'],
114
-		'give_form_id'    => intval( $purchase_data['post_data']['give-form-id'] ),
115
-		'give_price_id'   => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '',
114
+		'give_form_id'    => intval($purchase_data['post_data']['give-form-id']),
115
+		'give_price_id'   => isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '',
116 116
 		'date'            => $purchase_data['date'],
117 117
 		'user_email'      => $purchase_data['user_email'],
118 118
 		'purchase_key'    => $purchase_data['purchase_key'],
119
-		'currency'        => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ),
119
+		'currency'        => give_get_currency($purchase_data['post_data']['give-form-id'], $purchase_data),
120 120
 		'user_info'       => $purchase_data['user_info'],
121 121
 		'status'          => 'pending',
122 122
 		'gateway'         => 'offline',
@@ -124,18 +124,18 @@  discard block
 block discarded – undo
124 124
 
125 125
 
126 126
 	// record the pending payment
127
-	$payment = give_insert_payment( $payment_data );
127
+	$payment = give_insert_payment($payment_data);
128 128
 
129
-	if ( $payment ) {
129
+	if ($payment) {
130 130
 		give_send_to_success_page();
131 131
 	} else {
132 132
 		// if errors are present, send the user back to the donation form so they can be corrected
133
-		give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
133
+		give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']);
134 134
 	}
135 135
 
136 136
 }
137 137
 
138
-add_action( 'give_gateway_offline', 'give_offline_process_payment' );
138
+add_action('give_gateway_offline', 'give_offline_process_payment');
139 139
 
140 140
 
141 141
 /**
@@ -148,59 +148,59 @@  discard block
 block discarded – undo
148 148
  * @since       1.0
149 149
  * @return void
150 150
  */
151
-function give_offline_send_donor_instructions( $payment_id = 0 ) {
151
+function give_offline_send_donor_instructions($payment_id = 0) {
152 152
 
153
-	$payment_data                      = give_get_payment_meta( $payment_id );
154
-	$post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );
153
+	$payment_data                      = give_get_payment_meta($payment_id);
154
+	$post_offline_customization_option = give_get_meta($payment_data['form_id'], '_give_customize_offline_donations', true);
155 155
 
156 156
 	//Customize email content depending on whether the single form has been customized
157
-	$email_content = give_get_option( 'global_offline_donation_email' );
157
+	$email_content = give_get_option('global_offline_donation_email');
158 158
 
159
-	if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
160
-		$email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
159
+	if (give_is_setting_enabled($post_offline_customization_option, 'enabled')) {
160
+		$email_content = give_get_meta($payment_data['form_id'], '_give_offline_donation_email', true);
161 161
 	}
162 162
 
163
-	$from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
163
+	$from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
164 164
 
165 165
 	/**
166 166
 	 * Filters the from name.
167 167
 	 *
168 168
 	 * @since 1.7
169 169
 	 */
170
-	$from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data );
170
+	$from_name = apply_filters('give_donation_from_name', $from_name, $payment_id, $payment_data);
171 171
 
172
-	$from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
172
+	$from_email = give_get_option('from_email', get_bloginfo('admin_email'));
173 173
 
174 174
 	/**
175 175
 	 * Filters the from email.
176 176
 	 *
177 177
 	 * @since 1.7
178 178
 	 */
179
-	$from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data );
179
+	$from_email = apply_filters('give_donation_from_address', $from_email, $payment_id, $payment_data);
180 180
 
181
-	$to_email = give_get_payment_user_email( $payment_id );
181
+	$to_email = give_get_payment_user_email($payment_id);
182 182
 
183
-	$subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) );
184
-	if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
185
-		$subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true );
183
+	$subject = give_get_option('offline_donation_subject', __('Offline Donation Instructions', 'give'));
184
+	if (give_is_setting_enabled($post_offline_customization_option, 'enabled')) {
185
+		$subject = give_get_meta($payment_data['form_id'], '_give_offline_donation_subject', true);
186 186
 	}
187 187
 
188
-	$subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id );
189
-	$subject = give_do_email_tags( $subject, $payment_id );
188
+	$subject = apply_filters('give_offline_donation_subject', wp_strip_all_tags($subject), $payment_id);
189
+	$subject = give_do_email_tags($subject, $payment_id);
190 190
 
191
-	$attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data );
192
-	$message     = give_do_email_tags( $email_content, $payment_id );
191
+	$attachments = apply_filters('give_offline_donation_attachments', array(), $payment_id, $payment_data);
192
+	$message     = give_do_email_tags($email_content, $payment_id);
193 193
 
194 194
 	$emails = Give()->emails;
195 195
 
196
-	$emails->__set( 'from_name', $from_name );
197
-	$emails->__set( 'from_email', $from_email );
198
-	$emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
196
+	$emails->__set('from_name', $from_name);
197
+	$emails->__set('from_email', $from_email);
198
+	$emails->__set('heading', __('Offline Donation Instructions', 'give'));
199 199
 
200
-	$headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data );
201
-	$emails->__set( 'headers', $headers );
200
+	$headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data);
201
+	$emails->__set('headers', $headers);
202 202
 
203
-	$emails->send( $to_email, $subject, $message, $attachments );
203
+	$emails->send($to_email, $subject, $message, $attachments);
204 204
 
205 205
 }
206 206
 
@@ -217,54 +217,54 @@  discard block
 block discarded – undo
217 217
  * @return void
218 218
  *
219 219
  */
220
-function give_offline_send_admin_notice( $payment_id = 0 ) {
220
+function give_offline_send_admin_notice($payment_id = 0) {
221 221
 
222 222
 	/* Send an email notification to the admin */
223 223
 	$admin_email = give_get_admin_notice_emails();
224
-	$user_info   = give_get_payment_meta_user_info( $payment_id );
224
+	$user_info   = give_get_payment_meta_user_info($payment_id);
225 225
 
226
-	if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
227
-		$user_data = get_userdata( $user_info['id'] );
226
+	if (isset($user_info['id']) && $user_info['id'] > 0) {
227
+		$user_data = get_userdata($user_info['id']);
228 228
 		$name      = $user_data->display_name;
229
-	} elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
230
-		$name = $user_info['first_name'] . ' ' . $user_info['last_name'];
229
+	} elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
230
+		$name = $user_info['first_name'].' '.$user_info['last_name'];
231 231
 	} else {
232 232
 		$name = $user_info['email'];
233 233
 	}
234 234
 
235
-	$amount = give_donation_amount( $payment_id );
235
+	$amount = give_donation_amount($payment_id);
236 236
 
237
-	$admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id );
237
+	$admin_subject = apply_filters('give_offline_admin_donation_notification_subject', __('New Pending Donation', 'give'), $payment_id);
238 238
 
239
-	$admin_message = __( 'Dear Admin,', 'give' ) . "\n\n";
240
-	$admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n";
241
-	$admin_message .= __( 'The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n";
239
+	$admin_message = __('Dear Admin,', 'give')."\n\n";
240
+	$admin_message .= sprintf(__('A new offline donation has been made on your website for %s.', 'give'), $amount)."\n\n";
241
+	$admin_message .= __('The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give')."\n\n";
242 242
 
243 243
 
244
-	$admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
245
-	$admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
244
+	$admin_message .= '<strong>'.__('Donor:', 'give').'</strong> {fullname}'."\n";
245
+	$admin_message .= '<strong>'.__('Amount:', 'give').'</strong> {amount}'."\n\n";
246 246
 
247 247
 	$admin_message .= sprintf(
248 248
 		                  '<a href="%1$s">%2$s</a>',
249
-		                  admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
250
-		                  __( 'View Donation Details &raquo;', 'give' )
251
-	                  ) . "\n\n";
249
+		                  admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id='.$payment_id),
250
+		                  __('View Donation Details &raquo;', 'give')
251
+	                  )."\n\n";
252 252
 
253
-	$admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
254
-	$admin_message = give_do_email_tags( $admin_message, $payment_id );
253
+	$admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id);
254
+	$admin_message = give_do_email_tags($admin_message, $payment_id);
255 255
 
256
-	$attachments   = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id );
257
-	$admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id );
256
+	$attachments   = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id);
257
+	$admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id);
258 258
 
259 259
 	//Send Email
260 260
 	$emails = Give()->emails;
261
-	$emails->__set( 'heading', __( 'New Offline Donation', 'give' ) );
261
+	$emails->__set('heading', __('New Offline Donation', 'give'));
262 262
 
263
-	if ( ! empty( $admin_headers ) ) {
264
-		$emails->__set( 'headers', $admin_headers );
263
+	if ( ! empty($admin_headers)) {
264
+		$emails->__set('headers', $admin_headers);
265 265
 	}
266 266
 
267
-	$emails->send( $admin_email, $admin_subject, $admin_message, $attachments );
267
+	$emails->send($admin_email, $admin_subject, $admin_message, $attachments);
268 268
 
269 269
 }
270 270
 
@@ -277,20 +277,20 @@  discard block
 block discarded – undo
277 277
  *
278 278
  * @return array
279 279
  */
280
-function give_offline_add_settings( $settings ) {
280
+function give_offline_add_settings($settings) {
281 281
 
282 282
 	// Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
283
-	if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) {
283
+	if (in_array('offline', (array) give_get_option('gateways'))) {
284 284
 		return $settings;
285 285
 	}
286 286
 
287 287
 	//Vars
288 288
 	$prefix = '_give_';
289 289
 
290
-	$is_gateway_active = give_is_gateway_active( 'offline' );
290
+	$is_gateway_active = give_is_gateway_active('offline');
291 291
 
292 292
 	//this gateway isn't active
293
-	if ( ! $is_gateway_active ) {
293
+	if ( ! $is_gateway_active) {
294 294
 		//return settings and bounce
295 295
 		return $settings;
296 296
 	}
@@ -299,34 +299,34 @@  discard block
 block discarded – undo
299 299
 	$check_settings = array(
300 300
 
301 301
 		array(
302
-			'name'    => __( 'Offline Donations', 'give' ),
303
-			'desc'    => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
304
-			'id'      => $prefix . 'customize_offline_donations',
302
+			'name'    => __('Offline Donations', 'give'),
303
+			'desc'    => __('Do you want to customize the donation instructions for this form?', 'give'),
304
+			'id'      => $prefix.'customize_offline_donations',
305 305
 			'type'    => 'radio_inline',
306 306
 			'default' => 'global',
307
-			'options' => apply_filters( 'give_forms_content_options_select', array(
308
-					'global'   => __( 'Global Option', 'give' ),
309
-					'enabled'  => __( 'Customize', 'give' ),
310
-					'disabled' => __( 'Disable', 'give' ),
307
+			'options' => apply_filters('give_forms_content_options_select', array(
308
+					'global'   => __('Global Option', 'give'),
309
+					'enabled'  => __('Customize', 'give'),
310
+					'disabled' => __('Disable', 'give'),
311 311
 				)
312 312
 			),
313 313
 		),
314 314
 		array(
315
-			'name'        => __( 'Billing Fields', 'give' ),
316
-			'desc'        => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
317
-			'id'          => $prefix . 'offline_donation_enable_billing_fields_single',
315
+			'name'        => __('Billing Fields', 'give'),
316
+			'desc'        => __('This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give'),
317
+			'id'          => $prefix.'offline_donation_enable_billing_fields_single',
318 318
 			'row_classes' => 'give-subfield give-hidden',
319 319
 			'type'        => 'radio_inline',
320 320
 			'default'     => 'disabled',
321 321
 			'options'     => array(
322
-				'enabled'  => __( 'Enabled', 'give' ),
323
-				'disabled' => __( 'Disabled', 'give' ),
322
+				'enabled'  => __('Enabled', 'give'),
323
+				'disabled' => __('Disabled', 'give'),
324 324
 			),
325 325
 		),
326 326
 		array(
327
-			'id'          => $prefix . 'offline_checkout_notes',
328
-			'name'        => __( 'Donation Instructions', 'give' ),
329
-			'desc'        => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
327
+			'id'          => $prefix.'offline_checkout_notes',
328
+			'name'        => __('Donation Instructions', 'give'),
329
+			'desc'        => __('Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give'),
330 330
 			'default'     => give_get_default_offline_donation_content(),
331 331
 			'type'        => 'wysiwyg',
332 332
 			'row_classes' => 'give-subfield give-hidden',
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
 			'name'  => 'offline_docs',
339 339
 			'type'  => 'docs_link',
340 340
 			'url'   => 'http://docs.givewp.com/settings-gateway-offline-donations',
341
-			'title' => __( 'Offline Donations', 'give' ),
341
+			'title' => __('Offline Donations', 'give'),
342 342
 		),
343 343
 	);
344 344
 
345
-	return array_merge( $settings, $check_settings );
345
+	return array_merge($settings, $check_settings);
346 346
 }
347 347
 
348
-add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
348
+add_filter('give_forms_offline_donations_metabox_fields', 'give_offline_add_settings');
349 349
 
350 350
 
351 351
 /**
@@ -357,32 +357,32 @@  discard block
 block discarded – undo
357 357
  */
358 358
 function give_get_default_offline_donation_content() {
359 359
 
360
-	$sitename = get_bloginfo( 'sitename' );
360
+	$sitename = get_bloginfo('sitename');
361 361
 
362
-	$default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>';
362
+	$default_text = '<p>'.__('In order to make an offline donation we ask that you please follow these instructions', 'give').': </p>';
363 363
 	$default_text .= '<ol>';
364 364
 	$default_text .= '<li>';
365 365
 	$default_text .= sprintf(
366 366
 	/* translators: %s: site name */
367
-		__( 'Make a check payable to "%s"', 'give' ),
367
+		__('Make a check payable to "%s"', 'give'),
368 368
 		$sitename
369 369
 	);
370 370
 	$default_text .= '</li>';
371 371
 	$default_text .= '<li>';
372 372
 	$default_text .= sprintf(
373 373
 	/* translators: %s: site name */
374
-		__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
374
+		__('On the memo line of the check, please indicate that the donation is for "%s"', 'give'),
375 375
 		$sitename
376 376
 	);
377 377
 	$default_text .= '</li>';
378
-	$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
378
+	$default_text .= '<li>'.__('Please mail your check to:', 'give').'</li>';
379 379
 	$default_text .= '</ol>';
380
-	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
380
+	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>'.$sitename.'</em><br>';
381 381
 	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
382 382
 	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
383
-	$default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>';
383
+	$default_text .= '<p>'.__('All contributions will be gratefully acknowledged and are tax deductible.', 'give').'</p>';
384 384
 
385
-	return apply_filters( 'give_default_offline_donation_content', $default_text );
385
+	return apply_filters('give_default_offline_donation_content', $default_text);
386 386
 
387 387
 }
388 388
 
@@ -395,34 +395,34 @@  discard block
 block discarded – undo
395 395
  */
396 396
 function give_get_default_offline_donation_email_content() {
397 397
 
398
-	$sitename     = get_bloginfo( 'sitename' );
399
-	$default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>';
400
-	$default_text .= '<p>' . __( 'Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give' ) . '</p>';
398
+	$sitename     = get_bloginfo('sitename');
399
+	$default_text = '<p>'.__('Dear {name},', 'give').'</p>';
400
+	$default_text .= '<p>'.__('Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give').'</p>';
401 401
 	$default_text .= '<ol>';
402 402
 	$default_text .= '<li>';
403 403
 	$default_text .= sprintf(
404 404
 	/* translators: %s: site name */
405
-		__( 'Make a check payable to "%s"', 'give' ),
405
+		__('Make a check payable to "%s"', 'give'),
406 406
 		$sitename
407 407
 	);
408 408
 	$default_text .= '</li>';
409 409
 	$default_text .= '<li>';
410 410
 	$default_text .= sprintf(
411 411
 	/* translators: %s: site name */
412
-		__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
412
+		__('On the memo line of the check, please indicate that the donation is for "%s"', 'give'),
413 413
 		$sitename
414 414
 	);
415 415
 	$default_text .= '</li>';
416
-	$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
416
+	$default_text .= '<li>'.__('Please mail your check to:', 'give').'</li>';
417 417
 	$default_text .= '</ol>';
418
-	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
418
+	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>'.$sitename.'</em><br>';
419 419
 	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
420 420
 	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
421
-	$default_text .= '<p>' . __( 'Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>';
422
-	$default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>';
423
-	$default_text .= '<p>' . $sitename . '</p>';
421
+	$default_text .= '<p>'.__('Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give').'</p>';
422
+	$default_text .= '<p>'.__('Sincerely,', 'give').'</p>';
423
+	$default_text .= '<p>'.$sitename.'</p>';
424 424
 
425
-	return apply_filters( 'give_default_offline_donation_content', $default_text );
425
+	return apply_filters('give_default_offline_donation_content', $default_text);
426 426
 
427 427
 }
428 428
 
@@ -436,17 +436,17 @@  discard block
 block discarded – undo
436 436
  *
437 437
  * @return string
438 438
  */
439
-function give_offline_donation_receipt_status_notice( $notice, $id ) {
440
-	$payment = new Give_Payment( $id );
439
+function give_offline_donation_receipt_status_notice($notice, $id) {
440
+	$payment = new Give_Payment($id);
441 441
 
442
-	if ( 'offline' !== $payment->gateway || $payment->is_completed() ) {
442
+	if ('offline' !== $payment->gateway || $payment->is_completed()) {
443 443
 		return $notice;
444 444
 	}
445 445
 
446
-	return Give()->notices->print_frontend_notice( __( 'Payment Pending: Please follow the instructions below to complete your donation.', 'give' ), false, 'warning' );
446
+	return Give()->notices->print_frontend_notice(__('Payment Pending: Please follow the instructions below to complete your donation.', 'give'), false, 'warning');
447 447
 }
448 448
 
449
-add_filter( 'give_receipt_status_notice', 'give_offline_donation_receipt_status_notice', 10, 2 );
449
+add_filter('give_receipt_status_notice', 'give_offline_donation_receipt_status_notice', 10, 2);
450 450
 
451 451
 /**
452 452
  * Get offline payment instructions.
@@ -458,27 +458,27 @@  discard block
 block discarded – undo
458 458
  *
459 459
  * @return string
460 460
  */
461
-function give_get_offline_payment_instruction( $form_id, $wpautop = false ) {
461
+function give_get_offline_payment_instruction($form_id, $wpautop = false) {
462 462
 	// Bailout.
463
-	if ( ! $form_id ) {
463
+	if ( ! $form_id) {
464 464
 		return '';
465 465
 	}
466 466
 
467
-	$post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
468
-	$post_offline_instructions         = give_get_meta( $form_id, '_give_offline_checkout_notes', true );
469
-	$global_offline_instruction        = give_get_option( 'global_offline_donation_content' );
467
+	$post_offline_customization_option = give_get_meta($form_id, '_give_customize_offline_donations', true);
468
+	$post_offline_instructions         = give_get_meta($form_id, '_give_offline_checkout_notes', true);
469
+	$global_offline_instruction        = give_get_option('global_offline_donation_content');
470 470
 	$offline_instructions              = $global_offline_instruction;
471 471
 
472
-	if ( give_is_setting_enabled( $post_offline_customization_option ) ) {
472
+	if (give_is_setting_enabled($post_offline_customization_option)) {
473 473
 		$offline_instructions = $post_offline_instructions;
474 474
 	}
475 475
 
476
-	$settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' );
476
+	$settings_url = admin_url('post.php?post='.$form_id.'&action=edit&message=1');
477 477
 
478 478
 	/* translators: %s: form settings url */
479
-	$offline_instructions = ! empty( $offline_instructions ) ? $offline_instructions : sprintf( __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), $settings_url );
479
+	$offline_instructions = ! empty($offline_instructions) ? $offline_instructions : sprintf(__('Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give'), $settings_url);
480 480
 
481
-	return ( $wpautop ? wpautop( $offline_instructions ) : $offline_instructions );
481
+	return ($wpautop ? wpautop($offline_instructions) : $offline_instructions);
482 482
 }
483 483
 
484 484
 
@@ -492,21 +492,21 @@  discard block
 block discarded – undo
492 492
  *
493 493
  * @return array
494 494
  */
495
-function give_filter_offline_gateway( $gateway_list, $form_id ) {
495
+function give_filter_offline_gateway($gateway_list, $form_id) {
496 496
 	if (
497 497
 		// Show offline payment gateway if enable for new donation form.
498
-		( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) )
498
+		(false === strpos($_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms'))
499 499
 		&& $form_id
500
-		&& ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true ), array( 'enabled', 'global' ) )
500
+		&& ! give_is_setting_enabled(give_get_meta($form_id, '_give_customize_offline_donations', true), array('enabled', 'global'))
501 501
 	) {
502
-		unset( $gateway_list['offline'] );
502
+		unset($gateway_list['offline']);
503 503
 	}
504 504
 
505 505
 	// Output.
506 506
 	return $gateway_list;
507 507
 }
508 508
 
509
-add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 );
509
+add_filter('give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2);
510 510
 
511 511
 /**
512 512
  * Set default gateway to global default payment gateway
@@ -520,13 +520,13 @@  discard block
 block discarded – undo
520 520
  *
521 521
  * @return void
522 522
  */
523
-function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) {
523
+function _give_customize_offline_donations_on_save_callback($meta_key, $meta_value, $postid) {
524 524
 	if (
525
-		! give_is_setting_enabled( $meta_value, array( 'global', 'enabled' ) )
526
-		&& ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) )
525
+		! give_is_setting_enabled($meta_value, array('global', 'enabled'))
526
+		&& ('offline' === give_get_meta($postid, '_give_default_gateway', true))
527 527
 	) {
528
-		give_update_meta( $postid, '_give_default_gateway', 'global' );
528
+		give_update_meta($postid, '_give_default_gateway', 'global');
529 529
 	}
530 530
 }
531 531
 
532
-add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 );
532
+add_filter('give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3);
Please login to merge, or discard this patch.
includes/admin/tools/export/export-functions.php 1 patch
Spacing   +27 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
  */
26 26
 function give_do_ajax_export() {
27 27
 
28
-	require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export.php';
28
+	require_once GIVE_PLUGIN_DIR.'includes/admin/tools/export/class-batch-export.php';
29 29
 
30
-	parse_str( $_POST['form'], $form );
30
+	parse_str($_POST['form'], $form);
31 31
 
32 32
 	$_REQUEST = $form = (array) $form;
33 33
 
34
-	if ( ! wp_verify_nonce( $_REQUEST['give_ajax_export'], 'give_ajax_export' ) ) {
35
-		die( '-2' );
34
+	if ( ! wp_verify_nonce($_REQUEST['give_ajax_export'], 'give_ajax_export')) {
35
+		die('-2');
36 36
 	}
37 37
 
38 38
 	/**
@@ -42,28 +42,28 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param string $class Export class.
44 44
 	 */
45
-	do_action( 'give_batch_export_class_include', $form['give-export-class'] );
45
+	do_action('give_batch_export_class_include', $form['give-export-class']);
46 46
 
47
-	$step   = absint( $_POST['step'] );
48
-	$class  = sanitize_text_field( $form['give-export-class'] );
47
+	$step   = absint($_POST['step']);
48
+	$class  = sanitize_text_field($form['give-export-class']);
49 49
 
50 50
 	/* @var Give_Batch_Export $export */
51
-	$export = new $class( $step );
51
+	$export = new $class($step);
52 52
 
53
-	if ( ! $export->can_export() ) {
54
-		die( '-1' );
53
+	if ( ! $export->can_export()) {
54
+		die('-1');
55 55
 	}
56 56
 
57
-	if ( ! $export->is_writable ) {
57
+	if ( ! $export->is_writable) {
58 58
 		$json_args = array(
59 59
 			'error'   => true,
60
-			'message' => esc_html__( 'Export location or file not writable.', 'give' )
60
+			'message' => esc_html__('Export location or file not writable.', 'give')
61 61
 		);
62 62
 		echo json_encode($json_args);
63 63
 		exit;
64 64
 	}
65 65
 
66
-	$export->set_properties( give_clean( $_REQUEST ) );
66
+	$export->set_properties(give_clean($_REQUEST));
67 67
 
68 68
 	$export->pre_fetch();
69 69
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 
72 72
 	$percentage = $export->get_percentage_complete();
73 73
 
74
-	if ( $ret ) {
74
+	if ($ret) {
75 75
 
76 76
 		$step += 1;
77 77
 		$json_data = array(
@@ -79,18 +79,17 @@  discard block
 block discarded – undo
79 79
 			'percentage' => $percentage
80 80
 		);
81 81
 
82
-	} elseif ( true === $export->is_empty ) {
82
+	} elseif (true === $export->is_empty) {
83 83
 
84 84
 		$json_data = array(
85 85
 			'error'   => true,
86
-			'message' => esc_html__( 'No data found for export parameters.', 'give' )
86
+			'message' => esc_html__('No data found for export parameters.', 'give')
87 87
 		);
88 88
 
89
-	} elseif ( true === $export->done && true === $export->is_void ) {
89
+	} elseif (true === $export->done && true === $export->is_void) {
90 90
 
91
-		$message = ! empty( $export->message ) ?
92
-			$export->message :
93
-			esc_html__( 'Batch Processing Complete', 'give' );
91
+		$message = ! empty($export->message) ?
92
+			$export->message : esc_html__('Batch Processing Complete', 'give');
94 93
 
95 94
 		$json_data = array(
96 95
 			'success' => true,
@@ -99,23 +98,23 @@  discard block
 block discarded – undo
99 98
 
100 99
 	} else {
101 100
 		
102
-		$args = array_merge( $_REQUEST, array(
101
+		$args = array_merge($_REQUEST, array(
103 102
 			'step'        => $step,
104 103
 			'class'       => $class,
105
-			'nonce'       => wp_create_nonce( 'give-batch-export' ),
104
+			'nonce'       => wp_create_nonce('give-batch-export'),
106 105
 			'give_action' => 'form_batch_export',
107
-		) );
106
+		));
108 107
 
109 108
 		$json_data = array(
110 109
 			'step' => 'done',
111
-			'url' => add_query_arg( $args, admin_url() )
110
+			'url' => add_query_arg($args, admin_url())
112 111
 		);
113 112
 
114 113
 	}
115 114
 
116
-	$export->unset_properties( give_clean( $_REQUEST ), $export );
117
-	echo json_encode( $json_data );
115
+	$export->unset_properties(give_clean($_REQUEST), $export);
116
+	echo json_encode($json_data);
118 117
 	exit;
119 118
 }
120 119
 
121
-add_action( 'wp_ajax_give_do_ajax_export', 'give_do_ajax_export' );
120
+add_action('wp_ajax_give_do_ajax_export', 'give_do_ajax_export');
Please login to merge, or discard this patch.
includes/admin/tools/export/class-batch-export-donors.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,7 @@
 block discarded – undo
245 245
 
246 246
 					// Continue if donor already included.
247 247
 					if ( empty( $payment->customer_id ) ||
248
-					     in_array( $payment->customer_id, $cached_donor_ids )
248
+						 in_array( $payment->customer_id, $cached_donor_ids )
249 249
 					) {
250 250
 						continue;
251 251
 					}
Please login to merge, or discard this patch.
Spacing   +103 added lines, -105 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -70,23 +70,23 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @param array $request The Form Data passed into the batch processing
72 72
 	 */
73
-	public function set_properties( $request ) {
73
+	public function set_properties($request) {
74 74
 
75 75
 		// Set data from form submission
76
-		if ( isset( $_POST['form'] ) ) {
77
-			parse_str( $_POST['form'], $this->data );
76
+		if (isset($_POST['form'])) {
77
+			parse_str($_POST['form'], $this->data);
78 78
 		}
79 79
 
80 80
 		$this->form = $this->data['forms'];
81 81
 
82 82
 		// Setup donor ids cache.
83
-		if ( ! empty( $this->form ) ) {
83
+		if ( ! empty($this->form)) {
84 84
 			// Cache donor ids to output unique list of donor.
85
-			$this->query_id = give_clean( $_REQUEST['give_export_option']['query_id'] );
85
+			$this->query_id = give_clean($_REQUEST['give_export_option']['query_id']);
86 86
 			$this->cache_donor_ids();
87 87
 		}
88 88
 
89
-		$this->price_id = ! empty( $request['give_price_option'] ) && 'all' !== $request['give_price_option'] ? absint( $request['give_price_option'] ) : null;
89
+		$this->price_id = ! empty($request['give_price_option']) && 'all' !== $request['give_price_option'] ? absint($request['give_price_option']) : null;
90 90
 
91 91
 	}
92 92
 
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 		// Fetch already cached donor ids.
102 102
 		$donor_ids = $this->donor_ids;
103 103
 
104
-		if ( $cached_donor_ids = Give_Cache::get( $this->query_id, true ) ) {
105
-			$donor_ids = array_unique( array_merge( $cached_donor_ids, $this->donor_ids ) );
104
+		if ($cached_donor_ids = Give_Cache::get($this->query_id, true)) {
105
+			$donor_ids = array_unique(array_merge($cached_donor_ids, $this->donor_ids));
106 106
 		}
107 107
 
108
-		$donor_ids = array_values( $donor_ids );
109
-		Give_Cache::set( $this->query_id, $donor_ids, HOUR_IN_SECONDS, true );
108
+		$donor_ids = array_values($donor_ids);
109
+		Give_Cache::set($this->query_id, $donor_ids, HOUR_IN_SECONDS, true);
110 110
 	}
111 111
 
112 112
 	/**
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function csv_cols() {
120 120
 
121
-		$columns = isset( $this->data['give_export_option'] ) ? $this->data['give_export_option'] : array();
121
+		$columns = isset($this->data['give_export_option']) ? $this->data['give_export_option'] : array();
122 122
 
123 123
 		// We need columns.
124
-		if ( empty( $columns ) ) {
124
+		if (empty($columns)) {
125 125
 			return false;
126 126
 		}
127 127
 
128
-		$cols = $this->get_cols( $columns );
128
+		$cols = $this->get_cols($columns);
129 129
 
130 130
 		return $cols;
131 131
 	}
@@ -137,41 +137,41 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 * @return array
139 139
 	 */
140
-	private function get_cols( $columns ) {
140
+	private function get_cols($columns) {
141 141
 
142 142
 		$cols = array();
143 143
 
144
-		foreach ( $columns as $key => $value ) {
144
+		foreach ($columns as $key => $value) {
145 145
 
146
-			switch ( $key ) {
146
+			switch ($key) {
147 147
 				case 'full_name' :
148
-					$cols['full_name'] = esc_html__( 'Full Name', 'give' );
148
+					$cols['full_name'] = esc_html__('Full Name', 'give');
149 149
 					break;
150 150
 				case 'email' :
151
-					$cols['email'] = esc_html__( 'Email Address', 'give' );
151
+					$cols['email'] = esc_html__('Email Address', 'give');
152 152
 					break;
153 153
 				case 'address' :
154
-					$cols['address_line1']   = esc_html__( 'Address', 'give' );
155
-					$cols['address_line2']   = esc_html__( 'Address 2', 'give' );
156
-					$cols['address_city']    = esc_html__( 'City', 'give' );
157
-					$cols['address_state']   = esc_html__( 'State', 'give' );
158
-					$cols['address_zip']     = esc_html__( 'Zip', 'give' );
159
-					$cols['address_country'] = esc_html__( 'Country', 'give' );
154
+					$cols['address_line1']   = esc_html__('Address', 'give');
155
+					$cols['address_line2']   = esc_html__('Address 2', 'give');
156
+					$cols['address_city']    = esc_html__('City', 'give');
157
+					$cols['address_state']   = esc_html__('State', 'give');
158
+					$cols['address_zip']     = esc_html__('Zip', 'give');
159
+					$cols['address_country'] = esc_html__('Country', 'give');
160 160
 					break;
161 161
 				case 'userid' :
162
-					$cols['userid'] = esc_html__( 'User ID', 'give' );
162
+					$cols['userid'] = esc_html__('User ID', 'give');
163 163
 					break;
164 164
 				case 'donation_form' :
165
-					$cols['donation_form'] = esc_html__( 'Donation Form', 'give' );
165
+					$cols['donation_form'] = esc_html__('Donation Form', 'give');
166 166
 					break;
167 167
 				case 'date_first_donated' :
168
-					$cols['date_first_donated'] = esc_html__( 'First Donation Date', 'give' );
168
+					$cols['date_first_donated'] = esc_html__('First Donation Date', 'give');
169 169
 					break;
170 170
 				case 'donations' :
171
-					$cols['donations'] = esc_html__( 'Number of Donations', 'give' );
171
+					$cols['donations'] = esc_html__('Number of Donations', 'give');
172 172
 					break;
173 173
 				case 'donation_sum' :
174
-					$cols['donation_sum'] = esc_html__( 'Sum of Donations', 'give' );
174
+					$cols['donation_sum'] = esc_html__('Sum of Donations', 'give');
175 175
 					break;
176 176
 			}
177 177
 		}
@@ -192,29 +192,29 @@  discard block
 block discarded – undo
192 192
 		$i = 0;
193 193
 
194 194
 		$data             = array();
195
-		$cached_donor_ids = Give_Cache::get( $this->query_id, true );
195
+		$cached_donor_ids = Give_Cache::get($this->query_id, true);
196 196
 
197
-		if ( ! empty( $this->form ) ) {
197
+		if ( ! empty($this->form)) {
198 198
 
199 199
 			// Export donors for a specific donation form and also within specified timeframe
200 200
 			$args = array(
201 201
 				'output'     => 'payments', // Use 'posts' to get standard post objects
202
-				'post_type'  => array( 'give_payment' ),
202
+				'post_type'  => array('give_payment'),
203 203
 				'number'     => 30,
204 204
 				'paged'      => $this->step,
205 205
 				'status'     => 'publish',
206 206
 				'meta_key'   => '_give_payment_form_id',
207
-				'meta_value' => absint( $this->form ),
207
+				'meta_value' => absint($this->form),
208 208
 			);
209 209
 
210 210
 			// Check for date option filter
211
-			if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) {
212
-				$args['start_date'] = ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' );
213
-				$args['end_date']   = ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) );
211
+			if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) {
212
+				$args['start_date'] = ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00');
213
+				$args['end_date']   = ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp'));
214 214
 			}
215 215
 
216 216
 			// Check for price option.
217
-			if ( null !== $this->price_id ) {
217
+			if (null !== $this->price_id) {
218 218
 				$args['meta_query'] = array(
219 219
 					array(
220 220
 						'key'   => '_give_payment_price_id',
@@ -223,45 +223,43 @@  discard block
 block discarded – undo
223 223
 				);
224 224
 			}
225 225
 
226
-			$payments_query = new Give_Payments_Query( $args );
226
+			$payments_query = new Give_Payments_Query($args);
227 227
 			$payments       = $payments_query->get_payments();
228 228
 
229
-			if ( $payments ) {
229
+			if ($payments) {
230 230
 				/* @var Give_Payment $payment */
231
-				foreach ( $payments as $payment ) {
231
+				foreach ($payments as $payment) {
232 232
 					// Set donation sum.
233
-					$this->payment_stats[ $payment->customer_id ]['donation_sum'] = isset( $this->payment_stats[ $payment->customer_id ]['donation_sum'] ) ?
234
-						$this->payment_stats[ $payment->customer_id ]['donation_sum'] :
235
-						0;
236
-					$this->payment_stats[ $payment->customer_id ]['donation_sum'] += $payment->total;
233
+					$this->payment_stats[$payment->customer_id]['donation_sum'] = isset($this->payment_stats[$payment->customer_id]['donation_sum']) ?
234
+						$this->payment_stats[$payment->customer_id]['donation_sum'] : 0;
235
+					$this->payment_stats[$payment->customer_id]['donation_sum'] += $payment->total;
237 236
 
238 237
 					// Set donation count.
239
-					$this->payment_stats[ $payment->customer_id ]['donations'] = isset( $this->payment_stats[ $payment->customer_id ]['donations'] ) ?
240
-						++ $this->payment_stats[ $payment->customer_id ]['donations'] :
241
-						1;
238
+					$this->payment_stats[$payment->customer_id]['donations'] = isset($this->payment_stats[$payment->customer_id]['donations']) ?
239
+						++$this->payment_stats[$payment->customer_id]['donations'] : 1;
242 240
 
243 241
 					// Set donation form name.
244
-					$this->payment_stats[ $payment->customer_id ]['form_title'] = $payment->form_title;
242
+					$this->payment_stats[$payment->customer_id]['form_title'] = $payment->form_title;
245 243
 
246 244
 					// Continue if donor already included.
247
-					if ( empty( $payment->customer_id ) ||
248
-					     in_array( $payment->customer_id, $cached_donor_ids )
245
+					if (empty($payment->customer_id) ||
246
+					     in_array($payment->customer_id, $cached_donor_ids)
249 247
 					) {
250 248
 						continue;
251 249
 					}
252 250
 
253 251
 					$this->donor_ids[] = $cached_donor_ids[] = $payment->customer_id;
254 252
 
255
-					$i ++;
253
+					$i++;
256 254
 				}
257 255
 
258
-				if ( ! empty( $this->donor_ids ) ) {
259
-					foreach ( $this->donor_ids as $donor_id ) {
260
-						$donor                      = Give()->donors->get_donor_by( 'id', $donor_id );
261
-						$donor->donation_form_title = $this->payment_stats[ $donor_id ]['form_title'];
262
-						$donor->purchase_count      = $this->payment_stats[ $donor_id ]['donations'];
263
-						$donor->purchase_value      = $this->payment_stats[ $donor_id ]['donation_sum'];
264
-						$data[]                     = $this->set_donor_data( $i, $data, $donor );
256
+				if ( ! empty($this->donor_ids)) {
257
+					foreach ($this->donor_ids as $donor_id) {
258
+						$donor                      = Give()->donors->get_donor_by('id', $donor_id);
259
+						$donor->donation_form_title = $this->payment_stats[$donor_id]['form_title'];
260
+						$donor->purchase_count      = $this->payment_stats[$donor_id]['donations'];
261
+						$donor->purchase_value      = $this->payment_stats[$donor_id]['donation_sum'];
262
+						$data[]                     = $this->set_donor_data($i, $data, $donor);
265 263
 					}
266 264
 
267 265
 					// Cache donor ids only if admin export donor for specific form.
@@ -271,7 +269,7 @@  discard block
 block discarded – undo
271 269
 		} else {
272 270
 
273 271
 			// Export all donors.
274
-			$offset = 30 * ( $this->step - 1 );
272
+			$offset = 30 * ($this->step - 1);
275 273
 
276 274
 			$args = array(
277 275
 				'number' => 30,
@@ -279,31 +277,31 @@  discard block
 block discarded – undo
279 277
 			);
280 278
 
281 279
 			// Check for date option filter
282
-			if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) {
280
+			if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) {
283 281
 				$args['date'] = array(
284
-					'start' => ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' ),
285
-					'end'   => ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) ),
282
+					'start' => ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00'),
283
+					'end'   => ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp')),
286 284
 				);
287 285
 			}
288 286
 
289
-			$donors = Give()->donors->get_donors( $args );
287
+			$donors = Give()->donors->get_donors($args);
290 288
 
291
-			foreach ( $donors as $donor ) {
289
+			foreach ($donors as $donor) {
292 290
 
293 291
 				// Continue if donor already included.
294
-				if ( empty( $donor->id ) || empty( $donor->payment_ids ) ) {
292
+				if (empty($donor->id) || empty($donor->payment_ids)) {
295 293
 					continue;
296 294
 				}
297 295
 
298
-				$payment                    = new Give_Payment( $donor->payment_ids );
296
+				$payment                    = new Give_Payment($donor->payment_ids);
299 297
 				$donor->donation_form_title = $payment->form_title;
300
-				$data[]                     = $this->set_donor_data( $i, $data, $donor );
301
-				$i ++;
298
+				$data[]                     = $this->set_donor_data($i, $data, $donor);
299
+				$i++;
302 300
 			}
303 301
 		}// End if().
304 302
 
305
-		$data = apply_filters( 'give_export_get_data', $data );
306
-		$data = apply_filters( "give_export_get_data_{$this->export_type}", $data );
303
+		$data = apply_filters('give_export_get_data', $data);
304
+		$data = apply_filters("give_export_get_data_{$this->export_type}", $data);
307 305
 
308 306
 		return $data;
309 307
 	}
@@ -319,18 +317,18 @@  discard block
 block discarded – undo
319 317
 		$percentage = 0;
320 318
 
321 319
 		// We can't count the number when getting them for a specific form.
322
-		if ( empty( $this->form ) ) {
320
+		if (empty($this->form)) {
323 321
 
324 322
 			$total = Give()->donors->count();
325 323
 
326
-			if ( $total > 0 ) {
324
+			if ($total > 0) {
327 325
 
328
-				$percentage = ( ( 30 * $this->step ) / $total ) * 100;
326
+				$percentage = ((30 * $this->step) / $total) * 100;
329 327
 
330 328
 			}
331 329
 		}
332 330
 
333
-		if ( $percentage > 100 ) {
331
+		if ($percentage > 100) {
334 332
 			$percentage = 100;
335 333
 		}
336 334
 
@@ -346,51 +344,51 @@  discard block
 block discarded – undo
346 344
 	 *
347 345
 	 * @return mixed
348 346
 	 */
349
-	private function set_donor_data( $i, $data, $donor ) {
347
+	private function set_donor_data($i, $data, $donor) {
350 348
 
351 349
 		$columns = $this->csv_cols();
352 350
 
353 351
 		// Set address variable
354 352
 		$address = '';
355
-		if ( isset( $donor->user_id ) && $donor->user_id > 0 ) {
356
-			$address = give_get_donor_address( $donor->user_id );
353
+		if (isset($donor->user_id) && $donor->user_id > 0) {
354
+			$address = give_get_donor_address($donor->user_id);
357 355
 		}
358 356
 
359 357
 		// Set columns
360
-		if ( ! empty( $columns['full_name'] ) ) {
361
-			$data[ $i ]['full_name'] = $donor->name;
358
+		if ( ! empty($columns['full_name'])) {
359
+			$data[$i]['full_name'] = $donor->name;
362 360
 		}
363
-		if ( ! empty( $columns['email'] ) ) {
364
-			$data[ $i ]['email'] = $donor->email;
361
+		if ( ! empty($columns['email'])) {
362
+			$data[$i]['email'] = $donor->email;
365 363
 		}
366
-		if ( ! empty( $columns['address_line1'] ) ) {
367
-
368
-			$data[ $i ]['address_line1']   = isset( $address['line1'] ) ? $address['line1'] : '';
369
-			$data[ $i ]['address_line2']   = isset( $address['line2'] ) ? $address['line2'] : '';
370
-			$data[ $i ]['address_city']    = isset( $address['city'] ) ? $address['city'] : '';
371
-			$data[ $i ]['address_state']   = isset( $address['state'] ) ? $address['state'] : '';
372
-			$data[ $i ]['address_zip']     = isset( $address['zip'] ) ? $address['zip'] : '';
373
-			$data[ $i ]['address_country'] = isset( $address['country'] ) ? $address['country'] : '';
364
+		if ( ! empty($columns['address_line1'])) {
365
+
366
+			$data[$i]['address_line1']   = isset($address['line1']) ? $address['line1'] : '';
367
+			$data[$i]['address_line2']   = isset($address['line2']) ? $address['line2'] : '';
368
+			$data[$i]['address_city']    = isset($address['city']) ? $address['city'] : '';
369
+			$data[$i]['address_state']   = isset($address['state']) ? $address['state'] : '';
370
+			$data[$i]['address_zip']     = isset($address['zip']) ? $address['zip'] : '';
371
+			$data[$i]['address_country'] = isset($address['country']) ? $address['country'] : '';
374 372
 		}
375
-		if ( ! empty( $columns['userid'] ) ) {
376
-			$data[ $i ]['userid'] = ! empty( $donor->user_id ) ? $donor->user_id : '';
373
+		if ( ! empty($columns['userid'])) {
374
+			$data[$i]['userid'] = ! empty($donor->user_id) ? $donor->user_id : '';
377 375
 		}
378
-		if ( ! empty( $columns['donation_form'] ) ) {
379
-			$data[ $i ]['donation_form'] = ! empty( $donor->donation_form_title ) ? $donor->donation_form_title : '';
376
+		if ( ! empty($columns['donation_form'])) {
377
+			$data[$i]['donation_form'] = ! empty($donor->donation_form_title) ? $donor->donation_form_title : '';
380 378
 		}
381
-		if ( ! empty( $columns['date_first_donated'] ) ) {
382
-			$data[ $i ]['date_first_donated'] = date_i18n( give_date_format(), strtotime( $donor->date_created ) );
379
+		if ( ! empty($columns['date_first_donated'])) {
380
+			$data[$i]['date_first_donated'] = date_i18n(give_date_format(), strtotime($donor->date_created));
383 381
 		}
384
-		if ( ! empty( $columns['donations'] ) ) {
385
-			$data[ $i ]['donations'] = $donor->purchase_count;
382
+		if ( ! empty($columns['donations'])) {
383
+			$data[$i]['donations'] = $donor->purchase_count;
386 384
 		}
387
-		if ( ! empty( $columns['donation_sum'] ) ) {
388
-			$data[ $i ]['donation_sum'] = give_format_amount( $donor->purchase_value, array( 'sanitize' => false ) );
385
+		if ( ! empty($columns['donation_sum'])) {
386
+			$data[$i]['donation_sum'] = give_format_amount($donor->purchase_value, array('sanitize' => false));
389 387
 		}
390 388
 
391
-		$data[ $i ] = apply_filters( 'give_export_set_donor_data', $data[ $i ], $donor );
389
+		$data[$i] = apply_filters('give_export_set_donor_data', $data[$i], $donor);
392 390
 
393
-		return $data[ $i ];
391
+		return $data[$i];
394 392
 
395 393
 	}
396 394
 
@@ -400,9 +398,9 @@  discard block
 block discarded – undo
400 398
 	 * @param array             $request
401 399
 	 * @param Give_Batch_Export $export
402 400
 	 */
403
-	public function unset_properties( $request, $export ) {
404
-		if ( $export->done ) {
405
-			Give_Cache::delete( "give_cache_{$this->query_id}" );
401
+	public function unset_properties($request, $export) {
402
+		if ($export->done) {
403
+			Give_Cache::delete("give_cache_{$this->query_id}");
406 404
 		}
407 405
 	}
408 406
 }
409 407
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/tools/export/class-batch-export.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param int $_step
120 120
 	 */
121
-	public function __construct( $_step = 1 ) {
121
+	public function __construct($_step = 1) {
122 122
 
123 123
 		$upload_dir     = wp_upload_dir();
124 124
 		$this->filetype = '.csv';
125
-		$this->filename = 'give-' . $this->export_type . $this->filetype;
126
-		$this->file     = trailingslashit( $upload_dir['basedir'] ) . $this->filename;
125
+		$this->filename = 'give-'.$this->export_type.$this->filetype;
126
+		$this->file     = trailingslashit($upload_dir['basedir']).$this->filename;
127 127
 
128
-		if ( ! is_writeable( $upload_dir['basedir'] ) ) {
128
+		if ( ! is_writeable($upload_dir['basedir'])) {
129 129
 			$this->is_writable = false;
130 130
 		}
131 131
 
@@ -141,22 +141,22 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public function process_step() {
143 143
 
144
-		if ( ! $this->can_export() ) {
145
-			wp_die( esc_html__( 'You do not have permission to export data.', 'give' ), esc_html__( 'Error', 'give' ), array(
144
+		if ( ! $this->can_export()) {
145
+			wp_die(esc_html__('You do not have permission to export data.', 'give'), esc_html__('Error', 'give'), array(
146 146
 				'response' => 403,
147
-			) );
147
+			));
148 148
 		}
149 149
 
150
-		if ( $this->step < 2 ) {
150
+		if ($this->step < 2) {
151 151
 
152 152
 			// Make sure we start with a fresh file on step 1.
153
-			@unlink( $this->file );
153
+			@unlink($this->file);
154 154
 			$this->print_csv_cols();
155 155
 		}
156 156
 
157 157
 		$rows = $this->print_csv_rows();
158 158
 
159
-		if ( $rows ) {
159
+		if ($rows) {
160 160
 			return true;
161 161
 		} else {
162 162
 			return false;
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
 		$col_data = '';
177 177
 		$cols     = $this->get_csv_cols();
178 178
 		$i        = 1;
179
-		foreach ( $cols as $col_id => $column ) {
180
-			$col_data .= '"' . addslashes( $column ) . '"';
181
-			$col_data .= $i == count( $cols ) ? '' : ',';
182
-			$i ++;
179
+		foreach ($cols as $col_id => $column) {
180
+			$col_data .= '"'.addslashes($column).'"';
181
+			$col_data .= $i == count($cols) ? '' : ',';
182
+			$i++;
183 183
 		}
184 184
 		$col_data .= "\r\n";
185 185
 
186
-		$this->stash_step_data( $col_data );
186
+		$this->stash_step_data($col_data);
187 187
 
188 188
 		return $col_data;
189 189
 
@@ -202,23 +202,23 @@  discard block
 block discarded – undo
202 202
 		$data     = $this->get_data();
203 203
 		$cols     = $this->get_csv_cols();
204 204
 
205
-		if ( $data ) {
205
+		if ($data) {
206 206
 
207 207
 			// Output each row
208
-			foreach ( $data as $row ) {
208
+			foreach ($data as $row) {
209 209
 				$i = 1;
210
-				foreach ( $row as $col_id => $column ) {
210
+				foreach ($row as $col_id => $column) {
211 211
 					// Make sure the column is valid
212
-					if ( array_key_exists( $col_id, $cols ) ) {
213
-						$row_data .= '"' . addslashes( preg_replace( '/"/', "'", $column ) ) . '"';
214
-						$row_data .= $i == count( $cols ) ? '' : ',';
215
-						$i ++;
212
+					if (array_key_exists($col_id, $cols)) {
213
+						$row_data .= '"'.addslashes(preg_replace('/"/', "'", $column)).'"';
214
+						$row_data .= $i == count($cols) ? '' : ',';
215
+						$i++;
216 216
 					}
217 217
 				}
218 218
 				$row_data .= "\r\n";
219 219
 			}
220 220
 
221
-			$this->stash_step_data( $row_data );
221
+			$this->stash_step_data($row_data);
222 222
 
223 223
 			return $row_data;
224 224
 		}
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 
247 247
 		$file = '';
248 248
 
249
-		if ( @file_exists( $this->file ) ) {
249
+		if (@file_exists($this->file)) {
250 250
 
251
-			if ( ! is_writeable( $this->file ) ) {
251
+			if ( ! is_writeable($this->file)) {
252 252
 				$this->is_writable = false;
253 253
 			}
254 254
 
255
-			$file = @file_get_contents( $this->file );
255
+			$file = @file_get_contents($this->file);
256 256
 
257 257
 		} else {
258 258
 
259
-			@file_put_contents( $this->file, '' );
260
-			@chmod( $this->file, 0664 );
259
+			@file_put_contents($this->file, '');
260
+			@chmod($this->file, 0664);
261 261
 
262 262
 		}
263 263
 
@@ -273,18 +273,18 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return void
275 275
 	 */
276
-	protected function stash_step_data( $data = '' ) {
276
+	protected function stash_step_data($data = '') {
277 277
 
278 278
 		$file = $this->get_file();
279 279
 		$file .= $data;
280
-		@file_put_contents( $this->file, $file );
280
+		@file_put_contents($this->file, $file);
281 281
 
282 282
 		// If we have no rows after this step, mark it as an empty export.
283
-		$file_rows    = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+		$file_rows    = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
 		$default_cols = $this->get_csv_cols();
285
-		$default_cols = empty( $default_cols ) ? 0 : 1;
285
+		$default_cols = empty($default_cols) ? 0 : 1;
286 286
 
287
-		$this->is_empty = count( $file_rows ) == $default_cols ? true : false;
287
+		$this->is_empty = count($file_rows) == $default_cols ? true : false;
288 288
 
289 289
 	}
290 290
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 
303 303
 		$file = $this->get_file();
304 304
 
305
-		@unlink( $this->file );
305
+		@unlink($this->file);
306 306
 
307 307
 		echo $file;
308 308
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 		 *
312 312
 		 * @since 1.8
313 313
 		 */
314
-		do_action( 'give_file_export_complete', $_REQUEST );
314
+		do_action('give_file_export_complete', $_REQUEST);
315 315
 
316 316
 		give_die();
317 317
 	}
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 	 *
324 324
 	 * @param array $request The Form Data passed into the batch processing.
325 325
 	 */
326
-	public function set_properties( $request ) {
326
+	public function set_properties($request) {
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	 * @param array             $request The Form Data passed into the batch processing.
335 335
 	 * @param Give_Batch_Export $export
336 336
 	 */
337
-	public function unset_properties( $request, $export ) {
337
+	public function unset_properties($request, $export) {
338 338
 	}
339 339
 
340 340
 	/**
Please login to merge, or discard this patch.