@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -38,35 +38,35 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return float|int Total amount of donations based on the passed arguments. |
40 | 40 | */ |
41 | - public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
|
41 | + public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { |
|
42 | 42 | |
43 | - $this->setup_dates( $start_date, $end_date ); |
|
43 | + $this->setup_dates($start_date, $end_date); |
|
44 | 44 | |
45 | 45 | // Make sure start date is valid |
46 | - if ( is_wp_error( $this->start_date ) ) { |
|
46 | + if (is_wp_error($this->start_date)) { |
|
47 | 47 | return $this->start_date; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Make sure end date is valid |
51 | - if ( is_wp_error( $this->end_date ) ) { |
|
51 | + if (is_wp_error($this->end_date)) { |
|
52 | 52 | return $this->end_date; |
53 | 53 | } |
54 | 54 | |
55 | - if ( empty( $form_id ) ) { |
|
55 | + if (empty($form_id)) { |
|
56 | 56 | |
57 | 57 | // Global sale stats |
58 | - add_filter( 'give_count_payments_where', array( $this, 'count_where' ) ); |
|
58 | + add_filter('give_count_payments_where', array($this, 'count_where')); |
|
59 | 59 | |
60 | - if ( is_array( $status ) ) { |
|
60 | + if (is_array($status)) { |
|
61 | 61 | $count = 0; |
62 | - foreach ( $status as $payment_status ) { |
|
62 | + foreach ($status as $payment_status) { |
|
63 | 63 | $count += give_count_payments()->$payment_status; |
64 | 64 | } |
65 | 65 | } else { |
66 | 66 | $count = give_count_payments()->$status; |
67 | 67 | } |
68 | 68 | |
69 | - remove_filter( 'give_count_payments_where', array( $this, 'count_where' ) ); |
|
69 | + remove_filter('give_count_payments_where', array($this, 'count_where')); |
|
70 | 70 | |
71 | 71 | } else { |
72 | 72 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | // Product specific stats |
76 | 76 | global $give_logs; |
77 | 77 | |
78 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
78 | + add_filter('posts_where', array($this, 'payments_where')); |
|
79 | 79 | |
80 | - $count = $give_logs->get_log_count( $form_id, 'sale' ); |
|
80 | + $count = $give_logs->get_log_count($form_id, 'sale'); |
|
81 | 81 | |
82 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
82 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
@@ -101,31 +101,31 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return float|int Total amount of donations based on the passed arguments. |
103 | 103 | */ |
104 | - public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
104 | + public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
105 | 105 | |
106 | 106 | global $wpdb; |
107 | 107 | |
108 | - $this->setup_dates( $start_date, $end_date ); |
|
108 | + $this->setup_dates($start_date, $end_date); |
|
109 | 109 | |
110 | 110 | // Make sure start date is valid |
111 | - if ( is_wp_error( $this->start_date ) ) { |
|
111 | + if (is_wp_error($this->start_date)) { |
|
112 | 112 | return $this->start_date; |
113 | 113 | } |
114 | 114 | |
115 | 115 | // Make sure end date is valid |
116 | - if ( is_wp_error( $this->end_date ) ) { |
|
116 | + if (is_wp_error($this->end_date)) { |
|
117 | 117 | return $this->end_date; |
118 | 118 | } |
119 | 119 | |
120 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
120 | + add_filter('posts_where', array($this, 'payments_where')); |
|
121 | 121 | |
122 | - if ( empty( $form_id ) ) { |
|
122 | + if (empty($form_id)) { |
|
123 | 123 | |
124 | 124 | // Global earning stats |
125 | 125 | $args = array( |
126 | 126 | 'post_type' => 'give_payment', |
127 | 127 | 'nopaging' => true, |
128 | - 'post_status' => array( 'publish' ), |
|
128 | + 'post_status' => array('publish'), |
|
129 | 129 | 'fields' => 'ids', |
130 | 130 | 'update_post_term_cache' => false, |
131 | 131 | 'suppress_filters' => false, |
@@ -137,24 +137,24 @@ discard block |
||
137 | 137 | ); |
138 | 138 | |
139 | 139 | //Filter by Gateway ID meta_key |
140 | - if ( $gateway_id !== false ) { |
|
140 | + if ($gateway_id !== false) { |
|
141 | 141 | $args['meta_key'] = '_give_payment_gateway'; |
142 | 142 | $args['meta_value'] = $gateway_id; |
143 | 143 | } |
144 | 144 | |
145 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
146 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
147 | - $earnings = Give_Cache::get( $key ); |
|
145 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
146 | + $key = Give_Cache::get_key('give_stats', $args); |
|
147 | + $earnings = Give_Cache::get($key); |
|
148 | 148 | |
149 | - if ( false === $earnings ) { |
|
150 | - $sales = get_posts( $args ); |
|
149 | + if (false === $earnings) { |
|
150 | + $sales = get_posts($args); |
|
151 | 151 | $earnings = 0; |
152 | - if ( $sales ) { |
|
153 | - $sales = implode( ',', array_map('intval', $sales ) ); |
|
154 | - $earnings += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})" ); |
|
152 | + if ($sales) { |
|
153 | + $sales = implode(',', array_map('intval', $sales)); |
|
154 | + $earnings += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})"); |
|
155 | 155 | } |
156 | 156 | // Cache the results for one hour |
157 | - Give_Cache::set( $key, $earnings, HOUR_IN_SECONDS ); |
|
157 | + Give_Cache::set($key, $earnings, HOUR_IN_SECONDS); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | } else { |
@@ -174,37 +174,37 @@ discard block |
||
174 | 174 | 'give_transient_type' => 'give_earnings', |
175 | 175 | // This is not a valid query arg, but is used for cache keying |
176 | 176 | ); |
177 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
178 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
177 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
178 | + $key = Give_Cache::get_key('give_stats', $args); |
|
179 | 179 | //Set transient for faster stats |
180 | - $earnings = Give_Cache::get( $key ); |
|
180 | + $earnings = Give_Cache::get($key); |
|
181 | 181 | |
182 | - if ( false === $earnings ) { |
|
182 | + if (false === $earnings) { |
|
183 | 183 | |
184 | 184 | $this->timestamp = false; |
185 | - $log_ids = $give_logs->get_connected_logs( $args, 'sale' ); |
|
185 | + $log_ids = $give_logs->get_connected_logs($args, 'sale'); |
|
186 | 186 | $earnings = 0; |
187 | 187 | |
188 | - if ( $log_ids ) { |
|
189 | - $log_ids = implode( ',', array_map('intval', $log_ids ) ); |
|
190 | - $payment_ids = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_give_log_payment_id' AND post_id IN ($log_ids);" ); |
|
188 | + if ($log_ids) { |
|
189 | + $log_ids = implode(',', array_map('intval', $log_ids)); |
|
190 | + $payment_ids = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_give_log_payment_id' AND post_id IN ($log_ids);"); |
|
191 | 191 | |
192 | - foreach ( $payment_ids as $payment_id ) { |
|
193 | - $earnings += give_get_payment_amount( $payment_id ); |
|
192 | + foreach ($payment_ids as $payment_id) { |
|
193 | + $earnings += give_get_payment_amount($payment_id); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | } |
197 | 197 | |
198 | 198 | // Cache the results for one hour |
199 | - Give_Cache::set( $key, $earnings, 60 * 60 ); |
|
199 | + Give_Cache::set($key, $earnings, 60 * 60); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | 203 | //remove our filter |
204 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
204 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
205 | 205 | |
206 | 206 | //return earnings |
207 | - return round( $earnings, give_currency_decimal_filter() ); |
|
207 | + return round($earnings, give_currency_decimal_filter()); |
|
208 | 208 | |
209 | 209 | } |
210 | 210 | |
@@ -221,29 +221,29 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return float|int Total amount of donations based on the passed arguments. |
223 | 223 | */ |
224 | - public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
224 | + public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
225 | 225 | |
226 | - $this->setup_dates( $start_date, $end_date ); |
|
226 | + $this->setup_dates($start_date, $end_date); |
|
227 | 227 | |
228 | 228 | // Make sure start date is valid |
229 | - if ( is_wp_error( $this->start_date ) ) { |
|
229 | + if (is_wp_error($this->start_date)) { |
|
230 | 230 | return $this->start_date; |
231 | 231 | } |
232 | 232 | |
233 | 233 | // Make sure end date is valid |
234 | - if ( is_wp_error( $this->end_date ) ) { |
|
234 | + if (is_wp_error($this->end_date)) { |
|
235 | 235 | return $this->end_date; |
236 | 236 | } |
237 | 237 | |
238 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
238 | + add_filter('posts_where', array($this, 'payments_where')); |
|
239 | 239 | |
240 | - if ( empty( $form_id ) ) { |
|
240 | + if (empty($form_id)) { |
|
241 | 241 | |
242 | 242 | // Global earning stats |
243 | 243 | $args = array( |
244 | 244 | 'post_type' => 'give_payment', |
245 | 245 | 'nopaging' => true, |
246 | - 'post_status' => array( 'publish' ), |
|
246 | + 'post_status' => array('publish'), |
|
247 | 247 | 'fields' => 'ids', |
248 | 248 | 'update_post_term_cache' => false, |
249 | 249 | 'suppress_filters' => false, |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | ); |
256 | 256 | |
257 | 257 | //Filter by Gateway ID meta_key |
258 | - if ( $gateway_id !== false ) { |
|
258 | + if ($gateway_id !== false) { |
|
259 | 259 | $args['meta_key'] = '_give_payment_gateway'; |
260 | 260 | $args['meta_value'] = $gateway_id; |
261 | 261 | } |
262 | 262 | |
263 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
264 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
263 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
264 | + $key = Give_Cache::get_key('give_stats', $args); |
|
265 | 265 | |
266 | 266 | } else { |
267 | 267 | |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | // This is not a valid query arg, but is used for cache keying |
282 | 282 | ); |
283 | 283 | |
284 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
285 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
284 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
285 | + $key = Give_Cache::get_key('give_stats', $args); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | //remove our filter |
289 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
289 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
290 | 290 | |
291 | 291 | //return earnings |
292 | 292 | return $key; |
@@ -303,16 +303,16 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return array Best selling forms |
305 | 305 | */ |
306 | - public function get_best_selling( $number = 10 ) { |
|
306 | + public function get_best_selling($number = 10) { |
|
307 | 307 | |
308 | 308 | global $wpdb; |
309 | 309 | |
310 | - $give_forms = $wpdb->get_results( $wpdb->prepare( |
|
310 | + $give_forms = $wpdb->get_results($wpdb->prepare( |
|
311 | 311 | "SELECT post_id as form_id, max(meta_value) as sales |
312 | 312 | FROM $wpdb->postmeta WHERE meta_key='_give_form_sales' AND meta_value > 0 |
313 | 313 | GROUP BY meta_value+0 |
314 | 314 | DESC LIMIT %d;", $number |
315 | - ) ); |
|
315 | + )); |
|
316 | 316 | |
317 | 317 | return $give_forms; |
318 | 318 | } |
@@ -10,7 +10,7 @@ discard block |
||
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 | |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return array $payments Payments retrieved from the database |
45 | 45 | */ |
46 | -function give_get_payments( $args = array() ) { |
|
46 | +function give_get_payments($args = array()) { |
|
47 | 47 | |
48 | 48 | // Fallback to post objects to ensure backwards compatibility. |
49 | - if ( ! isset( $args['output'] ) ) { |
|
49 | + if ( ! isset($args['output'])) { |
|
50 | 50 | $args['output'] = 'posts'; |
51 | 51 | } |
52 | 52 | |
53 | - $args = apply_filters( 'give_get_payments_args', $args ); |
|
54 | - $payments = new Give_Payments_Query( $args ); |
|
53 | + $args = apply_filters('give_get_payments_args', $args); |
|
54 | + $payments = new Give_Payments_Query($args); |
|
55 | 55 | |
56 | 56 | return $payments->get_payments(); |
57 | 57 | } |
@@ -66,48 +66,48 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | -function give_get_payment_by( $field = '', $value = '' ) { |
|
69 | +function give_get_payment_by($field = '', $value = '') { |
|
70 | 70 | |
71 | - if ( empty( $field ) || empty( $value ) ) { |
|
71 | + if (empty($field) || empty($value)) { |
|
72 | 72 | return false; |
73 | 73 | } |
74 | 74 | |
75 | - switch ( strtolower( $field ) ) { |
|
75 | + switch (strtolower($field)) { |
|
76 | 76 | |
77 | 77 | case 'id': |
78 | - $payment = new Give_Payment( $value ); |
|
78 | + $payment = new Give_Payment($value); |
|
79 | 79 | $id = $payment->ID; |
80 | 80 | |
81 | - if ( empty( $id ) ) { |
|
81 | + if (empty($id)) { |
|
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | 85 | break; |
86 | 86 | |
87 | 87 | case 'key': |
88 | - $payment = give_get_payments( array( |
|
88 | + $payment = give_get_payments(array( |
|
89 | 89 | 'meta_key' => '_give_payment_purchase_key', |
90 | 90 | 'meta_value' => $value, |
91 | 91 | 'posts_per_page' => 1, |
92 | 92 | 'fields' => 'ids', |
93 | - ) ); |
|
93 | + )); |
|
94 | 94 | |
95 | - if ( $payment ) { |
|
96 | - $payment = new Give_Payment( $payment[0] ); |
|
95 | + if ($payment) { |
|
96 | + $payment = new Give_Payment($payment[0]); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | break; |
100 | 100 | |
101 | 101 | case 'payment_number': |
102 | - $payment = give_get_payments( array( |
|
102 | + $payment = give_get_payments(array( |
|
103 | 103 | 'meta_key' => '_give_payment_number', |
104 | 104 | 'meta_value' => $value, |
105 | 105 | 'posts_per_page' => 1, |
106 | 106 | 'fields' => 'ids', |
107 | - ) ); |
|
107 | + )); |
|
108 | 108 | |
109 | - if ( $payment ) { |
|
110 | - $payment = new Give_Payment( $payment[0] ); |
|
109 | + if ($payment) { |
|
110 | + $payment = new Give_Payment($payment[0]); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | break; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | return false; |
117 | 117 | } |
118 | 118 | |
119 | - if ( $payment ) { |
|
119 | + if ($payment) { |
|
120 | 120 | return $payment; |
121 | 121 | } |
122 | 122 | |
@@ -132,23 +132,23 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return int|bool Payment ID if payment is inserted, false otherwise. |
134 | 134 | */ |
135 | -function give_insert_payment( $payment_data = array() ) { |
|
135 | +function give_insert_payment($payment_data = array()) { |
|
136 | 136 | |
137 | - if ( empty( $payment_data ) ) { |
|
137 | + if (empty($payment_data)) { |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | |
141 | 141 | $payment = new Give_Payment(); |
142 | - $gateway = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : ''; |
|
143 | - $gateway = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway; |
|
144 | - $form_id = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0; |
|
145 | - $price_id = give_get_payment_meta_price_id( $payment_data ); |
|
146 | - $form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id ); |
|
142 | + $gateway = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : ''; |
|
143 | + $gateway = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway; |
|
144 | + $form_id = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0; |
|
145 | + $price_id = give_get_payment_meta_price_id($payment_data); |
|
146 | + $form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id); |
|
147 | 147 | |
148 | 148 | // Set properties. |
149 | 149 | $payment->total = $payment_data['price']; |
150 | - $payment->status = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending'; |
|
151 | - $payment->currency = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency(); |
|
150 | + $payment->status = ! empty($payment_data['status']) ? $payment_data['status'] : 'pending'; |
|
151 | + $payment->currency = ! empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency(); |
|
152 | 152 | $payment->user_info = $payment_data['user_info']; |
153 | 153 | $payment->gateway = $gateway; |
154 | 154 | $payment->form_title = $form_title; |
@@ -162,31 +162,31 @@ discard block |
||
162 | 162 | $payment->ip = give_get_ip(); |
163 | 163 | $payment->key = $payment_data['purchase_key']; |
164 | 164 | $payment->mode = give_is_test_mode() ? 'test' : 'live'; |
165 | - $payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : ''; |
|
165 | + $payment->parent_payment = ! empty($payment_data['parent']) ? absint($payment_data['parent']) : ''; |
|
166 | 166 | |
167 | 167 | // Add the donation. |
168 | 168 | $args = array( |
169 | 169 | 'price' => $payment->total, |
170 | 170 | 'price_id' => $payment->price_id, |
171 | - 'fees' => isset( $payment_data['fees'] ) ? $payment_data['fees'] : array(), |
|
171 | + 'fees' => isset($payment_data['fees']) ? $payment_data['fees'] : array(), |
|
172 | 172 | ); |
173 | 173 | |
174 | - $payment->add_donation( $payment->form_id, $args ); |
|
174 | + $payment->add_donation($payment->form_id, $args); |
|
175 | 175 | |
176 | 176 | // Set date if present. |
177 | - if ( isset( $payment_data['post_date'] ) ) { |
|
177 | + if (isset($payment_data['post_date'])) { |
|
178 | 178 | $payment->date = $payment_data['post_date']; |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Handle sequential payments. |
182 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
182 | + if (give_get_option('enable_sequential')) { |
|
183 | 183 | $number = give_get_next_payment_number(); |
184 | - $payment->number = give_format_payment_number( $number ); |
|
185 | - update_option( 'give_last_payment_number', $number ); |
|
184 | + $payment->number = give_format_payment_number($number); |
|
185 | + update_option('give_last_payment_number', $number); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | // Clear the user's donation cache. |
189 | - delete_transient( 'give_user_' . $payment_data['user_info']['id'] . '_purchases' ); |
|
189 | + delete_transient('give_user_'.$payment_data['user_info']['id'].'_purchases'); |
|
190 | 190 | |
191 | 191 | // Save payment. |
192 | 192 | $payment->save(); |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @param int $payment_id The payment ID. |
200 | 200 | * @param array $payment_data Arguments passed. |
201 | 201 | */ |
202 | - do_action( 'give_insert_payment', $payment->ID, $payment_data ); |
|
202 | + do_action('give_insert_payment', $payment->ID, $payment_data); |
|
203 | 203 | |
204 | 204 | // Return payment ID upon success. |
205 | - if ( ! empty( $payment->ID ) ) { |
|
205 | + if ( ! empty($payment->ID)) { |
|
206 | 206 | return $payment->ID; |
207 | 207 | } |
208 | 208 | |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return bool|int |
220 | 220 | */ |
221 | -function give_create_payment( $payment_data ) { |
|
221 | +function give_create_payment($payment_data) { |
|
222 | 222 | |
223 | - $form_id = intval( $payment_data['post_data']['give-form-id'] ); |
|
224 | - $price_id = isset( $payment_data['post_data']['give-price-id'] ) ? $payment_data['post_data']['give-price-id'] : ''; |
|
223 | + $form_id = intval($payment_data['post_data']['give-form-id']); |
|
224 | + $price_id = isset($payment_data['post_data']['give-price-id']) ? $payment_data['post_data']['give-price-id'] : ''; |
|
225 | 225 | |
226 | 226 | // Collect payment data. |
227 | 227 | $insert_payment_data = array( |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @param array $insert_payment_data |
247 | 247 | */ |
248 | - $insert_payment_data = apply_filters( 'give_create_payment', $insert_payment_data ); |
|
248 | + $insert_payment_data = apply_filters('give_create_payment', $insert_payment_data); |
|
249 | 249 | |
250 | 250 | // Record the pending payment. |
251 | - return give_insert_payment( $insert_payment_data ); |
|
251 | + return give_insert_payment($insert_payment_data); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return bool |
263 | 263 | */ |
264 | -function give_update_payment_status( $payment_id, $new_status = 'publish' ) { |
|
264 | +function give_update_payment_status($payment_id, $new_status = 'publish') { |
|
265 | 265 | |
266 | - $payment = new Give_Payment( $payment_id ); |
|
266 | + $payment = new Give_Payment($payment_id); |
|
267 | 267 | $payment->status = $new_status; |
268 | 268 | $updated = $payment->save(); |
269 | 269 | |
@@ -282,38 +282,38 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return void |
284 | 284 | */ |
285 | -function give_delete_purchase( $payment_id = 0, $update_customer = true ) { |
|
285 | +function give_delete_purchase($payment_id = 0, $update_customer = true) { |
|
286 | 286 | global $give_logs; |
287 | 287 | |
288 | - $payment = new Give_Payment( $payment_id ); |
|
289 | - $amount = give_get_payment_amount( $payment_id ); |
|
288 | + $payment = new Give_Payment($payment_id); |
|
289 | + $amount = give_get_payment_amount($payment_id); |
|
290 | 290 | $status = $payment->post_status; |
291 | - $customer_id = give_get_payment_customer_id( $payment_id ); |
|
292 | - $customer = new Give_Customer( $customer_id ); |
|
291 | + $customer_id = give_get_payment_customer_id($payment_id); |
|
292 | + $customer = new Give_Customer($customer_id); |
|
293 | 293 | |
294 | 294 | // Only undo donations that aren't these statuses. |
295 | - $dont_undo_statuses = apply_filters( 'give_undo_purchase_statuses', array( |
|
295 | + $dont_undo_statuses = apply_filters('give_undo_purchase_statuses', array( |
|
296 | 296 | 'pending', |
297 | 297 | 'cancelled', |
298 | - ) ); |
|
298 | + )); |
|
299 | 299 | |
300 | - if ( ! in_array( $status, $dont_undo_statuses ) ) { |
|
301 | - give_undo_purchase( false, $payment_id ); |
|
300 | + if ( ! in_array($status, $dont_undo_statuses)) { |
|
301 | + give_undo_purchase(false, $payment_id); |
|
302 | 302 | } |
303 | 303 | |
304 | - if ( $status == 'publish' ) { |
|
304 | + if ($status == 'publish') { |
|
305 | 305 | |
306 | 306 | // Only decrease earnings if they haven't already been decreased (or were never increased for this payment). |
307 | - give_decrease_total_earnings( $amount ); |
|
307 | + give_decrease_total_earnings($amount); |
|
308 | 308 | |
309 | 309 | // @todo: Refresh only range related stat cache |
310 | 310 | give_delete_donation_stats(); |
311 | 311 | |
312 | - if ( $customer->id && $update_customer ) { |
|
312 | + if ($customer->id && $update_customer) { |
|
313 | 313 | |
314 | 314 | // Decrement the stats for the donor. |
315 | 315 | $customer->decrease_purchase_count(); |
316 | - $customer->decrease_value( $amount ); |
|
316 | + $customer->decrease_value($amount); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | } |
@@ -325,17 +325,17 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @param int $payment_id Payment ID. |
327 | 327 | */ |
328 | - do_action( 'give_payment_delete', $payment_id ); |
|
328 | + do_action('give_payment_delete', $payment_id); |
|
329 | 329 | |
330 | - if ( $customer->id && $update_customer ) { |
|
330 | + if ($customer->id && $update_customer) { |
|
331 | 331 | |
332 | 332 | // Remove the payment ID from the donor. |
333 | - $customer->remove_payment( $payment_id ); |
|
333 | + $customer->remove_payment($payment_id); |
|
334 | 334 | |
335 | 335 | } |
336 | 336 | |
337 | 337 | // Remove the payment. |
338 | - wp_delete_post( $payment_id, true ); |
|
338 | + wp_delete_post($payment_id, true); |
|
339 | 339 | |
340 | 340 | // Remove related sale log entries. |
341 | 341 | $give_logs->delete_logs( |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @param int $payment_id Payment ID. |
358 | 358 | */ |
359 | - do_action( 'give_payment_deleted', $payment_id ); |
|
359 | + do_action('give_payment_deleted', $payment_id); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -372,25 +372,25 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @return void |
374 | 374 | */ |
375 | -function give_undo_purchase( $form_id = false, $payment_id ) { |
|
375 | +function give_undo_purchase($form_id = false, $payment_id) { |
|
376 | 376 | |
377 | - if ( ! empty( $form_id ) ) { |
|
377 | + if ( ! empty($form_id)) { |
|
378 | 378 | $form_id = false; |
379 | - _give_deprected_argument( 'form_id', 'give_undo_purchase', '1.5' ); |
|
379 | + _give_deprected_argument('form_id', 'give_undo_purchase', '1.5'); |
|
380 | 380 | } |
381 | 381 | |
382 | - $payment = new Give_Payment( $payment_id ); |
|
382 | + $payment = new Give_Payment($payment_id); |
|
383 | 383 | |
384 | - $maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id ); |
|
385 | - if ( true === $maybe_decrease_earnings ) { |
|
384 | + $maybe_decrease_earnings = apply_filters('give_decrease_earnings_on_undo', true, $payment, $payment->form_id); |
|
385 | + if (true === $maybe_decrease_earnings) { |
|
386 | 386 | // Decrease earnings. |
387 | - give_decrease_earnings( $payment->form_id, $payment->total ); |
|
387 | + give_decrease_earnings($payment->form_id, $payment->total); |
|
388 | 388 | } |
389 | 389 | |
390 | - $maybe_decrease_sales = apply_filters( 'give_decrease_sales_on_undo', true, $payment, $payment->form_id ); |
|
391 | - if ( true === $maybe_decrease_sales ) { |
|
390 | + $maybe_decrease_sales = apply_filters('give_decrease_sales_on_undo', true, $payment, $payment->form_id); |
|
391 | + if (true === $maybe_decrease_sales) { |
|
392 | 392 | // Decrease donation count. |
393 | - give_decrease_purchase_count( $payment->form_id ); |
|
393 | + give_decrease_purchase_count($payment->form_id); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | } |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @return object $stats Contains the number of payments per payment status. |
409 | 409 | */ |
410 | -function give_count_payments( $args = array() ) { |
|
410 | +function give_count_payments($args = array()) { |
|
411 | 411 | |
412 | 412 | global $wpdb; |
413 | 413 | |
@@ -419,18 +419,18 @@ discard block |
||
419 | 419 | 'form_id' => null, |
420 | 420 | ); |
421 | 421 | |
422 | - $args = wp_parse_args( $args, $defaults ); |
|
422 | + $args = wp_parse_args($args, $defaults); |
|
423 | 423 | |
424 | 424 | $select = 'SELECT p.post_status,count( * ) AS num_posts'; |
425 | 425 | $join = ''; |
426 | 426 | $where = "WHERE p.post_type = 'give_payment'"; |
427 | 427 | |
428 | 428 | // Count payments for a specific user. |
429 | - if ( ! empty( $args['user'] ) ) { |
|
429 | + if ( ! empty($args['user'])) { |
|
430 | 430 | |
431 | - if ( is_email( $args['user'] ) ) { |
|
431 | + if (is_email($args['user'])) { |
|
432 | 432 | $field = 'email'; |
433 | - } elseif ( is_numeric( $args['user'] ) ) { |
|
433 | + } elseif (is_numeric($args['user'])) { |
|
434 | 434 | $field = 'id'; |
435 | 435 | } else { |
436 | 436 | $field = ''; |
@@ -438,105 +438,105 @@ discard block |
||
438 | 438 | |
439 | 439 | $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
440 | 440 | |
441 | - if ( ! empty( $field ) ) { |
|
441 | + if ( ! empty($field)) { |
|
442 | 442 | $where .= " |
443 | 443 | AND m.meta_key = '_give_payment_user_{$field}' |
444 | 444 | AND m.meta_value = '{$args['user']}'"; |
445 | 445 | } |
446 | 446 | |
447 | 447 | // Count payments for a search. |
448 | - } elseif ( ! empty( $args['s'] ) ) { |
|
448 | + } elseif ( ! empty($args['s'])) { |
|
449 | 449 | |
450 | - if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) { |
|
450 | + if (is_email($args['s']) || strlen($args['s']) == 32) { |
|
451 | 451 | |
452 | - if ( is_email( $args['s'] ) ) { |
|
452 | + if (is_email($args['s'])) { |
|
453 | 453 | $field = '_give_payment_user_email'; |
454 | 454 | } else { |
455 | 455 | $field = '_give_payment_purchase_key'; |
456 | 456 | } |
457 | 457 | |
458 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
459 | - $where .= $wpdb->prepare( ' |
|
458 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
459 | + $where .= $wpdb->prepare(' |
|
460 | 460 | AND m.meta_key = %s |
461 | 461 | AND m.meta_value = %s', |
462 | 462 | $field, |
463 | 463 | $args['s'] |
464 | 464 | ); |
465 | 465 | |
466 | - } elseif ( '#' == substr( $args['s'], 0, 1 ) ) { |
|
466 | + } elseif ('#' == substr($args['s'], 0, 1)) { |
|
467 | 467 | |
468 | - $search = str_replace( '#:', '', $args['s'] ); |
|
469 | - $search = str_replace( '#', '', $search ); |
|
468 | + $search = str_replace('#:', '', $args['s']); |
|
469 | + $search = str_replace('#', '', $search); |
|
470 | 470 | |
471 | 471 | $select = 'SELECT p2.post_status,count( * ) AS num_posts '; |
472 | 472 | $join = "LEFT JOIN $wpdb->postmeta m ON m.meta_key = '_give_log_payment_id' AND m.post_id = p.ID "; |
473 | 473 | $join .= "INNER JOIN $wpdb->posts p2 ON m.meta_value = p2.ID "; |
474 | 474 | $where = "WHERE p.post_type = 'give_log' "; |
475 | - $where .= $wpdb->prepare( 'AND p.post_parent = %d} ', $search ); |
|
475 | + $where .= $wpdb->prepare('AND p.post_parent = %d} ', $search); |
|
476 | 476 | |
477 | - } elseif ( is_numeric( $args['s'] ) ) { |
|
477 | + } elseif (is_numeric($args['s'])) { |
|
478 | 478 | |
479 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
480 | - $where .= $wpdb->prepare( " |
|
479 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
480 | + $where .= $wpdb->prepare(" |
|
481 | 481 | AND m.meta_key = '_give_payment_user_id' |
482 | 482 | AND m.meta_value = %d", |
483 | 483 | $args['s'] |
484 | 484 | ); |
485 | 485 | |
486 | 486 | } else { |
487 | - $search = $wpdb->esc_like( $args['s'] ); |
|
488 | - $search = '%' . $search . '%'; |
|
487 | + $search = $wpdb->esc_like($args['s']); |
|
488 | + $search = '%'.$search.'%'; |
|
489 | 489 | |
490 | - $where .= $wpdb->prepare( 'AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search ); |
|
490 | + $where .= $wpdb->prepare('AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search); |
|
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | - if ( ! empty( $args['form_id'] ) && is_numeric( $args['form_id'] ) ) { |
|
494 | + if ( ! empty($args['form_id']) && is_numeric($args['form_id'])) { |
|
495 | 495 | |
496 | - $where .= $wpdb->prepare( ' AND p.post_parent = %d', $args['form_id'] ); |
|
496 | + $where .= $wpdb->prepare(' AND p.post_parent = %d', $args['form_id']); |
|
497 | 497 | |
498 | 498 | } |
499 | 499 | // Limit payments count by date. |
500 | - if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) { |
|
500 | + if ( ! empty($args['start-date']) && false !== strpos($args['start-date'], '/')) { |
|
501 | 501 | |
502 | - $date_parts = explode( '/', $args['start-date'] ); |
|
503 | - $month = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0; |
|
504 | - $day = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0; |
|
505 | - $year = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0; |
|
502 | + $date_parts = explode('/', $args['start-date']); |
|
503 | + $month = ! empty($date_parts[0]) && is_numeric($date_parts[0]) ? $date_parts[0] : 0; |
|
504 | + $day = ! empty($date_parts[1]) && is_numeric($date_parts[1]) ? $date_parts[1] : 0; |
|
505 | + $year = ! empty($date_parts[2]) && is_numeric($date_parts[2]) ? $date_parts[2] : 0; |
|
506 | 506 | |
507 | - $is_date = checkdate( $month, $day, $year ); |
|
508 | - if ( false !== $is_date ) { |
|
507 | + $is_date = checkdate($month, $day, $year); |
|
508 | + if (false !== $is_date) { |
|
509 | 509 | |
510 | - $date = new DateTime( $args['start-date'] ); |
|
511 | - $where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) ); |
|
510 | + $date = new DateTime($args['start-date']); |
|
511 | + $where .= $wpdb->prepare(" AND p.post_date >= '%s'", $date->format('Y-m-d')); |
|
512 | 512 | |
513 | 513 | } |
514 | 514 | |
515 | 515 | // Fixes an issue with the payments list table counts when no end date is specified (partiy with stats class). |
516 | - if ( empty( $args['end-date'] ) ) { |
|
516 | + if (empty($args['end-date'])) { |
|
517 | 517 | $args['end-date'] = $args['start-date']; |
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
521 | - if ( ! empty( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) { |
|
521 | + if ( ! empty($args['end-date']) && false !== strpos($args['end-date'], '/')) { |
|
522 | 522 | |
523 | - $date_parts = explode( '/', $args['end-date'] ); |
|
523 | + $date_parts = explode('/', $args['end-date']); |
|
524 | 524 | |
525 | - $month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0; |
|
526 | - $day = ! empty( $date_parts[1] ) ? $date_parts[1] : 0; |
|
527 | - $year = ! empty( $date_parts[2] ) ? $date_parts[2] : 0; |
|
525 | + $month = ! empty($date_parts[0]) ? $date_parts[0] : 0; |
|
526 | + $day = ! empty($date_parts[1]) ? $date_parts[1] : 0; |
|
527 | + $year = ! empty($date_parts[2]) ? $date_parts[2] : 0; |
|
528 | 528 | |
529 | - $is_date = checkdate( $month, $day, $year ); |
|
530 | - if ( false !== $is_date ) { |
|
529 | + $is_date = checkdate($month, $day, $year); |
|
530 | + if (false !== $is_date) { |
|
531 | 531 | |
532 | - $date = new DateTime( $args['end-date'] ); |
|
533 | - $where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) ); |
|
532 | + $date = new DateTime($args['end-date']); |
|
533 | + $where .= $wpdb->prepare(" AND p.post_date <= '%s'", $date->format('Y-m-d')); |
|
534 | 534 | |
535 | 535 | } |
536 | 536 | } |
537 | 537 | |
538 | - $where = apply_filters( 'give_count_payments_where', $where ); |
|
539 | - $join = apply_filters( 'give_count_payments_join', $join ); |
|
538 | + $where = apply_filters('give_count_payments_where', $where); |
|
539 | + $join = apply_filters('give_count_payments_join', $join); |
|
540 | 540 | |
541 | 541 | $query = "$select |
542 | 542 | FROM $wpdb->posts p |
@@ -545,36 +545,36 @@ discard block |
||
545 | 545 | GROUP BY p.post_status |
546 | 546 | "; |
547 | 547 | |
548 | - $cache_key = md5( $query ); |
|
548 | + $cache_key = md5($query); |
|
549 | 549 | |
550 | - $count = wp_cache_get( $cache_key, 'counts' ); |
|
551 | - if ( false !== $count ) { |
|
550 | + $count = wp_cache_get($cache_key, 'counts'); |
|
551 | + if (false !== $count) { |
|
552 | 552 | return $count; |
553 | 553 | } |
554 | 554 | |
555 | - $count = $wpdb->get_results( $query, ARRAY_A ); |
|
555 | + $count = $wpdb->get_results($query, ARRAY_A); |
|
556 | 556 | |
557 | 557 | $stats = array(); |
558 | 558 | $statuses = get_post_stati(); |
559 | - if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) { |
|
560 | - unset( $statuses['private'] ); |
|
559 | + if (isset($statuses['private']) && empty($args['s'])) { |
|
560 | + unset($statuses['private']); |
|
561 | 561 | } |
562 | 562 | |
563 | - foreach ( $statuses as $state ) { |
|
564 | - $stats[ $state ] = 0; |
|
563 | + foreach ($statuses as $state) { |
|
564 | + $stats[$state] = 0; |
|
565 | 565 | } |
566 | 566 | |
567 | - foreach ( (array) $count as $row ) { |
|
567 | + foreach ((array) $count as $row) { |
|
568 | 568 | |
569 | - if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) { |
|
569 | + if ('private' == $row['post_status'] && empty($args['s'])) { |
|
570 | 570 | continue; |
571 | 571 | } |
572 | 572 | |
573 | - $stats[ $row['post_status'] ] = $row['num_posts']; |
|
573 | + $stats[$row['post_status']] = $row['num_posts']; |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | $stats = (object) $stats; |
577 | - wp_cache_set( $cache_key, $stats, 'counts' ); |
|
577 | + wp_cache_set($cache_key, $stats, 'counts'); |
|
578 | 578 | |
579 | 579 | return $stats; |
580 | 580 | } |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | * |
590 | 590 | * @return bool $exists True if payment exists, false otherwise. |
591 | 591 | */ |
592 | -function give_check_for_existing_payment( $payment_id ) { |
|
592 | +function give_check_for_existing_payment($payment_id) { |
|
593 | 593 | $exists = false; |
594 | - $payment = new Give_Payment( $payment_id ); |
|
594 | + $payment = new Give_Payment($payment_id); |
|
595 | 595 | |
596 | - if ( $payment_id === $payment->ID && 'publish' === $payment->status ) { |
|
596 | + if ($payment_id === $payment->ID && 'publish' === $payment->status) { |
|
597 | 597 | $exists = true; |
598 | 598 | } |
599 | 599 | |
@@ -611,31 +611,31 @@ discard block |
||
611 | 611 | * |
612 | 612 | * @return bool|mixed True if payment status exists, false otherwise. |
613 | 613 | */ |
614 | -function give_get_payment_status( $payment, $return_label = false ) { |
|
614 | +function give_get_payment_status($payment, $return_label = false) { |
|
615 | 615 | |
616 | - if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) { |
|
616 | + if ( ! is_object($payment) || ! isset($payment->post_status)) { |
|
617 | 617 | return false; |
618 | 618 | } |
619 | 619 | |
620 | 620 | $statuses = give_get_payment_statuses(); |
621 | 621 | |
622 | - if ( ! is_array( $statuses ) || empty( $statuses ) ) { |
|
622 | + if ( ! is_array($statuses) || empty($statuses)) { |
|
623 | 623 | return false; |
624 | 624 | } |
625 | 625 | |
626 | 626 | // Get payment object if no already given. |
627 | - $payment = $payment instanceof Give_Payment ? $payment : new Give_Payment( $payment->ID ); |
|
627 | + $payment = $payment instanceof Give_Payment ? $payment : new Give_Payment($payment->ID); |
|
628 | 628 | |
629 | - if ( array_key_exists( $payment->status, $statuses ) ) { |
|
630 | - if ( true === $return_label ) { |
|
629 | + if (array_key_exists($payment->status, $statuses)) { |
|
630 | + if (true === $return_label) { |
|
631 | 631 | // Return translated status label. |
632 | - return $statuses[ $payment->status ]; |
|
632 | + return $statuses[$payment->status]; |
|
633 | 633 | } else { |
634 | 634 | // Account that our 'publish' status is labeled 'Complete' |
635 | 635 | $post_status = 'publish' == $payment->status ? 'Complete' : $payment->post_status; |
636 | 636 | |
637 | 637 | // Make sure we're matching cases, since they matter |
638 | - return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) ); |
|
638 | + return array_search(strtolower($post_status), array_map('strtolower', $statuses)); |
|
639 | 639 | } |
640 | 640 | } |
641 | 641 | |
@@ -651,17 +651,17 @@ discard block |
||
651 | 651 | */ |
652 | 652 | function give_get_payment_statuses() { |
653 | 653 | $payment_statuses = array( |
654 | - 'pending' => __( 'Pending', 'give' ), |
|
655 | - 'publish' => __( 'Complete', 'give' ), |
|
656 | - 'refunded' => __( 'Refunded', 'give' ), |
|
657 | - 'failed' => __( 'Failed', 'give' ), |
|
658 | - 'cancelled' => __( 'Cancelled', 'give' ), |
|
659 | - 'abandoned' => __( 'Abandoned', 'give' ), |
|
660 | - 'preapproval' => __( 'Pre-Approved', 'give' ), |
|
661 | - 'revoked' => __( 'Revoked', 'give' ), |
|
654 | + 'pending' => __('Pending', 'give'), |
|
655 | + 'publish' => __('Complete', 'give'), |
|
656 | + 'refunded' => __('Refunded', 'give'), |
|
657 | + 'failed' => __('Failed', 'give'), |
|
658 | + 'cancelled' => __('Cancelled', 'give'), |
|
659 | + 'abandoned' => __('Abandoned', 'give'), |
|
660 | + 'preapproval' => __('Pre-Approved', 'give'), |
|
661 | + 'revoked' => __('Revoked', 'give'), |
|
662 | 662 | ); |
663 | 663 | |
664 | - return apply_filters( 'give_payment_statuses', $payment_statuses ); |
|
664 | + return apply_filters('give_payment_statuses', $payment_statuses); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | /** |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | * @return array $payment_status All the available payment statuses. |
675 | 675 | */ |
676 | 676 | function give_get_payment_status_keys() { |
677 | - $statuses = array_keys( give_get_payment_statuses() ); |
|
678 | - asort( $statuses ); |
|
677 | + $statuses = array_keys(give_get_payment_statuses()); |
|
678 | + asort($statuses); |
|
679 | 679 | |
680 | - return array_values( $statuses ); |
|
680 | + return array_values($statuses); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | * |
693 | 693 | * @return int $earnings Earnings |
694 | 694 | */ |
695 | -function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) { |
|
695 | +function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) { |
|
696 | 696 | |
697 | 697 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead. |
698 | 698 | global $wpdb; |
@@ -702,41 +702,41 @@ discard block |
||
702 | 702 | 'nopaging' => true, |
703 | 703 | 'year' => $year, |
704 | 704 | 'monthnum' => $month_num, |
705 | - 'post_status' => array( 'publish' ), |
|
705 | + 'post_status' => array('publish'), |
|
706 | 706 | 'fields' => 'ids', |
707 | 707 | 'update_post_term_cache' => false, |
708 | 708 | ); |
709 | - if ( ! empty( $day ) ) { |
|
709 | + if ( ! empty($day)) { |
|
710 | 710 | $args['day'] = $day; |
711 | 711 | } |
712 | 712 | |
713 | - if ( ! empty( $hour ) ) { |
|
713 | + if ( ! empty($hour)) { |
|
714 | 714 | $args['hour'] = $hour; |
715 | 715 | } |
716 | 716 | |
717 | - $args = apply_filters( 'give_get_earnings_by_date_args', $args ); |
|
718 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
717 | + $args = apply_filters('give_get_earnings_by_date_args', $args); |
|
718 | + $key = Give_Cache::get_key('give_stats', $args); |
|
719 | 719 | |
720 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
720 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
721 | 721 | $earnings = false; |
722 | 722 | } else { |
723 | - $earnings = Give_Cache::get( $key ); |
|
723 | + $earnings = Give_Cache::get($key); |
|
724 | 724 | } |
725 | 725 | |
726 | - if ( false === $earnings ) { |
|
727 | - $sales = get_posts( $args ); |
|
726 | + if (false === $earnings) { |
|
727 | + $sales = get_posts($args); |
|
728 | 728 | $earnings = 0; |
729 | - if ( $sales ) { |
|
730 | - $sales = implode( ',', $sales ); |
|
729 | + if ($sales) { |
|
730 | + $sales = implode(',', $sales); |
|
731 | 731 | |
732 | - $earnings = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$sales})" ); |
|
732 | + $earnings = $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$sales})"); |
|
733 | 733 | |
734 | 734 | } |
735 | 735 | // Cache the results for one hour. |
736 | - Give_Cache::set( $key, $earnings, HOUR_IN_SECONDS ); |
|
736 | + Give_Cache::set($key, $earnings, HOUR_IN_SECONDS); |
|
737 | 737 | } |
738 | 738 | |
739 | - return round( $earnings, 2 ); |
|
739 | + return round($earnings, 2); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | /** |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | * |
752 | 752 | * @return int $count Sales |
753 | 753 | */ |
754 | -function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) { |
|
754 | +function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) { |
|
755 | 755 | |
756 | 756 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead. |
757 | 757 | $args = array( |
@@ -759,14 +759,14 @@ discard block |
||
759 | 759 | 'nopaging' => true, |
760 | 760 | 'year' => $year, |
761 | 761 | 'fields' => 'ids', |
762 | - 'post_status' => array( 'publish' ), |
|
762 | + 'post_status' => array('publish'), |
|
763 | 763 | 'update_post_meta_cache' => false, |
764 | 764 | 'update_post_term_cache' => false, |
765 | 765 | ); |
766 | 766 | |
767 | - $show_free = apply_filters( 'give_sales_by_date_show_free', true, $args ); |
|
767 | + $show_free = apply_filters('give_sales_by_date_show_free', true, $args); |
|
768 | 768 | |
769 | - if ( false === $show_free ) { |
|
769 | + if (false === $show_free) { |
|
770 | 770 | $args['meta_query'] = array( |
771 | 771 | array( |
772 | 772 | 'key' => '_give_payment_total', |
@@ -777,33 +777,33 @@ discard block |
||
777 | 777 | ); |
778 | 778 | } |
779 | 779 | |
780 | - if ( ! empty( $month_num ) ) { |
|
780 | + if ( ! empty($month_num)) { |
|
781 | 781 | $args['monthnum'] = $month_num; |
782 | 782 | } |
783 | 783 | |
784 | - if ( ! empty( $day ) ) { |
|
784 | + if ( ! empty($day)) { |
|
785 | 785 | $args['day'] = $day; |
786 | 786 | } |
787 | 787 | |
788 | - if ( ! empty( $hour ) ) { |
|
788 | + if ( ! empty($hour)) { |
|
789 | 789 | $args['hour'] = $hour; |
790 | 790 | } |
791 | 791 | |
792 | - $args = apply_filters( 'give_get_sales_by_date_args', $args ); |
|
792 | + $args = apply_filters('give_get_sales_by_date_args', $args); |
|
793 | 793 | |
794 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
794 | + $key = Give_Cache::get_key('give_stats', $args); |
|
795 | 795 | |
796 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
796 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
797 | 797 | $count = false; |
798 | 798 | } else { |
799 | - $count = Give_Cache::get( $key ); |
|
799 | + $count = Give_Cache::get($key); |
|
800 | 800 | } |
801 | 801 | |
802 | - if ( false === $count ) { |
|
803 | - $sales = new WP_Query( $args ); |
|
802 | + if (false === $count) { |
|
803 | + $sales = new WP_Query($args); |
|
804 | 804 | $count = (int) $sales->post_count; |
805 | 805 | // Cache the results for one hour. |
806 | - Give_Cache::set( $key, $count, HOUR_IN_SECONDS ); |
|
806 | + Give_Cache::set($key, $count, HOUR_IN_SECONDS); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | return $count; |
@@ -818,19 +818,19 @@ discard block |
||
818 | 818 | * |
819 | 819 | * @return bool $ret True if complete, false otherwise. |
820 | 820 | */ |
821 | -function give_is_payment_complete( $payment_id ) { |
|
822 | - $payment = new Give_Payment( $payment_id ); |
|
821 | +function give_is_payment_complete($payment_id) { |
|
822 | + $payment = new Give_Payment($payment_id); |
|
823 | 823 | |
824 | 824 | $ret = false; |
825 | 825 | |
826 | - if ( $payment->ID > 0 ) { |
|
826 | + if ($payment->ID > 0) { |
|
827 | 827 | |
828 | - if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) { |
|
828 | + if ((int) $payment_id === (int) $payment->ID && 'publish' == $payment->status) { |
|
829 | 829 | $ret = true; |
830 | 830 | } |
831 | 831 | } |
832 | 832 | |
833 | - return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status ); |
|
833 | + return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment->post_status); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
@@ -856,49 +856,49 @@ discard block |
||
856 | 856 | * |
857 | 857 | * @return float $total Total earnings. |
858 | 858 | */ |
859 | -function give_get_total_earnings( $recalculate = false ) { |
|
859 | +function give_get_total_earnings($recalculate = false) { |
|
860 | 860 | |
861 | - $total = get_option( 'give_earnings_total', 0 ); |
|
861 | + $total = get_option('give_earnings_total', 0); |
|
862 | 862 | |
863 | 863 | // Calculate total earnings. |
864 | - if ( ! $total || $recalculate ) { |
|
864 | + if ( ! $total || $recalculate) { |
|
865 | 865 | global $wpdb; |
866 | 866 | |
867 | 867 | $total = (float) 0; |
868 | 868 | |
869 | - $args = apply_filters( 'give_get_total_earnings_args', array( |
|
869 | + $args = apply_filters('give_get_total_earnings_args', array( |
|
870 | 870 | 'offset' => 0, |
871 | - 'number' => - 1, |
|
872 | - 'status' => array( 'publish' ), |
|
871 | + 'number' => -1, |
|
872 | + 'status' => array('publish'), |
|
873 | 873 | 'fields' => 'ids', |
874 | - ) ); |
|
874 | + )); |
|
875 | 875 | |
876 | - $payments = give_get_payments( $args ); |
|
877 | - if ( $payments ) { |
|
876 | + $payments = give_get_payments($args); |
|
877 | + if ($payments) { |
|
878 | 878 | |
879 | 879 | /** |
880 | 880 | * If performing a donation, we need to skip the very last payment in the database, |
881 | 881 | * since it calls give_increase_total_earnings() on completion, |
882 | 882 | * which results in duplicated earnings for the very first donation. |
883 | 883 | */ |
884 | - if ( did_action( 'give_update_payment_status' ) ) { |
|
885 | - array_pop( $payments ); |
|
884 | + if (did_action('give_update_payment_status')) { |
|
885 | + array_pop($payments); |
|
886 | 886 | } |
887 | 887 | |
888 | - if ( ! empty( $payments ) ) { |
|
889 | - $payments = implode( ',', $payments ); |
|
890 | - $total += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" ); |
|
888 | + if ( ! empty($payments)) { |
|
889 | + $payments = implode(',', $payments); |
|
890 | + $total += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})"); |
|
891 | 891 | } |
892 | 892 | } |
893 | 893 | |
894 | - update_option( 'give_earnings_total', $total, 'no' ); |
|
894 | + update_option('give_earnings_total', $total, 'no'); |
|
895 | 895 | } |
896 | 896 | |
897 | - if ( $total < 0 ) { |
|
897 | + if ($total < 0) { |
|
898 | 898 | $total = 0; // Don't ever show negative earnings. |
899 | 899 | } |
900 | 900 | |
901 | - return apply_filters( 'give_total_earnings', round( $total, give_currency_decimal_filter() ) ); |
|
901 | + return apply_filters('give_total_earnings', round($total, give_currency_decimal_filter())); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
@@ -911,10 +911,10 @@ discard block |
||
911 | 911 | * |
912 | 912 | * @return float $total Total earnings. |
913 | 913 | */ |
914 | -function give_increase_total_earnings( $amount = 0 ) { |
|
914 | +function give_increase_total_earnings($amount = 0) { |
|
915 | 915 | $total = give_get_total_earnings(); |
916 | 916 | $total += $amount; |
917 | - update_option( 'give_earnings_total', $total ); |
|
917 | + update_option('give_earnings_total', $total); |
|
918 | 918 | |
919 | 919 | return $total; |
920 | 920 | } |
@@ -928,13 +928,13 @@ discard block |
||
928 | 928 | * |
929 | 929 | * @return float $total Total earnings. |
930 | 930 | */ |
931 | -function give_decrease_total_earnings( $amount = 0 ) { |
|
931 | +function give_decrease_total_earnings($amount = 0) { |
|
932 | 932 | $total = give_get_total_earnings(); |
933 | 933 | $total -= $amount; |
934 | - if ( $total < 0 ) { |
|
934 | + if ($total < 0) { |
|
935 | 935 | $total = 0; |
936 | 936 | } |
937 | - update_option( 'give_earnings_total', $total ); |
|
937 | + update_option('give_earnings_total', $total); |
|
938 | 938 | |
939 | 939 | return $total; |
940 | 940 | } |
@@ -950,10 +950,10 @@ discard block |
||
950 | 950 | * |
951 | 951 | * @return mixed $meta Payment Meta. |
952 | 952 | */ |
953 | -function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) { |
|
954 | - $payment = new Give_Payment( $payment_id ); |
|
953 | +function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) { |
|
954 | + $payment = new Give_Payment($payment_id); |
|
955 | 955 | |
956 | - return $payment->get_meta( $meta_key, $single ); |
|
956 | + return $payment->get_meta($meta_key, $single); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | /** |
@@ -966,10 +966,10 @@ discard block |
||
966 | 966 | * |
967 | 967 | * @return mixed Meta ID if successful, false if unsuccessful. |
968 | 968 | */ |
969 | -function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
970 | - $payment = new Give_Payment( $payment_id ); |
|
969 | +function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
970 | + $payment = new Give_Payment($payment_id); |
|
971 | 971 | |
972 | - return $payment->update_meta( $meta_key, $meta_value, $prev_value ); |
|
972 | + return $payment->update_meta($meta_key, $meta_value, $prev_value); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
@@ -981,8 +981,8 @@ discard block |
||
981 | 981 | * |
982 | 982 | * @return string $user_info User Info Meta Values. |
983 | 983 | */ |
984 | -function give_get_payment_meta_user_info( $payment_id ) { |
|
985 | - $payment = new Give_Payment( $payment_id ); |
|
984 | +function give_get_payment_meta_user_info($payment_id) { |
|
985 | + $payment = new Give_Payment($payment_id); |
|
986 | 986 | |
987 | 987 | return $payment->user_info; |
988 | 988 | } |
@@ -998,8 +998,8 @@ discard block |
||
998 | 998 | * |
999 | 999 | * @return int $form_id Form ID. |
1000 | 1000 | */ |
1001 | -function give_get_payment_form_id( $payment_id ) { |
|
1002 | - $payment = new Give_Payment( $payment_id ); |
|
1001 | +function give_get_payment_form_id($payment_id) { |
|
1002 | + $payment = new Give_Payment($payment_id); |
|
1003 | 1003 | |
1004 | 1004 | return $payment->form_id; |
1005 | 1005 | } |
@@ -1013,8 +1013,8 @@ discard block |
||
1013 | 1013 | * |
1014 | 1014 | * @return string $email User email. |
1015 | 1015 | */ |
1016 | -function give_get_payment_user_email( $payment_id ) { |
|
1017 | - $payment = new Give_Payment( $payment_id ); |
|
1016 | +function give_get_payment_user_email($payment_id) { |
|
1017 | + $payment = new Give_Payment($payment_id); |
|
1018 | 1018 | |
1019 | 1019 | return $payment->email; |
1020 | 1020 | } |
@@ -1028,11 +1028,11 @@ discard block |
||
1028 | 1028 | * |
1029 | 1029 | * @return bool $is_guest_payment If the payment is associated with a user (false) or not (true) |
1030 | 1030 | */ |
1031 | -function give_is_guest_payment( $payment_id ) { |
|
1032 | - $payment_user_id = give_get_payment_user_id( $payment_id ); |
|
1033 | - $is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true; |
|
1031 | +function give_is_guest_payment($payment_id) { |
|
1032 | + $payment_user_id = give_get_payment_user_id($payment_id); |
|
1033 | + $is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true; |
|
1034 | 1034 | |
1035 | - return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id ); |
|
1035 | + return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | /** |
@@ -1044,8 +1044,8 @@ discard block |
||
1044 | 1044 | * |
1045 | 1045 | * @return int $user_id User ID. |
1046 | 1046 | */ |
1047 | -function give_get_payment_user_id( $payment_id ) { |
|
1048 | - $payment = new Give_Payment( $payment_id ); |
|
1047 | +function give_get_payment_user_id($payment_id) { |
|
1048 | + $payment = new Give_Payment($payment_id); |
|
1049 | 1049 | |
1050 | 1050 | return $payment->user_id; |
1051 | 1051 | } |
@@ -1059,8 +1059,8 @@ discard block |
||
1059 | 1059 | * |
1060 | 1060 | * @return int $customer_id Customer ID. |
1061 | 1061 | */ |
1062 | -function give_get_payment_customer_id( $payment_id ) { |
|
1063 | - $payment = new Give_Payment( $payment_id ); |
|
1062 | +function give_get_payment_customer_id($payment_id) { |
|
1063 | + $payment = new Give_Payment($payment_id); |
|
1064 | 1064 | |
1065 | 1065 | return $payment->customer_id; |
1066 | 1066 | } |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * |
1075 | 1075 | * @return string $ip User IP. |
1076 | 1076 | */ |
1077 | -function give_get_payment_user_ip( $payment_id ) { |
|
1078 | - $payment = new Give_Payment( $payment_id ); |
|
1077 | +function give_get_payment_user_ip($payment_id) { |
|
1078 | + $payment = new Give_Payment($payment_id); |
|
1079 | 1079 | |
1080 | 1080 | return $payment->ip; |
1081 | 1081 | } |
@@ -1089,8 +1089,8 @@ discard block |
||
1089 | 1089 | * |
1090 | 1090 | * @return string $date The date the payment was completed. |
1091 | 1091 | */ |
1092 | -function give_get_payment_completed_date( $payment_id = 0 ) { |
|
1093 | - $payment = new Give_Payment( $payment_id ); |
|
1092 | +function give_get_payment_completed_date($payment_id = 0) { |
|
1093 | + $payment = new Give_Payment($payment_id); |
|
1094 | 1094 | |
1095 | 1095 | return $payment->completed_date; |
1096 | 1096 | } |
@@ -1104,8 +1104,8 @@ discard block |
||
1104 | 1104 | * |
1105 | 1105 | * @return string $gateway Gateway. |
1106 | 1106 | */ |
1107 | -function give_get_payment_gateway( $payment_id ) { |
|
1108 | - $payment = new Give_Payment( $payment_id ); |
|
1107 | +function give_get_payment_gateway($payment_id) { |
|
1108 | + $payment = new Give_Payment($payment_id); |
|
1109 | 1109 | |
1110 | 1110 | return $payment->gateway; |
1111 | 1111 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
1119 | 1119 | * |
1120 | 1120 | * @return string $currency The currency code. |
1121 | 1121 | */ |
1122 | -function give_get_payment_currency_code( $payment_id = 0 ) { |
|
1123 | - $payment = new Give_Payment( $payment_id ); |
|
1122 | +function give_get_payment_currency_code($payment_id = 0) { |
|
1123 | + $payment = new Give_Payment($payment_id); |
|
1124 | 1124 | |
1125 | 1125 | return $payment->currency; |
1126 | 1126 | } |
@@ -1134,10 +1134,10 @@ discard block |
||
1134 | 1134 | * |
1135 | 1135 | * @return string $currency The currency name. |
1136 | 1136 | */ |
1137 | -function give_get_payment_currency( $payment_id = 0 ) { |
|
1138 | - $currency = give_get_payment_currency_code( $payment_id ); |
|
1137 | +function give_get_payment_currency($payment_id = 0) { |
|
1138 | + $currency = give_get_payment_currency_code($payment_id); |
|
1139 | 1139 | |
1140 | - return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id ); |
|
1140 | + return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1149,8 +1149,8 @@ discard block |
||
1149 | 1149 | * |
1150 | 1150 | * @return string $key Donation key. |
1151 | 1151 | */ |
1152 | -function give_get_payment_key( $payment_id = 0 ) { |
|
1153 | - $payment = new Give_Payment( $payment_id ); |
|
1152 | +function give_get_payment_key($payment_id = 0) { |
|
1153 | + $payment = new Give_Payment($payment_id); |
|
1154 | 1154 | |
1155 | 1155 | return $payment->key; |
1156 | 1156 | } |
@@ -1166,8 +1166,8 @@ discard block |
||
1166 | 1166 | * |
1167 | 1167 | * @return string $number Payment order number. |
1168 | 1168 | */ |
1169 | -function give_get_payment_number( $payment_id = 0 ) { |
|
1170 | - $payment = new Give_Payment( $payment_id ); |
|
1169 | +function give_get_payment_number($payment_id = 0) { |
|
1170 | + $payment = new Give_Payment($payment_id); |
|
1171 | 1171 | |
1172 | 1172 | return $payment->number; |
1173 | 1173 | } |
@@ -1181,23 +1181,23 @@ discard block |
||
1181 | 1181 | * |
1182 | 1182 | * @return string The formatted payment number. |
1183 | 1183 | */ |
1184 | -function give_format_payment_number( $number ) { |
|
1184 | +function give_format_payment_number($number) { |
|
1185 | 1185 | |
1186 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
1186 | + if ( ! give_get_option('enable_sequential')) { |
|
1187 | 1187 | return $number; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - if ( ! is_numeric( $number ) ) { |
|
1190 | + if ( ! is_numeric($number)) { |
|
1191 | 1191 | return $number; |
1192 | 1192 | } |
1193 | 1193 | |
1194 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
1195 | - $number = absint( $number ); |
|
1196 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
1194 | + $prefix = give_get_option('sequential_prefix'); |
|
1195 | + $number = absint($number); |
|
1196 | + $postfix = give_get_option('sequential_postfix'); |
|
1197 | 1197 | |
1198 | - $formatted_number = $prefix . $number . $postfix; |
|
1198 | + $formatted_number = $prefix.$number.$postfix; |
|
1199 | 1199 | |
1200 | - return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix ); |
|
1200 | + return apply_filters('give_format_payment_number', $formatted_number, $prefix, $number, $postfix); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | /** |
@@ -1210,17 +1210,17 @@ discard block |
||
1210 | 1210 | */ |
1211 | 1211 | function give_get_next_payment_number() { |
1212 | 1212 | |
1213 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
1213 | + if ( ! give_get_option('enable_sequential')) { |
|
1214 | 1214 | return false; |
1215 | 1215 | } |
1216 | 1216 | |
1217 | - $number = get_option( 'give_last_payment_number' ); |
|
1218 | - $start = give_get_option( 'sequential_start', 1 ); |
|
1217 | + $number = get_option('give_last_payment_number'); |
|
1218 | + $start = give_get_option('sequential_start', 1); |
|
1219 | 1219 | $increment_number = true; |
1220 | 1220 | |
1221 | - if ( false !== $number ) { |
|
1221 | + if (false !== $number) { |
|
1222 | 1222 | |
1223 | - if ( empty( $number ) ) { |
|
1223 | + if (empty($number)) { |
|
1224 | 1224 | |
1225 | 1225 | $number = $start; |
1226 | 1226 | $increment_number = false; |
@@ -1229,24 +1229,24 @@ discard block |
||
1229 | 1229 | } else { |
1230 | 1230 | |
1231 | 1231 | // This case handles the first addition of the new option, as well as if it get's deleted for any reason. |
1232 | - $payments = new Give_Payments_Query( array( |
|
1232 | + $payments = new Give_Payments_Query(array( |
|
1233 | 1233 | 'number' => 1, |
1234 | 1234 | 'order' => 'DESC', |
1235 | 1235 | 'orderby' => 'ID', |
1236 | 1236 | 'output' => 'posts', |
1237 | 1237 | 'fields' => 'ids', |
1238 | - ) ); |
|
1238 | + )); |
|
1239 | 1239 | $last_payment = $payments->get_payments(); |
1240 | 1240 | |
1241 | - if ( ! empty( $last_payment ) ) { |
|
1241 | + if ( ! empty($last_payment)) { |
|
1242 | 1242 | |
1243 | - $number = give_get_payment_number( $last_payment[0] ); |
|
1243 | + $number = give_get_payment_number($last_payment[0]); |
|
1244 | 1244 | |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - if ( ! empty( $number ) && $number !== (int) $last_payment[0] ) { |
|
1247 | + if ( ! empty($number) && $number !== (int) $last_payment[0]) { |
|
1248 | 1248 | |
1249 | - $number = give_remove_payment_prefix_postfix( $number ); |
|
1249 | + $number = give_remove_payment_prefix_postfix($number); |
|
1250 | 1250 | |
1251 | 1251 | } else { |
1252 | 1252 | |
@@ -1255,13 +1255,13 @@ discard block |
||
1255 | 1255 | } |
1256 | 1256 | } |
1257 | 1257 | |
1258 | - $increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number ); |
|
1258 | + $increment_number = apply_filters('give_increment_payment_number', $increment_number, $number); |
|
1259 | 1259 | |
1260 | - if ( $increment_number ) { |
|
1261 | - $number ++; |
|
1260 | + if ($increment_number) { |
|
1261 | + $number++; |
|
1262 | 1262 | } |
1263 | 1263 | |
1264 | - return apply_filters( 'give_get_next_payment_number', $number ); |
|
1264 | + return apply_filters('give_get_next_payment_number', $number); |
|
1265 | 1265 | } |
1266 | 1266 | |
1267 | 1267 | /** |
@@ -1273,25 +1273,25 @@ discard block |
||
1273 | 1273 | * |
1274 | 1274 | * @return string The new Payment number without prefix and postfix. |
1275 | 1275 | */ |
1276 | -function give_remove_payment_prefix_postfix( $number ) { |
|
1276 | +function give_remove_payment_prefix_postfix($number) { |
|
1277 | 1277 | |
1278 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
1279 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
1278 | + $prefix = give_get_option('sequential_prefix'); |
|
1279 | + $postfix = give_get_option('sequential_postfix'); |
|
1280 | 1280 | |
1281 | 1281 | // Remove prefix. |
1282 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
1282 | + $number = preg_replace('/'.$prefix.'/', '', $number, 1); |
|
1283 | 1283 | |
1284 | 1284 | // Remove the postfix. |
1285 | - $length = strlen( $number ); |
|
1286 | - $postfix_pos = strrpos( $number, $postfix ); |
|
1287 | - if ( false !== $postfix_pos ) { |
|
1288 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
1285 | + $length = strlen($number); |
|
1286 | + $postfix_pos = strrpos($number, $postfix); |
|
1287 | + if (false !== $postfix_pos) { |
|
1288 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
1289 | 1289 | } |
1290 | 1290 | |
1291 | 1291 | // Ensure it's a whole number. |
1292 | - $number = intval( $number ); |
|
1292 | + $number = intval($number); |
|
1293 | 1293 | |
1294 | - return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix ); |
|
1294 | + return apply_filters('give_remove_payment_prefix_postfix', $number, $prefix, $postfix); |
|
1295 | 1295 | |
1296 | 1296 | } |
1297 | 1297 | |
@@ -1308,10 +1308,10 @@ discard block |
||
1308 | 1308 | * |
1309 | 1309 | * @return string $amount Fully formatted payment amount. |
1310 | 1310 | */ |
1311 | -function give_payment_amount( $payment_id = 0 ) { |
|
1312 | - $amount = give_get_payment_amount( $payment_id ); |
|
1311 | +function give_payment_amount($payment_id = 0) { |
|
1312 | + $amount = give_get_payment_amount($payment_id); |
|
1313 | 1313 | |
1314 | - return give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment_id ) ); |
|
1314 | + return give_currency_filter(give_format_amount($amount), give_get_payment_currency_code($payment_id)); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | /** |
@@ -1324,11 +1324,11 @@ discard block |
||
1324 | 1324 | * |
1325 | 1325 | * @return mixed|void |
1326 | 1326 | */ |
1327 | -function give_get_payment_amount( $payment_id ) { |
|
1327 | +function give_get_payment_amount($payment_id) { |
|
1328 | 1328 | |
1329 | - $payment = new Give_Payment( $payment_id ); |
|
1329 | + $payment = new Give_Payment($payment_id); |
|
1330 | 1330 | |
1331 | - return apply_filters( 'give_payment_amount', floatval( $payment->total ), $payment_id ); |
|
1331 | + return apply_filters('give_payment_amount', floatval($payment->total), $payment_id); |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | /** |
@@ -1345,10 +1345,10 @@ discard block |
||
1345 | 1345 | * |
1346 | 1346 | * @return array Fully formatted payment subtotal. |
1347 | 1347 | */ |
1348 | -function give_payment_subtotal( $payment_id = 0 ) { |
|
1349 | - $subtotal = give_get_payment_subtotal( $payment_id ); |
|
1348 | +function give_payment_subtotal($payment_id = 0) { |
|
1349 | + $subtotal = give_get_payment_subtotal($payment_id); |
|
1350 | 1350 | |
1351 | - return give_currency_filter( give_format_amount( $subtotal ), give_get_payment_currency_code( $payment_id ) ); |
|
1351 | + return give_currency_filter(give_format_amount($subtotal), give_get_payment_currency_code($payment_id)); |
|
1352 | 1352 | } |
1353 | 1353 | |
1354 | 1354 | /** |
@@ -1362,8 +1362,8 @@ discard block |
||
1362 | 1362 | * |
1363 | 1363 | * @return float $subtotal Subtotal for payment (non formatted). |
1364 | 1364 | */ |
1365 | -function give_get_payment_subtotal( $payment_id = 0 ) { |
|
1366 | - $payment = new G_Payment( $payment_id ); |
|
1365 | +function give_get_payment_subtotal($payment_id = 0) { |
|
1366 | + $payment = new G_Payment($payment_id); |
|
1367 | 1367 | |
1368 | 1368 | return $payment->subtotal; |
1369 | 1369 | } |
@@ -1378,10 +1378,10 @@ discard block |
||
1378 | 1378 | * |
1379 | 1379 | * @return mixed array if payment fees found, false otherwise. |
1380 | 1380 | */ |
1381 | -function give_get_payment_fees( $payment_id = 0, $type = 'all' ) { |
|
1382 | - $payment = new Give_Payment( $payment_id ); |
|
1381 | +function give_get_payment_fees($payment_id = 0, $type = 'all') { |
|
1382 | + $payment = new Give_Payment($payment_id); |
|
1383 | 1383 | |
1384 | - return $payment->get_fees( $type ); |
|
1384 | + return $payment->get_fees($type); |
|
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | /** |
@@ -1393,8 +1393,8 @@ discard block |
||
1393 | 1393 | * |
1394 | 1394 | * @return string The donation ID. |
1395 | 1395 | */ |
1396 | -function give_get_payment_transaction_id( $payment_id = 0 ) { |
|
1397 | - $payment = new Give_Payment( $payment_id ); |
|
1396 | +function give_get_payment_transaction_id($payment_id = 0) { |
|
1397 | + $payment = new Give_Payment($payment_id); |
|
1398 | 1398 | |
1399 | 1399 | return $payment->transaction_id; |
1400 | 1400 | } |
@@ -1409,15 +1409,15 @@ discard block |
||
1409 | 1409 | * |
1410 | 1410 | * @return bool|mixed |
1411 | 1411 | */ |
1412 | -function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) { |
|
1412 | +function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') { |
|
1413 | 1413 | |
1414 | - if ( empty( $payment_id ) || empty( $transaction_id ) ) { |
|
1414 | + if (empty($payment_id) || empty($transaction_id)) { |
|
1415 | 1415 | return false; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - $transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
1418 | + $transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id); |
|
1419 | 1419 | |
1420 | - return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id ); |
|
1420 | + return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id); |
|
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | /** |
@@ -1430,12 +1430,12 @@ discard block |
||
1430 | 1430 | * |
1431 | 1431 | * @return int $purchase Donation ID. |
1432 | 1432 | */ |
1433 | -function give_get_purchase_id_by_key( $key ) { |
|
1433 | +function give_get_purchase_id_by_key($key) { |
|
1434 | 1434 | global $wpdb; |
1435 | 1435 | |
1436 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1436 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key)); |
|
1437 | 1437 | |
1438 | - if ( $purchase != null ) { |
|
1438 | + if ($purchase != null) { |
|
1439 | 1439 | return $purchase; |
1440 | 1440 | } |
1441 | 1441 | |
@@ -1453,12 +1453,12 @@ discard block |
||
1453 | 1453 | * |
1454 | 1454 | * @return int $purchase Donation ID. |
1455 | 1455 | */ |
1456 | -function give_get_purchase_id_by_transaction_id( $key ) { |
|
1456 | +function give_get_purchase_id_by_transaction_id($key) { |
|
1457 | 1457 | global $wpdb; |
1458 | 1458 | |
1459 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
1459 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
1460 | 1460 | |
1461 | - if ( $purchase != null ) { |
|
1461 | + if ($purchase != null) { |
|
1462 | 1462 | return $purchase; |
1463 | 1463 | } |
1464 | 1464 | |
@@ -1475,19 +1475,19 @@ discard block |
||
1475 | 1475 | * |
1476 | 1476 | * @return array $notes Donation Notes |
1477 | 1477 | */ |
1478 | -function give_get_payment_notes( $payment_id = 0, $search = '' ) { |
|
1478 | +function give_get_payment_notes($payment_id = 0, $search = '') { |
|
1479 | 1479 | |
1480 | - if ( empty( $payment_id ) && empty( $search ) ) { |
|
1480 | + if (empty($payment_id) && empty($search)) { |
|
1481 | 1481 | return false; |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1485 | - remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10 ); |
|
1484 | + remove_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1485 | + remove_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10); |
|
1486 | 1486 | |
1487 | - $notes = get_comments( array( 'post_id' => $payment_id, 'order' => 'ASC', 'search' => $search ) ); |
|
1487 | + $notes = get_comments(array('post_id' => $payment_id, 'order' => 'ASC', 'search' => $search)); |
|
1488 | 1488 | |
1489 | - add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1490 | - add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
1489 | + add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1490 | + add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
1491 | 1491 | |
1492 | 1492 | return $notes; |
1493 | 1493 | } |
@@ -1503,8 +1503,8 @@ discard block |
||
1503 | 1503 | * |
1504 | 1504 | * @return int The new note ID |
1505 | 1505 | */ |
1506 | -function give_insert_payment_note( $payment_id = 0, $note = '' ) { |
|
1507 | - if ( empty( $payment_id ) ) { |
|
1506 | +function give_insert_payment_note($payment_id = 0, $note = '') { |
|
1507 | + if (empty($payment_id)) { |
|
1508 | 1508 | return false; |
1509 | 1509 | } |
1510 | 1510 | |
@@ -1516,14 +1516,14 @@ discard block |
||
1516 | 1516 | * @param int $payment_id Payment ID. |
1517 | 1517 | * @param string $note The note. |
1518 | 1518 | */ |
1519 | - do_action( 'give_pre_insert_payment_note', $payment_id, $note ); |
|
1519 | + do_action('give_pre_insert_payment_note', $payment_id, $note); |
|
1520 | 1520 | |
1521 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
1521 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
1522 | 1522 | 'comment_post_ID' => $payment_id, |
1523 | 1523 | 'comment_content' => $note, |
1524 | 1524 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
1525 | - 'comment_date' => current_time( 'mysql' ), |
|
1526 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
1525 | + 'comment_date' => current_time('mysql'), |
|
1526 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
1527 | 1527 | 'comment_approved' => 1, |
1528 | 1528 | 'comment_parent' => 0, |
1529 | 1529 | 'comment_author' => '', |
@@ -1532,7 +1532,7 @@ discard block |
||
1532 | 1532 | 'comment_author_email' => '', |
1533 | 1533 | 'comment_type' => 'give_payment_note', |
1534 | 1534 | |
1535 | - ) ) ); |
|
1535 | + ))); |
|
1536 | 1536 | |
1537 | 1537 | /** |
1538 | 1538 | * Fires after payment note inserted. |
@@ -1543,7 +1543,7 @@ discard block |
||
1543 | 1543 | * @param int $payment_id Payment ID. |
1544 | 1544 | * @param string $note The note. |
1545 | 1545 | */ |
1546 | - do_action( 'give_insert_payment_note', $note_id, $payment_id, $note ); |
|
1546 | + do_action('give_insert_payment_note', $note_id, $payment_id, $note); |
|
1547 | 1547 | |
1548 | 1548 | return $note_id; |
1549 | 1549 | } |
@@ -1558,8 +1558,8 @@ discard block |
||
1558 | 1558 | * |
1559 | 1559 | * @return bool True on success, false otherwise. |
1560 | 1560 | */ |
1561 | -function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) { |
|
1562 | - if ( empty( $comment_id ) ) { |
|
1561 | +function give_delete_payment_note($comment_id = 0, $payment_id = 0) { |
|
1562 | + if (empty($comment_id)) { |
|
1563 | 1563 | return false; |
1564 | 1564 | } |
1565 | 1565 | |
@@ -1571,9 +1571,9 @@ discard block |
||
1571 | 1571 | * @param int $comment_id Note ID. |
1572 | 1572 | * @param int $payment_id Payment ID. |
1573 | 1573 | */ |
1574 | - do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id ); |
|
1574 | + do_action('give_pre_delete_payment_note', $comment_id, $payment_id); |
|
1575 | 1575 | |
1576 | - $ret = wp_delete_comment( $comment_id, true ); |
|
1576 | + $ret = wp_delete_comment($comment_id, true); |
|
1577 | 1577 | |
1578 | 1578 | /** |
1579 | 1579 | * Fires after donation note deleted. |
@@ -1583,7 +1583,7 @@ discard block |
||
1583 | 1583 | * @param int $comment_id Note ID. |
1584 | 1584 | * @param int $payment_id Payment ID. |
1585 | 1585 | */ |
1586 | - do_action( 'give_post_delete_payment_note', $comment_id, $payment_id ); |
|
1586 | + do_action('give_post_delete_payment_note', $comment_id, $payment_id); |
|
1587 | 1587 | |
1588 | 1588 | return $ret; |
1589 | 1589 | } |
@@ -1598,34 +1598,34 @@ discard block |
||
1598 | 1598 | * |
1599 | 1599 | * @return string |
1600 | 1600 | */ |
1601 | -function give_get_payment_note_html( $note, $payment_id = 0 ) { |
|
1601 | +function give_get_payment_note_html($note, $payment_id = 0) { |
|
1602 | 1602 | |
1603 | - if ( is_numeric( $note ) ) { |
|
1604 | - $note = get_comment( $note ); |
|
1603 | + if (is_numeric($note)) { |
|
1604 | + $note = get_comment($note); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | - if ( ! empty( $note->user_id ) ) { |
|
1608 | - $user = get_userdata( $note->user_id ); |
|
1607 | + if ( ! empty($note->user_id)) { |
|
1608 | + $user = get_userdata($note->user_id); |
|
1609 | 1609 | $user = $user->display_name; |
1610 | 1610 | } else { |
1611 | - $user = esc_html__( 'System', 'give' ); |
|
1611 | + $user = esc_html__('System', 'give'); |
|
1612 | 1612 | } |
1613 | 1613 | |
1614 | - $date_format = give_date_format() . ', ' . get_option( 'time_format' ); |
|
1614 | + $date_format = give_date_format().', '.get_option('time_format'); |
|
1615 | 1615 | |
1616 | - $delete_note_url = wp_nonce_url( add_query_arg( array( |
|
1616 | + $delete_note_url = wp_nonce_url(add_query_arg(array( |
|
1617 | 1617 | 'give-action' => 'delete_payment_note', |
1618 | 1618 | 'note_id' => $note->comment_ID, |
1619 | 1619 | 'payment_id' => $payment_id, |
1620 | - ) ), |
|
1621 | - 'give_delete_payment_note_' . $note->comment_ID |
|
1620 | + )), |
|
1621 | + 'give_delete_payment_note_'.$note->comment_ID |
|
1622 | 1622 | ); |
1623 | 1623 | |
1624 | - $note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">'; |
|
1624 | + $note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">'; |
|
1625 | 1625 | $note_html .= '<p>'; |
1626 | - $note_html .= '<strong>' . $user . '</strong> – <span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>'; |
|
1626 | + $note_html .= '<strong>'.$user.'</strong> – <span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>'; |
|
1627 | 1627 | $note_html .= $note->comment_content; |
1628 | - $note_html .= ' – <a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" aria-label="' . esc_attr__( 'Delete this donation note.', 'give' ) . '">' . esc_html__( 'Delete', 'give' ) . '</a>'; |
|
1628 | + $note_html .= ' – <a href="'.esc_url($delete_note_url).'" class="give-delete-payment-note" data-note-id="'.absint($note->comment_ID).'" data-payment-id="'.absint($payment_id).'" aria-label="'.esc_attr__('Delete this donation note.', 'give').'">'.esc_html__('Delete', 'give').'</a>'; |
|
1629 | 1629 | $note_html .= '</p>'; |
1630 | 1630 | $note_html .= '</div>'; |
1631 | 1631 | |
@@ -1643,18 +1643,18 @@ discard block |
||
1643 | 1643 | * |
1644 | 1644 | * @return void |
1645 | 1645 | */ |
1646 | -function give_hide_payment_notes( $query ) { |
|
1647 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '>=' ) ) { |
|
1648 | - $types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array(); |
|
1649 | - if ( ! is_array( $types ) ) { |
|
1650 | - $types = array( $types ); |
|
1646 | +function give_hide_payment_notes($query) { |
|
1647 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '>=')) { |
|
1648 | + $types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array(); |
|
1649 | + if ( ! is_array($types)) { |
|
1650 | + $types = array($types); |
|
1651 | 1651 | } |
1652 | 1652 | $types[] = 'give_payment_note'; |
1653 | 1653 | $query->query_vars['type__not_in'] = $types; |
1654 | 1654 | } |
1655 | 1655 | } |
1656 | 1656 | |
1657 | -add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1657 | +add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1658 | 1658 | |
1659 | 1659 | /** |
1660 | 1660 | * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets |
@@ -1666,15 +1666,15 @@ discard block |
||
1666 | 1666 | * |
1667 | 1667 | * @return array $clauses Updated comment clauses. |
1668 | 1668 | */ |
1669 | -function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) { |
|
1670 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '<' ) ) { |
|
1669 | +function give_hide_payment_notes_pre_41($clauses, $wp_comment_query) { |
|
1670 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '<')) { |
|
1671 | 1671 | $clauses['where'] .= ' AND comment_type != "give_payment_note"'; |
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | return $clauses; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | -add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
1677 | +add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
1678 | 1678 | |
1679 | 1679 | |
1680 | 1680 | /** |
@@ -1687,15 +1687,15 @@ discard block |
||
1687 | 1687 | * |
1688 | 1688 | * @return string $where |
1689 | 1689 | */ |
1690 | -function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) { |
|
1690 | +function give_hide_payment_notes_from_feeds($where, $wp_comment_query) { |
|
1691 | 1691 | global $wpdb; |
1692 | 1692 | |
1693 | - $where .= $wpdb->prepare( ' AND comment_type != %s', 'give_payment_note' ); |
|
1693 | + $where .= $wpdb->prepare(' AND comment_type != %s', 'give_payment_note'); |
|
1694 | 1694 | |
1695 | 1695 | return $where; |
1696 | 1696 | } |
1697 | 1697 | |
1698 | -add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 ); |
|
1698 | +add_filter('comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2); |
|
1699 | 1699 | |
1700 | 1700 | |
1701 | 1701 | /** |
@@ -1709,32 +1709,32 @@ discard block |
||
1709 | 1709 | * |
1710 | 1710 | * @return array Array of comment counts. |
1711 | 1711 | */ |
1712 | -function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) { |
|
1712 | +function give_remove_payment_notes_in_comment_counts($stats, $post_id) { |
|
1713 | 1713 | global $wpdb, $pagenow; |
1714 | 1714 | |
1715 | - if ( 'index.php' != $pagenow ) { |
|
1715 | + if ('index.php' != $pagenow) { |
|
1716 | 1716 | return $stats; |
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 | $post_id = (int) $post_id; |
1720 | 1720 | |
1721 | - if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) { |
|
1721 | + if (apply_filters('give_count_payment_notes_in_comments', false)) { |
|
1722 | 1722 | return $stats; |
1723 | 1723 | } |
1724 | 1724 | |
1725 | - $stats = wp_cache_get( "comments-{$post_id}", 'counts' ); |
|
1725 | + $stats = wp_cache_get("comments-{$post_id}", 'counts'); |
|
1726 | 1726 | |
1727 | - if ( false !== $stats ) { |
|
1727 | + if (false !== $stats) { |
|
1728 | 1728 | return $stats; |
1729 | 1729 | } |
1730 | 1730 | |
1731 | 1731 | $where = 'WHERE comment_type != "give_payment_note"'; |
1732 | 1732 | |
1733 | - if ( $post_id > 0 ) { |
|
1734 | - $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); |
|
1733 | + if ($post_id > 0) { |
|
1734 | + $where .= $wpdb->prepare(' AND comment_post_ID = %d', $post_id); |
|
1735 | 1735 | } |
1736 | 1736 | |
1737 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
1737 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
1738 | 1738 | |
1739 | 1739 | $total = 0; |
1740 | 1740 | $approved = array( |
@@ -1744,30 +1744,30 @@ discard block |
||
1744 | 1744 | 'trash' => 'trash', |
1745 | 1745 | 'post-trashed' => 'post-trashed', |
1746 | 1746 | ); |
1747 | - foreach ( (array) $count as $row ) { |
|
1747 | + foreach ((array) $count as $row) { |
|
1748 | 1748 | // Don't count post-trashed toward totals. |
1749 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
1749 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { |
|
1750 | 1750 | $total += $row['num_comments']; |
1751 | 1751 | } |
1752 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
1753 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
1752 | + if (isset($approved[$row['comment_approved']])) { |
|
1753 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
1754 | 1754 | } |
1755 | 1755 | } |
1756 | 1756 | |
1757 | 1757 | $stats['total_comments'] = $total; |
1758 | - foreach ( $approved as $key ) { |
|
1759 | - if ( empty( $stats[ $key ] ) ) { |
|
1760 | - $stats[ $key ] = 0; |
|
1758 | + foreach ($approved as $key) { |
|
1759 | + if (empty($stats[$key])) { |
|
1760 | + $stats[$key] = 0; |
|
1761 | 1761 | } |
1762 | 1762 | } |
1763 | 1763 | |
1764 | 1764 | $stats = (object) $stats; |
1765 | - wp_cache_set( "comments-{$post_id}", $stats, 'counts' ); |
|
1765 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
1766 | 1766 | |
1767 | 1767 | return $stats; |
1768 | 1768 | } |
1769 | 1769 | |
1770 | -add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 ); |
|
1770 | +add_filter('wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2); |
|
1771 | 1771 | |
1772 | 1772 | |
1773 | 1773 | /** |
@@ -1780,9 +1780,9 @@ discard block |
||
1780 | 1780 | * |
1781 | 1781 | * @return string $where Modified where clause. |
1782 | 1782 | */ |
1783 | -function give_filter_where_older_than_week( $where = '' ) { |
|
1783 | +function give_filter_where_older_than_week($where = '') { |
|
1784 | 1784 | // Payments older than one week. |
1785 | - $start = date( 'Y-m-d', strtotime( '-7 days' ) ); |
|
1785 | + $start = date('Y-m-d', strtotime('-7 days')); |
|
1786 | 1786 | $where .= " AND post_date <= '{$start}'"; |
1787 | 1787 | |
1788 | 1788 | return $where; |
@@ -1802,38 +1802,38 @@ discard block |
||
1802 | 1802 | * |
1803 | 1803 | * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title. |
1804 | 1804 | */ |
1805 | -function give_get_payment_form_title( $payment_meta, $only_level = false, $separator = '' ) { |
|
1805 | +function give_get_payment_form_title($payment_meta, $only_level = false, $separator = '') { |
|
1806 | 1806 | |
1807 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0; |
|
1808 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1809 | - $form_title = isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : ''; |
|
1807 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0; |
|
1808 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1809 | + $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : ''; |
|
1810 | 1810 | |
1811 | - if ( $only_level == true ) { |
|
1811 | + if ($only_level == true) { |
|
1812 | 1812 | $form_title = ''; |
1813 | 1813 | } |
1814 | 1814 | |
1815 | 1815 | //If multi-level, append to the form title. |
1816 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1816 | + if (give_has_variable_prices($form_id)) { |
|
1817 | 1817 | |
1818 | 1818 | //Only add separator if there is a form title. |
1819 | - if ( ! empty( $form_title ) ) { |
|
1820 | - $form_title .= ' ' . $separator . ' '; |
|
1819 | + if ( ! empty($form_title)) { |
|
1820 | + $form_title .= ' '.$separator.' '; |
|
1821 | 1821 | } |
1822 | 1822 | |
1823 | 1823 | $form_title .= '<span class="donation-level-text-wrap">'; |
1824 | 1824 | |
1825 | - if ( $price_id == 'custom' ) { |
|
1826 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
1827 | - $form_title .= ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ); |
|
1825 | + if ($price_id == 'custom') { |
|
1826 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
1827 | + $form_title .= ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'); |
|
1828 | 1828 | } else { |
1829 | - $form_title .= give_get_price_option_name( $form_id, $price_id ); |
|
1829 | + $form_title .= give_get_price_option_name($form_id, $price_id); |
|
1830 | 1830 | } |
1831 | 1831 | |
1832 | 1832 | $form_title .= '</span>'; |
1833 | 1833 | |
1834 | 1834 | } |
1835 | 1835 | |
1836 | - return apply_filters( 'give_get_payment_form_title', $form_title, $payment_meta ); |
|
1836 | + return apply_filters('give_get_payment_form_title', $form_title, $payment_meta); |
|
1837 | 1837 | |
1838 | 1838 | } |
1839 | 1839 | |
@@ -1847,20 +1847,20 @@ discard block |
||
1847 | 1847 | * |
1848 | 1848 | * @return string $price_id |
1849 | 1849 | */ |
1850 | -function give_get_price_id( $form_id, $price ) { |
|
1850 | +function give_get_price_id($form_id, $price) { |
|
1851 | 1851 | |
1852 | 1852 | $price_id = 0; |
1853 | 1853 | |
1854 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1854 | + if (give_has_variable_prices($form_id)) { |
|
1855 | 1855 | |
1856 | - $levels = maybe_unserialize( get_post_meta( $form_id, '_give_donation_levels', true ) ); |
|
1856 | + $levels = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true)); |
|
1857 | 1857 | |
1858 | - foreach ( $levels as $level ) { |
|
1858 | + foreach ($levels as $level) { |
|
1859 | 1859 | |
1860 | - $level_amount = (float) give_sanitize_amount( $level['_give_amount'] ); |
|
1860 | + $level_amount = (float) give_sanitize_amount($level['_give_amount']); |
|
1861 | 1861 | |
1862 | 1862 | // Check that this indeed the recurring price. |
1863 | - if ( $level_amount == $price ) { |
|
1863 | + if ($level_amount == $price) { |
|
1864 | 1864 | |
1865 | 1865 | $price_id = $level['_give_id']['level_id']; |
1866 | 1866 | |
@@ -1885,10 +1885,10 @@ discard block |
||
1885 | 1885 | * |
1886 | 1886 | * @return string|void |
1887 | 1887 | */ |
1888 | -function give_get_form_dropdown( $args = array(), $echo = false ) { |
|
1889 | - $form_dropdown_html = Give()->html->forms_dropdown( $args ); |
|
1888 | +function give_get_form_dropdown($args = array(), $echo = false) { |
|
1889 | + $form_dropdown_html = Give()->html->forms_dropdown($args); |
|
1890 | 1890 | |
1891 | - if ( ! $echo ) { |
|
1891 | + if ( ! $echo) { |
|
1892 | 1892 | return $form_dropdown_html; |
1893 | 1893 | } |
1894 | 1894 | |
@@ -1905,17 +1905,17 @@ discard block |
||
1905 | 1905 | * |
1906 | 1906 | * @return string|bool |
1907 | 1907 | */ |
1908 | -function give_get_form_variable_price_dropdown( $args = array(), $echo = false ) { |
|
1908 | +function give_get_form_variable_price_dropdown($args = array(), $echo = false) { |
|
1909 | 1909 | |
1910 | 1910 | // Check for give form id. |
1911 | - if ( empty( $args['id'] ) ) { |
|
1911 | + if (empty($args['id'])) { |
|
1912 | 1912 | return false; |
1913 | 1913 | } |
1914 | 1914 | |
1915 | - $form = new Give_Donate_Form( $args['id'] ); |
|
1915 | + $form = new Give_Donate_Form($args['id']); |
|
1916 | 1916 | |
1917 | 1917 | // Check if form has variable prices or not. |
1918 | - if ( ! $form->ID || ! $form->has_variable_prices() ) { |
|
1918 | + if ( ! $form->ID || ! $form->has_variable_prices()) { |
|
1919 | 1919 | return false; |
1920 | 1920 | } |
1921 | 1921 | |
@@ -1923,22 +1923,22 @@ discard block |
||
1923 | 1923 | $variable_price_options = array(); |
1924 | 1924 | |
1925 | 1925 | // Check if multi donation form support custom donation or not. |
1926 | - if ( $form->is_custom_price_mode() ) { |
|
1927 | - $variable_price_options['custom'] = _x( 'Custom', 'custom donation dropdown item', 'give' ); |
|
1926 | + if ($form->is_custom_price_mode()) { |
|
1927 | + $variable_price_options['custom'] = _x('Custom', 'custom donation dropdown item', 'give'); |
|
1928 | 1928 | } |
1929 | 1929 | |
1930 | 1930 | // Get variable price and ID from variable price array. |
1931 | - foreach ( $variable_prices as $variable_price ) { |
|
1932 | - $variable_price_options[ $variable_price['_give_id']['level_id'] ] = ! empty( $variable_price['_give_text'] ) ? $variable_price['_give_text'] : give_currency_filter( give_format_amount( $variable_price['_give_amount'] ) ); |
|
1931 | + foreach ($variable_prices as $variable_price) { |
|
1932 | + $variable_price_options[$variable_price['_give_id']['level_id']] = ! empty($variable_price['_give_text']) ? $variable_price['_give_text'] : give_currency_filter(give_format_amount($variable_price['_give_amount'])); |
|
1933 | 1933 | } |
1934 | 1934 | |
1935 | 1935 | // Update options. |
1936 | - $args = array_merge( $args, array( 'options' => $variable_price_options ) ); |
|
1936 | + $args = array_merge($args, array('options' => $variable_price_options)); |
|
1937 | 1937 | |
1938 | 1938 | // Generate select html. |
1939 | - $form_dropdown_html = Give()->html->select( $args ); |
|
1939 | + $form_dropdown_html = Give()->html->select($args); |
|
1940 | 1940 | |
1941 | - if ( ! $echo ) { |
|
1941 | + if ( ! $echo) { |
|
1942 | 1942 | return $form_dropdown_html; |
1943 | 1943 | } |
1944 | 1944 | |
@@ -1957,14 +1957,14 @@ discard block |
||
1957 | 1957 | * |
1958 | 1958 | * @return string |
1959 | 1959 | */ |
1960 | -function give_get_payment_meta_price_id( $payment_meta ) { |
|
1960 | +function give_get_payment_meta_price_id($payment_meta) { |
|
1961 | 1961 | |
1962 | - if(isset($payment_meta['give_price_id'])) { |
|
1963 | - $price_id = $payment_meta['give_price_id']; |
|
1964 | - } elseif(isset($payment_meta['price_id'])) { |
|
1965 | - $price_id = $payment_meta['price_id']; |
|
1962 | + if (isset($payment_meta['give_price_id'])) { |
|
1963 | + $price_id = $payment_meta['give_price_id']; |
|
1964 | + } elseif (isset($payment_meta['price_id'])) { |
|
1965 | + $price_id = $payment_meta['price_id']; |
|
1966 | 1966 | } else { |
1967 | - $price_id = give_get_price_id( $payment_meta['give_form_id'], $payment_meta['price'] ); |
|
1967 | + $price_id = give_get_price_id($payment_meta['give_form_id'], $payment_meta['price']); |
|
1968 | 1968 | } |
1969 | 1969 | |
1970 | 1970 | return apply_filters('give_get_payment_meta_price_id', $price_id); |
@@ -10,7 +10,7 @@ discard block |
||
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 | |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return void |
30 | 30 | */ |
31 | -function give_complete_purchase( $payment_id, $new_status, $old_status ) { |
|
31 | +function give_complete_purchase($payment_id, $new_status, $old_status) { |
|
32 | 32 | |
33 | 33 | // Make sure that payments are only completed once. |
34 | - if ( $old_status == 'publish' || $old_status == 'complete' ) { |
|
34 | + if ($old_status == 'publish' || $old_status == 'complete') { |
|
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | 38 | // Make sure the payment completion is only processed when new status is complete. |
39 | - if ( $new_status != 'publish' && $new_status != 'complete' ) { |
|
39 | + if ($new_status != 'publish' && $new_status != 'complete') { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - $payment = new Give_Payment( $payment_id ); |
|
43 | + $payment = new Give_Payment($payment_id); |
|
44 | 44 | |
45 | - $creation_date = get_post_field( 'post_date', $payment_id, 'raw' ); |
|
45 | + $creation_date = get_post_field('post_date', $payment_id, 'raw'); |
|
46 | 46 | $payment_meta = $payment->payment_meta; |
47 | 47 | $completed_date = $payment->completed_date; |
48 | 48 | $user_info = $payment->user_info; |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param int $payment_id The ID of the payment. |
60 | 60 | */ |
61 | - do_action( 'give_pre_complete_purchase', $payment_id ); |
|
61 | + do_action('give_pre_complete_purchase', $payment_id); |
|
62 | 62 | |
63 | 63 | // Ensure these actions only run once, ever. |
64 | - if ( empty( $completed_date ) ) { |
|
64 | + if (empty($completed_date)) { |
|
65 | 65 | |
66 | - give_record_sale_in_log( $form_id, $payment_id, $price_id, $creation_date ); |
|
66 | + give_record_sale_in_log($form_id, $payment_id, $price_id, $creation_date); |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Fires after logging donation record. |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | * @param int $payment_id The ID number of the payment. |
75 | 75 | * @param array $payment_meta The payment meta. |
76 | 76 | */ |
77 | - do_action( 'give_complete_form_donation', $form_id, $payment_id, $payment_meta ); |
|
77 | + do_action('give_complete_form_donation', $form_id, $payment_id, $payment_meta); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Increase the earnings for this form ID. |
82 | - give_increase_earnings( $form_id, $amount ); |
|
83 | - give_increase_purchase_count( $form_id ); |
|
82 | + give_increase_earnings($form_id, $amount); |
|
83 | + give_increase_purchase_count($form_id); |
|
84 | 84 | |
85 | 85 | // @todo: Refresh only range related stat cache |
86 | 86 | give_delete_donation_stats(); |
87 | 87 | |
88 | 88 | // Increase the donor's donation stats. |
89 | - $customer = new Give_Customer( $customer_id ); |
|
89 | + $customer = new Give_Customer($customer_id); |
|
90 | 90 | $customer->increase_purchase_count(); |
91 | - $customer->increase_value( $amount ); |
|
91 | + $customer->increase_value($amount); |
|
92 | 92 | |
93 | - give_increase_total_earnings( $amount ); |
|
93 | + give_increase_total_earnings($amount); |
|
94 | 94 | |
95 | 95 | // Ensure this action only runs once ever. |
96 | - if ( empty( $completed_date ) ) { |
|
96 | + if (empty($completed_date)) { |
|
97 | 97 | |
98 | 98 | // Save the completed date. |
99 | - $payment->completed_date = current_time( 'mysql' ); |
|
99 | + $payment->completed_date = current_time('mysql'); |
|
100 | 100 | $payment->save(); |
101 | 101 | |
102 | 102 | /** |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param int $payment_id The ID of the payment. |
108 | 108 | */ |
109 | - do_action( 'give_complete_donation', $payment_id ); |
|
109 | + do_action('give_complete_donation', $payment_id); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | } |
113 | 113 | |
114 | -add_action( 'give_update_payment_status', 'give_complete_purchase', 100, 3 ); |
|
114 | +add_action('give_update_payment_status', 'give_complete_purchase', 100, 3); |
|
115 | 115 | |
116 | 116 | |
117 | 117 | /** |
@@ -125,24 +125,24 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return void |
127 | 127 | */ |
128 | -function give_record_status_change( $payment_id, $new_status, $old_status ) { |
|
128 | +function give_record_status_change($payment_id, $new_status, $old_status) { |
|
129 | 129 | |
130 | 130 | // Get the list of statuses so that status in the payment note can be translated. |
131 | 131 | $stati = give_get_payment_statuses(); |
132 | - $old_status = isset( $stati[ $old_status ] ) ? $stati[ $old_status ] : $old_status; |
|
133 | - $new_status = isset( $stati[ $new_status ] ) ? $stati[ $new_status ] : $new_status; |
|
132 | + $old_status = isset($stati[$old_status]) ? $stati[$old_status] : $old_status; |
|
133 | + $new_status = isset($stati[$new_status]) ? $stati[$new_status] : $new_status; |
|
134 | 134 | |
135 | 135 | // translators: 1: old status 2: new status. |
136 | 136 | $status_change = sprintf( |
137 | - esc_html__( 'Status changed from %1$s to %2$s.', 'give' ), |
|
137 | + esc_html__('Status changed from %1$s to %2$s.', 'give'), |
|
138 | 138 | $old_status, |
139 | 139 | $new_status |
140 | 140 | ); |
141 | 141 | |
142 | - give_insert_payment_note( $payment_id, $status_change ); |
|
142 | + give_insert_payment_note($payment_id, $status_change); |
|
143 | 143 | } |
144 | 144 | |
145 | -add_action( 'give_update_payment_status', 'give_record_status_change', 100, 3 ); |
|
145 | +add_action('give_update_payment_status', 'give_record_status_change', 100, 3); |
|
146 | 146 | |
147 | 147 | |
148 | 148 | /** |
@@ -158,25 +158,25 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return void |
160 | 160 | */ |
161 | -function give_update_old_payments_with_totals( $data ) { |
|
162 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_upgrade_payments_nonce' ) ) { |
|
161 | +function give_update_old_payments_with_totals($data) { |
|
162 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give_upgrade_payments_nonce')) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | - if ( get_option( 'give_payment_totals_upgraded' ) ) { |
|
166 | + if (get_option('give_payment_totals_upgraded')) { |
|
167 | 167 | return; |
168 | 168 | } |
169 | 169 | |
170 | - $payments = give_get_payments( array( |
|
170 | + $payments = give_get_payments(array( |
|
171 | 171 | 'offset' => 0, |
172 | - 'number' => - 1, |
|
172 | + 'number' => -1, |
|
173 | 173 | 'mode' => 'all', |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | |
176 | - if ( $payments ) { |
|
177 | - foreach ( $payments as $payment ) { |
|
176 | + if ($payments) { |
|
177 | + foreach ($payments as $payment) { |
|
178 | 178 | |
179 | - $payment = new Give_Payment( $payment->ID ); |
|
179 | + $payment = new Give_Payment($payment->ID); |
|
180 | 180 | $meta = $payment->get_meta(); |
181 | 181 | |
182 | 182 | $payment->total = $meta['amount']; |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - add_option( 'give_payment_totals_upgraded', 1 ); |
|
188 | + add_option('give_payment_totals_upgraded', 1); |
|
189 | 189 | } |
190 | 190 | |
191 | -add_action( 'give_upgrade_payments', 'give_update_old_payments_with_totals' ); |
|
191 | +add_action('give_upgrade_payments', 'give_update_old_payments_with_totals'); |
|
192 | 192 | |
193 | 193 | /** |
194 | 194 | * Mark Abandoned Donations |
@@ -202,17 +202,17 @@ discard block |
||
202 | 202 | function give_mark_abandoned_donations() { |
203 | 203 | $args = array( |
204 | 204 | 'status' => 'pending', |
205 | - 'number' => - 1, |
|
205 | + 'number' => -1, |
|
206 | 206 | 'output' => 'give_payments', |
207 | 207 | ); |
208 | 208 | |
209 | - add_filter( 'posts_where', 'give_filter_where_older_than_week' ); |
|
209 | + add_filter('posts_where', 'give_filter_where_older_than_week'); |
|
210 | 210 | |
211 | - $payments = give_get_payments( $args ); |
|
211 | + $payments = give_get_payments($args); |
|
212 | 212 | |
213 | - remove_filter( 'posts_where', 'give_filter_where_older_than_week' ); |
|
213 | + remove_filter('posts_where', 'give_filter_where_older_than_week'); |
|
214 | 214 | |
215 | - if ( $payments ) { |
|
215 | + if ($payments) { |
|
216 | 216 | /** |
217 | 217 | * Filter payment gateways: Used to set payment gateways which can be skip while transferring pending payment to abandon. |
218 | 218 | * |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param array $skip_payment_gateways Array of payment gateways |
222 | 222 | */ |
223 | - $skip_payment_gateways = apply_filters( 'give_mark_abandoned_donation_gateways', array( 'offline' ) ); |
|
223 | + $skip_payment_gateways = apply_filters('give_mark_abandoned_donation_gateways', array('offline')); |
|
224 | 224 | |
225 | - foreach ( $payments as $payment ) { |
|
226 | - $gateway = give_get_payment_gateway( $payment ); |
|
225 | + foreach ($payments as $payment) { |
|
226 | + $gateway = give_get_payment_gateway($payment); |
|
227 | 227 | |
228 | 228 | // Skip payment gateways. |
229 | - if ( in_array( $gateway, $skip_payment_gateways ) ) { |
|
229 | + if (in_array($gateway, $skip_payment_gateways)) { |
|
230 | 230 | continue; |
231 | 231 | } |
232 | 232 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | -add_action( 'give_weekly_scheduled_events', 'give_mark_abandoned_donations' ); |
|
239 | +add_action('give_weekly_scheduled_events', 'give_mark_abandoned_donations'); |
|
240 | 240 | |
241 | 241 | |
242 | 242 | /** |
@@ -248,12 +248,12 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return void |
250 | 250 | */ |
251 | -function give_refresh_thismonth_stat_transients( $payment_ID ) { |
|
251 | +function give_refresh_thismonth_stat_transients($payment_ID) { |
|
252 | 252 | // Monthly stats. |
253 | - Give_Cache::delete( Give_Cache::get_key( 'give_estimated_monthly_stats' ) ); |
|
253 | + Give_Cache::delete(Give_Cache::get_key('give_estimated_monthly_stats')); |
|
254 | 254 | |
255 | 255 | // @todo: Refresh only range related stat cache |
256 | 256 | give_delete_donation_stats(); |
257 | 257 | } |
258 | 258 | |
259 | -add_action( 'save_post_give_payment', 'give_refresh_thismonth_stat_transients' ); |
|
259 | +add_action('save_post_give_payment', 'give_refresh_thismonth_stat_transients'); |
@@ -10,7 +10,7 @@ discard block |
||
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 | |
@@ -394,13 +394,13 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @return mixed void|false |
396 | 396 | */ |
397 | - public function __construct( $payment_id = false ) { |
|
397 | + public function __construct($payment_id = false) { |
|
398 | 398 | |
399 | - if ( empty( $payment_id ) ) { |
|
399 | + if (empty($payment_id)) { |
|
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - $this->setup_payment( $payment_id ); |
|
403 | + $this->setup_payment($payment_id); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -413,11 +413,11 @@ discard block |
||
413 | 413 | * |
414 | 414 | * @return mixed The value. |
415 | 415 | */ |
416 | - public function __get( $key ) { |
|
416 | + public function __get($key) { |
|
417 | 417 | |
418 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
418 | + if (method_exists($this, 'get_'.$key)) { |
|
419 | 419 | |
420 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
420 | + $value = call_user_func(array($this, 'get_'.$key)); |
|
421 | 421 | |
422 | 422 | } else { |
423 | 423 | |
@@ -439,18 +439,18 @@ discard block |
||
439 | 439 | * @param string $key The property name |
440 | 440 | * @param mixed $value The value of the property |
441 | 441 | */ |
442 | - public function __set( $key, $value ) { |
|
443 | - $ignore = array( '_ID' ); |
|
442 | + public function __set($key, $value) { |
|
443 | + $ignore = array('_ID'); |
|
444 | 444 | |
445 | - if ( $key === 'status' ) { |
|
445 | + if ($key === 'status') { |
|
446 | 446 | $this->old_status = $this->status; |
447 | 447 | } |
448 | 448 | |
449 | - if ( ! in_array( $key, $ignore ) ) { |
|
450 | - $this->pending[ $key ] = $value; |
|
449 | + if ( ! in_array($key, $ignore)) { |
|
450 | + $this->pending[$key] = $value; |
|
451 | 451 | } |
452 | 452 | |
453 | - if ( '_ID' !== $key ) { |
|
453 | + if ('_ID' !== $key) { |
|
454 | 454 | $this->$key = $value; |
455 | 455 | } |
456 | 456 | } |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @return boolean If the item is set or not |
467 | 467 | */ |
468 | - public function __isset( $name ) { |
|
469 | - if ( property_exists( $this, $name ) ) { |
|
470 | - return false === empty( $this->$name ); |
|
468 | + public function __isset($name) { |
|
469 | + if (property_exists($this, $name)) { |
|
470 | + return false === empty($this->$name); |
|
471 | 471 | } else { |
472 | 472 | return null; |
473 | 473 | } |
@@ -483,20 +483,20 @@ discard block |
||
483 | 483 | * |
484 | 484 | * @return bool If the setup was successful or not |
485 | 485 | */ |
486 | - private function setup_payment( $payment_id ) { |
|
486 | + private function setup_payment($payment_id) { |
|
487 | 487 | $this->pending = array(); |
488 | 488 | |
489 | - if ( empty( $payment_id ) ) { |
|
489 | + if (empty($payment_id)) { |
|
490 | 490 | return false; |
491 | 491 | } |
492 | 492 | |
493 | - $payment = get_post( $payment_id ); |
|
493 | + $payment = get_post($payment_id); |
|
494 | 494 | |
495 | - if ( ! $payment || is_wp_error( $payment ) ) { |
|
495 | + if ( ! $payment || is_wp_error($payment)) { |
|
496 | 496 | return false; |
497 | 497 | } |
498 | 498 | |
499 | - if ( 'give_payment' !== $payment->post_type ) { |
|
499 | + if ('give_payment' !== $payment->post_type) { |
|
500 | 500 | return false; |
501 | 501 | } |
502 | 502 | |
@@ -510,13 +510,13 @@ discard block |
||
510 | 510 | * @param Give_Payment $this Payment object. |
511 | 511 | * @param int $payment_id The ID of the payment. |
512 | 512 | */ |
513 | - do_action( 'give_pre_setup_payment', $this, $payment_id ); |
|
513 | + do_action('give_pre_setup_payment', $this, $payment_id); |
|
514 | 514 | |
515 | 515 | // Primary Identifier. |
516 | - $this->ID = absint( $payment_id ); |
|
516 | + $this->ID = absint($payment_id); |
|
517 | 517 | |
518 | 518 | // Protected ID that can never be changed. |
519 | - $this->_ID = absint( $payment_id ); |
|
519 | + $this->_ID = absint($payment_id); |
|
520 | 520 | |
521 | 521 | // We have a payment, get the generic payment_meta item to reduce calls to it. |
522 | 522 | $this->payment_meta = $this->get_meta(); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | $this->parent_payment = $payment->post_parent; |
532 | 532 | |
533 | 533 | $all_payment_statuses = give_get_payment_statuses(); |
534 | - $this->status_nicename = array_key_exists( $this->status, $all_payment_statuses ) ? $all_payment_statuses[ $this->status ] : ucfirst( $this->status ); |
|
534 | + $this->status_nicename = array_key_exists($this->status, $all_payment_statuses) ? $all_payment_statuses[$this->status] : ucfirst($this->status); |
|
535 | 535 | |
536 | 536 | // Items. |
537 | 537 | $this->fees = $this->setup_fees(); |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param Give_Payment $this Payment object. |
574 | 574 | * @param int $payment_id The ID of the payment. |
575 | 575 | */ |
576 | - do_action( 'give_setup_payment', $this, $payment_id ); |
|
576 | + do_action('give_setup_payment', $this, $payment_id); |
|
577 | 577 | |
578 | 578 | return true; |
579 | 579 | } |
@@ -591,8 +591,8 @@ discard block |
||
591 | 591 | * |
592 | 592 | * @return void |
593 | 593 | */ |
594 | - public function update_payment_setup( $payment_id ) { |
|
595 | - $this->setup_payment( $payment_id ); |
|
594 | + public function update_payment_setup($payment_id) { |
|
595 | + $this->setup_payment($payment_id); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -607,24 +607,24 @@ discard block |
||
607 | 607 | |
608 | 608 | // Construct the payment title. |
609 | 609 | $payment_title = ''; |
610 | - if ( ! empty( $this->first_name ) && ! empty( $this->last_name ) ) { |
|
611 | - $payment_title = $this->first_name . ' ' . $this->last_name; |
|
612 | - } elseif ( ! empty( $this->first_name ) && empty( $this->last_name ) ) { |
|
610 | + if ( ! empty($this->first_name) && ! empty($this->last_name)) { |
|
611 | + $payment_title = $this->first_name.' '.$this->last_name; |
|
612 | + } elseif ( ! empty($this->first_name) && empty($this->last_name)) { |
|
613 | 613 | $payment_title = $this->first_name; |
614 | - } elseif ( ! empty( $this->email ) && is_email( $this->email ) ) { |
|
614 | + } elseif ( ! empty($this->email) && is_email($this->email)) { |
|
615 | 615 | $payment_title = $this->email; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Set Key. |
619 | - if ( empty( $this->key ) ) { |
|
619 | + if (empty($this->key)) { |
|
620 | 620 | |
621 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
622 | - $this->key = strtolower( md5( $this->email . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); // Unique key |
|
621 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
622 | + $this->key = strtolower(md5($this->email.date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); // Unique key |
|
623 | 623 | $this->pending['key'] = $this->key; |
624 | 624 | } |
625 | 625 | |
626 | 626 | // Set IP. |
627 | - if ( empty( $this->ip ) ) { |
|
627 | + if (empty($this->ip)) { |
|
628 | 628 | |
629 | 629 | $this->ip = give_get_ip(); |
630 | 630 | $this->pending['ip'] = $this->ip; |
@@ -651,63 +651,63 @@ discard block |
||
651 | 651 | 'fees' => $this->fees, |
652 | 652 | ); |
653 | 653 | |
654 | - $args = apply_filters( 'give_insert_payment_args', array( |
|
654 | + $args = apply_filters('give_insert_payment_args', array( |
|
655 | 655 | 'post_title' => $payment_title, |
656 | 656 | 'post_status' => $this->status, |
657 | 657 | 'post_type' => 'give_payment', |
658 | - 'post_date' => ! empty( $this->date ) ? $this->date : null, |
|
659 | - 'post_date_gmt' => ! empty( $this->date ) ? get_gmt_from_date( $this->date ) : null, |
|
658 | + 'post_date' => ! empty($this->date) ? $this->date : null, |
|
659 | + 'post_date_gmt' => ! empty($this->date) ? get_gmt_from_date($this->date) : null, |
|
660 | 660 | 'post_parent' => $this->parent_payment, |
661 | - ), $payment_data ); |
|
661 | + ), $payment_data); |
|
662 | 662 | |
663 | 663 | // Create a blank payment |
664 | - $payment_id = wp_insert_post( $args ); |
|
664 | + $payment_id = wp_insert_post($args); |
|
665 | 665 | |
666 | - if ( ! empty( $payment_id ) ) { |
|
666 | + if ( ! empty($payment_id)) { |
|
667 | 667 | |
668 | 668 | $this->ID = $payment_id; |
669 | 669 | $this->_ID = $payment_id; |
670 | 670 | |
671 | 671 | $customer = new stdClass; |
672 | 672 | |
673 | - if ( did_action( 'give_pre_process_donation' ) && is_user_logged_in() ) { |
|
674 | - $customer = new Give_Customer( get_current_user_id(), true ); |
|
673 | + if (did_action('give_pre_process_donation') && is_user_logged_in()) { |
|
674 | + $customer = new Give_Customer(get_current_user_id(), true); |
|
675 | 675 | |
676 | 676 | // Customer is logged in but used a different email to purchase with so assign to their customer record |
677 | - if ( ! empty( $customer->id ) && $this->email != $customer->email ) { |
|
678 | - $customer->add_email( $this->email ); |
|
677 | + if ( ! empty($customer->id) && $this->email != $customer->email) { |
|
678 | + $customer->add_email($this->email); |
|
679 | 679 | } |
680 | 680 | } |
681 | 681 | |
682 | - if ( empty( $customer->id ) ) { |
|
683 | - $customer = new Give_Customer( $this->email ); |
|
682 | + if (empty($customer->id)) { |
|
683 | + $customer = new Give_Customer($this->email); |
|
684 | 684 | } |
685 | 685 | |
686 | - if ( empty( $customer->id ) ) { |
|
686 | + if (empty($customer->id)) { |
|
687 | 687 | |
688 | 688 | $customer_data = array( |
689 | - 'name' => ! is_email( $payment_title ) ? $this->first_name . ' ' . $this->last_name : '', |
|
689 | + 'name' => ! is_email($payment_title) ? $this->first_name.' '.$this->last_name : '', |
|
690 | 690 | 'email' => $this->email, |
691 | 691 | 'user_id' => $this->user_id, |
692 | 692 | ); |
693 | 693 | |
694 | - $customer->create( $customer_data ); |
|
694 | + $customer->create($customer_data); |
|
695 | 695 | |
696 | 696 | } |
697 | 697 | |
698 | 698 | $this->customer_id = $customer->id; |
699 | 699 | $this->pending['customer_id'] = $this->customer_id; |
700 | - $customer->attach_payment( $this->ID, false ); |
|
700 | + $customer->attach_payment($this->ID, false); |
|
701 | 701 | |
702 | - $this->payment_meta = apply_filters( 'give_payment_meta', $this->payment_meta, $payment_data ); |
|
703 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
704 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
705 | - foreach ( $this->fees as $fee ) { |
|
706 | - $this->increase_fees( $fee['amount'] ); |
|
702 | + $this->payment_meta = apply_filters('give_payment_meta', $this->payment_meta, $payment_data); |
|
703 | + if ( ! empty($this->payment_meta['fees'])) { |
|
704 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
705 | + foreach ($this->fees as $fee) { |
|
706 | + $this->increase_fees($fee['amount']); |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | |
710 | - $this->update_meta( '_give_payment_meta', $this->payment_meta ); |
|
710 | + $this->update_meta('_give_payment_meta', $this->payment_meta); |
|
711 | 711 | $this->new = true; |
712 | 712 | } |
713 | 713 | |
@@ -729,11 +729,11 @@ discard block |
||
729 | 729 | $saved = false; |
730 | 730 | |
731 | 731 | // Must have an ID. |
732 | - if ( empty( $this->ID ) ) { |
|
732 | + if (empty($this->ID)) { |
|
733 | 733 | |
734 | 734 | $payment_id = $this->insert_payment(); |
735 | 735 | |
736 | - if ( false === $payment_id ) { |
|
736 | + if (false === $payment_id) { |
|
737 | 737 | $saved = false; |
738 | 738 | } else { |
739 | 739 | $this->ID = $payment_id; |
@@ -741,48 +741,48 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Set ID if not matching. |
744 | - if ( $this->ID !== $this->_ID ) { |
|
744 | + if ($this->ID !== $this->_ID) { |
|
745 | 745 | $this->ID = $this->_ID; |
746 | 746 | } |
747 | 747 | |
748 | 748 | // If we have something pending, let's save it. |
749 | - if ( ! empty( $this->pending ) ) { |
|
749 | + if ( ! empty($this->pending)) { |
|
750 | 750 | |
751 | 751 | $total_increase = 0; |
752 | 752 | $total_decrease = 0; |
753 | 753 | |
754 | - foreach ( $this->pending as $key => $value ) { |
|
754 | + foreach ($this->pending as $key => $value) { |
|
755 | 755 | |
756 | - switch ( $key ) { |
|
756 | + switch ($key) { |
|
757 | 757 | |
758 | 758 | case 'donations': |
759 | 759 | // Update totals for pending donations. |
760 | - foreach ( $this->pending[ $key ] as $item ) { |
|
760 | + foreach ($this->pending[$key] as $item) { |
|
761 | 761 | |
762 | - $quantity = isset( $item['quantity'] ) ? $item['quantity'] : 1; |
|
763 | - $price_id = isset( $item['price_id'] ) ? $item['price_id'] : 0; |
|
762 | + $quantity = isset($item['quantity']) ? $item['quantity'] : 1; |
|
763 | + $price_id = isset($item['price_id']) ? $item['price_id'] : 0; |
|
764 | 764 | |
765 | - switch ( $item['action'] ) { |
|
765 | + switch ($item['action']) { |
|
766 | 766 | |
767 | 767 | case 'add': |
768 | 768 | |
769 | 769 | $price = $item['price']; |
770 | 770 | |
771 | - if ( 'publish' === $this->status || 'complete' === $this->status ) { |
|
771 | + if ('publish' === $this->status || 'complete' === $this->status) { |
|
772 | 772 | |
773 | 773 | // Add sales logs. |
774 | - $log_date = date_i18n( 'Y-m-d G:i:s', current_time( 'timestamp' ) ); |
|
774 | + $log_date = date_i18n('Y-m-d G:i:s', current_time('timestamp')); |
|
775 | 775 | |
776 | 776 | $y = 0; |
777 | - while ( $y < $quantity ) { |
|
777 | + while ($y < $quantity) { |
|
778 | 778 | |
779 | - give_record_sale_in_log( $item['id'], $this->ID, $price_id, $log_date ); |
|
780 | - $y ++; |
|
779 | + give_record_sale_in_log($item['id'], $this->ID, $price_id, $log_date); |
|
780 | + $y++; |
|
781 | 781 | } |
782 | 782 | |
783 | - $form = new Give_Donate_Form( $item['id'] ); |
|
784 | - $form->increase_sales( $quantity ); |
|
785 | - $form->increase_earnings( $price ); |
|
783 | + $form = new Give_Donate_Form($item['id']); |
|
784 | + $form->increase_sales($quantity); |
|
785 | + $form->increase_earnings($price); |
|
786 | 786 | |
787 | 787 | $total_increase += $price; |
788 | 788 | } |
@@ -807,15 +807,15 @@ discard block |
||
807 | 807 | ), |
808 | 808 | ); |
809 | 809 | |
810 | - $found_logs = get_posts( $log_args ); |
|
811 | - foreach ( $found_logs as $log ) { |
|
812 | - wp_delete_post( $log->ID, true ); |
|
810 | + $found_logs = get_posts($log_args); |
|
811 | + foreach ($found_logs as $log) { |
|
812 | + wp_delete_post($log->ID, true); |
|
813 | 813 | } |
814 | 814 | |
815 | - if ( 'publish' === $this->status || 'complete' === $this->status ) { |
|
816 | - $form = new Give_Donate_Form( $item['id'] ); |
|
817 | - $form->decrease_sales( $quantity ); |
|
818 | - $form->decrease_earnings( $item['amount'] ); |
|
815 | + if ('publish' === $this->status || 'complete' === $this->status) { |
|
816 | + $form = new Give_Donate_Form($item['id']); |
|
817 | + $form->decrease_sales($quantity); |
|
818 | + $form->decrease_earnings($item['amount']); |
|
819 | 819 | |
820 | 820 | $total_decrease += $item['amount']; |
821 | 821 | } |
@@ -827,17 +827,17 @@ discard block |
||
827 | 827 | |
828 | 828 | case 'fees': |
829 | 829 | |
830 | - if ( 'publish' !== $this->status && 'complete' !== $this->status ) { |
|
830 | + if ('publish' !== $this->status && 'complete' !== $this->status) { |
|
831 | 831 | break; |
832 | 832 | } |
833 | 833 | |
834 | - if ( empty( $this->pending[ $key ] ) ) { |
|
834 | + if (empty($this->pending[$key])) { |
|
835 | 835 | break; |
836 | 836 | } |
837 | 837 | |
838 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
838 | + foreach ($this->pending[$key] as $fee) { |
|
839 | 839 | |
840 | - switch ( $fee['action'] ) { |
|
840 | + switch ($fee['action']) { |
|
841 | 841 | |
842 | 842 | case 'add': |
843 | 843 | $total_increase += $fee['amount']; |
@@ -853,43 +853,43 @@ discard block |
||
853 | 853 | break; |
854 | 854 | |
855 | 855 | case 'status': |
856 | - $this->update_status( $this->status ); |
|
856 | + $this->update_status($this->status); |
|
857 | 857 | break; |
858 | 858 | |
859 | 859 | case 'gateway': |
860 | - $this->update_meta( '_give_payment_gateway', $this->gateway ); |
|
860 | + $this->update_meta('_give_payment_gateway', $this->gateway); |
|
861 | 861 | break; |
862 | 862 | |
863 | 863 | case 'mode': |
864 | - $this->update_meta( '_give_payment_mode', $this->mode ); |
|
864 | + $this->update_meta('_give_payment_mode', $this->mode); |
|
865 | 865 | break; |
866 | 866 | |
867 | 867 | case 'transaction_id': |
868 | - $this->update_meta( '_give_payment_transaction_id', $this->transaction_id ); |
|
868 | + $this->update_meta('_give_payment_transaction_id', $this->transaction_id); |
|
869 | 869 | break; |
870 | 870 | |
871 | 871 | case 'ip': |
872 | - $this->update_meta( '_give_payment_user_ip', $this->ip ); |
|
872 | + $this->update_meta('_give_payment_user_ip', $this->ip); |
|
873 | 873 | break; |
874 | 874 | |
875 | 875 | case 'customer_id': |
876 | - $this->update_meta( '_give_payment_customer_id', $this->customer_id ); |
|
876 | + $this->update_meta('_give_payment_customer_id', $this->customer_id); |
|
877 | 877 | break; |
878 | 878 | |
879 | 879 | case 'user_id': |
880 | - $this->update_meta( '_give_payment_user_id', $this->user_id ); |
|
880 | + $this->update_meta('_give_payment_user_id', $this->user_id); |
|
881 | 881 | break; |
882 | 882 | |
883 | 883 | case 'form_title': |
884 | - $this->update_meta( '_give_payment_form_title', $this->form_title ); |
|
884 | + $this->update_meta('_give_payment_form_title', $this->form_title); |
|
885 | 885 | break; |
886 | 886 | |
887 | 887 | case 'form_id': |
888 | - $this->update_meta( '_give_payment_form_id', $this->form_id ); |
|
888 | + $this->update_meta('_give_payment_form_id', $this->form_id); |
|
889 | 889 | break; |
890 | 890 | |
891 | 891 | case 'price_id': |
892 | - $this->update_meta( '_give_payment_price_id', $this->price_id ); |
|
892 | + $this->update_meta('_give_payment_price_id', $this->price_id); |
|
893 | 893 | break; |
894 | 894 | |
895 | 895 | case 'first_name': |
@@ -905,15 +905,15 @@ discard block |
||
905 | 905 | break; |
906 | 906 | |
907 | 907 | case 'email': |
908 | - $this->update_meta( '_give_payment_user_email', $this->email ); |
|
908 | + $this->update_meta('_give_payment_user_email', $this->email); |
|
909 | 909 | break; |
910 | 910 | |
911 | 911 | case 'key': |
912 | - $this->update_meta( '_give_payment_purchase_key', $this->key ); |
|
912 | + $this->update_meta('_give_payment_purchase_key', $this->key); |
|
913 | 913 | break; |
914 | 914 | |
915 | 915 | case 'number': |
916 | - $this->update_meta( '_give_payment_number', $this->number ); |
|
916 | + $this->update_meta('_give_payment_number', $this->number); |
|
917 | 917 | break; |
918 | 918 | |
919 | 919 | case 'date': |
@@ -923,11 +923,11 @@ discard block |
||
923 | 923 | 'edit_date' => true, |
924 | 924 | ); |
925 | 925 | |
926 | - wp_update_post( $args ); |
|
926 | + wp_update_post($args); |
|
927 | 927 | break; |
928 | 928 | |
929 | 929 | case 'completed_date': |
930 | - $this->update_meta( '_give_completed_date', $this->completed_date ); |
|
930 | + $this->update_meta('_give_completed_date', $this->completed_date); |
|
931 | 931 | break; |
932 | 932 | |
933 | 933 | case 'parent_payment': |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | 'post_parent' => $this->parent_payment, |
937 | 937 | ); |
938 | 938 | |
939 | - wp_update_post( $args ); |
|
939 | + wp_update_post($args); |
|
940 | 940 | break; |
941 | 941 | |
942 | 942 | default: |
@@ -947,33 +947,33 @@ discard block |
||
947 | 947 | * |
948 | 948 | * @param Give_Payment $this Payment object. |
949 | 949 | */ |
950 | - do_action( 'give_payment_save', $this, $key ); |
|
950 | + do_action('give_payment_save', $this, $key); |
|
951 | 951 | break; |
952 | 952 | } |
953 | 953 | } |
954 | 954 | |
955 | - if ( 'pending' !== $this->status ) { |
|
955 | + if ('pending' !== $this->status) { |
|
956 | 956 | |
957 | - $customer = new Give_Customer( $this->customer_id ); |
|
957 | + $customer = new Give_Customer($this->customer_id); |
|
958 | 958 | |
959 | 959 | $total_change = $total_increase - $total_decrease; |
960 | - if ( $total_change < 0 ) { |
|
960 | + if ($total_change < 0) { |
|
961 | 961 | |
962 | - $total_change = - ( $total_change ); |
|
962 | + $total_change = - ($total_change); |
|
963 | 963 | // Decrease the customer's donation stats. |
964 | - $customer->decrease_value( $total_change ); |
|
965 | - give_decrease_total_earnings( $total_change ); |
|
964 | + $customer->decrease_value($total_change); |
|
965 | + give_decrease_total_earnings($total_change); |
|
966 | 966 | |
967 | - } elseif ( $total_change > 0 ) { |
|
967 | + } elseif ($total_change > 0) { |
|
968 | 968 | |
969 | 969 | // Increase the customer's donation stats. |
970 | - $customer->increase_value( $total_change ); |
|
971 | - give_increase_total_earnings( $total_change ); |
|
970 | + $customer->increase_value($total_change); |
|
971 | + give_increase_total_earnings($total_change); |
|
972 | 972 | |
973 | 973 | } |
974 | 974 | } |
975 | 975 | |
976 | - $this->update_meta( '_give_payment_total', $this->total ); |
|
976 | + $this->update_meta('_give_payment_total', $this->total); |
|
977 | 977 | |
978 | 978 | $new_meta = array( |
979 | 979 | 'form_title' => $this->form_title, |
@@ -985,12 +985,12 @@ discard block |
||
985 | 985 | ); |
986 | 986 | |
987 | 987 | $meta = $this->get_meta(); |
988 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
988 | + $merged_meta = array_merge($meta, $new_meta); |
|
989 | 989 | |
990 | 990 | // Only save the payment meta if it's changed. |
991 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta ) ) ) { |
|
992 | - $updated = $this->update_meta( '_give_payment_meta', $merged_meta ); |
|
993 | - if ( false !== $updated ) { |
|
991 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
992 | + $updated = $this->update_meta('_give_payment_meta', $merged_meta); |
|
993 | + if (false !== $updated) { |
|
994 | 994 | $saved = true; |
995 | 995 | } |
996 | 996 | } |
@@ -999,8 +999,8 @@ discard block |
||
999 | 999 | $saved = true; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - if ( true === $saved ) { |
|
1003 | - $this->setup_payment( $this->ID ); |
|
1002 | + if (true === $saved) { |
|
1003 | + $this->setup_payment($this->ID); |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | return $saved; |
@@ -1018,12 +1018,12 @@ discard block |
||
1018 | 1018 | * |
1019 | 1019 | * @return bool True when successful, false otherwise |
1020 | 1020 | */ |
1021 | - public function add_donation( $form_id = 0, $args = array(), $options = array() ) { |
|
1021 | + public function add_donation($form_id = 0, $args = array(), $options = array()) { |
|
1022 | 1022 | |
1023 | - $donation = new Give_Donate_Form( $form_id ); |
|
1023 | + $donation = new Give_Donate_Form($form_id); |
|
1024 | 1024 | |
1025 | 1025 | // Bail if this post isn't a give donation form. |
1026 | - if ( ! $donation || $donation->post_type !== 'give_forms' ) { |
|
1026 | + if ( ! $donation || $donation->post_type !== 'give_forms') { |
|
1027 | 1027 | return false; |
1028 | 1028 | } |
1029 | 1029 | |
@@ -1034,59 +1034,59 @@ discard block |
||
1034 | 1034 | 'fees' => array(), |
1035 | 1035 | ); |
1036 | 1036 | |
1037 | - $args = wp_parse_args( apply_filters( 'give_payment_add_donation_args', $args, $donation->ID ), $defaults ); |
|
1037 | + $args = wp_parse_args(apply_filters('give_payment_add_donation_args', $args, $donation->ID), $defaults); |
|
1038 | 1038 | |
1039 | 1039 | // Allow overriding the price. |
1040 | - if ( false !== $args['price'] ) { |
|
1040 | + if (false !== $args['price']) { |
|
1041 | 1041 | $item_price = $args['price']; |
1042 | 1042 | } else { |
1043 | 1043 | |
1044 | 1044 | // Deal with variable pricing. |
1045 | - if ( give_has_variable_prices( $donation->ID ) ) { |
|
1046 | - $prices = maybe_unserialize( get_post_meta( $form_id, '_give_donation_levels', true ) ); |
|
1045 | + if (give_has_variable_prices($donation->ID)) { |
|
1046 | + $prices = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true)); |
|
1047 | 1047 | $item_price = ''; |
1048 | 1048 | // Loop through prices. |
1049 | - foreach ( $prices as $price ) { |
|
1049 | + foreach ($prices as $price) { |
|
1050 | 1050 | // Find a match between price_id and level_id. |
1051 | 1051 | // First verify array keys exists THEN make the match. |
1052 | - if ( ( isset( $args['price_id'] ) && isset( $price['_give_id']['level_id'] ) ) |
|
1052 | + if ((isset($args['price_id']) && isset($price['_give_id']['level_id'])) |
|
1053 | 1053 | && $args['price_id'] == $price['_give_id']['level_id'] |
1054 | 1054 | ) { |
1055 | 1055 | $item_price = $price['_give_amount']; |
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | // Fallback to the lowest price point. |
1059 | - if ( $item_price == '' ) { |
|
1060 | - $item_price = give_get_lowest_price_option( $donation->ID ); |
|
1061 | - $args['price_id'] = give_get_lowest_price_id( $donation->ID ); |
|
1059 | + if ($item_price == '') { |
|
1060 | + $item_price = give_get_lowest_price_option($donation->ID); |
|
1061 | + $args['price_id'] = give_get_lowest_price_id($donation->ID); |
|
1062 | 1062 | } |
1063 | 1063 | } else { |
1064 | 1064 | // Simple form price. |
1065 | - $item_price = give_get_form_price( $donation->ID ); |
|
1065 | + $item_price = give_get_form_price($donation->ID); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | // Sanitizing the price here so we don't have a dozen calls later. |
1070 | - $item_price = give_sanitize_amount( $item_price ); |
|
1071 | - $total = round( $item_price, give_currency_decimal_filter() ); |
|
1070 | + $item_price = give_sanitize_amount($item_price); |
|
1071 | + $total = round($item_price, give_currency_decimal_filter()); |
|
1072 | 1072 | |
1073 | 1073 | // Add Options. |
1074 | 1074 | $default_options = array(); |
1075 | - if ( false !== $args['price_id'] ) { |
|
1075 | + if (false !== $args['price_id']) { |
|
1076 | 1076 | $default_options['price_id'] = (int) $args['price_id']; |
1077 | 1077 | } |
1078 | - $options = wp_parse_args( $options, $default_options ); |
|
1078 | + $options = wp_parse_args($options, $default_options); |
|
1079 | 1079 | |
1080 | 1080 | // Do not allow totals to go negative. |
1081 | - if ( $total < 0 ) { |
|
1081 | + if ($total < 0) { |
|
1082 | 1082 | $total = 0; |
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | $donation = array( |
1086 | 1086 | 'name' => $donation->post_title, |
1087 | 1087 | 'id' => $donation->ID, |
1088 | - 'price' => round( $total, give_currency_decimal_filter() ), |
|
1089 | - 'subtotal' => round( $total, give_currency_decimal_filter() ), |
|
1088 | + 'price' => round($total, give_currency_decimal_filter()), |
|
1089 | + 'subtotal' => round($total, give_currency_decimal_filter()), |
|
1090 | 1090 | 'fees' => $args['fees'], |
1091 | 1091 | 'price_id' => $args['price_id'], |
1092 | 1092 | 'action' => 'add', |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | |
1096 | 1096 | $this->pending['donations'][] = $donation; |
1097 | 1097 | |
1098 | - $this->increase_subtotal( $total ); |
|
1098 | + $this->increase_subtotal($total); |
|
1099 | 1099 | |
1100 | 1100 | return true; |
1101 | 1101 | |
@@ -1112,7 +1112,7 @@ discard block |
||
1112 | 1112 | * |
1113 | 1113 | * @return bool If the item was removed or not |
1114 | 1114 | */ |
1115 | - public function remove_donation( $form_id, $args = array() ) { |
|
1115 | + public function remove_donation($form_id, $args = array()) { |
|
1116 | 1116 | |
1117 | 1117 | // Set some defaults. |
1118 | 1118 | $defaults = array( |
@@ -1120,12 +1120,12 @@ discard block |
||
1120 | 1120 | 'price' => false, |
1121 | 1121 | 'price_id' => false, |
1122 | 1122 | ); |
1123 | - $args = wp_parse_args( $args, $defaults ); |
|
1123 | + $args = wp_parse_args($args, $defaults); |
|
1124 | 1124 | |
1125 | - $form = new Give_Donate_Form( $form_id ); |
|
1125 | + $form = new Give_Donate_Form($form_id); |
|
1126 | 1126 | |
1127 | 1127 | // Bail if this post isn't a valid give donation form. |
1128 | - if ( ! $form || $form->post_type !== 'give_forms' ) { |
|
1128 | + if ( ! $form || $form->post_type !== 'give_forms') { |
|
1129 | 1129 | return false; |
1130 | 1130 | } |
1131 | 1131 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | |
1139 | 1139 | $this->pending['donations'][] = $pending_args; |
1140 | 1140 | |
1141 | - $this->decrease_subtotal( $this->total ); |
|
1141 | + $this->decrease_subtotal($this->total); |
|
1142 | 1142 | |
1143 | 1143 | return true; |
1144 | 1144 | } |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | * |
1155 | 1155 | * @return bool If the fee was added |
1156 | 1156 | */ |
1157 | - public function add_fee( $args, $global = true ) { |
|
1157 | + public function add_fee($args, $global = true) { |
|
1158 | 1158 | |
1159 | 1159 | $default_args = array( |
1160 | 1160 | 'label' => '', |
@@ -1164,15 +1164,15 @@ discard block |
||
1164 | 1164 | 'price_id' => 0, |
1165 | 1165 | ); |
1166 | 1166 | |
1167 | - $fee = wp_parse_args( $args, $default_args ); |
|
1167 | + $fee = wp_parse_args($args, $default_args); |
|
1168 | 1168 | $this->fees[] = $fee; |
1169 | 1169 | |
1170 | 1170 | $added_fee = $fee; |
1171 | 1171 | $added_fee['action'] = 'add'; |
1172 | 1172 | $this->pending['fees'][] = $added_fee; |
1173 | - reset( $this->fees ); |
|
1173 | + reset($this->fees); |
|
1174 | 1174 | |
1175 | - $this->increase_fees( $fee['amount'] ); |
|
1175 | + $this->increase_fees($fee['amount']); |
|
1176 | 1176 | |
1177 | 1177 | return true; |
1178 | 1178 | } |
@@ -1187,11 +1187,11 @@ discard block |
||
1187 | 1187 | * |
1188 | 1188 | * @return bool If the fee was removed successfully |
1189 | 1189 | */ |
1190 | - public function remove_fee( $key ) { |
|
1190 | + public function remove_fee($key) { |
|
1191 | 1191 | $removed = false; |
1192 | 1192 | |
1193 | - if ( is_numeric( $key ) ) { |
|
1194 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
1193 | + if (is_numeric($key)) { |
|
1194 | + $removed = $this->remove_fee_by('index', $key); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | return $removed; |
@@ -1210,55 +1210,55 @@ discard block |
||
1210 | 1210 | * |
1211 | 1211 | * @return boolean If the item is removed |
1212 | 1212 | */ |
1213 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
1213 | + public function remove_fee_by($key, $value, $global = false) { |
|
1214 | 1214 | |
1215 | - $allowed_fee_keys = apply_filters( 'give_payment_fee_keys', array( |
|
1215 | + $allowed_fee_keys = apply_filters('give_payment_fee_keys', array( |
|
1216 | 1216 | 'index', |
1217 | 1217 | 'label', |
1218 | 1218 | 'amount', |
1219 | 1219 | 'type', |
1220 | - ) ); |
|
1220 | + )); |
|
1221 | 1221 | |
1222 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
1222 | + if ( ! in_array($key, $allowed_fee_keys)) { |
|
1223 | 1223 | return false; |
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | $removed = false; |
1227 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
1227 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
1228 | 1228 | |
1229 | - $removed_fee = $this->fees[ $value ]; |
|
1229 | + $removed_fee = $this->fees[$value]; |
|
1230 | 1230 | $removed_fee['action'] = 'remove'; |
1231 | 1231 | $this->pending['fees'][] = $removed_fee; |
1232 | 1232 | |
1233 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1233 | + $this->decrease_fees($removed_fee['amount']); |
|
1234 | 1234 | |
1235 | - unset( $this->fees[ $value ] ); |
|
1235 | + unset($this->fees[$value]); |
|
1236 | 1236 | $removed = true; |
1237 | 1237 | |
1238 | - } elseif ( 'index' !== $key ) { |
|
1238 | + } elseif ('index' !== $key) { |
|
1239 | 1239 | |
1240 | - foreach ( $this->fees as $index => $fee ) { |
|
1240 | + foreach ($this->fees as $index => $fee) { |
|
1241 | 1241 | |
1242 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
1242 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
1243 | 1243 | |
1244 | 1244 | $removed_fee = $fee; |
1245 | 1245 | $removed_fee['action'] = 'remove'; |
1246 | 1246 | $this->pending['fees'][] = $removed_fee; |
1247 | 1247 | |
1248 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1248 | + $this->decrease_fees($removed_fee['amount']); |
|
1249 | 1249 | |
1250 | - unset( $this->fees[ $index ] ); |
|
1250 | + unset($this->fees[$index]); |
|
1251 | 1251 | $removed = true; |
1252 | 1252 | |
1253 | - if ( false === $global ) { |
|
1253 | + if (false === $global) { |
|
1254 | 1254 | break; |
1255 | 1255 | } |
1256 | 1256 | } |
1257 | 1257 | } |
1258 | 1258 | } |
1259 | 1259 | |
1260 | - if ( true === $removed ) { |
|
1261 | - $this->fees = array_values( $this->fees ); |
|
1260 | + if (true === $removed) { |
|
1261 | + $this->fees = array_values($this->fees); |
|
1262 | 1262 | } |
1263 | 1263 | |
1264 | 1264 | return $removed; |
@@ -1274,14 +1274,14 @@ discard block |
||
1274 | 1274 | * |
1275 | 1275 | * @return array The Fees for the type specified |
1276 | 1276 | */ |
1277 | - public function get_fees( $type = 'all' ) { |
|
1277 | + public function get_fees($type = 'all') { |
|
1278 | 1278 | $fees = array(); |
1279 | 1279 | |
1280 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1280 | + if ( ! empty($this->fees) && is_array($this->fees)) { |
|
1281 | 1281 | |
1282 | - foreach ( $this->fees as $fee_id => $fee ) { |
|
1282 | + foreach ($this->fees as $fee_id => $fee) { |
|
1283 | 1283 | |
1284 | - if ( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1284 | + if ('all' != $type && ! empty($fee['type']) && $type != $fee['type']) { |
|
1285 | 1285 | continue; |
1286 | 1286 | } |
1287 | 1287 | |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | } |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - return apply_filters( 'give_get_payment_fees', $fees, $this->ID, $this ); |
|
1294 | + return apply_filters('give_get_payment_fees', $fees, $this->ID, $this); |
|
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | /** |
@@ -1304,13 +1304,13 @@ discard block |
||
1304 | 1304 | * |
1305 | 1305 | * @return void |
1306 | 1306 | */ |
1307 | - public function add_note( $note = false ) { |
|
1307 | + public function add_note($note = false) { |
|
1308 | 1308 | // Bail if no note specified. |
1309 | - if ( ! $note ) { |
|
1309 | + if ( ! $note) { |
|
1310 | 1310 | return false; |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - give_insert_payment_note( $this->ID, $note ); |
|
1313 | + give_insert_payment_note($this->ID, $note); |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | /** |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | * |
1324 | 1324 | * @return void |
1325 | 1325 | */ |
1326 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1326 | + private function increase_subtotal($amount = 0.00) { |
|
1327 | 1327 | $amount = (float) $amount; |
1328 | 1328 | $this->subtotal += $amount; |
1329 | 1329 | |
@@ -1340,11 +1340,11 @@ discard block |
||
1340 | 1340 | * |
1341 | 1341 | * @return void |
1342 | 1342 | */ |
1343 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1343 | + private function decrease_subtotal($amount = 0.00) { |
|
1344 | 1344 | $amount = (float) $amount; |
1345 | 1345 | $this->subtotal -= $amount; |
1346 | 1346 | |
1347 | - if ( $this->subtotal < 0 ) { |
|
1347 | + if ($this->subtotal < 0) { |
|
1348 | 1348 | $this->subtotal = 0; |
1349 | 1349 | } |
1350 | 1350 | |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | * |
1362 | 1362 | * @return void |
1363 | 1363 | */ |
1364 | - private function increase_fees( $amount = 0.00 ) { |
|
1364 | + private function increase_fees($amount = 0.00) { |
|
1365 | 1365 | $amount = (float) $amount; |
1366 | 1366 | $this->fees_total += $amount; |
1367 | 1367 | |
@@ -1378,11 +1378,11 @@ discard block |
||
1378 | 1378 | * |
1379 | 1379 | * @return void |
1380 | 1380 | */ |
1381 | - private function decrease_fees( $amount = 0.00 ) { |
|
1381 | + private function decrease_fees($amount = 0.00) { |
|
1382 | 1382 | $amount = (float) $amount; |
1383 | 1383 | $this->fees_total -= $amount; |
1384 | 1384 | |
1385 | - if ( $this->fees_total < 0 ) { |
|
1385 | + if ($this->fees_total < 0) { |
|
1386 | 1386 | $this->fees_total = 0; |
1387 | 1387 | } |
1388 | 1388 | |
@@ -1411,24 +1411,24 @@ discard block |
||
1411 | 1411 | * |
1412 | 1412 | * @return bool $updated Returns if the status was successfully updated. |
1413 | 1413 | */ |
1414 | - public function update_status( $status = false ) { |
|
1414 | + public function update_status($status = false) { |
|
1415 | 1415 | |
1416 | 1416 | // standardize the 'complete(d)' status. |
1417 | - if ( $status == 'completed' || $status == 'complete' ) { |
|
1417 | + if ($status == 'completed' || $status == 'complete') { |
|
1418 | 1418 | $status = 'publish'; |
1419 | 1419 | } |
1420 | 1420 | |
1421 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : false; |
|
1421 | + $old_status = ! empty($this->old_status) ? $this->old_status : false; |
|
1422 | 1422 | |
1423 | - if ( $old_status === $status ) { |
|
1423 | + if ($old_status === $status) { |
|
1424 | 1424 | return false; // Don't permit status changes that aren't changes. |
1425 | 1425 | } |
1426 | 1426 | |
1427 | - $do_change = apply_filters( 'give_should_update_payment_status', true, $this->ID, $status, $old_status ); |
|
1427 | + $do_change = apply_filters('give_should_update_payment_status', true, $this->ID, $status, $old_status); |
|
1428 | 1428 | |
1429 | 1429 | $updated = false; |
1430 | 1430 | |
1431 | - if ( $do_change ) { |
|
1431 | + if ($do_change) { |
|
1432 | 1432 | |
1433 | 1433 | /** |
1434 | 1434 | * Fires before changing payment status. |
@@ -1439,21 +1439,21 @@ discard block |
||
1439 | 1439 | * @param string $status The new status. |
1440 | 1440 | * @param string $old_status The old status. |
1441 | 1441 | */ |
1442 | - do_action( 'give_before_payment_status_change', $this->ID, $status, $old_status ); |
|
1442 | + do_action('give_before_payment_status_change', $this->ID, $status, $old_status); |
|
1443 | 1443 | |
1444 | 1444 | $update_fields = array( |
1445 | 1445 | 'ID' => $this->ID, |
1446 | 1446 | 'post_status' => $status, |
1447 | - 'edit_date' => current_time( 'mysql' ), |
|
1447 | + 'edit_date' => current_time('mysql'), |
|
1448 | 1448 | ); |
1449 | 1449 | |
1450 | - $updated = wp_update_post( apply_filters( 'give_update_payment_status_fields', $update_fields ) ); |
|
1450 | + $updated = wp_update_post(apply_filters('give_update_payment_status_fields', $update_fields)); |
|
1451 | 1451 | |
1452 | 1452 | $all_payment_statuses = give_get_payment_statuses(); |
1453 | - $this->status_nicename = array_key_exists( $status, $all_payment_statuses ) ? $all_payment_statuses[ $status ] : ucfirst( $status ); |
|
1453 | + $this->status_nicename = array_key_exists($status, $all_payment_statuses) ? $all_payment_statuses[$status] : ucfirst($status); |
|
1454 | 1454 | |
1455 | 1455 | // Process any specific status functions. |
1456 | - switch ( $status ) { |
|
1456 | + switch ($status) { |
|
1457 | 1457 | case 'refunded': |
1458 | 1458 | $this->process_refund(); |
1459 | 1459 | break; |
@@ -1480,7 +1480,7 @@ discard block |
||
1480 | 1480 | * @param string $status The new status. |
1481 | 1481 | * @param string $old_status The old status. |
1482 | 1482 | */ |
1483 | - do_action( 'give_update_payment_status', $this->ID, $status, $old_status ); |
|
1483 | + do_action('give_update_payment_status', $this->ID, $status, $old_status); |
|
1484 | 1484 | |
1485 | 1485 | } |
1486 | 1486 | |
@@ -1515,33 +1515,33 @@ discard block |
||
1515 | 1515 | * |
1516 | 1516 | * @return mixed The value from the post meta |
1517 | 1517 | */ |
1518 | - public function get_meta( $meta_key = '_give_payment_meta', $single = true ) { |
|
1518 | + public function get_meta($meta_key = '_give_payment_meta', $single = true) { |
|
1519 | 1519 | |
1520 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1520 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1521 | 1521 | |
1522 | - if ( $meta_key === '_give_payment_meta' ) { |
|
1522 | + if ($meta_key === '_give_payment_meta') { |
|
1523 | 1523 | $meta = (array) $meta; |
1524 | 1524 | |
1525 | - if ( empty( $meta['key'] ) ) { |
|
1525 | + if (empty($meta['key'])) { |
|
1526 | 1526 | $meta['key'] = $this->setup_payment_key(); |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - if ( empty( $meta['form_title'] ) ) { |
|
1529 | + if (empty($meta['form_title'])) { |
|
1530 | 1530 | $meta['form_title'] = $this->setup_form_title(); |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( empty( $meta['email'] ) ) { |
|
1533 | + if (empty($meta['email'])) { |
|
1534 | 1534 | $meta['email'] = $this->setup_email(); |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( empty( $meta['date'] ) ) { |
|
1538 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1537 | + if (empty($meta['date'])) { |
|
1538 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1539 | 1539 | } |
1540 | 1540 | } |
1541 | 1541 | |
1542 | - $meta = apply_filters( "give_get_payment_meta_{$meta_key}", $meta, $this->ID ); |
|
1542 | + $meta = apply_filters("give_get_payment_meta_{$meta_key}", $meta, $this->ID); |
|
1543 | 1543 | |
1544 | - return apply_filters( 'give_get_payment_meta', $meta, $this->ID, $meta_key ); |
|
1544 | + return apply_filters('give_get_payment_meta', $meta, $this->ID, $meta_key); |
|
1545 | 1545 | } |
1546 | 1546 | |
1547 | 1547 | /** |
@@ -1556,23 +1556,23 @@ discard block |
||
1556 | 1556 | * |
1557 | 1557 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure |
1558 | 1558 | */ |
1559 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1560 | - if ( empty( $meta_key ) ) { |
|
1559 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1560 | + if (empty($meta_key)) { |
|
1561 | 1561 | return false; |
1562 | 1562 | } |
1563 | 1563 | |
1564 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1564 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1565 | 1565 | |
1566 | 1566 | $current_meta = $this->get_meta(); |
1567 | - $current_meta[ $meta_key ] = $meta_value; |
|
1567 | + $current_meta[$meta_key] = $meta_value; |
|
1568 | 1568 | |
1569 | 1569 | $meta_key = '_give_payment_meta'; |
1570 | 1570 | $meta_value = $current_meta; |
1571 | 1571 | |
1572 | - } elseif ( $meta_key == 'email' || $meta_key == '_give_payment_user_email' ) { |
|
1572 | + } elseif ($meta_key == 'email' || $meta_key == '_give_payment_user_email') { |
|
1573 | 1573 | |
1574 | - $meta_value = apply_filters( "give_give_update_payment_meta_{$meta_key}", $meta_value, $this->ID ); |
|
1575 | - update_post_meta( $this->ID, '_give_payment_user_email', $meta_value ); |
|
1574 | + $meta_value = apply_filters("give_give_update_payment_meta_{$meta_key}", $meta_value, $this->ID); |
|
1575 | + update_post_meta($this->ID, '_give_payment_user_email', $meta_value); |
|
1576 | 1576 | |
1577 | 1577 | $current_meta = $this->get_meta(); |
1578 | 1578 | $current_meta['user_info']['email'] = $meta_value; |
@@ -1582,9 +1582,9 @@ discard block |
||
1582 | 1582 | |
1583 | 1583 | } |
1584 | 1584 | |
1585 | - $meta_value = apply_filters( "give_update_payment_meta_{$meta_key}", $meta_value, $this->ID ); |
|
1585 | + $meta_value = apply_filters("give_update_payment_meta_{$meta_key}", $meta_value, $this->ID); |
|
1586 | 1586 | |
1587 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1587 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | /** |
@@ -1599,14 +1599,14 @@ discard block |
||
1599 | 1599 | $process_refund = true; |
1600 | 1600 | |
1601 | 1601 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1602 | - if ( 'publish' != $this->old_status || 'refunded' != $this->status ) { |
|
1602 | + if ('publish' != $this->old_status || 'refunded' != $this->status) { |
|
1603 | 1603 | $process_refund = false; |
1604 | 1604 | } |
1605 | 1605 | |
1606 | 1606 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1607 | - $process_refund = apply_filters( 'give_should_process_refund', $process_refund, $this ); |
|
1607 | + $process_refund = apply_filters('give_should_process_refund', $process_refund, $this); |
|
1608 | 1608 | |
1609 | - if ( false === $process_refund ) { |
|
1609 | + if (false === $process_refund) { |
|
1610 | 1610 | return; |
1611 | 1611 | } |
1612 | 1612 | |
@@ -1617,13 +1617,13 @@ discard block |
||
1617 | 1617 | * |
1618 | 1618 | * @param Give_Payment $this Payment object. |
1619 | 1619 | */ |
1620 | - do_action( 'give_pre_refund_payment', $this ); |
|
1620 | + do_action('give_pre_refund_payment', $this); |
|
1621 | 1621 | |
1622 | - $decrease_store_earnings = apply_filters( 'give_decrease_store_earnings_on_refund', true, $this ); |
|
1623 | - $decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_refund', true, $this ); |
|
1624 | - $decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1622 | + $decrease_store_earnings = apply_filters('give_decrease_store_earnings_on_refund', true, $this); |
|
1623 | + $decrease_customer_value = apply_filters('give_decrease_customer_value_on_refund', true, $this); |
|
1624 | + $decrease_purchase_count = apply_filters('give_decrease_customer_purchase_count_on_refund', true, $this); |
|
1625 | 1625 | |
1626 | - $this->maybe_alter_stats( $decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count ); |
|
1626 | + $this->maybe_alter_stats($decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count); |
|
1627 | 1627 | $this->delete_sales_logs(); |
1628 | 1628 | |
1629 | 1629 | // @todo: Refresh only range related stat cache |
@@ -1636,7 +1636,7 @@ discard block |
||
1636 | 1636 | * |
1637 | 1637 | * @param Give_Payment $this Payment object. |
1638 | 1638 | */ |
1639 | - do_action( 'give_post_refund_payment', $this ); |
|
1639 | + do_action('give_post_refund_payment', $this); |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | /** |
@@ -1663,26 +1663,26 @@ discard block |
||
1663 | 1663 | $process_pending = true; |
1664 | 1664 | |
1665 | 1665 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1666 | - if ( 'publish' != $this->old_status || 'pending' != $this->status ) { |
|
1666 | + if ('publish' != $this->old_status || 'pending' != $this->status) { |
|
1667 | 1667 | $process_pending = false; |
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1671 | - $process_pending = apply_filters( 'give_should_process_pending', $process_pending, $this ); |
|
1671 | + $process_pending = apply_filters('give_should_process_pending', $process_pending, $this); |
|
1672 | 1672 | |
1673 | - if ( false === $process_pending ) { |
|
1673 | + if (false === $process_pending) { |
|
1674 | 1674 | return; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | - $decrease_store_earnings = apply_filters( 'give_decrease_store_earnings_on_pending', true, $this ); |
|
1678 | - $decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_pending', true, $this ); |
|
1679 | - $decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1677 | + $decrease_store_earnings = apply_filters('give_decrease_store_earnings_on_pending', true, $this); |
|
1678 | + $decrease_customer_value = apply_filters('give_decrease_customer_value_on_pending', true, $this); |
|
1679 | + $decrease_purchase_count = apply_filters('give_decrease_customer_purchase_count_on_pending', true, $this); |
|
1680 | 1680 | |
1681 | - $this->maybe_alter_stats( $decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count ); |
|
1681 | + $this->maybe_alter_stats($decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count); |
|
1682 | 1682 | $this->delete_sales_logs(); |
1683 | 1683 | |
1684 | 1684 | $this->completed_date = false; |
1685 | - $this->update_meta( '_give_completed_date', '' ); |
|
1685 | + $this->update_meta('_give_completed_date', ''); |
|
1686 | 1686 | |
1687 | 1687 | // @todo: Refresh only range related stat cache |
1688 | 1688 | give_delete_donation_stats(); |
@@ -1700,26 +1700,26 @@ discard block |
||
1700 | 1700 | $process_cancelled = true; |
1701 | 1701 | |
1702 | 1702 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1703 | - if ( 'publish' != $this->old_status || 'cancelled' != $this->status ) { |
|
1703 | + if ('publish' != $this->old_status || 'cancelled' != $this->status) { |
|
1704 | 1704 | $process_cancelled = false; |
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1708 | - $process_cancelled = apply_filters( 'give_should_process_cancelled', $process_cancelled, $this ); |
|
1708 | + $process_cancelled = apply_filters('give_should_process_cancelled', $process_cancelled, $this); |
|
1709 | 1709 | |
1710 | - if ( false === $process_cancelled ) { |
|
1710 | + if (false === $process_cancelled) { |
|
1711 | 1711 | return; |
1712 | 1712 | } |
1713 | 1713 | |
1714 | - $decrease_store_earnings = apply_filters( 'give_decrease_store_earnings_on_cancelled', true, $this ); |
|
1715 | - $decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_cancelled', true, $this ); |
|
1716 | - $decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_cancelled', true, $this ); |
|
1714 | + $decrease_store_earnings = apply_filters('give_decrease_store_earnings_on_cancelled', true, $this); |
|
1715 | + $decrease_customer_value = apply_filters('give_decrease_customer_value_on_cancelled', true, $this); |
|
1716 | + $decrease_purchase_count = apply_filters('give_decrease_customer_purchase_count_on_cancelled', true, $this); |
|
1717 | 1717 | |
1718 | - $this->maybe_alter_stats( $decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count ); |
|
1718 | + $this->maybe_alter_stats($decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count); |
|
1719 | 1719 | $this->delete_sales_logs(); |
1720 | 1720 | |
1721 | 1721 | $this->completed_date = false; |
1722 | - $this->update_meta( '_give_completed_date', '' ); |
|
1722 | + $this->update_meta('_give_completed_date', ''); |
|
1723 | 1723 | |
1724 | 1724 | // @todo: Refresh only range related stat cache |
1725 | 1725 | give_delete_donation_stats(); |
@@ -1735,26 +1735,26 @@ discard block |
||
1735 | 1735 | $process_revoked = true; |
1736 | 1736 | |
1737 | 1737 | // If the payment was not in publish, don't decrement stats as they were never incremented. |
1738 | - if ( 'publish' != $this->old_status || 'revoked' != $this->status ) { |
|
1738 | + if ('publish' != $this->old_status || 'revoked' != $this->status) { |
|
1739 | 1739 | $process_revoked = false; |
1740 | 1740 | } |
1741 | 1741 | |
1742 | 1742 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1743 | - $process_revoked = apply_filters( 'give_should_process_revoked', $process_revoked, $this ); |
|
1743 | + $process_revoked = apply_filters('give_should_process_revoked', $process_revoked, $this); |
|
1744 | 1744 | |
1745 | - if ( false === $process_revoked ) { |
|
1745 | + if (false === $process_revoked) { |
|
1746 | 1746 | return; |
1747 | 1747 | } |
1748 | 1748 | |
1749 | - $decrease_store_earnings = apply_filters( 'give_decrease_store_earnings_on_revoked', true, $this ); |
|
1750 | - $decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_revoked', true, $this ); |
|
1751 | - $decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_revoked', true, $this ); |
|
1749 | + $decrease_store_earnings = apply_filters('give_decrease_store_earnings_on_revoked', true, $this); |
|
1750 | + $decrease_customer_value = apply_filters('give_decrease_customer_value_on_revoked', true, $this); |
|
1751 | + $decrease_purchase_count = apply_filters('give_decrease_customer_purchase_count_on_revoked', true, $this); |
|
1752 | 1752 | |
1753 | - $this->maybe_alter_stats( $decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count ); |
|
1753 | + $this->maybe_alter_stats($decrease_store_earnings, $decrease_customer_value, $decrease_purchase_count); |
|
1754 | 1754 | $this->delete_sales_logs(); |
1755 | 1755 | |
1756 | 1756 | $this->completed_date = false; |
1757 | - $this->update_meta( '_give_completed_date', '' ); |
|
1757 | + $this->update_meta('_give_completed_date', ''); |
|
1758 | 1758 | |
1759 | 1759 | // @todo: Refresh only range related stat cache |
1760 | 1760 | give_delete_donation_stats(); |
@@ -1772,25 +1772,25 @@ discard block |
||
1772 | 1772 | * |
1773 | 1773 | * @return void |
1774 | 1774 | */ |
1775 | - private function maybe_alter_stats( $alter_store_earnings, $alter_customer_value, $alter_customer_purchase_count ) { |
|
1775 | + private function maybe_alter_stats($alter_store_earnings, $alter_customer_value, $alter_customer_purchase_count) { |
|
1776 | 1776 | |
1777 | - give_undo_purchase( false, $this->ID ); |
|
1777 | + give_undo_purchase(false, $this->ID); |
|
1778 | 1778 | |
1779 | 1779 | // Decrease store earnings. |
1780 | - if ( true === $alter_store_earnings ) { |
|
1781 | - give_decrease_total_earnings( $this->total ); |
|
1780 | + if (true === $alter_store_earnings) { |
|
1781 | + give_decrease_total_earnings($this->total); |
|
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | // Decrement the stats for the customer. |
1785 | - if ( ! empty( $this->customer_id ) ) { |
|
1785 | + if ( ! empty($this->customer_id)) { |
|
1786 | 1786 | |
1787 | - $customer = new Give_Customer( $this->customer_id ); |
|
1787 | + $customer = new Give_Customer($this->customer_id); |
|
1788 | 1788 | |
1789 | - if ( true === $alter_customer_value ) { |
|
1790 | - $customer->decrease_value( $this->total ); |
|
1789 | + if (true === $alter_customer_value) { |
|
1790 | + $customer->decrease_value($this->total); |
|
1791 | 1791 | } |
1792 | 1792 | |
1793 | - if ( true === $alter_customer_purchase_count ) { |
|
1793 | + if (true === $alter_customer_purchase_count) { |
|
1794 | 1794 | $customer->decrease_purchase_count(); |
1795 | 1795 | } |
1796 | 1796 | } |
@@ -1839,13 +1839,13 @@ discard block |
||
1839 | 1839 | * @return string The date the payment was completed |
1840 | 1840 | */ |
1841 | 1841 | private function setup_completed_date() { |
1842 | - $payment = get_post( $this->ID ); |
|
1842 | + $payment = get_post($this->ID); |
|
1843 | 1843 | |
1844 | - if ( 'pending' == $payment->post_status || 'preapproved' == $payment->post_status ) { |
|
1844 | + if ('pending' == $payment->post_status || 'preapproved' == $payment->post_status) { |
|
1845 | 1845 | return false; // This payment was never completed. |
1846 | 1846 | } |
1847 | 1847 | |
1848 | - $date = ( $date = $this->get_meta( '_give_completed_date', true ) ) ? $date : $payment->modified_date; |
|
1848 | + $date = ($date = $this->get_meta('_give_completed_date', true)) ? $date : $payment->modified_date; |
|
1849 | 1849 | |
1850 | 1850 | return $date; |
1851 | 1851 | } |
@@ -1859,7 +1859,7 @@ discard block |
||
1859 | 1859 | * @return string The payment mode |
1860 | 1860 | */ |
1861 | 1861 | private function setup_mode() { |
1862 | - return $this->get_meta( '_give_payment_mode' ); |
|
1862 | + return $this->get_meta('_give_payment_mode'); |
|
1863 | 1863 | } |
1864 | 1864 | |
1865 | 1865 | /** |
@@ -1871,19 +1871,19 @@ discard block |
||
1871 | 1871 | * @return float The payment total |
1872 | 1872 | */ |
1873 | 1873 | private function setup_total() { |
1874 | - $amount = $this->get_meta( '_give_payment_total', true ); |
|
1874 | + $amount = $this->get_meta('_give_payment_total', true); |
|
1875 | 1875 | |
1876 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
1877 | - $meta = $this->get_meta( '_give_payment_meta', true ); |
|
1878 | - $meta = maybe_unserialize( $meta ); |
|
1876 | + if (empty($amount) && '0.00' != $amount) { |
|
1877 | + $meta = $this->get_meta('_give_payment_meta', true); |
|
1878 | + $meta = maybe_unserialize($meta); |
|
1879 | 1879 | |
1880 | - if ( isset( $meta['amount'] ) ) { |
|
1880 | + if (isset($meta['amount'])) { |
|
1881 | 1881 | $amount = $meta['amount']; |
1882 | 1882 | } |
1883 | 1883 | } |
1884 | 1884 | |
1885 | 1885 | |
1886 | - return round( floatval( $amount ), give_currency_decimal_filter() ); |
|
1886 | + return round(floatval($amount), give_currency_decimal_filter()); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | /** |
@@ -1911,9 +1911,9 @@ discard block |
||
1911 | 1911 | private function setup_fees_total() { |
1912 | 1912 | $fees_total = (float) 0.00; |
1913 | 1913 | |
1914 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1915 | - if ( ! empty( $payment_fees ) ) { |
|
1916 | - foreach ( $payment_fees as $fee ) { |
|
1914 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1915 | + if ( ! empty($payment_fees)) { |
|
1916 | + foreach ($payment_fees as $fee) { |
|
1917 | 1917 | $fees_total += (float) $fee['amount']; |
1918 | 1918 | } |
1919 | 1919 | } |
@@ -1931,7 +1931,7 @@ discard block |
||
1931 | 1931 | * @return string The currency for the payment |
1932 | 1932 | */ |
1933 | 1933 | private function setup_currency() { |
1934 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'give_payment_currency_default', give_get_currency(), $this ); |
|
1934 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('give_payment_currency_default', give_get_currency(), $this); |
|
1935 | 1935 | |
1936 | 1936 | return $currency; |
1937 | 1937 | } |
@@ -1945,7 +1945,7 @@ discard block |
||
1945 | 1945 | * @return array The Fees |
1946 | 1946 | */ |
1947 | 1947 | private function setup_fees() { |
1948 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1948 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1949 | 1949 | |
1950 | 1950 | return $payment_fees; |
1951 | 1951 | } |
@@ -1959,7 +1959,7 @@ discard block |
||
1959 | 1959 | * @return string The gateway |
1960 | 1960 | */ |
1961 | 1961 | private function setup_gateway() { |
1962 | - $gateway = $this->get_meta( '_give_payment_gateway', true ); |
|
1962 | + $gateway = $this->get_meta('_give_payment_gateway', true); |
|
1963 | 1963 | |
1964 | 1964 | return $gateway; |
1965 | 1965 | } |
@@ -1973,11 +1973,11 @@ discard block |
||
1973 | 1973 | * @return string The donation ID |
1974 | 1974 | */ |
1975 | 1975 | private function setup_transaction_id() { |
1976 | - $transaction_id = $this->get_meta( '_give_payment_transaction_id', true ); |
|
1976 | + $transaction_id = $this->get_meta('_give_payment_transaction_id', true); |
|
1977 | 1977 | |
1978 | - if ( empty( $transaction_id ) ) { |
|
1978 | + if (empty($transaction_id)) { |
|
1979 | 1979 | $gateway = $this->gateway; |
1980 | - $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $this->ID ); |
|
1980 | + $transaction_id = apply_filters("give_get_payment_transaction_id-{$gateway}", $this->ID); |
|
1981 | 1981 | } |
1982 | 1982 | |
1983 | 1983 | return $transaction_id; |
@@ -1992,7 +1992,7 @@ discard block |
||
1992 | 1992 | * @return string The IP address for the payment |
1993 | 1993 | */ |
1994 | 1994 | private function setup_ip() { |
1995 | - $ip = $this->get_meta( '_give_payment_user_ip', true ); |
|
1995 | + $ip = $this->get_meta('_give_payment_user_ip', true); |
|
1996 | 1996 | |
1997 | 1997 | return $ip; |
1998 | 1998 | } |
@@ -2006,7 +2006,7 @@ discard block |
||
2006 | 2006 | * @return int The Customer ID |
2007 | 2007 | */ |
2008 | 2008 | private function setup_customer_id() { |
2009 | - $customer_id = $this->get_meta( '_give_payment_customer_id', true ); |
|
2009 | + $customer_id = $this->get_meta('_give_payment_customer_id', true); |
|
2010 | 2010 | |
2011 | 2011 | return $customer_id; |
2012 | 2012 | } |
@@ -2020,7 +2020,7 @@ discard block |
||
2020 | 2020 | * @return int The User ID |
2021 | 2021 | */ |
2022 | 2022 | private function setup_user_id() { |
2023 | - $user_id = $this->get_meta( '_give_payment_user_id', true ); |
|
2023 | + $user_id = $this->get_meta('_give_payment_user_id', true); |
|
2024 | 2024 | |
2025 | 2025 | return $user_id; |
2026 | 2026 | } |
@@ -2034,10 +2034,10 @@ discard block |
||
2034 | 2034 | * @return string The email address for the payment |
2035 | 2035 | */ |
2036 | 2036 | private function setup_email() { |
2037 | - $email = $this->get_meta( '_give_payment_user_email', true ); |
|
2037 | + $email = $this->get_meta('_give_payment_user_email', true); |
|
2038 | 2038 | |
2039 | - if ( empty( $email ) ) { |
|
2040 | - $email = Give()->customers->get_column( 'email', $this->customer_id ); |
|
2039 | + if (empty($email)) { |
|
2040 | + $email = Give()->customers->get_column('email', $this->customer_id); |
|
2041 | 2041 | } |
2042 | 2042 | |
2043 | 2043 | return $email; |
@@ -2057,15 +2057,15 @@ discard block |
||
2057 | 2057 | 'last_name' => $this->last_name, |
2058 | 2058 | ); |
2059 | 2059 | |
2060 | - $user_info = isset( $this->payment_meta['user_info'] ) ? maybe_unserialize( $this->payment_meta['user_info'] ) : array(); |
|
2061 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
2060 | + $user_info = isset($this->payment_meta['user_info']) ? maybe_unserialize($this->payment_meta['user_info']) : array(); |
|
2061 | + $user_info = wp_parse_args($user_info, $defaults); |
|
2062 | 2062 | |
2063 | - if ( empty( $user_info ) ) { |
|
2063 | + if (empty($user_info)) { |
|
2064 | 2064 | // Get the customer, but only if it's been created. |
2065 | - $customer = new Give_Customer( $this->customer_id ); |
|
2065 | + $customer = new Give_Customer($this->customer_id); |
|
2066 | 2066 | |
2067 | - if ( $customer->id > 0 ) { |
|
2068 | - $name = explode( ' ', $customer->name, 2 ); |
|
2067 | + if ($customer->id > 0) { |
|
2068 | + $name = explode(' ', $customer->name, 2); |
|
2069 | 2069 | $user_info = array( |
2070 | 2070 | 'first_name' => $name[0], |
2071 | 2071 | 'last_name' => $name[1], |
@@ -2075,29 +2075,29 @@ discard block |
||
2075 | 2075 | } |
2076 | 2076 | } else { |
2077 | 2077 | // Get the customer, but only if it's been created. |
2078 | - $customer = new Give_Customer( $this->customer_id ); |
|
2079 | - if ( $customer->id > 0 ) { |
|
2080 | - foreach ( $user_info as $key => $value ) { |
|
2081 | - if ( ! empty( $value ) ) { |
|
2078 | + $customer = new Give_Customer($this->customer_id); |
|
2079 | + if ($customer->id > 0) { |
|
2080 | + foreach ($user_info as $key => $value) { |
|
2081 | + if ( ! empty($value)) { |
|
2082 | 2082 | continue; |
2083 | 2083 | } |
2084 | 2084 | |
2085 | - switch ( $key ) { |
|
2085 | + switch ($key) { |
|
2086 | 2086 | case 'first_name': |
2087 | - $name = explode( ' ', $customer->name, 2 ); |
|
2087 | + $name = explode(' ', $customer->name, 2); |
|
2088 | 2088 | |
2089 | - $user_info[ $key ] = $name[0]; |
|
2089 | + $user_info[$key] = $name[0]; |
|
2090 | 2090 | break; |
2091 | 2091 | |
2092 | 2092 | case 'last_name': |
2093 | - $name = explode( ' ', $customer->name, 2 ); |
|
2094 | - $last_name = ! empty( $name[1] ) ? $name[1] : ''; |
|
2093 | + $name = explode(' ', $customer->name, 2); |
|
2094 | + $last_name = ! empty($name[1]) ? $name[1] : ''; |
|
2095 | 2095 | |
2096 | - $user_info[ $key ] = $last_name; |
|
2096 | + $user_info[$key] = $last_name; |
|
2097 | 2097 | break; |
2098 | 2098 | |
2099 | 2099 | case 'email': |
2100 | - $user_info[ $key ] = $customer->email; |
|
2100 | + $user_info[$key] = $customer->email; |
|
2101 | 2101 | break; |
2102 | 2102 | } |
2103 | 2103 | } |
@@ -2118,7 +2118,7 @@ discard block |
||
2118 | 2118 | */ |
2119 | 2119 | private function setup_address() { |
2120 | 2120 | |
2121 | - $address = ! empty( $this->payment_meta['user_info']['address'] ) ? $this->payment_meta['user_info']['address'] : array( |
|
2121 | + $address = ! empty($this->payment_meta['user_info']['address']) ? $this->payment_meta['user_info']['address'] : array( |
|
2122 | 2122 | 'line1' => '', |
2123 | 2123 | 'line2' => '', |
2124 | 2124 | 'city' => '', |
@@ -2140,7 +2140,7 @@ discard block |
||
2140 | 2140 | */ |
2141 | 2141 | private function setup_form_title() { |
2142 | 2142 | |
2143 | - $form_id = $this->get_meta( '_give_payment_form_title', true ); |
|
2143 | + $form_id = $this->get_meta('_give_payment_form_title', true); |
|
2144 | 2144 | |
2145 | 2145 | return $form_id; |
2146 | 2146 | } |
@@ -2155,7 +2155,7 @@ discard block |
||
2155 | 2155 | */ |
2156 | 2156 | private function setup_form_id() { |
2157 | 2157 | |
2158 | - $form_id = $this->get_meta( '_give_payment_form_id', true ); |
|
2158 | + $form_id = $this->get_meta('_give_payment_form_id', true); |
|
2159 | 2159 | |
2160 | 2160 | return $form_id; |
2161 | 2161 | } |
@@ -2169,7 +2169,7 @@ discard block |
||
2169 | 2169 | * @return int The Form Price ID |
2170 | 2170 | */ |
2171 | 2171 | private function setup_price_id() { |
2172 | - $price_id = $this->get_meta( '_give_payment_price_id', true ); |
|
2172 | + $price_id = $this->get_meta('_give_payment_price_id', true); |
|
2173 | 2173 | |
2174 | 2174 | return $price_id; |
2175 | 2175 | } |
@@ -2183,7 +2183,7 @@ discard block |
||
2183 | 2183 | * @return string The Payment Key |
2184 | 2184 | */ |
2185 | 2185 | private function setup_payment_key() { |
2186 | - $key = $this->get_meta( '_give_payment_purchase_key', true ); |
|
2186 | + $key = $this->get_meta('_give_payment_purchase_key', true); |
|
2187 | 2187 | |
2188 | 2188 | return $key; |
2189 | 2189 | } |
@@ -2199,11 +2199,11 @@ discard block |
||
2199 | 2199 | private function setup_payment_number() { |
2200 | 2200 | $number = $this->ID; |
2201 | 2201 | |
2202 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
2202 | + if (give_get_option('enable_sequential')) { |
|
2203 | 2203 | |
2204 | - $number = $this->get_meta( '_give_payment_number', true ); |
|
2204 | + $number = $this->get_meta('_give_payment_number', true); |
|
2205 | 2205 | |
2206 | - if ( ! $number ) { |
|
2206 | + if ( ! $number) { |
|
2207 | 2207 | |
2208 | 2208 | $number = $this->ID; |
2209 | 2209 | |
@@ -2221,7 +2221,7 @@ discard block |
||
2221 | 2221 | * @return array The payment object as an array |
2222 | 2222 | */ |
2223 | 2223 | public function array_convert() { |
2224 | - return get_object_vars( $this ); |
|
2224 | + return get_object_vars($this); |
|
2225 | 2225 | } |
2226 | 2226 | |
2227 | 2227 | |
@@ -2234,7 +2234,7 @@ discard block |
||
2234 | 2234 | * @return bool |
2235 | 2235 | */ |
2236 | 2236 | public function is_completed() { |
2237 | - return ( 'publish' === $this->status && $this->completed_date ); |
|
2237 | + return ('publish' === $this->status && $this->completed_date); |
|
2238 | 2238 | } |
2239 | 2239 | |
2240 | 2240 | /** |
@@ -2246,7 +2246,7 @@ discard block |
||
2246 | 2246 | * @return string Date payment was completed |
2247 | 2247 | */ |
2248 | 2248 | private function get_completed_date() { |
2249 | - return apply_filters( 'give_payment_completed_date', $this->completed_date, $this->ID, $this ); |
|
2249 | + return apply_filters('give_payment_completed_date', $this->completed_date, $this->ID, $this); |
|
2250 | 2250 | } |
2251 | 2251 | |
2252 | 2252 | /** |
@@ -2258,7 +2258,7 @@ discard block |
||
2258 | 2258 | * @return float Payment subtotal |
2259 | 2259 | */ |
2260 | 2260 | private function get_subtotal() { |
2261 | - return apply_filters( 'give_get_payment_subtotal', $this->subtotal, $this->ID, $this ); |
|
2261 | + return apply_filters('give_get_payment_subtotal', $this->subtotal, $this->ID, $this); |
|
2262 | 2262 | } |
2263 | 2263 | |
2264 | 2264 | /** |
@@ -2270,7 +2270,7 @@ discard block |
||
2270 | 2270 | * @return string Payment currency code |
2271 | 2271 | */ |
2272 | 2272 | private function get_currency() { |
2273 | - return apply_filters( 'give_payment_currency_code', $this->currency, $this->ID, $this ); |
|
2273 | + return apply_filters('give_payment_currency_code', $this->currency, $this->ID, $this); |
|
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | /** |
@@ -2282,7 +2282,7 @@ discard block |
||
2282 | 2282 | * @return string Gateway used |
2283 | 2283 | */ |
2284 | 2284 | private function get_gateway() { |
2285 | - return apply_filters( 'give_payment_gateway', $this->gateway, $this->ID, $this ); |
|
2285 | + return apply_filters('give_payment_gateway', $this->gateway, $this->ID, $this); |
|
2286 | 2286 | } |
2287 | 2287 | |
2288 | 2288 | /** |
@@ -2294,7 +2294,7 @@ discard block |
||
2294 | 2294 | * @return string Donation ID from merchant processor |
2295 | 2295 | */ |
2296 | 2296 | private function get_transaction_id() { |
2297 | - return apply_filters( 'give_get_payment_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
2297 | + return apply_filters('give_get_payment_transaction_id', $this->transaction_id, $this->ID, $this); |
|
2298 | 2298 | } |
2299 | 2299 | |
2300 | 2300 | /** |
@@ -2306,7 +2306,7 @@ discard block |
||
2306 | 2306 | * @return string Payment IP address |
2307 | 2307 | */ |
2308 | 2308 | private function get_ip() { |
2309 | - return apply_filters( 'give_payment_user_ip', $this->ip, $this->ID, $this ); |
|
2309 | + return apply_filters('give_payment_user_ip', $this->ip, $this->ID, $this); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | /** |
@@ -2318,7 +2318,7 @@ discard block |
||
2318 | 2318 | * @return int Payment customer ID |
2319 | 2319 | */ |
2320 | 2320 | private function get_customer_id() { |
2321 | - return apply_filters( 'give_payment_customer_id', $this->customer_id, $this->ID, $this ); |
|
2321 | + return apply_filters('give_payment_customer_id', $this->customer_id, $this->ID, $this); |
|
2322 | 2322 | } |
2323 | 2323 | |
2324 | 2324 | /** |
@@ -2330,7 +2330,7 @@ discard block |
||
2330 | 2330 | * @return int Payment user ID |
2331 | 2331 | */ |
2332 | 2332 | private function get_user_id() { |
2333 | - return apply_filters( 'give_payment_user_id', $this->user_id, $this->ID, $this ); |
|
2333 | + return apply_filters('give_payment_user_id', $this->user_id, $this->ID, $this); |
|
2334 | 2334 | } |
2335 | 2335 | |
2336 | 2336 | /** |
@@ -2342,7 +2342,7 @@ discard block |
||
2342 | 2342 | * @return string Payment customer email |
2343 | 2343 | */ |
2344 | 2344 | private function get_email() { |
2345 | - return apply_filters( 'give_payment_user_email', $this->email, $this->ID, $this ); |
|
2345 | + return apply_filters('give_payment_user_email', $this->email, $this->ID, $this); |
|
2346 | 2346 | } |
2347 | 2347 | |
2348 | 2348 | /** |
@@ -2354,7 +2354,7 @@ discard block |
||
2354 | 2354 | * @return array Payment user info |
2355 | 2355 | */ |
2356 | 2356 | private function get_user_info() { |
2357 | - return apply_filters( 'give_payment_meta_user_info', $this->user_info, $this->ID, $this ); |
|
2357 | + return apply_filters('give_payment_meta_user_info', $this->user_info, $this->ID, $this); |
|
2358 | 2358 | } |
2359 | 2359 | |
2360 | 2360 | /** |
@@ -2366,7 +2366,7 @@ discard block |
||
2366 | 2366 | * @return array Payment billing address |
2367 | 2367 | */ |
2368 | 2368 | private function get_address() { |
2369 | - return apply_filters( 'give_payment_address', $this->address, $this->ID, $this ); |
|
2369 | + return apply_filters('give_payment_address', $this->address, $this->ID, $this); |
|
2370 | 2370 | } |
2371 | 2371 | |
2372 | 2372 | /** |
@@ -2378,7 +2378,7 @@ discard block |
||
2378 | 2378 | * @return string Payment key |
2379 | 2379 | */ |
2380 | 2380 | private function get_key() { |
2381 | - return apply_filters( 'give_payment_key', $this->key, $this->ID, $this ); |
|
2381 | + return apply_filters('give_payment_key', $this->key, $this->ID, $this); |
|
2382 | 2382 | } |
2383 | 2383 | |
2384 | 2384 | /** |
@@ -2390,7 +2390,7 @@ discard block |
||
2390 | 2390 | * @return string Payment form id |
2391 | 2391 | */ |
2392 | 2392 | private function get_form_id() { |
2393 | - return apply_filters( 'give_payment_form_id', $this->form_id, $this->ID, $this ); |
|
2393 | + return apply_filters('give_payment_form_id', $this->form_id, $this->ID, $this); |
|
2394 | 2394 | } |
2395 | 2395 | |
2396 | 2396 | /** |
@@ -2402,7 +2402,7 @@ discard block |
||
2402 | 2402 | * @return int|string Payment number |
2403 | 2403 | */ |
2404 | 2404 | private function get_number() { |
2405 | - return apply_filters( 'give_payment_number', $this->number, $this->ID, $this ); |
|
2405 | + return apply_filters('give_payment_number', $this->number, $this->ID, $this); |
|
2406 | 2406 | } |
2407 | 2407 | |
2408 | 2408 | } |
@@ -10,7 +10,7 @@ discard block |
||
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,7 +23,7 @@ discard block |
||
23 | 23 | * @return mixed |
24 | 24 | */ |
25 | 25 | function give_get_price_decimals() { |
26 | - return apply_filters( 'give_sanitize_amount_decimals', give_get_option( 'number_decimals', 0 ) ); |
|
26 | + return apply_filters('give_sanitize_amount_decimals', give_get_option('number_decimals', 0)); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return mixed |
35 | 35 | */ |
36 | 36 | function give_get_price_thousand_separator() { |
37 | - return give_get_option( 'thousands_separator', ',' ); |
|
37 | + return give_get_option('thousands_separator', ','); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @return mixed |
46 | 46 | */ |
47 | 47 | function give_get_price_decimal_separator() { |
48 | - return give_get_option( 'decimal_separator', '.' ); |
|
48 | + return give_get_option('decimal_separator', '.'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -61,67 +61,67 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string $amount Newly sanitized amount |
63 | 63 | */ |
64 | -function give_sanitize_amount( $number, $dp = false, $trim_zeros = false ) { |
|
64 | +function give_sanitize_amount($number, $dp = false, $trim_zeros = false) { |
|
65 | 65 | |
66 | 66 | // Bailout. |
67 | - if ( empty( $number ) ) { |
|
67 | + if (empty($number)) { |
|
68 | 68 | return $number; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Remove slash from amount. |
72 | 72 | // If thousand or decimal separator is set to ' then in $_POST or $_GET param we will get an escaped number. |
73 | 73 | // To prevent notices and warning remove slash from amount/number. |
74 | - $number = wp_unslash( $number ); |
|
74 | + $number = wp_unslash($number); |
|
75 | 75 | |
76 | 76 | $thousand_separator = give_get_price_thousand_separator(); |
77 | 77 | |
78 | 78 | $locale = localeconv(); |
79 | - $decimals = array( give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); |
|
79 | + $decimals = array(give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']); |
|
80 | 80 | |
81 | 81 | // Remove locale from string |
82 | - if ( ! is_float( $number ) ) { |
|
83 | - $number = str_replace( $decimals, '.', $number ); |
|
82 | + if ( ! is_float($number)) { |
|
83 | + $number = str_replace($decimals, '.', $number); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | // Remove thousand amount formatting if amount has. |
87 | 87 | // This condition use to add backward compatibility to version before 1.6, because before version 1.6 we were saving formatted amount to db. |
88 | 88 | // Do not replace thousand separator from price if it is same as decimal separator, because it will be already replace by above code. |
89 | - if ( ! in_array( $thousand_separator, $decimals ) && ( false !== strpos( $number, $thousand_separator ) ) ) { |
|
90 | - $number = str_replace( $thousand_separator, '', $number ); |
|
91 | - } elseif ( in_array( $thousand_separator, $decimals ) ) { |
|
92 | - $number = preg_replace( '/\.(?=.*\.)/', '', $number ); |
|
89 | + if ( ! in_array($thousand_separator, $decimals) && (false !== strpos($number, $thousand_separator))) { |
|
90 | + $number = str_replace($thousand_separator, '', $number); |
|
91 | + } elseif (in_array($thousand_separator, $decimals)) { |
|
92 | + $number = preg_replace('/\.(?=.*\.)/', '', $number); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Remove non numeric entity before decimal separator. |
96 | - $number = preg_replace( '/[^0-9\.]/', '', $number ); |
|
96 | + $number = preg_replace('/[^0-9\.]/', '', $number); |
|
97 | 97 | $default_dp = give_get_price_decimals(); |
98 | 98 | |
99 | 99 | // Reset negative amount to zero. |
100 | - if ( 0 > $number ) { |
|
101 | - $number = number_format( 0, $default_dp, '.' ); |
|
100 | + if (0 > $number) { |
|
101 | + $number = number_format(0, $default_dp, '.'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // If number does not have decimal then add number of decimals to it. |
105 | 105 | if ( |
106 | - false === strpos( $number, '.' ) |
|
107 | - || ( $default_dp > strlen( substr( $number, strpos( $number, '.' ) + 1 ) ) ) |
|
106 | + false === strpos($number, '.') |
|
107 | + || ($default_dp > strlen(substr($number, strpos($number, '.') + 1))) |
|
108 | 108 | ) { |
109 | - $number = number_format( $number, $default_dp, '.', '' ); |
|
109 | + $number = number_format($number, $default_dp, '.', ''); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | // Format number by custom number of decimals. |
113 | - if ( false !== $dp ) { |
|
114 | - $dp = intval( is_bool( $dp ) ? $default_dp : $dp ); |
|
115 | - $dp = apply_filters( 'give_sanitize_amount_decimals', $dp, $number ); |
|
116 | - $number = number_format( floatval( $number ), $dp, '.', '' ); |
|
113 | + if (false !== $dp) { |
|
114 | + $dp = intval(is_bool($dp) ? $default_dp : $dp); |
|
115 | + $dp = apply_filters('give_sanitize_amount_decimals', $dp, $number); |
|
116 | + $number = number_format(floatval($number), $dp, '.', ''); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Trim zeros. |
120 | - if ( $trim_zeros && strstr( $number, '.' ) ) { |
|
121 | - $number = rtrim( rtrim( $number, '0' ), '.' ); |
|
120 | + if ($trim_zeros && strstr($number, '.')) { |
|
121 | + $number = rtrim(rtrim($number, '0'), '.'); |
|
122 | 122 | } |
123 | 123 | |
124 | - return apply_filters( 'give_sanitize_amount', $number ); |
|
124 | + return apply_filters('give_sanitize_amount', $number); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @return string $amount Newly formatted amount or Price Not Available |
136 | 136 | */ |
137 | -function give_format_amount( $amount, $decimals = true ) { |
|
138 | - $thousands_sep = give_get_option( 'thousands_separator', ',' ); |
|
139 | - $decimal_sep = give_get_option( 'decimal_separator', '.' ); |
|
137 | +function give_format_amount($amount, $decimals = true) { |
|
138 | + $thousands_sep = give_get_option('thousands_separator', ','); |
|
139 | + $decimal_sep = give_get_option('decimal_separator', '.'); |
|
140 | 140 | |
141 | - if ( empty( $amount ) ) { |
|
141 | + if (empty($amount)) { |
|
142 | 142 | $amount = 0; |
143 | 143 | } else { |
144 | 144 | // Sanitize amount before formatting. |
145 | - $amount = give_sanitize_amount( $amount ); |
|
145 | + $amount = give_sanitize_amount($amount); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $decimals = $decimals ? give_get_price_decimals() : 0; |
149 | 149 | |
150 | - $formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
150 | + $formatted = number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
151 | 151 | |
152 | - return apply_filters( 'give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
152 | + return apply_filters('give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | |
@@ -166,33 +166,33 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return float|string formatted amount number with large number names. |
168 | 168 | */ |
169 | -function give_human_format_large_amount( $amount ) { |
|
169 | +function give_human_format_large_amount($amount) { |
|
170 | 170 | |
171 | 171 | // Get thousand separator. |
172 | 172 | $thousands_sep = give_get_price_thousand_separator(); |
173 | 173 | |
174 | 174 | // Sanitize amount. |
175 | - $sanitize_amount = give_sanitize_amount( $amount ); |
|
175 | + $sanitize_amount = give_sanitize_amount($amount); |
|
176 | 176 | |
177 | 177 | // Explode amount to calculate name of large numbers. |
178 | - $amount_array = explode( $thousands_sep, $amount ); |
|
178 | + $amount_array = explode($thousands_sep, $amount); |
|
179 | 179 | |
180 | 180 | // Calculate amount parts count. |
181 | - $amount_count_parts = count( $amount_array ); |
|
181 | + $amount_count_parts = count($amount_array); |
|
182 | 182 | |
183 | 183 | // Human format amount (default). |
184 | 184 | $human_format_amount = $amount; |
185 | 185 | |
186 | 186 | // Calculate large number formatted amount. |
187 | - if ( 4 < $amount_count_parts ) { |
|
188 | - $human_format_amount = sprintf( esc_html__( '%s trillion', 'give' ), round( ( $sanitize_amount / 1000000000000 ), 2 ) ); |
|
189 | - } elseif ( 3 < $amount_count_parts ) { |
|
190 | - $human_format_amount = sprintf( esc_html__( '%s billion', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ) ); |
|
191 | - } elseif ( 2 < $amount_count_parts ) { |
|
192 | - $human_format_amount = sprintf( esc_html__( '%s million', 'give' ), round( ( $sanitize_amount / 1000000 ), 2 ) ); |
|
187 | + if (4 < $amount_count_parts) { |
|
188 | + $human_format_amount = sprintf(esc_html__('%s trillion', 'give'), round(($sanitize_amount / 1000000000000), 2)); |
|
189 | + } elseif (3 < $amount_count_parts) { |
|
190 | + $human_format_amount = sprintf(esc_html__('%s billion', 'give'), round(($sanitize_amount / 1000000000), 2)); |
|
191 | + } elseif (2 < $amount_count_parts) { |
|
192 | + $human_format_amount = sprintf(esc_html__('%s million', 'give'), round(($sanitize_amount / 1000000), 2)); |
|
193 | 193 | } |
194 | 194 | |
195 | - return apply_filters( 'give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount ); |
|
195 | + return apply_filters('give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return string $amount Newly formatted amount or Price Not Available |
207 | 207 | */ |
208 | -function give_format_decimal( $amount, $dp = false ) { |
|
208 | +function give_format_decimal($amount, $dp = false) { |
|
209 | 209 | $decimal_separator = give_get_price_decimal_separator(); |
210 | - $formatted_amount = give_sanitize_amount( $amount, $dp ); |
|
210 | + $formatted_amount = give_sanitize_amount($amount, $dp); |
|
211 | 211 | |
212 | - if ( false !== strpos( $formatted_amount, '.' ) ) { |
|
213 | - $formatted_amount = str_replace( '.', $decimal_separator, $formatted_amount ); |
|
212 | + if (false !== strpos($formatted_amount, '.')) { |
|
213 | + $formatted_amount = str_replace('.', $decimal_separator, $formatted_amount); |
|
214 | 214 | } |
215 | 215 | |
216 | - return apply_filters( 'give_format_decimal', $formatted_amount, $amount, $decimal_separator ); |
|
216 | + return apply_filters('give_format_decimal', $formatted_amount, $amount, $decimal_separator); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -226,24 +226,24 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return mixed|string |
228 | 228 | */ |
229 | -function give_currency_filter( $price = '', $currency = '' ) { |
|
229 | +function give_currency_filter($price = '', $currency = '') { |
|
230 | 230 | |
231 | - if ( empty( $currency ) ) { |
|
231 | + if (empty($currency)) { |
|
232 | 232 | $currency = give_get_currency(); |
233 | 233 | } |
234 | 234 | |
235 | - $position = give_get_option( 'currency_position', 'before' ); |
|
235 | + $position = give_get_option('currency_position', 'before'); |
|
236 | 236 | |
237 | 237 | $negative = $price < 0; |
238 | 238 | |
239 | - if ( $negative ) { |
|
239 | + if ($negative) { |
|
240 | 240 | // Remove proceeding "-". |
241 | - $price = substr( $price, 1 ); |
|
241 | + $price = substr($price, 1); |
|
242 | 242 | } |
243 | 243 | |
244 | - $symbol = give_currency_symbol( $currency ); |
|
244 | + $symbol = give_currency_symbol($currency); |
|
245 | 245 | |
246 | - switch ( $currency ) : |
|
246 | + switch ($currency) : |
|
247 | 247 | case 'GBP' : |
248 | 248 | case 'BRL' : |
249 | 249 | case 'EUR' : |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | case 'MAD' : |
273 | 273 | case 'KRW' : |
274 | 274 | case 'ZAR' : |
275 | - $formatted = ( 'before' === $position ? $symbol . $price : $price . $symbol ); |
|
275 | + $formatted = ('before' === $position ? $symbol.$price : $price.$symbol); |
|
276 | 276 | break; |
277 | 277 | case 'NOK' : |
278 | - $formatted = ( 'before' === $position ? $symbol . ' ' . $price : $price . ' ' . $symbol ); |
|
278 | + $formatted = ('before' === $position ? $symbol.' '.$price : $price.' '.$symbol); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $formatted = ( 'before' === $position ? $currency . ' ' . $price : $price . ' ' . $currency ); |
|
281 | + $formatted = ('before' === $position ? $currency.' '.$price : $price.' '.$currency); |
|
282 | 282 | break; |
283 | 283 | endswitch; |
284 | 284 | |
@@ -293,11 +293,11 @@ discard block |
||
293 | 293 | * and if currency is USD and currency position is after then |
294 | 294 | * filter name will be give_usd_currency_filter_after |
295 | 295 | */ |
296 | - $formatted = apply_filters( 'give_' . strtolower( $currency ) . "_currency_filter_{$position}", $formatted, $currency, $price ); |
|
296 | + $formatted = apply_filters('give_'.strtolower($currency)."_currency_filter_{$position}", $formatted, $currency, $price); |
|
297 | 297 | |
298 | - if ( $negative ) { |
|
298 | + if ($negative) { |
|
299 | 299 | // Prepend the minus sign before the currency sign. |
300 | - $formatted = '-' . $formatted; |
|
300 | + $formatted = '-'.$formatted; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | return $formatted; |
@@ -313,21 +313,21 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function give_currency_decimal_filter() { |
315 | 315 | |
316 | - remove_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' ); |
|
316 | + remove_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter'); |
|
317 | 317 | |
318 | 318 | // Set default number of decimals. |
319 | 319 | $decimals = give_get_price_decimals(); |
320 | 320 | |
321 | - add_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' ); |
|
321 | + add_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter'); |
|
322 | 322 | |
323 | 323 | // Get number of decimals with backward compatibility ( version < 1.6 ) |
324 | - if ( 1 <= func_num_args() ) { |
|
325 | - $decimals = ( false === func_get_arg( 0 ) ? $decimals : absint( func_get_arg( 0 ) ) ); |
|
324 | + if (1 <= func_num_args()) { |
|
325 | + $decimals = (false === func_get_arg(0) ? $decimals : absint(func_get_arg(0))); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | $currency = give_get_currency(); |
329 | 329 | |
330 | - switch ( $currency ) { |
|
330 | + switch ($currency) { |
|
331 | 331 | case 'RIAL' : |
332 | 332 | case 'JPY' : |
333 | 333 | case 'TWD' : |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | break; |
338 | 338 | } |
339 | 339 | |
340 | - return apply_filters( 'give_currency_decimal_count', $decimals, $currency ); |
|
340 | + return apply_filters('give_currency_decimal_count', $decimals, $currency); |
|
341 | 341 | } |
342 | 342 | |
343 | -add_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' ); |
|
344 | -add_filter( 'give_format_amount_decimals', 'give_currency_decimal_filter' ); |
|
343 | +add_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter'); |
|
344 | +add_filter('give_format_amount_decimals', 'give_currency_decimal_filter'); |
|
345 | 345 | |
346 | 346 | |
347 | 347 | /** |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @return string Date format string |
355 | 355 | */ |
356 | -function give_date_format( $date_context = '' ) { |
|
356 | +function give_date_format($date_context = '') { |
|
357 | 357 | /** |
358 | 358 | * Filter the date context |
359 | 359 | * |
@@ -374,19 +374,19 @@ discard block |
||
374 | 374 | * |
375 | 375 | * } |
376 | 376 | */ |
377 | - $date_format_contexts = apply_filters( 'give_date_format_contexts', array() ); |
|
377 | + $date_format_contexts = apply_filters('give_date_format_contexts', array()); |
|
378 | 378 | |
379 | 379 | // Set date format to default date format. |
380 | - $date_format = get_option( 'date_format' ); |
|
380 | + $date_format = get_option('date_format'); |
|
381 | 381 | |
382 | 382 | // Update date format if we have non empty date format context array and non empty date format string for that context. |
383 | - if ( $date_context && ! empty( $date_format_contexts ) && array_key_exists( $date_context, $date_format_contexts ) ) { |
|
384 | - $date_format = ! empty( $date_format_contexts[ $date_context ] ) |
|
385 | - ? $date_format_contexts[ $date_context ] |
|
383 | + if ($date_context && ! empty($date_format_contexts) && array_key_exists($date_context, $date_format_contexts)) { |
|
384 | + $date_format = ! empty($date_format_contexts[$date_context]) |
|
385 | + ? $date_format_contexts[$date_context] |
|
386 | 386 | : $date_format; |
387 | 387 | } |
388 | 388 | |
389 | - return apply_filters( 'give_date_format', $date_format ); |
|
389 | + return apply_filters('give_date_format', $date_format); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | * |
401 | 401 | * @return string |
402 | 402 | */ |
403 | -function give_get_cache_key( $action, $query_args ) { |
|
404 | - return Give_Cache::get_key( $action, $query_args ); |
|
403 | +function give_get_cache_key($action, $query_args) { |
|
404 | + return Give_Cache::get_key($action, $query_args); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @return string|array |
416 | 416 | */ |
417 | -function give_clean( $var ) { |
|
418 | - if ( is_array( $var ) ) { |
|
419 | - return array_map( 'give_clean', $var ); |
|
417 | +function give_clean($var) { |
|
418 | + if (is_array($var)) { |
|
419 | + return array_map('give_clean', $var); |
|
420 | 420 | } else { |
421 | - return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; |
|
421 | + return is_scalar($var) ? sanitize_text_field($var) : $var; |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * |
432 | 432 | * @return int |
433 | 433 | */ |
434 | -function give_let_to_num( $size ) { |
|
435 | - $l = substr( $size, - 1 ); |
|
436 | - $ret = substr( $size, 0, - 1 ); |
|
437 | - switch ( strtoupper( $l ) ) { |
|
434 | +function give_let_to_num($size) { |
|
435 | + $l = substr($size, - 1); |
|
436 | + $ret = substr($size, 0, - 1); |
|
437 | + switch (strtoupper($l)) { |
|
438 | 438 | case 'P': |
439 | 439 | $ret *= 1024; |
440 | 440 | case 'T': |
@@ -459,17 +459,17 @@ discard block |
||
459 | 459 | * @param int $action |
460 | 460 | * @param array $wp_die_args |
461 | 461 | */ |
462 | -function give_validate_nonce( $nonce, $action = - 1, $wp_die_args = array() ) { |
|
462 | +function give_validate_nonce($nonce, $action = - 1, $wp_die_args = array()) { |
|
463 | 463 | |
464 | 464 | $default_wp_die_args = array( |
465 | - 'message' => esc_html__( 'Nonce verification has failed.', 'give' ), |
|
466 | - 'title' => esc_html__( 'Error', 'give' ), |
|
467 | - 'args' => array( 'response' => 403 ), |
|
465 | + 'message' => esc_html__('Nonce verification has failed.', 'give'), |
|
466 | + 'title' => esc_html__('Error', 'give'), |
|
467 | + 'args' => array('response' => 403), |
|
468 | 468 | ); |
469 | 469 | |
470 | - $wp_die_args = wp_parse_args( $wp_die_args, $default_wp_die_args ); |
|
470 | + $wp_die_args = wp_parse_args($wp_die_args, $default_wp_die_args); |
|
471 | 471 | |
472 | - if ( ! wp_verify_nonce( $nonce, $action ) ) { |
|
472 | + if ( ! wp_verify_nonce($nonce, $action)) { |
|
473 | 473 | wp_die( |
474 | 474 | $wp_die_args['message'], |
475 | 475 | $wp_die_args['title'], |
@@ -491,23 +491,23 @@ discard block |
||
491 | 491 | * |
492 | 492 | * @return mixed |
493 | 493 | */ |
494 | -function give_check_variable( $variable, $conditional = '', $default = false ) { |
|
494 | +function give_check_variable($variable, $conditional = '', $default = false) { |
|
495 | 495 | |
496 | - switch ( $conditional ) { |
|
496 | + switch ($conditional) { |
|
497 | 497 | case 'isset_empty': |
498 | - $variable = ( isset( $variable ) && ! empty( $variable ) ) ? $variable : $default; |
|
498 | + $variable = (isset($variable) && ! empty($variable)) ? $variable : $default; |
|
499 | 499 | break; |
500 | 500 | |
501 | 501 | case 'empty': |
502 | - $variable = ! empty( $variable ) ? $variable : $default; |
|
502 | + $variable = ! empty($variable) ? $variable : $default; |
|
503 | 503 | break; |
504 | 504 | |
505 | 505 | case 'null': |
506 | - $variable = ! is_null( $variable ) ? $variable : $default; |
|
506 | + $variable = ! is_null($variable) ? $variable : $default; |
|
507 | 507 | break; |
508 | 508 | |
509 | 509 | default: |
510 | - $variable = isset( $variable ) ? $variable : $default; |
|
510 | + $variable = isset($variable) ? $variable : $default; |
|
511 | 511 | |
512 | 512 | } |
513 | 513 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_get_actions() { |
27 | 27 | |
28 | - $_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null; |
|
28 | + $_get_action = ! empty($_GET['give_action']) ? $_GET['give_action'] : null; |
|
29 | 29 | |
30 | 30 | // Add backward compatibility to give-action param ( $_GET ) |
31 | - if( empty( $_get_action ) ) { |
|
32 | - $_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null; |
|
31 | + if (empty($_get_action)) { |
|
32 | + $_get_action = ! empty($_GET['give-action']) ? $_GET['give-action'] : null; |
|
33 | 33 | } |
34 | 34 | |
35 | - if ( isset( $_get_action ) ) { |
|
35 | + if (isset($_get_action)) { |
|
36 | 36 | /** |
37 | 37 | * Fires in WordPress init or admin init, when give_action is present in $_GET. |
38 | 38 | * |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param array $_GET Array of HTTP GET variables. |
42 | 42 | */ |
43 | - do_action( "give_{$_get_action}", $_GET ); |
|
43 | + do_action("give_{$_get_action}", $_GET); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
47 | 47 | |
48 | -add_action( 'init', 'give_get_actions' ); |
|
48 | +add_action('init', 'give_get_actions'); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Hooks Give actions, when present in the $_POST super global. Every give_action |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | */ |
59 | 59 | function give_post_actions() { |
60 | 60 | |
61 | - $_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null; |
|
61 | + $_post_action = ! empty($_POST['give_action']) ? $_POST['give_action'] : null; |
|
62 | 62 | |
63 | 63 | |
64 | 64 | // Add backward compatibility to give-action param ( $_POST ) |
65 | - if( empty( $_post_action ) ) { |
|
66 | - $_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null; |
|
65 | + if (empty($_post_action)) { |
|
66 | + $_post_action = ! empty($_POST['give-action']) ? $_POST['give-action'] : null; |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( isset( $_post_action ) ) { |
|
69 | + if (isset($_post_action)) { |
|
70 | 70 | /** |
71 | 71 | * Fires in WordPress init or admin init, when give_action is present in $_POST. |
72 | 72 | * |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param array $_POST Array of HTTP POST variables. |
76 | 76 | */ |
77 | - do_action( "give_{$_post_action}", $_POST ); |
|
77 | + do_action("give_{$_post_action}", $_POST); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | -add_action( 'init', 'give_post_actions' ); |
|
82 | +add_action('init', 'give_post_actions'); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Connect WordPress user with Donor. |
@@ -89,28 +89,28 @@ discard block |
||
89 | 89 | * @param array $user_data User Data |
90 | 90 | * @return void |
91 | 91 | */ |
92 | -function give_connect_donor_to_wpuser( $user_id, $user_data ){ |
|
92 | +function give_connect_donor_to_wpuser($user_id, $user_data) { |
|
93 | 93 | /* @var Give_Customer $donor */ |
94 | - $donor = new Give_Customer( $user_data['user_email'] ); |
|
94 | + $donor = new Give_Customer($user_data['user_email']); |
|
95 | 95 | |
96 | 96 | // Validate donor id and check if do nor is already connect to wp user or not. |
97 | - if( $donor->id && ! $donor->user_id ) { |
|
97 | + if ($donor->id && ! $donor->user_id) { |
|
98 | 98 | |
99 | 99 | // Update donor user_id. |
100 | - if( $donor->update( array( 'user_id' => $user_id ) ) ) { |
|
101 | - $donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id ); |
|
102 | - $donor->add_note( $donor_note ); |
|
100 | + if ($donor->update(array('user_id' => $user_id))) { |
|
101 | + $donor_note = sprintf(esc_html__('WordPress user #%d is connected to #%d', 'give'), $user_id, $donor->id); |
|
102 | + $donor->add_note($donor_note); |
|
103 | 103 | |
104 | 104 | // Update user_id meta in payments. |
105 | - if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) { |
|
106 | - foreach ( $donations as $donation ) { |
|
107 | - update_post_meta( $donation, '_give_payment_user_id', $user_id ); |
|
105 | + if ( ! empty($donor->payment_ids) && ($donations = explode(',', $donor->payment_ids))) { |
|
106 | + foreach ($donations as $donation) { |
|
107 | + update_post_meta($donation, '_give_payment_user_id', $user_id); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
113 | -add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 ); |
|
113 | +add_action('give_insert_user', 'give_connect_donor_to_wpuser', 10, 2); |
|
114 | 114 | |
115 | 115 | |
116 | 116 | /** |
@@ -124,24 +124,24 @@ discard block |
||
124 | 124 | function give_validate_license_when_site_migrated() { |
125 | 125 | // Store current site address if not already stored. |
126 | 126 | $homeurl = home_url(); |
127 | - if( ! get_option( 'give_site_address_before_migrate' ) ) { |
|
127 | + if ( ! get_option('give_site_address_before_migrate')) { |
|
128 | 128 | // Update site address. |
129 | - update_option( 'give_site_address_before_migrate', $homeurl ); |
|
129 | + update_option('give_site_address_before_migrate', $homeurl); |
|
130 | 130 | |
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if( $homeurl !== get_option( 'give_site_address_before_migrate' ) ) { |
|
134 | + if ($homeurl !== get_option('give_site_address_before_migrate')) { |
|
135 | 135 | // Immediately run cron. |
136 | - wp_schedule_single_event( time() , 'give_validate_license_when_site_migrated' ); |
|
136 | + wp_schedule_single_event(time(), 'give_validate_license_when_site_migrated'); |
|
137 | 137 | |
138 | 138 | // Update site address. |
139 | - update_option( 'give_site_address_before_migrate', home_url() ); |
|
139 | + update_option('give_site_address_before_migrate', home_url()); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | } |
143 | -add_action( 'init', 'give_validate_license_when_site_migrated' ); |
|
144 | -add_action( 'admin_init', 'give_validate_license_when_site_migrated' ); |
|
143 | +add_action('init', 'give_validate_license_when_site_migrated'); |
|
144 | +add_action('admin_init', 'give_validate_license_when_site_migrated'); |
|
145 | 145 | |
146 | 146 | |
147 | 147 | /** |
@@ -150,15 +150,15 @@ discard block |
||
150 | 150 | * @since 1.8 |
151 | 151 | * @param $data |
152 | 152 | */ |
153 | -function give_donor_batch_export_complete( $data ) { |
|
153 | +function give_donor_batch_export_complete($data) { |
|
154 | 154 | // Remove donor ids cache. |
155 | - if( |
|
156 | - isset( $data['class'] ) |
|
155 | + if ( |
|
156 | + isset($data['class']) |
|
157 | 157 | && 'Give_Batch_Customers_Export' === $data['class'] |
158 | - && ! empty( $data['forms'] ) |
|
159 | - && isset( $data['give_export_option']['query_id'] ) |
|
158 | + && ! empty($data['forms']) |
|
159 | + && isset($data['give_export_option']['query_id']) |
|
160 | 160 | ) { |
161 | - Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) ); |
|
161 | + Give_Cache::delete(Give_Cache::get_key($data['give_export_option']['query_id'])); |
|
162 | 162 | } |
163 | 163 | } |
164 | -add_action('give_file_export_complete', 'give_donor_batch_export_complete' ); |
|
164 | +add_action('give_file_export_complete', 'give_donor_batch_export_complete'); |
@@ -12,7 +12,7 @@ discard block |
||
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 | |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool|object List of all user donations |
32 | 32 | */ |
33 | -function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
33 | +function give_get_users_purchases($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
34 | 34 | |
35 | - if ( empty( $user ) ) { |
|
35 | + if (empty($user)) { |
|
36 | 36 | $user = get_current_user_id(); |
37 | 37 | } |
38 | 38 | |
39 | - if ( 0 === $user && ! Give()->email_access->token_exists ) { |
|
39 | + if (0 === $user && ! Give()->email_access->token_exists) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $status = $status === 'complete' ? 'publish' : $status; |
44 | 44 | |
45 | - if ( $pagination ) { |
|
46 | - if ( get_query_var( 'paged' ) ) { |
|
47 | - $paged = get_query_var( 'paged' ); |
|
48 | - } elseif ( get_query_var( 'page' ) ) { |
|
49 | - $paged = get_query_var( 'page' ); |
|
45 | + if ($pagination) { |
|
46 | + if (get_query_var('paged')) { |
|
47 | + $paged = get_query_var('paged'); |
|
48 | + } elseif (get_query_var('page')) { |
|
49 | + $paged = get_query_var('page'); |
|
50 | 50 | } else { |
51 | 51 | $paged = 1; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - $args = apply_filters( 'give_get_users_donations_args', array( |
|
55 | + $args = apply_filters('give_get_users_donations_args', array( |
|
56 | 56 | 'user' => $user, |
57 | 57 | 'number' => $number, |
58 | 58 | 'status' => $status, |
59 | 59 | 'orderby' => 'date', |
60 | - ) ); |
|
60 | + )); |
|
61 | 61 | |
62 | - if ( $pagination ) { |
|
62 | + if ($pagination) { |
|
63 | 63 | |
64 | 64 | $args['page'] = $paged; |
65 | 65 | |
@@ -69,20 +69,20 @@ discard block |
||
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
73 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
72 | + $by_user_id = is_numeric($user) ? true : false; |
|
73 | + $customer = new Give_Customer($user, $by_user_id); |
|
74 | 74 | |
75 | - if ( ! empty( $customer->payment_ids ) ) { |
|
75 | + if ( ! empty($customer->payment_ids)) { |
|
76 | 76 | |
77 | - unset( $args['user'] ); |
|
78 | - $args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) ); |
|
77 | + unset($args['user']); |
|
78 | + $args['post__in'] = array_map('absint', explode(',', $customer->payment_ids)); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - $purchases = give_get_payments( apply_filters( 'give_get_users_donations_args', $args ) ); |
|
82 | + $purchases = give_get_payments(apply_filters('give_get_users_donations_args', $args)); |
|
83 | 83 | |
84 | 84 | // No donations |
85 | - if ( ! $purchases ) { |
|
85 | + if ( ! $purchases) { |
|
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
@@ -101,65 +101,65 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return bool|object List of unique forms donated by user |
103 | 103 | */ |
104 | -function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
|
105 | - if ( empty( $user ) ) { |
|
104 | +function give_get_users_completed_donations($user = 0, $status = 'complete') { |
|
105 | + if (empty($user)) { |
|
106 | 106 | $user = get_current_user_id(); |
107 | 107 | } |
108 | 108 | |
109 | - if ( empty( $user ) ) { |
|
109 | + if (empty($user)) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
113 | + $by_user_id = is_numeric($user) ? true : false; |
|
114 | 114 | |
115 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
115 | + $customer = new Give_Customer($user, $by_user_id); |
|
116 | 116 | |
117 | - if ( empty( $customer->payment_ids ) ) { |
|
117 | + if (empty($customer->payment_ids)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Get all the items donated |
122 | - $payment_ids = array_reverse( explode( ',', $customer->payment_ids ) ); |
|
123 | - $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
|
124 | - if ( ! empty( $limit_payments ) ) { |
|
125 | - $payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
|
122 | + $payment_ids = array_reverse(explode(',', $customer->payment_ids)); |
|
123 | + $limit_payments = apply_filters('give_users_completed_donations_payments', 50); |
|
124 | + if ( ! empty($limit_payments)) { |
|
125 | + $payment_ids = array_slice($payment_ids, 0, $limit_payments); |
|
126 | 126 | } |
127 | 127 | $donation_data = array(); |
128 | - foreach ( $payment_ids as $payment_id ) { |
|
129 | - $donation_data[] = give_get_payment_meta( $payment_id ); |
|
128 | + foreach ($payment_ids as $payment_id) { |
|
129 | + $donation_data[] = give_get_payment_meta($payment_id); |
|
130 | 130 | } |
131 | 131 | |
132 | - if ( empty( $donation_data ) ) { |
|
132 | + if (empty($donation_data)) { |
|
133 | 133 | return false; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Grab only the post ids "form_id" of the forms donated on this order |
137 | 137 | $completed_donations_ids = array(); |
138 | - foreach ( $donation_data as $purchase_meta ) { |
|
139 | - $completed_donations_ids[] = isset( $purchase_meta['form_id'] ) ? $purchase_meta['form_id'] : ''; |
|
138 | + foreach ($donation_data as $purchase_meta) { |
|
139 | + $completed_donations_ids[] = isset($purchase_meta['form_id']) ? $purchase_meta['form_id'] : ''; |
|
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $completed_donations_ids ) ) { |
|
142 | + if (empty($completed_donations_ids)) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Only include each donation once |
147 | - $form_ids = array_unique( $completed_donations_ids ); |
|
147 | + $form_ids = array_unique($completed_donations_ids); |
|
148 | 148 | |
149 | 149 | // Make sure we still have some products and a first item |
150 | - if ( empty( $form_ids ) || ! isset( $form_ids[0] ) ) { |
|
150 | + if (empty($form_ids) || ! isset($form_ids[0])) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | - $post_type = get_post_type( $form_ids[0] ); |
|
154 | + $post_type = get_post_type($form_ids[0]); |
|
155 | 155 | |
156 | - $args = apply_filters( 'give_get_users_completed_donations_args', array( |
|
156 | + $args = apply_filters('give_get_users_completed_donations_args', array( |
|
157 | 157 | 'include' => $form_ids, |
158 | 158 | 'post_type' => $post_type, |
159 | - 'posts_per_page' => - 1, |
|
160 | - ) ); |
|
159 | + 'posts_per_page' => -1, |
|
160 | + )); |
|
161 | 161 | |
162 | - return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
|
162 | + return apply_filters('give_users_completed_donations_list', get_posts($args)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return bool True if has donated, false other wise. |
177 | 177 | */ |
178 | -function give_has_purchases( $user_id = null ) { |
|
179 | - if ( empty( $user_id ) ) { |
|
178 | +function give_has_purchases($user_id = null) { |
|
179 | + if (empty($user_id)) { |
|
180 | 180 | $user_id = get_current_user_id(); |
181 | 181 | } |
182 | 182 | |
183 | - if ( give_get_users_purchases( $user_id, 1 ) ) { |
|
183 | + if (give_get_users_purchases($user_id, 1)) { |
|
184 | 184 | return true; // User has at least one donation |
185 | 185 | } |
186 | 186 | |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return array |
202 | 202 | */ |
203 | -function give_get_purchase_stats_by_user( $user = '' ) { |
|
203 | +function give_get_purchase_stats_by_user($user = '') { |
|
204 | 204 | |
205 | - if ( is_email( $user ) ) { |
|
205 | + if (is_email($user)) { |
|
206 | 206 | |
207 | 207 | $field = 'email'; |
208 | 208 | |
209 | - } elseif ( is_numeric( $user ) ) { |
|
209 | + } elseif (is_numeric($user)) { |
|
210 | 210 | |
211 | 211 | $field = 'user_id'; |
212 | 212 | |
213 | 213 | } |
214 | 214 | |
215 | 215 | $stats = array(); |
216 | - $customer = Give()->customers->get_customer_by( $field, $user ); |
|
216 | + $customer = Give()->customers->get_customer_by($field, $user); |
|
217 | 217 | |
218 | - if ( $customer ) { |
|
218 | + if ($customer) { |
|
219 | 219 | |
220 | - $customer = new Give_Customer( $customer->id ); |
|
220 | + $customer = new Give_Customer($customer->id); |
|
221 | 221 | |
222 | - $stats['purchases'] = absint( $customer->purchase_count ); |
|
223 | - $stats['total_spent'] = give_sanitize_amount( $customer->purchase_value ); |
|
222 | + $stats['purchases'] = absint($customer->purchase_count); |
|
223 | + $stats['total_spent'] = give_sanitize_amount($customer->purchase_value); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @since 1.7 |
231 | 231 | */ |
232 | - $stats = (array) apply_filters( 'give_donation_stats_by_user', $stats, $user ); |
|
232 | + $stats = (array) apply_filters('give_donation_stats_by_user', $stats, $user); |
|
233 | 233 | |
234 | 234 | return $stats; |
235 | 235 | } |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return int The total number of donations |
249 | 249 | */ |
250 | -function give_count_purchases_of_customer( $user = null ) { |
|
250 | +function give_count_purchases_of_customer($user = null) { |
|
251 | 251 | |
252 | 252 | // Logged in? |
253 | - if ( empty( $user ) ) { |
|
253 | + if (empty($user)) { |
|
254 | 254 | $user = get_current_user_id(); |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Email access? |
258 | - if ( empty( $user ) && Give()->email_access->token_email ) { |
|
258 | + if (empty($user) && Give()->email_access->token_email) { |
|
259 | 259 | $user = Give()->email_access->token_email; |
260 | 260 | } |
261 | 261 | |
262 | - $stats = ! empty( $user ) ? give_get_purchase_stats_by_user( $user ) : false; |
|
262 | + $stats = ! empty($user) ? give_get_purchase_stats_by_user($user) : false; |
|
263 | 263 | |
264 | - return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
|
264 | + return isset($stats['purchases']) ? $stats['purchases'] : 0; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return float The total amount the user has spent |
276 | 276 | */ |
277 | -function give_purchase_total_of_user( $user = null ) { |
|
277 | +function give_purchase_total_of_user($user = null) { |
|
278 | 278 | |
279 | - $stats = give_get_purchase_stats_by_user( $user ); |
|
279 | + $stats = give_get_purchase_stats_by_user($user); |
|
280 | 280 | |
281 | 281 | return $stats['total_spent']; |
282 | 282 | } |
@@ -292,40 +292,40 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @return bool |
294 | 294 | */ |
295 | -function give_validate_username( $username, $form_id = 0 ) { |
|
295 | +function give_validate_username($username, $form_id = 0) { |
|
296 | 296 | $valid = true; |
297 | 297 | |
298 | 298 | // Validate username. |
299 | - if ( ! empty( $username ) ) { |
|
299 | + if ( ! empty($username)) { |
|
300 | 300 | |
301 | 301 | // Sanitize username. |
302 | - $sanitized_user_name = sanitize_user( $username, false ); |
|
302 | + $sanitized_user_name = sanitize_user($username, false); |
|
303 | 303 | |
304 | 304 | // We have an user name, check if it already exists. |
305 | - if ( username_exists( $username ) ) { |
|
305 | + if (username_exists($username)) { |
|
306 | 306 | // Username already registered. |
307 | - give_set_error( 'username_unavailable', esc_html__( 'Username already taken.', 'give' ) ); |
|
307 | + give_set_error('username_unavailable', esc_html__('Username already taken.', 'give')); |
|
308 | 308 | $valid = false; |
309 | 309 | |
310 | 310 | // Check if it's valid. |
311 | - } elseif ( $sanitized_user_name !== $username ) { |
|
311 | + } elseif ($sanitized_user_name !== $username) { |
|
312 | 312 | // Invalid username. |
313 | - if ( is_multisite() ) { |
|
314 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) ); |
|
313 | + if (is_multisite()) { |
|
314 | + give_set_error('username_invalid', esc_html__('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give')); |
|
315 | 315 | $valid = false; |
316 | 316 | } else { |
317 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username.', 'give' ) ); |
|
317 | + give_set_error('username_invalid', esc_html__('Invalid username.', 'give')); |
|
318 | 318 | $valid = false; |
319 | 319 | } |
320 | 320 | } |
321 | 321 | } else { |
322 | 322 | // Username is empty. |
323 | - give_set_error( 'username_empty', esc_html__( 'Enter a username.', 'give' ) ); |
|
323 | + give_set_error('username_empty', esc_html__('Enter a username.', 'give')); |
|
324 | 324 | $valid = false; |
325 | 325 | |
326 | 326 | // Check if guest checkout is disable for form. |
327 | - if ( $form_id && give_logged_in_only( $form_id ) ) { |
|
328 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation.', 'give' ) ); |
|
327 | + if ($form_id && give_logged_in_only($form_id)) { |
|
328 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation.', 'give')); |
|
329 | 329 | $valid = false; |
330 | 330 | } |
331 | 331 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @param string $username |
340 | 340 | * @param bool $form_id |
341 | 341 | */ |
342 | - $valid = (bool) apply_filters( 'give_validate_username', $valid, $username, $form_id ); |
|
342 | + $valid = (bool) apply_filters('give_validate_username', $valid, $username, $form_id); |
|
343 | 343 | |
344 | 344 | return $valid; |
345 | 345 | } |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return bool |
357 | 357 | */ |
358 | -function give_validate_user_email( $email, $registering_new_user = false ) { |
|
358 | +function give_validate_user_email($email, $registering_new_user = false) { |
|
359 | 359 | $valid = true; |
360 | 360 | |
361 | - if ( empty( $email ) ) { |
|
361 | + if (empty($email)) { |
|
362 | 362 | // No email. |
363 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
363 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
364 | 364 | $valid = false; |
365 | 365 | |
366 | - } elseif ( ! is_email( $email ) ) { |
|
366 | + } elseif ( ! is_email($email)) { |
|
367 | 367 | // Validate email. |
368 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
368 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
369 | 369 | $valid = false; |
370 | 370 | |
371 | - } elseif ( $registering_new_user && email_exists( $email ) ) { |
|
371 | + } elseif ($registering_new_user && email_exists($email)) { |
|
372 | 372 | // Check if email exists. |
373 | - give_set_error( 'email_used', esc_html__( 'The email already active for another user.', 'give' ) ); |
|
373 | + give_set_error('email_used', esc_html__('The email already active for another user.', 'give')); |
|
374 | 374 | $valid = false; |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param string $email |
384 | 384 | * @param bool $registering_new_user |
385 | 385 | */ |
386 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $email, $registering_new_user ); |
|
386 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $email, $registering_new_user); |
|
387 | 387 | |
388 | 388 | return $valid; |
389 | 389 | } |
@@ -399,25 +399,25 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | -function give_validate_user_password( $password = '', $confirm_password = '', $registering_new_user = false ) { |
|
402 | +function give_validate_user_password($password = '', $confirm_password = '', $registering_new_user = false) { |
|
403 | 403 | $valid = true; |
404 | 404 | |
405 | - if ( $password && $confirm_password ) { |
|
405 | + if ($password && $confirm_password) { |
|
406 | 406 | // Verify confirmation matches. |
407 | - if ( $password != $confirm_password ) { |
|
407 | + if ($password != $confirm_password) { |
|
408 | 408 | // Passwords do not match |
409 | - give_set_error( 'password_mismatch', esc_html__( 'Passwords don\'t match.', 'give' ) ); |
|
409 | + give_set_error('password_mismatch', esc_html__('Passwords don\'t match.', 'give')); |
|
410 | 410 | $valid = false; |
411 | 411 | } |
412 | - } elseif ( $registering_new_user ) { |
|
412 | + } elseif ($registering_new_user) { |
|
413 | 413 | // Password or confirmation missing. |
414 | - if ( ! $password ) { |
|
414 | + if ( ! $password) { |
|
415 | 415 | // The password is invalid. |
416 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
416 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
417 | 417 | $valid = false; |
418 | - } elseif ( ! $confirm_password ) { |
|
418 | + } elseif ( ! $confirm_password) { |
|
419 | 419 | // Confirmation password is invalid. |
420 | - give_set_error( 'confirmation_empty', esc_html__( 'Enter the password confirmation.', 'give' ) ); |
|
420 | + give_set_error('confirmation_empty', esc_html__('Enter the password confirmation.', 'give')); |
|
421 | 421 | $valid = false; |
422 | 422 | } |
423 | 423 | } |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param string $confirm_password |
433 | 433 | * @param bool $registering_new_user |
434 | 434 | */ |
435 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user ); |
|
435 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user); |
|
436 | 436 | |
437 | 437 | return $valid; |
438 | 438 | } |
@@ -451,32 +451,32 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @return void |
453 | 453 | */ |
454 | -function give_add_past_purchases_to_new_user( $user_id ) { |
|
454 | +function give_add_past_purchases_to_new_user($user_id) { |
|
455 | 455 | |
456 | - $email = get_the_author_meta( 'user_email', $user_id ); |
|
456 | + $email = get_the_author_meta('user_email', $user_id); |
|
457 | 457 | |
458 | - $payments = give_get_payments( array( 's' => $email ) ); |
|
458 | + $payments = give_get_payments(array('s' => $email)); |
|
459 | 459 | |
460 | - if ( $payments ) { |
|
461 | - foreach ( $payments as $payment ) { |
|
462 | - if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) { |
|
460 | + if ($payments) { |
|
461 | + foreach ($payments as $payment) { |
|
462 | + if (intval(give_get_payment_user_id($payment->ID)) > 0) { |
|
463 | 463 | continue; |
464 | 464 | } // This payment already associated with an account |
465 | 465 | |
466 | - $meta = give_get_payment_meta( $payment->ID ); |
|
467 | - $meta['user_info'] = maybe_unserialize( $meta['user_info'] ); |
|
466 | + $meta = give_get_payment_meta($payment->ID); |
|
467 | + $meta['user_info'] = maybe_unserialize($meta['user_info']); |
|
468 | 468 | $meta['user_info']['id'] = $user_id; |
469 | 469 | $meta['user_info'] = $meta['user_info']; |
470 | 470 | |
471 | 471 | // Store the updated user ID in the payment meta |
472 | - give_update_payment_meta( $payment->ID, '_give_payment_meta', $meta ); |
|
473 | - give_update_payment_meta( $payment->ID, '_give_payment_user_id', $user_id ); |
|
472 | + give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); |
|
473 | + give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | 477 | } |
478 | 478 | |
479 | -add_action( 'user_register', 'give_add_past_purchases_to_new_user' ); |
|
479 | +add_action('user_register', 'give_add_past_purchases_to_new_user'); |
|
480 | 480 | |
481 | 481 | |
482 | 482 | /** |
@@ -502,34 +502,34 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return array The donor's address, if any |
504 | 504 | */ |
505 | -function give_get_donor_address( $user_id = 0 ) { |
|
506 | - if ( empty( $user_id ) ) { |
|
505 | +function give_get_donor_address($user_id = 0) { |
|
506 | + if (empty($user_id)) { |
|
507 | 507 | $user_id = get_current_user_id(); |
508 | 508 | } |
509 | 509 | |
510 | - $address = get_user_meta( $user_id, '_give_user_address', true ); |
|
510 | + $address = get_user_meta($user_id, '_give_user_address', true); |
|
511 | 511 | |
512 | - if ( ! isset( $address['line1'] ) ) { |
|
512 | + if ( ! isset($address['line1'])) { |
|
513 | 513 | $address['line1'] = ''; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! isset( $address['line2'] ) ) { |
|
516 | + if ( ! isset($address['line2'])) { |
|
517 | 517 | $address['line2'] = ''; |
518 | 518 | } |
519 | 519 | |
520 | - if ( ! isset( $address['city'] ) ) { |
|
520 | + if ( ! isset($address['city'])) { |
|
521 | 521 | $address['city'] = ''; |
522 | 522 | } |
523 | 523 | |
524 | - if ( ! isset( $address['zip'] ) ) { |
|
524 | + if ( ! isset($address['zip'])) { |
|
525 | 525 | $address['zip'] = ''; |
526 | 526 | } |
527 | 527 | |
528 | - if ( ! isset( $address['country'] ) ) { |
|
528 | + if ( ! isset($address['country'])) { |
|
529 | 529 | $address['country'] = ''; |
530 | 530 | } |
531 | 531 | |
532 | - if ( ! isset( $address['state'] ) ) { |
|
532 | + if ( ! isset($address['state'])) { |
|
533 | 533 | $address['state'] = ''; |
534 | 534 | } |
535 | 535 | |
@@ -549,42 +549,42 @@ discard block |
||
549 | 549 | * |
550 | 550 | * @return void |
551 | 551 | */ |
552 | -function give_new_user_notification( $user_id = 0, $user_data = array() ) { |
|
552 | +function give_new_user_notification($user_id = 0, $user_data = array()) { |
|
553 | 553 | |
554 | - if ( empty( $user_id ) || empty( $user_data ) ) { |
|
554 | + if (empty($user_id) || empty($user_data)) { |
|
555 | 555 | return; |
556 | 556 | } |
557 | - $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
557 | + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
558 | 558 | |
559 | 559 | /* translators: %s: site name */ |
560 | - $message = sprintf( esc_attr__( 'New user registration on your site %s:', 'give' ), $blogname ) . "\r\n\r\n"; |
|
560 | + $message = sprintf(esc_attr__('New user registration on your site %s:', 'give'), $blogname)."\r\n\r\n"; |
|
561 | 561 | /* translators: %s: user login */ |
562 | - $message .= sprintf( esc_attr__( 'Username: %s', 'give' ), $user_data['user_login'] ) . "\r\n\r\n"; |
|
562 | + $message .= sprintf(esc_attr__('Username: %s', 'give'), $user_data['user_login'])."\r\n\r\n"; |
|
563 | 563 | /* translators: %s: user email */ |
564 | - $message .= sprintf( esc_attr__( 'E-mail: %s', 'give' ), $user_data['user_email'] ) . "\r\n"; |
|
564 | + $message .= sprintf(esc_attr__('E-mail: %s', 'give'), $user_data['user_email'])."\r\n"; |
|
565 | 565 | |
566 | 566 | Give()->emails->send( |
567 | - get_option( 'admin_email' ), |
|
567 | + get_option('admin_email'), |
|
568 | 568 | sprintf( |
569 | 569 | /* translators: %s: site name */ |
570 | - esc_attr__( '[%s] New User Registration', 'give' ), |
|
570 | + esc_attr__('[%s] New User Registration', 'give'), |
|
571 | 571 | $blogname |
572 | 572 | ), |
573 | 573 | $message |
574 | 574 | ); |
575 | 575 | |
576 | 576 | /* translators: %s: user login */ |
577 | - $message = sprintf( esc_attr__( 'Username: %s', 'give' ), $user_data['user_login'] ) . "\r\n"; |
|
577 | + $message = sprintf(esc_attr__('Username: %s', 'give'), $user_data['user_login'])."\r\n"; |
|
578 | 578 | /* translators: %s: paswword */ |
579 | - $message .= sprintf( esc_attr__( 'Password: %s', 'give' ), esc_attr__( '[Password entered during donation]', 'give' ) ) . "\r\n"; |
|
579 | + $message .= sprintf(esc_attr__('Password: %s', 'give'), esc_attr__('[Password entered during donation]', 'give'))."\r\n"; |
|
580 | 580 | |
581 | - $message .= '<a href="' . wp_login_url() . '"> ' . esc_attr__( 'Click Here to Login »', 'give' ) . '</a>' . "\r\n"; |
|
581 | + $message .= '<a href="'.wp_login_url().'"> '.esc_attr__('Click Here to Login »', 'give').'</a>'."\r\n"; |
|
582 | 582 | |
583 | 583 | Give()->emails->send( |
584 | 584 | $user_data['user_email'], |
585 | 585 | sprintf( |
586 | 586 | /* translators: %s: site name */ |
587 | - esc_attr__( '[%s] Your username and password', 'give' ), |
|
587 | + esc_attr__('[%s] Your username and password', 'give'), |
|
588 | 588 | $blogname |
589 | 589 | ), |
590 | 590 | $message |
@@ -592,4 +592,4 @@ discard block |
||
592 | 592 | |
593 | 593 | } |
594 | 594 | |
595 | -add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); |
|
595 | +add_action('give_insert_user', 'give_new_user_notification', 10, 2); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | * @global $wpdb |
27 | 27 | * @return void |
28 | 28 | */ |
29 | -function give_install( $network_wide = false ) { |
|
29 | +function give_install($network_wide = false) { |
|
30 | 30 | |
31 | 31 | global $wpdb; |
32 | 32 | |
33 | - if ( is_multisite() && $network_wide ) { |
|
33 | + if (is_multisite() && $network_wide) { |
|
34 | 34 | |
35 | - foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) { |
|
35 | + foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs LIMIT 100") as $blog_id) { |
|
36 | 36 | |
37 | - switch_to_blog( $blog_id ); |
|
37 | + switch_to_blog($blog_id); |
|
38 | 38 | give_run_install(); |
39 | 39 | restore_current_blog(); |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | } |
50 | 50 | |
51 | -register_activation_hook( GIVE_PLUGIN_FILE, 'give_install' ); |
|
51 | +register_activation_hook(GIVE_PLUGIN_FILE, 'give_install'); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Run the Give Install process. |
@@ -64,24 +64,24 @@ discard block |
||
64 | 64 | give_setup_post_types(); |
65 | 65 | |
66 | 66 | // Clear the permalinks. |
67 | - flush_rewrite_rules( false ); |
|
67 | + flush_rewrite_rules(false); |
|
68 | 68 | |
69 | 69 | // Add Upgraded From Option. |
70 | - $current_version = get_option( 'give_version' ); |
|
71 | - if ( $current_version ) { |
|
72 | - update_option( 'give_version_upgraded_from', $current_version ); |
|
70 | + $current_version = get_option('give_version'); |
|
71 | + if ($current_version) { |
|
72 | + update_option('give_version_upgraded_from', $current_version); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Setup some default options. |
76 | 76 | $options = array(); |
77 | 77 | |
78 | 78 | // Checks if the Success Page option exists AND that the page exists. |
79 | - if ( ! get_post( give_get_option( 'success_page' ) ) ) { |
|
79 | + if ( ! get_post(give_get_option('success_page'))) { |
|
80 | 80 | |
81 | 81 | // Donation Confirmation (Success) Page |
82 | 82 | $success = wp_insert_post( |
83 | 83 | array( |
84 | - 'post_title' => esc_html__( 'Donation Confirmation', 'give' ), |
|
84 | + 'post_title' => esc_html__('Donation Confirmation', 'give'), |
|
85 | 85 | 'post_content' => '[give_receipt]', |
86 | 86 | 'post_status' => 'publish', |
87 | 87 | 'post_author' => 1, |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | // Checks if the Failure Page option exists AND that the page exists. |
98 | - if ( ! get_post( give_get_option( 'failure_page' ) ) ) { |
|
98 | + if ( ! get_post(give_get_option('failure_page'))) { |
|
99 | 99 | |
100 | 100 | // Failed Donation Page |
101 | 101 | $failed = wp_insert_post( |
102 | 102 | array( |
103 | - 'post_title' => esc_html__( 'Donation Failed', 'give' ), |
|
104 | - 'post_content' => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ), |
|
103 | + 'post_title' => esc_html__('Donation Failed', 'give'), |
|
104 | + 'post_content' => esc_html__('We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give'), |
|
105 | 105 | 'post_status' => 'publish', |
106 | 106 | 'post_author' => 1, |
107 | 107 | 'post_type' => 'page', |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | // Checks if the History Page option exists AND that the page exists. |
116 | - if ( ! get_post( give_get_option( 'history_page' ) ) ) { |
|
116 | + if ( ! get_post(give_get_option('history_page'))) { |
|
117 | 117 | // Donation History Page |
118 | 118 | $history = wp_insert_post( |
119 | 119 | array( |
120 | - 'post_title' => esc_html__( 'Donation History', 'give' ), |
|
120 | + 'post_title' => esc_html__('Donation History', 'give'), |
|
121 | 121 | 'post_content' => '[donation_history]', |
122 | 122 | 'post_status' => 'publish', |
123 | 123 | 'post_author' => 1, |
@@ -130,23 +130,23 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | //Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency. |
133 | - if ( empty( $current_version ) ) { |
|
134 | - $options = array_merge( $options, give_get_default_settings() ); |
|
133 | + if (empty($current_version)) { |
|
134 | + $options = array_merge($options, give_get_default_settings()); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | // Populate the default values. |
138 | - update_option( 'give_settings', array_merge( $give_options, $options ) ); |
|
138 | + update_option('give_settings', array_merge($give_options, $options)); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Run plugin upgrades. |
142 | 142 | * |
143 | 143 | * @since 1.8 |
144 | 144 | */ |
145 | - do_action( 'give_upgrades' ); |
|
145 | + do_action('give_upgrades'); |
|
146 | 146 | |
147 | 147 | |
148 | - if( GIVE_VERSION !== get_option( 'give_version' ) ) { |
|
149 | - update_option( 'give_version', GIVE_VERSION ); |
|
148 | + if (GIVE_VERSION !== get_option('give_version')) { |
|
149 | + update_option('give_version', GIVE_VERSION); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Create Give roles. |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $roles->add_caps(); |
156 | 156 | |
157 | 157 | $api = new Give_API(); |
158 | - update_option( 'give_default_api_version', 'v' . $api->get_version() ); |
|
158 | + update_option('give_default_api_version', 'v'.$api->get_version()); |
|
159 | 159 | |
160 | 160 | // Create the customers databases. |
161 | 161 | @Give()->customers->create_table(); |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | Give()->session->use_php_sessions(); |
166 | 166 | |
167 | 167 | // Add a temporary option to note that Give pages have been created. |
168 | - Give_Cache::set( '_give_installed', $options, 30, true ); |
|
168 | + Give_Cache::set('_give_installed', $options, 30, true); |
|
169 | 169 | |
170 | - if ( ! $current_version ) { |
|
170 | + if ( ! $current_version) { |
|
171 | 171 | |
172 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
172 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
173 | 173 | |
174 | 174 | // When new upgrade routines are added, mark them as complete on fresh install. |
175 | 175 | $upgrade_routines = array( |
@@ -180,22 +180,22 @@ discard block |
||
180 | 180 | 'v18_upgrades_form_metadata' |
181 | 181 | ); |
182 | 182 | |
183 | - foreach ( $upgrade_routines as $upgrade ) { |
|
184 | - give_set_upgrade_complete( $upgrade ); |
|
183 | + foreach ($upgrade_routines as $upgrade) { |
|
184 | + give_set_upgrade_complete($upgrade); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Bail if activating from network, or bulk. |
189 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
189 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Add the transient to redirect. |
194 | - Give_Cache::set( '_give_activation_redirect', true, 30, true ); |
|
194 | + Give_Cache::set('_give_activation_redirect', true, 30, true); |
|
195 | 195 | |
196 | 196 | } |
197 | 197 | |
198 | -register_activation_hook( GIVE_PLUGIN_FILE, 'give_install' ); |
|
198 | +register_activation_hook(GIVE_PLUGIN_FILE, 'give_install'); |
|
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Network Activated New Site Setup. |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @param int $site_id The Site ID. |
212 | 212 | * @param array $meta Blog Meta. |
213 | 213 | */ |
214 | -function on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
|
214 | +function on_create_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) { |
|
215 | 215 | |
216 | - if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) { |
|
216 | + if (is_plugin_active_for_network(GIVE_PLUGIN_BASENAME)) { |
|
217 | 217 | |
218 | - switch_to_blog( $blog_id ); |
|
218 | + switch_to_blog($blog_id); |
|
219 | 219 | give_install(); |
220 | 220 | restore_current_blog(); |
221 | 221 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | } |
225 | 225 | |
226 | -add_action( 'wpmu_new_blog', 'on_create_blog', 10, 6 ); |
|
226 | +add_action('wpmu_new_blog', 'on_create_blog', 10, 6); |
|
227 | 227 | |
228 | 228 | |
229 | 229 | /** |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return array The tables to drop. |
238 | 238 | */ |
239 | -function give_wpmu_drop_tables( $tables, $blog_id ) { |
|
239 | +function give_wpmu_drop_tables($tables, $blog_id) { |
|
240 | 240 | |
241 | - switch_to_blog( $blog_id ); |
|
241 | + switch_to_blog($blog_id); |
|
242 | 242 | $customers_db = new Give_DB_Customers(); |
243 | 243 | $customer_meta_db = new Give_DB_Customer_Meta(); |
244 | 244 | |
245 | - if ( $customers_db->installed() ) { |
|
245 | + if ($customers_db->installed()) { |
|
246 | 246 | $tables[] = $customers_db->table_name; |
247 | 247 | $tables[] = $customer_meta_db->table_name; |
248 | 248 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | } |
254 | 254 | |
255 | -add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 ); |
|
255 | +add_filter('wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2); |
|
256 | 256 | |
257 | 257 | /** |
258 | 258 | * Post-installation |
@@ -264,16 +264,16 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function give_after_install() { |
266 | 266 | |
267 | - if ( ! is_admin() ) { |
|
267 | + if ( ! is_admin()) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - $give_options = Give_Cache::get( '_give_installed', true ); |
|
272 | - $give_table_check = get_option( '_give_table_check', false ); |
|
271 | + $give_options = Give_Cache::get('_give_installed', true); |
|
272 | + $give_table_check = get_option('_give_table_check', false); |
|
273 | 273 | |
274 | - if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) { |
|
274 | + if (false === $give_table_check || current_time('timestamp') > $give_table_check) { |
|
275 | 275 | |
276 | - if ( ! @Give()->customer_meta->installed() ) { |
|
276 | + if ( ! @Give()->customer_meta->installed()) { |
|
277 | 277 | |
278 | 278 | // Create the customer meta database |
279 | 279 | // (this ensures it creates it on multisite instances where it is network activated). |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | } |
283 | 283 | |
284 | - if ( ! @Give()->customers->installed() ) { |
|
284 | + if ( ! @Give()->customers->installed()) { |
|
285 | 285 | // Create the customers database |
286 | 286 | // (this ensures it creates it on multisite instances where it is network activated). |
287 | 287 | @Give()->customers->create_table(); |
@@ -293,22 +293,22 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @param array $give_options Give plugin options. |
295 | 295 | */ |
296 | - do_action( 'give_after_install', $give_options ); |
|
296 | + do_action('give_after_install', $give_options); |
|
297 | 297 | } |
298 | 298 | |
299 | - update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ) ); |
|
299 | + update_option('_give_table_check', (current_time('timestamp') + WEEK_IN_SECONDS)); |
|
300 | 300 | |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Delete the transient |
304 | - if ( false !== $give_options ) { |
|
305 | - Give_Cache::delete( Give_Cache::get_key( '_give_installed' ) ); |
|
304 | + if (false !== $give_options) { |
|
305 | + Give_Cache::delete(Give_Cache::get_key('_give_installed')); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
309 | 309 | } |
310 | 310 | |
311 | -add_action( 'admin_init', 'give_after_install' ); |
|
311 | +add_action('admin_init', 'give_after_install'); |
|
312 | 312 | |
313 | 313 | |
314 | 314 | /** |
@@ -323,11 +323,11 @@ discard block |
||
323 | 323 | |
324 | 324 | global $wp_roles; |
325 | 325 | |
326 | - if ( ! is_object( $wp_roles ) ) { |
|
326 | + if ( ! is_object($wp_roles)) { |
|
327 | 327 | return; |
328 | 328 | } |
329 | 329 | |
330 | - if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) { |
|
330 | + if ( ! array_key_exists('give_manager', $wp_roles->roles)) { |
|
331 | 331 | |
332 | 332 | // Create Give plugin roles |
333 | 333 | $roles = new Give_Roles(); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | |
339 | 339 | } |
340 | 340 | |
341 | -add_action( 'admin_init', 'give_install_roles_on_network' ); |
|
341 | +add_action('admin_init', 'give_install_roles_on_network'); |
|
342 | 342 | |
343 | 343 | /** |
344 | 344 | * Default core setting values. |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | 'paypal_verification' => 'enabled', |
379 | 379 | |
380 | 380 | // Default is manual gateway. |
381 | - 'gateways' => array( 'manual' => 1, 'offline' => 1 ), |
|
381 | + 'gateways' => array('manual' => 1, 'offline' => 1), |
|
382 | 382 | 'default_gateway' => 'manual', |
383 | 383 | |
384 | 384 | // Offline gateway setup. |
@@ -12,7 +12,7 @@ discard block |
||
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 | |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | 'v1' => 'GIVE_API_V1', |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $this->get_versions() as $version => $class ) { |
|
144 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
143 | + foreach ($this->get_versions() as $version => $class) { |
|
144 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
145 | 145 | } |
146 | 146 | |
147 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
148 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
149 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
150 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
154 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
147 | + add_action('init', array($this, 'add_endpoint')); |
|
148 | + add_action('wp', array($this, 'process_query'), - 1); |
|
149 | + add_filter('query_vars', array($this, 'query_vars')); |
|
150 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('personal_options_update', array($this, 'update_key')); |
|
153 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
154 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
155 | 155 | |
156 | 156 | // Setup a backwards compatibility check for user API Keys |
157 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
157 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
158 | 158 | |
159 | 159 | // Determine if JSON_PRETTY_PRINT is available |
160 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
160 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
161 | 161 | |
162 | 162 | // Allow API request logging to be turned off |
163 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
163 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
164 | 164 | |
165 | 165 | // Setup Give_Payment_Stats instance |
166 | 166 | $this->stats = new Give_Payment_Stats; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @since 1.1 |
178 | 178 | */ |
179 | - public function add_endpoint( $rewrite_rules ) { |
|
180 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
179 | + public function add_endpoint($rewrite_rules) { |
|
180 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] $vars New query vars |
192 | 192 | */ |
193 | - public function query_vars( $vars ) { |
|
193 | + public function query_vars($vars) { |
|
194 | 194 | |
195 | 195 | $vars[] = 'token'; |
196 | 196 | $vars[] = 'key'; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function get_default_version() { |
243 | 243 | |
244 | - $version = get_option( 'give_default_api_version' ); |
|
244 | + $version = get_option('give_default_api_version'); |
|
245 | 245 | |
246 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
246 | + if (defined('GIVE_API_VERSION')) { |
|
247 | 247 | $version = GIVE_API_VERSION; |
248 | - } elseif ( ! $version ) { |
|
248 | + } elseif ( ! $version) { |
|
249 | 249 | $version = 'v1'; |
250 | 250 | } |
251 | 251 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | $version = $wp_query->query_vars['give-api']; |
268 | 268 | |
269 | - if ( strpos( $version, '/' ) ) { |
|
269 | + if (strpos($version, '/')) { |
|
270 | 270 | |
271 | - $version = explode( '/', $version ); |
|
272 | - $version = strtolower( $version[0] ); |
|
271 | + $version = explode('/', $version); |
|
272 | + $version = strtolower($version[0]); |
|
273 | 273 | |
274 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
274 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
275 | 275 | |
276 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
276 | + if (array_key_exists($version, $this->versions)) { |
|
277 | 277 | |
278 | 278 | $this->queried_version = $version; |
279 | 279 | |
@@ -309,32 +309,32 @@ discard block |
||
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 |
||
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 = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
|
364 | + $user = Give_Cache::get(md5('give_api_user_'.$key), true); |
|
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 | - Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
|
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 | + Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true); |
|
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 |
||
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 = Give_Cache::get( $cache_key, true ); |
|
387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
388 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
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 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
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 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
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 = Give_Cache::get( $cache_key, true ); |
|
405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
406 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
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 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
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 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | */ |
424 | 424 | private function missing_auth() { |
425 | 425 | $error = array(); |
426 | - $error['error'] = esc_html__( 'You must specify both a token and API key.', 'give' ); |
|
426 | + $error['error'] = esc_html__('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 |
||
440 | 440 | */ |
441 | 441 | private function invalid_auth() { |
442 | 442 | $error = array(); |
443 | - $error['error'] = esc_html__( 'Your request could not be authenticated.', 'give' ); |
|
443 | + $error['error'] = esc_html__('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 |
||
457 | 457 | */ |
458 | 458 | private function invalid_key() { |
459 | 459 | $error = array(); |
460 | - $error['error'] = esc_html__( 'Invalid API key.', 'give' ); |
|
460 | + $error['error'] = esc_html__('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 |
||
473 | 473 | */ |
474 | 474 | private function invalid_version() { |
475 | 475 | $error = array(); |
476 | - $error['error'] = esc_html__( 'Invalid API version.', 'give' ); |
|
476 | + $error['error'] = esc_html__('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 |
||
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 |
||
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 |
||
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 |
||
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'] = esc_html__( 'Invalid query.', 'give' ); |
|
613 | + if ( ! in_array($query, $accepted)) { |
|
614 | + $error['error'] = esc_html__('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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | - } elseif ( $month_now <= 6 ) { |
|
759 | + } elseif ($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 | - } elseif ( $month_now <= 9 ) { |
|
765 | + } elseif ($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 | - } elseif ( $month_now <= 6 ) { |
|
791 | + } elseif ($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 | - } elseif ( $month_now <= 9 ) { |
|
797 | + } elseif ($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 |
||
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; |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | * |
834 | 834 | * @param array $dates The dates used for retrieving earnings/donations |
835 | 835 | */ |
836 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
836 | + return apply_filters('give_api_stat_dates', $dates); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -848,11 +848,11 @@ discard block |
||
848 | 848 | * |
849 | 849 | * @return array $customers Multidimensional array of the customers |
850 | 850 | */ |
851 | - public function get_customers( $customer = null ) { |
|
851 | + public function get_customers($customer = null) { |
|
852 | 852 | |
853 | 853 | $customers = array(); |
854 | 854 | $error = array(); |
855 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
855 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
856 | 856 | return $customers; |
857 | 857 | } |
858 | 858 | |
@@ -860,63 +860,63 @@ discard block |
||
860 | 860 | |
861 | 861 | $paged = $this->get_paged(); |
862 | 862 | $per_page = $this->per_page(); |
863 | - $offset = $per_page * ( $paged - 1 ); |
|
863 | + $offset = $per_page * ($paged - 1); |
|
864 | 864 | |
865 | - if ( is_numeric( $customer ) ) { |
|
865 | + if (is_numeric($customer)) { |
|
866 | 866 | $field = 'id'; |
867 | 867 | } else { |
868 | 868 | $field = 'email'; |
869 | 869 | } |
870 | 870 | |
871 | - $customer_query = Give()->customers->get_customers( array( |
|
871 | + $customer_query = Give()->customers->get_customers(array( |
|
872 | 872 | 'number' => $per_page, |
873 | 873 | 'offset' => $offset, |
874 | 874 | $field => $customer, |
875 | - ) ); |
|
875 | + )); |
|
876 | 876 | $customer_count = 0; |
877 | 877 | |
878 | - if ( $customer_query ) { |
|
878 | + if ($customer_query) { |
|
879 | 879 | |
880 | - foreach ( $customer_query as $customer_obj ) { |
|
880 | + foreach ($customer_query as $customer_obj) { |
|
881 | 881 | |
882 | - $names = explode( ' ', $customer_obj->name ); |
|
883 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
882 | + $names = explode(' ', $customer_obj->name); |
|
883 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
884 | 884 | $last_name = ''; |
885 | - if ( ! empty( $names[1] ) ) { |
|
886 | - unset( $names[0] ); |
|
887 | - $last_name = implode( ' ', $names ); |
|
885 | + if ( ! empty($names[1])) { |
|
886 | + unset($names[0]); |
|
887 | + $last_name = implode(' ', $names); |
|
888 | 888 | } |
889 | 889 | |
890 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
891 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
892 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
894 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
895 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
896 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
890 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
891 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
892 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
894 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
895 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
896 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
897 | 897 | |
898 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
898 | + if ( ! empty($customer_obj->user_id)) { |
|
899 | 899 | |
900 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
900 | + $user_data = get_userdata($customer_obj->user_id); |
|
901 | 901 | |
902 | 902 | // Customer with registered account. |
903 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
904 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
905 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
903 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
904 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
905 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
906 | 906 | |
907 | 907 | } |
908 | 908 | |
909 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
910 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
909 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
910 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
911 | 911 | |
912 | - $customer_count ++; |
|
912 | + $customer_count++; |
|
913 | 913 | |
914 | 914 | } |
915 | - } elseif ( $customer ) { |
|
915 | + } elseif ($customer) { |
|
916 | 916 | |
917 | 917 | $error['error'] = sprintf( |
918 | 918 | /* translators: %s: customer */ |
919 | - esc_html__( 'Donor %s not found.', 'give' ), |
|
919 | + esc_html__('Donor %s not found.', 'give'), |
|
920 | 920 | $customer |
921 | 921 | ); |
922 | 922 | |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | |
925 | 925 | } else { |
926 | 926 | |
927 | - $error['error'] = esc_html__( 'No donors found.', 'give' ); |
|
927 | + $error['error'] = esc_html__('No donors found.', 'give'); |
|
928 | 928 | |
929 | 929 | return $error; |
930 | 930 | |
@@ -943,38 +943,38 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @return array $customers Multidimensional array of the forms |
945 | 945 | */ |
946 | - public function get_forms( $form = null ) { |
|
946 | + public function get_forms($form = null) { |
|
947 | 947 | |
948 | 948 | $forms = array(); |
949 | 949 | $error = array(); |
950 | 950 | |
951 | - if ( $form == null ) { |
|
951 | + if ($form == null) { |
|
952 | 952 | $forms['forms'] = array(); |
953 | 953 | |
954 | - $form_list = get_posts( array( |
|
954 | + $form_list = get_posts(array( |
|
955 | 955 | 'post_type' => 'give_forms', |
956 | 956 | 'posts_per_page' => $this->per_page(), |
957 | 957 | 'suppress_filters' => true, |
958 | 958 | 'paged' => $this->get_paged(), |
959 | - ) ); |
|
959 | + )); |
|
960 | 960 | |
961 | - if ( $form_list ) { |
|
961 | + if ($form_list) { |
|
962 | 962 | $i = 0; |
963 | - foreach ( $form_list as $form_info ) { |
|
964 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
965 | - $i ++; |
|
963 | + foreach ($form_list as $form_info) { |
|
964 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
965 | + $i++; |
|
966 | 966 | } |
967 | 967 | } |
968 | 968 | } else { |
969 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
970 | - $form_info = get_post( $form ); |
|
969 | + if (get_post_type($form) == 'give_forms') { |
|
970 | + $form_info = get_post($form); |
|
971 | 971 | |
972 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
972 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
973 | 973 | |
974 | 974 | } else { |
975 | 975 | $error['error'] = sprintf( |
976 | 976 | /* translators: %s: form */ |
977 | - esc_html__( 'Form %s not found.', 'give' ), |
|
977 | + esc_html__('Form %s not found.', 'give'), |
|
978 | 978 | $form |
979 | 979 | ); |
980 | 980 | |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @return array Array of post data to return back in the API |
996 | 996 | */ |
997 | - private function get_form_data( $form_info ) { |
|
997 | + private function get_form_data($form_info) { |
|
998 | 998 | |
999 | 999 | $form = array(); |
1000 | 1000 | |
@@ -1004,50 +1004,50 @@ discard block |
||
1004 | 1004 | $form['info']['create_date'] = $form_info->post_date; |
1005 | 1005 | $form['info']['modified_date'] = $form_info->post_modified; |
1006 | 1006 | $form['info']['status'] = $form_info->post_status; |
1007 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1008 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1009 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1007 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1008 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1009 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1010 | 1010 | |
1011 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
1012 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1013 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1011 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
1012 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1013 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1014 | 1014 | } |
1015 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
1016 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1015 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
1016 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1020 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1021 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1022 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1023 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1019 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1020 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1021 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1022 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1023 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | $counter = 0; |
1027 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1028 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1029 | - $counter ++; |
|
1027 | + if (give_has_variable_prices($form_info->ID)) { |
|
1028 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1029 | + $counter++; |
|
1030 | 1030 | // muli-level item |
1031 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1032 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1031 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1032 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1033 | 1033 | |
1034 | 1034 | } |
1035 | 1035 | } else { |
1036 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1036 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1039 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1040 | 1040 | |
1041 | 1041 | /** |
1042 | 1042 | * Fires when generating API sensitive data. |
1043 | 1043 | * |
1044 | 1044 | * @since 1.1 |
1045 | 1045 | */ |
1046 | - do_action( 'give_api_sensitive_data' ); |
|
1046 | + do_action('give_api_sensitive_data'); |
|
1047 | 1047 | |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1050 | + return apply_filters('give_api_forms_form', $form); |
|
1051 | 1051 | |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | * |
1063 | 1063 | * @return array |
1064 | 1064 | */ |
1065 | - public function get_stats( $args = array() ) { |
|
1065 | + public function get_stats($args = array()) { |
|
1066 | 1066 | $defaults = array( |
1067 | 1067 | 'type' => null, |
1068 | 1068 | 'form' => null, |
@@ -1071,9 +1071,9 @@ discard block |
||
1071 | 1071 | 'enddate' => null, |
1072 | 1072 | ); |
1073 | 1073 | |
1074 | - $args = wp_parse_args( $args, $defaults ); |
|
1074 | + $args = wp_parse_args($args, $defaults); |
|
1075 | 1075 | |
1076 | - $dates = $this->get_dates( $args ); |
|
1076 | + $dates = $this->get_dates($args); |
|
1077 | 1077 | |
1078 | 1078 | $stats = array(); |
1079 | 1079 | $earnings = array( |
@@ -1084,40 +1084,40 @@ discard block |
||
1084 | 1084 | ); |
1085 | 1085 | $error = array(); |
1086 | 1086 | |
1087 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1087 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1088 | 1088 | return $stats; |
1089 | 1089 | } |
1090 | 1090 | |
1091 | - if ( $args['type'] == 'donations' ) { |
|
1091 | + if ($args['type'] == 'donations') { |
|
1092 | 1092 | |
1093 | - if ( $args['form'] == null ) { |
|
1094 | - if ( $args['date'] == null ) { |
|
1093 | + if ($args['form'] == null) { |
|
1094 | + if ($args['date'] == null) { |
|
1095 | 1095 | $sales = $this->get_default_sales_stats(); |
1096 | - } elseif ( $args['date'] === 'range' ) { |
|
1096 | + } elseif ($args['date'] === 'range') { |
|
1097 | 1097 | // Return sales for a date range |
1098 | 1098 | // Ensure the end date is later than the start date |
1099 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1100 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1099 | + if ($args['enddate'] < $args['startdate']) { |
|
1100 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Ensure both the start and end date are specified |
1104 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1105 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1104 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1105 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $total = 0; |
1109 | 1109 | |
1110 | 1110 | // Loop through the years |
1111 | 1111 | $y = $dates['year']; |
1112 | - while ( $y <= $dates['year_end'] ) : |
|
1112 | + while ($y <= $dates['year_end']) : |
|
1113 | 1113 | |
1114 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1114 | + if ($dates['year'] == $dates['year_end']) { |
|
1115 | 1115 | $month_start = $dates['m_start']; |
1116 | 1116 | $month_end = $dates['m_end']; |
1117 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1117 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1118 | 1118 | $month_start = $dates['m_start']; |
1119 | 1119 | $month_end = 12; |
1120 | - } elseif ( $y == $dates['year_end'] ) { |
|
1120 | + } elseif ($y == $dates['year_end']) { |
|
1121 | 1121 | $month_start = 1; |
1122 | 1122 | $month_end = $dates['m_end']; |
1123 | 1123 | } else { |
@@ -1126,112 +1126,112 @@ discard block |
||
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | $i = $month_start; |
1129 | - while ( $i <= $month_end ) : |
|
1129 | + while ($i <= $month_end) : |
|
1130 | 1130 | |
1131 | - if ( $i == $dates['m_start'] ) { |
|
1131 | + if ($i == $dates['m_start']) { |
|
1132 | 1132 | $d = $dates['day_start']; |
1133 | 1133 | } else { |
1134 | 1134 | $d = 1; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if ( $i == $dates['m_end'] ) { |
|
1137 | + if ($i == $dates['m_end']) { |
|
1138 | 1138 | $num_of_days = $dates['day_end']; |
1139 | 1139 | } else { |
1140 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1140 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - while ( $d <= $num_of_days ) : |
|
1144 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1145 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1146 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1147 | - $sales['sales'][ $date_key ] = 0; |
|
1143 | + while ($d <= $num_of_days) : |
|
1144 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1145 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1146 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1147 | + $sales['sales'][$date_key] = 0; |
|
1148 | 1148 | } |
1149 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1149 | + $sales['sales'][$date_key] += $sale_count; |
|
1150 | 1150 | $total += $sale_count; |
1151 | - $d ++; |
|
1151 | + $d++; |
|
1152 | 1152 | endwhile; |
1153 | - $i ++; |
|
1153 | + $i++; |
|
1154 | 1154 | endwhile; |
1155 | 1155 | |
1156 | - $y ++; |
|
1156 | + $y++; |
|
1157 | 1157 | endwhile; |
1158 | 1158 | |
1159 | 1159 | $sales['totals'] = $total; |
1160 | 1160 | } else { |
1161 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1161 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1162 | 1162 | $sales_count = 0; |
1163 | 1163 | |
1164 | 1164 | // Loop through the months |
1165 | 1165 | $month = $dates['m_start']; |
1166 | 1166 | |
1167 | - while ( $month <= $dates['m_end'] ) : |
|
1168 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1169 | - $month ++; |
|
1167 | + while ($month <= $dates['m_end']) : |
|
1168 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1169 | + $month++; |
|
1170 | 1170 | endwhile; |
1171 | 1171 | |
1172 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1172 | + $sales['donations'][$args['date']] = $sales_count; |
|
1173 | 1173 | } else { |
1174 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1174 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1175 | 1175 | } |
1176 | 1176 | } |
1177 | - } elseif ( $args['form'] == 'all' ) { |
|
1178 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1177 | + } elseif ($args['form'] == 'all') { |
|
1178 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1179 | 1179 | $i = 0; |
1180 | - foreach ( $forms as $form_info ) { |
|
1181 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1182 | - $i ++; |
|
1180 | + foreach ($forms as $form_info) { |
|
1181 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1182 | + $i++; |
|
1183 | 1183 | } |
1184 | 1184 | } else { |
1185 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1186 | - $form_info = get_post( $args['form'] ); |
|
1187 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1185 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1186 | + $form_info = get_post($args['form']); |
|
1187 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1188 | 1188 | } else { |
1189 | 1189 | $error['error'] = sprintf( |
1190 | 1190 | /* translators: %s: form */ |
1191 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1191 | + esc_html__('Form %s not found.', 'give'), |
|
1192 | 1192 | $args['form'] |
1193 | 1193 | ); |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( ! empty( $error ) ) { |
|
1197 | + if ( ! empty($error)) { |
|
1198 | 1198 | return $error; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | return $sales; |
1202 | 1202 | |
1203 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1204 | - if ( $args['form'] == null ) { |
|
1205 | - if ( $args['date'] == null ) { |
|
1203 | + } elseif ($args['type'] == 'earnings') { |
|
1204 | + if ($args['form'] == null) { |
|
1205 | + if ($args['date'] == null) { |
|
1206 | 1206 | $earnings = $this->get_default_earnings_stats(); |
1207 | - } elseif ( $args['date'] === 'range' ) { |
|
1207 | + } elseif ($args['date'] === 'range') { |
|
1208 | 1208 | // Return sales for a date range |
1209 | 1209 | // Ensure the end date is later than the start date |
1210 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1211 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1210 | + if ($args['enddate'] < $args['startdate']) { |
|
1211 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Ensure both the start and end date are specified |
1215 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1216 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1215 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1216 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | $total = (float) 0.00; |
1220 | 1220 | |
1221 | 1221 | // Loop through the years |
1222 | 1222 | $y = $dates['year']; |
1223 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1223 | + if ( ! isset($earnings['earnings'])) { |
|
1224 | 1224 | $earnings['earnings'] = array(); |
1225 | 1225 | } |
1226 | - while ( $y <= $dates['year_end'] ) : |
|
1226 | + while ($y <= $dates['year_end']) : |
|
1227 | 1227 | |
1228 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1228 | + if ($dates['year'] == $dates['year_end']) { |
|
1229 | 1229 | $month_start = $dates['m_start']; |
1230 | 1230 | $month_end = $dates['m_end']; |
1231 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1231 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1232 | 1232 | $month_start = $dates['m_start']; |
1233 | 1233 | $month_end = 12; |
1234 | - } elseif ( $y == $dates['year_end'] ) { |
|
1234 | + } elseif ($y == $dates['year_end']) { |
|
1235 | 1235 | $month_start = 1; |
1236 | 1236 | $month_end = $dates['m_end']; |
1237 | 1237 | } else { |
@@ -1240,92 +1240,92 @@ discard block |
||
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | $i = $month_start; |
1243 | - while ( $i <= $month_end ) : |
|
1243 | + while ($i <= $month_end) : |
|
1244 | 1244 | |
1245 | - if ( $i == $dates['m_start'] ) { |
|
1245 | + if ($i == $dates['m_start']) { |
|
1246 | 1246 | $d = $dates['day_start']; |
1247 | 1247 | } else { |
1248 | 1248 | $d = 1; |
1249 | 1249 | } |
1250 | 1250 | |
1251 | - if ( $i == $dates['m_end'] ) { |
|
1251 | + if ($i == $dates['m_end']) { |
|
1252 | 1252 | $num_of_days = $dates['day_end']; |
1253 | 1253 | } else { |
1254 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1254 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | - while ( $d <= $num_of_days ) : |
|
1258 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1259 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1260 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1261 | - $earnings['earnings'][ $date_key ] = 0; |
|
1257 | + while ($d <= $num_of_days) : |
|
1258 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1259 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1260 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1261 | + $earnings['earnings'][$date_key] = 0; |
|
1262 | 1262 | } |
1263 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1263 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1264 | 1264 | $total += $earnings_stat; |
1265 | - $d ++; |
|
1265 | + $d++; |
|
1266 | 1266 | endwhile; |
1267 | 1267 | |
1268 | - $i ++; |
|
1268 | + $i++; |
|
1269 | 1269 | endwhile; |
1270 | 1270 | |
1271 | - $y ++; |
|
1271 | + $y++; |
|
1272 | 1272 | endwhile; |
1273 | 1273 | |
1274 | 1274 | $earnings['totals'] = $total; |
1275 | 1275 | } else { |
1276 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1276 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1277 | 1277 | $earnings_count = (float) 0.00; |
1278 | 1278 | |
1279 | 1279 | // Loop through the months |
1280 | 1280 | $month = $dates['m_start']; |
1281 | 1281 | |
1282 | - while ( $month <= $dates['m_end'] ) : |
|
1283 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1284 | - $month ++; |
|
1282 | + while ($month <= $dates['m_end']) : |
|
1283 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1284 | + $month++; |
|
1285 | 1285 | endwhile; |
1286 | 1286 | |
1287 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1287 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1288 | 1288 | } else { |
1289 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1289 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | - } elseif ( $args['form'] == 'all' ) { |
|
1293 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1292 | + } elseif ($args['form'] == 'all') { |
|
1293 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1294 | 1294 | |
1295 | 1295 | $i = 0; |
1296 | - foreach ( $forms as $form_info ) { |
|
1297 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1298 | - $i ++; |
|
1296 | + foreach ($forms as $form_info) { |
|
1297 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1298 | + $i++; |
|
1299 | 1299 | } |
1300 | 1300 | } else { |
1301 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1302 | - $form_info = get_post( $args['form'] ); |
|
1303 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1301 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1302 | + $form_info = get_post($args['form']); |
|
1303 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1304 | 1304 | } else { |
1305 | 1305 | $error['error'] = sprintf( |
1306 | 1306 | /* translators: %s: form */ |
1307 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1307 | + esc_html__('Form %s not found.', 'give'), |
|
1308 | 1308 | $args['form'] |
1309 | 1309 | ); |
1310 | 1310 | } |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( ! empty( $error ) ) { |
|
1313 | + if ( ! empty($error)) { |
|
1314 | 1314 | return $error; |
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $earnings; |
1318 | - } elseif ( $args['type'] == 'donors' ) { |
|
1318 | + } elseif ($args['type'] == 'donors') { |
|
1319 | 1319 | $customers = new Give_DB_Customers(); |
1320 | 1320 | $stats['donations']['total_donors'] = $customers->count(); |
1321 | 1321 | |
1322 | 1322 | return $stats; |
1323 | 1323 | |
1324 | - } elseif ( empty( $args['type'] ) ) { |
|
1325 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1326 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1324 | + } elseif (empty($args['type'])) { |
|
1325 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1326 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1327 | 1327 | |
1328 | - return array( 'stats' => $stats ); |
|
1328 | + return array('stats' => $stats); |
|
1329 | 1329 | } |
1330 | 1330 | } |
1331 | 1331 | |
@@ -1341,18 +1341,18 @@ discard block |
||
1341 | 1341 | |
1342 | 1342 | $sales = array(); |
1343 | 1343 | |
1344 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1344 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1345 | 1345 | return $sales; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1348 | + if (isset($wp_query->query_vars['id'])) { |
|
1349 | 1349 | $query = array(); |
1350 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1351 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1350 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1351 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1352 | 1352 | $query = array(); |
1353 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1354 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1355 | - $args = array( |
|
1353 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1354 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1355 | + $args = array( |
|
1356 | 1356 | 'fields' => 'ids', |
1357 | 1357 | 'meta_key' => '_give_payment_user_email', |
1358 | 1358 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1360,7 +1360,7 @@ discard block |
||
1360 | 1360 | 'page' => $this->get_paged(), |
1361 | 1361 | 'status' => 'publish', |
1362 | 1362 | ); |
1363 | - $query = give_get_payments( $args ); |
|
1363 | + $query = give_get_payments($args); |
|
1364 | 1364 | } else { |
1365 | 1365 | $args = array( |
1366 | 1366 | 'fields' => 'ids', |
@@ -1368,14 +1368,14 @@ discard block |
||
1368 | 1368 | 'page' => $this->get_paged(), |
1369 | 1369 | 'status' => 'publish', |
1370 | 1370 | ); |
1371 | - $query = give_get_payments( $args ); |
|
1371 | + $query = give_get_payments($args); |
|
1372 | 1372 | } |
1373 | - if ( $query ) { |
|
1373 | + if ($query) { |
|
1374 | 1374 | $i = 0; |
1375 | - foreach ( $query as $payment ) { |
|
1375 | + foreach ($query as $payment) { |
|
1376 | 1376 | |
1377 | - if ( is_numeric( $payment ) ) { |
|
1378 | - $payment = new Give_Payment( $payment ); |
|
1377 | + if (is_numeric($payment)) { |
|
1378 | + $payment = new Give_Payment($payment); |
|
1379 | 1379 | $payment_meta = $payment->get_meta(); |
1380 | 1380 | $user_info = $payment->user_info; |
1381 | 1381 | } else { |
@@ -1385,40 +1385,40 @@ discard block |
||
1385 | 1385 | $payment_meta = $payment->get_meta(); |
1386 | 1386 | $user_info = $payment->user_info; |
1387 | 1387 | |
1388 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1389 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1390 | - |
|
1391 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1392 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1393 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1394 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1395 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1396 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1397 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1398 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1399 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1400 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1401 | - |
|
1402 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1404 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1405 | - |
|
1406 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1407 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1408 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1409 | - |
|
1410 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1411 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1412 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1413 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1414 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1415 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1388 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1389 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1390 | + |
|
1391 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1392 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1393 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1394 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1395 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1396 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1397 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1398 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1399 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1400 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1401 | + |
|
1402 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1404 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1405 | + |
|
1406 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1407 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1408 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1409 | + |
|
1410 | + if (give_has_variable_prices($form_id)) { |
|
1411 | + if (isset($payment_meta['price_id'])) { |
|
1412 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1413 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1414 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1415 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1416 | 1416 | |
1417 | 1417 | } |
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | // Add custom meta to API |
1421 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1421 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1422 | 1422 | |
1423 | 1423 | $exceptions = array( |
1424 | 1424 | 'form_title', |
@@ -1431,19 +1431,19 @@ discard block |
||
1431 | 1431 | ); |
1432 | 1432 | |
1433 | 1433 | // Don't clutter up results with dupes |
1434 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1434 | + if (in_array($meta_key, $exceptions)) { |
|
1435 | 1435 | continue; |
1436 | 1436 | } |
1437 | 1437 | |
1438 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1438 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1439 | 1439 | |
1440 | 1440 | } |
1441 | 1441 | |
1442 | - $i ++; |
|
1442 | + $i++; |
|
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1446 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | /** |
@@ -1459,9 +1459,9 @@ discard block |
||
1459 | 1459 | public function get_output_format() { |
1460 | 1460 | global $wp_query; |
1461 | 1461 | |
1462 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1462 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1463 | 1463 | |
1464 | - return apply_filters( 'give_api_output_format', $format ); |
|
1464 | + return apply_filters('give_api_output_format', $format); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | 1467 | |
@@ -1478,8 +1478,8 @@ discard block |
||
1478 | 1478 | * |
1479 | 1479 | * @return void |
1480 | 1480 | */ |
1481 | - private function log_request( $data = array() ) { |
|
1482 | - if ( ! $this->log_requests ) { |
|
1481 | + private function log_request($data = array()) { |
|
1482 | + if ( ! $this->log_requests) { |
|
1483 | 1483 | return; |
1484 | 1484 | } |
1485 | 1485 | |
@@ -1495,36 +1495,36 @@ discard block |
||
1495 | 1495 | |
1496 | 1496 | $query = array( |
1497 | 1497 | 'give-api' => $wp_query->query_vars['give-api'], |
1498 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1499 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1500 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1501 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1502 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1503 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1504 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1505 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1506 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1507 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1508 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1509 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1498 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1499 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1500 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1501 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1502 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1503 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1504 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1505 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1506 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1507 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1508 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1509 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1510 | 1510 | ); |
1511 | 1511 | |
1512 | 1512 | $log_data = array( |
1513 | 1513 | 'log_type' => 'api_request', |
1514 | - 'post_excerpt' => http_build_query( $query ), |
|
1515 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1514 | + 'post_excerpt' => http_build_query($query), |
|
1515 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1516 | 1516 | ); |
1517 | 1517 | |
1518 | 1518 | $log_meta = array( |
1519 | 1519 | 'request_ip' => give_get_ip(), |
1520 | 1520 | 'user' => $this->user_id, |
1521 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1522 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1521 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1522 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1523 | 1523 | 'time' => $data['request_speed'], |
1524 | 1524 | 'version' => $this->get_queried_version(), |
1525 | 1525 | ); |
1526 | 1526 | |
1527 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1527 | + $give_logs->insert_log($log_data, $log_meta); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | * |
1549 | 1549 | * @param int $status_code |
1550 | 1550 | */ |
1551 | - public function output( $status_code = 200 ) { |
|
1551 | + public function output($status_code = 200) { |
|
1552 | 1552 | /** |
1553 | 1553 | * @var WP_Query $wp_query |
1554 | 1554 | */ |
@@ -1556,7 +1556,7 @@ discard block |
||
1556 | 1556 | |
1557 | 1557 | $format = $this->get_output_format(); |
1558 | 1558 | |
1559 | - status_header( $status_code ); |
|
1559 | + status_header($status_code); |
|
1560 | 1560 | |
1561 | 1561 | /** |
1562 | 1562 | * Fires before outputing the API. |
@@ -1567,25 +1567,25 @@ discard block |
||
1567 | 1567 | * @param Give_API $this The Give_API object. |
1568 | 1568 | * @param string $format Output format, XML or JSON. Default is JSON. |
1569 | 1569 | */ |
1570 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1570 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1571 | 1571 | |
1572 | - switch ( $format ) : |
|
1572 | + switch ($format) : |
|
1573 | 1573 | |
1574 | 1574 | case 'xml' : |
1575 | 1575 | |
1576 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1577 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1576 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1577 | + $xml = Array2XML::createXML('give', $this->data); |
|
1578 | 1578 | echo $xml->saveXML(); |
1579 | 1579 | |
1580 | 1580 | break; |
1581 | 1581 | |
1582 | 1582 | case 'json' : |
1583 | 1583 | |
1584 | - header( 'Content-Type: application/json' ); |
|
1585 | - if ( ! empty( $this->pretty_print ) ) { |
|
1586 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1584 | + header('Content-Type: application/json'); |
|
1585 | + if ( ! empty($this->pretty_print)) { |
|
1586 | + echo json_encode($this->data, $this->pretty_print); |
|
1587 | 1587 | } else { |
1588 | - echo json_encode( $this->data ); |
|
1588 | + echo json_encode($this->data); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | break; |
@@ -1600,7 +1600,7 @@ discard block |
||
1600 | 1600 | * @param array $data Response data to return. |
1601 | 1601 | * @param Give_API $this The Give_API object. |
1602 | 1602 | */ |
1603 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
1603 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
1604 | 1604 | |
1605 | 1605 | break; |
1606 | 1606 | |
@@ -1615,7 +1615,7 @@ discard block |
||
1615 | 1615 | * @param Give_API $this The Give_API object. |
1616 | 1616 | * @param string $format Output format, XML or JSON. Default is JSON. |
1617 | 1617 | */ |
1618 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1618 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1619 | 1619 | |
1620 | 1620 | give_die(); |
1621 | 1621 | } |
@@ -1632,40 +1632,40 @@ discard block |
||
1632 | 1632 | * |
1633 | 1633 | * @return void |
1634 | 1634 | */ |
1635 | - function user_key_field( $user ) { |
|
1635 | + function user_key_field($user) { |
|
1636 | 1636 | |
1637 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1638 | - $user = get_userdata( $user->ID ); |
|
1637 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1638 | + $user = get_userdata($user->ID); |
|
1639 | 1639 | ?> |
1640 | 1640 | <table class="form-table"> |
1641 | 1641 | <tbody> |
1642 | 1642 | <tr> |
1643 | 1643 | <th> |
1644 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1644 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1645 | 1645 | </th> |
1646 | 1646 | <td> |
1647 | 1647 | <?php |
1648 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1649 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1648 | + $public_key = $this->get_user_public_key($user->ID); |
|
1649 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1650 | 1650 | ?> |
1651 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1651 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1652 | 1652 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1653 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1653 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1654 | 1654 | <?php } else { ?> |
1655 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> |
|
1655 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> |
|
1656 | 1656 | </strong> |
1657 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1657 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1658 | 1658 | <br/> |
1659 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> |
|
1659 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> |
|
1660 | 1660 | </strong> |
1661 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1661 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1662 | 1662 | <br/> |
1663 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> |
|
1663 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> |
|
1664 | 1664 | </strong> |
1665 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1665 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1666 | 1666 | <br/> |
1667 | 1667 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1668 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1668 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1669 | 1669 | <?php } ?> |
1670 | 1670 | </td> |
1671 | 1671 | </tr> |
@@ -1684,69 +1684,69 @@ discard block |
||
1684 | 1684 | * |
1685 | 1685 | * @return void |
1686 | 1686 | */ |
1687 | - public function process_api_key( $args ) { |
|
1687 | + public function process_api_key($args) { |
|
1688 | 1688 | |
1689 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1689 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1690 | 1690 | |
1691 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1691 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
1692 | 1692 | |
1693 | 1693 | } |
1694 | 1694 | |
1695 | - if ( empty( $args['user_id'] ) ) { |
|
1696 | - wp_die( esc_html__( 'User ID Required.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1695 | + if (empty($args['user_id'])) { |
|
1696 | + wp_die(esc_html__('User ID Required.', 'give'), esc_html__('Error', 'give'), array('response' => 401)); |
|
1697 | 1697 | } |
1698 | 1698 | |
1699 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1700 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1699 | + if (is_numeric($args['user_id'])) { |
|
1700 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1701 | 1701 | } else { |
1702 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1702 | + $userdata = get_user_by('login', $args['user_id']); |
|
1703 | 1703 | $user_id = $userdata->ID; |
1704 | 1704 | } |
1705 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1705 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1706 | 1706 | |
1707 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1707 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1708 | 1708 | wp_die( |
1709 | 1709 | sprintf( |
1710 | 1710 | /* translators: %s: process */ |
1711 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1711 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1712 | 1712 | $process |
1713 | 1713 | ), |
1714 | - esc_html__( 'Error', 'give' ), |
|
1715 | - array( 'response' => 403 ) |
|
1714 | + esc_html__('Error', 'give'), |
|
1715 | + array('response' => 403) |
|
1716 | 1716 | ); |
1717 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1717 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1718 | 1718 | wp_die( |
1719 | 1719 | sprintf( |
1720 | 1720 | /* translators: %s: process */ |
1721 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1721 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1722 | 1722 | $process |
1723 | 1723 | ), |
1724 | - esc_html__( 'Error', 'give' ), |
|
1725 | - array( 'response' => 403 ) |
|
1724 | + esc_html__('Error', 'give'), |
|
1725 | + array('response' => 403) |
|
1726 | 1726 | ); |
1727 | 1727 | } |
1728 | 1728 | |
1729 | - switch ( $process ) { |
|
1729 | + switch ($process) { |
|
1730 | 1730 | case 'generate': |
1731 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1732 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1733 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1731 | + if ($this->generate_api_key($user_id)) { |
|
1732 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1733 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1734 | 1734 | exit(); |
1735 | 1735 | } else { |
1736 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1736 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1737 | 1737 | exit(); |
1738 | 1738 | } |
1739 | 1739 | break; |
1740 | 1740 | case 'regenerate': |
1741 | - $this->generate_api_key( $user_id, true ); |
|
1742 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1743 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1741 | + $this->generate_api_key($user_id, true); |
|
1742 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1743 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1744 | 1744 | exit(); |
1745 | 1745 | break; |
1746 | 1746 | case 'revoke': |
1747 | - $this->revoke_api_key( $user_id ); |
|
1748 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1749 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1747 | + $this->revoke_api_key($user_id); |
|
1748 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1749 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1750 | 1750 | exit(); |
1751 | 1751 | break; |
1752 | 1752 | default; |
@@ -1765,34 +1765,34 @@ discard block |
||
1765 | 1765 | * |
1766 | 1766 | * @return boolean True if (re)generated succesfully, false otherwise. |
1767 | 1767 | */ |
1768 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1768 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1769 | 1769 | |
1770 | - if ( empty( $user_id ) ) { |
|
1770 | + if (empty($user_id)) { |
|
1771 | 1771 | return false; |
1772 | 1772 | } |
1773 | 1773 | |
1774 | - $user = get_userdata( $user_id ); |
|
1774 | + $user = get_userdata($user_id); |
|
1775 | 1775 | |
1776 | - if ( ! $user ) { |
|
1776 | + if ( ! $user) { |
|
1777 | 1777 | return false; |
1778 | 1778 | } |
1779 | 1779 | |
1780 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1781 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1780 | + $public_key = $this->get_user_public_key($user_id); |
|
1781 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1782 | 1782 | |
1783 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1784 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1785 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1783 | + if (empty($public_key) || $regenerate == true) { |
|
1784 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1785 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1786 | 1786 | } else { |
1787 | 1787 | return false; |
1788 | 1788 | } |
1789 | 1789 | |
1790 | - if ( $regenerate == true ) { |
|
1791 | - $this->revoke_api_key( $user->ID ); |
|
1790 | + if ($regenerate == true) { |
|
1791 | + $this->revoke_api_key($user->ID); |
|
1792 | 1792 | } |
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 | |
1797 | 1797 | return true; |
1798 | 1798 | } |
@@ -1807,26 +1807,26 @@ discard block |
||
1807 | 1807 | * |
1808 | 1808 | * @return bool |
1809 | 1809 | */ |
1810 | - public function revoke_api_key( $user_id = 0 ) { |
|
1810 | + public function revoke_api_key($user_id = 0) { |
|
1811 | 1811 | |
1812 | - if ( empty( $user_id ) ) { |
|
1812 | + if (empty($user_id)) { |
|
1813 | 1813 | return false; |
1814 | 1814 | } |
1815 | 1815 | |
1816 | - $user = get_userdata( $user_id ); |
|
1816 | + $user = get_userdata($user_id); |
|
1817 | 1817 | |
1818 | - if ( ! $user ) { |
|
1818 | + if ( ! $user) { |
|
1819 | 1819 | return false; |
1820 | 1820 | } |
1821 | 1821 | |
1822 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1823 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1824 | - if ( ! empty( $public_key ) ) { |
|
1825 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
1826 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
1827 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
1828 | - delete_user_meta( $user_id, $public_key ); |
|
1829 | - delete_user_meta( $user_id, $secret_key ); |
|
1822 | + $public_key = $this->get_user_public_key($user_id); |
|
1823 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1824 | + if ( ! empty($public_key)) { |
|
1825 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
1826 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
1827 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
1828 | + delete_user_meta($user_id, $public_key); |
|
1829 | + delete_user_meta($user_id, $secret_key); |
|
1830 | 1830 | } else { |
1831 | 1831 | return false; |
1832 | 1832 | } |
@@ -1851,22 +1851,22 @@ discard block |
||
1851 | 1851 | * |
1852 | 1852 | * @return void |
1853 | 1853 | */ |
1854 | - public function update_key( $user_id ) { |
|
1855 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1854 | + public function update_key($user_id) { |
|
1855 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1856 | 1856 | |
1857 | - $user = get_userdata( $user_id ); |
|
1857 | + $user = get_userdata($user_id); |
|
1858 | 1858 | |
1859 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1860 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1859 | + $public_key = $this->get_user_public_key($user_id); |
|
1860 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1861 | 1861 | |
1862 | - if ( empty( $public_key ) ) { |
|
1863 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1864 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1862 | + if (empty($public_key)) { |
|
1863 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1864 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1865 | 1865 | |
1866 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1867 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1866 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1867 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1868 | 1868 | } else { |
1869 | - $this->revoke_api_key( $user_id ); |
|
1869 | + $this->revoke_api_key($user_id); |
|
1870 | 1870 | } |
1871 | 1871 | } |
1872 | 1872 | } |
@@ -1881,9 +1881,9 @@ discard block |
||
1881 | 1881 | * |
1882 | 1882 | * @return string |
1883 | 1883 | */ |
1884 | - private function generate_public_key( $user_email = '' ) { |
|
1885 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1886 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1884 | + private function generate_public_key($user_email = '') { |
|
1885 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1886 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1887 | 1887 | |
1888 | 1888 | return $public; |
1889 | 1889 | } |
@@ -1898,9 +1898,9 @@ discard block |
||
1898 | 1898 | * |
1899 | 1899 | * @return string |
1900 | 1900 | */ |
1901 | - private function generate_private_key( $user_id = 0 ) { |
|
1902 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1903 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1901 | + private function generate_private_key($user_id = 0) { |
|
1902 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1903 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1904 | 1904 | |
1905 | 1905 | return $secret; |
1906 | 1906 | } |
@@ -1915,8 +1915,8 @@ discard block |
||
1915 | 1915 | * |
1916 | 1916 | * @return string |
1917 | 1917 | */ |
1918 | - public function get_token( $user_id = 0 ) { |
|
1919 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1918 | + public function get_token($user_id = 0) { |
|
1919 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1920 | 1920 | } |
1921 | 1921 | |
1922 | 1922 | /** |
@@ -1930,9 +1930,9 @@ discard block |
||
1930 | 1930 | |
1931 | 1931 | // Default sales return |
1932 | 1932 | $sales = array(); |
1933 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1934 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1935 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1933 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1934 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1935 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1936 | 1936 | $sales['donations']['totals'] = give_get_total_sales(); |
1937 | 1937 | |
1938 | 1938 | return $sales; |
@@ -1949,9 +1949,9 @@ discard block |
||
1949 | 1949 | |
1950 | 1950 | // Default earnings return |
1951 | 1951 | $earnings = array(); |
1952 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1953 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1954 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1952 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1953 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1954 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1955 | 1955 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1956 | 1956 | |
1957 | 1957 | return $earnings; |
@@ -1971,25 +1971,25 @@ discard block |
||
1971 | 1971 | * |
1972 | 1972 | * @return string The API key/secret for the user supplied |
1973 | 1973 | */ |
1974 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1974 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1975 | 1975 | |
1976 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1976 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1977 | 1977 | return $check; |
1978 | 1978 | } |
1979 | 1979 | |
1980 | 1980 | $return = $check; |
1981 | 1981 | |
1982 | - switch ( $meta_key ) { |
|
1982 | + switch ($meta_key) { |
|
1983 | 1983 | case 'give_user_public_key': |
1984 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1984 | + $return = Give()->api->get_user_public_key($object_id); |
|
1985 | 1985 | break; |
1986 | 1986 | case 'give_user_secret_key': |
1987 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1987 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1988 | 1988 | break; |
1989 | 1989 | } |
1990 | 1990 | |
1991 | - if ( ! $single ) { |
|
1992 | - $return = array( $return ); |
|
1991 | + if ( ! $single) { |
|
1992 | + $return = array($return); |
|
1993 | 1993 | } |
1994 | 1994 | |
1995 | 1995 | return $return; |