Completed
Pull Request — master (#664)
by Devin
19:01
created
includes/admin/reporting/tools/tools-actions.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
  * @since  1.5
20 20
  */
21 21
 function give_register_batch_recount_store_earnings_tool() {
22
-	add_action( 'give_batch_export_class_include', 'give_include_recount_income_tool_batch_processor', 10, 1 );
22
+	add_action('give_batch_export_class_include', 'give_include_recount_income_tool_batch_processor', 10, 1);
23 23
 }
24 24
 
25
-add_action( 'give_register_batch_exporter', 'give_register_batch_recount_store_earnings_tool', 10 );
25
+add_action('give_register_batch_exporter', 'give_register_batch_recount_store_earnings_tool', 10);
26 26
 
27 27
 /**
28 28
  * Loads the tools batch processing class for recounting store earnings
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
  *
34 34
  * @return void
35 35
  */
36
-function give_include_recount_income_tool_batch_processor( $class ) {
36
+function give_include_recount_income_tool_batch_processor($class) {
37 37
 
38
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-recount-income.php';
38
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-recount-income.php';
39 39
 
40
-	if ( 'Give_Tools_Recount_Income' === $class && file_exists( $file_path ) ) {
40
+	if ('Give_Tools_Recount_Income' === $class && file_exists($file_path)) {
41 41
 		require_once $file_path;
42 42
 	}
43 43
 
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
  * @since  1.5
50 50
  */
51 51
 function give_register_batch_recount_form_tool() {
52
-	add_action( 'give_batch_export_class_include', 'give_include_recount_form_tool_batch_processor', 10, 1 );
52
+	add_action('give_batch_export_class_include', 'give_include_recount_form_tool_batch_processor', 10, 1);
53 53
 }
54 54
 
55
-add_action( 'give_register_batch_exporter', 'give_register_batch_recount_form_tool', 10 );
55
+add_action('give_register_batch_exporter', 'give_register_batch_recount_form_tool', 10);
56 56
 
57 57
 /**
58 58
  * Loads the tools batch processing class for recounting download stats
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  *
64 64
  * @return void
65 65
  */
66
-function give_include_recount_form_tool_batch_processor( $class ) {
66
+function give_include_recount_form_tool_batch_processor($class) {
67 67
 
68
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-recount-form-stats.php';
68
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-recount-form-stats.php';
69 69
 
70
-	if ( 'Give_Tools_Recount_Form_Stats' === $class && file_exists( $file_path ) ) {
70
+	if ('Give_Tools_Recount_Form_Stats' === $class && file_exists($file_path)) {
71 71
 		require_once $file_path;
72 72
 	}
73 73
 
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
  * @since  1.5
79 79
  */
80 80
 function give_register_batch_recount_all_tool() {
81
-	add_action( 'give_batch_export_class_include', 'give_include_recount_all_tool_batch_processor', 10, 1 );
81
+	add_action('give_batch_export_class_include', 'give_include_recount_all_tool_batch_processor', 10, 1);
82 82
 }
83 83
 
84
-add_action( 'give_register_batch_exporter', 'give_register_batch_recount_all_tool', 10 );
84
+add_action('give_register_batch_exporter', 'give_register_batch_recount_all_tool', 10);
85 85
 
86 86
 /**
87 87
  * Loads the tools batch processing class for recounting all stats
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
  *
93 93
  * @return void
94 94
  */
95
-function give_include_recount_all_tool_batch_processor( $class ) {
96
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-recount-all-stats.php';
97
-	if ( 'Give_Tools_Recount_All_Stats' === $class && file_exists( $file_path ) ) {
95
+function give_include_recount_all_tool_batch_processor($class) {
96
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-recount-all-stats.php';
97
+	if ('Give_Tools_Recount_All_Stats' === $class && file_exists($file_path)) {
98 98
 		require_once $file_path;
99 99
 	}
100 100
 
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
  * @since  1.5
107 107
  */
108 108
 function give_register_batch_reset_tool() {
109
-	add_action( 'give_batch_export_class_include', 'give_include_reset_tool_batch_processor', 10, 1 );
109
+	add_action('give_batch_export_class_include', 'give_include_reset_tool_batch_processor', 10, 1);
110 110
 }
111 111
 
112
-add_action( 'give_register_batch_exporter', 'give_register_batch_reset_tool', 10 );
112
+add_action('give_register_batch_exporter', 'give_register_batch_reset_tool', 10);
113 113
 
114 114
 /**
115 115
  * Loads the tools batch processing class for resetting store and product earnings
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
  *
121 121
  * @return void
122 122
  */
123
-function give_include_reset_tool_batch_processor( $class ) {
123
+function give_include_reset_tool_batch_processor($class) {
124 124
 
125
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-reset-stats.php';
125
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-reset-stats.php';
126 126
 
127
-	if ( 'Give_Tools_Reset_Stats' === $class && file_exists( $file_path ) ) {
127
+	if ('Give_Tools_Reset_Stats' === $class && file_exists($file_path)) {
128 128
 		require_once $file_path;
129 129
 	}
130 130
 
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
  * @since  1.5
136 136
  */
137 137
 function give_register_batch_customer_recount_tool() {
138
-	add_action( 'give_batch_export_class_include', 'give_include_customer_recount_tool_batch_processor', 10, 1 );
138
+	add_action('give_batch_export_class_include', 'give_include_customer_recount_tool_batch_processor', 10, 1);
139 139
 }
140 140
 
141
-add_action( 'give_register_batch_exporter', 'give_register_batch_customer_recount_tool', 10 );
141
+add_action('give_register_batch_exporter', 'give_register_batch_customer_recount_tool', 10);
142 142
 
143 143
 /**
144 144
  * Loads the tools batch processing class for resetting all customer stats
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
  *
150 150
  * @return void
151 151
  */
152
-function give_include_customer_recount_tool_batch_processor( $class ) {
152
+function give_include_customer_recount_tool_batch_processor($class) {
153 153
 
154
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-recount-customer-stats.php';
154
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-recount-customer-stats.php';
155 155
 
156
-	if ( 'Give_Tools_Recount_Customer_Stats' === $class && file_exists( $file_path ) ) {
156
+	if ('Give_Tools_Recount_Customer_Stats' === $class && file_exists($file_path)) {
157 157
 		require_once $file_path;
158 158
 	}
159 159
 
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
  * @since  1.5
165 165
  */
166 166
 function give_register_batch_delete_test_transactions_tool() {
167
-	add_action( 'give_batch_export_class_include', 'give_include_delete_test_transactions_batch_processor', 10, 1 );
167
+	add_action('give_batch_export_class_include', 'give_include_delete_test_transactions_batch_processor', 10, 1);
168 168
 }
169 169
 
170
-add_action( 'give_register_batch_exporter', 'give_register_batch_delete_test_transactions_tool', 10 );
170
+add_action('give_register_batch_exporter', 'give_register_batch_delete_test_transactions_tool', 10);
171 171
 
172 172
 /**
173 173
  * Loads the tools batch processing class for resetting all customer stats
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
  *
179 179
  * @return void
180 180
  */
181
-function give_include_delete_test_transactions_batch_processor( $class ) {
181
+function give_include_delete_test_transactions_batch_processor($class) {
182 182
 
183
-	$file_path = GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/class-give-tools-delete-test-transactions.php';
183
+	$file_path = GIVE_PLUGIN_DIR.'includes/admin/reporting/tools/class-give-tools-delete-test-transactions.php';
184 184
 
185
-	if ( 'Give_Tools_Delete_Test_Transactions' === $class && file_exists( $file_path ) ) {
185
+	if ('Give_Tools_Delete_Test_Transactions' === $class && file_exists($file_path)) {
186 186
 		require_once $file_path;
187 187
 	}
188 188
 
Please login to merge, or discard this patch.
includes/admin/reporting/class-form-reports-table.php 1 patch
Spacing   +55 added lines, -55 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
 /**
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
 		global $status, $page;
51 51
 
52 52
 		// Set parent defaults
53
-		parent::__construct( array(
54
-			'singular' => give_get_forms_label_singular(),    // Singular name of the listed records
55
-			'plural'   => give_get_forms_label_plural(),        // Plural name of the listed records
53
+		parent::__construct(array(
54
+			'singular' => give_get_forms_label_singular(), // Singular name of the listed records
55
+			'plural'   => give_get_forms_label_plural(), // Plural name of the listed records
56 56
 			'ajax'     => false                        // Does this table support ajax?
57
-		) );
57
+		));
58 58
 
59
-		add_action( 'give_report_view_actions', array( $this, 'category_filter' ) );
59
+		add_action('give_report_view_actions', array($this, 'category_filter'));
60 60
 		$this->query();
61 61
 
62 62
 	}
@@ -72,18 +72,18 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @return string Column Name
74 74
 	 */
75
-	public function column_default( $item, $column_name ) {
76
-		switch ( $column_name ) {
75
+	public function column_default($item, $column_name) {
76
+		switch ($column_name) {
77 77
 			case 'earnings' :
78
-				return give_currency_filter( give_format_amount( $item[ $column_name ] ) );
78
+				return give_currency_filter(give_format_amount($item[$column_name]));
79 79
 			case 'average_sales' :
80
-				return round( $item[ $column_name ] );
80
+				return round($item[$column_name]);
81 81
 			case 'average_earnings' :
82
-				return give_currency_filter( give_format_amount( $item[ $column_name ] ) );
82
+				return give_currency_filter(give_format_amount($item[$column_name]));
83 83
 			case 'details' :
84
-				return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-reports&view=forms&form-id=' . $item['ID'] ) . '">' . __( 'View Detailed Report', 'give' ) . '</a>';
84
+				return '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-reports&view=forms&form-id='.$item['ID']).'">'.__('View Detailed Report', 'give').'</a>';
85 85
 			default:
86
-				return $item[ $column_name ];
86
+				return $item[$column_name];
87 87
 		}
88 88
 	}
89 89
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	public function get_columns() {
98 98
 		$columns = array(
99 99
 			'title'            => give_get_forms_label_singular(),
100
-			'sales'            => __( 'Donations', 'give' ),
101
-			'earnings'         => __( 'Income', 'give' ),
102
-			'average_sales'    => __( 'Monthly Average Donations', 'give' ),
103
-			'average_earnings' => __( 'Monthly Average Income', 'give' ),
104
-			'details'          => __( 'Detailed Report', 'give' )
100
+			'sales'            => __('Donations', 'give'),
101
+			'earnings'         => __('Income', 'give'),
102
+			'average_sales'    => __('Monthly Average Donations', 'give'),
103
+			'average_earnings' => __('Monthly Average Income', 'give'),
104
+			'details'          => __('Detailed Report', 'give')
105 105
 		);
106 106
 
107 107
 		return $columns;
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public function get_sortable_columns() {
118 118
 		return array(
119
-			'title'    => array( 'title', true ),
120
-			'sales'    => array( 'sales', false ),
121
-			'earnings' => array( 'earnings', false ),
119
+			'title'    => array('title', true),
120
+			'sales'    => array('sales', false),
121
+			'earnings' => array('earnings', false),
122 122
 		);
123 123
 	}
124 124
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return int Current page number
131 131
 	 */
132 132
 	public function get_paged() {
133
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
133
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
134 134
 	}
135 135
 
136 136
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @return int Category ID
143 143
 	 */
144 144
 	public function get_category() {
145
-		return isset( $_GET['category'] ) ? absint( $_GET['category'] ) : 0;
145
+		return isset($_GET['category']) ? absint($_GET['category']) : 0;
146 146
 	}
147 147
 
148 148
 
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	public function get_total_forms() {
157 157
 		$total  = 0;
158
-		$counts = wp_count_posts( 'give_forms', 'readable' );
159
-		foreach ( $counts as $status => $count ) {
158
+		$counts = wp_count_posts('give_forms', 'readable');
159
+		foreach ($counts as $status => $count) {
160 160
 			$total += $count;
161 161
 		}
162 162
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @since  1.0
171 171
 	 * @return void
172 172
 	 */
173
-	public function bulk_actions( $which = '' ) {
173
+	public function bulk_actions($which = '') {
174 174
 		// These aren't really bulk actions but this outputs the markup in the right place
175 175
 		give_report_views();
176 176
 	}
@@ -183,23 +183,23 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @param string $which
185 185
 	 */
186
-	protected function display_tablenav( $which ) {
186
+	protected function display_tablenav($which) {
187 187
 
188
-		if ( 'top' == $which ) {
189
-			wp_nonce_field( 'bulk-' . $this->_args['plural'] );
188
+		if ('top' == $which) {
189
+			wp_nonce_field('bulk-'.$this->_args['plural']);
190 190
 		}
191 191
 		?>
192
-		<div class="tablenav give-clearfix <?php echo esc_attr( $which ); ?>">
192
+		<div class="tablenav give-clearfix <?php echo esc_attr($which); ?>">
193 193
 
194
-			<h3 class="alignleft reports-earnings-title"><span><?php _e( 'Donation Forms Report', 'give' ); ?></span></h3>
194
+			<h3 class="alignleft reports-earnings-title"><span><?php _e('Donation Forms Report', 'give'); ?></span></h3>
195 195
 
196 196
 			<div class="alignright tablenav-right">
197 197
 				<div class="actions bulkactions">
198
-					<?php $this->bulk_actions( $which ); ?>
198
+					<?php $this->bulk_actions($which); ?>
199 199
 				</div>
200 200
 				<?php
201
-				$this->extra_tablenav( $which );
202
-				$this->pagination( $which );
201
+				$this->extra_tablenav($which);
202
+				$this->pagination($which);
203 203
 				?>
204 204
 			</div>
205 205
 
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	public function category_filter() {
221 221
 
222
-		$categories = get_terms( 'form_category' );
223
-		if ( $categories && ! is_wp_error( $categories ) ) {
224
-			echo Give()->html->category_dropdown( 'category', $this->get_category() );
222
+		$categories = get_terms('form_category');
223
+		if ($categories && ! is_wp_error($categories)) {
224
+			echo Give()->html->category_dropdown('category', $this->get_category());
225 225
 		}
226 226
 	}
227 227
 
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 	 */
236 236
 	public function query() {
237 237
 
238
-		$orderby  = isset( $_GET['orderby'] ) ? $_GET['orderby'] : 'title';
239
-		$order    = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
238
+		$orderby  = isset($_GET['orderby']) ? $_GET['orderby'] : 'title';
239
+		$order    = isset($_GET['order']) ? $_GET['order'] : 'DESC';
240 240
 		$category = $this->get_category();
241 241
 
242 242
 		$args = array(
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			'suppress_filters' => true
250 250
 		);
251 251
 
252
-		if ( ! empty( $category ) ) {
252
+		if ( ! empty($category)) {
253 253
 			$args['tax_query'] = array(
254 254
 				array(
255 255
 					'taxonomy' => 'form_category',
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 			);
259 259
 		}
260 260
 
261
-		switch ( $orderby ) :
261
+		switch ($orderby) :
262 262
 			case 'title' :
263 263
 				$args['orderby'] = 'title';
264 264
 				break;
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 				break;
275 275
 		endswitch;
276 276
 
277
-		$args = apply_filters( 'give_form_reports_prepare_items_args', $args, $this );
277
+		$args = apply_filters('give_form_reports_prepare_items_args', $args, $this);
278 278
 
279
-		$this->products = new WP_Query( $args );
279
+		$this->products = new WP_Query($args);
280 280
 
281 281
 	}
282 282
 
@@ -292,15 +292,15 @@  discard block
 block discarded – undo
292 292
 
293 293
 		$give_forms = $this->products->posts;
294 294
 
295
-		if ( $give_forms ) {
296
-			foreach ( $give_forms as $form ) {
295
+		if ($give_forms) {
296
+			foreach ($give_forms as $form) {
297 297
 				$reports_data[] = array(
298 298
 					'ID'               => $form,
299
-					'title'            => get_the_title( $form ),
300
-					'sales'            => give_get_form_sales_stats( $form ),
301
-					'earnings'         => give_get_form_earnings_stats( $form ),
302
-					'average_sales'    => give_get_average_monthly_form_sales( $form ),
303
-					'average_earnings' => give_get_average_monthly_form_earnings( $form )
299
+					'title'            => get_the_title($form),
300
+					'sales'            => give_get_form_sales_stats($form),
301
+					'earnings'         => give_get_form_earnings_stats($form),
302
+					'average_sales'    => give_get_average_monthly_form_sales($form),
303
+					'average_earnings' => give_get_average_monthly_form_earnings($form)
304 304
 				);
305 305
 			}
306 306
 		}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 
329 329
 		$sortable = $this->get_sortable_columns();
330 330
 
331
-		$this->_column_headers = array( $columns, $hidden, $sortable );
331
+		$this->_column_headers = array($columns, $hidden, $sortable);
332 332
 
333 333
 		$data = $this->reports_data();
334 334
 
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$this->items = $data;
338 338
 
339
-		$this->set_pagination_args( array(
339
+		$this->set_pagination_args(array(
340 340
 				'total_items' => $total_items,
341 341
 				'per_page'    => $this->per_page,
342
-				'total_pages' => ceil( $total_items / $this->per_page )
342
+				'total_pages' => ceil($total_items / $this->per_page)
343 343
 			)
344 344
 		);
345 345
 	}
Please login to merge, or discard this patch.
includes/class-give-db.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since       1.0
10 10
  */
11 11
 
12
-if ( ! defined( 'ABSPATH' ) ) {
12
+if ( ! defined('ABSPATH')) {
13 13
 	exit;
14 14
 } // Exit if accessed directly
15 15
 
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	 * @since   1.0
81 81
 	 * @return  object
82 82
 	 */
83
-	public function get( $row_id ) {
83
+	public function get($row_id) {
84 84
 		global $wpdb;
85 85
 
86
-		return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
86
+		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id));
87 87
 	}
88 88
 
89 89
 	/**
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
 	 * @since   1.0
94 94
 	 * @return  object
95 95
 	 */
96
-	public function get_by( $column, $row_id ) {
96
+	public function get_by($column, $row_id) {
97 97
 		global $wpdb;
98
-		$column = esc_sql( $column );
99
-		return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );
98
+		$column = esc_sql($column);
99
+		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id));
100 100
 	}
101 101
 
102 102
 	/**
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
 	 * @since   1.0
107 107
 	 * @return  string
108 108
 	 */
109
-	public function get_column( $column, $row_id ) {
109
+	public function get_column($column, $row_id) {
110 110
 		global $wpdb;
111
-		$column = esc_sql( $column );
112
-		return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
111
+		$column = esc_sql($column);
112
+		return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id));
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
 	 * @since   1.0
120 120
 	 * @return  string
121 121
 	 */
122
-	public function get_column_by( $column, $column_where, $column_value ) {
122
+	public function get_column_by($column, $column_where, $column_value) {
123 123
 		global $wpdb;
124
-		$column_where = esc_sql( $column_where );
125
-		$column       = esc_sql( $column );
126
-		return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
124
+		$column_where = esc_sql($column_where);
125
+		$column       = esc_sql($column);
126
+		return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value));
127 127
 	}
128 128
 
129 129
 	/**
@@ -133,30 +133,30 @@  discard block
 block discarded – undo
133 133
 	 * @since   1.0
134 134
 	 * @return  int
135 135
 	 */
136
-	public function insert( $data, $type = '' ) {
136
+	public function insert($data, $type = '') {
137 137
 		global $wpdb;
138 138
 
139 139
 		// Set default values
140
-		$data = wp_parse_args( $data, $this->get_column_defaults() );
140
+		$data = wp_parse_args($data, $this->get_column_defaults());
141 141
 
142
-		do_action( 'give_pre_insert_' . $type, $data );
142
+		do_action('give_pre_insert_'.$type, $data);
143 143
 
144 144
 		// Initialise column format array
145 145
 		$column_formats = $this->get_columns();
146 146
 
147 147
 		// Force fields to lower case
148
-		$data = array_change_key_case( $data );
148
+		$data = array_change_key_case($data);
149 149
 
150 150
 		// White list columns
151
-		$data = array_intersect_key( $data, $column_formats );
151
+		$data = array_intersect_key($data, $column_formats);
152 152
 
153 153
 		// Reorder $column_formats to match the order of columns given in $data
154
-		$data_keys      = array_keys( $data );
155
-		$column_formats = array_merge( array_flip( $data_keys ), $column_formats );
154
+		$data_keys      = array_keys($data);
155
+		$column_formats = array_merge(array_flip($data_keys), $column_formats);
156 156
 
157
-		$wpdb->insert( $this->table_name, $data, $column_formats );
157
+		$wpdb->insert($this->table_name, $data, $column_formats);
158 158
 
159
-		do_action( 'give_post_insert_' . $type, $wpdb->insert_id, $data );
159
+		do_action('give_post_insert_'.$type, $wpdb->insert_id, $data);
160 160
 
161 161
 		return $wpdb->insert_id;
162 162
 	}
@@ -168,18 +168,18 @@  discard block
 block discarded – undo
168 168
 	 * @since   1.0
169 169
 	 * @return  bool
170 170
 	 */
171
-	public function update( $row_id, $data = array(), $where = '' ) {
171
+	public function update($row_id, $data = array(), $where = '') {
172 172
 
173 173
 		global $wpdb;
174 174
 
175 175
 		// Row ID must be positive integer
176
-		$row_id = absint( $row_id );
176
+		$row_id = absint($row_id);
177 177
 
178
-		if ( empty( $row_id ) ) {
178
+		if (empty($row_id)) {
179 179
 			return false;
180 180
 		}
181 181
 
182
-		if ( empty( $where ) ) {
182
+		if (empty($where)) {
183 183
 			$where = $this->primary_key;
184 184
 		}
185 185
 
@@ -187,16 +187,16 @@  discard block
 block discarded – undo
187 187
 		$column_formats = $this->get_columns();
188 188
 
189 189
 		// Force fields to lower case
190
-		$data = array_change_key_case( $data );
190
+		$data = array_change_key_case($data);
191 191
 
192 192
 		// White list columns
193
-		$data = array_intersect_key( $data, $column_formats );
193
+		$data = array_intersect_key($data, $column_formats);
194 194
 
195 195
 		// Reorder $column_formats to match the order of columns given in $data
196
-		$data_keys      = array_keys( $data );
197
-		$column_formats = array_merge( array_flip( $data_keys ), $column_formats );
196
+		$data_keys      = array_keys($data);
197
+		$column_formats = array_merge(array_flip($data_keys), $column_formats);
198 198
 
199
-		if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) {
199
+		if (false === $wpdb->update($this->table_name, $data, array($where => $row_id), $column_formats)) {
200 200
 			return false;
201 201
 		}
202 202
 
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
 	 * @since   1.0
211 211
 	 * @return  bool
212 212
 	 */
213
-	public function delete( $row_id = 0 ) {
213
+	public function delete($row_id = 0) {
214 214
 
215 215
 		global $wpdb;
216 216
 
217 217
 		// Row ID must be positive integer
218
-		$row_id = absint( $row_id );
218
+		$row_id = absint($row_id);
219 219
 
220
-		if ( empty( $row_id ) ) {
220
+		if (empty($row_id)) {
221 221
 			return false;
222 222
 		}
223 223
 
224
-		if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) {
224
+		if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id))) {
225 225
 			return false;
226 226
 		}
227 227
 
@@ -235,11 +235,11 @@  discard block
 block discarded – undo
235 235
 	 * @param  string $table The table name
236 236
 	 * @return bool          If the table name exists
237 237
 	 */
238
-	public function table_exists( $table ) {
238
+	public function table_exists($table) {
239 239
 		global $wpdb;
240
-		$table = sanitize_text_field( $table );
240
+		$table = sanitize_text_field($table);
241 241
 
242
-		return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
242
+		return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE '%s'", $table)) === $table;
243 243
 	}
244 244
 
245 245
 }
246 246
\ No newline at end of file
Please login to merge, or discard this patch.
includes/forms/functions.php 1 patch
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 
24 24
 	global $typenow;
25 25
 
26
-	if ( $typenow != 'give_forms' && $typenow != 'give_campaigns' ) {
26
+	if ($typenow != 'give_forms' && $typenow != 'give_campaigns') {
27 27
 		return true;
28 28
 	}
29 29
 
30 30
 	return false;
31 31
 }
32 32
 
33
-add_filter( 'give_shortcode_button_condition', 'give_shortcode_button_condition' );
33
+add_filter('give_shortcode_button_condition', 'give_shortcode_button_condition');
34 34
 
35 35
 
36 36
 /**
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
  *
41 41
  * @return int|false
42 42
  */
43
-function get_form_id_from_args( $args ) {
43
+function get_form_id_from_args($args) {
44 44
 
45
-	if ( isset( $args['form_id'] ) && $args['form_id'] != 0 ) {
45
+	if (isset($args['form_id']) && $args['form_id'] != 0) {
46 46
 
47
-		return intval( $args['form_id'] );
47
+		return intval($args['form_id']);
48 48
 	}
49 49
 
50 50
 	return false;
@@ -59,23 +59,23 @@  discard block
 block discarded – undo
59 59
  *
60 60
  * @return bool
61 61
  */
62
-function give_is_float_labels_enabled( $args ) {
62
+function give_is_float_labels_enabled($args) {
63 63
 
64 64
 	$float_labels = '';
65 65
 
66
-	if ( ! empty( $args['float_labels'] ) ) {
66
+	if ( ! empty($args['float_labels'])) {
67 67
 		$float_labels = $args['float_labels'];
68 68
 	}
69 69
 
70
-	if ( empty( $float_labels ) ) {
71
-		$float_labels = get_post_meta( $args['form_id'], '_give_form_floating_labels', true );
70
+	if (empty($float_labels)) {
71
+		$float_labels = get_post_meta($args['form_id'], '_give_form_floating_labels', true);
72 72
 	}
73 73
 
74
-	if ( empty( $float_labels ) ) {
75
-		$float_labels = give_get_option( 'enable_floatlabels' ) ? 'enabled' : 'disabled';
74
+	if (empty($float_labels)) {
75
+		$float_labels = give_get_option('enable_floatlabels') ? 'enabled' : 'disabled';
76 76
 	}
77 77
 
78
-	return ( $float_labels == 'enabled' ) ? true : false;
78
+	return ($float_labels == 'enabled') ? true : false;
79 79
 }
80 80
 
81 81
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 
91 91
 	$can_checkout = true;
92 92
 
93
-	return (bool) apply_filters( 'give_can_checkout', $can_checkout );
93
+	return (bool) apply_filters('give_can_checkout', $can_checkout);
94 94
 }
95 95
 
96 96
 /**
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 function give_get_success_page_uri() {
104 104
 	global $give_options;
105 105
 
106
-	$success_page = isset( $give_options['success_page'] ) ? get_permalink( absint( $give_options['success_page'] ) ) : get_bloginfo( 'url' );
106
+	$success_page = isset($give_options['success_page']) ? get_permalink(absint($give_options['success_page'])) : get_bloginfo('url');
107 107
 
108
-	return apply_filters( 'give_get_success_page_uri', $success_page );
108
+	return apply_filters('give_get_success_page_uri', $success_page);
109 109
 }
110 110
 
111 111
 /**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
  */
117 117
 function give_is_success_page() {
118 118
 	global $give_options;
119
-	$is_success_page = isset( $give_options['success_page'] ) ? is_page( $give_options['success_page'] ) : false;
119
+	$is_success_page = isset($give_options['success_page']) ? is_page($give_options['success_page']) : false;
120 120
 
121
-	return apply_filters( 'give_is_success_page', $is_success_page );
121
+	return apply_filters('give_is_success_page', $is_success_page);
122 122
 }
123 123
 
124 124
 /**
@@ -132,17 +132,17 @@  discard block
 block discarded – undo
132 132
  * @since       1.0
133 133
  * @return      void
134 134
  */
135
-function give_send_to_success_page( $query_string = null ) {
135
+function give_send_to_success_page($query_string = null) {
136 136
 
137 137
 	$redirect = give_get_success_page_uri();
138 138
 
139
-	if ( $query_string ) {
139
+	if ($query_string) {
140 140
 		$redirect .= $query_string;
141 141
 	}
142 142
 
143
-	$gateway = isset( $_REQUEST['give-gateway'] ) ? $_REQUEST['give-gateway'] : '';
143
+	$gateway = isset($_REQUEST['give-gateway']) ? $_REQUEST['give-gateway'] : '';
144 144
 
145
-	wp_redirect( apply_filters( 'give_success_page_redirect', $redirect, $gateway, $query_string ) );
145
+	wp_redirect(apply_filters('give_success_page_redirect', $redirect, $gateway, $query_string));
146 146
 	give_die();
147 147
 }
148 148
 
@@ -159,25 +159,25 @@  discard block
 block discarded – undo
159 159
  * @since  1.0
160 160
  * @return Void
161 161
  */
162
-function give_send_back_to_checkout( $args = array() ) {
162
+function give_send_back_to_checkout($args = array()) {
163 163
 
164
-	$redirect = ( isset( $_POST['give-current-url'] ) ) ? $_POST['give-current-url'] : '';
165
-	$form_id  = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : 0;
164
+	$redirect = (isset($_POST['give-current-url'])) ? $_POST['give-current-url'] : '';
165
+	$form_id  = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : 0;
166 166
 
167 167
 	$defaults = array(
168 168
 		'form-id' => (int) $form_id
169 169
 	);
170 170
 
171 171
 	// Check for backward compatibility
172
-	if ( is_string( $args ) ) {
173
-		$args = str_replace( '?', '', $args );
172
+	if (is_string($args)) {
173
+		$args = str_replace('?', '', $args);
174 174
 	}
175 175
 
176
-	$args = wp_parse_args( $args, $defaults );
176
+	$args = wp_parse_args($args, $defaults);
177 177
 
178
-	$redirect = add_query_arg( $args, $redirect ) . '#give-form-' . $form_id . '-wrap';
178
+	$redirect = add_query_arg($args, $redirect).'#give-form-'.$form_id.'-wrap';
179 179
 
180
-	wp_redirect( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) );
180
+	wp_redirect(apply_filters('give_send_back_to_checkout', $redirect, $args));
181 181
 	give_die();
182 182
 }
183 183
 
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
  * @since       1.0
193 193
  * @return      string
194 194
  */
195
-function give_get_success_page_url( $query_string = null ) {
195
+function give_get_success_page_url($query_string = null) {
196 196
 
197
-	$success_page = give_get_option( 'success_page', 0 );
198
-	$success_page = get_permalink( $success_page );
197
+	$success_page = give_get_option('success_page', 0);
198
+	$success_page = get_permalink($success_page);
199 199
 
200
-	if ( $query_string ) {
200
+	if ($query_string) {
201 201
 		$success_page .= $query_string;
202 202
 	}
203 203
 
204
-	return apply_filters( 'give_success_page_url', $success_page );
204
+	return apply_filters('give_success_page_url', $success_page);
205 205
 
206 206
 }
207 207
 
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
  *
216 216
  * @return mixed|void Full URL to the Transaction Failed page, if present, home page if it doesn't exist
217 217
  */
218
-function give_get_failed_transaction_uri( $extras = false ) {
218
+function give_get_failed_transaction_uri($extras = false) {
219 219
 	global $give_options;
220 220
 
221
-	$uri = ! empty( $give_options['failure_page'] ) ? trailingslashit( get_permalink( $give_options['failure_page'] ) ) : home_url();
222
-	if ( $extras ) {
221
+	$uri = ! empty($give_options['failure_page']) ? trailingslashit(get_permalink($give_options['failure_page'])) : home_url();
222
+	if ($extras) {
223 223
 		$uri .= $extras;
224 224
 	}
225 225
 
226
-	return apply_filters( 'give_get_failed_transaction_uri', $uri );
226
+	return apply_filters('give_get_failed_transaction_uri', $uri);
227 227
 }
228 228
 
229 229
 /**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
  */
235 235
 function give_is_failed_transaction_page() {
236 236
 	global $give_options;
237
-	$ret = isset( $give_options['failure_page'] ) ? is_page( $give_options['failure_page'] ) : false;
237
+	$ret = isset($give_options['failure_page']) ? is_page($give_options['failure_page']) : false;
238 238
 
239
-	return apply_filters( 'give_is_failure_page', $ret );
239
+	return apply_filters('give_is_failure_page', $ret);
240 240
 }
241 241
 
242 242
 /**
@@ -248,18 +248,18 @@  discard block
 block discarded – undo
248 248
  */
249 249
 function give_listen_for_failed_payments() {
250 250
 
251
-	$failed_page = give_get_option( 'failure_page', 0 );
251
+	$failed_page = give_get_option('failure_page', 0);
252 252
 
253
-	if ( ! empty( $failed_page ) && is_page( $failed_page ) && ! empty( $_GET['payment-id'] ) ) {
253
+	if ( ! empty($failed_page) && is_page($failed_page) && ! empty($_GET['payment-id'])) {
254 254
 
255
-		$payment_id = absint( $_GET['payment-id'] );
256
-		give_update_payment_status( $payment_id, 'failed' );
255
+		$payment_id = absint($_GET['payment-id']);
256
+		give_update_payment_status($payment_id, 'failed');
257 257
 
258 258
 	}
259 259
 
260 260
 }
261 261
 
262
-add_action( 'template_redirect', 'give_listen_for_failed_payments' );
262
+add_action('template_redirect', 'give_listen_for_failed_payments');
263 263
 
264 264
 
265 265
 /**
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
  * @since       1.0
273 273
  * @return      bool
274 274
  */
275
-function give_field_is_required( $field = '', $form_id ) {
275
+function give_field_is_required($field = '', $form_id) {
276 276
 
277
-	$required_fields = give_purchase_form_required_fields( $form_id );
277
+	$required_fields = give_purchase_form_required_fields($form_id);
278 278
 
279
-	return array_key_exists( $field, $required_fields );
279
+	return array_key_exists($field, $required_fields);
280 280
 }
281 281
 
282 282
 /**
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
  *
295 295
  * @return void
296 296
  */
297
-function give_record_sale_in_log( $give_form_id = 0, $payment_id, $price_id = false, $sale_date = null ) {
297
+function give_record_sale_in_log($give_form_id = 0, $payment_id, $price_id = false, $sale_date = null) {
298 298
 	global $give_logs;
299 299
 
300 300
 	$log_data = array(
301 301
 		'post_parent'   => $give_form_id,
302 302
 		'log_type'      => 'sale',
303
-		'post_date'     => isset( $sale_date ) ? $sale_date : null,
304
-		'post_date_gmt' => isset( $sale_date ) ? $sale_date : null
303
+		'post_date'     => isset($sale_date) ? $sale_date : null,
304
+		'post_date_gmt' => isset($sale_date) ? $sale_date : null
305 305
 	);
306 306
 
307 307
 	$log_meta = array(
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		'price_id'   => (int) $price_id
310 310
 	);
311 311
 
312
-	$give_logs->insert_log( $log_data, $log_meta );
312
+	$give_logs->insert_log($log_data, $log_meta);
313 313
 }
314 314
 
315 315
 
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
  *
324 324
  * @return bool|int
325 325
  */
326
-function give_increase_purchase_count( $form_id = 0, $quantity = 1 ) {
326
+function give_increase_purchase_count($form_id = 0, $quantity = 1) {
327 327
 	$quantity = (int) $quantity;
328
-	$form     = new Give_Donate_Form( $form_id );
328
+	$form     = new Give_Donate_Form($form_id);
329 329
 
330
-	return $form->increase_sales( $quantity );
330
+	return $form->increase_sales($quantity);
331 331
 }
332 332
 
333 333
 /**
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
  *
341 341
  * @return bool|int
342 342
  */
343
-function give_decrease_purchase_count( $form_id = 0, $quantity = 1 ) {
343
+function give_decrease_purchase_count($form_id = 0, $quantity = 1) {
344 344
 	$quantity = (int) $quantity;
345
-	$form     = new Give_Donate_Form( $form_id );
345
+	$form     = new Give_Donate_Form($form_id);
346 346
 
347
-	return $form->decrease_sales( $quantity );
347
+	return $form->decrease_sales($quantity);
348 348
 }
349 349
 
350 350
 /**
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
  *
358 358
  * @return bool|int
359 359
  */
360
-function give_increase_earnings( $give_form_id = 0, $amount ) {
361
-	$form = new Give_Donate_Form( $give_form_id );
360
+function give_increase_earnings($give_form_id = 0, $amount) {
361
+	$form = new Give_Donate_Form($give_form_id);
362 362
 
363
-	return $form->increase_earnings( $amount );
363
+	return $form->increase_earnings($amount);
364 364
 }
365 365
 
366 366
 /**
@@ -373,10 +373,10 @@  discard block
 block discarded – undo
373 373
  *
374 374
  * @return bool|int
375 375
  */
376
-function give_decrease_earnings( $form_id = 0, $amount ) {
377
-	$form = new Give_Donate_Form( $form_id );
376
+function give_decrease_earnings($form_id = 0, $amount) {
377
+	$form = new Give_Donate_Form($form_id);
378 378
 
379
-	return $form->decrease_earnings( $amount );
379
+	return $form->decrease_earnings($amount);
380 380
 }
381 381
 
382 382
 
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
  *
390 390
  * @return int $earnings Earnings for a certain form
391 391
  */
392
-function give_get_form_earnings_stats( $form_id = 0 ) {
393
-	$give_form = new Give_Donate_Form( $form_id );
392
+function give_get_form_earnings_stats($form_id = 0) {
393
+	$give_form = new Give_Donate_Form($form_id);
394 394
 
395 395
 	return $give_form->earnings;
396 396
 }
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
  *
406 406
  * @return int $sales Amount of sales for a certain form
407 407
  */
408
-function give_get_form_sales_stats( $give_form_id = 0 ) {
409
-	$give_form = new Give_Donate_Form( $give_form_id );
408
+function give_get_form_sales_stats($give_form_id = 0) {
409
+	$give_form = new Give_Donate_Form($give_form_id);
410 410
 
411 411
 	return $give_form->sales;
412 412
 }
@@ -421,16 +421,16 @@  discard block
 block discarded – undo
421 421
  *
422 422
  * @return float $sales Average monthly sales
423 423
  */
424
-function give_get_average_monthly_form_sales( $form_id = 0 ) {
425
-	$sales        = give_get_form_sales_stats( $form_id );
426
-	$release_date = get_post_field( 'post_date', $form_id );
424
+function give_get_average_monthly_form_sales($form_id = 0) {
425
+	$sales        = give_get_form_sales_stats($form_id);
426
+	$release_date = get_post_field('post_date', $form_id);
427 427
 
428
-	$diff = abs( current_time( 'timestamp' ) - strtotime( $release_date ) );
428
+	$diff = abs(current_time('timestamp') - strtotime($release_date));
429 429
 
430
-	$months = floor( $diff / ( 30 * 60 * 60 * 24 ) ); // Number of months since publication
430
+	$months = floor($diff / (30 * 60 * 60 * 24)); // Number of months since publication
431 431
 
432
-	if ( $months > 0 ) {
433
-		$sales = ( $sales / $months );
432
+	if ($months > 0) {
433
+		$sales = ($sales / $months);
434 434
 	}
435 435
 
436 436
 	return $sales;
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
  *
447 447
  * @return float $earnings Average monthly earnings
448 448
  */
449
-function give_get_average_monthly_form_earnings( $form_id = 0 ) {
450
-	$earnings     = give_get_form_earnings_stats( $form_id );
451
-	$release_date = get_post_field( 'post_date', $form_id );
449
+function give_get_average_monthly_form_earnings($form_id = 0) {
450
+	$earnings     = give_get_form_earnings_stats($form_id);
451
+	$release_date = get_post_field('post_date', $form_id);
452 452
 
453
-	$diff = abs( current_time( 'timestamp' ) - strtotime( $release_date ) );
453
+	$diff = abs(current_time('timestamp') - strtotime($release_date));
454 454
 
455
-	$months = floor( $diff / ( 30 * 60 * 60 * 24 ) ); // Number of months since publication
455
+	$months = floor($diff / (30 * 60 * 60 * 24)); // Number of months since publication
456 456
 
457
-	if ( $months > 0 ) {
458
-		$earnings = ( $earnings / $months );
457
+	if ($months > 0) {
458
+		$earnings = ($earnings / $months);
459 459
 	}
460 460
 
461 461
 	return $earnings < 0 ? 0 : $earnings;
@@ -475,25 +475,25 @@  discard block
 block discarded – undo
475 475
  *
476 476
  * @return string $price_name Name of the price option
477 477
  */
478
-function give_get_price_option_name( $form_id = 0, $price_id = 0, $payment_id = 0 ) {
478
+function give_get_price_option_name($form_id = 0, $price_id = 0, $payment_id = 0) {
479 479
 
480
-	$prices     = give_get_variable_prices( $form_id );
480
+	$prices     = give_get_variable_prices($form_id);
481 481
 	$price_name = '';
482 482
 
483
-	foreach ( $prices as $price ) {
483
+	foreach ($prices as $price) {
484 484
 
485
-		if ( intval( $price['_give_id']['level_id'] ) == intval( $price_id ) ) {
485
+		if (intval($price['_give_id']['level_id']) == intval($price_id)) {
486 486
 
487
-			$price_text     = isset( $price['_give_text'] ) ? $price['_give_text'] : '';
488
-			$price_fallback = give_currency_filter( give_format_amount( $price['_give_amount'] ) );
489
-			$price_name     = ! empty( $price_text ) ? $price_text : $price_fallback;
487
+			$price_text     = isset($price['_give_text']) ? $price['_give_text'] : '';
488
+			$price_fallback = give_currency_filter(give_format_amount($price['_give_amount']));
489
+			$price_name     = ! empty($price_text) ? $price_text : $price_fallback;
490 490
 
491 491
 		}
492 492
 
493 493
 	}
494 494
 
495 495
 
496
-	return apply_filters( 'give_get_price_option_name', $price_name, $form_id, $payment_id, $price_id );
496
+	return apply_filters('give_get_price_option_name', $price_name, $form_id, $payment_id, $price_id);
497 497
 }
498 498
 
499 499
 
@@ -506,14 +506,14 @@  discard block
 block discarded – undo
506 506
  *
507 507
  * @return string $range A fully formatted price range
508 508
  */
509
-function give_price_range( $form_id = 0 ) {
510
-	$low   = give_get_lowest_price_option( $form_id );
511
-	$high  = give_get_highest_price_option( $form_id );
512
-	$range = '<span class="give_price_range_low">' . give_currency_filter( give_format_amount( $low ) ) . '</span>';
509
+function give_price_range($form_id = 0) {
510
+	$low   = give_get_lowest_price_option($form_id);
511
+	$high  = give_get_highest_price_option($form_id);
512
+	$range = '<span class="give_price_range_low">'.give_currency_filter(give_format_amount($low)).'</span>';
513 513
 	$range .= '<span class="give_price_range_sep">&nbsp;&ndash;&nbsp;</span>';
514
-	$range .= '<span class="give_price_range_high">' . give_currency_filter( give_format_amount( $high ) ) . '</span>';
514
+	$range .= '<span class="give_price_range_high">'.give_currency_filter(give_format_amount($high)).'</span>';
515 515
 
516
-	return apply_filters( 'give_price_range', $range, $form_id, $low, $high );
516
+	return apply_filters('give_price_range', $range, $form_id, $low, $high);
517 517
 }
518 518
 
519 519
 
@@ -528,36 +528,36 @@  discard block
 block discarded – undo
528 528
  *
529 529
  * @return int ID of the lowest price
530 530
  */
531
-function give_get_lowest_price_id( $form_id = 0 ) {
531
+function give_get_lowest_price_id($form_id = 0) {
532 532
 
533
-	if ( empty( $form_id ) ) {
533
+	if (empty($form_id)) {
534 534
 		$form_id = get_the_ID();
535 535
 	}
536 536
 
537
-	if ( ! give_has_variable_prices( $form_id ) ) {
538
-		return give_get_form_price( $form_id );
537
+	if ( ! give_has_variable_prices($form_id)) {
538
+		return give_get_form_price($form_id);
539 539
 	}
540 540
 
541
-	$prices = give_get_variable_prices( $form_id );
541
+	$prices = give_get_variable_prices($form_id);
542 542
 
543 543
 	$low    = 0.00;
544 544
 	$min_id = 1;
545 545
 
546
-	if ( ! empty( $prices ) ) {
546
+	if ( ! empty($prices)) {
547 547
 
548
-		foreach ( $prices as $key => $price ) {
548
+		foreach ($prices as $key => $price) {
549 549
 
550
-			if ( empty( $price['_give_amount'] ) ) {
550
+			if (empty($price['_give_amount'])) {
551 551
 				continue;
552 552
 			}
553 553
 
554
-			if ( ! isset( $min ) ) {
554
+			if ( ! isset($min)) {
555 555
 				$min = $price['_give_amount'];
556 556
 			} else {
557
-				$min = min( $min, $price['_give_amount'] );
557
+				$min = min($min, $price['_give_amount']);
558 558
 			}
559 559
 
560
-			if ( $price['_give_amount'] == $min ) {
560
+			if ($price['_give_amount'] == $min) {
561 561
 				$min_id = $price['_give_id']['level_id'];
562 562
 			}
563 563
 		}
@@ -575,43 +575,43 @@  discard block
 block discarded – undo
575 575
  *
576 576
  * @return float Amount of the lowest price
577 577
  */
578
-function give_get_lowest_price_option( $form_id = 0 ) {
579
-	if ( empty( $form_id ) ) {
578
+function give_get_lowest_price_option($form_id = 0) {
579
+	if (empty($form_id)) {
580 580
 		$form_id = get_the_ID();
581 581
 	}
582 582
 
583
-	if ( ! give_has_variable_prices( $form_id ) ) {
584
-		return give_get_form_price( $form_id );
583
+	if ( ! give_has_variable_prices($form_id)) {
584
+		return give_get_form_price($form_id);
585 585
 	}
586 586
 
587
-	$prices = give_get_variable_prices( $form_id );
587
+	$prices = give_get_variable_prices($form_id);
588 588
 
589 589
 	$low = 0.00;
590 590
 
591
-	if ( ! empty( $prices ) ) {
591
+	if ( ! empty($prices)) {
592 592
 
593
-		foreach ( $prices as $key => $price ) {
593
+		foreach ($prices as $key => $price) {
594 594
 
595
-			if ( empty( $price['_give_amount'] ) ) {
595
+			if (empty($price['_give_amount'])) {
596 596
 				continue;
597 597
 			}
598 598
 
599
-			if ( ! isset( $min ) ) {
599
+			if ( ! isset($min)) {
600 600
 				$min = $price['_give_amount'];
601 601
 			} else {
602
-				$min = min( $min, give_sanitize_amount( $price['_give_amount'] ) );
602
+				$min = min($min, give_sanitize_amount($price['_give_amount']));
603 603
 			}
604 604
 
605
-			if ( $price['_give_amount'] == $min ) {
605
+			if ($price['_give_amount'] == $min) {
606 606
 				$min_id = $key;
607 607
 			}
608 608
 		}
609 609
 
610
-		$low = $prices[ $min_id ]['_give_amount'];
610
+		$low = $prices[$min_id]['_give_amount'];
611 611
 
612 612
 	}
613 613
 
614
-	return give_sanitize_amount( $low );
614
+	return give_sanitize_amount($low);
615 615
 }
616 616
 
617 617
 /**
@@ -623,41 +623,41 @@  discard block
 block discarded – undo
623 623
  *
624 624
  * @return float Amount of the highest price
625 625
  */
626
-function give_get_highest_price_option( $form_id = 0 ) {
626
+function give_get_highest_price_option($form_id = 0) {
627 627
 
628
-	if ( empty( $form_id ) ) {
628
+	if (empty($form_id)) {
629 629
 		$form_id = get_the_ID();
630 630
 	}
631 631
 
632
-	if ( ! give_has_variable_prices( $form_id ) ) {
633
-		return give_get_form_price( $form_id );
632
+	if ( ! give_has_variable_prices($form_id)) {
633
+		return give_get_form_price($form_id);
634 634
 	}
635 635
 
636
-	$prices = give_get_variable_prices( $form_id );
636
+	$prices = give_get_variable_prices($form_id);
637 637
 
638 638
 	$high = 0.00;
639 639
 
640
-	if ( ! empty( $prices ) ) {
640
+	if ( ! empty($prices)) {
641 641
 
642 642
 		$max = 0;
643 643
 
644
-		foreach ( $prices as $key => $price ) {
645
-			if ( empty( $price['_give_amount'] ) ) {
644
+		foreach ($prices as $key => $price) {
645
+			if (empty($price['_give_amount'])) {
646 646
 				continue;
647 647
 			}
648
-			$give_amount = give_sanitize_amount( $price['_give_amount'] );
648
+			$give_amount = give_sanitize_amount($price['_give_amount']);
649 649
 
650
-			$max = max( $max, $give_amount );
650
+			$max = max($max, $give_amount);
651 651
 
652
-			if ( $give_amount == $max ) {
652
+			if ($give_amount == $max) {
653 653
 				$max_id = $key;
654 654
 			}
655 655
 		}
656 656
 
657
-		$high = $prices[ $max_id ]['_give_amount'];
657
+		$high = $prices[$max_id]['_give_amount'];
658 658
 	}
659 659
 
660
-	return give_sanitize_amount( $high );
660
+	return give_sanitize_amount($high);
661 661
 }
662 662
 
663 663
 /**
@@ -669,15 +669,15 @@  discard block
 block discarded – undo
669 669
  *
670 670
  * @return mixed string|int Price of the form
671 671
  */
672
-function give_get_form_price( $form_id = 0 ) {
672
+function give_get_form_price($form_id = 0) {
673 673
 
674
-	if ( empty( $form_id ) ) {
674
+	if (empty($form_id)) {
675 675
 		return false;
676 676
 	}
677 677
 
678
-	$form = new Give_Donate_Form( $form_id );
678
+	$form = new Give_Donate_Form($form_id);
679 679
 
680
-	return $form->__get( 'price' );
680
+	return $form->__get('price');
681 681
 }
682 682
 
683 683
 /**
@@ -689,15 +689,15 @@  discard block
 block discarded – undo
689 689
  *
690 690
  * @return mixed string|int Minimum price of the form
691 691
  */
692
-function give_get_form_minimum_price( $form_id = 0 ) {
692
+function give_get_form_minimum_price($form_id = 0) {
693 693
 
694
-	if ( empty( $form_id ) ) {
694
+	if (empty($form_id)) {
695 695
 		return false;
696 696
 	}
697 697
 
698
-	$form = new Give_Donate_Form( $form_id );
698
+	$form = new Give_Donate_Form($form_id);
699 699
 
700
-	return $form->__get( 'minimum_price' );
700
+	return $form->__get('minimum_price');
701 701
 
702 702
 }
703 703
 
@@ -712,52 +712,52 @@  discard block
 block discarded – undo
712 712
  *
713 713
  * @return int $formatted_price
714 714
  */
715
-function give_price( $form_id = 0, $echo = true, $price_id = false ) {
715
+function give_price($form_id = 0, $echo = true, $price_id = false) {
716 716
 
717
-	if ( empty( $form_id ) ) {
717
+	if (empty($form_id)) {
718 718
 		$form_id = get_the_ID();
719 719
 	}
720 720
 
721
-	if ( give_has_variable_prices( $form_id ) ) {
721
+	if (give_has_variable_prices($form_id)) {
722 722
 
723
-		$prices = give_get_variable_prices( $form_id );
723
+		$prices = give_get_variable_prices($form_id);
724 724
 
725
-		if ( false !== $price_id ) {
725
+		if (false !== $price_id) {
726 726
 
727 727
 			//loop through multi-prices to see which is default
728
-			foreach ( $prices as $price ) {
728
+			foreach ($prices as $price) {
729 729
 				//this is the default price
730
-				if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
730
+				if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
731 731
 					$price = (float) $price['_give_amount'];
732 732
 				};
733 733
 			}
734 734
 
735 735
 		} else {
736 736
 
737
-			$price = give_get_lowest_price_option( $form_id );
737
+			$price = give_get_lowest_price_option($form_id);
738 738
 		}
739 739
 
740
-		$price = give_sanitize_amount( $price );
740
+		$price = give_sanitize_amount($price);
741 741
 
742 742
 	} else {
743 743
 
744
-		$price = give_get_form_price( $form_id );
744
+		$price = give_get_form_price($form_id);
745 745
 
746 746
 	}
747 747
 
748
-	$price           = apply_filters( 'give_form_price', give_sanitize_amount( $price ), $form_id );
749
-	$formatted_price = '<span class="give_price" id="give_price_' . $form_id . '">' . $price . '</span>';
750
-	$formatted_price = apply_filters( 'give_form_price_after_html', $formatted_price, $form_id, $price );
748
+	$price           = apply_filters('give_form_price', give_sanitize_amount($price), $form_id);
749
+	$formatted_price = '<span class="give_price" id="give_price_'.$form_id.'">'.$price.'</span>';
750
+	$formatted_price = apply_filters('give_form_price_after_html', $formatted_price, $form_id, $price);
751 751
 
752
-	if ( $echo ) {
752
+	if ($echo) {
753 753
 		echo $formatted_price;
754 754
 	} else {
755 755
 		return $formatted_price;
756 756
 	}
757 757
 }
758 758
 
759
-add_filter( 'give_form_price', 'give_format_amount', 10 );
760
-add_filter( 'give_form_price', 'give_currency_filter', 20 );
759
+add_filter('give_form_price', 'give_format_amount', 10);
760
+add_filter('give_form_price', 'give_currency_filter', 20);
761 761
 
762 762
 
763 763
 /**
@@ -771,18 +771,18 @@  discard block
 block discarded – undo
771 771
  *
772 772
  * @return float $amount Amount of the price option
773 773
  */
774
-function give_get_price_option_amount( $form_id = 0, $price_id = 0 ) {
775
-	$prices = give_get_variable_prices( $form_id );
774
+function give_get_price_option_amount($form_id = 0, $price_id = 0) {
775
+	$prices = give_get_variable_prices($form_id);
776 776
 
777 777
 	$amount = 0.00;
778 778
 
779
-	foreach ( $prices as $price ) {
780
-		if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] === $price_id ) {
781
-			$amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00;
779
+	foreach ($prices as $price) {
780
+		if (isset($price['_give_id']['level_id']) && $price['_give_id']['level_id'] === $price_id) {
781
+			$amount = isset($price['_give_amount']) ? $price['_give_amount'] : 0.00;
782 782
 		};
783 783
 	}
784 784
 
785
-	return apply_filters( 'give_get_price_option_amount', give_sanitize_amount( $amount ), $form_id, $price_id );
785
+	return apply_filters('give_get_price_option_amount', give_sanitize_amount($amount), $form_id, $price_id);
786 786
 }
787 787
 
788 788
 /**
@@ -794,13 +794,13 @@  discard block
 block discarded – undo
794 794
  *
795 795
  * @return mixed string|int Goal of the form
796 796
  */
797
-function give_get_form_goal( $form_id = 0 ) {
797
+function give_get_form_goal($form_id = 0) {
798 798
 
799
-	if ( empty( $form_id ) ) {
799
+	if (empty($form_id)) {
800 800
 		return false;
801 801
 	}
802 802
 
803
-	$form = new Give_Donate_Form( $form_id );
803
+	$form = new Give_Donate_Form($form_id);
804 804
 
805 805
 	return $form->goal;
806 806
 
@@ -816,27 +816,27 @@  discard block
 block discarded – undo
816 816
  *
817 817
  * @return string $formatted_goal
818 818
  */
819
-function give_goal( $form_id = 0, $echo = true ) {
819
+function give_goal($form_id = 0, $echo = true) {
820 820
 
821
-	if ( empty( $form_id ) ) {
821
+	if (empty($form_id)) {
822 822
 		$form_id = get_the_ID();
823 823
 	}
824 824
 
825
-	$goal = give_get_form_goal( $form_id );
825
+	$goal = give_get_form_goal($form_id);
826 826
 
827
-	$goal           = apply_filters( 'give_form_goal', give_sanitize_amount( $goal ), $form_id );
828
-	$formatted_goal = '<span class="give_price" id="give_price_' . $form_id . '">' . $goal . '</span>';
829
-	$formatted_goal = apply_filters( 'give_form_price_after_html', $formatted_goal, $form_id, $goal );
827
+	$goal           = apply_filters('give_form_goal', give_sanitize_amount($goal), $form_id);
828
+	$formatted_goal = '<span class="give_price" id="give_price_'.$form_id.'">'.$goal.'</span>';
829
+	$formatted_goal = apply_filters('give_form_price_after_html', $formatted_goal, $form_id, $goal);
830 830
 
831
-	if ( $echo ) {
831
+	if ($echo) {
832 832
 		echo $formatted_goal;
833 833
 	} else {
834 834
 		return $formatted_goal;
835 835
 	}
836 836
 }
837 837
 
838
-add_filter( 'give_form_goal', 'give_format_amount', 10 );
839
-add_filter( 'give_form_goal', 'give_currency_filter', 20 );
838
+add_filter('give_form_goal', 'give_format_amount', 10);
839
+add_filter('give_form_goal', 'give_currency_filter', 20);
840 840
 
841 841
 
842 842
 /**
@@ -846,13 +846,13 @@  discard block
 block discarded – undo
846 846
  * @global $give_options
847 847
  * @return bool $ret Whether or not the logged_in_only setting is set
848 848
  */
849
-function give_logged_in_only( $form_id ) {
849
+function give_logged_in_only($form_id) {
850 850
 
851
-	$form_option = get_post_meta( $form_id, '_give_logged_in_only', true );
851
+	$form_option = get_post_meta($form_id, '_give_logged_in_only', true);
852 852
 
853
-	$ret = ! empty( $form_option ) ? $form_option : false;
853
+	$ret = ! empty($form_option) ? $form_option : false;
854 854
 
855
-	return (bool) apply_filters( 'give_logged_in_only', $ret, $form_id );
855
+	return (bool) apply_filters('give_logged_in_only', $ret, $form_id);
856 856
 
857 857
 }
858 858
 
@@ -864,10 +864,10 @@  discard block
 block discarded – undo
864 864
  *
865 865
  * @param $form_id
866 866
  */
867
-function give_show_login_register_option( $form_id ) {
867
+function give_show_login_register_option($form_id) {
868 868
 
869
-	$show_register_form = get_post_meta( $form_id, '_give_show_register_form', true );
869
+	$show_register_form = get_post_meta($form_id, '_give_show_register_form', true);
870 870
 
871
-	return apply_filters( 'give_show_register_form', $show_register_form, $form_id );
871
+	return apply_filters('give_show_register_form', $show_register_form, $form_id);
872 872
 
873 873
 }
874 874
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-give-stats.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function get_predefined_dates() {
78 78
 		$predefined = array(
79
-			'today'        => __( 'Today', 'give' ),
80
-			'yesterday'    => __( 'Yesterday', 'give' ),
81
-			'this_week'    => __( 'This Week', 'give' ),
82
-			'last_week'    => __( 'Last Week', 'give' ),
83
-			'this_month'   => __( 'This Month', 'give' ),
84
-			'last_month'   => __( 'Last Month', 'give' ),
85
-			'this_quarter' => __( 'This Quarter', 'give' ),
86
-			'last_quarter' => __( 'Last Quarter', 'give' ),
87
-			'this_year'    => __( 'This Year', 'give' ),
88
-			'last_year'    => __( 'Last Year', 'give' )
79
+			'today'        => __('Today', 'give'),
80
+			'yesterday'    => __('Yesterday', 'give'),
81
+			'this_week'    => __('This Week', 'give'),
82
+			'last_week'    => __('Last Week', 'give'),
83
+			'this_month'   => __('This Month', 'give'),
84
+			'last_month'   => __('Last Month', 'give'),
85
+			'this_quarter' => __('This Quarter', 'give'),
86
+			'last_quarter' => __('Last Quarter', 'give'),
87
+			'this_year'    => __('This Year', 'give'),
88
+			'last_year'    => __('Last Year', 'give')
89 89
 		);
90 90
 
91
-		return apply_filters( 'give_stats_predefined_dates', $predefined );
91
+		return apply_filters('give_stats_predefined_dates', $predefined);
92 92
 	}
93 93
 
94 94
 	/**
@@ -104,18 +104,18 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return void
106 106
 	 */
107
-	public function setup_dates( $_start_date = 'this_month', $_end_date = false ) {
107
+	public function setup_dates($_start_date = 'this_month', $_end_date = false) {
108 108
 
109
-		if ( empty( $_start_date ) ) {
109
+		if (empty($_start_date)) {
110 110
 			$_start_date = 'this_month';
111 111
 		}
112 112
 
113
-		if ( empty( $_end_date ) ) {
113
+		if (empty($_end_date)) {
114 114
 			$_end_date = $_start_date;
115 115
 		}
116 116
 
117
-		$this->start_date = $this->convert_date( $_start_date );
118
-		$this->end_date   = $this->convert_date( $_end_date, true );
117
+		$this->start_date = $this->convert_date($_start_date);
118
+		$this->end_date   = $this->convert_date($_end_date, true);
119 119
 	}
120 120
 
121 121
 	/**
@@ -125,26 +125,26 @@  discard block
 block discarded – undo
125 125
 	 * @since  1.0
126 126
 	 * @return array|WP_Error If the date is invalid, a WP_Error object will be returned
127 127
 	 */
128
-	public function convert_date( $date, $end_date = false ) {
128
+	public function convert_date($date, $end_date = false) {
129 129
 
130 130
 		$this->timestamp = false;
131 131
 		$second          = $end_date ? 59 : 0;
132 132
 		$minute          = $end_date ? 59 : 0;
133 133
 		$hour            = $end_date ? 23 : 0;
134 134
 		$day             = 1;
135
-		$month           = date( 'n', current_time( 'timestamp' ) );
136
-		$year            = date( 'Y', current_time( 'timestamp' ) );
135
+		$month           = date('n', current_time('timestamp'));
136
+		$year            = date('Y', current_time('timestamp'));
137 137
 
138
-		if ( array_key_exists( $date, $this->get_predefined_dates() ) ) {
138
+		if (array_key_exists($date, $this->get_predefined_dates())) {
139 139
 
140 140
 			// This is a predefined date rate, such as last_week
141
-			switch ( $date ) {
141
+			switch ($date) {
142 142
 
143 143
 				case 'this_month' :
144 144
 
145
-					if ( $end_date ) {
145
+					if ($end_date) {
146 146
 
147
-						$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
147
+						$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
148 148
 						$hour   = 23;
149 149
 						$minute = 59;
150 150
 						$second = 59;
@@ -154,28 +154,28 @@  discard block
 block discarded – undo
154 154
 
155 155
 				case 'last_month' :
156 156
 
157
-					if ( $month == 1 ) {
157
+					if ($month == 1) {
158 158
 
159 159
 						$month = 12;
160
-						$year --;
160
+						$year--;
161 161
 
162 162
 					} else {
163 163
 
164
-						$month --;
164
+						$month--;
165 165
 
166 166
 					}
167 167
 
168
-					if ( $end_date ) {
169
-						$day = cal_days_in_month( CAL_GREGORIAN, $month, $year );
168
+					if ($end_date) {
169
+						$day = cal_days_in_month(CAL_GREGORIAN, $month, $year);
170 170
 					}
171 171
 
172 172
 					break;
173 173
 
174 174
 				case 'today' :
175 175
 
176
-					$day = date( 'd', current_time( 'timestamp' ) );
176
+					$day = date('d', current_time('timestamp'));
177 177
 
178
-					if ( $end_date ) {
178
+					if ($end_date) {
179 179
 						$hour   = 23;
180 180
 						$minute = 59;
181 181
 						$second = 59;
@@ -185,23 +185,23 @@  discard block
 block discarded – undo
185 185
 
186 186
 				case 'yesterday' :
187 187
 
188
-					$day = date( 'd', current_time( 'timestamp' ) ) - 1;
188
+					$day = date('d', current_time('timestamp')) - 1;
189 189
 
190 190
 					// Check if Today is the first day of the month (meaning subtracting one will get us 0)
191
-					if ( $day < 1 ) {
191
+					if ($day < 1) {
192 192
 
193 193
 						// If current month is 1
194
-						if ( 1 == $month ) {
194
+						if (1 == $month) {
195 195
 
196 196
 							$year -= 1; // Today is January 1, so skip back to last day of December
197 197
 							$month = 12;
198
-							$day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );
198
+							$day   = cal_days_in_month(CAL_GREGORIAN, $month, $year);
199 199
 
200 200
 						} else {
201 201
 
202 202
 							// Go back one month and get the last day of the month
203 203
 							$month -= 1;
204
-							$day = cal_days_in_month( CAL_GREGORIAN, $month, $year );
204
+							$day = cal_days_in_month(CAL_GREGORIAN, $month, $year);
205 205
 
206 206
 						}
207 207
 					}
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
 
211 211
 				case 'this_week' :
212 212
 
213
-					$days_to_week_start = ( date( 'w', current_time( 'timestamp' ) ) - 1 ) * 60 * 60 * 24;
214
-					$today              = date( 'd', current_time( 'timestamp' ) ) * 60 * 60 * 24;
213
+					$days_to_week_start = (date('w', current_time('timestamp')) - 1) * 60 * 60 * 24;
214
+					$today              = date('d', current_time('timestamp')) * 60 * 60 * 24;
215 215
 
216
-					if ( $today < $days_to_week_start ) {
216
+					if ($today < $days_to_week_start) {
217 217
 
218
-						if ( $month > 1 ) {
218
+						if ($month > 1) {
219 219
 							$month -= 1;
220 220
 						} else {
221 221
 							$month = 12;
@@ -223,19 +223,19 @@  discard block
 block discarded – undo
223 223
 
224 224
 					}
225 225
 
226
-					if ( ! $end_date ) {
226
+					if ( ! $end_date) {
227 227
 
228 228
 						// Getting the start day
229 229
 
230
-						$day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 1;
231
-						$day += get_option( 'start_of_week' );
230
+						$day = date('d', current_time('timestamp') - $days_to_week_start) - 1;
231
+						$day += get_option('start_of_week');
232 232
 
233 233
 					} else {
234 234
 
235 235
 						// Getting the end day
236 236
 
237
-						$day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 1;
238
-						$day += get_option( 'start_of_week' ) + 6;
237
+						$day = date('d', current_time('timestamp') - $days_to_week_start) - 1;
238
+						$day += get_option('start_of_week') + 6;
239 239
 
240 240
 					}
241 241
 
@@ -243,12 +243,12 @@  discard block
 block discarded – undo
243 243
 
244 244
 				case 'last_week' :
245 245
 
246
-					$days_to_week_start = ( date( 'w', current_time( 'timestamp' ) ) - 1 ) * 60 * 60 * 24;
247
-					$today              = date( 'd', current_time( 'timestamp' ) ) * 60 * 60 * 24;
246
+					$days_to_week_start = (date('w', current_time('timestamp')) - 1) * 60 * 60 * 24;
247
+					$today              = date('d', current_time('timestamp')) * 60 * 60 * 24;
248 248
 
249
-					if ( $today < $days_to_week_start ) {
249
+					if ($today < $days_to_week_start) {
250 250
 
251
-						if ( $month > 1 ) {
251
+						if ($month > 1) {
252 252
 							$month -= 1;
253 253
 						} else {
254 254
 							$month = 12;
@@ -256,19 +256,19 @@  discard block
 block discarded – undo
256 256
 
257 257
 					}
258 258
 
259
-					if ( ! $end_date ) {
259
+					if ( ! $end_date) {
260 260
 
261 261
 						// Getting the start day
262 262
 
263
-						$day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 8;
264
-						$day += get_option( 'start_of_week' );
263
+						$day = date('d', current_time('timestamp') - $days_to_week_start) - 8;
264
+						$day += get_option('start_of_week');
265 265
 
266 266
 					} else {
267 267
 
268 268
 						// Getting the end day
269 269
 
270
-						$day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 8;
271
-						$day += get_option( 'start_of_week' ) + 6;
270
+						$day = date('d', current_time('timestamp') - $days_to_week_start) - 8;
271
+						$day += get_option('start_of_week') + 6;
272 272
 
273 273
 					}
274 274
 
@@ -276,39 +276,39 @@  discard block
 block discarded – undo
276 276
 
277 277
 				case 'this_quarter' :
278 278
 
279
-					$month_now = date( 'n', current_time( 'timestamp' ) );
279
+					$month_now = date('n', current_time('timestamp'));
280 280
 
281
-					if ( $month_now <= 3 ) {
281
+					if ($month_now <= 3) {
282 282
 
283
-						if ( ! $end_date ) {
283
+						if ( ! $end_date) {
284 284
 							$month = 1;
285 285
 						} else {
286 286
 							$month  = 3;
287
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
287
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
288 288
 							$hour   = 23;
289 289
 							$minute = 59;
290 290
 							$second = 59;
291 291
 						}
292 292
 
293
-					} else if ( $month_now <= 6 ) {
293
+					} else if ($month_now <= 6) {
294 294
 
295
-						if ( ! $end_date ) {
295
+						if ( ! $end_date) {
296 296
 							$month = 4;
297 297
 						} else {
298 298
 							$month  = 6;
299
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
299
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
300 300
 							$hour   = 23;
301 301
 							$minute = 59;
302 302
 							$second = 59;
303 303
 						}
304 304
 
305
-					} else if ( $month_now <= 9 ) {
305
+					} else if ($month_now <= 9) {
306 306
 
307
-						if ( ! $end_date ) {
307
+						if ( ! $end_date) {
308 308
 							$month = 7;
309 309
 						} else {
310 310
 							$month  = 9;
311
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
311
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
312 312
 							$hour   = 23;
313 313
 							$minute = 59;
314 314
 							$second = 59;
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
 
317 317
 					} else {
318 318
 
319
-						if ( ! $end_date ) {
319
+						if ( ! $end_date) {
320 320
 							$month = 10;
321 321
 						} else {
322 322
 							$month  = 12;
323
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
323
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
324 324
 							$hour   = 23;
325 325
 							$minute = 59;
326 326
 							$second = 59;
@@ -332,40 +332,40 @@  discard block
 block discarded – undo
332 332
 
333 333
 				case 'last_quarter' :
334 334
 
335
-					$month_now = date( 'n', current_time( 'timestamp' ) );
335
+					$month_now = date('n', current_time('timestamp'));
336 336
 
337
-					if ( $month_now <= 3 ) {
337
+					if ($month_now <= 3) {
338 338
 
339
-						if ( ! $end_date ) {
339
+						if ( ! $end_date) {
340 340
 							$month = 10;
341 341
 						} else {
342 342
 							$year -= 1;
343 343
 							$month  = 12;
344
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
344
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
345 345
 							$hour   = 23;
346 346
 							$minute = 59;
347 347
 							$second = 59;
348 348
 						}
349 349
 
350
-					} else if ( $month_now <= 6 ) {
350
+					} else if ($month_now <= 6) {
351 351
 
352
-						if ( ! $end_date ) {
352
+						if ( ! $end_date) {
353 353
 							$month = 1;
354 354
 						} else {
355 355
 							$month  = 3;
356
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
356
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
357 357
 							$hour   = 23;
358 358
 							$minute = 59;
359 359
 							$second = 59;
360 360
 						}
361 361
 
362
-					} else if ( $month_now <= 9 ) {
362
+					} else if ($month_now <= 9) {
363 363
 
364
-						if ( ! $end_date ) {
364
+						if ( ! $end_date) {
365 365
 							$month = 4;
366 366
 						} else {
367 367
 							$month  = 6;
368
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
368
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
369 369
 							$hour   = 23;
370 370
 							$minute = 59;
371 371
 							$second = 59;
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
 
374 374
 					} else {
375 375
 
376
-						if ( ! $end_date ) {
376
+						if ( ! $end_date) {
377 377
 							$month = 7;
378 378
 						} else {
379 379
 							$month  = 9;
380
-							$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
380
+							$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
381 381
 							$hour   = 23;
382 382
 							$minute = 59;
383 383
 							$second = 59;
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 
390 390
 				case 'this_year' :
391 391
 
392
-					if ( ! $end_date ) {
392
+					if ( ! $end_date) {
393 393
 						$month = 1;
394 394
 					} else {
395 395
 						$month  = 12;
396
-						$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
396
+						$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
397 397
 						$hour   = 23;
398 398
 						$minute = 59;
399 399
 						$second = 59;
@@ -404,11 +404,11 @@  discard block
 block discarded – undo
404 404
 				case 'last_year' :
405 405
 
406 406
 					$year -= 1;
407
-					if ( ! $end_date ) {
407
+					if ( ! $end_date) {
408 408
 						$month = 1;
409 409
 					} else {
410 410
 						$month  = 12;
411
-						$day    = cal_days_in_month( CAL_GREGORIAN, $month, $year );
411
+						$day    = cal_days_in_month(CAL_GREGORIAN, $month, $year);
412 412
 						$hour   = 23;
413 413
 						$minute = 59;
414 414
 						$second = 59;
@@ -419,30 +419,30 @@  discard block
 block discarded – undo
419 419
 			}
420 420
 
421 421
 
422
-		} else if ( is_numeric( $date ) ) {
422
+		} else if (is_numeric($date)) {
423 423
 
424 424
 			// return $date unchanged since it is a timestamp
425 425
 			$this->timestamp = true;
426 426
 
427
-		} else if ( false !== strtotime( $date ) ) {
427
+		} else if (false !== strtotime($date)) {
428 428
 
429
-			$date  = strtotime( $date, current_time( 'timestamp' ) );
430
-			$year  = date( 'Y', $date );
431
-			$month = date( 'm', $date );
432
-			$day   = date( 'd', $date );
429
+			$date  = strtotime($date, current_time('timestamp'));
430
+			$year  = date('Y', $date);
431
+			$month = date('m', $date);
432
+			$day   = date('d', $date);
433 433
 
434 434
 		} else {
435 435
 
436
-			return new WP_Error( 'invalid_date', __( 'Improper date provided.', 'give' ) );
436
+			return new WP_Error('invalid_date', __('Improper date provided.', 'give'));
437 437
 
438 438
 		}
439 439
 
440
-		if ( false === $this->timestamp ) {
440
+		if (false === $this->timestamp) {
441 441
 			// Create an exact timestamp
442
-			$date = mktime( $hour, $minute, $second, $month, $day, $year );
442
+			$date = mktime($hour, $minute, $second, $month, $day, $year);
443 443
 		}
444 444
 
445
-		return apply_filters( 'give_stats_date', $date, $end_date, $this );
445
+		return apply_filters('give_stats_date', $date, $end_date, $this);
446 446
 
447 447
 	}
448 448
 
@@ -453,33 +453,33 @@  discard block
 block discarded – undo
453 453
 	 * @since  1.0
454 454
 	 * @return string
455 455
 	 */
456
-	public function count_where( $where = '' ) {
456
+	public function count_where($where = '') {
457 457
 		// Only get payments in our date range
458 458
 
459 459
 		$start_where = '';
460 460
 		$end_where   = '';
461 461
 
462
-		if ( $this->start_date ) {
462
+		if ($this->start_date) {
463 463
 
464
-			if ( $this->timestamp ) {
464
+			if ($this->timestamp) {
465 465
 				$format = 'Y-m-d H:i:s';
466 466
 			} else {
467 467
 				$format = 'Y-m-d 00:00:00';
468 468
 			}
469 469
 
470
-			$start_date  = date( $format, $this->start_date );
470
+			$start_date  = date($format, $this->start_date);
471 471
 			$start_where = " AND p.post_date >= '{$start_date}'";
472 472
 		}
473 473
 
474
-		if ( $this->end_date ) {
474
+		if ($this->end_date) {
475 475
 
476
-			if ( $this->timestamp ) {
476
+			if ($this->timestamp) {
477 477
 				$format = 'Y-m-d H:i:s';
478 478
 			} else {
479 479
 				$format = 'Y-m-d 23:59:59';
480 480
 			}
481 481
 
482
-			$end_date = date( $format, $this->end_date );
482
+			$end_date = date($format, $this->end_date);
483 483
 
484 484
 			$end_where = " AND p.post_date <= '{$end_date}'";
485 485
 		}
@@ -499,34 +499,34 @@  discard block
 block discarded – undo
499 499
 	 *
500 500
 	 * @return string
501 501
 	 */
502
-	public function payments_where( $where = '' ) {
502
+	public function payments_where($where = '') {
503 503
 
504 504
 		global $wpdb;
505 505
 
506 506
 		$start_where = '';
507 507
 		$end_where   = '';
508 508
 
509
-		if ( ! is_wp_error( $this->start_date ) ) {
509
+		if ( ! is_wp_error($this->start_date)) {
510 510
 
511
-			if ( $this->timestamp ) {
511
+			if ($this->timestamp) {
512 512
 				$format = 'Y-m-d H:i:s';
513 513
 			} else {
514 514
 				$format = 'Y-m-d 00:00:00';
515 515
 			}
516 516
 
517
-			$start_date  = date( $format, $this->start_date );
517
+			$start_date  = date($format, $this->start_date);
518 518
 			$start_where = " AND $wpdb->posts.post_date >= '{$start_date}'";
519 519
 		}
520 520
 
521
-		if ( ! is_wp_error( $this->end_date ) ) {
521
+		if ( ! is_wp_error($this->end_date)) {
522 522
 
523
-			if ( $this->timestamp ) {
523
+			if ($this->timestamp) {
524 524
 				$format = 'Y-m-d 00:00:00';
525 525
 			} else {
526 526
 				$format = 'Y-m-d 23:59:59';
527 527
 			}
528 528
 
529
-			$end_date = date( $format, $this->end_date );
529
+			$end_date = date($format, $this->end_date);
530 530
 
531 531
 			$end_where = " AND $wpdb->posts.post_date <= '{$end_date}'";
532 532
 		}
Please login to merge, or discard this patch.
includes/gateways/paypal-standard.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since       1.0
10 10
  */
11 11
 
12
-if ( ! defined( 'ABSPATH' ) ) {
12
+if ( ! defined('ABSPATH')) {
13 13
 	exit;
14 14
 }
15 15
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  * @access private
22 22
  * @since  1.0
23 23
  */
24
-add_action( 'give_paypal_cc_form', '__return_false' );
24
+add_action('give_paypal_cc_form', '__return_false');
25 25
 
26 26
 /**
27 27
  * Process PayPal Purchase
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  *
33 33
  * @return void
34 34
  */
35
-function give_process_paypal_purchase( $purchase_data ) {
35
+function give_process_paypal_purchase($purchase_data) {
36 36
 
37
-	if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) {
38
-		wp_die( __( 'Nonce verification has failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
37
+	if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
38
+		wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403));
39 39
 	}
40 40
 
41
-	$form_id = intval( $purchase_data['post_data']['give-form-id'] );
41
+	$form_id = intval($purchase_data['post_data']['give-form-id']);
42 42
 
43 43
 	// Collect payment data
44 44
 	$payment_data = array(
@@ -56,59 +56,59 @@  discard block
 block discarded – undo
56 56
 	);
57 57
 
58 58
 	// Record the pending payment
59
-	$payment = give_insert_payment( $payment_data );
59
+	$payment = give_insert_payment($payment_data);
60 60
 
61 61
 	// Check payment
62
-	if ( ! $payment ) {
62
+	if ( ! $payment) {
63 63
 		// Record the error
64
-		give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment );
64
+		give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
65 65
 		// Problems? send back
66
-		give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
66
+		give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']);
67 67
 	} else {
68 68
 		// Only send to PayPal if the pending payment is created successfully
69
-		$listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) );
69
+		$listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
70 70
 
71 71
 		// Get the success url
72
-		$return_url = add_query_arg( array(
72
+		$return_url = add_query_arg(array(
73 73
 			'payment-confirmation' => 'paypal',
74 74
 			'payment-id'           => $payment
75 75
 
76
-		), get_permalink( give_get_option( 'success_page' ) ) );
76
+		), get_permalink(give_get_option('success_page')));
77 77
 
78 78
 		// Get the PayPal redirect uri
79
-		$paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?';
79
+		$paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?';
80 80
 
81 81
 		//Item name - pass level name if variable priced
82 82
 		$item_name = $purchase_data['post_data']['give-form-title'];
83 83
 
84 84
 		//Verify has variable prices
85
-		if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) {
85
+		if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) {
86 86
 
87
-			$item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] );
87
+			$item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']);
88 88
 
89
-			$price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] );
89
+			$price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']);
90 90
 
91 91
 			//Donation given doesn't match selected level (must be a custom amount)
92
-			if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) {
93
-				$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
92
+			if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) {
93
+				$custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
94 94
 				//user custom amount text if any, fallback to default if not
95
-				$item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) );
95
+				$item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'));
96 96
 
97 97
 			} //Is there any donation level text?
98
-			elseif ( ! empty( $item_price_level_text ) ) {
99
-				$item_name .= ' - ' . $item_price_level_text;
98
+			elseif ( ! empty($item_price_level_text)) {
99
+				$item_name .= ' - '.$item_price_level_text;
100 100
 			}
101 101
 
102 102
 		} //Single donation: Custom Amount
103
-		elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) {
104
-			$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
103
+		elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) {
104
+			$custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
105 105
 			//user custom amount text if any, fallback to default if not
106
-			$item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) );
106
+			$item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'));
107 107
 		}
108 108
 
109 109
 		// Setup PayPal arguments
110 110
 		$paypal_args = array(
111
-			'business'      => give_get_option( 'paypal_email', false ),
111
+			'business'      => give_get_option('paypal_email', false),
112 112
 			'email'         => $purchase_data['user_email'],
113 113
 			'invoice'       => $purchase_data['purchase_key'],
114 114
 			'amount'        => $purchase_data['price'],
@@ -119,25 +119,25 @@  discard block
 block discarded – undo
119 119
 			'shipping'      => '0',
120 120
 			'no_note'       => '1',
121 121
 			'currency_code' => give_get_currency(),
122
-			'charset'       => get_bloginfo( 'charset' ),
122
+			'charset'       => get_bloginfo('charset'),
123 123
 			'custom'        => $payment,
124 124
 			'rm'            => '2',
125 125
 			'return'        => $return_url,
126
-			'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ),
126
+			'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment),
127 127
 			'notify_url'    => $listener_url,
128 128
 			'page_style'    => give_get_paypal_page_style(),
129
-			'cbt'           => get_bloginfo( 'name' ),
129
+			'cbt'           => get_bloginfo('name'),
130 130
 			'bn'            => 'givewp_SP'
131 131
 		);
132 132
 
133
-		if ( ! empty( $purchase_data['user_info']['address'] ) ) {
133
+		if ( ! empty($purchase_data['user_info']['address'])) {
134 134
 			$paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
135 135
 			$paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
136 136
 			$paypal_args['city']     = $purchase_data['user_info']['address']['city'];
137 137
 			$paypal_args['country']  = $purchase_data['user_info']['address']['country'];
138 138
 		}
139 139
 
140
-		if ( give_get_option( 'paypal_button_type' ) === 'standard' ) {
140
+		if (give_get_option('paypal_button_type') === 'standard') {
141 141
 			$paypal_extra_args = array(
142 142
 				'cmd' => '_xclick',
143 143
 			);
@@ -147,23 +147,23 @@  discard block
 block discarded – undo
147 147
 			);
148 148
 		}
149 149
 
150
-		$paypal_args = array_merge( $paypal_extra_args, $paypal_args );
151
-		$paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data );
150
+		$paypal_args = array_merge($paypal_extra_args, $paypal_args);
151
+		$paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
152 152
 
153 153
 		// Build query
154
-		$paypal_redirect .= http_build_query( $paypal_args );
154
+		$paypal_redirect .= http_build_query($paypal_args);
155 155
 
156 156
 		// Fix for some sites that encode the entities
157
-		$paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
157
+		$paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
158 158
 
159 159
 		// Redirect to PayPal
160
-		wp_redirect( $paypal_redirect );
160
+		wp_redirect($paypal_redirect);
161 161
 		exit;
162 162
 	}
163 163
 
164 164
 }
165 165
 
166
-add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' );
166
+add_action('give_gateway_paypal', 'give_process_paypal_purchase');
167 167
 
168 168
 /**
169 169
  * Listens for a PayPal IPN requests and then sends to the processing function
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
  */
174 174
 function give_listen_for_paypal_ipn() {
175 175
 	// Regular PayPal IPN
176
-	if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) {
177
-		do_action( 'give_verify_paypal_ipn' );
176
+	if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') {
177
+		do_action('give_verify_paypal_ipn');
178 178
 	}
179 179
 }
180 180
 
181
-add_action( 'init', 'give_listen_for_paypal_ipn' );
181
+add_action('init', 'give_listen_for_paypal_ipn');
182 182
 
183 183
 /**
184 184
  * Process PayPal IPN
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 function give_process_paypal_ipn() {
190 190
 
191 191
 	// Check the request method is POST
192
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
192
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
193 193
 		return;
194 194
 	}
195 195
 
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 	$post_data = '';
198 198
 
199 199
 	// Fallback just in case post_max_size is lower than needed
200
-	if ( ini_get( 'allow_url_fopen' ) ) {
201
-		$post_data = file_get_contents( 'php://input' );
200
+	if (ini_get('allow_url_fopen')) {
201
+		$post_data = file_get_contents('php://input');
202 202
 	} else {
203 203
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
204
-		ini_set( 'post_max_size', '12M' );
204
+		ini_set('post_max_size', '12M');
205 205
 	}
206 206
 	// Start the encoded data collection with notification command
207 207
 	$encoded_data = 'cmd=_notify-validate';
@@ -210,40 +210,40 @@  discard block
 block discarded – undo
210 210
 	$arg_separator = give_get_php_arg_separator_output();
211 211
 
212 212
 	// Verify there is a post_data
213
-	if ( $post_data || strlen( $post_data ) > 0 ) {
213
+	if ($post_data || strlen($post_data) > 0) {
214 214
 		// Append the data
215
-		$encoded_data .= $arg_separator . $post_data;
215
+		$encoded_data .= $arg_separator.$post_data;
216 216
 	} else {
217 217
 		// Check if POST is empty
218
-		if ( empty( $_POST ) ) {
218
+		if (empty($_POST)) {
219 219
 			// Nothing to do
220 220
 			return;
221 221
 		} else {
222 222
 			// Loop through each POST
223
-			foreach ( $_POST as $key => $value ) {
223
+			foreach ($_POST as $key => $value) {
224 224
 				// Encode the value and append the data
225
-				$encoded_data .= $arg_separator . "$key=" . urlencode( $value );
225
+				$encoded_data .= $arg_separator."$key=".urlencode($value);
226 226
 			}
227 227
 		}
228 228
 	}
229 229
 
230 230
 	// Convert collected post data to an array
231
-	parse_str( $encoded_data, $encoded_data_array );
231
+	parse_str($encoded_data, $encoded_data_array);
232 232
 
233
-	foreach ( $encoded_data_array as $key => $value ) {
233
+	foreach ($encoded_data_array as $key => $value) {
234 234
 
235
-		if ( false !== strpos( $key, 'amp;' ) ) {
236
-			$new_key = str_replace( '&amp;', '&', $key );
237
-			$new_key = str_replace( 'amp;', '&' , $new_key );
235
+		if (false !== strpos($key, 'amp;')) {
236
+			$new_key = str_replace('&amp;', '&', $key);
237
+			$new_key = str_replace('amp;', '&', $new_key);
238 238
 
239
-			unset( $encoded_data_array[ $key ] );
240
-			$encoded_data_array[ $new_key ] = $value;
239
+			unset($encoded_data_array[$key]);
240
+			$encoded_data_array[$new_key] = $value;
241 241
 		}
242 242
 
243 243
 	}
244 244
 	
245 245
 	//Validate IPN request w/ PayPal if user hasn't disabled this security measure
246
-	if ( ! give_get_option( 'disable_paypal_verification' ) ) {
246
+	if ( ! give_get_option('disable_paypal_verification')) {
247 247
 
248 248
 		$remote_post_vars = array(
249 249
 			'method'      => 'POST',
@@ -263,22 +263,22 @@  discard block
 block discarded – undo
263 263
 		);
264 264
 
265 265
 		// Validate the IPN
266
-		$api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars );
266
+		$api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars);
267 267
 
268
-		if ( is_wp_error( $api_response ) ) {
269
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) );
268
+		if (is_wp_error($api_response)) {
269
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response)));
270 270
 			return; // Something went wrong
271 271
 		}
272 272
 
273
-		if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) {
274
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) );
273
+		if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) {
274
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response)));
275 275
 			return; // Response not okay
276 276
 		}
277 277
 
278 278
 	}
279 279
 
280 280
 	// Check if $post_data_array has been populated
281
-	if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) {
281
+	if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) {
282 282
 		return;
283 283
 	}
284 284
 
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
 		'payment_status' => ''
288 288
 	);
289 289
 
290
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
290
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
291 291
 
292
-	$payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
292
+	$payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
293 293
 
294
-	if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) {
294
+	if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) {
295 295
 		// Allow PayPal IPN types to be processed separately
296
-		do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id );
296
+		do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id);
297 297
 	} else {
298 298
 		// Fallback to web accept just in case the txn_type isn't present
299
-		do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id );
299
+		do_action('give_paypal_web_accept', $encoded_data_array, $payment_id);
300 300
 	}
301 301
 	exit;
302 302
 }
303 303
 
304
-add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' );
304
+add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn');
305 305
 
306 306
 /**
307 307
  * Process web accept (one time) payment IPNs
@@ -312,185 +312,185 @@  discard block
 block discarded – undo
312 312
  *
313 313
  * @return void
314 314
  */
315
-function give_process_paypal_web_accept_and_cart( $data, $payment_id ) {
315
+function give_process_paypal_web_accept_and_cart($data, $payment_id) {
316 316
 
317
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
317
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
318 318
 		return;
319 319
 	}
320 320
 
321
-	if ( empty( $payment_id ) ) {
321
+	if (empty($payment_id)) {
322 322
 		return;
323 323
 	}
324 324
 
325 325
 	// Collect payment details
326
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
326
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
327 327
 	$paypal_amount  = $data['mc_gross'];
328
-	$payment_status = strtolower( $data['payment_status'] );
329
-	$currency_code  = strtolower( $data['mc_currency'] );
330
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
331
-	$payment_meta   = give_get_payment_meta( $payment_id );
328
+	$payment_status = strtolower($data['payment_status']);
329
+	$currency_code  = strtolower($data['mc_currency']);
330
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
331
+	$payment_meta   = give_get_payment_meta($payment_id);
332 332
 
333 333
 
334
-	if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) {
334
+	if (give_get_payment_gateway($payment_id) != 'paypal') {
335 335
 		return; // this isn't a PayPal standard IPN
336 336
 	}
337 337
 
338 338
 	// Verify payment recipient
339
-	if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) {
339
+	if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
340 340
 
341
-		give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
342
-		give_update_payment_status( $payment_id, 'failed' );
343
-		give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) );
341
+		give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
342
+		give_update_payment_status($payment_id, 'failed');
343
+		give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give'));
344 344
 
345 345
 		return;
346 346
 	}
347 347
 
348 348
 	// Verify payment currency
349
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
349
+	if ($currency_code != strtolower($payment_meta['currency'])) {
350 350
 
351
-		give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
352
-		give_update_payment_status( $payment_id, 'failed' );
353
-		give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) );
351
+		give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
352
+		give_update_payment_status($payment_id, 'failed');
353
+		give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give'));
354 354
 
355 355
 		return;
356 356
 	}
357 357
 
358
-	if ( ! give_get_payment_user_email( $payment_id ) ) {
358
+	if ( ! give_get_payment_user_email($payment_id)) {
359 359
 
360 360
 		// No email associated with purchase, so store from PayPal
361
-		give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] );
361
+		give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']);
362 362
 
363 363
 		// Setup and store the donors's details
364 364
 		$address            = array();
365
-		$address['line1']   = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false;
366
-		$address['city']    = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false;
367
-		$address['state']   = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false;
368
-		$address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
369
-		$address['zip']     = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false;
365
+		$address['line1']   = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
366
+		$address['city']    = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
367
+		$address['state']   = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
368
+		$address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
369
+		$address['zip']     = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
370 370
 
371 371
 		$user_info = array(
372 372
 			'id'         => '-1',
373
-			'email'      => sanitize_text_field( $data['payer_email'] ),
374
-			'first_name' => sanitize_text_field( $data['first_name'] ),
375
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
373
+			'email'      => sanitize_text_field($data['payer_email']),
374
+			'first_name' => sanitize_text_field($data['first_name']),
375
+			'last_name'  => sanitize_text_field($data['last_name']),
376 376
 			'discount'   => '',
377 377
 			'address'    => $address
378 378
 		);
379 379
 
380 380
 		$payment_meta['user_info'] = $user_info;
381
-		give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta );
381
+		give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta);
382 382
 	}
383 383
 
384
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
384
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
385 385
 
386 386
 		// Process a refund
387
-		give_process_paypal_refund( $data, $payment_id );
387
+		give_process_paypal_refund($data, $payment_id);
388 388
 
389 389
 	} else {
390 390
 
391
-		if ( get_post_status( $payment_id ) == 'publish' ) {
391
+		if (get_post_status($payment_id) == 'publish') {
392 392
 			return; // Only complete payments once
393 393
 		}
394 394
 
395 395
 		// Retrieve the total purchase amount (before PayPal)
396
-		$payment_amount = give_get_payment_amount( $payment_id );
396
+		$payment_amount = give_get_payment_amount($payment_id);
397 397
 
398
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
398
+		if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
399 399
 			// The prices don't match
400
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
401
-			give_update_payment_status( $payment_id, 'failed' );
402
-			give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) );
400
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
401
+			give_update_payment_status($payment_id, 'failed');
402
+			give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give'));
403 403
 
404 404
 			return;
405 405
 		}
406
-		if ( $purchase_key != give_get_payment_key( $payment_id ) ) {
406
+		if ($purchase_key != give_get_payment_key($payment_id)) {
407 407
 			// Purchase keys don't match
408
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
409
-			give_update_payment_status( $payment_id, 'failed' );
410
-			give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) );
408
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
409
+			give_update_payment_status($payment_id, 'failed');
410
+			give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give'));
411 411
 
412 412
 			return;
413 413
 		}
414 414
 
415
-		if ( $payment_status == 'completed' || give_is_test_mode() ) {
416
-			give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Transaction ID: %s', 'give' ), $data['txn_id'] ) );
417
-			give_set_payment_transaction_id( $payment_id, $data['txn_id'] );
418
-			give_update_payment_status( $payment_id, 'publish' );
419
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
415
+		if ($payment_status == 'completed' || give_is_test_mode()) {
416
+			give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
417
+			give_set_payment_transaction_id($payment_id, $data['txn_id']);
418
+			give_update_payment_status($payment_id, 'publish');
419
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
420 420
 
421 421
 			// Look for possible pending reasons, such as an echeck
422 422
 
423 423
 			$note = '';
424 424
 
425
-			switch ( strtolower( $data['pending_reason'] ) ) {
425
+			switch (strtolower($data['pending_reason'])) {
426 426
 
427 427
 				case 'echeck' :
428 428
 
429
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'give' );
429
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'give');
430 430
 
431 431
 					break;
432 432
 
433 433
 				case 'address' :
434 434
 
435
-					$note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give' );
435
+					$note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give');
436 436
 
437 437
 					break;
438 438
 
439 439
 				case 'intl' :
440 440
 
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'give' );
441
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'give');
442 442
 
443 443
 					break;
444 444
 
445 445
 				case 'multi-currency' :
446 446
 
447
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'give' );
447
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'give');
448 448
 
449 449
 					break;
450 450
 
451 451
 				case 'paymentreview' :
452 452
 				case 'regulatory_review' :
453 453
 
454
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give' );
454
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give');
455 455
 
456 456
 					break;
457 457
 
458 458
 				case 'unilateral' :
459 459
 
460
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' );
460
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'give');
461 461
 
462 462
 					break;
463 463
 
464 464
 				case 'upgrade' :
465 465
 
466
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'give' );
466
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'give');
467 467
 
468 468
 					break;
469 469
 
470 470
 				case 'verify' :
471 471
 
472
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'give' );
472
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'give');
473 473
 
474 474
 					break;
475 475
 
476 476
 				case 'other' :
477 477
 
478
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give' );
478
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give');
479 479
 
480 480
 					break;
481 481
 
482 482
 			}
483 483
 
484
-			if ( ! empty( $note ) ) {
484
+			if ( ! empty($note)) {
485 485
 
486
-				give_insert_payment_note( $payment_id, $note );
486
+				give_insert_payment_note($payment_id, $note);
487 487
 
488 488
 			}
489 489
 		}
490 490
 	}
491 491
 }
492 492
 
493
-add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 );
493
+add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2);
494 494
 
495 495
 /**
496 496
  * Process PayPal IPN Refunds
@@ -501,32 +501,32 @@  discard block
 block discarded – undo
501 501
  *
502 502
  * @return void
503 503
  */
504
-function give_process_paypal_refund( $data, $payment_id = 0 ) {
504
+function give_process_paypal_refund($data, $payment_id = 0) {
505 505
 
506 506
 	// Collect payment details
507 507
 
508
-	if ( empty( $payment_id ) ) {
508
+	if (empty($payment_id)) {
509 509
 		return;
510 510
 	}
511 511
 
512
-	if ( get_post_status( $payment_id ) == 'refunded' ) {
512
+	if (get_post_status($payment_id) == 'refunded') {
513 513
 		return; // Only refund payments once
514 514
 	}
515 515
 
516
-	$payment_amount = give_get_payment_amount( $payment_id );
516
+	$payment_amount = give_get_payment_amount($payment_id);
517 517
 	$refund_amount  = $data['payment_gross'] * - 1;
518 518
 
519
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
519
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
520 520
 
521
-		give_insert_payment_note( $payment_id, sprintf( __( 'Partial PayPal refund processed: %s', 'give' ), $data['parent_txn_id'] ) );
521
+		give_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id']));
522 522
 
523 523
 		return; // This is a partial refund
524 524
 
525 525
 	}
526 526
 
527
-	give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), $data['parent_txn_id'], $data['reason_code'] ) );
528
-	give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'give' ), $data['txn_id'] ) );
529
-	give_update_payment_status( $payment_id, 'refunded' );
527
+	give_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code']));
528
+	give_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id']));
529
+	give_update_payment_status($payment_id, 'refunded');
530 530
 }
531 531
 
532 532
 /**
@@ -538,24 +538,24 @@  discard block
 block discarded – undo
538 538
  *
539 539
  * @return string
540 540
  */
541
-function give_get_paypal_redirect( $ssl_check = false ) {
541
+function give_get_paypal_redirect($ssl_check = false) {
542 542
 
543
-	if ( is_ssl() || ! $ssl_check ) {
543
+	if (is_ssl() || ! $ssl_check) {
544 544
 		$protocal = 'https://';
545 545
 	} else {
546 546
 		$protocal = 'http://';
547 547
 	}
548 548
 
549 549
 	// Check the current payment mode
550
-	if ( give_is_test_mode() ) {
550
+	if (give_is_test_mode()) {
551 551
 		// Test mode
552
-		$paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr';
552
+		$paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr';
553 553
 	} else {
554 554
 		// Live mode
555
-		$paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr';
555
+		$paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr';
556 556
 	}
557 557
 
558
-	return apply_filters( 'give_paypal_uri', $paypal_uri );
558
+	return apply_filters('give_paypal_uri', $paypal_uri);
559 559
 }
560 560
 
561 561
 /**
@@ -565,8 +565,8 @@  discard block
 block discarded – undo
565 565
  * @return string
566 566
  */
567 567
 function give_get_paypal_page_style() {
568
-	$page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) );
569
-	return apply_filters( 'give_paypal_page_style', $page_style );
568
+	$page_style = trim(give_get_option('paypal_page_style', 'PayPal'));
569
+	return apply_filters('give_paypal_page_style', $page_style);
570 570
 }
571 571
 
572 572
 /**
@@ -581,27 +581,27 @@  discard block
 block discarded – undo
581 581
  * @return string
582 582
  *
583 583
  */
584
-function give_paypal_success_page_content( $content ) {
584
+function give_paypal_success_page_content($content) {
585 585
 
586
-	if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) {
586
+	if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) {
587 587
 		return $content;
588 588
 	}
589 589
 
590
-	$payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false;
590
+	$payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false;
591 591
 
592
-	if ( ! $payment_id ) {
592
+	if ( ! $payment_id) {
593 593
 		$session    = give_get_purchase_session();
594
-		$payment_id = give_get_purchase_id_by_key( $session['purchase_key'] );
594
+		$payment_id = give_get_purchase_id_by_key($session['purchase_key']);
595 595
 	}
596 596
 
597
-	$payment = get_post( $payment_id );
597
+	$payment = get_post($payment_id);
598 598
 
599
-	if ( $payment && 'pending' == $payment->post_status ) {
599
+	if ($payment && 'pending' == $payment->post_status) {
600 600
 
601 601
 		// Payment is still pending so show processing indicator to fix the Race Condition
602 602
 		ob_start();
603 603
 
604
-		give_get_template_part( 'payment', 'processing' );
604
+		give_get_template_part('payment', 'processing');
605 605
 
606 606
 		$content = ob_get_clean();
607 607
 
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 
612 612
 }
613 613
 
614
-add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' );
614
+add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content');
615 615
 
616 616
 /**
617 617
  * Given a Payment ID, extract the transaction ID
@@ -622,22 +622,22 @@  discard block
 block discarded – undo
622 622
  *
623 623
  * @return string                   Transaction ID
624 624
  */
625
-function give_paypal_get_payment_transaction_id( $payment_id ) {
625
+function give_paypal_get_payment_transaction_id($payment_id) {
626 626
 
627 627
 	$transaction_id = '';
628
-	$notes          = give_get_payment_notes( $payment_id );
628
+	$notes          = give_get_payment_notes($payment_id);
629 629
 
630
-	foreach ( $notes as $note ) {
631
-		if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
630
+	foreach ($notes as $note) {
631
+		if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
632 632
 			$transaction_id = $match[1];
633 633
 			continue;
634 634
 		}
635 635
 	}
636 636
 
637
-	return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id );
637
+	return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id);
638 638
 }
639 639
 
640
-add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 );
640
+add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1);
641 641
 
642 642
 /**
643 643
  * Given a transaction ID, generate a link to the PayPal transaction ID details
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
  *
650 650
  * @return string                 A link to the PayPal transaction details
651 651
  */
652
-function give_paypal_link_transaction_id( $transaction_id, $payment_id ) {
652
+function give_paypal_link_transaction_id($transaction_id, $payment_id) {
653 653
 
654 654
 	$paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id=';
655
-	$transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>';
655
+	$transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>';
656 656
 
657
-	return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url );
657
+	return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url);
658 658
 
659 659
 }
660 660
 
661
-add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 );
661
+add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2);
Please login to merge, or discard this patch.
includes/gateways/manual.php 1 patch
Spacing   +12 added lines, -12 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
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @since 1.0
21 21
  * @return void
22 22
  */
23
-add_action( 'give_manual_cc_form', '__return_false' );
23
+add_action('give_manual_cc_form', '__return_false');
24 24
 
25 25
 /**
26 26
  * Processes the purchase data and uses the Manual Payment gateway to record
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
  *
33 33
  * @return void
34 34
  */
35
-function give_manual_payment( $purchase_data ) {
35
+function give_manual_payment($purchase_data) {
36 36
 
37
-	if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) {
38
-		wp_die( __( 'Nonce verification has failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
37
+	if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
38
+		wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403));
39 39
 	}
40 40
 	
41 41
 	//Create payment_data array
42 42
 	$payment_data = array(
43 43
 		'price'           => $purchase_data['price'],
44 44
 		'give_form_title' => $purchase_data['post_data']['give-form-title'],
45
-		'give_form_id'    => intval( $purchase_data['post_data']['give-form-id'] ),
45
+		'give_form_id'    => intval($purchase_data['post_data']['give-form-id']),
46 46
 		'give_price_id'   => $purchase_data['post_data']['give-price-id'],
47 47
 		'date'            => $purchase_data['date'],
48 48
 		'user_email'      => $purchase_data['user_email'],
@@ -52,16 +52,16 @@  discard block
 block discarded – undo
52 52
 		'status'          => 'pending'
53 53
 	);
54 54
 	// Record the pending payment
55
-	$payment = give_insert_payment( $payment_data );
55
+	$payment = give_insert_payment($payment_data);
56 56
 
57
-	if ( $payment ) {
58
-		give_update_payment_status( $payment, 'publish' );
57
+	if ($payment) {
58
+		give_update_payment_status($payment, 'publish');
59 59
 		give_send_to_success_page();
60 60
 	} else {
61
-		give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment );
61
+		give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
62 62
 		// If errors are present, send the user back to the purchase page so they can be corrected
63
-		give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
63
+		give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']);
64 64
 	}
65 65
 }
66 66
 
67
-add_action( 'give_gateway_manual', 'give_manual_payment' );
67
+add_action('give_gateway_manual', 'give_manual_payment');
Please login to merge, or discard this patch.
includes/class-give-html-elements.php 1 patch
Spacing   +128 added lines, -128 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
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @return string $output Give forms dropdown
35 35
 	 */
36
-	public function forms_dropdown( $args = array() ) {
36
+	public function forms_dropdown($args = array()) {
37 37
 
38 38
 		$defaults = array(
39 39
 			'name'        => 'forms',
@@ -43,43 +43,43 @@  discard block
 block discarded – undo
43 43
 			'selected'    => 0,
44 44
 			'chosen'      => false,
45 45
 			'number'      => 30,
46
-			'placeholder' => sprintf( __( 'Select a %s', 'give' ), give_get_forms_label_singular() )
46
+			'placeholder' => sprintf(__('Select a %s', 'give'), give_get_forms_label_singular())
47 47
 		);
48 48
 
49
-		$args = wp_parse_args( $args, $defaults );
49
+		$args = wp_parse_args($args, $defaults);
50 50
 
51
-		$forms = get_posts( array(
51
+		$forms = get_posts(array(
52 52
 			'post_type'      => 'give_forms',
53 53
 			'orderby'        => 'title',
54 54
 			'order'          => 'ASC',
55 55
 			'posts_per_page' => $args['number']
56
-		) );
56
+		));
57 57
 
58 58
 		$options = array();
59 59
 
60
-		if ( $forms ) {
61
-			$options[0] = sprintf( __( 'Select a %s', 'give' ), give_get_forms_label_singular() );
62
-			foreach ( $forms as $form ) {
63
-				$options[ absint( $form->ID ) ] = esc_html( $form->post_title );
60
+		if ($forms) {
61
+			$options[0] = sprintf(__('Select a %s', 'give'), give_get_forms_label_singular());
62
+			foreach ($forms as $form) {
63
+				$options[absint($form->ID)] = esc_html($form->post_title);
64 64
 			}
65 65
 		} else {
66
-			$options[0] = __( 'No Give Forms Found', 'give' );
66
+			$options[0] = __('No Give Forms Found', 'give');
67 67
 		}
68 68
 
69 69
 		// This ensures that any selected forms are included in the drop down
70
-		if ( is_array( $args['selected'] ) ) {
71
-			foreach ( $args['selected'] as $item ) {
72
-				if ( ! in_array( $item, $options ) ) {
73
-					$options[ $item ] = get_the_title( $item );
70
+		if (is_array($args['selected'])) {
71
+			foreach ($args['selected'] as $item) {
72
+				if ( ! in_array($item, $options)) {
73
+					$options[$item] = get_the_title($item);
74 74
 				}
75 75
 			}
76
-		} elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
77
-			if ( ! in_array( $args['selected'], $options ) ) {
78
-				$options[ $args['selected'] ] = get_the_title( $args['selected'] );
76
+		} elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
77
+			if ( ! in_array($args['selected'], $options)) {
78
+				$options[$args['selected']] = get_the_title($args['selected']);
79 79
 			}
80 80
 		}
81 81
 
82
-		$output = $this->select( array(
82
+		$output = $this->select(array(
83 83
 			'name'             => $args['name'],
84 84
 			'selected'         => $args['selected'],
85 85
 			'id'               => $args['id'],
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			'placeholder'      => $args['placeholder'],
91 91
 			'show_option_all'  => false,
92 92
 			'show_option_none' => false
93
-		) );
93
+		));
94 94
 
95 95
 		return $output;
96 96
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return string $output Donor dropdown
107 107
 	 */
108
-	public function donor_dropdown( $args = array() ) {
108
+	public function donor_dropdown($args = array()) {
109 109
 
110 110
 		$defaults = array(
111 111
 			'name'        => 'customers',
@@ -114,38 +114,38 @@  discard block
 block discarded – undo
114 114
 			'multiple'    => false,
115 115
 			'selected'    => 0,
116 116
 			'chosen'      => true,
117
-			'placeholder' => __( 'Select a Donor', 'give' ),
117
+			'placeholder' => __('Select a Donor', 'give'),
118 118
 			'number'      => 30
119 119
 		);
120 120
 
121
-		$args = wp_parse_args( $args, $defaults );
121
+		$args = wp_parse_args($args, $defaults);
122 122
 
123
-		$customers = Give()->customers->get_customers( array(
123
+		$customers = Give()->customers->get_customers(array(
124 124
 			'number' => $args['number']
125
-		) );
125
+		));
126 126
 
127 127
 		$options = array();
128 128
 
129
-		if ( $customers ) {
130
-			$options[0] = __( 'No donor attached', 'give' );
131
-			foreach ( $customers as $customer ) {
132
-				$options[ absint( $customer->id ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' );
129
+		if ($customers) {
130
+			$options[0] = __('No donor attached', 'give');
131
+			foreach ($customers as $customer) {
132
+				$options[absint($customer->id)] = esc_html($customer->name.' ('.$customer->email.')');
133 133
 			}
134 134
 		} else {
135
-			$options[0] = __( 'No donors found', 'give' );
135
+			$options[0] = __('No donors found', 'give');
136 136
 		}
137 137
 
138
-		if ( ! empty( $args['selected'] ) ) {
138
+		if ( ! empty($args['selected'])) {
139 139
 
140 140
 			// If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed
141 141
 
142
-			if ( ! array_key_exists( $args['selected'], $options ) ) {
142
+			if ( ! array_key_exists($args['selected'], $options)) {
143 143
 
144
-				$customer = new Give_Customer( $args['selected'] );
144
+				$customer = new Give_Customer($args['selected']);
145 145
 
146
-				if ( $customer ) {
146
+				if ($customer) {
147 147
 
148
-					$options[ absint( $args['selected'] ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' );
148
+					$options[absint($args['selected'])] = esc_html($customer->name.' ('.$customer->email.')');
149 149
 
150 150
 				}
151 151
 
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 
154 154
 		}
155 155
 
156
-		$output = $this->select( array(
156
+		$output = $this->select(array(
157 157
 			'name'             => $args['name'],
158 158
 			'selected'         => $args['selected'],
159 159
 			'id'               => $args['id'],
160
-			'class'            => $args['class'] . ' give-customer-select',
160
+			'class'            => $args['class'].' give-customer-select',
161 161
 			'options'          => $options,
162 162
 			'multiple'         => $args['multiple'],
163 163
 			'chosen'           => $args['chosen'],
164 164
 			'show_option_all'  => false,
165 165
 			'show_option_none' => false
166
-		) );
166
+		));
167 167
 
168 168
 		return $output;
169 169
 	}
@@ -180,21 +180,21 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @return string $output Category dropdown
182 182
 	 */
183
-	public function category_dropdown( $name = 'give_forms_categories', $selected = 0 ) {
184
-		$categories = get_terms( 'give_forms_category', apply_filters( 'give_forms_category_dropdown', array() ) );
183
+	public function category_dropdown($name = 'give_forms_categories', $selected = 0) {
184
+		$categories = get_terms('give_forms_category', apply_filters('give_forms_category_dropdown', array()));
185 185
 		$options    = array();
186 186
 
187
-		foreach ( $categories as $category ) {
188
-			$options[ absint( $category->term_id ) ] = esc_html( $category->name );
187
+		foreach ($categories as $category) {
188
+			$options[absint($category->term_id)] = esc_html($category->name);
189 189
 		}
190 190
 
191
-		$output = $this->select( array(
191
+		$output = $this->select(array(
192 192
 			'name'             => $name,
193 193
 			'selected'         => $selected,
194 194
 			'options'          => $options,
195
-			'show_option_all'  => __( 'All Categories', 'give' ),
195
+			'show_option_all'  => __('All Categories', 'give'),
196 196
 			'show_option_none' => false
197
-		) );
197
+		));
198 198
 
199 199
 		return $output;
200 200
 	}
@@ -212,25 +212,25 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return string $output Year dropdown
214 214
 	 */
215
-	public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
216
-		$current    = date( 'Y' );
217
-		$start_year = $current - absint( $years_before );
218
-		$end_year   = $current + absint( $years_after );
219
-		$selected   = empty( $selected ) ? date( 'Y' ) : $selected;
215
+	public function year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
216
+		$current    = date('Y');
217
+		$start_year = $current - absint($years_before);
218
+		$end_year   = $current + absint($years_after);
219
+		$selected   = empty($selected) ? date('Y') : $selected;
220 220
 		$options    = array();
221 221
 
222
-		while ( $start_year <= $end_year ) {
223
-			$options[ absint( $start_year ) ] = $start_year;
224
-			$start_year ++;
222
+		while ($start_year <= $end_year) {
223
+			$options[absint($start_year)] = $start_year;
224
+			$start_year++;
225 225
 		}
226 226
 
227
-		$output = $this->select( array(
227
+		$output = $this->select(array(
228 228
 			'name'             => $name,
229 229
 			'selected'         => $selected,
230 230
 			'options'          => $options,
231 231
 			'show_option_all'  => false,
232 232
 			'show_option_none' => false
233
-		) );
233
+		));
234 234
 
235 235
 		return $output;
236 236
 	}
@@ -247,23 +247,23 @@  discard block
 block discarded – undo
247 247
 	 *
248 248
 	 * @return string $output Month dropdown
249 249
 	 */
250
-	public function month_dropdown( $name = 'month', $selected = 0 ) {
250
+	public function month_dropdown($name = 'month', $selected = 0) {
251 251
 		$month    = 1;
252 252
 		$options  = array();
253
-		$selected = empty( $selected ) ? date( 'n' ) : $selected;
253
+		$selected = empty($selected) ? date('n') : $selected;
254 254
 
255
-		while ( $month <= 12 ) {
256
-			$options[ absint( $month ) ] = give_month_num_to_name( $month );
257
-			$month ++;
255
+		while ($month <= 12) {
256
+			$options[absint($month)] = give_month_num_to_name($month);
257
+			$month++;
258 258
 		}
259 259
 
260
-		$output = $this->select( array(
260
+		$output = $this->select(array(
261 261
 			'name'             => $name,
262 262
 			'selected'         => $selected,
263 263
 			'options'          => $options,
264 264
 			'show_option_all'  => false,
265 265
 			'show_option_none' => false
266
-		) );
266
+		));
267 267
 
268 268
 		return $output;
269 269
 	}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @return string
279 279
 	 */
280
-	public function select( $args = array() ) {
280
+	public function select($args = array()) {
281 281
 		$defaults = array(
282 282
 			'options'          => array(),
283 283
 			'name'             => null,
@@ -287,60 +287,60 @@  discard block
 block discarded – undo
287 287
 			'chosen'           => false,
288 288
 			'placeholder'      => null,
289 289
 			'multiple'         => false,
290
-			'show_option_all'  => _x( 'All', 'all dropdown items', 'give' ),
291
-			'show_option_none' => _x( 'None', 'no dropdown items', 'give' )
290
+			'show_option_all'  => _x('All', 'all dropdown items', 'give'),
291
+			'show_option_none' => _x('None', 'no dropdown items', 'give')
292 292
 		);
293 293
 
294
-		$args = wp_parse_args( $args, $defaults );
294
+		$args = wp_parse_args($args, $defaults);
295 295
 
296 296
 
297
-		if ( $args['multiple'] ) {
297
+		if ($args['multiple']) {
298 298
 			$multiple = ' MULTIPLE';
299 299
 		} else {
300 300
 			$multiple = '';
301 301
 		}
302 302
 
303
-		if ( $args['chosen'] ) {
303
+		if ($args['chosen']) {
304 304
 			$args['class'] .= ' give-select-chosen';
305 305
 		}
306 306
 
307
-		if ( $args['placeholder'] ) {
307
+		if ($args['placeholder']) {
308 308
 			$placeholder = $args['placeholder'];
309 309
 		} else {
310 310
 			$placeholder = '';
311 311
 		}
312 312
 
313
-		$output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="give-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' data-placeholder="' . $placeholder . '">';
313
+		$output = '<select name="'.esc_attr($args['name']).'" id="'.esc_attr(sanitize_key(str_replace('-', '_', $args['id']))).'" class="give-select '.esc_attr($args['class']).'"'.$multiple.' data-placeholder="'.$placeholder.'">';
314 314
 
315
-		if ( $args['show_option_all'] ) {
316
-			if ( $args['multiple'] ) {
317
-				$selected = selected( true, in_array( 0, $args['selected'] ), false );
315
+		if ($args['show_option_all']) {
316
+			if ($args['multiple']) {
317
+				$selected = selected(true, in_array(0, $args['selected']), false);
318 318
 			} else {
319
-				$selected = selected( $args['selected'], 0, false );
319
+				$selected = selected($args['selected'], 0, false);
320 320
 			}
321
-			$output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
321
+			$output .= '<option value="all"'.$selected.'>'.esc_html($args['show_option_all']).'</option>';
322 322
 		}
323 323
 
324
-		if ( ! empty( $args['options'] ) ) {
324
+		if ( ! empty($args['options'])) {
325 325
 
326
-			if ( $args['show_option_none'] ) {
327
-				if ( $args['multiple'] ) {
328
-					$selected = selected( true, in_array( - 1, $args['selected'] ), false );
326
+			if ($args['show_option_none']) {
327
+				if ($args['multiple']) {
328
+					$selected = selected(true, in_array( -1, $args['selected'] ), false);
329 329
 				} else {
330
-					$selected = selected( $args['selected'], - 1, false );
330
+					$selected = selected($args['selected'], - 1, false);
331 331
 				}
332
-				$output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
332
+				$output .= '<option value="-1"'.$selected.'>'.esc_html($args['show_option_none']).'</option>';
333 333
 			}
334 334
 
335
-			foreach ( $args['options'] as $key => $option ) {
335
+			foreach ($args['options'] as $key => $option) {
336 336
 
337
-				if ( $args['multiple'] && is_array( $args['selected'] ) ) {
338
-					$selected = selected( true, in_array( $key, $args['selected'] ), false );
337
+				if ($args['multiple'] && is_array($args['selected'])) {
338
+					$selected = selected(true, in_array($key, $args['selected']), false);
339 339
 				} else {
340
-					$selected = selected( $args['selected'], $key, false );
340
+					$selected = selected($args['selected'], $key, false);
341 341
 				}
342 342
 
343
-				$output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
343
+				$output .= '<option value="'.esc_attr($key).'"'.$selected.'>'.esc_html($option).'</option>';
344 344
 			}
345 345
 		}
346 346
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @return string
360 360
 	 */
361
-	public function checkbox( $args = array() ) {
361
+	public function checkbox($args = array()) {
362 362
 		$defaults = array(
363 363
 			'name'    => null,
364 364
 			'current' => null,
@@ -369,16 +369,16 @@  discard block
 block discarded – undo
369 369
 			)
370 370
 		);
371 371
 
372
-		$args = wp_parse_args( $args, $defaults );
372
+		$args = wp_parse_args($args, $defaults);
373 373
 
374 374
 		$options = '';
375
-		if ( ! empty( $args['options']['disabled'] ) ) {
375
+		if ( ! empty($args['options']['disabled'])) {
376 376
 			$options .= ' disabled="disabled"';
377
-		} elseif ( ! empty( $args['options']['readonly'] ) ) {
377
+		} elseif ( ! empty($args['options']['readonly'])) {
378 378
 			$options .= ' readonly';
379 379
 		}
380 380
 
381
-		$output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
381
+		$output = '<input type="checkbox"'.$options.' name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].' '.esc_attr($args['name']).'" '.checked(1, $args['current'], false).' />';
382 382
 
383 383
 		return $output;
384 384
 	}
@@ -392,22 +392,22 @@  discard block
 block discarded – undo
392 392
 	 *
393 393
 	 * @return string Text field
394 394
 	 */
395
-	public function text( $args = array() ) {
395
+	public function text($args = array()) {
396 396
 		// Backwards compatabliity
397
-		if ( func_num_args() > 1 ) {
397
+		if (func_num_args() > 1) {
398 398
 			$args = func_get_args();
399 399
 
400 400
 			$name  = $args[0];
401
-			$value = isset( $args[1] ) ? $args[1] : '';
402
-			$label = isset( $args[2] ) ? $args[2] : '';
403
-			$desc  = isset( $args[3] ) ? $args[3] : '';
401
+			$value = isset($args[1]) ? $args[1] : '';
402
+			$label = isset($args[2]) ? $args[2] : '';
403
+			$desc  = isset($args[3]) ? $args[3] : '';
404 404
 		}
405 405
 
406 406
 		$defaults = array(
407
-			'name'         => isset( $name ) ? $name : 'text',
408
-			'value'        => isset( $value ) ? $value : null,
409
-			'label'        => isset( $label ) ? $label : null,
410
-			'desc'         => isset( $desc ) ? $desc : null,
407
+			'name'         => isset($name) ? $name : 'text',
408
+			'value'        => isset($value) ? $value : null,
409
+			'label'        => isset($label) ? $label : null,
410
+			'desc'         => isset($desc) ? $desc : null,
411 411
 			'placeholder'  => '',
412 412
 			'class'        => 'regular-text',
413 413
 			'disabled'     => false,
@@ -415,29 +415,29 @@  discard block
 block discarded – undo
415 415
 			'data'         => false
416 416
 		);
417 417
 
418
-		$args = wp_parse_args( $args, $defaults );
418
+		$args = wp_parse_args($args, $defaults);
419 419
 
420 420
 		$disabled = '';
421
-		if ( $args['disabled'] ) {
421
+		if ($args['disabled']) {
422 422
 			$disabled = ' disabled="disabled"';
423 423
 		}
424 424
 
425 425
 		$data = '';
426
-		if ( ! empty( $args['data'] ) ) {
427
-			foreach ( $args['data'] as $key => $value ) {
428
-				$data .= 'data-' . $key . '="' . $value . '" ';
426
+		if ( ! empty($args['data'])) {
427
+			foreach ($args['data'] as $key => $value) {
428
+				$data .= 'data-'.$key.'="'.$value.'" ';
429 429
 			}
430 430
 		}
431 431
 
432
-		$output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
432
+		$output = '<span id="give-'.sanitize_key($args['name']).'-wrap">';
433 433
 
434
-		$output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
434
+		$output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>';
435 435
 
436
-		if ( ! empty( $args['desc'] ) ) {
437
-			$output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
436
+		if ( ! empty($args['desc'])) {
437
+			$output .= '<span class="give-description">'.esc_html($args['desc']).'</span>';
438 438
 		}
439 439
 
440
-		$output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $args['class'] . '" ' . $data . '' . $disabled . '/>';
440
+		$output .= '<input type="text" name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" autocomplete="'.esc_attr($args['autocomplete']).'" value="'.esc_attr($args['value']).'" placeholder="'.esc_attr($args['placeholder']).'" class="'.$args['class'].'" '.$data.''.$disabled.'/>';
441 441
 
442 442
 		$output .= '</span>';
443 443
 
@@ -453,15 +453,15 @@  discard block
 block discarded – undo
453 453
 	 *
454 454
 	 * @return string Datepicker field
455 455
 	 */
456
-	public function date_field( $args = array() ) {
456
+	public function date_field($args = array()) {
457 457
 
458
-		if ( empty( $args['class'] ) ) {
458
+		if (empty($args['class'])) {
459 459
 			$args['class'] = 'give_datepicker';
460
-		} elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) {
460
+		} elseif ( ! strpos($args['class'], 'give_datepicker')) {
461 461
 			$args['class'] .= ' give_datepicker';
462 462
 		}
463 463
 
464
-		return $this->text( $args );
464
+		return $this->text($args);
465 465
 	}
466 466
 
467 467
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @return string textarea
476 476
 	 */
477
-	public function textarea( $args = array() ) {
477
+	public function textarea($args = array()) {
478 478
 		$defaults = array(
479 479
 			'name'     => 'textarea',
480 480
 			'value'    => null,
@@ -484,21 +484,21 @@  discard block
 block discarded – undo
484 484
 			'disabled' => false
485 485
 		);
486 486
 
487
-		$args = wp_parse_args( $args, $defaults );
487
+		$args = wp_parse_args($args, $defaults);
488 488
 
489 489
 		$disabled = '';
490
-		if ( $args['disabled'] ) {
490
+		if ($args['disabled']) {
491 491
 			$disabled = ' disabled="disabled"';
492 492
 		}
493 493
 
494
-		$output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
494
+		$output = '<span id="give-'.sanitize_key($args['name']).'-wrap">';
495 495
 
496
-		$output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
496
+		$output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>';
497 497
 
498
-		$output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
498
+		$output .= '<textarea name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].'"'.$disabled.'>'.esc_attr($args['value']).'</textarea>';
499 499
 
500
-		if ( ! empty( $args['desc'] ) ) {
501
-			$output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
500
+		if ( ! empty($args['desc'])) {
501
+			$output .= '<span class="give-description">'.esc_html($args['desc']).'</span>';
502 502
 		}
503 503
 
504 504
 		$output .= '</span>';
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
 	 *
516 516
 	 * @return string text field with ajax search
517 517
 	 */
518
-	public function ajax_user_search( $args = array() ) {
518
+	public function ajax_user_search($args = array()) {
519 519
 
520 520
 		$defaults = array(
521 521
 			'name'         => 'user_id',
522 522
 			'value'        => null,
523
-			'placeholder'  => __( 'Enter username', 'give' ),
523
+			'placeholder'  => __('Enter username', 'give'),
524 524
 			'label'        => null,
525 525
 			'desc'         => null,
526 526
 			'class'        => '',
@@ -529,13 +529,13 @@  discard block
 block discarded – undo
529 529
 			'data'         => false
530 530
 		);
531 531
 
532
-		$args = wp_parse_args( $args, $defaults );
532
+		$args = wp_parse_args($args, $defaults);
533 533
 
534
-		$args['class'] = 'give-ajax-user-search ' . $args['class'];
534
+		$args['class'] = 'give-ajax-user-search '.$args['class'];
535 535
 
536 536
 		$output = '<span class="give_user_search_wrap">';
537
-		$output .= $this->text( $args );
538
-		$output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="' . __( 'Cancel', 'give' ) . '" aria-label="' . __( 'Cancel', 'give' ) . '" href="#">x</a><span></span></span>';
537
+		$output .= $this->text($args);
538
+		$output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="'.__('Cancel', 'give').'" aria-label="'.__('Cancel', 'give').'" href="#">x</a><span></span></span>';
539 539
 		$output .= '</span>';
540 540
 
541 541
 		return $output;
Please login to merge, or discard this patch.
includes/api/class-give-api.php 1 patch
Spacing   +478 added lines, -478 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
 
@@ -139,27 +139,27 @@  discard block
 block discarded – undo
139 139
 			'v1' => 'GIVE_API_V1',
140 140
 		);
141 141
 
142
-		foreach ( $this->get_versions() as $version => $class ) {
143
-			require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php';
142
+		foreach ($this->get_versions() as $version => $class) {
143
+			require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php';
144 144
 		}
145 145
 
146
-		add_action( 'init', array( $this, 'add_endpoint' ) );
147
-		add_action( 'wp', array( $this, 'process_query' ), - 1 );
148
-		add_filter( 'query_vars', array( $this, 'query_vars' ) );
149
-		add_action( 'show_user_profile', array( $this, 'user_key_field' ) );
150
-		add_action( 'edit_user_profile', array( $this, 'user_key_field' ) );
151
-		add_action( 'personal_options_update', array( $this, 'update_key' ) );
152
-		add_action( 'edit_user_profile_update', array( $this, 'update_key' ) );
153
-		add_action( 'give_process_api_key', array( $this, 'process_api_key' ) );
146
+		add_action('init', array($this, 'add_endpoint'));
147
+		add_action('wp', array($this, 'process_query'), - 1);
148
+		add_filter('query_vars', array($this, 'query_vars'));
149
+		add_action('show_user_profile', array($this, 'user_key_field'));
150
+		add_action('edit_user_profile', array($this, 'user_key_field'));
151
+		add_action('personal_options_update', array($this, 'update_key'));
152
+		add_action('edit_user_profile_update', array($this, 'update_key'));
153
+		add_action('give_process_api_key', array($this, 'process_api_key'));
154 154
 
155 155
 		// Setup a backwards compatibility check for user API Keys
156
-		add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 );
156
+		add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4);
157 157
 
158 158
 		// Determine if JSON_PRETTY_PRINT is available
159
-		$this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
159
+		$this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null;
160 160
 
161 161
 		// Allow API request logging to be turned off
162
-		$this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests );
162
+		$this->log_requests = apply_filters('give_api_log_requests', $this->log_requests);
163 163
 
164 164
 		// Setup Give_Payment_Stats instance
165 165
 		$this->stats = new Give_Payment_Stats;
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 *
176 176
 	 * @since  1.1
177 177
 	 */
178
-	public function add_endpoint( $rewrite_rules ) {
179
-		add_rewrite_endpoint( 'give-api', EP_ALL );
178
+	public function add_endpoint($rewrite_rules) {
179
+		add_rewrite_endpoint('give-api', EP_ALL);
180 180
 	}
181 181
 
182 182
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 *
190 190
 	 * @return string[] $vars New query vars
191 191
 	 */
192
-	public function query_vars( $vars ) {
192
+	public function query_vars($vars) {
193 193
 
194 194
 		$vars[] = 'token';
195 195
 		$vars[] = 'key';
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 	 */
241 241
 	public function get_default_version() {
242 242
 
243
-		$version = get_option( 'give_default_api_version' );
243
+		$version = get_option('give_default_api_version');
244 244
 
245
-		if ( defined( 'GIVE_API_VERSION' ) ) {
245
+		if (defined('GIVE_API_VERSION')) {
246 246
 			$version = GIVE_API_VERSION;
247
-		} elseif ( ! $version ) {
247
+		} elseif ( ! $version) {
248 248
 			$version = 'v1';
249 249
 		}
250 250
 
@@ -265,14 +265,14 @@  discard block
 block discarded – undo
265 265
 
266 266
 		$version = $wp_query->query_vars['give-api'];
267 267
 
268
-		if ( strpos( $version, '/' ) ) {
268
+		if (strpos($version, '/')) {
269 269
 
270
-			$version = explode( '/', $version );
271
-			$version = strtolower( $version[0] );
270
+			$version = explode('/', $version);
271
+			$version = strtolower($version[0]);
272 272
 
273
-			$wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] );
273
+			$wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']);
274 274
 
275
-			if ( array_key_exists( $version, $this->versions ) ) {
275
+			if (array_key_exists($version, $this->versions)) {
276 276
 
277 277
 				$this->queried_version = $version;
278 278
 
@@ -309,32 +309,32 @@  discard block
 block discarded – undo
309 309
 		$this->override = false;
310 310
 
311 311
 		// Make sure we have both user and api key
312
-		if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) {
312
+		if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) {
313 313
 
314
-			if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) {
314
+			if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) {
315 315
 				$this->missing_auth();
316 316
 			}
317 317
 
318 318
 			// Retrieve the user by public API key and ensure they exist
319
-			if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) {
319
+			if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) {
320 320
 
321 321
 				$this->invalid_key();
322 322
 
323 323
 			} else {
324 324
 
325
-				$token  = urldecode( $wp_query->query_vars['token'] );
326
-				$secret = $this->get_user_secret_key( $user );
327
-				$public = urldecode( $wp_query->query_vars['key'] );
325
+				$token  = urldecode($wp_query->query_vars['token']);
326
+				$secret = $this->get_user_secret_key($user);
327
+				$public = urldecode($wp_query->query_vars['key']);
328 328
 
329
-				if ( hash_equals( md5( $secret . $public ), $token ) ) {
329
+				if (hash_equals(md5($secret.$public), $token)) {
330 330
 					$this->is_valid_request = true;
331 331
 				} else {
332 332
 					$this->invalid_auth();
333 333
 				}
334 334
 			}
335
-		} elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) {
335
+		} elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') {
336 336
 			$this->is_valid_request = true;
337
-			$wp_query->set( 'key', 'public' );
337
+			$wp_query->set('key', 'public');
338 338
 		}
339 339
 	}
340 340
 
@@ -350,25 +350,25 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return bool if user ID is found, false otherwise
352 352
 	 */
353
-	public function get_user( $key = '' ) {
353
+	public function get_user($key = '') {
354 354
 		global $wpdb, $wp_query;
355 355
 
356
-		if ( empty( $key ) ) {
357
-			$key = urldecode( $wp_query->query_vars['key'] );
356
+		if (empty($key)) {
357
+			$key = urldecode($wp_query->query_vars['key']);
358 358
 		}
359 359
 
360
-		if ( empty( $key ) ) {
360
+		if (empty($key)) {
361 361
 			return false;
362 362
 		}
363 363
 
364
-		$user = get_transient( md5( 'give_api_user_' . $key ) );
364
+		$user = get_transient(md5('give_api_user_'.$key));
365 365
 
366
-		if ( false === $user ) {
367
-			$user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) );
368
-			set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS );
366
+		if (false === $user) {
367
+			$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key));
368
+			set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS);
369 369
 		}
370 370
 
371
-		if ( $user != null ) {
371
+		if ($user != null) {
372 372
 			$this->user_id = $user;
373 373
 
374 374
 			return $user;
@@ -377,37 +377,37 @@  discard block
 block discarded – undo
377 377
 		return false;
378 378
 	}
379 379
 
380
-	public function get_user_public_key( $user_id = 0 ) {
380
+	public function get_user_public_key($user_id = 0) {
381 381
 		global $wpdb;
382 382
 
383
-		if ( empty( $user_id ) ) {
383
+		if (empty($user_id)) {
384 384
 			return '';
385 385
 		}
386 386
 
387
-		$cache_key       = md5( 'give_api_user_public_key' . $user_id );
388
-		$user_public_key = get_transient( $cache_key );
387
+		$cache_key       = md5('give_api_user_public_key'.$user_id);
388
+		$user_public_key = get_transient($cache_key);
389 389
 
390
-		if ( empty( $user_public_key ) ) {
391
-			$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 ) );
392
-			set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS );
390
+		if (empty($user_public_key)) {
391
+			$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));
392
+			set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS);
393 393
 		}
394 394
 
395 395
 		return $user_public_key;
396 396
 	}
397 397
 
398
-	public function get_user_secret_key( $user_id = 0 ) {
398
+	public function get_user_secret_key($user_id = 0) {
399 399
 		global $wpdb;
400 400
 
401
-		if ( empty( $user_id ) ) {
401
+		if (empty($user_id)) {
402 402
 			return '';
403 403
 		}
404 404
 
405
-		$cache_key       = md5( 'give_api_user_secret_key' . $user_id );
406
-		$user_secret_key = get_transient( $cache_key );
405
+		$cache_key       = md5('give_api_user_secret_key'.$user_id);
406
+		$user_secret_key = get_transient($cache_key);
407 407
 
408
-		if ( empty( $user_secret_key ) ) {
409
-			$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 ) );
410
-			set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS );
408
+		if (empty($user_secret_key)) {
409
+			$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));
410
+			set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS);
411 411
 		}
412 412
 
413 413
 		return $user_secret_key;
@@ -423,10 +423,10 @@  discard block
 block discarded – undo
423 423
 	 */
424 424
 	private function missing_auth() {
425 425
 		$error          = array();
426
-		$error['error'] = esc_attr__( 'You must specify both a token and API key!', 'give' );
426
+		$error['error'] = esc_attr__('You must specify both a token and API key!', 'give');
427 427
 
428 428
 		$this->data = $error;
429
-		$this->output( 401 );
429
+		$this->output(401);
430 430
 	}
431 431
 
432 432
 	/**
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
 	 */
441 441
 	private function invalid_auth() {
442 442
 		$error          = array();
443
-		$error['error'] = esc_attr__( 'Your request could not be authenticated!', 'give' );
443
+		$error['error'] = esc_attr__('Your request could not be authenticated!', 'give');
444 444
 
445 445
 		$this->data = $error;
446
-		$this->output( 403 );
446
+		$this->output(403);
447 447
 	}
448 448
 
449 449
 	/**
@@ -457,10 +457,10 @@  discard block
 block discarded – undo
457 457
 	 */
458 458
 	private function invalid_key() {
459 459
 		$error          = array();
460
-		$error['error'] = esc_attr__( 'Invalid API key!', 'give' );
460
+		$error['error'] = esc_attr__('Invalid API key!', 'give');
461 461
 
462 462
 		$this->data = $error;
463
-		$this->output( 403 );
463
+		$this->output(403);
464 464
 	}
465 465
 
466 466
 	/**
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
 	 */
474 474
 	private function invalid_version() {
475 475
 		$error          = array();
476
-		$error['error'] = esc_attr__( 'Invalid API version!', 'give' );
476
+		$error['error'] = esc_attr__('Invalid API version!', 'give');
477 477
 
478 478
 		$this->data = $error;
479
-		$this->output( 404 );
479
+		$this->output(404);
480 480
 	}
481 481
 
482 482
 	/**
@@ -492,10 +492,10 @@  discard block
 block discarded – undo
492 492
 		global $wp_query;
493 493
 
494 494
 		// Start logging how long the request takes for logging
495
-		$before = microtime( true );
495
+		$before = microtime(true);
496 496
 
497 497
 		// Check for give-api var. Get out if not present
498
-		if ( empty( $wp_query->query_vars['give-api'] ) ) {
498
+		if (empty($wp_query->query_vars['give-api'])) {
499 499
 			return;
500 500
 		}
501 501
 
@@ -509,45 +509,45 @@  discard block
 block discarded – undo
509 509
 		$this->validate_request();
510 510
 
511 511
 		// Only proceed if no errors have been noted
512
-		if ( ! $this->is_valid_request ) {
512
+		if ( ! $this->is_valid_request) {
513 513
 			return;
514 514
 		}
515 515
 
516
-		if ( ! defined( 'GIVE_DOING_API' ) ) {
517
-			define( 'GIVE_DOING_API', true );
516
+		if ( ! defined('GIVE_DOING_API')) {
517
+			define('GIVE_DOING_API', true);
518 518
 		}
519 519
 
520 520
 		$data         = array();
521 521
 		$this->routes = new $this->versions[$this->get_queried_version()];
522 522
 		$this->routes->validate_request();
523 523
 
524
-		switch ( $this->endpoint ) :
524
+		switch ($this->endpoint) :
525 525
 
526 526
 			case 'stats' :
527 527
 
528
-				$data = $this->routes->get_stats( array(
529
-					'type'      => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null,
530
-					'form'      => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null,
531
-					'date'      => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null,
532
-					'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null,
533
-					'enddate'   => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null
534
-				) );
528
+				$data = $this->routes->get_stats(array(
529
+					'type'      => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null,
530
+					'form'      => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null,
531
+					'date'      => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null,
532
+					'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null,
533
+					'enddate'   => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null
534
+				));
535 535
 
536 536
 				break;
537 537
 
538 538
 			case 'forms' :
539 539
 
540
-				$form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null;
540
+				$form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null;
541 541
 
542
-				$data = $this->routes->get_forms( $form );
542
+				$data = $this->routes->get_forms($form);
543 543
 
544 544
 				break;
545 545
 
546 546
 			case 'donors' :
547 547
 
548
-				$customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null;
548
+				$customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null;
549 549
 
550
-				$data = $this->routes->get_customers( $customer );
550
+				$data = $this->routes->get_customers($customer);
551 551
 
552 552
 				break;
553 553
 
@@ -560,14 +560,14 @@  discard block
 block discarded – undo
560 560
 		endswitch;
561 561
 
562 562
 		// Allow extensions to setup their own return data
563
-		$this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this );
563
+		$this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this);
564 564
 
565
-		$after                       = microtime( true );
566
-		$request_time                = ( $after - $before );
565
+		$after                       = microtime(true);
566
+		$request_time                = ($after - $before);
567 567
 		$this->data['request_speed'] = $request_time;
568 568
 
569 569
 		// Log this API request, if enabled. We log it here because we have access to errors.
570
-		$this->log_request( $this->data );
570
+		$this->log_request($this->data);
571 571
 
572 572
 		// Send out data to the output function
573 573
 		$this->output();
@@ -597,25 +597,25 @@  discard block
 block discarded – undo
597 597
 		global $wp_query;
598 598
 
599 599
 		// Whitelist our query options
600
-		$accepted = apply_filters( 'give_api_valid_query_modes', array(
600
+		$accepted = apply_filters('give_api_valid_query_modes', array(
601 601
 			'stats',
602 602
 			'forms',
603 603
 			'donors',
604 604
 			'donations'
605
-		) );
605
+		));
606 606
 
607
-		$query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null;
608
-		$query = str_replace( $this->queried_version . '/', '', $query );
607
+		$query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null;
608
+		$query = str_replace($this->queried_version.'/', '', $query);
609 609
 
610 610
 		$error = array();
611 611
 
612 612
 		// Make sure our query is valid
613
-		if ( ! in_array( $query, $accepted ) ) {
614
-			$error['error'] = __( 'Invalid query!', 'give' );
613
+		if ( ! in_array($query, $accepted)) {
614
+			$error['error'] = __('Invalid query!', 'give');
615 615
 
616 616
 			$this->data = $error;
617 617
 			// 400 is Bad Request
618
-			$this->output( 400 );
618
+			$this->output(400);
619 619
 		}
620 620
 
621 621
 		$this->endpoint = $query;
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	public function get_paged() {
633 633
 		global $wp_query;
634 634
 
635
-		return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1;
635
+		return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1;
636 636
 	}
637 637
 
638 638
 
@@ -647,13 +647,13 @@  discard block
 block discarded – undo
647 647
 	public function per_page() {
648 648
 		global $wp_query;
649 649
 
650
-		$per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10;
650
+		$per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10;
651 651
 
652
-		if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) {
652
+		if ($per_page < 0 && $this->get_query_mode() == 'donors') {
653 653
 			$per_page = 99999999;
654 654
 		} // Customers query doesn't support -1
655 655
 
656
-		return apply_filters( 'give_api_results_per_page', $per_page );
656
+		return apply_filters('give_api_results_per_page', $per_page);
657 657
 	}
658 658
 
659 659
 	/**
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 *
667 667
 	 * @return array $dates
668 668
 	 */
669
-	public function get_dates( $args = array() ) {
669
+	public function get_dates($args = array()) {
670 670
 		$dates = array();
671 671
 
672 672
 		$defaults = array(
@@ -677,60 +677,60 @@  discard block
 block discarded – undo
677 677
 			'enddate'   => null
678 678
 		);
679 679
 
680
-		$args = wp_parse_args( $args, $defaults );
680
+		$args = wp_parse_args($args, $defaults);
681 681
 
682
-		$current_time = current_time( 'timestamp' );
682
+		$current_time = current_time('timestamp');
683 683
 
684
-		if ( 'range' === $args['date'] ) {
685
-			$startdate          = strtotime( $args['startdate'] );
686
-			$enddate            = strtotime( $args['enddate'] );
687
-			$dates['day_start'] = date( 'd', $startdate );
688
-			$dates['day_end']   = date( 'd', $enddate );
689
-			$dates['m_start']   = date( 'n', $startdate );
690
-			$dates['m_end']     = date( 'n', $enddate );
691
-			$dates['year']      = date( 'Y', $startdate );
692
-			$dates['year_end']  = date( 'Y', $enddate );
684
+		if ('range' === $args['date']) {
685
+			$startdate          = strtotime($args['startdate']);
686
+			$enddate            = strtotime($args['enddate']);
687
+			$dates['day_start'] = date('d', $startdate);
688
+			$dates['day_end']   = date('d', $enddate);
689
+			$dates['m_start']   = date('n', $startdate);
690
+			$dates['m_end']     = date('n', $enddate);
691
+			$dates['year']      = date('Y', $startdate);
692
+			$dates['year_end']  = date('Y', $enddate);
693 693
 		} else {
694 694
 			// Modify dates based on predefined ranges
695
-			switch ( $args['date'] ) :
695
+			switch ($args['date']) :
696 696
 
697 697
 				case 'this_month' :
698 698
 					$dates['day']     = null;
699
-					$dates['m_start'] = date( 'n', $current_time );
700
-					$dates['m_end']   = date( 'n', $current_time );
701
-					$dates['year']    = date( 'Y', $current_time );
699
+					$dates['m_start'] = date('n', $current_time);
700
+					$dates['m_end']   = date('n', $current_time);
701
+					$dates['year']    = date('Y', $current_time);
702 702
 					break;
703 703
 
704 704
 				case 'last_month' :
705 705
 					$dates['day']     = null;
706
-					$dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1;
706
+					$dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1;
707 707
 					$dates['m_end']   = $dates['m_start'];
708
-					$dates['year']    = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time );
708
+					$dates['year']    = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time);
709 709
 					break;
710 710
 
711 711
 				case 'today' :
712
-					$dates['day']     = date( 'd', $current_time );
713
-					$dates['m_start'] = date( 'n', $current_time );
714
-					$dates['m_end']   = date( 'n', $current_time );
715
-					$dates['year']    = date( 'Y', $current_time );
712
+					$dates['day']     = date('d', $current_time);
713
+					$dates['m_start'] = date('n', $current_time);
714
+					$dates['m_end']   = date('n', $current_time);
715
+					$dates['year']    = date('Y', $current_time);
716 716
 					break;
717 717
 
718 718
 				case 'yesterday' :
719 719
 
720
-					$year  = date( 'Y', $current_time );
721
-					$month = date( 'n', $current_time );
722
-					$day   = date( 'd', $current_time );
720
+					$year  = date('Y', $current_time);
721
+					$month = date('n', $current_time);
722
+					$day   = date('d', $current_time);
723 723
 
724
-					if ( $month == 1 && $day == 1 ) {
724
+					if ($month == 1 && $day == 1) {
725 725
 
726 726
 						$year -= 1;
727 727
 						$month = 12;
728
-						$day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );
728
+						$day   = cal_days_in_month(CAL_GREGORIAN, $month, $year);
729 729
 
730
-					} elseif ( $month > 1 && $day == 1 ) {
730
+					} elseif ($month > 1 && $day == 1) {
731 731
 
732 732
 						$month -= 1;
733
-						$day = cal_days_in_month( CAL_GREGORIAN, $month, $year );
733
+						$day = cal_days_in_month(CAL_GREGORIAN, $month, $year);
734 734
 
735 735
 					} else {
736 736
 
@@ -746,65 +746,65 @@  discard block
 block discarded – undo
746 746
 					break;
747 747
 
748 748
 				case 'this_quarter' :
749
-					$month_now = date( 'n', $current_time );
749
+					$month_now = date('n', $current_time);
750 750
 
751 751
 					$dates['day'] = null;
752 752
 
753
-					if ( $month_now <= 3 ) {
753
+					if ($month_now <= 3) {
754 754
 
755 755
 						$dates['m_start'] = 1;
756 756
 						$dates['m_end']   = 3;
757
-						$dates['year']    = date( 'Y', $current_time );
757
+						$dates['year']    = date('Y', $current_time);
758 758
 
759
-					} else if ( $month_now <= 6 ) {
759
+					} else if ($month_now <= 6) {
760 760
 
761 761
 						$dates['m_start'] = 4;
762 762
 						$dates['m_end']   = 6;
763
-						$dates['year']    = date( 'Y', $current_time );
763
+						$dates['year']    = date('Y', $current_time);
764 764
 
765
-					} else if ( $month_now <= 9 ) {
765
+					} else if ($month_now <= 9) {
766 766
 
767 767
 						$dates['m_start'] = 7;
768 768
 						$dates['m_end']   = 9;
769
-						$dates['year']    = date( 'Y', $current_time );
769
+						$dates['year']    = date('Y', $current_time);
770 770
 
771 771
 					} else {
772 772
 
773 773
 						$dates['m_start'] = 10;
774 774
 						$dates['m_end']   = 12;
775
-						$dates['year']    = date( 'Y', $current_time );
775
+						$dates['year']    = date('Y', $current_time);
776 776
 
777 777
 					}
778 778
 					break;
779 779
 
780 780
 				case 'last_quarter' :
781
-					$month_now = date( 'n', $current_time );
781
+					$month_now = date('n', $current_time);
782 782
 
783 783
 					$dates['day'] = null;
784 784
 
785
-					if ( $month_now <= 3 ) {
785
+					if ($month_now <= 3) {
786 786
 
787 787
 						$dates['m_start'] = 10;
788 788
 						$dates['m_end']   = 12;
789
-						$dates['year']    = date( 'Y', $current_time ) - 1; // Previous year
789
+						$dates['year']    = date('Y', $current_time) - 1; // Previous year
790 790
 
791
-					} else if ( $month_now <= 6 ) {
791
+					} else if ($month_now <= 6) {
792 792
 
793 793
 						$dates['m_start'] = 1;
794 794
 						$dates['m_end']   = 3;
795
-						$dates['year']    = date( 'Y', $current_time );
795
+						$dates['year']    = date('Y', $current_time);
796 796
 
797
-					} else if ( $month_now <= 9 ) {
797
+					} else if ($month_now <= 9) {
798 798
 
799 799
 						$dates['m_start'] = 4;
800 800
 						$dates['m_end']   = 6;
801
-						$dates['year']    = date( 'Y', $current_time );
801
+						$dates['year']    = date('Y', $current_time);
802 802
 
803 803
 					} else {
804 804
 
805 805
 						$dates['m_start'] = 7;
806 806
 						$dates['m_end']   = 9;
807
-						$dates['year']    = date( 'Y', $current_time );
807
+						$dates['year']    = date('Y', $current_time);
808 808
 
809 809
 					}
810 810
 					break;
@@ -813,14 +813,14 @@  discard block
 block discarded – undo
813 813
 					$dates['day']     = null;
814 814
 					$dates['m_start'] = null;
815 815
 					$dates['m_end']   = null;
816
-					$dates['year']    = date( 'Y', $current_time );
816
+					$dates['year']    = date('Y', $current_time);
817 817
 					break;
818 818
 
819 819
 				case 'last_year' :
820 820
 					$dates['day']     = null;
821 821
 					$dates['m_start'] = null;
822 822
 					$dates['m_end']   = null;
823
-					$dates['year']    = date( 'Y', $current_time ) - 1;
823
+					$dates['year']    = date('Y', $current_time) - 1;
824 824
 					break;
825 825
 
826 826
 			endswitch;
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 		 * @param object $dates The dates used for retreiving earnings/donations
835 835
 		 */
836 836
 
837
-		return apply_filters( 'give_api_stat_dates', $dates );
837
+		return apply_filters('give_api_stat_dates', $dates);
838 838
 	}
839 839
 
840 840
 	/**
@@ -849,11 +849,11 @@  discard block
 block discarded – undo
849 849
 	 *
850 850
 	 * @return array $customers Multidimensional array of the customers
851 851
 	 */
852
-	public function get_customers( $customer = null ) {
852
+	public function get_customers($customer = null) {
853 853
 
854 854
 		$customers = array();
855 855
 		$error     = array();
856
-		if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) {
856
+		if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) {
857 857
 			return $customers;
858 858
 		}
859 859
 
@@ -861,68 +861,68 @@  discard block
 block discarded – undo
861 861
 
862 862
 		$paged    = $this->get_paged();
863 863
 		$per_page = $this->per_page();
864
-		$offset   = $per_page * ( $paged - 1 );
864
+		$offset   = $per_page * ($paged - 1);
865 865
 
866
-		if ( is_numeric( $customer ) ) {
866
+		if (is_numeric($customer)) {
867 867
 			$field = 'id';
868 868
 		} else {
869 869
 			$field = 'email';
870 870
 		}
871 871
 
872
-		$customer_query = Give()->customers->get_customers( array(
872
+		$customer_query = Give()->customers->get_customers(array(
873 873
 			'number' => $per_page,
874 874
 			'offset' => $offset,
875 875
 			$field   => $customer
876
-		) );
876
+		));
877 877
 		$customer_count = 0;
878 878
 
879
-		if ( $customer_query ) {
879
+		if ($customer_query) {
880 880
 
881
-			foreach ( $customer_query as $customer_obj ) {
881
+			foreach ($customer_query as $customer_obj) {
882 882
 
883
-				$names      = explode( ' ', $customer_obj->name );
884
-				$first_name = ! empty( $names[0] ) ? $names[0] : '';
883
+				$names      = explode(' ', $customer_obj->name);
884
+				$first_name = ! empty($names[0]) ? $names[0] : '';
885 885
 				$last_name  = '';
886
-				if ( ! empty( $names[1] ) ) {
887
-					unset( $names[0] );
888
-					$last_name = implode( ' ', $names );
886
+				if ( ! empty($names[1])) {
887
+					unset($names[0]);
888
+					$last_name = implode(' ', $names);
889 889
 				}
890 890
 
891
-				$customers['donors'][ $customer_count ]['info']['user_id']      = '';
892
-				$customers['donors'][ $customer_count ]['info']['username']     = '';
893
-				$customers['donors'][ $customer_count ]['info']['display_name'] = '';
894
-				$customers['donors'][ $customer_count ]['info']['customer_id']  = $customer_obj->id;
895
-				$customers['donors'][ $customer_count ]['info']['first_name']   = $first_name;
896
-				$customers['donors'][ $customer_count ]['info']['last_name']    = $last_name;
897
-				$customers['donors'][ $customer_count ]['info']['email']        = $customer_obj->email;
891
+				$customers['donors'][$customer_count]['info']['user_id']      = '';
892
+				$customers['donors'][$customer_count]['info']['username']     = '';
893
+				$customers['donors'][$customer_count]['info']['display_name'] = '';
894
+				$customers['donors'][$customer_count]['info']['customer_id']  = $customer_obj->id;
895
+				$customers['donors'][$customer_count]['info']['first_name']   = $first_name;
896
+				$customers['donors'][$customer_count]['info']['last_name']    = $last_name;
897
+				$customers['donors'][$customer_count]['info']['email']        = $customer_obj->email;
898 898
 
899
-				if ( ! empty( $customer_obj->user_id ) ) {
899
+				if ( ! empty($customer_obj->user_id)) {
900 900
 
901
-					$user_data = get_userdata( $customer_obj->user_id );
901
+					$user_data = get_userdata($customer_obj->user_id);
902 902
 
903 903
 					// Customer with registered account
904
-					$customers['donors'][ $customer_count ]['info']['user_id']      = $customer_obj->user_id;
905
-					$customers['donors'][ $customer_count ]['info']['username']     = $user_data->user_login;
906
-					$customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name;
904
+					$customers['donors'][$customer_count]['info']['user_id']      = $customer_obj->user_id;
905
+					$customers['donors'][$customer_count]['info']['username']     = $user_data->user_login;
906
+					$customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name;
907 907
 
908 908
 				}
909 909
 
910
-				$customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count;
911
-				$customers['donors'][ $customer_count ]['stats']['total_spent']     = $customer_obj->purchase_value;
910
+				$customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count;
911
+				$customers['donors'][$customer_count]['stats']['total_spent']     = $customer_obj->purchase_value;
912 912
 
913
-				$customer_count ++;
913
+				$customer_count++;
914 914
 
915 915
 			}
916 916
 
917
-		} elseif ( $customer ) {
917
+		} elseif ($customer) {
918 918
 
919
-			$error['error'] = sprintf( __( 'Donor %s not found!', 'give' ), $customer );
919
+			$error['error'] = sprintf(__('Donor %s not found!', 'give'), $customer);
920 920
 
921 921
 			return $error;
922 922
 
923 923
 		} else {
924 924
 
925
-			$error['error'] = __( 'No donors found!', 'give' );
925
+			$error['error'] = __('No donors found!', 'give');
926 926
 
927 927
 			return $error;
928 928
 
@@ -941,36 +941,36 @@  discard block
 block discarded – undo
941 941
 	 *
942 942
 	 * @return array $customers Multidimensional array of the forms
943 943
 	 */
944
-	public function get_forms( $form = null ) {
944
+	public function get_forms($form = null) {
945 945
 
946 946
 		$forms = array();
947 947
 		$error = array();
948 948
 
949
-		if ( $form == null ) {
949
+		if ($form == null) {
950 950
 			$forms['forms'] = array();
951 951
 
952
-			$form_list = get_posts( array(
952
+			$form_list = get_posts(array(
953 953
 				'post_type'        => 'give_forms',
954 954
 				'posts_per_page'   => $this->per_page(),
955 955
 				'suppress_filters' => true,
956 956
 				'paged'            => $this->get_paged()
957
-			) );
957
+			));
958 958
 
959
-			if ( $form_list ) {
959
+			if ($form_list) {
960 960
 				$i = 0;
961
-				foreach ( $form_list as $form_info ) {
962
-					$forms['forms'][ $i ] = $this->get_form_data( $form_info );
963
-					$i ++;
961
+				foreach ($form_list as $form_info) {
962
+					$forms['forms'][$i] = $this->get_form_data($form_info);
963
+					$i++;
964 964
 				}
965 965
 			}
966 966
 		} else {
967
-			if ( get_post_type( $form ) == 'give_forms' ) {
968
-				$form_info = get_post( $form );
967
+			if (get_post_type($form) == 'give_forms') {
968
+				$form_info = get_post($form);
969 969
 
970
-				$forms['forms'][0] = $this->get_form_data( $form_info );
970
+				$forms['forms'][0] = $this->get_form_data($form_info);
971 971
 
972 972
 			} else {
973
-				$error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $form );
973
+				$error['error'] = sprintf(__('Form %s not found!', 'give'), $form);
974 974
 
975 975
 				return $error;
976 976
 			}
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 	 *
989 989
 	 * @return array                Array of post data to return back in the API
990 990
 	 */
991
-	private function get_form_data( $form_info ) {
991
+	private function get_form_data($form_info) {
992 992
 
993 993
 		$form = array();
994 994
 
@@ -998,46 +998,46 @@  discard block
 block discarded – undo
998 998
 		$form['info']['create_date']   = $form_info->post_date;
999 999
 		$form['info']['modified_date'] = $form_info->post_modified;
1000 1000
 		$form['info']['status']        = $form_info->post_status;
1001
-		$form['info']['link']          = html_entity_decode( $form_info->guid );
1002
-		$form['info']['content']       = get_post_meta( $form_info->ID, '_give_form_content', true );
1003
-		$form['info']['thumbnail']     = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) );
1001
+		$form['info']['link']          = html_entity_decode($form_info->guid);
1002
+		$form['info']['content']       = get_post_meta($form_info->ID, '_give_form_content', true);
1003
+		$form['info']['thumbnail']     = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID));
1004 1004
 
1005
-		if ( give_get_option( 'enable_categories' ) == 'on' ) {
1006
-			$form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' );
1007
-			$form['info']['tags']     = get_the_terms( $form_info, 'give_forms_tag' );
1005
+		if (give_get_option('enable_categories') == 'on') {
1006
+			$form['info']['category'] = get_the_terms($form_info, 'give_forms_category');
1007
+			$form['info']['tags']     = get_the_terms($form_info, 'give_forms_tag');
1008 1008
 		}
1009
-		if ( give_get_option( 'enable_tags' ) == 'on' ) {
1010
-			$form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' );
1009
+		if (give_get_option('enable_tags') == 'on') {
1010
+			$form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag');
1011 1011
 		}
1012 1012
 
1013
-		if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) {
1014
-			$form['stats']['total']['donations']           = give_get_form_sales_stats( $form_info->ID );
1015
-			$form['stats']['total']['earnings']            = give_get_form_earnings_stats( $form_info->ID );
1016
-			$form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID );
1017
-			$form['stats']['monthly_average']['earnings']  = give_get_average_monthly_form_earnings( $form_info->ID );
1013
+		if (user_can($this->user_id, 'view_give_reports') || $this->override) {
1014
+			$form['stats']['total']['donations']           = give_get_form_sales_stats($form_info->ID);
1015
+			$form['stats']['total']['earnings']            = give_get_form_earnings_stats($form_info->ID);
1016
+			$form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID);
1017
+			$form['stats']['monthly_average']['earnings']  = give_get_average_monthly_form_earnings($form_info->ID);
1018 1018
 		}
1019 1019
 
1020 1020
 		$counter = 0;
1021
-		if ( give_has_variable_prices( $form_info->ID ) ) {
1022
-			foreach ( give_get_variable_prices( $form_info->ID ) as $price ) {
1023
-				$counter ++;
1021
+		if (give_has_variable_prices($form_info->ID)) {
1022
+			foreach (give_get_variable_prices($form_info->ID) as $price) {
1023
+				$counter++;
1024 1024
 				//muli-level item
1025
-				$level                                     = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter;
1026
-				$form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount'];
1025
+				$level                                     = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter;
1026
+				$form['pricing'][sanitize_key($level)] = $price['_give_amount'];
1027 1027
 
1028 1028
 			}
1029 1029
 		} else {
1030
-			$form['pricing']['amount'] = give_get_form_price( $form_info->ID );
1030
+			$form['pricing']['amount'] = give_get_form_price($form_info->ID);
1031 1031
 		}
1032 1032
 
1033
-		if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) {
1033
+		if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) {
1034 1034
 
1035 1035
 			//Sensitive data here
1036
-			do_action( 'give_api_sensitive_data' );
1036
+			do_action('give_api_sensitive_data');
1037 1037
 
1038 1038
 		}
1039 1039
 
1040
-		return apply_filters( 'give_api_forms_form', $form );
1040
+		return apply_filters('give_api_forms_form', $form);
1041 1041
 
1042 1042
 	}
1043 1043
 
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 	 *
1053 1053
 	 * @return array
1054 1054
 	 */
1055
-	public function get_stats( $args = array() ) {
1055
+	public function get_stats($args = array()) {
1056 1056
 		$defaults = array(
1057 1057
 			'type'      => null,
1058 1058
 			'form'      => null,
@@ -1061,9 +1061,9 @@  discard block
 block discarded – undo
1061 1061
 			'enddate'   => null
1062 1062
 		);
1063 1063
 
1064
-		$args = wp_parse_args( $args, $defaults );
1064
+		$args = wp_parse_args($args, $defaults);
1065 1065
 
1066
-		$dates = $this->get_dates( $args );
1066
+		$dates = $this->get_dates($args);
1067 1067
 
1068 1068
 		$stats    = array();
1069 1069
 		$earnings = array(
@@ -1074,41 +1074,41 @@  discard block
 block discarded – undo
1074 1074
 		);
1075 1075
 		$error    = array();
1076 1076
 
1077
-		if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) {
1077
+		if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) {
1078 1078
 			return $stats;
1079 1079
 		}
1080 1080
 
1081
-		if ( $args['type'] == 'donations' ) {
1081
+		if ($args['type'] == 'donations') {
1082 1082
 
1083
-			if ( $args['form'] == null ) {
1084
-				if ( $args['date'] == null ) {
1083
+			if ($args['form'] == null) {
1084
+				if ($args['date'] == null) {
1085 1085
 					$sales = $this->get_default_sales_stats();
1086
-				} elseif ( $args['date'] === 'range' ) {
1086
+				} elseif ($args['date'] === 'range') {
1087 1087
 					// Return sales for a date range
1088 1088
 
1089 1089
 					// Ensure the end date is later than the start date
1090
-					if ( $args['enddate'] < $args['startdate'] ) {
1091
-						$error['error'] = __( 'The end date must be later than the start date!', 'give' );
1090
+					if ($args['enddate'] < $args['startdate']) {
1091
+						$error['error'] = __('The end date must be later than the start date!', 'give');
1092 1092
 					}
1093 1093
 
1094 1094
 					// Ensure both the start and end date are specified
1095
-					if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) {
1096
-						$error['error'] = __( 'Invalid or no date range specified!', 'give' );
1095
+					if (empty($args['startdate']) || empty($args['enddate'])) {
1096
+						$error['error'] = __('Invalid or no date range specified!', 'give');
1097 1097
 					}
1098 1098
 
1099 1099
 					$total = 0;
1100 1100
 
1101 1101
 					// Loop through the years
1102 1102
 					$y = $dates['year'];
1103
-					while ( $y <= $dates['year_end'] ) :
1103
+					while ($y <= $dates['year_end']) :
1104 1104
 
1105
-						if ( $dates['year'] == $dates['year_end'] ) {
1105
+						if ($dates['year'] == $dates['year_end']) {
1106 1106
 							$month_start = $dates['m_start'];
1107 1107
 							$month_end   = $dates['m_end'];
1108
-						} elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) {
1108
+						} elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
1109 1109
 							$month_start = $dates['m_start'];
1110 1110
 							$month_end   = 12;
1111
-						} elseif ( $y == $dates['year_end'] ) {
1111
+						} elseif ($y == $dates['year_end']) {
1112 1112
 							$month_start = 1;
1113 1113
 							$month_end   = $dates['m_end'];
1114 1114
 						} else {
@@ -1117,109 +1117,109 @@  discard block
 block discarded – undo
1117 1117
 						}
1118 1118
 
1119 1119
 						$i = $month_start;
1120
-						while ( $i <= $month_end ) :
1120
+						while ($i <= $month_end) :
1121 1121
 
1122
-							if ( $i == $dates['m_start'] ) {
1122
+							if ($i == $dates['m_start']) {
1123 1123
 								$d = $dates['day_start'];
1124 1124
 							} else {
1125 1125
 								$d = 1;
1126 1126
 							}
1127 1127
 
1128
-							if ( $i == $dates['m_end'] ) {
1128
+							if ($i == $dates['m_end']) {
1129 1129
 								$num_of_days = $dates['day_end'];
1130 1130
 							} else {
1131
-								$num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y );
1131
+								$num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
1132 1132
 							}
1133 1133
 
1134
-							while ( $d <= $num_of_days ) :
1135
-								$sale_count = give_get_sales_by_date( $d, $i, $y );
1136
-								$date_key   = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) );
1137
-								if ( ! isset( $sales['sales'][ $date_key ] ) ) {
1138
-									$sales['sales'][ $date_key ] = 0;
1134
+							while ($d <= $num_of_days) :
1135
+								$sale_count = give_get_sales_by_date($d, $i, $y);
1136
+								$date_key   = date('Ymd', strtotime($y.'/'.$i.'/'.$d));
1137
+								if ( ! isset($sales['sales'][$date_key])) {
1138
+									$sales['sales'][$date_key] = 0;
1139 1139
 								}
1140
-								$sales['sales'][ $date_key ] += $sale_count;
1140
+								$sales['sales'][$date_key] += $sale_count;
1141 1141
 								$total += $sale_count;
1142
-								$d ++;
1142
+								$d++;
1143 1143
 							endwhile;
1144
-							$i ++;
1144
+							$i++;
1145 1145
 						endwhile;
1146 1146
 
1147
-						$y ++;
1147
+						$y++;
1148 1148
 					endwhile;
1149 1149
 
1150 1150
 					$sales['totals'] = $total;
1151 1151
 				} else {
1152
-					if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) {
1152
+					if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
1153 1153
 						$sales_count = 0;
1154 1154
 
1155 1155
 						// Loop through the months
1156 1156
 						$month = $dates['m_start'];
1157 1157
 
1158
-						while ( $month <= $dates['m_end'] ) :
1159
-							$sales_count += give_get_sales_by_date( null, $month, $dates['year'] );
1160
-							$month ++;
1158
+						while ($month <= $dates['m_end']) :
1159
+							$sales_count += give_get_sales_by_date(null, $month, $dates['year']);
1160
+							$month++;
1161 1161
 						endwhile;
1162 1162
 
1163
-						$sales['donations'][ $args['date'] ] = $sales_count;
1163
+						$sales['donations'][$args['date']] = $sales_count;
1164 1164
 					} else {
1165
-						$sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] );
1165
+						$sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']);
1166 1166
 					}
1167 1167
 				}
1168
-			} elseif ( $args['form'] == 'all' ) {
1169
-				$forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) );
1168
+			} elseif ($args['form'] == 'all') {
1169
+				$forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true));
1170 1170
 				$i     = 0;
1171
-				foreach ( $forms as $form_info ) {
1172
-					$sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) );
1173
-					$i ++;
1171
+				foreach ($forms as $form_info) {
1172
+					$sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID));
1173
+					$i++;
1174 1174
 				}
1175 1175
 			} else {
1176
-				if ( get_post_type( $args['form'] ) == 'give_forms' ) {
1177
-					$form_info             = get_post( $args['form'] );
1178
-					$sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) );
1176
+				if (get_post_type($args['form']) == 'give_forms') {
1177
+					$form_info             = get_post($args['form']);
1178
+					$sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form']));
1179 1179
 				} else {
1180
-					$error['error'] = sprintf( __( 'Product %s not found!', 'give' ), $args['form'] );
1180
+					$error['error'] = sprintf(__('Product %s not found!', 'give'), $args['form']);
1181 1181
 				}
1182 1182
 			}
1183 1183
 
1184
-			if ( ! empty( $error ) ) {
1184
+			if ( ! empty($error)) {
1185 1185
 				return $error;
1186 1186
 			}
1187 1187
 
1188 1188
 			return $sales;
1189 1189
 
1190
-		} elseif ( $args['type'] == 'earnings' ) {
1191
-			if ( $args['form'] == null ) {
1192
-				if ( $args['date'] == null ) {
1190
+		} elseif ($args['type'] == 'earnings') {
1191
+			if ($args['form'] == null) {
1192
+				if ($args['date'] == null) {
1193 1193
 					$earnings = $this->get_default_earnings_stats();
1194
-				} elseif ( $args['date'] === 'range' ) {
1194
+				} elseif ($args['date'] === 'range') {
1195 1195
 					// Return sales for a date range
1196 1196
 
1197 1197
 					// Ensure the end date is later than the start date
1198
-					if ( $args['enddate'] < $args['startdate'] ) {
1199
-						$error['error'] = __( 'The end date must be later than the start date!', 'give' );
1198
+					if ($args['enddate'] < $args['startdate']) {
1199
+						$error['error'] = __('The end date must be later than the start date!', 'give');
1200 1200
 					}
1201 1201
 
1202 1202
 					// Ensure both the start and end date are specified
1203
-					if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) {
1204
-						$error['error'] = __( 'Invalid or no date range specified!', 'give' );
1203
+					if (empty($args['startdate']) || empty($args['enddate'])) {
1204
+						$error['error'] = __('Invalid or no date range specified!', 'give');
1205 1205
 					}
1206 1206
 
1207 1207
 					$total = (float) 0.00;
1208 1208
 
1209 1209
 					// Loop through the years
1210 1210
 					$y = $dates['year'];
1211
-					if ( ! isset( $earnings['earnings'] ) ) {
1211
+					if ( ! isset($earnings['earnings'])) {
1212 1212
 						$earnings['earnings'] = array();
1213 1213
 					}
1214
-					while ( $y <= $dates['year_end'] ) :
1214
+					while ($y <= $dates['year_end']) :
1215 1215
 
1216
-						if ( $dates['year'] == $dates['year_end'] ) {
1216
+						if ($dates['year'] == $dates['year_end']) {
1217 1217
 							$month_start = $dates['m_start'];
1218 1218
 							$month_end   = $dates['m_end'];
1219
-						} elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) {
1219
+						} elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
1220 1220
 							$month_start = $dates['m_start'];
1221 1221
 							$month_end   = 12;
1222
-						} elseif ( $y == $dates['year_end'] ) {
1222
+						} elseif ($y == $dates['year_end']) {
1223 1223
 							$month_start = 1;
1224 1224
 							$month_end   = $dates['m_end'];
1225 1225
 						} else {
@@ -1228,88 +1228,88 @@  discard block
 block discarded – undo
1228 1228
 						}
1229 1229
 
1230 1230
 						$i = $month_start;
1231
-						while ( $i <= $month_end ) :
1231
+						while ($i <= $month_end) :
1232 1232
 
1233
-							if ( $i == $dates['m_start'] ) {
1233
+							if ($i == $dates['m_start']) {
1234 1234
 								$d = $dates['day_start'];
1235 1235
 							} else {
1236 1236
 								$d = 1;
1237 1237
 							}
1238 1238
 
1239
-							if ( $i == $dates['m_end'] ) {
1239
+							if ($i == $dates['m_end']) {
1240 1240
 								$num_of_days = $dates['day_end'];
1241 1241
 							} else {
1242
-								$num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y );
1242
+								$num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
1243 1243
 							}
1244 1244
 
1245
-							while ( $d <= $num_of_days ) :
1246
-								$earnings_stat = give_get_earnings_by_date( $d, $i, $y );
1247
-								$date_key      = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) );
1248
-								if ( ! isset( $earnings['earnings'][ $date_key ] ) ) {
1249
-									$earnings['earnings'][ $date_key ] = 0;
1245
+							while ($d <= $num_of_days) :
1246
+								$earnings_stat = give_get_earnings_by_date($d, $i, $y);
1247
+								$date_key      = date('Ymd', strtotime($y.'/'.$i.'/'.$d));
1248
+								if ( ! isset($earnings['earnings'][$date_key])) {
1249
+									$earnings['earnings'][$date_key] = 0;
1250 1250
 								}
1251
-								$earnings['earnings'][ $date_key ] += $earnings_stat;
1251
+								$earnings['earnings'][$date_key] += $earnings_stat;
1252 1252
 								$total += $earnings_stat;
1253
-								$d ++;
1253
+								$d++;
1254 1254
 							endwhile;
1255 1255
 
1256
-							$i ++;
1256
+							$i++;
1257 1257
 						endwhile;
1258 1258
 
1259
-						$y ++;
1259
+						$y++;
1260 1260
 					endwhile;
1261 1261
 
1262 1262
 					$earnings['totals'] = $total;
1263 1263
 				} else {
1264
-					if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) {
1264
+					if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
1265 1265
 						$earnings_count = (float) 0.00;
1266 1266
 
1267 1267
 						// Loop through the months
1268 1268
 						$month = $dates['m_start'];
1269 1269
 
1270
-						while ( $month <= $dates['m_end'] ) :
1271
-							$earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] );
1272
-							$month ++;
1270
+						while ($month <= $dates['m_end']) :
1271
+							$earnings_count += give_get_earnings_by_date(null, $month, $dates['year']);
1272
+							$month++;
1273 1273
 						endwhile;
1274 1274
 
1275
-						$earnings['earnings'][ $args['date'] ] = $earnings_count;
1275
+						$earnings['earnings'][$args['date']] = $earnings_count;
1276 1276
 					} else {
1277
-						$earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] );
1277
+						$earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']);
1278 1278
 					}
1279 1279
 				}
1280
-			} elseif ( $args['form'] == 'all' ) {
1281
-				$forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) );
1280
+			} elseif ($args['form'] == 'all') {
1281
+				$forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true));
1282 1282
 
1283 1283
 				$i = 0;
1284
-				foreach ( $forms as $form_info ) {
1285
-					$earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) );
1286
-					$i ++;
1284
+				foreach ($forms as $form_info) {
1285
+					$earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID));
1286
+					$i++;
1287 1287
 				}
1288 1288
 			} else {
1289
-				if ( get_post_type( $args['form'] ) == 'give_forms' ) {
1290
-					$form_info               = get_post( $args['form'] );
1291
-					$earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) );
1289
+				if (get_post_type($args['form']) == 'give_forms') {
1290
+					$form_info               = get_post($args['form']);
1291
+					$earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form']));
1292 1292
 				} else {
1293
-					$error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $args['form'] );
1293
+					$error['error'] = sprintf(__('Form %s not found!', 'give'), $args['form']);
1294 1294
 				}
1295 1295
 			}
1296 1296
 
1297
-			if ( ! empty( $error ) ) {
1297
+			if ( ! empty($error)) {
1298 1298
 				return $error;
1299 1299
 			}
1300 1300
 
1301 1301
 			return $earnings;
1302
-		} elseif ( $args['type'] == 'donors' ) {
1302
+		} elseif ($args['type'] == 'donors') {
1303 1303
 			$customers                          = new Give_DB_Customers();
1304 1304
 			$stats['donations']['total_donors'] = $customers->count();
1305 1305
 
1306 1306
 			return $stats;
1307 1307
 
1308
-		} elseif ( empty( $args['type'] ) ) {
1309
-			$stats = array_merge( $stats, $this->get_default_sales_stats() );
1310
-			$stats = array_merge( $stats, $this->get_default_earnings_stats() );
1308
+		} elseif (empty($args['type'])) {
1309
+			$stats = array_merge($stats, $this->get_default_sales_stats());
1310
+			$stats = array_merge($stats, $this->get_default_earnings_stats());
1311 1311
 
1312
-			return array( 'stats' => $stats );
1312
+			return array('stats' => $stats);
1313 1313
 		}
1314 1314
 	}
1315 1315
 
@@ -1325,18 +1325,18 @@  discard block
 block discarded – undo
1325 1325
 
1326 1326
 		$sales = array();
1327 1327
 
1328
-		if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) {
1328
+		if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) {
1329 1329
 			return $sales;
1330 1330
 		}
1331 1331
 
1332
-		if ( isset( $wp_query->query_vars['id'] ) ) {
1332
+		if (isset($wp_query->query_vars['id'])) {
1333 1333
 			$query   = array();
1334
-			$query[] = new Give_Payment( $wp_query->query_vars['id'] );
1335
-		} elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) {
1334
+			$query[] = new Give_Payment($wp_query->query_vars['id']);
1335
+		} elseif (isset($wp_query->query_vars['purchasekey'])) {
1336 1336
 			$query   = array();
1337
-			$query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] );
1338
-		} elseif ( isset( $wp_query->query_vars['email'] ) ) {
1339
-			$args  = array(
1337
+			$query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
1338
+		} elseif (isset($wp_query->query_vars['email'])) {
1339
+			$args = array(
1340 1340
 				'fields'     => 'ids',
1341 1341
 				'meta_key'   => '_give_payment_user_email',
1342 1342
 				'meta_value' => $wp_query->query_vars['email'],
@@ -1344,7 +1344,7 @@  discard block
 block discarded – undo
1344 1344
 				'page'       => $this->get_paged(),
1345 1345
 				'status'     => 'publish'
1346 1346
 			);
1347
-			$query = give_get_payments( $args );
1347
+			$query = give_get_payments($args);
1348 1348
 		} else {
1349 1349
 			$args  = array(
1350 1350
 				'fields' => 'ids',
@@ -1352,14 +1352,14 @@  discard block
 block discarded – undo
1352 1352
 				'page'   => $this->get_paged(),
1353 1353
 				'status' => 'publish'
1354 1354
 			);
1355
-			$query = give_get_payments( $args );
1355
+			$query = give_get_payments($args);
1356 1356
 		}
1357
-		if ( $query ) {
1357
+		if ($query) {
1358 1358
 			$i = 0;
1359
-			foreach ( $query as $payment ) {
1359
+			foreach ($query as $payment) {
1360 1360
 
1361
-				if ( is_numeric( $payment ) ) {
1362
-					$payment      = new Give_Payment( $payment );
1361
+				if (is_numeric($payment)) {
1362
+					$payment      = new Give_Payment($payment);
1363 1363
 					$payment_meta = $payment->get_meta();
1364 1364
 					$user_info    = $payment->user_info;
1365 1365
 				} else {
@@ -1369,40 +1369,40 @@  discard block
 block discarded – undo
1369 1369
 				$payment_meta = $payment->get_meta();
1370 1370
 				$user_info    = $payment->user_info;
1371 1371
 
1372
-				$first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : '';
1373
-				$last_name  = isset( $user_info['last_name'] ) ? $user_info['last_name'] : '';
1374
-
1375
-				$sales['donations'][ $i ]['ID']             = $payment->number;
1376
-				$sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id;
1377
-				$sales['donations'][ $i ]['key']            = $payment->key;
1378
-				$sales['donations'][ $i ]['total']          = $payment->total;
1379
-				$sales['donations'][ $i ]['gateway']        = $payment->gateway;
1380
-				$sales['donations'][ $i ]['name']           = $first_name . ' ' . $last_name;
1381
-				$sales['donations'][ $i ]['fname']          = $first_name;
1382
-				$sales['donations'][ $i ]['lname']          = $last_name;
1383
-				$sales['donations'][ $i ]['email']          = $payment->email;
1384
-				$sales['donations'][ $i ]['date']           = $payment->date;
1385
-
1386
-				$form_id  = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta;
1387
-				$price    = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false;
1388
-				$price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null;
1389
-
1390
-				$sales['donations'][ $i ]['form']['id']    = $form_id;
1391
-				$sales['donations'][ $i ]['form']['name']  = get_the_title( $payment_meta['form_id'] );
1392
-				$sales['donations'][ $i ]['form']['price'] = $price;
1393
-
1394
-				if ( give_has_variable_prices( $form_id ) ) {
1395
-					if ( isset( $payment_meta['price_id'] ) ) {
1396
-						$price_name                                     = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID );
1397
-						$sales['donations'][ $i ]['form']['price_name'] = $price_name;
1398
-						$sales['donations'][ $i ]['form']['price_id']   = $price_id;
1399
-						$sales['donations'][ $i ]['form']['price']      = give_get_price_option_amount( $form_id, $price_id );
1372
+				$first_name = isset($user_info['first_name']) ? $user_info['first_name'] : '';
1373
+				$last_name  = isset($user_info['last_name']) ? $user_info['last_name'] : '';
1374
+
1375
+				$sales['donations'][$i]['ID']             = $payment->number;
1376
+				$sales['donations'][$i]['transaction_id'] = $payment->transaction_id;
1377
+				$sales['donations'][$i]['key']            = $payment->key;
1378
+				$sales['donations'][$i]['total']          = $payment->total;
1379
+				$sales['donations'][$i]['gateway']        = $payment->gateway;
1380
+				$sales['donations'][$i]['name']           = $first_name.' '.$last_name;
1381
+				$sales['donations'][$i]['fname']          = $first_name;
1382
+				$sales['donations'][$i]['lname']          = $last_name;
1383
+				$sales['donations'][$i]['email']          = $payment->email;
1384
+				$sales['donations'][$i]['date']           = $payment->date;
1385
+
1386
+				$form_id  = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
1387
+				$price    = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
1388
+				$price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
1389
+
1390
+				$sales['donations'][$i]['form']['id']    = $form_id;
1391
+				$sales['donations'][$i]['form']['name']  = get_the_title($payment_meta['form_id']);
1392
+				$sales['donations'][$i]['form']['price'] = $price;
1393
+
1394
+				if (give_has_variable_prices($form_id)) {
1395
+					if (isset($payment_meta['price_id'])) {
1396
+						$price_name                                     = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
1397
+						$sales['donations'][$i]['form']['price_name'] = $price_name;
1398
+						$sales['donations'][$i]['form']['price_id']   = $price_id;
1399
+						$sales['donations'][$i]['form']['price']      = give_get_price_option_amount($form_id, $price_id);
1400 1400
 
1401 1401
 					}
1402 1402
 				}
1403 1403
 
1404 1404
 				//Add custom meta to API
1405
-				foreach ( $payment_meta as $meta_key => $meta_value ) {
1405
+				foreach ($payment_meta as $meta_key => $meta_value) {
1406 1406
 
1407 1407
 					$exceptions = array(
1408 1408
 						'form_title',
@@ -1415,19 +1415,19 @@  discard block
 block discarded – undo
1415 1415
 					);
1416 1416
 
1417 1417
 					//Don't clutter up results with dupes
1418
-					if ( in_array( $meta_key, $exceptions ) ) {
1418
+					if (in_array($meta_key, $exceptions)) {
1419 1419
 						continue;
1420 1420
 					}
1421 1421
 
1422
-					$sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value;
1422
+					$sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value;
1423 1423
 
1424 1424
 				}
1425 1425
 
1426
-				$i ++;
1426
+				$i++;
1427 1427
 			}
1428 1428
 		}
1429 1429
 
1430
-		return apply_filters( 'give_api_donations_endpoint', $sales );
1430
+		return apply_filters('give_api_donations_endpoint', $sales);
1431 1431
 	}
1432 1432
 
1433 1433
 	/**
@@ -1442,9 +1442,9 @@  discard block
 block discarded – undo
1442 1442
 	public function get_output_format() {
1443 1443
 		global $wp_query;
1444 1444
 
1445
-		$format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json';
1445
+		$format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json';
1446 1446
 
1447
-		return apply_filters( 'give_api_output_format', $format );
1447
+		return apply_filters('give_api_output_format', $format);
1448 1448
 	}
1449 1449
 
1450 1450
 
@@ -1460,8 +1460,8 @@  discard block
 block discarded – undo
1460 1460
 	 *
1461 1461
 	 * @return void
1462 1462
 	 */
1463
-	private function log_request( $data = array() ) {
1464
-		if ( ! $this->log_requests ) {
1463
+	private function log_request($data = array()) {
1464
+		if ( ! $this->log_requests) {
1465 1465
 			return;
1466 1466
 		}
1467 1467
 
@@ -1469,36 +1469,36 @@  discard block
 block discarded – undo
1469 1469
 
1470 1470
 		$query = array(
1471 1471
 			'give-api'    => $wp_query->query_vars['give-api'],
1472
-			'key'         => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null,
1473
-			'token'       => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null,
1474
-			'query'       => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null,
1475
-			'type'        => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null,
1476
-			'form'        => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null,
1477
-			'customer'    => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null,
1478
-			'date'        => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null,
1479
-			'startdate'   => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null,
1480
-			'enddate'     => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null,
1481
-			'id'          => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null,
1482
-			'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null,
1483
-			'email'       => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null,
1472
+			'key'         => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null,
1473
+			'token'       => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null,
1474
+			'query'       => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null,
1475
+			'type'        => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null,
1476
+			'form'        => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null,
1477
+			'customer'    => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null,
1478
+			'date'        => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null,
1479
+			'startdate'   => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null,
1480
+			'enddate'     => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null,
1481
+			'id'          => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null,
1482
+			'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null,
1483
+			'email'       => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null,
1484 1484
 		);
1485 1485
 
1486 1486
 		$log_data = array(
1487 1487
 			'log_type'     => 'api_request',
1488
-			'post_excerpt' => http_build_query( $query ),
1489
-			'post_content' => ! empty( $data['error'] ) ? $data['error'] : '',
1488
+			'post_excerpt' => http_build_query($query),
1489
+			'post_content' => ! empty($data['error']) ? $data['error'] : '',
1490 1490
 		);
1491 1491
 
1492 1492
 		$log_meta = array(
1493 1493
 			'request_ip' => give_get_ip(),
1494 1494
 			'user'       => $this->user_id,
1495
-			'key'        => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null,
1496
-			'token'      => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null,
1495
+			'key'        => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null,
1496
+			'token'      => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null,
1497 1497
 			'time'       => $data['request_speed'],
1498 1498
 			'version'    => $this->get_queried_version()
1499 1499
 		);
1500 1500
 
1501
-		$give_logs->insert_log( $log_data, $log_meta );
1501
+		$give_logs->insert_log($log_data, $log_meta);
1502 1502
 	}
1503 1503
 
1504 1504
 
@@ -1522,32 +1522,32 @@  discard block
 block discarded – undo
1522 1522
 	 *
1523 1523
 	 * @param int $status_code
1524 1524
 	 */
1525
-	public function output( $status_code = 200 ) {
1525
+	public function output($status_code = 200) {
1526 1526
 		global $wp_query;
1527 1527
 
1528 1528
 		$format = $this->get_output_format();
1529 1529
 
1530
-		status_header( $status_code );
1530
+		status_header($status_code);
1531 1531
 
1532
-		do_action( 'give_api_output_before', $this->data, $this, $format );
1532
+		do_action('give_api_output_before', $this->data, $this, $format);
1533 1533
 
1534
-		switch ( $format ) :
1534
+		switch ($format) :
1535 1535
 
1536 1536
 			case 'xml' :
1537 1537
 
1538
-				require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php';
1539
-				$xml = Array2XML::createXML( 'give', $this->data );
1538
+				require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php';
1539
+				$xml = Array2XML::createXML('give', $this->data);
1540 1540
 				echo $xml->saveXML();
1541 1541
 
1542 1542
 				break;
1543 1543
 
1544 1544
 			case 'json' :
1545 1545
 
1546
-				header( 'Content-Type: application/json' );
1547
-				if ( ! empty( $this->pretty_print ) ) {
1548
-					echo json_encode( $this->data, $this->pretty_print );
1546
+				header('Content-Type: application/json');
1547
+				if ( ! empty($this->pretty_print)) {
1548
+					echo json_encode($this->data, $this->pretty_print);
1549 1549
 				} else {
1550
-					echo json_encode( $this->data );
1550
+					echo json_encode($this->data);
1551 1551
 				}
1552 1552
 
1553 1553
 				break;
@@ -1556,13 +1556,13 @@  discard block
 block discarded – undo
1556 1556
 			default :
1557 1557
 
1558 1558
 				// Allow other formats to be added via extensions
1559
-				do_action( 'give_api_output_' . $format, $this->data, $this );
1559
+				do_action('give_api_output_'.$format, $this->data, $this);
1560 1560
 
1561 1561
 				break;
1562 1562
 
1563 1563
 		endswitch;
1564 1564
 
1565
-		do_action( 'give_api_output_after', $this->data, $this, $format );
1565
+		do_action('give_api_output_after', $this->data, $this, $format);
1566 1566
 
1567 1567
 		give_die();
1568 1568
 	}
@@ -1579,37 +1579,37 @@  discard block
 block discarded – undo
1579 1579
 	 *
1580 1580
 	 * @return void
1581 1581
 	 */
1582
-	function user_key_field( $user ) {
1582
+	function user_key_field($user) {
1583 1583
 
1584
-		if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) {
1585
-			$user = get_userdata( $user->ID );
1584
+		if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) {
1585
+			$user = get_userdata($user->ID);
1586 1586
 			?>
1587 1587
 			<table class="form-table">
1588 1588
 				<tbody>
1589 1589
 				<tr>
1590 1590
 					<th>
1591
-						<?php esc_attr_e( 'Give API Keys', 'give' ); ?>
1591
+						<?php esc_attr_e('Give API Keys', 'give'); ?>
1592 1592
 					</th>
1593 1593
 					<td>
1594 1594
 						<?php
1595
-						$public_key = $this->get_user_public_key( $user->ID );
1596
-						$secret_key = $this->get_user_secret_key( $user->ID );
1595
+						$public_key = $this->get_user_public_key($user->ID);
1596
+						$secret_key = $this->get_user_secret_key($user->ID);
1597 1597
 						?>
1598
-						<?php if ( empty( $user->give_user_public_key ) ) { ?>
1598
+						<?php if (empty($user->give_user_public_key)) { ?>
1599 1599
 							<input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/>
1600
-							<span class="description"><?php esc_attr_e( 'Generate API Key', 'give' ); ?></span>
1600
+							<span class="description"><?php esc_attr_e('Generate API Key', 'give'); ?></span>
1601 1601
 						<?php } else { ?>
1602
-							<strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?>&nbsp;</strong>
1603
-							<input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/>
1602
+							<strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?>&nbsp;</strong>
1603
+							<input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/>
1604 1604
 							<br/>
1605
-							<strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Secret key:', 'give' ); ?>&nbsp;</strong>
1606
-							<input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/>
1605
+							<strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Secret key:', 'give'); ?>&nbsp;</strong>
1606
+							<input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/>
1607 1607
 							<br/>
1608
-							<strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Token:', 'give' ); ?>&nbsp;</strong>
1609
-							<input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/>
1608
+							<strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Token:', 'give'); ?>&nbsp;</strong>
1609
+							<input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/>
1610 1610
 							<br/>
1611 1611
 							<input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/>
1612
-							<span class="description"><label for="give_set_api_key"><?php esc_attr_e( 'Revoke API Keys', 'give' ); ?></label></span>
1612
+							<span class="description"><label for="give_set_api_key"><?php esc_attr_e('Revoke API Keys', 'give'); ?></label></span>
1613 1613
 						<?php } ?>
1614 1614
 					</td>
1615 1615
 				</tr>
@@ -1628,53 +1628,53 @@  discard block
 block discarded – undo
1628 1628
 	 *
1629 1629
 	 * @return void
1630 1630
 	 */
1631
-	public function process_api_key( $args ) {
1631
+	public function process_api_key($args) {
1632 1632
 
1633
-		if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) {
1633
+		if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) {
1634 1634
 
1635
-			wp_die( esc_attr__( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
1635
+			wp_die(esc_attr__('Nonce verification failed', 'give'), __('Error', 'give'), array('response' => 403));
1636 1636
 
1637 1637
 		}
1638 1638
 
1639
-		if ( empty( $args['user_id'] ) ) {
1640
-			wp_die( esc_attr__( 'User ID Required', 'give' ), esc_attr__( 'Error', 'give' ), array( 'response' => 401 ) );
1639
+		if (empty($args['user_id'])) {
1640
+			wp_die(esc_attr__('User ID Required', 'give'), esc_attr__('Error', 'give'), array('response' => 401));
1641 1641
 		}
1642 1642
 
1643
-		if ( is_numeric( $args['user_id'] ) ) {
1644
-			$user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id();
1643
+		if (is_numeric($args['user_id'])) {
1644
+			$user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id();
1645 1645
 		} else {
1646
-			$userdata = get_user_by( 'login', $args['user_id'] );
1646
+			$userdata = get_user_by('login', $args['user_id']);
1647 1647
 			$user_id  = $userdata->ID;
1648 1648
 		}
1649
-		$process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false;
1649
+		$process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false;
1650 1650
 
1651
-		if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) {
1652
-			wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) );
1653
-		} elseif ( ! current_user_can( 'manage_give_settings' ) ) {
1654
-			wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) );
1651
+		if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) {
1652
+			wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403));
1653
+		} elseif ( ! current_user_can('manage_give_settings')) {
1654
+			wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403));
1655 1655
 		}
1656 1656
 
1657
-		switch ( $process ) {
1657
+		switch ($process) {
1658 1658
 			case 'generate':
1659
-				if ( $this->generate_api_key( $user_id ) ) {
1660
-					delete_transient( 'give-total-api-keys' );
1661
-					wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) );
1659
+				if ($this->generate_api_key($user_id)) {
1660
+					delete_transient('give-total-api-keys');
1661
+					wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api'));
1662 1662
 					exit();
1663 1663
 				} else {
1664
-					wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) );
1664
+					wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api'));
1665 1665
 					exit();
1666 1666
 				}
1667 1667
 				break;
1668 1668
 			case 'regenerate':
1669
-				$this->generate_api_key( $user_id, true );
1670
-				delete_transient( 'give-total-api-keys' );
1671
-				wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) );
1669
+				$this->generate_api_key($user_id, true);
1670
+				delete_transient('give-total-api-keys');
1671
+				wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api'));
1672 1672
 				exit();
1673 1673
 				break;
1674 1674
 			case 'revoke':
1675
-				$this->revoke_api_key( $user_id );
1676
-				delete_transient( 'give-total-api-keys' );
1677
-				wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) );
1675
+				$this->revoke_api_key($user_id);
1676
+				delete_transient('give-total-api-keys');
1677
+				wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api'));
1678 1678
 				exit();
1679 1679
 				break;
1680 1680
 			default;
@@ -1693,34 +1693,34 @@  discard block
 block discarded – undo
1693 1693
 	 *
1694 1694
 	 * @return boolean True if (re)generated succesfully, false otherwise.
1695 1695
 	 */
1696
-	public function generate_api_key( $user_id = 0, $regenerate = false ) {
1696
+	public function generate_api_key($user_id = 0, $regenerate = false) {
1697 1697
 
1698
-		if ( empty( $user_id ) ) {
1698
+		if (empty($user_id)) {
1699 1699
 			return false;
1700 1700
 		}
1701 1701
 
1702
-		$user = get_userdata( $user_id );
1702
+		$user = get_userdata($user_id);
1703 1703
 
1704
-		if ( ! $user ) {
1704
+		if ( ! $user) {
1705 1705
 			return false;
1706 1706
 		}
1707 1707
 
1708
-		$public_key = $this->get_user_public_key( $user_id );
1709
-		$secret_key = $this->get_user_secret_key( $user_id );
1708
+		$public_key = $this->get_user_public_key($user_id);
1709
+		$secret_key = $this->get_user_secret_key($user_id);
1710 1710
 
1711
-		if ( empty( $public_key ) || $regenerate == true ) {
1712
-			$new_public_key = $this->generate_public_key( $user->user_email );
1713
-			$new_secret_key = $this->generate_private_key( $user->ID );
1711
+		if (empty($public_key) || $regenerate == true) {
1712
+			$new_public_key = $this->generate_public_key($user->user_email);
1713
+			$new_secret_key = $this->generate_private_key($user->ID);
1714 1714
 		} else {
1715 1715
 			return false;
1716 1716
 		}
1717 1717
 
1718
-		if ( $regenerate == true ) {
1719
-			$this->revoke_api_key( $user->ID );
1718
+		if ($regenerate == true) {
1719
+			$this->revoke_api_key($user->ID);
1720 1720
 		}
1721 1721
 
1722
-		update_user_meta( $user_id, $new_public_key, 'give_user_public_key' );
1723
-		update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' );
1722
+		update_user_meta($user_id, $new_public_key, 'give_user_public_key');
1723
+		update_user_meta($user_id, $new_secret_key, 'give_user_secret_key');
1724 1724
 
1725 1725
 		return true;
1726 1726
 	}
@@ -1735,26 +1735,26 @@  discard block
 block discarded – undo
1735 1735
 	 *
1736 1736
 	 * @return string
1737 1737
 	 */
1738
-	public function revoke_api_key( $user_id = 0 ) {
1738
+	public function revoke_api_key($user_id = 0) {
1739 1739
 
1740
-		if ( empty( $user_id ) ) {
1740
+		if (empty($user_id)) {
1741 1741
 			return false;
1742 1742
 		}
1743 1743
 
1744
-		$user = get_userdata( $user_id );
1744
+		$user = get_userdata($user_id);
1745 1745
 
1746
-		if ( ! $user ) {
1746
+		if ( ! $user) {
1747 1747
 			return false;
1748 1748
 		}
1749 1749
 
1750
-		$public_key = $this->get_user_public_key( $user_id );
1751
-		$secret_key = $this->get_user_secret_key( $user_id );
1752
-		if ( ! empty( $public_key ) ) {
1753
-			delete_transient( md5( 'give_api_user_' . $public_key ) );
1754
-			delete_transient( md5( 'give_api_user_public_key' . $user_id ) );
1755
-			delete_transient( md5( 'give_api_user_secret_key' . $user_id ) );
1756
-			delete_user_meta( $user_id, $public_key );
1757
-			delete_user_meta( $user_id, $secret_key );
1750
+		$public_key = $this->get_user_public_key($user_id);
1751
+		$secret_key = $this->get_user_secret_key($user_id);
1752
+		if ( ! empty($public_key)) {
1753
+			delete_transient(md5('give_api_user_'.$public_key));
1754
+			delete_transient(md5('give_api_user_public_key'.$user_id));
1755
+			delete_transient(md5('give_api_user_secret_key'.$user_id));
1756
+			delete_user_meta($user_id, $public_key);
1757
+			delete_user_meta($user_id, $secret_key);
1758 1758
 		} else {
1759 1759
 			return false;
1760 1760
 		}
@@ -1779,22 +1779,22 @@  discard block
 block discarded – undo
1779 1779
 	 *
1780 1780
 	 * @return void
1781 1781
 	 */
1782
-	public function update_key( $user_id ) {
1783
-		if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) {
1782
+	public function update_key($user_id) {
1783
+		if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) {
1784 1784
 
1785
-			$user = get_userdata( $user_id );
1785
+			$user = get_userdata($user_id);
1786 1786
 
1787
-			$public_key = $this->get_user_public_key( $user_id );
1788
-			$secret_key = $this->get_user_secret_key( $user_id );
1787
+			$public_key = $this->get_user_public_key($user_id);
1788
+			$secret_key = $this->get_user_secret_key($user_id);
1789 1789
 
1790
-			if ( empty( $public_key ) ) {
1791
-				$new_public_key = $this->generate_public_key( $user->user_email );
1792
-				$new_secret_key = $this->generate_private_key( $user->ID );
1790
+			if (empty($public_key)) {
1791
+				$new_public_key = $this->generate_public_key($user->user_email);
1792
+				$new_secret_key = $this->generate_private_key($user->ID);
1793 1793
 
1794
-				update_user_meta( $user_id, $new_public_key, 'give_user_public_key' );
1795
-				update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' );
1794
+				update_user_meta($user_id, $new_public_key, 'give_user_public_key');
1795
+				update_user_meta($user_id, $new_secret_key, 'give_user_secret_key');
1796 1796
 			} else {
1797
-				$this->revoke_api_key( $user_id );
1797
+				$this->revoke_api_key($user_id);
1798 1798
 			}
1799 1799
 		}
1800 1800
 	}
@@ -1809,9 +1809,9 @@  discard block
 block discarded – undo
1809 1809
 	 *
1810 1810
 	 * @return string
1811 1811
 	 */
1812
-	private function generate_public_key( $user_email = '' ) {
1813
-		$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
1814
-		$public   = hash( 'md5', $user_email . $auth_key . date( 'U' ) );
1812
+	private function generate_public_key($user_email = '') {
1813
+		$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
1814
+		$public   = hash('md5', $user_email.$auth_key.date('U'));
1815 1815
 
1816 1816
 		return $public;
1817 1817
 	}
@@ -1826,9 +1826,9 @@  discard block
 block discarded – undo
1826 1826
 	 *
1827 1827
 	 * @return string
1828 1828
 	 */
1829
-	private function generate_private_key( $user_id = 0 ) {
1830
-		$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
1831
-		$secret   = hash( 'md5', $user_id . $auth_key . date( 'U' ) );
1829
+	private function generate_private_key($user_id = 0) {
1830
+		$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
1831
+		$secret   = hash('md5', $user_id.$auth_key.date('U'));
1832 1832
 
1833 1833
 		return $secret;
1834 1834
 	}
@@ -1843,8 +1843,8 @@  discard block
 block discarded – undo
1843 1843
 	 *
1844 1844
 	 * @return string
1845 1845
 	 */
1846
-	public function get_token( $user_id = 0 ) {
1847
-		return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) );
1846
+	public function get_token($user_id = 0) {
1847
+		return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id));
1848 1848
 	}
1849 1849
 
1850 1850
 	/**
@@ -1858,9 +1858,9 @@  discard block
 block discarded – undo
1858 1858
 
1859 1859
 		// Default sales return
1860 1860
 		$sales                               = array();
1861
-		$sales['donations']['today']         = $this->stats->get_sales( 0, 'today' );
1862
-		$sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' );
1863
-		$sales['donations']['last_month']    = $this->stats->get_sales( 0, 'last_month' );
1861
+		$sales['donations']['today']         = $this->stats->get_sales(0, 'today');
1862
+		$sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month');
1863
+		$sales['donations']['last_month']    = $this->stats->get_sales(0, 'last_month');
1864 1864
 		$sales['donations']['totals']        = give_get_total_sales();
1865 1865
 
1866 1866
 		return $sales;
@@ -1877,9 +1877,9 @@  discard block
 block discarded – undo
1877 1877
 
1878 1878
 		// Default earnings return
1879 1879
 		$earnings                              = array();
1880
-		$earnings['earnings']['today']         = $this->stats->get_earnings( 0, 'today' );
1881
-		$earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' );
1882
-		$earnings['earnings']['last_month']    = $this->stats->get_earnings( 0, 'last_month' );
1880
+		$earnings['earnings']['today']         = $this->stats->get_earnings(0, 'today');
1881
+		$earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month');
1882
+		$earnings['earnings']['last_month']    = $this->stats->get_earnings(0, 'last_month');
1883 1883
 		$earnings['earnings']['totals']        = give_get_total_earnings();
1884 1884
 
1885 1885
 		return $earnings;
@@ -1899,25 +1899,25 @@  discard block
 block discarded – undo
1899 1899
 	 *
1900 1900
 	 * @return string            The API key/secret for the user supplied
1901 1901
 	 */
1902
-	public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) {
1902
+	public function api_key_backwards_compat($check, $object_id, $meta_key, $single) {
1903 1903
 
1904
-		if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) {
1904
+		if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') {
1905 1905
 			return $check;
1906 1906
 		}
1907 1907
 
1908 1908
 		$return = $check;
1909 1909
 
1910
-		switch ( $meta_key ) {
1910
+		switch ($meta_key) {
1911 1911
 			case 'give_user_public_key':
1912
-				$return = Give()->api->get_user_public_key( $object_id );
1912
+				$return = Give()->api->get_user_public_key($object_id);
1913 1913
 				break;
1914 1914
 			case 'give_user_secret_key':
1915
-				$return = Give()->api->get_user_secret_key( $object_id );
1915
+				$return = Give()->api->get_user_secret_key($object_id);
1916 1916
 				break;
1917 1917
 		}
1918 1918
 
1919
-		if ( ! $single ) {
1920
-			$return = array( $return );
1919
+		if ( ! $single) {
1920
+			$return = array($return);
1921 1921
 		}
1922 1922
 
1923 1923
 		return $return;
Please login to merge, or discard this patch.