@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * @since 1.8 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; // Exit if accessed directly |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! class_exists( 'Give_Settings_Export' ) ) : |
|
16 | +if ( ! class_exists('Give_Settings_Export')) : |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Give_Settings_Export. |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | 45 | $this->id = 'export'; |
46 | - $this->label = __( 'Export', 'give' ); |
|
46 | + $this->label = __('Export', 'give'); |
|
47 | 47 | |
48 | - add_filter( 'give-tools_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
|
49 | - add_action( "give-tools_settings_{$this->id}_page", array( $this, 'output' ) ); |
|
50 | - add_action( 'give_admin_field_tools_export', array( $this, 'render_export_field' ), 10, 2 ); |
|
48 | + add_filter('give-tools_tabs_array', array($this, 'add_settings_page'), 20); |
|
49 | + add_action("give-tools_settings_{$this->id}_page", array($this, 'output')); |
|
50 | + add_action('give_admin_field_tools_export', array($this, 'render_export_field'), 10, 2); |
|
51 | 51 | |
52 | 52 | // Do not use main donor for this tab. |
53 | - if( give_get_current_setting_tab() === $this->id ) { |
|
54 | - add_action( 'give-tools_open_form', '__return_empty_string' ); |
|
55 | - add_action( 'give-tools_close_form', '__return_empty_string' ); |
|
53 | + if (give_get_current_setting_tab() === $this->id) { |
|
54 | + add_action('give-tools_open_form', '__return_empty_string'); |
|
55 | + add_action('give-tools_close_form', '__return_empty_string'); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * @param array $pages Lst of pages. |
64 | 64 | * @return array |
65 | 65 | */ |
66 | - public function add_settings_page( $pages ) { |
|
67 | - $pages[ $this->id ] = $this->label; |
|
66 | + public function add_settings_page($pages) { |
|
67 | + $pages[$this->id] = $this->label; |
|
68 | 68 | |
69 | 69 | return $pages; |
70 | 70 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param array $settings |
87 | 87 | */ |
88 | 88 | $settings = apply_filters( |
89 | - 'give_get_settings_' . $this->id, |
|
89 | + 'give_get_settings_'.$this->id, |
|
90 | 90 | array( |
91 | 91 | array( |
92 | 92 | 'id' => 'give_tools_export', |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'id' => 'export', |
98 | - 'name' => __( 'Export', 'give' ), |
|
98 | + 'name' => __('Export', 'give'), |
|
99 | 99 | 'type' => 'tools_export', |
100 | 100 | ), |
101 | 101 | array( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function output() { |
120 | 120 | $settings = $this->get_settings(); |
121 | 121 | |
122 | - Give_Admin_Settings::output_fields( $settings, 'give_settings' ); |
|
122 | + Give_Admin_Settings::output_fields($settings, 'give_settings'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param $field |
132 | 132 | * @param $option_value |
133 | 133 | */ |
134 | - public function render_export_field( $field, $option_value ) { |
|
135 | - include_once( 'views/html-admin-page-exports.php' ); |
|
134 | + public function render_export_field($field, $option_value) { |
|
135 | + include_once('views/html-admin-page-exports.php'); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 |
@@ -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 | function give_donation_history() { |
27 | 27 | |
28 | 28 | // If payment_key query arg exists, return receipt instead of donation history. |
29 | - if ( isset( $_GET['payment_key'] ) ) { |
|
29 | + if (isset($_GET['payment_key'])) { |
|
30 | 30 | ob_start(); |
31 | - echo give_receipt_shortcode( array() ); |
|
32 | - echo '<a href="' . esc_url( give_get_history_page_uri() ) . '">« ' . __( 'Return to All Donations', 'give' ) . '</a>'; |
|
31 | + echo give_receipt_shortcode(array()); |
|
32 | + echo '<a href="'.esc_url(give_get_history_page_uri()).'">« '.__('Return to All Donations', 'give').'</a>'; |
|
33 | 33 | |
34 | 34 | return ob_get_clean(); |
35 | 35 | } |
36 | 36 | |
37 | - $email_access = give_get_option( 'email_access' ); |
|
37 | + $email_access = give_get_option('email_access'); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Determine access |
@@ -44,30 +44,30 @@ discard block |
||
44 | 44 | */ |
45 | 45 | if ( |
46 | 46 | is_user_logged_in() || false !== Give()->session->get_session_expiration() |
47 | - || ( give_is_setting_enabled( $email_access ) && Give()->email_access->token_exists ) |
|
47 | + || (give_is_setting_enabled($email_access) && Give()->email_access->token_exists) |
|
48 | 48 | ) { |
49 | 49 | ob_start(); |
50 | - give_get_template_part( 'history', 'donations' ); |
|
50 | + give_get_template_part('history', 'donations'); |
|
51 | 51 | |
52 | 52 | return ob_get_clean(); |
53 | 53 | |
54 | - } elseif ( give_is_setting_enabled( $email_access ) ) { |
|
54 | + } elseif (give_is_setting_enabled($email_access)) { |
|
55 | 55 | // Is Email-based access enabled? |
56 | 56 | ob_start(); |
57 | - give_get_template_part( 'email', 'login-form' ); |
|
57 | + give_get_template_part('email', 'login-form'); |
|
58 | 58 | |
59 | 59 | return ob_get_clean(); |
60 | 60 | |
61 | 61 | } else { |
62 | 62 | |
63 | - $output = apply_filters( 'give_donation_history_nonuser_message', give_output_error( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) ); |
|
64 | - $output .= do_shortcode( '[give_login]' ); |
|
63 | + $output = apply_filters('give_donation_history_nonuser_message', give_output_error(__('You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give'), false)); |
|
64 | + $output .= do_shortcode('[give_login]'); |
|
65 | 65 | |
66 | 66 | return $output; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | -add_shortcode( 'donation_history', 'give_donation_history' ); |
|
70 | +add_shortcode('donation_history', 'give_donation_history'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Donation Form Shortcode |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return string |
82 | 82 | */ |
83 | -function give_form_shortcode( $atts ) { |
|
84 | - $atts = shortcode_atts( array( |
|
83 | +function give_form_shortcode($atts) { |
|
84 | + $atts = shortcode_atts(array( |
|
85 | 85 | 'id' => '', |
86 | 86 | 'show_title' => true, |
87 | 87 | 'show_goal' => true, |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | 'float_labels' => '', |
90 | 90 | 'display_style' => '', |
91 | 91 | 'continue_button_title' => '', |
92 | - ), $atts, 'give_form' ); |
|
92 | + ), $atts, 'give_form'); |
|
93 | 93 | |
94 | 94 | // Convert string to bool. |
95 | - $atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN ); |
|
96 | - $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN ); |
|
95 | + $atts['show_title'] = filter_var($atts['show_title'], FILTER_VALIDATE_BOOLEAN); |
|
96 | + $atts['show_goal'] = filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN); |
|
97 | 97 | |
98 | 98 | //get the Give Form |
99 | 99 | ob_start(); |
100 | - give_get_donation_form( $atts ); |
|
100 | + give_get_donation_form($atts); |
|
101 | 101 | $final_output = ob_get_clean(); |
102 | 102 | |
103 | - return apply_filters( 'give_donate_form', $final_output, $atts ); |
|
103 | + return apply_filters('give_donate_form', $final_output, $atts); |
|
104 | 104 | } |
105 | 105 | |
106 | -add_shortcode( 'give_form', 'give_form_shortcode' ); |
|
106 | +add_shortcode('give_form', 'give_form_shortcode'); |
|
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Donation Form Goal Shortcode. |
@@ -116,37 +116,37 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return string |
118 | 118 | */ |
119 | -function give_goal_shortcode( $atts ) { |
|
120 | - $atts = shortcode_atts( array( |
|
119 | +function give_goal_shortcode($atts) { |
|
120 | + $atts = shortcode_atts(array( |
|
121 | 121 | 'id' => '', |
122 | 122 | 'show_text' => true, |
123 | 123 | 'show_bar' => true, |
124 | - ), $atts, 'give_goal' ); |
|
124 | + ), $atts, 'give_goal'); |
|
125 | 125 | |
126 | 126 | |
127 | 127 | //get the Give Form. |
128 | 128 | ob_start(); |
129 | 129 | |
130 | 130 | //Sanity check 1: ensure there is an ID Provided. |
131 | - if ( empty( $atts['id'] ) ) { |
|
132 | - give_output_error( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true ); |
|
131 | + if (empty($atts['id'])) { |
|
132 | + give_output_error(__('The shortcode is missing Donation Form ID attribute.', 'give'), true); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | //Sanity check 2: Check the form even has Goals enabled. |
136 | - if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) { |
|
136 | + if ( ! give_is_setting_enabled(give_get_meta($atts['id'], '_give_goal_option', true))) { |
|
137 | 137 | |
138 | - give_output_error( __( 'The form does not have Goals enabled.', 'give' ), true ); |
|
138 | + give_output_error(__('The form does not have Goals enabled.', 'give'), true); |
|
139 | 139 | } else { |
140 | 140 | //Passed all sanity checks: output Goal. |
141 | - give_show_goal_progress( $atts['id'], $atts ); |
|
141 | + give_show_goal_progress($atts['id'], $atts); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | $final_output = ob_get_clean(); |
145 | 145 | |
146 | - return apply_filters( 'give_goal_shortcode_output', $final_output, $atts ); |
|
146 | + return apply_filters('give_goal_shortcode_output', $final_output, $atts); |
|
147 | 147 | } |
148 | 148 | |
149 | -add_shortcode( 'give_goal', 'give_goal_shortcode' ); |
|
149 | +add_shortcode('give_goal', 'give_goal_shortcode'); |
|
150 | 150 | |
151 | 151 | |
152 | 152 | /** |
@@ -163,22 +163,22 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return string |
165 | 165 | */ |
166 | -function give_login_form_shortcode( $atts ) { |
|
167 | - $atts = shortcode_atts( array( |
|
166 | +function give_login_form_shortcode($atts) { |
|
167 | + $atts = shortcode_atts(array( |
|
168 | 168 | // Add backward compatibility for redirect attribute. |
169 | 169 | 'redirect' => '', |
170 | 170 | |
171 | 171 | 'login-redirect' => '', |
172 | 172 | 'logout-redirect' => '', |
173 | - ), $atts, 'give_login' ); |
|
173 | + ), $atts, 'give_login'); |
|
174 | 174 | |
175 | 175 | // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute. |
176 | - $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect'] ) ? $atts['redirect'] : '' ); |
|
176 | + $atts['login-redirect'] = ! empty($atts['login-redirect']) ? $atts['login-redirect'] : ( ! empty($atts['redirect']) ? $atts['redirect'] : ''); |
|
177 | 177 | |
178 | - return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] ); |
|
178 | + return give_login_form($atts['login-redirect'], $atts['logout-redirect']); |
|
179 | 179 | } |
180 | 180 | |
181 | -add_shortcode( 'give_login', 'give_login_form_shortcode' ); |
|
181 | +add_shortcode('give_login', 'give_login_form_shortcode'); |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Register Shortcode. |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return string |
195 | 195 | */ |
196 | -function give_register_form_shortcode( $atts ) { |
|
197 | - $atts = shortcode_atts( array( |
|
196 | +function give_register_form_shortcode($atts) { |
|
197 | + $atts = shortcode_atts(array( |
|
198 | 198 | 'redirect' => '', |
199 | - ), $atts, 'give_register' ); |
|
199 | + ), $atts, 'give_register'); |
|
200 | 200 | |
201 | - return give_register_form( $atts['redirect'] ); |
|
201 | + return give_register_form($atts['redirect']); |
|
202 | 202 | } |
203 | 203 | |
204 | -add_shortcode( 'give_register', 'give_register_form_shortcode' ); |
|
204 | +add_shortcode('give_register', 'give_register_form_shortcode'); |
|
205 | 205 | |
206 | 206 | /** |
207 | 207 | * Receipt Shortcode. |
@@ -214,12 +214,12 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return string |
216 | 216 | */ |
217 | -function give_receipt_shortcode( $atts ) { |
|
217 | +function give_receipt_shortcode($atts) { |
|
218 | 218 | |
219 | 219 | global $give_receipt_args, $payment; |
220 | 220 | |
221 | - $give_receipt_args = shortcode_atts( array( |
|
222 | - 'error' => __( 'You are missing the payment key to view this donation receipt.', 'give' ), |
|
221 | + $give_receipt_args = shortcode_atts(array( |
|
222 | + 'error' => __('You are missing the payment key to view this donation receipt.', 'give'), |
|
223 | 223 | 'price' => true, |
224 | 224 | 'donor' => true, |
225 | 225 | 'date' => true, |
@@ -228,50 +228,50 @@ discard block |
||
228 | 228 | 'payment_id' => true, |
229 | 229 | 'payment_status' => false, |
230 | 230 | 'status_notice' => true, |
231 | - ), $atts, 'give_receipt' ); |
|
231 | + ), $atts, 'give_receipt'); |
|
232 | 232 | |
233 | 233 | //set $session var |
234 | 234 | $session = give_get_purchase_session(); |
235 | 235 | |
236 | 236 | //set payment key var |
237 | - if ( isset( $_GET['payment_key'] ) ) { |
|
238 | - $payment_key = urldecode( $_GET['payment_key'] ); |
|
239 | - } elseif ( $session ) { |
|
237 | + if (isset($_GET['payment_key'])) { |
|
238 | + $payment_key = urldecode($_GET['payment_key']); |
|
239 | + } elseif ($session) { |
|
240 | 240 | $payment_key = $session['purchase_key']; |
241 | - } elseif ( $give_receipt_args['payment_key'] ) { |
|
241 | + } elseif ($give_receipt_args['payment_key']) { |
|
242 | 242 | $payment_key = $give_receipt_args['payment_key']; |
243 | 243 | } |
244 | 244 | |
245 | - $email_access = give_get_option( 'email_access' ); |
|
245 | + $email_access = give_get_option('email_access'); |
|
246 | 246 | |
247 | 247 | // No payment_key found & Email Access is Turned on: |
248 | - if ( ! isset( $payment_key ) && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) { |
|
248 | + if ( ! isset($payment_key) && give_is_setting_enabled($email_access) && ! Give()->email_access->token_exists) { |
|
249 | 249 | |
250 | 250 | ob_start(); |
251 | 251 | |
252 | - give_get_template_part( 'email-login-form' ); |
|
252 | + give_get_template_part('email-login-form'); |
|
253 | 253 | |
254 | 254 | return ob_get_clean(); |
255 | 255 | |
256 | - } elseif ( ! isset( $payment_key ) ) { |
|
256 | + } elseif ( ! isset($payment_key)) { |
|
257 | 257 | |
258 | - return give_output_error( $give_receipt_args['error'], false, 'error' ); |
|
258 | + return give_output_error($give_receipt_args['error'], false, 'error'); |
|
259 | 259 | |
260 | 260 | } |
261 | 261 | |
262 | - $payment_id = give_get_purchase_id_by_key( $payment_key ); |
|
263 | - $user_can_view = give_can_view_receipt( $payment_key ); |
|
262 | + $payment_id = give_get_purchase_id_by_key($payment_key); |
|
263 | + $user_can_view = give_can_view_receipt($payment_key); |
|
264 | 264 | |
265 | 265 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt. |
266 | - if ( ! $user_can_view && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) { |
|
266 | + if ( ! $user_can_view && give_is_setting_enabled($email_access) && ! Give()->email_access->token_exists) { |
|
267 | 267 | |
268 | 268 | ob_start(); |
269 | 269 | |
270 | - give_get_template_part( 'email-login-form' ); |
|
270 | + give_get_template_part('email-login-form'); |
|
271 | 271 | |
272 | 272 | return ob_get_clean(); |
273 | 273 | |
274 | - } elseif ( ! $user_can_view ) { |
|
274 | + } elseif ( ! $user_can_view) { |
|
275 | 275 | |
276 | 276 | global $give_login_redirect; |
277 | 277 | |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | |
280 | 280 | ob_start(); |
281 | 281 | |
282 | - give_output_error( apply_filters( 'give_must_be_logged_in_error_message', __( 'You must be logged in to view this donation receipt.', 'give' ) ) ); |
|
282 | + give_output_error(apply_filters('give_must_be_logged_in_error_message', __('You must be logged in to view this donation receipt.', 'give'))); |
|
283 | 283 | |
284 | - give_get_template_part( 'shortcode', 'login' ); |
|
284 | + give_get_template_part('shortcode', 'login'); |
|
285 | 285 | |
286 | 286 | $login_form = ob_get_clean(); |
287 | 287 | |
@@ -296,20 +296,20 @@ discard block |
||
296 | 296 | * or if user is logged in and the user can view sensitive shop data. |
297 | 297 | * |
298 | 298 | */ |
299 | - if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) { |
|
300 | - return give_output_error( $give_receipt_args['error'], false, 'error' ); |
|
299 | + if ( ! apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) { |
|
300 | + return give_output_error($give_receipt_args['error'], false, 'error'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | ob_start(); |
304 | 304 | |
305 | - give_get_template_part( 'shortcode', 'receipt' ); |
|
305 | + give_get_template_part('shortcode', 'receipt'); |
|
306 | 306 | |
307 | 307 | $display = ob_get_clean(); |
308 | 308 | |
309 | 309 | return $display; |
310 | 310 | } |
311 | 311 | |
312 | -add_shortcode( 'give_receipt', 'give_receipt_shortcode' ); |
|
312 | +add_shortcode('give_receipt', 'give_receipt_shortcode'); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Profile Editor Shortcode. |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @return string Output generated from the profile editor |
330 | 330 | */ |
331 | -function give_profile_editor_shortcode( $atts ) { |
|
331 | +function give_profile_editor_shortcode($atts) { |
|
332 | 332 | |
333 | 333 | ob_start(); |
334 | 334 | |
335 | - give_get_template_part( 'shortcode', 'profile-editor' ); |
|
335 | + give_get_template_part('shortcode', 'profile-editor'); |
|
336 | 336 | |
337 | 337 | $display = ob_get_clean(); |
338 | 338 | |
339 | 339 | return $display; |
340 | 340 | } |
341 | 341 | |
342 | -add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' ); |
|
342 | +add_shortcode('give_profile_editor', 'give_profile_editor_shortcode'); |
|
343 | 343 | |
344 | 344 | /** |
345 | 345 | * Process Profile Updater Form. |
@@ -352,30 +352,30 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return bool |
354 | 354 | */ |
355 | -function give_process_profile_editor_updates( $data ) { |
|
355 | +function give_process_profile_editor_updates($data) { |
|
356 | 356 | // Profile field change request |
357 | - if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) { |
|
357 | + if (empty($_POST['give_profile_editor_submit']) && ! is_user_logged_in()) { |
|
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Nonce security |
362 | - if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) { |
|
362 | + if ( ! wp_verify_nonce($data['give_profile_editor_nonce'], 'give-profile-editor-nonce')) { |
|
363 | 363 | return false; |
364 | 364 | } |
365 | 365 | |
366 | 366 | $user_id = get_current_user_id(); |
367 | - $old_user_data = get_userdata( $user_id ); |
|
368 | - |
|
369 | - $display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name; |
|
370 | - $first_name = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name; |
|
371 | - $last_name = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name; |
|
372 | - $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email; |
|
373 | - $line1 = ( isset( $data['give_address_line1'] ) ? sanitize_text_field( $data['give_address_line1'] ) : '' ); |
|
374 | - $line2 = ( isset( $data['give_address_line2'] ) ? sanitize_text_field( $data['give_address_line2'] ) : '' ); |
|
375 | - $city = ( isset( $data['give_address_city'] ) ? sanitize_text_field( $data['give_address_city'] ) : '' ); |
|
376 | - $state = ( isset( $data['give_address_state'] ) ? sanitize_text_field( $data['give_address_state'] ) : '' ); |
|
377 | - $zip = ( isset( $data['give_address_zip'] ) ? sanitize_text_field( $data['give_address_zip'] ) : '' ); |
|
378 | - $country = ( isset( $data['give_address_country'] ) ? sanitize_text_field( $data['give_address_country'] ) : '' ); |
|
367 | + $old_user_data = get_userdata($user_id); |
|
368 | + |
|
369 | + $display_name = isset($data['give_display_name']) ? sanitize_text_field($data['give_display_name']) : $old_user_data->display_name; |
|
370 | + $first_name = isset($data['give_first_name']) ? sanitize_text_field($data['give_first_name']) : $old_user_data->first_name; |
|
371 | + $last_name = isset($data['give_last_name']) ? sanitize_text_field($data['give_last_name']) : $old_user_data->last_name; |
|
372 | + $email = isset($data['give_email']) ? sanitize_email($data['give_email']) : $old_user_data->user_email; |
|
373 | + $line1 = (isset($data['give_address_line1']) ? sanitize_text_field($data['give_address_line1']) : ''); |
|
374 | + $line2 = (isset($data['give_address_line2']) ? sanitize_text_field($data['give_address_line2']) : ''); |
|
375 | + $city = (isset($data['give_address_city']) ? sanitize_text_field($data['give_address_city']) : ''); |
|
376 | + $state = (isset($data['give_address_state']) ? sanitize_text_field($data['give_address_state']) : ''); |
|
377 | + $zip = (isset($data['give_address_zip']) ? sanitize_text_field($data['give_address_zip']) : ''); |
|
378 | + $country = (isset($data['give_address_country']) ? sanitize_text_field($data['give_address_country']) : ''); |
|
379 | 379 | |
380 | 380 | $userdata = array( |
381 | 381 | 'ID' => $user_id, |
@@ -403,46 +403,46 @@ discard block |
||
403 | 403 | * @param int $user_id The ID of the user. |
404 | 404 | * @param array $userdata User info, including ID, first name, last name, display name and email. |
405 | 405 | */ |
406 | - do_action( 'give_pre_update_user_profile', $user_id, $userdata ); |
|
406 | + do_action('give_pre_update_user_profile', $user_id, $userdata); |
|
407 | 407 | |
408 | 408 | // New password |
409 | - if ( ! empty( $data['give_new_user_pass1'] ) ) { |
|
410 | - if ( $data['give_new_user_pass1'] !== $data['give_new_user_pass2'] ) { |
|
411 | - give_set_error( 'password_mismatch', __( 'The passwords you entered do not match. Please try again.', 'give' ) ); |
|
409 | + if ( ! empty($data['give_new_user_pass1'])) { |
|
410 | + if ($data['give_new_user_pass1'] !== $data['give_new_user_pass2']) { |
|
411 | + give_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'give')); |
|
412 | 412 | } else { |
413 | 413 | $userdata['user_pass'] = $data['give_new_user_pass1']; |
414 | 414 | } |
415 | 415 | } |
416 | 416 | |
417 | - if ( empty( $email ) ) { |
|
417 | + if (empty($email)) { |
|
418 | 418 | // Make sure email should not be empty. |
419 | - give_set_error( 'email_empty', __( 'The email you entered is empty.', 'give' ) ); |
|
419 | + give_set_error('email_empty', __('The email you entered is empty.', 'give')); |
|
420 | 420 | |
421 | - } else if ( ! is_email( $email ) ) { |
|
421 | + } else if ( ! is_email($email)) { |
|
422 | 422 | // Make sure email should be valid. |
423 | - give_set_error( 'email_not_valid', __( 'The email you entered is not valid. Please use another', 'give' ) ); |
|
423 | + give_set_error('email_not_valid', __('The email you entered is not valid. Please use another', 'give')); |
|
424 | 424 | |
425 | - } else if ( $email != $old_user_data->user_email ) { |
|
425 | + } else if ($email != $old_user_data->user_email) { |
|
426 | 426 | // Make sure the new email doesn't belong to another user |
427 | - if ( email_exists( $email ) ) { |
|
428 | - give_set_error( 'email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) ); |
|
427 | + if (email_exists($email)) { |
|
428 | + give_set_error('email_exists', __('The email you entered belongs to another user. Please use another.', 'give')); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
432 | 432 | // Check for errors |
433 | 433 | $errors = give_get_errors(); |
434 | 434 | |
435 | - if ( $errors ) { |
|
435 | + if ($errors) { |
|
436 | 436 | // Send back to the profile editor if there are errors |
437 | - wp_redirect( $data['give_redirect'] ); |
|
437 | + wp_redirect($data['give_redirect']); |
|
438 | 438 | give_die(); |
439 | 439 | } |
440 | 440 | |
441 | 441 | // Update the user |
442 | - $meta = update_user_meta( $user_id, '_give_user_address', $address ); |
|
443 | - $updated = wp_update_user( $userdata ); |
|
442 | + $meta = update_user_meta($user_id, '_give_user_address', $address); |
|
443 | + $updated = wp_update_user($userdata); |
|
444 | 444 | |
445 | - if ( $updated ) { |
|
445 | + if ($updated) { |
|
446 | 446 | |
447 | 447 | /** |
448 | 448 | * Fires after updating user profile. |
@@ -452,12 +452,12 @@ discard block |
||
452 | 452 | * @param int $user_id The ID of the user. |
453 | 453 | * @param array $userdata User info, including ID, first name, last name, display name and email. |
454 | 454 | */ |
455 | - do_action( 'give_user_profile_updated', $user_id, $userdata ); |
|
456 | - wp_redirect( add_query_arg( 'updated', 'true', $data['give_redirect'] ) ); |
|
455 | + do_action('give_user_profile_updated', $user_id, $userdata); |
|
456 | + wp_redirect(add_query_arg('updated', 'true', $data['give_redirect'])); |
|
457 | 457 | give_die(); |
458 | 458 | } |
459 | 459 | |
460 | 460 | return false; |
461 | 461 | } |
462 | 462 | |
463 | -add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' ); |
|
463 | +add_action('give_edit_user_profile', 'give_process_profile_editor_updates'); |
@@ -89,7 +89,7 @@ |
||
89 | 89 | add_role( 'give_worker', esc_html__( 'Give Worker', 'give' ), array( |
90 | 90 | 'read' => true, |
91 | 91 | 'edit_posts' => true, |
92 | - 'edit_pages' => true, |
|
92 | + 'edit_pages' => true, |
|
93 | 93 | 'upload_files' => true, |
94 | 94 | 'delete_posts' => false |
95 | 95 | ) ); |
@@ -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 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @access public |
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | - add_filter( 'give_map_meta_cap', array( $this, 'meta_caps' ), 10, 4 ); |
|
38 | + add_filter('give_map_meta_cap', array($this, 'meta_caps'), 10, 4); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | public function add_roles() { |
52 | - add_role( 'give_manager', esc_html__( 'Give Manager', 'give' ), array( |
|
52 | + add_role('give_manager', esc_html__('Give Manager', 'give'), array( |
|
53 | 53 | 'read' => true, |
54 | 54 | 'edit_posts' => true, |
55 | 55 | 'delete_posts' => true, |
@@ -78,21 +78,21 @@ discard block |
||
78 | 78 | 'publish_posts' => true, |
79 | 79 | 'read_private_pages' => true, |
80 | 80 | 'read_private_posts' => true |
81 | - ) ); |
|
81 | + )); |
|
82 | 82 | |
83 | - add_role( 'give_accountant', esc_html__( 'Give Accountant', 'give' ), array( |
|
83 | + add_role('give_accountant', esc_html__('Give Accountant', 'give'), array( |
|
84 | 84 | 'read' => true, |
85 | 85 | 'edit_posts' => false, |
86 | 86 | 'delete_posts' => false |
87 | - ) ); |
|
87 | + )); |
|
88 | 88 | |
89 | - add_role( 'give_worker', esc_html__( 'Give Worker', 'give' ), array( |
|
89 | + add_role('give_worker', esc_html__('Give Worker', 'give'), array( |
|
90 | 90 | 'read' => true, |
91 | 91 | 'edit_posts' => true, |
92 | 92 | 'edit_pages' => true, |
93 | 93 | 'upload_files' => true, |
94 | 94 | 'delete_posts' => false |
95 | - ) ); |
|
95 | + )); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -111,38 +111,38 @@ discard block |
||
111 | 111 | public function add_caps() { |
112 | 112 | global $wp_roles; |
113 | 113 | |
114 | - if ( class_exists( 'WP_Roles' ) ) { |
|
115 | - if ( ! isset( $wp_roles ) ) { |
|
114 | + if (class_exists('WP_Roles')) { |
|
115 | + if ( ! isset($wp_roles)) { |
|
116 | 116 | $wp_roles = new WP_Roles(); |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( is_object( $wp_roles ) ) { |
|
121 | - $wp_roles->add_cap( 'give_manager', 'view_give_reports' ); |
|
122 | - $wp_roles->add_cap( 'give_manager', 'view_give_sensitive_data' ); |
|
123 | - $wp_roles->add_cap( 'give_manager', 'export_give_reports' ); |
|
124 | - $wp_roles->add_cap( 'give_manager', 'manage_give_settings' ); |
|
120 | + if (is_object($wp_roles)) { |
|
121 | + $wp_roles->add_cap('give_manager', 'view_give_reports'); |
|
122 | + $wp_roles->add_cap('give_manager', 'view_give_sensitive_data'); |
|
123 | + $wp_roles->add_cap('give_manager', 'export_give_reports'); |
|
124 | + $wp_roles->add_cap('give_manager', 'manage_give_settings'); |
|
125 | 125 | |
126 | - $wp_roles->add_cap( 'administrator', 'view_give_reports' ); |
|
127 | - $wp_roles->add_cap( 'administrator', 'view_give_sensitive_data' ); |
|
128 | - $wp_roles->add_cap( 'administrator', 'export_give_reports' ); |
|
129 | - $wp_roles->add_cap( 'administrator', 'manage_give_settings' ); |
|
126 | + $wp_roles->add_cap('administrator', 'view_give_reports'); |
|
127 | + $wp_roles->add_cap('administrator', 'view_give_sensitive_data'); |
|
128 | + $wp_roles->add_cap('administrator', 'export_give_reports'); |
|
129 | + $wp_roles->add_cap('administrator', 'manage_give_settings'); |
|
130 | 130 | |
131 | 131 | // Add the main post type capabilities. |
132 | 132 | $capabilities = $this->get_core_caps(); |
133 | - foreach ( $capabilities as $cap_group ) { |
|
134 | - foreach ( $cap_group as $cap ) { |
|
135 | - $wp_roles->add_cap( 'administrator', $cap ); |
|
136 | - $wp_roles->add_cap( 'give_manager', $cap ); |
|
137 | - $wp_roles->add_cap( 'give_worker', $cap ); |
|
133 | + foreach ($capabilities as $cap_group) { |
|
134 | + foreach ($cap_group as $cap) { |
|
135 | + $wp_roles->add_cap('administrator', $cap); |
|
136 | + $wp_roles->add_cap('give_manager', $cap); |
|
137 | + $wp_roles->add_cap('give_worker', $cap); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - $wp_roles->add_cap( 'give_accountant', 'edit_give_forms' ); |
|
142 | - $wp_roles->add_cap( 'give_accountant', 'read_private_give_forms' ); |
|
143 | - $wp_roles->add_cap( 'give_accountant', 'view_give_reports' ); |
|
144 | - $wp_roles->add_cap( 'give_accountant', 'export_give_reports' ); |
|
145 | - $wp_roles->add_cap( 'give_accountant', 'edit_give_payments' ); |
|
141 | + $wp_roles->add_cap('give_accountant', 'edit_give_forms'); |
|
142 | + $wp_roles->add_cap('give_accountant', 'read_private_give_forms'); |
|
143 | + $wp_roles->add_cap('give_accountant', 'view_give_reports'); |
|
144 | + $wp_roles->add_cap('give_accountant', 'export_give_reports'); |
|
145 | + $wp_roles->add_cap('give_accountant', 'edit_give_payments'); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | } |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | public function get_core_caps() { |
161 | 161 | $capabilities = array(); |
162 | 162 | |
163 | - $capability_types = array( 'give_form', 'give_payment' ); |
|
163 | + $capability_types = array('give_form', 'give_payment'); |
|
164 | 164 | |
165 | - foreach ( $capability_types as $capability_type ) { |
|
166 | - $capabilities[ $capability_type ] = array( |
|
165 | + foreach ($capability_types as $capability_type) { |
|
166 | + $capabilities[$capability_type] = array( |
|
167 | 167 | // Post type. |
168 | 168 | "edit_{$capability_type}", |
169 | 169 | "read_{$capability_type}", |
@@ -209,22 +209,22 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return array $caps Meta capabilities. |
211 | 211 | */ |
212 | - public function meta_caps( $caps, $cap, $user_id, $args ) { |
|
212 | + public function meta_caps($caps, $cap, $user_id, $args) { |
|
213 | 213 | |
214 | - switch ( $cap ) { |
|
214 | + switch ($cap) { |
|
215 | 215 | |
216 | 216 | case 'view_give_form_stats' : |
217 | 217 | |
218 | - if ( empty( $args[0] ) ) { |
|
218 | + if (empty($args[0])) { |
|
219 | 219 | break; |
220 | 220 | } |
221 | 221 | |
222 | - $form = get_post( $args[0] ); |
|
223 | - if ( empty( $form ) ) { |
|
222 | + $form = get_post($args[0]); |
|
223 | + if (empty($form)) { |
|
224 | 224 | break; |
225 | 225 | } |
226 | 226 | |
227 | - if ( user_can( $user_id, 'view_give_reports' ) || $user_id == $form->post_author ) { |
|
227 | + if (user_can($user_id, 'view_give_reports') || $user_id == $form->post_author) { |
|
228 | 228 | $caps = array(); |
229 | 229 | } |
230 | 230 | |
@@ -251,41 +251,41 @@ discard block |
||
251 | 251 | |
252 | 252 | global $wp_roles; |
253 | 253 | |
254 | - if ( class_exists( 'WP_Roles' ) ) { |
|
255 | - if ( ! isset( $wp_roles ) ) { |
|
254 | + if (class_exists('WP_Roles')) { |
|
255 | + if ( ! isset($wp_roles)) { |
|
256 | 256 | $wp_roles = new WP_Roles(); |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | - if ( is_object( $wp_roles ) ) { |
|
260 | + if (is_object($wp_roles)) { |
|
261 | 261 | // Give Manager Capabilities. |
262 | - $wp_roles->remove_cap( 'give_manager', 'view_give_reports' ); |
|
263 | - $wp_roles->remove_cap( 'give_manager', 'view_give_sensitive_data' ); |
|
264 | - $wp_roles->remove_cap( 'give_manager', 'export_give_reports' ); |
|
265 | - $wp_roles->remove_cap( 'give_manager', 'manage_give_settings' ); |
|
262 | + $wp_roles->remove_cap('give_manager', 'view_give_reports'); |
|
263 | + $wp_roles->remove_cap('give_manager', 'view_give_sensitive_data'); |
|
264 | + $wp_roles->remove_cap('give_manager', 'export_give_reports'); |
|
265 | + $wp_roles->remove_cap('give_manager', 'manage_give_settings'); |
|
266 | 266 | |
267 | 267 | // Site Administrator Capabilities. |
268 | - $wp_roles->remove_cap( 'administrator', 'view_give_reports' ); |
|
269 | - $wp_roles->remove_cap( 'administrator', 'view_give_sensitive_data' ); |
|
270 | - $wp_roles->remove_cap( 'administrator', 'export_give_reports' ); |
|
271 | - $wp_roles->remove_cap( 'administrator', 'manage_give_settings' ); |
|
268 | + $wp_roles->remove_cap('administrator', 'view_give_reports'); |
|
269 | + $wp_roles->remove_cap('administrator', 'view_give_sensitive_data'); |
|
270 | + $wp_roles->remove_cap('administrator', 'export_give_reports'); |
|
271 | + $wp_roles->remove_cap('administrator', 'manage_give_settings'); |
|
272 | 272 | |
273 | 273 | // Remove the Main Post Type Capabilities. |
274 | 274 | $capabilities = $this->get_core_caps(); |
275 | 275 | |
276 | - foreach ( $capabilities as $cap_group ) { |
|
277 | - foreach ( $cap_group as $cap ) { |
|
278 | - $wp_roles->remove_cap( 'give_manager', $cap ); |
|
279 | - $wp_roles->remove_cap( 'administrator', $cap ); |
|
280 | - $wp_roles->remove_cap( 'give_worker', $cap ); |
|
276 | + foreach ($capabilities as $cap_group) { |
|
277 | + foreach ($cap_group as $cap) { |
|
278 | + $wp_roles->remove_cap('give_manager', $cap); |
|
279 | + $wp_roles->remove_cap('administrator', $cap); |
|
280 | + $wp_roles->remove_cap('give_worker', $cap); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** Give Accountant Capabilities */ |
285 | - $wp_roles->remove_cap( 'give_accountant', 'edit_give_forms' ); |
|
286 | - $wp_roles->remove_cap( 'give_accountant', 'read_private_give_forms' ); |
|
287 | - $wp_roles->remove_cap( 'give_accountant', 'view_give_reports' ); |
|
288 | - $wp_roles->remove_cap( 'give_accountant', 'export_give_reports' ); |
|
285 | + $wp_roles->remove_cap('give_accountant', 'edit_give_forms'); |
|
286 | + $wp_roles->remove_cap('give_accountant', 'read_private_give_forms'); |
|
287 | + $wp_roles->remove_cap('give_accountant', 'view_give_reports'); |
|
288 | + $wp_roles->remove_cap('give_accountant', 'export_give_reports'); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | } |
@@ -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 | - give_update_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 | + give_update_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,18 +150,18 @@ 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'); |
|
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Print css for wordpress setting pages. |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | /* @var WP_Screen $screen */ |
173 | 173 | $screen = get_current_screen(); |
174 | 174 | |
175 | - if( ! ( $screen instanceof WP_Screen ) ) { |
|
175 | + if ( ! ($screen instanceof WP_Screen)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - switch ( true ) { |
|
180 | - case ( 'plugins' === $screen->base ): |
|
179 | + switch (true) { |
|
180 | + case ('plugins' === $screen->base): |
|
181 | 181 | ?> |
182 | 182 | <style> |
183 | 183 | tr.active.update + tr.give-addon-notice-tr td{ |
@@ -210,4 +210,4 @@ discard block |
||
210 | 210 | <?php |
211 | 211 | } |
212 | 212 | } |
213 | -add_action( 'admin_head', 'give_admin_quick_css' ); |
|
213 | +add_action('admin_head', 'give_admin_quick_css'); |
@@ -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. |
@@ -374,14 +374,14 @@ discard block |
||
374 | 374 | 'uninstall_on_delete' => 'disabled', |
375 | 375 | 'the_content_filter' => 'enabled', |
376 | 376 | 'scripts_footer' => 'disabled', |
377 | - 'agree_to_terms_label' => __( 'Agree to Terms?', 'give' ), |
|
377 | + 'agree_to_terms_label' => __('Agree to Terms?', 'give'), |
|
378 | 378 | 'agreement_text' => give_get_default_agreement_text(), |
379 | 379 | |
380 | 380 | // Paypal IPN verification. |
381 | 381 | 'paypal_verification' => 'enabled', |
382 | 382 | |
383 | 383 | // Default is manual gateway. |
384 | - 'gateways' => array( 'manual' => 1, 'offline' => 1 ), |
|
384 | + 'gateways' => array('manual' => 1, 'offline' => 1), |
|
385 | 385 | 'default_gateway' => 'manual', |
386 | 386 | |
387 | 387 | // Offline gateway setup. |
@@ -406,17 +406,17 @@ discard block |
||
406 | 406 | */ |
407 | 407 | function give_get_default_agreement_text() { |
408 | 408 | |
409 | - $org_name = get_bloginfo( 'name' ); |
|
409 | + $org_name = get_bloginfo('name'); |
|
410 | 410 | |
411 | - $agreement = '<p>Acceptance of any contribution, gift or grant is at the discretion of the ' . $org_name . '. The ' . $org_name . ' will not accept any gift unless it can be used or expended consistently with the purpose and mission of the ' . $org_name . '.</p> |
|
411 | + $agreement = '<p>Acceptance of any contribution, gift or grant is at the discretion of the '.$org_name.'. The '.$org_name.' will not accept any gift unless it can be used or expended consistently with the purpose and mission of the '.$org_name.'.</p> |
|
412 | 412 | <p>No irrevocable gift, whether outright or life-income in character, will be accepted if under any reasonable set of circumstances the gift would jeopardize the donor’s financial security.</p> |
413 | -<p>The ' . $org_name . ' will refrain from providing advice about the tax or other treatment of gifts and will encourage donors to seek guidance from their own professional advisers to assist them in the process of making their donation.</p> |
|
414 | -<p>The ' . $org_name . ' will accept donations of cash or publicly traded securities. Gifts of in-kind services will be accepted at the discretion of the ' . $org_name . '.</p> |
|
415 | -<p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for ' . $org_name . '.</p> |
|
416 | -<p>The ' . $org_name . ' will provide acknowledgments to donors meeting tax requirements for property received by the charity as a gift. However, except for gifts of cash and publicly traded securities, no value shall be ascribed to any receipt or other form of substantiation of a gift received by ' . $org_name . '.</p> |
|
417 | -<p>The ' . $org_name . ' will respect the intent of the donor relating to gifts for restricted purposes and those relating to the desire to remain anonymous. With respect to anonymous gifts, the ' . $org_name . ' will restrict information about the donor to only those staff members with a need to know.</p> |
|
418 | -<p>The ' . $org_name . ' will not compensate, whether through commissions, finders\' fees, or other means, any third party for directing a gift or a donor to the ' . $org_name . '.</p>'; |
|
419 | - |
|
420 | - return apply_filters( 'give_get_default_agreement_text', $agreement, $org_name ); |
|
413 | +<p>The ' . $org_name.' will refrain from providing advice about the tax or other treatment of gifts and will encourage donors to seek guidance from their own professional advisers to assist them in the process of making their donation.</p> |
|
414 | +<p>The ' . $org_name.' will accept donations of cash or publicly traded securities. Gifts of in-kind services will be accepted at the discretion of the '.$org_name.'.</p> |
|
415 | +<p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for ' . $org_name.'.</p> |
|
416 | +<p>The ' . $org_name.' will provide acknowledgments to donors meeting tax requirements for property received by the charity as a gift. However, except for gifts of cash and publicly traded securities, no value shall be ascribed to any receipt or other form of substantiation of a gift received by '.$org_name.'.</p> |
|
417 | +<p>The ' . $org_name.' will respect the intent of the donor relating to gifts for restricted purposes and those relating to the desire to remain anonymous. With respect to anonymous gifts, the '.$org_name.' will restrict information about the donor to only those staff members with a need to know.</p> |
|
418 | +<p>The ' . $org_name.' will not compensate, whether through commissions, finders\' fees, or other means, any third party for directing a gift or a donor to the '.$org_name.'.</p>'; |
|
419 | + |
|
420 | + return apply_filters('give_get_default_agreement_text', $agreement, $org_name); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | \ No newline at end of file |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @access public |
217 | 217 | * @since 1.1 |
218 | - * @return array |
|
218 | + * @return string |
|
219 | 219 | */ |
220 | 220 | public function get_versions() { |
221 | 221 | return $this->versions; |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | * |
690 | 690 | * @param array $args Arguments to override defaults |
691 | 691 | * |
692 | - * @return array $dates |
|
692 | + * @return integer|null $dates |
|
693 | 693 | */ |
694 | 694 | public function get_dates( $args = array() ) { |
695 | 695 | $dates = array(); |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
381 | - * Get user public key. |
|
382 | - * |
|
381 | + * Get user public key. |
|
382 | + * |
|
383 | 383 | * @param int $user_id |
384 | 384 | * |
385 | 385 | * @return mixed|null|string |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Get user secret key. |
|
407 | - * |
|
406 | + * Get user secret key. |
|
407 | + * |
|
408 | 408 | * @param int $user_id |
409 | 409 | * |
410 | 410 | * @return mixed|null|string |
@@ -567,14 +567,14 @@ discard block |
||
567 | 567 | |
568 | 568 | case 'donations' : |
569 | 569 | |
570 | - /** |
|
571 | - * Call to get recent donations |
|
572 | - * |
|
573 | - * @params text date | today, yesterday or range |
|
574 | - * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
575 | - * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
576 | - */ |
|
577 | - $data = $this->routes->get_recent_donations( array( |
|
570 | + /** |
|
571 | + * Call to get recent donations |
|
572 | + * |
|
573 | + * @params text date | today, yesterday or range |
|
574 | + * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
575 | + * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
576 | + */ |
|
577 | + $data = $this->routes->get_recent_donations( array( |
|
578 | 578 | 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
579 | 579 | 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
580 | 580 | 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
@@ -1364,7 +1364,7 @@ discard block |
||
1364 | 1364 | public function get_recent_donations( $args = array() ) { |
1365 | 1365 | global $wp_query; |
1366 | 1366 | |
1367 | - $defaults = array( |
|
1367 | + $defaults = array( |
|
1368 | 1368 | 'date' => null, |
1369 | 1369 | 'startdate' => null, |
1370 | 1370 | 'enddate' => null, |
@@ -1372,7 +1372,7 @@ discard block |
||
1372 | 1372 | |
1373 | 1373 | $args = wp_parse_args( $args, $defaults ); |
1374 | 1374 | |
1375 | - $sales = array(); |
|
1375 | + $sales = array(); |
|
1376 | 1376 | |
1377 | 1377 | if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
1378 | 1378 | return $sales; |
@@ -1396,55 +1396,55 @@ discard block |
||
1396 | 1396 | $query = give_get_payments( $args ); |
1397 | 1397 | } elseif ( isset( $wp_query->query_vars['date'] ) ) { |
1398 | 1398 | |
1399 | - $current_time = current_time( 'timestamp' ); |
|
1400 | - $dates = $this->get_dates( $args ); |
|
1399 | + $current_time = current_time( 'timestamp' ); |
|
1400 | + $dates = $this->get_dates( $args ); |
|
1401 | 1401 | |
1402 | - /** |
|
1403 | - * Switch case for date query argument |
|
1404 | - * |
|
1405 | - * @since 1.8.8 |
|
1406 | - * |
|
1407 | - * @params text date | today, yesterday or range |
|
1408 | - * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
1409 | - * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
1410 | - */ |
|
1411 | - switch( $wp_query->query_vars['date'] ){ |
|
1402 | + /** |
|
1403 | + * Switch case for date query argument |
|
1404 | + * |
|
1405 | + * @since 1.8.8 |
|
1406 | + * |
|
1407 | + * @params text date | today, yesterday or range |
|
1408 | + * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
1409 | + * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
|
1410 | + */ |
|
1411 | + switch( $wp_query->query_vars['date'] ){ |
|
1412 | 1412 | |
1413 | - case 'today': |
|
1413 | + case 'today': |
|
1414 | 1414 | |
1415 | - // Set and Format Start and End Date to be date of today. |
|
1416 | - $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
1415 | + // Set and Format Start and End Date to be date of today. |
|
1416 | + $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
1417 | 1417 | |
1418 | - break; |
|
1418 | + break; |
|
1419 | 1419 | |
1420 | - case 'yesterday': |
|
1420 | + case 'yesterday': |
|
1421 | 1421 | |
1422 | - // Set and Format Start and End Date to be date of yesterday. |
|
1423 | - $start_date = $end_date = date( 'Y/m', $current_time ) . '/'. ( date( 'd', $current_time ) - 1 ); |
|
1422 | + // Set and Format Start and End Date to be date of yesterday. |
|
1423 | + $start_date = $end_date = date( 'Y/m', $current_time ) . '/'. ( date( 'd', $current_time ) - 1 ); |
|
1424 | 1424 | |
1425 | - break; |
|
1425 | + break; |
|
1426 | 1426 | |
1427 | - case 'range': |
|
1427 | + case 'range': |
|
1428 | 1428 | |
1429 | - // Format Start Date and End Date for filtering payment based on date range. |
|
1430 | - $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
1431 | - $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
1429 | + // Format Start Date and End Date for filtering payment based on date range. |
|
1430 | + $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
1431 | + $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
1432 | 1432 | |
1433 | - break; |
|
1433 | + break; |
|
1434 | 1434 | |
1435 | - } |
|
1435 | + } |
|
1436 | 1436 | |
1437 | - $args = array( |
|
1438 | - 'fields' => 'ids', |
|
1439 | - 'start_date' => $start_date, |
|
1440 | - 'end_date' => $end_date, |
|
1441 | - 'number' => $this->per_page(), |
|
1442 | - 'page' => $this->get_paged(), |
|
1443 | - 'status' => 'publish', |
|
1444 | - ); |
|
1437 | + $args = array( |
|
1438 | + 'fields' => 'ids', |
|
1439 | + 'start_date' => $start_date, |
|
1440 | + 'end_date' => $end_date, |
|
1441 | + 'number' => $this->per_page(), |
|
1442 | + 'page' => $this->get_paged(), |
|
1443 | + 'status' => 'publish', |
|
1444 | + ); |
|
1445 | 1445 | |
1446 | 1446 | $query = give_get_payments( $args ); |
1447 | - } else { |
|
1447 | + } else { |
|
1448 | 1448 | $args = array( |
1449 | 1449 | 'fields' => 'ids', |
1450 | 1450 | 'number' => $this->per_page(), |
@@ -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; |
@@ -384,19 +384,19 @@ discard block |
||
384 | 384 | * |
385 | 385 | * @return mixed|null|string |
386 | 386 | */ |
387 | - public function get_user_public_key( $user_id = 0 ) { |
|
387 | + public function get_user_public_key($user_id = 0) { |
|
388 | 388 | global $wpdb; |
389 | 389 | |
390 | - if ( empty( $user_id ) ) { |
|
390 | + if (empty($user_id)) { |
|
391 | 391 | return ''; |
392 | 392 | } |
393 | 393 | |
394 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
395 | - $user_public_key = Give_Cache::get( $cache_key, true ); |
|
394 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
395 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
396 | 396 | |
397 | - if ( empty( $user_public_key ) ) { |
|
398 | - $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 ) ); |
|
399 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
397 | + if (empty($user_public_key)) { |
|
398 | + $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)); |
|
399 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | return $user_public_key; |
@@ -409,19 +409,19 @@ discard block |
||
409 | 409 | * |
410 | 410 | * @return mixed|null|string |
411 | 411 | */ |
412 | - public function get_user_secret_key( $user_id = 0 ) { |
|
412 | + public function get_user_secret_key($user_id = 0) { |
|
413 | 413 | global $wpdb; |
414 | 414 | |
415 | - if ( empty( $user_id ) ) { |
|
415 | + if (empty($user_id)) { |
|
416 | 416 | return ''; |
417 | 417 | } |
418 | 418 | |
419 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
420 | - $user_secret_key = Give_Cache::get( $cache_key, true ); |
|
419 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
420 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
421 | 421 | |
422 | - if ( empty( $user_secret_key ) ) { |
|
423 | - $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 ) ); |
|
424 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
422 | + if (empty($user_secret_key)) { |
|
423 | + $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)); |
|
424 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | return $user_secret_key; |
@@ -437,10 +437,10 @@ discard block |
||
437 | 437 | */ |
438 | 438 | private function missing_auth() { |
439 | 439 | $error = array(); |
440 | - $error['error'] = esc_html__( 'You must specify both a token and API key.', 'give' ); |
|
440 | + $error['error'] = esc_html__('You must specify both a token and API key.', 'give'); |
|
441 | 441 | |
442 | 442 | $this->data = $error; |
443 | - $this->output( 401 ); |
|
443 | + $this->output(401); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -454,10 +454,10 @@ discard block |
||
454 | 454 | */ |
455 | 455 | private function invalid_auth() { |
456 | 456 | $error = array(); |
457 | - $error['error'] = esc_html__( 'Your request could not be authenticated.', 'give' ); |
|
457 | + $error['error'] = esc_html__('Your request could not be authenticated.', 'give'); |
|
458 | 458 | |
459 | 459 | $this->data = $error; |
460 | - $this->output( 403 ); |
|
460 | + $this->output(403); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -471,10 +471,10 @@ discard block |
||
471 | 471 | */ |
472 | 472 | private function invalid_key() { |
473 | 473 | $error = array(); |
474 | - $error['error'] = esc_html__( 'Invalid API key.', 'give' ); |
|
474 | + $error['error'] = esc_html__('Invalid API key.', 'give'); |
|
475 | 475 | |
476 | 476 | $this->data = $error; |
477 | - $this->output( 403 ); |
|
477 | + $this->output(403); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -487,10 +487,10 @@ discard block |
||
487 | 487 | */ |
488 | 488 | private function invalid_version() { |
489 | 489 | $error = array(); |
490 | - $error['error'] = esc_html__( 'Invalid API version.', 'give' ); |
|
490 | + $error['error'] = esc_html__('Invalid API version.', 'give'); |
|
491 | 491 | |
492 | 492 | $this->data = $error; |
493 | - $this->output( 404 ); |
|
493 | + $this->output(404); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | global $wp_query; |
507 | 507 | |
508 | 508 | // Start logging how long the request takes for logging |
509 | - $before = microtime( true ); |
|
509 | + $before = microtime(true); |
|
510 | 510 | |
511 | 511 | // Check for give-api var. Get out if not present |
512 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
512 | + if (empty($wp_query->query_vars['give-api'])) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
@@ -523,45 +523,45 @@ discard block |
||
523 | 523 | $this->validate_request(); |
524 | 524 | |
525 | 525 | // Only proceed if no errors have been noted |
526 | - if ( ! $this->is_valid_request ) { |
|
526 | + if ( ! $this->is_valid_request) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
531 | - define( 'GIVE_DOING_API', true ); |
|
530 | + if ( ! defined('GIVE_DOING_API')) { |
|
531 | + define('GIVE_DOING_API', true); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | $data = array(); |
535 | 535 | $this->routes = new $this->versions[$this->get_queried_version()]; |
536 | 536 | $this->routes->validate_request(); |
537 | 537 | |
538 | - switch ( $this->endpoint ) : |
|
538 | + switch ($this->endpoint) : |
|
539 | 539 | |
540 | 540 | case 'stats' : |
541 | 541 | |
542 | - $data = $this->routes->get_stats( array( |
|
543 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
544 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
545 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
546 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
547 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
548 | - ) ); |
|
542 | + $data = $this->routes->get_stats(array( |
|
543 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
544 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
545 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
546 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
547 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
548 | + )); |
|
549 | 549 | |
550 | 550 | break; |
551 | 551 | |
552 | 552 | case 'forms' : |
553 | 553 | |
554 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
554 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
555 | 555 | |
556 | - $data = $this->routes->get_forms( $form ); |
|
556 | + $data = $this->routes->get_forms($form); |
|
557 | 557 | |
558 | 558 | break; |
559 | 559 | |
560 | 560 | case 'donors' : |
561 | 561 | |
562 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
562 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
563 | 563 | |
564 | - $data = $this->routes->get_customers( $customer ); |
|
564 | + $data = $this->routes->get_customers($customer); |
|
565 | 565 | |
566 | 566 | break; |
567 | 567 | |
@@ -574,10 +574,10 @@ discard block |
||
574 | 574 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
575 | 575 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
576 | 576 | */ |
577 | - $data = $this->routes->get_recent_donations( array( |
|
578 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
579 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
580 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
577 | + $data = $this->routes->get_recent_donations(array( |
|
578 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
579 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
580 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
581 | 581 | )); |
582 | 582 | |
583 | 583 | break; |
@@ -585,14 +585,14 @@ discard block |
||
585 | 585 | endswitch; |
586 | 586 | |
587 | 587 | // Allow extensions to setup their own return data |
588 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
588 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
589 | 589 | |
590 | - $after = microtime( true ); |
|
591 | - $request_time = ( $after - $before ); |
|
590 | + $after = microtime(true); |
|
591 | + $request_time = ($after - $before); |
|
592 | 592 | $this->data['request_speed'] = $request_time; |
593 | 593 | |
594 | 594 | // Log this API request, if enabled. We log it here because we have access to errors. |
595 | - $this->log_request( $this->data ); |
|
595 | + $this->log_request($this->data); |
|
596 | 596 | |
597 | 597 | // Send out data to the output function |
598 | 598 | $this->output(); |
@@ -622,25 +622,25 @@ discard block |
||
622 | 622 | global $wp_query; |
623 | 623 | |
624 | 624 | // Whitelist our query options |
625 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
625 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
626 | 626 | 'stats', |
627 | 627 | 'forms', |
628 | 628 | 'donors', |
629 | 629 | 'donations', |
630 | - ) ); |
|
630 | + )); |
|
631 | 631 | |
632 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
633 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
632 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
633 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
634 | 634 | |
635 | 635 | $error = array(); |
636 | 636 | |
637 | 637 | // Make sure our query is valid |
638 | - if ( ! in_array( $query, $accepted ) ) { |
|
639 | - $error['error'] = esc_html__( 'Invalid query.', 'give' ); |
|
638 | + if ( ! in_array($query, $accepted)) { |
|
639 | + $error['error'] = esc_html__('Invalid query.', 'give'); |
|
640 | 640 | |
641 | 641 | $this->data = $error; |
642 | 642 | // 400 is Bad Request |
643 | - $this->output( 400 ); |
|
643 | + $this->output(400); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | $this->endpoint = $query; |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | public function get_paged() { |
658 | 658 | global $wp_query; |
659 | 659 | |
660 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
660 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | |
@@ -672,13 +672,13 @@ discard block |
||
672 | 672 | public function per_page() { |
673 | 673 | global $wp_query; |
674 | 674 | |
675 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
675 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
676 | 676 | |
677 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
677 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
678 | 678 | $per_page = 99999999; |
679 | 679 | } // Customers query doesn't support -1 |
680 | 680 | |
681 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
681 | + return apply_filters('give_api_results_per_page', $per_page); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * |
692 | 692 | * @return array $dates |
693 | 693 | */ |
694 | - public function get_dates( $args = array() ) { |
|
694 | + public function get_dates($args = array()) { |
|
695 | 695 | $dates = array(); |
696 | 696 | |
697 | 697 | $defaults = array( |
@@ -702,60 +702,60 @@ discard block |
||
702 | 702 | 'enddate' => null, |
703 | 703 | ); |
704 | 704 | |
705 | - $args = wp_parse_args( $args, $defaults ); |
|
705 | + $args = wp_parse_args($args, $defaults); |
|
706 | 706 | |
707 | - $current_time = current_time( 'timestamp' ); |
|
707 | + $current_time = current_time('timestamp'); |
|
708 | 708 | |
709 | - if ( 'range' === $args['date'] ) { |
|
710 | - $startdate = strtotime( $args['startdate'] ); |
|
711 | - $enddate = strtotime( $args['enddate'] ); |
|
712 | - $dates['day_start'] = date( 'd', $startdate ); |
|
713 | - $dates['day_end'] = date( 'd', $enddate ); |
|
714 | - $dates['m_start'] = date( 'n', $startdate ); |
|
715 | - $dates['m_end'] = date( 'n', $enddate ); |
|
716 | - $dates['year'] = date( 'Y', $startdate ); |
|
717 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
709 | + if ('range' === $args['date']) { |
|
710 | + $startdate = strtotime($args['startdate']); |
|
711 | + $enddate = strtotime($args['enddate']); |
|
712 | + $dates['day_start'] = date('d', $startdate); |
|
713 | + $dates['day_end'] = date('d', $enddate); |
|
714 | + $dates['m_start'] = date('n', $startdate); |
|
715 | + $dates['m_end'] = date('n', $enddate); |
|
716 | + $dates['year'] = date('Y', $startdate); |
|
717 | + $dates['year_end'] = date('Y', $enddate); |
|
718 | 718 | } else { |
719 | 719 | // Modify dates based on predefined ranges |
720 | - switch ( $args['date'] ) : |
|
720 | + switch ($args['date']) : |
|
721 | 721 | |
722 | 722 | case 'this_month' : |
723 | 723 | $dates['day'] = null; |
724 | - $dates['m_start'] = date( 'n', $current_time ); |
|
725 | - $dates['m_end'] = date( 'n', $current_time ); |
|
726 | - $dates['year'] = date( 'Y', $current_time ); |
|
724 | + $dates['m_start'] = date('n', $current_time); |
|
725 | + $dates['m_end'] = date('n', $current_time); |
|
726 | + $dates['year'] = date('Y', $current_time); |
|
727 | 727 | break; |
728 | 728 | |
729 | 729 | case 'last_month' : |
730 | 730 | $dates['day'] = null; |
731 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
731 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
732 | 732 | $dates['m_end'] = $dates['m_start']; |
733 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
733 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
734 | 734 | break; |
735 | 735 | |
736 | 736 | case 'today' : |
737 | - $dates['day'] = date( 'd', $current_time ); |
|
738 | - $dates['m_start'] = date( 'n', $current_time ); |
|
739 | - $dates['m_end'] = date( 'n', $current_time ); |
|
740 | - $dates['year'] = date( 'Y', $current_time ); |
|
737 | + $dates['day'] = date('d', $current_time); |
|
738 | + $dates['m_start'] = date('n', $current_time); |
|
739 | + $dates['m_end'] = date('n', $current_time); |
|
740 | + $dates['year'] = date('Y', $current_time); |
|
741 | 741 | break; |
742 | 742 | |
743 | 743 | case 'yesterday' : |
744 | 744 | |
745 | - $year = date( 'Y', $current_time ); |
|
746 | - $month = date( 'n', $current_time ); |
|
747 | - $day = date( 'd', $current_time ); |
|
745 | + $year = date('Y', $current_time); |
|
746 | + $month = date('n', $current_time); |
|
747 | + $day = date('d', $current_time); |
|
748 | 748 | |
749 | - if ( $month == 1 && $day == 1 ) { |
|
749 | + if ($month == 1 && $day == 1) { |
|
750 | 750 | |
751 | 751 | $year -= 1; |
752 | 752 | $month = 12; |
753 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
753 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
754 | 754 | |
755 | - } elseif ( $month > 1 && $day == 1 ) { |
|
755 | + } elseif ($month > 1 && $day == 1) { |
|
756 | 756 | |
757 | 757 | $month -= 1; |
758 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
758 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
759 | 759 | |
760 | 760 | } else { |
761 | 761 | |
@@ -771,65 +771,65 @@ discard block |
||
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'this_quarter' : |
774 | - $month_now = date( 'n', $current_time ); |
|
774 | + $month_now = date('n', $current_time); |
|
775 | 775 | |
776 | 776 | $dates['day'] = null; |
777 | 777 | |
778 | - if ( $month_now <= 3 ) { |
|
778 | + if ($month_now <= 3) { |
|
779 | 779 | |
780 | 780 | $dates['m_start'] = 1; |
781 | 781 | $dates['m_end'] = 3; |
782 | - $dates['year'] = date( 'Y', $current_time ); |
|
782 | + $dates['year'] = date('Y', $current_time); |
|
783 | 783 | |
784 | - } elseif ( $month_now <= 6 ) { |
|
784 | + } elseif ($month_now <= 6) { |
|
785 | 785 | |
786 | 786 | $dates['m_start'] = 4; |
787 | 787 | $dates['m_end'] = 6; |
788 | - $dates['year'] = date( 'Y', $current_time ); |
|
788 | + $dates['year'] = date('Y', $current_time); |
|
789 | 789 | |
790 | - } elseif ( $month_now <= 9 ) { |
|
790 | + } elseif ($month_now <= 9) { |
|
791 | 791 | |
792 | 792 | $dates['m_start'] = 7; |
793 | 793 | $dates['m_end'] = 9; |
794 | - $dates['year'] = date( 'Y', $current_time ); |
|
794 | + $dates['year'] = date('Y', $current_time); |
|
795 | 795 | |
796 | 796 | } else { |
797 | 797 | |
798 | 798 | $dates['m_start'] = 10; |
799 | 799 | $dates['m_end'] = 12; |
800 | - $dates['year'] = date( 'Y', $current_time ); |
|
800 | + $dates['year'] = date('Y', $current_time); |
|
801 | 801 | |
802 | 802 | } |
803 | 803 | break; |
804 | 804 | |
805 | 805 | case 'last_quarter' : |
806 | - $month_now = date( 'n', $current_time ); |
|
806 | + $month_now = date('n', $current_time); |
|
807 | 807 | |
808 | 808 | $dates['day'] = null; |
809 | 809 | |
810 | - if ( $month_now <= 3 ) { |
|
810 | + if ($month_now <= 3) { |
|
811 | 811 | |
812 | 812 | $dates['m_start'] = 10; |
813 | 813 | $dates['m_end'] = 12; |
814 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
814 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
815 | 815 | |
816 | - } elseif ( $month_now <= 6 ) { |
|
816 | + } elseif ($month_now <= 6) { |
|
817 | 817 | |
818 | 818 | $dates['m_start'] = 1; |
819 | 819 | $dates['m_end'] = 3; |
820 | - $dates['year'] = date( 'Y', $current_time ); |
|
820 | + $dates['year'] = date('Y', $current_time); |
|
821 | 821 | |
822 | - } elseif ( $month_now <= 9 ) { |
|
822 | + } elseif ($month_now <= 9) { |
|
823 | 823 | |
824 | 824 | $dates['m_start'] = 4; |
825 | 825 | $dates['m_end'] = 6; |
826 | - $dates['year'] = date( 'Y', $current_time ); |
|
826 | + $dates['year'] = date('Y', $current_time); |
|
827 | 827 | |
828 | 828 | } else { |
829 | 829 | |
830 | 830 | $dates['m_start'] = 7; |
831 | 831 | $dates['m_end'] = 9; |
832 | - $dates['year'] = date( 'Y', $current_time ); |
|
832 | + $dates['year'] = date('Y', $current_time); |
|
833 | 833 | |
834 | 834 | } |
835 | 835 | break; |
@@ -838,14 +838,14 @@ discard block |
||
838 | 838 | $dates['day'] = null; |
839 | 839 | $dates['m_start'] = null; |
840 | 840 | $dates['m_end'] = null; |
841 | - $dates['year'] = date( 'Y', $current_time ); |
|
841 | + $dates['year'] = date('Y', $current_time); |
|
842 | 842 | break; |
843 | 843 | |
844 | 844 | case 'last_year' : |
845 | 845 | $dates['day'] = null; |
846 | 846 | $dates['m_start'] = null; |
847 | 847 | $dates['m_end'] = null; |
848 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
848 | + $dates['year'] = date('Y', $current_time) - 1; |
|
849 | 849 | break; |
850 | 850 | |
851 | 851 | endswitch; |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | * |
859 | 859 | * @param array $dates The dates used for retrieving earnings/donations |
860 | 860 | */ |
861 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
861 | + return apply_filters('give_api_stat_dates', $dates); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | /** |
@@ -873,11 +873,11 @@ discard block |
||
873 | 873 | * |
874 | 874 | * @return array $customers Multidimensional array of the customers |
875 | 875 | */ |
876 | - public function get_customers( $customer = null ) { |
|
876 | + public function get_customers($customer = null) { |
|
877 | 877 | |
878 | 878 | $customers = array(); |
879 | 879 | $error = array(); |
880 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
880 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
881 | 881 | return $customers; |
882 | 882 | } |
883 | 883 | |
@@ -885,63 +885,63 @@ discard block |
||
885 | 885 | |
886 | 886 | $paged = $this->get_paged(); |
887 | 887 | $per_page = $this->per_page(); |
888 | - $offset = $per_page * ( $paged - 1 ); |
|
888 | + $offset = $per_page * ($paged - 1); |
|
889 | 889 | |
890 | - if ( is_numeric( $customer ) ) { |
|
890 | + if (is_numeric($customer)) { |
|
891 | 891 | $field = 'id'; |
892 | 892 | } else { |
893 | 893 | $field = 'email'; |
894 | 894 | } |
895 | 895 | |
896 | - $customer_query = Give()->customers->get_customers( array( |
|
896 | + $customer_query = Give()->customers->get_customers(array( |
|
897 | 897 | 'number' => $per_page, |
898 | 898 | 'offset' => $offset, |
899 | 899 | $field => $customer, |
900 | - ) ); |
|
900 | + )); |
|
901 | 901 | $customer_count = 0; |
902 | 902 | |
903 | - if ( $customer_query ) { |
|
903 | + if ($customer_query) { |
|
904 | 904 | |
905 | - foreach ( $customer_query as $customer_obj ) { |
|
905 | + foreach ($customer_query as $customer_obj) { |
|
906 | 906 | |
907 | - $names = explode( ' ', $customer_obj->name ); |
|
908 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
907 | + $names = explode(' ', $customer_obj->name); |
|
908 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
909 | 909 | $last_name = ''; |
910 | - if ( ! empty( $names[1] ) ) { |
|
911 | - unset( $names[0] ); |
|
912 | - $last_name = implode( ' ', $names ); |
|
910 | + if ( ! empty($names[1])) { |
|
911 | + unset($names[0]); |
|
912 | + $last_name = implode(' ', $names); |
|
913 | 913 | } |
914 | 914 | |
915 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
916 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
917 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
918 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
919 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
920 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
921 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
915 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
916 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
917 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
918 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
919 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
920 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
921 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
922 | 922 | |
923 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
923 | + if ( ! empty($customer_obj->user_id)) { |
|
924 | 924 | |
925 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
925 | + $user_data = get_userdata($customer_obj->user_id); |
|
926 | 926 | |
927 | 927 | // Customer with registered account. |
928 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
929 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
930 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
928 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
929 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
930 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
931 | 931 | |
932 | 932 | } |
933 | 933 | |
934 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
935 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
934 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
935 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
936 | 936 | |
937 | - $customer_count ++; |
|
937 | + $customer_count++; |
|
938 | 938 | |
939 | 939 | } |
940 | - } elseif ( $customer ) { |
|
940 | + } elseif ($customer) { |
|
941 | 941 | |
942 | 942 | $error['error'] = sprintf( |
943 | 943 | /* translators: %s: customer */ |
944 | - esc_html__( 'Donor %s not found.', 'give' ), |
|
944 | + esc_html__('Donor %s not found.', 'give'), |
|
945 | 945 | $customer |
946 | 946 | ); |
947 | 947 | |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | |
950 | 950 | } else { |
951 | 951 | |
952 | - $error['error'] = esc_html__( 'No donors found.', 'give' ); |
|
952 | + $error['error'] = esc_html__('No donors found.', 'give'); |
|
953 | 953 | |
954 | 954 | return $error; |
955 | 955 | |
@@ -968,38 +968,38 @@ discard block |
||
968 | 968 | * |
969 | 969 | * @return array $customers Multidimensional array of the forms |
970 | 970 | */ |
971 | - public function get_forms( $form = null ) { |
|
971 | + public function get_forms($form = null) { |
|
972 | 972 | |
973 | 973 | $forms = array(); |
974 | 974 | $error = array(); |
975 | 975 | |
976 | - if ( $form == null ) { |
|
976 | + if ($form == null) { |
|
977 | 977 | $forms['forms'] = array(); |
978 | 978 | |
979 | - $form_list = get_posts( array( |
|
979 | + $form_list = get_posts(array( |
|
980 | 980 | 'post_type' => 'give_forms', |
981 | 981 | 'posts_per_page' => $this->per_page(), |
982 | 982 | 'suppress_filters' => true, |
983 | 983 | 'paged' => $this->get_paged(), |
984 | - ) ); |
|
984 | + )); |
|
985 | 985 | |
986 | - if ( $form_list ) { |
|
986 | + if ($form_list) { |
|
987 | 987 | $i = 0; |
988 | - foreach ( $form_list as $form_info ) { |
|
989 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
990 | - $i ++; |
|
988 | + foreach ($form_list as $form_info) { |
|
989 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
990 | + $i++; |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | } else { |
994 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
995 | - $form_info = get_post( $form ); |
|
994 | + if (get_post_type($form) == 'give_forms') { |
|
995 | + $form_info = get_post($form); |
|
996 | 996 | |
997 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
997 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
998 | 998 | |
999 | 999 | } else { |
1000 | 1000 | $error['error'] = sprintf( |
1001 | 1001 | /* translators: %s: form */ |
1002 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1002 | + esc_html__('Form %s not found.', 'give'), |
|
1003 | 1003 | $form |
1004 | 1004 | ); |
1005 | 1005 | |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | * |
1020 | 1020 | * @return array Array of post data to return back in the API |
1021 | 1021 | */ |
1022 | - private function get_form_data( $form_info ) { |
|
1022 | + private function get_form_data($form_info) { |
|
1023 | 1023 | |
1024 | 1024 | $form = array(); |
1025 | 1025 | |
@@ -1029,50 +1029,50 @@ discard block |
||
1029 | 1029 | $form['info']['create_date'] = $form_info->post_date; |
1030 | 1030 | $form['info']['modified_date'] = $form_info->post_modified; |
1031 | 1031 | $form['info']['status'] = $form_info->post_status; |
1032 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1033 | - $form['info']['content'] = give_get_meta( $form_info->ID, '_give_form_content', true ); |
|
1034 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1032 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1033 | + $form['info']['content'] = give_get_meta($form_info->ID, '_give_form_content', true); |
|
1034 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1035 | 1035 | |
1036 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
1037 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1038 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1036 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
1037 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1038 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1039 | 1039 | } |
1040 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
1041 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1040 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
1041 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1045 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1046 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1047 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1048 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1044 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1045 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1046 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1047 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1048 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | $counter = 0; |
1052 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1053 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1054 | - $counter ++; |
|
1052 | + if (give_has_variable_prices($form_info->ID)) { |
|
1053 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1054 | + $counter++; |
|
1055 | 1055 | // muli-level item |
1056 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1057 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1056 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1057 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1058 | 1058 | |
1059 | 1059 | } |
1060 | 1060 | } else { |
1061 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1061 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1064 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1065 | 1065 | |
1066 | 1066 | /** |
1067 | 1067 | * Fires when generating API sensitive data. |
1068 | 1068 | * |
1069 | 1069 | * @since 1.1 |
1070 | 1070 | */ |
1071 | - do_action( 'give_api_sensitive_data' ); |
|
1071 | + do_action('give_api_sensitive_data'); |
|
1072 | 1072 | |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1075 | + return apply_filters('give_api_forms_form', $form); |
|
1076 | 1076 | |
1077 | 1077 | } |
1078 | 1078 | |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | * |
1088 | 1088 | * @return array |
1089 | 1089 | */ |
1090 | - public function get_stats( $args = array() ) { |
|
1090 | + public function get_stats($args = array()) { |
|
1091 | 1091 | $defaults = array( |
1092 | 1092 | 'type' => null, |
1093 | 1093 | 'form' => null, |
@@ -1096,9 +1096,9 @@ discard block |
||
1096 | 1096 | 'enddate' => null, |
1097 | 1097 | ); |
1098 | 1098 | |
1099 | - $args = wp_parse_args( $args, $defaults ); |
|
1099 | + $args = wp_parse_args($args, $defaults); |
|
1100 | 1100 | |
1101 | - $dates = $this->get_dates( $args ); |
|
1101 | + $dates = $this->get_dates($args); |
|
1102 | 1102 | |
1103 | 1103 | $stats = array(); |
1104 | 1104 | $earnings = array( |
@@ -1109,40 +1109,40 @@ discard block |
||
1109 | 1109 | ); |
1110 | 1110 | $error = array(); |
1111 | 1111 | |
1112 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1112 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1113 | 1113 | return $stats; |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ( $args['type'] == 'donations' ) { |
|
1116 | + if ($args['type'] == 'donations') { |
|
1117 | 1117 | |
1118 | - if ( $args['form'] == null ) { |
|
1119 | - if ( $args['date'] == null ) { |
|
1118 | + if ($args['form'] == null) { |
|
1119 | + if ($args['date'] == null) { |
|
1120 | 1120 | $sales = $this->get_default_sales_stats(); |
1121 | - } elseif ( $args['date'] === 'range' ) { |
|
1121 | + } elseif ($args['date'] === 'range') { |
|
1122 | 1122 | // Return sales for a date range |
1123 | 1123 | // Ensure the end date is later than the start date |
1124 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1125 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1124 | + if ($args['enddate'] < $args['startdate']) { |
|
1125 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // Ensure both the start and end date are specified |
1129 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1130 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1129 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1130 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | $total = 0; |
1134 | 1134 | |
1135 | 1135 | // Loop through the years |
1136 | 1136 | $y = $dates['year']; |
1137 | - while ( $y <= $dates['year_end'] ) : |
|
1137 | + while ($y <= $dates['year_end']) : |
|
1138 | 1138 | |
1139 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1139 | + if ($dates['year'] == $dates['year_end']) { |
|
1140 | 1140 | $month_start = $dates['m_start']; |
1141 | 1141 | $month_end = $dates['m_end']; |
1142 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1142 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1143 | 1143 | $month_start = $dates['m_start']; |
1144 | 1144 | $month_end = 12; |
1145 | - } elseif ( $y == $dates['year_end'] ) { |
|
1145 | + } elseif ($y == $dates['year_end']) { |
|
1146 | 1146 | $month_start = 1; |
1147 | 1147 | $month_end = $dates['m_end']; |
1148 | 1148 | } else { |
@@ -1151,112 +1151,112 @@ discard block |
||
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | $i = $month_start; |
1154 | - while ( $i <= $month_end ) : |
|
1154 | + while ($i <= $month_end) : |
|
1155 | 1155 | |
1156 | - if ( $i == $dates['m_start'] ) { |
|
1156 | + if ($i == $dates['m_start']) { |
|
1157 | 1157 | $d = $dates['day_start']; |
1158 | 1158 | } else { |
1159 | 1159 | $d = 1; |
1160 | 1160 | } |
1161 | 1161 | |
1162 | - if ( $i == $dates['m_end'] ) { |
|
1162 | + if ($i == $dates['m_end']) { |
|
1163 | 1163 | $num_of_days = $dates['day_end']; |
1164 | 1164 | } else { |
1165 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1165 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | - while ( $d <= $num_of_days ) : |
|
1169 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1170 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1171 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1172 | - $sales['sales'][ $date_key ] = 0; |
|
1168 | + while ($d <= $num_of_days) : |
|
1169 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1170 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1171 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1172 | + $sales['sales'][$date_key] = 0; |
|
1173 | 1173 | } |
1174 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1174 | + $sales['sales'][$date_key] += $sale_count; |
|
1175 | 1175 | $total += $sale_count; |
1176 | - $d ++; |
|
1176 | + $d++; |
|
1177 | 1177 | endwhile; |
1178 | - $i ++; |
|
1178 | + $i++; |
|
1179 | 1179 | endwhile; |
1180 | 1180 | |
1181 | - $y ++; |
|
1181 | + $y++; |
|
1182 | 1182 | endwhile; |
1183 | 1183 | |
1184 | 1184 | $sales['totals'] = $total; |
1185 | 1185 | } else { |
1186 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1186 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1187 | 1187 | $sales_count = 0; |
1188 | 1188 | |
1189 | 1189 | // Loop through the months |
1190 | 1190 | $month = $dates['m_start']; |
1191 | 1191 | |
1192 | - while ( $month <= $dates['m_end'] ) : |
|
1193 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1194 | - $month ++; |
|
1192 | + while ($month <= $dates['m_end']) : |
|
1193 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1194 | + $month++; |
|
1195 | 1195 | endwhile; |
1196 | 1196 | |
1197 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1197 | + $sales['donations'][$args['date']] = $sales_count; |
|
1198 | 1198 | } else { |
1199 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1199 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1200 | 1200 | } |
1201 | 1201 | } |
1202 | - } elseif ( $args['form'] == 'all' ) { |
|
1203 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1202 | + } elseif ($args['form'] == 'all') { |
|
1203 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1204 | 1204 | $i = 0; |
1205 | - foreach ( $forms as $form_info ) { |
|
1206 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1207 | - $i ++; |
|
1205 | + foreach ($forms as $form_info) { |
|
1206 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1207 | + $i++; |
|
1208 | 1208 | } |
1209 | 1209 | } else { |
1210 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1211 | - $form_info = get_post( $args['form'] ); |
|
1212 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1210 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1211 | + $form_info = get_post($args['form']); |
|
1212 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1213 | 1213 | } else { |
1214 | 1214 | $error['error'] = sprintf( |
1215 | 1215 | /* translators: %s: form */ |
1216 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1216 | + esc_html__('Form %s not found.', 'give'), |
|
1217 | 1217 | $args['form'] |
1218 | 1218 | ); |
1219 | 1219 | } |
1220 | 1220 | } |
1221 | 1221 | |
1222 | - if ( ! empty( $error ) ) { |
|
1222 | + if ( ! empty($error)) { |
|
1223 | 1223 | return $error; |
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | return $sales; |
1227 | 1227 | |
1228 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1229 | - if ( $args['form'] == null ) { |
|
1230 | - if ( $args['date'] == null ) { |
|
1228 | + } elseif ($args['type'] == 'earnings') { |
|
1229 | + if ($args['form'] == null) { |
|
1230 | + if ($args['date'] == null) { |
|
1231 | 1231 | $earnings = $this->get_default_earnings_stats(); |
1232 | - } elseif ( $args['date'] === 'range' ) { |
|
1232 | + } elseif ($args['date'] === 'range') { |
|
1233 | 1233 | // Return sales for a date range |
1234 | 1234 | // Ensure the end date is later than the start date |
1235 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1236 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1235 | + if ($args['enddate'] < $args['startdate']) { |
|
1236 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | // Ensure both the start and end date are specified |
1240 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1241 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1240 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1241 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | $total = (float) 0.00; |
1245 | 1245 | |
1246 | 1246 | // Loop through the years |
1247 | 1247 | $y = $dates['year']; |
1248 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1248 | + if ( ! isset($earnings['earnings'])) { |
|
1249 | 1249 | $earnings['earnings'] = array(); |
1250 | 1250 | } |
1251 | - while ( $y <= $dates['year_end'] ) : |
|
1251 | + while ($y <= $dates['year_end']) : |
|
1252 | 1252 | |
1253 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1253 | + if ($dates['year'] == $dates['year_end']) { |
|
1254 | 1254 | $month_start = $dates['m_start']; |
1255 | 1255 | $month_end = $dates['m_end']; |
1256 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1256 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1257 | 1257 | $month_start = $dates['m_start']; |
1258 | 1258 | $month_end = 12; |
1259 | - } elseif ( $y == $dates['year_end'] ) { |
|
1259 | + } elseif ($y == $dates['year_end']) { |
|
1260 | 1260 | $month_start = 1; |
1261 | 1261 | $month_end = $dates['m_end']; |
1262 | 1262 | } else { |
@@ -1265,92 +1265,92 @@ discard block |
||
1265 | 1265 | } |
1266 | 1266 | |
1267 | 1267 | $i = $month_start; |
1268 | - while ( $i <= $month_end ) : |
|
1268 | + while ($i <= $month_end) : |
|
1269 | 1269 | |
1270 | - if ( $i == $dates['m_start'] ) { |
|
1270 | + if ($i == $dates['m_start']) { |
|
1271 | 1271 | $d = $dates['day_start']; |
1272 | 1272 | } else { |
1273 | 1273 | $d = 1; |
1274 | 1274 | } |
1275 | 1275 | |
1276 | - if ( $i == $dates['m_end'] ) { |
|
1276 | + if ($i == $dates['m_end']) { |
|
1277 | 1277 | $num_of_days = $dates['day_end']; |
1278 | 1278 | } else { |
1279 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1279 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | - while ( $d <= $num_of_days ) : |
|
1283 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1284 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1285 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1286 | - $earnings['earnings'][ $date_key ] = 0; |
|
1282 | + while ($d <= $num_of_days) : |
|
1283 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1284 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1285 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1286 | + $earnings['earnings'][$date_key] = 0; |
|
1287 | 1287 | } |
1288 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1288 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1289 | 1289 | $total += $earnings_stat; |
1290 | - $d ++; |
|
1290 | + $d++; |
|
1291 | 1291 | endwhile; |
1292 | 1292 | |
1293 | - $i ++; |
|
1293 | + $i++; |
|
1294 | 1294 | endwhile; |
1295 | 1295 | |
1296 | - $y ++; |
|
1296 | + $y++; |
|
1297 | 1297 | endwhile; |
1298 | 1298 | |
1299 | 1299 | $earnings['totals'] = $total; |
1300 | 1300 | } else { |
1301 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1301 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1302 | 1302 | $earnings_count = (float) 0.00; |
1303 | 1303 | |
1304 | 1304 | // Loop through the months |
1305 | 1305 | $month = $dates['m_start']; |
1306 | 1306 | |
1307 | - while ( $month <= $dates['m_end'] ) : |
|
1308 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1309 | - $month ++; |
|
1307 | + while ($month <= $dates['m_end']) : |
|
1308 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1309 | + $month++; |
|
1310 | 1310 | endwhile; |
1311 | 1311 | |
1312 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1312 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1313 | 1313 | } else { |
1314 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1314 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1315 | 1315 | } |
1316 | 1316 | } |
1317 | - } elseif ( $args['form'] == 'all' ) { |
|
1318 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1317 | + } elseif ($args['form'] == 'all') { |
|
1318 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1319 | 1319 | |
1320 | 1320 | $i = 0; |
1321 | - foreach ( $forms as $form_info ) { |
|
1322 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1323 | - $i ++; |
|
1321 | + foreach ($forms as $form_info) { |
|
1322 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1323 | + $i++; |
|
1324 | 1324 | } |
1325 | 1325 | } else { |
1326 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1327 | - $form_info = get_post( $args['form'] ); |
|
1328 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1326 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1327 | + $form_info = get_post($args['form']); |
|
1328 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1329 | 1329 | } else { |
1330 | 1330 | $error['error'] = sprintf( |
1331 | 1331 | /* translators: %s: form */ |
1332 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1332 | + esc_html__('Form %s not found.', 'give'), |
|
1333 | 1333 | $args['form'] |
1334 | 1334 | ); |
1335 | 1335 | } |
1336 | 1336 | } |
1337 | 1337 | |
1338 | - if ( ! empty( $error ) ) { |
|
1338 | + if ( ! empty($error)) { |
|
1339 | 1339 | return $error; |
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | return $earnings; |
1343 | - } elseif ( $args['type'] == 'donors' ) { |
|
1343 | + } elseif ($args['type'] == 'donors') { |
|
1344 | 1344 | $customers = new Give_DB_Customers(); |
1345 | 1345 | $stats['donations']['total_donors'] = $customers->count(); |
1346 | 1346 | |
1347 | 1347 | return $stats; |
1348 | 1348 | |
1349 | - } elseif ( empty( $args['type'] ) ) { |
|
1350 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1351 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1349 | + } elseif (empty($args['type'])) { |
|
1350 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1351 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1352 | 1352 | |
1353 | - return array( 'stats' => $stats ); |
|
1353 | + return array('stats' => $stats); |
|
1354 | 1354 | } |
1355 | 1355 | } |
1356 | 1356 | |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | * @since 1.1 |
1362 | 1362 | * @return array |
1363 | 1363 | */ |
1364 | - public function get_recent_donations( $args = array() ) { |
|
1364 | + public function get_recent_donations($args = array()) { |
|
1365 | 1365 | global $wp_query; |
1366 | 1366 | |
1367 | 1367 | $defaults = array( |
@@ -1370,22 +1370,22 @@ discard block |
||
1370 | 1370 | 'enddate' => null, |
1371 | 1371 | ); |
1372 | 1372 | |
1373 | - $args = wp_parse_args( $args, $defaults ); |
|
1373 | + $args = wp_parse_args($args, $defaults); |
|
1374 | 1374 | |
1375 | 1375 | $sales = array(); |
1376 | 1376 | |
1377 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1377 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1378 | 1378 | return $sales; |
1379 | 1379 | } |
1380 | 1380 | |
1381 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1381 | + if (isset($wp_query->query_vars['id'])) { |
|
1382 | 1382 | $query = array(); |
1383 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1384 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1383 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1384 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1385 | 1385 | $query = array(); |
1386 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1387 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1388 | - $args = array( |
|
1386 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1387 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1388 | + $args = array( |
|
1389 | 1389 | 'fields' => 'ids', |
1390 | 1390 | 'meta_key' => '_give_payment_user_email', |
1391 | 1391 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1393,11 +1393,11 @@ discard block |
||
1393 | 1393 | 'page' => $this->get_paged(), |
1394 | 1394 | 'status' => 'publish', |
1395 | 1395 | ); |
1396 | - $query = give_get_payments( $args ); |
|
1397 | - } elseif ( isset( $wp_query->query_vars['date'] ) ) { |
|
1396 | + $query = give_get_payments($args); |
|
1397 | + } elseif (isset($wp_query->query_vars['date'])) { |
|
1398 | 1398 | |
1399 | - $current_time = current_time( 'timestamp' ); |
|
1400 | - $dates = $this->get_dates( $args ); |
|
1399 | + $current_time = current_time('timestamp'); |
|
1400 | + $dates = $this->get_dates($args); |
|
1401 | 1401 | |
1402 | 1402 | /** |
1403 | 1403 | * Switch case for date query argument |
@@ -1408,33 +1408,33 @@ discard block |
||
1408 | 1408 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
1409 | 1409 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
1410 | 1410 | */ |
1411 | - switch( $wp_query->query_vars['date'] ){ |
|
1411 | + switch ($wp_query->query_vars['date']) { |
|
1412 | 1412 | |
1413 | 1413 | case 'today': |
1414 | 1414 | |
1415 | 1415 | // Set and Format Start and End Date to be date of today. |
1416 | - $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
1416 | + $start_date = $end_date = date('Y/m/d', $current_time); |
|
1417 | 1417 | |
1418 | 1418 | break; |
1419 | 1419 | |
1420 | 1420 | case 'yesterday': |
1421 | 1421 | |
1422 | 1422 | // Set and Format Start and End Date to be date of yesterday. |
1423 | - $start_date = $end_date = date( 'Y/m', $current_time ) . '/'. ( date( 'd', $current_time ) - 1 ); |
|
1423 | + $start_date = $end_date = date('Y/m', $current_time).'/'.(date('d', $current_time) - 1); |
|
1424 | 1424 | |
1425 | 1425 | break; |
1426 | 1426 | |
1427 | 1427 | case 'range': |
1428 | 1428 | |
1429 | 1429 | // Format Start Date and End Date for filtering payment based on date range. |
1430 | - $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
1431 | - $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
1430 | + $start_date = $dates['year'].'/'.$dates['m_start'].'/'.$dates['day_start']; |
|
1431 | + $end_date = $dates['year_end'].'/'.$dates['m_end'].'/'.$dates['day_end']; |
|
1432 | 1432 | |
1433 | 1433 | break; |
1434 | 1434 | |
1435 | 1435 | } |
1436 | 1436 | |
1437 | - $args = array( |
|
1437 | + $args = array( |
|
1438 | 1438 | 'fields' => 'ids', |
1439 | 1439 | 'start_date' => $start_date, |
1440 | 1440 | 'end_date' => $end_date, |
@@ -1443,7 +1443,7 @@ discard block |
||
1443 | 1443 | 'status' => 'publish', |
1444 | 1444 | ); |
1445 | 1445 | |
1446 | - $query = give_get_payments( $args ); |
|
1446 | + $query = give_get_payments($args); |
|
1447 | 1447 | } else { |
1448 | 1448 | $args = array( |
1449 | 1449 | 'fields' => 'ids', |
@@ -1451,14 +1451,14 @@ discard block |
||
1451 | 1451 | 'page' => $this->get_paged(), |
1452 | 1452 | 'status' => 'publish', |
1453 | 1453 | ); |
1454 | - $query = give_get_payments( $args ); |
|
1454 | + $query = give_get_payments($args); |
|
1455 | 1455 | } |
1456 | - if ( $query ) { |
|
1456 | + if ($query) { |
|
1457 | 1457 | $i = 0; |
1458 | - foreach ( $query as $payment ) { |
|
1458 | + foreach ($query as $payment) { |
|
1459 | 1459 | |
1460 | - if ( is_numeric( $payment ) ) { |
|
1461 | - $payment = new Give_Payment( $payment ); |
|
1460 | + if (is_numeric($payment)) { |
|
1461 | + $payment = new Give_Payment($payment); |
|
1462 | 1462 | $payment_meta = $payment->get_meta(); |
1463 | 1463 | $user_info = $payment->user_info; |
1464 | 1464 | } else { |
@@ -1468,40 +1468,40 @@ discard block |
||
1468 | 1468 | $payment_meta = $payment->get_meta(); |
1469 | 1469 | $user_info = $payment->user_info; |
1470 | 1470 | |
1471 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1472 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1473 | - |
|
1474 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1475 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1476 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1477 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1478 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1479 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1480 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1481 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1482 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1483 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1484 | - |
|
1485 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1486 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1487 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1488 | - |
|
1489 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1490 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1491 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1492 | - |
|
1493 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1494 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1495 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1496 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1497 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1498 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1471 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1472 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1473 | + |
|
1474 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1475 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1476 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1477 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1478 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1479 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1480 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1481 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1482 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1483 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1484 | + |
|
1485 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1486 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1487 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1488 | + |
|
1489 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1490 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1491 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1492 | + |
|
1493 | + if (give_has_variable_prices($form_id)) { |
|
1494 | + if (isset($payment_meta['price_id'])) { |
|
1495 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1496 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1497 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1498 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1499 | 1499 | |
1500 | 1500 | } |
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | // Add custom meta to API |
1504 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1504 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1505 | 1505 | |
1506 | 1506 | $exceptions = array( |
1507 | 1507 | 'form_title', |
@@ -1514,19 +1514,19 @@ discard block |
||
1514 | 1514 | ); |
1515 | 1515 | |
1516 | 1516 | // Don't clutter up results with dupes |
1517 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1517 | + if (in_array($meta_key, $exceptions)) { |
|
1518 | 1518 | continue; |
1519 | 1519 | } |
1520 | 1520 | |
1521 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1521 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1522 | 1522 | |
1523 | 1523 | } |
1524 | 1524 | |
1525 | - $i ++; |
|
1525 | + $i++; |
|
1526 | 1526 | } |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1529 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1530 | 1530 | } |
1531 | 1531 | |
1532 | 1532 | /** |
@@ -1542,9 +1542,9 @@ discard block |
||
1542 | 1542 | public function get_output_format() { |
1543 | 1543 | global $wp_query; |
1544 | 1544 | |
1545 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1545 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1546 | 1546 | |
1547 | - return apply_filters( 'give_api_output_format', $format ); |
|
1547 | + return apply_filters('give_api_output_format', $format); |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | |
@@ -1561,8 +1561,8 @@ discard block |
||
1561 | 1561 | * |
1562 | 1562 | * @return void |
1563 | 1563 | */ |
1564 | - private function log_request( $data = array() ) { |
|
1565 | - if ( ! $this->log_requests ) { |
|
1564 | + private function log_request($data = array()) { |
|
1565 | + if ( ! $this->log_requests) { |
|
1566 | 1566 | return; |
1567 | 1567 | } |
1568 | 1568 | |
@@ -1578,36 +1578,36 @@ discard block |
||
1578 | 1578 | |
1579 | 1579 | $query = array( |
1580 | 1580 | 'give-api' => $wp_query->query_vars['give-api'], |
1581 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1582 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1583 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1584 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1585 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1586 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1587 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1588 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1589 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1590 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1591 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1592 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1581 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1582 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1583 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1584 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1585 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1586 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1587 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1588 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1589 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1590 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1591 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1592 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1593 | 1593 | ); |
1594 | 1594 | |
1595 | 1595 | $log_data = array( |
1596 | 1596 | 'log_type' => 'api_request', |
1597 | - 'post_excerpt' => http_build_query( $query ), |
|
1598 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1597 | + 'post_excerpt' => http_build_query($query), |
|
1598 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1599 | 1599 | ); |
1600 | 1600 | |
1601 | 1601 | $log_meta = array( |
1602 | 1602 | 'request_ip' => give_get_ip(), |
1603 | 1603 | 'user' => $this->user_id, |
1604 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1605 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1604 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1605 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1606 | 1606 | 'time' => $data['request_speed'], |
1607 | 1607 | 'version' => $this->get_queried_version(), |
1608 | 1608 | ); |
1609 | 1609 | |
1610 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1610 | + $give_logs->insert_log($log_data, $log_meta); |
|
1611 | 1611 | } |
1612 | 1612 | |
1613 | 1613 | |
@@ -1631,7 +1631,7 @@ discard block |
||
1631 | 1631 | * |
1632 | 1632 | * @param int $status_code |
1633 | 1633 | */ |
1634 | - public function output( $status_code = 200 ) { |
|
1634 | + public function output($status_code = 200) { |
|
1635 | 1635 | /** |
1636 | 1636 | * @var WP_Query $wp_query |
1637 | 1637 | */ |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | |
1640 | 1640 | $format = $this->get_output_format(); |
1641 | 1641 | |
1642 | - status_header( $status_code ); |
|
1642 | + status_header($status_code); |
|
1643 | 1643 | |
1644 | 1644 | /** |
1645 | 1645 | * Fires before outputing the API. |
@@ -1650,25 +1650,25 @@ discard block |
||
1650 | 1650 | * @param Give_API $this The Give_API object. |
1651 | 1651 | * @param string $format Output format, XML or JSON. Default is JSON. |
1652 | 1652 | */ |
1653 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1653 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1654 | 1654 | |
1655 | - switch ( $format ) : |
|
1655 | + switch ($format) : |
|
1656 | 1656 | |
1657 | 1657 | case 'xml' : |
1658 | 1658 | |
1659 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1660 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1659 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1660 | + $xml = Array2XML::createXML('give', $this->data); |
|
1661 | 1661 | echo $xml->saveXML(); |
1662 | 1662 | |
1663 | 1663 | break; |
1664 | 1664 | |
1665 | 1665 | case 'json' : |
1666 | 1666 | |
1667 | - header( 'Content-Type: application/json' ); |
|
1668 | - if ( ! empty( $this->pretty_print ) ) { |
|
1669 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1667 | + header('Content-Type: application/json'); |
|
1668 | + if ( ! empty($this->pretty_print)) { |
|
1669 | + echo json_encode($this->data, $this->pretty_print); |
|
1670 | 1670 | } else { |
1671 | - echo json_encode( $this->data ); |
|
1671 | + echo json_encode($this->data); |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | break; |
@@ -1683,7 +1683,7 @@ discard block |
||
1683 | 1683 | * @param array $data Response data to return. |
1684 | 1684 | * @param Give_API $this The Give_API object. |
1685 | 1685 | */ |
1686 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
1686 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
1687 | 1687 | |
1688 | 1688 | break; |
1689 | 1689 | |
@@ -1698,7 +1698,7 @@ discard block |
||
1698 | 1698 | * @param Give_API $this The Give_API object. |
1699 | 1699 | * @param string $format Output format, XML or JSON. Default is JSON. |
1700 | 1700 | */ |
1701 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1701 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1702 | 1702 | |
1703 | 1703 | give_die(); |
1704 | 1704 | } |
@@ -1715,40 +1715,40 @@ discard block |
||
1715 | 1715 | * |
1716 | 1716 | * @return void |
1717 | 1717 | */ |
1718 | - function user_key_field( $user ) { |
|
1718 | + function user_key_field($user) { |
|
1719 | 1719 | |
1720 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1721 | - $user = get_userdata( $user->ID ); |
|
1720 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1721 | + $user = get_userdata($user->ID); |
|
1722 | 1722 | ?> |
1723 | 1723 | <table class="form-table"> |
1724 | 1724 | <tbody> |
1725 | 1725 | <tr> |
1726 | 1726 | <th> |
1727 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1727 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1728 | 1728 | </th> |
1729 | 1729 | <td> |
1730 | 1730 | <?php |
1731 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1732 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1731 | + $public_key = $this->get_user_public_key($user->ID); |
|
1732 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1733 | 1733 | ?> |
1734 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1734 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1735 | 1735 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1736 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1736 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1737 | 1737 | <?php } else { ?> |
1738 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> |
|
1738 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> |
|
1739 | 1739 | </strong> |
1740 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1740 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1741 | 1741 | <br/> |
1742 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> |
|
1742 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> |
|
1743 | 1743 | </strong> |
1744 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1744 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1745 | 1745 | <br/> |
1746 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> |
|
1746 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> |
|
1747 | 1747 | </strong> |
1748 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1748 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1749 | 1749 | <br/> |
1750 | 1750 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1751 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1751 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1752 | 1752 | <?php } ?> |
1753 | 1753 | </td> |
1754 | 1754 | </tr> |
@@ -1767,67 +1767,67 @@ discard block |
||
1767 | 1767 | * |
1768 | 1768 | * @return void |
1769 | 1769 | */ |
1770 | - public function process_api_key( $args ) { |
|
1770 | + public function process_api_key($args) { |
|
1771 | 1771 | |
1772 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1773 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1772 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1773 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
1774 | 1774 | } |
1775 | 1775 | |
1776 | - if ( empty( $args['user_id'] ) ) { |
|
1777 | - wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1776 | + if (empty($args['user_id'])) { |
|
1777 | + wp_die(__('User ID Required.', 'give'), __('Error', 'give'), array('response' => 401)); |
|
1778 | 1778 | } |
1779 | 1779 | |
1780 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1781 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1780 | + if (is_numeric($args['user_id'])) { |
|
1781 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1782 | 1782 | } else { |
1783 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1783 | + $userdata = get_user_by('login', $args['user_id']); |
|
1784 | 1784 | $user_id = $userdata->ID; |
1785 | 1785 | } |
1786 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1786 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1787 | 1787 | |
1788 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1788 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1789 | 1789 | wp_die( |
1790 | 1790 | sprintf( |
1791 | 1791 | /* translators: %s: process */ |
1792 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1792 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1793 | 1793 | $process |
1794 | 1794 | ), |
1795 | - esc_html__( 'Error', 'give' ), |
|
1796 | - array( 'response' => 403 ) |
|
1795 | + esc_html__('Error', 'give'), |
|
1796 | + array('response' => 403) |
|
1797 | 1797 | ); |
1798 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1798 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1799 | 1799 | wp_die( |
1800 | 1800 | sprintf( |
1801 | 1801 | /* translators: %s: process */ |
1802 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1802 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1803 | 1803 | $process |
1804 | 1804 | ), |
1805 | - esc_html__( 'Error', 'give' ), |
|
1806 | - array( 'response' => 403 ) |
|
1805 | + esc_html__('Error', 'give'), |
|
1806 | + array('response' => 403) |
|
1807 | 1807 | ); |
1808 | 1808 | } |
1809 | 1809 | |
1810 | - switch ( $process ) { |
|
1810 | + switch ($process) { |
|
1811 | 1811 | case 'generate': |
1812 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1813 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1814 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1812 | + if ($this->generate_api_key($user_id)) { |
|
1813 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1814 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1815 | 1815 | exit(); |
1816 | 1816 | } else { |
1817 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1817 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1818 | 1818 | exit(); |
1819 | 1819 | } |
1820 | 1820 | break; |
1821 | 1821 | case 'regenerate': |
1822 | - $this->generate_api_key( $user_id, true ); |
|
1823 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1824 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1822 | + $this->generate_api_key($user_id, true); |
|
1823 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1824 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1825 | 1825 | exit(); |
1826 | 1826 | break; |
1827 | 1827 | case 'revoke': |
1828 | - $this->revoke_api_key( $user_id ); |
|
1829 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1830 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1828 | + $this->revoke_api_key($user_id); |
|
1829 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1830 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1831 | 1831 | exit(); |
1832 | 1832 | break; |
1833 | 1833 | default; |
@@ -1846,34 +1846,34 @@ discard block |
||
1846 | 1846 | * |
1847 | 1847 | * @return boolean True if (re)generated succesfully, false otherwise. |
1848 | 1848 | */ |
1849 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1849 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1850 | 1850 | |
1851 | - if ( empty( $user_id ) ) { |
|
1851 | + if (empty($user_id)) { |
|
1852 | 1852 | return false; |
1853 | 1853 | } |
1854 | 1854 | |
1855 | - $user = get_userdata( $user_id ); |
|
1855 | + $user = get_userdata($user_id); |
|
1856 | 1856 | |
1857 | - if ( ! $user ) { |
|
1857 | + if ( ! $user) { |
|
1858 | 1858 | return false; |
1859 | 1859 | } |
1860 | 1860 | |
1861 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1862 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1861 | + $public_key = $this->get_user_public_key($user_id); |
|
1862 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1863 | 1863 | |
1864 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1865 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1866 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1864 | + if (empty($public_key) || $regenerate == true) { |
|
1865 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1866 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1867 | 1867 | } else { |
1868 | 1868 | return false; |
1869 | 1869 | } |
1870 | 1870 | |
1871 | - if ( $regenerate == true ) { |
|
1872 | - $this->revoke_api_key( $user->ID ); |
|
1871 | + if ($regenerate == true) { |
|
1872 | + $this->revoke_api_key($user->ID); |
|
1873 | 1873 | } |
1874 | 1874 | |
1875 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1876 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1875 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1876 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1877 | 1877 | |
1878 | 1878 | return true; |
1879 | 1879 | } |
@@ -1888,26 +1888,26 @@ discard block |
||
1888 | 1888 | * |
1889 | 1889 | * @return bool |
1890 | 1890 | */ |
1891 | - public function revoke_api_key( $user_id = 0 ) { |
|
1891 | + public function revoke_api_key($user_id = 0) { |
|
1892 | 1892 | |
1893 | - if ( empty( $user_id ) ) { |
|
1893 | + if (empty($user_id)) { |
|
1894 | 1894 | return false; |
1895 | 1895 | } |
1896 | 1896 | |
1897 | - $user = get_userdata( $user_id ); |
|
1897 | + $user = get_userdata($user_id); |
|
1898 | 1898 | |
1899 | - if ( ! $user ) { |
|
1899 | + if ( ! $user) { |
|
1900 | 1900 | return false; |
1901 | 1901 | } |
1902 | 1902 | |
1903 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1904 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1905 | - if ( ! empty( $public_key ) ) { |
|
1906 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
1907 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
1908 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
1909 | - delete_user_meta( $user_id, $public_key ); |
|
1910 | - delete_user_meta( $user_id, $secret_key ); |
|
1903 | + $public_key = $this->get_user_public_key($user_id); |
|
1904 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1905 | + if ( ! empty($public_key)) { |
|
1906 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
1907 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
1908 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
1909 | + delete_user_meta($user_id, $public_key); |
|
1910 | + delete_user_meta($user_id, $secret_key); |
|
1911 | 1911 | } else { |
1912 | 1912 | return false; |
1913 | 1913 | } |
@@ -1932,22 +1932,22 @@ discard block |
||
1932 | 1932 | * |
1933 | 1933 | * @return void |
1934 | 1934 | */ |
1935 | - public function update_key( $user_id ) { |
|
1936 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1935 | + public function update_key($user_id) { |
|
1936 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1937 | 1937 | |
1938 | - $user = get_userdata( $user_id ); |
|
1938 | + $user = get_userdata($user_id); |
|
1939 | 1939 | |
1940 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1941 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1940 | + $public_key = $this->get_user_public_key($user_id); |
|
1941 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1942 | 1942 | |
1943 | - if ( empty( $public_key ) ) { |
|
1944 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1945 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1943 | + if (empty($public_key)) { |
|
1944 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1945 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1946 | 1946 | |
1947 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1948 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1947 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1948 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1949 | 1949 | } else { |
1950 | - $this->revoke_api_key( $user_id ); |
|
1950 | + $this->revoke_api_key($user_id); |
|
1951 | 1951 | } |
1952 | 1952 | } |
1953 | 1953 | } |
@@ -1962,9 +1962,9 @@ discard block |
||
1962 | 1962 | * |
1963 | 1963 | * @return string |
1964 | 1964 | */ |
1965 | - private function generate_public_key( $user_email = '' ) { |
|
1966 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1967 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1965 | + private function generate_public_key($user_email = '') { |
|
1966 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1967 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1968 | 1968 | |
1969 | 1969 | return $public; |
1970 | 1970 | } |
@@ -1979,9 +1979,9 @@ discard block |
||
1979 | 1979 | * |
1980 | 1980 | * @return string |
1981 | 1981 | */ |
1982 | - private function generate_private_key( $user_id = 0 ) { |
|
1983 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1984 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1982 | + private function generate_private_key($user_id = 0) { |
|
1983 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1984 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1985 | 1985 | |
1986 | 1986 | return $secret; |
1987 | 1987 | } |
@@ -1996,8 +1996,8 @@ discard block |
||
1996 | 1996 | * |
1997 | 1997 | * @return string |
1998 | 1998 | */ |
1999 | - public function get_token( $user_id = 0 ) { |
|
2000 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1999 | + public function get_token($user_id = 0) { |
|
2000 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
2001 | 2001 | } |
2002 | 2002 | |
2003 | 2003 | /** |
@@ -2011,9 +2011,9 @@ discard block |
||
2011 | 2011 | |
2012 | 2012 | // Default sales return |
2013 | 2013 | $sales = array(); |
2014 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
2015 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
2016 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
2014 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
2015 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
2016 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
2017 | 2017 | $sales['donations']['totals'] = give_get_total_sales(); |
2018 | 2018 | |
2019 | 2019 | return $sales; |
@@ -2030,9 +2030,9 @@ discard block |
||
2030 | 2030 | |
2031 | 2031 | // Default earnings return |
2032 | 2032 | $earnings = array(); |
2033 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
2034 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
2035 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
2033 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
2034 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
2035 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
2036 | 2036 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
2037 | 2037 | |
2038 | 2038 | return $earnings; |
@@ -2052,25 +2052,25 @@ discard block |
||
2052 | 2052 | * |
2053 | 2053 | * @return string The API key/secret for the user supplied |
2054 | 2054 | */ |
2055 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
2055 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
2056 | 2056 | |
2057 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
2057 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
2058 | 2058 | return $check; |
2059 | 2059 | } |
2060 | 2060 | |
2061 | 2061 | $return = $check; |
2062 | 2062 | |
2063 | - switch ( $meta_key ) { |
|
2063 | + switch ($meta_key) { |
|
2064 | 2064 | case 'give_user_public_key': |
2065 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
2065 | + $return = Give()->api->get_user_public_key($object_id); |
|
2066 | 2066 | break; |
2067 | 2067 | case 'give_user_secret_key': |
2068 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
2068 | + $return = Give()->api->get_user_secret_key($object_id); |
|
2069 | 2069 | break; |
2070 | 2070 | } |
2071 | 2071 | |
2072 | - if ( ! $single ) { |
|
2073 | - $return = array( $return ); |
|
2072 | + if ( ! $single) { |
|
2073 | + $return = array($return); |
|
2074 | 2074 | } |
2075 | 2075 | |
2076 | 2076 | return $return; |
@@ -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 | |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return bool $ret True if guest checkout is enabled, false otherwise |
29 | 29 | */ |
30 | -function give_no_guest_checkout( $form_id ) { |
|
30 | +function give_no_guest_checkout($form_id) { |
|
31 | 31 | |
32 | 32 | $backtrace = debug_backtrace(); |
33 | 33 | |
34 | - _give_deprecated_function( __FUNCTION__, '1.4.1', null, $backtrace ); |
|
34 | + _give_deprecated_function(__FUNCTION__, '1.4.1', null, $backtrace); |
|
35 | 35 | |
36 | - $ret = give_get_meta( $form_id, '_give_logged_in_only', true ); |
|
36 | + $ret = give_get_meta($form_id, '_give_logged_in_only', true); |
|
37 | 37 | |
38 | - return (bool) apply_filters( 'give_no_guest_checkout', give_is_setting_enabled( $ret ) ); |
|
38 | + return (bool) apply_filters('give_no_guest_checkout', give_is_setting_enabled($ret)); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | |
51 | 51 | $backtrace = debug_backtrace(); |
52 | 52 | |
53 | - _give_deprecated_function( __FUNCTION__, '1.8', null, $backtrace ); |
|
53 | + _give_deprecated_function(__FUNCTION__, '1.8', null, $backtrace); |
|
54 | 54 | |
55 | 55 | $views = array( |
56 | - 'sales' => __( 'Donations', 'give' ), |
|
57 | - 'gateway_errors' => __( 'Payment Errors', 'give' ), |
|
58 | - 'api_requests' => __( 'API Requests', 'give' ), |
|
56 | + 'sales' => __('Donations', 'give'), |
|
57 | + 'gateway_errors' => __('Payment Errors', 'give'), |
|
58 | + 'api_requests' => __('API Requests', 'give'), |
|
59 | 59 | ); |
60 | 60 | |
61 | - $views = apply_filters( 'give_log_views', $views ); |
|
61 | + $views = apply_filters('give_log_views', $views); |
|
62 | 62 | |
63 | 63 | return $views; |
64 | 64 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | $backtrace = debug_backtrace(); |
75 | 75 | |
76 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_agree_to_terms', $backtrace ); |
|
76 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_agree_to_terms', $backtrace); |
|
77 | 77 | |
78 | 78 | // Call new renamed function. |
79 | 79 | give_donation_form_validate_agree_to_terms(); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | $backtrace = debug_backtrace(); |
92 | 92 | |
93 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_logged_in_user', $backtrace ); |
|
93 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_logged_in_user', $backtrace); |
|
94 | 94 | |
95 | 95 | // Call new renamed function. |
96 | 96 | give_donation_form_validate_logged_in_user(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $backtrace = debug_backtrace(); |
109 | 109 | |
110 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_gateway', $backtrace ); |
|
110 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_gateway', $backtrace); |
|
111 | 111 | |
112 | 112 | // Call new renamed function. |
113 | 113 | give_donation_form_validate_gateway(); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | $backtrace = debug_backtrace(); |
126 | 126 | |
127 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_fields', $backtrace ); |
|
127 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_fields', $backtrace); |
|
128 | 128 | |
129 | 129 | // Call new renamed function. |
130 | 130 | give_donation_form_validate_fields(); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | $backtrace = debug_backtrace(); |
143 | 143 | |
144 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_cc', $backtrace ); |
|
144 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_cc', $backtrace); |
|
145 | 145 | |
146 | 146 | // Call new renamed function. |
147 | 147 | give_donation_form_validate_cc(); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | $backtrace = debug_backtrace(); |
160 | 160 | |
161 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_get_donation_cc_info', $backtrace ); |
|
161 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_get_donation_cc_info', $backtrace); |
|
162 | 162 | |
163 | 163 | // Call new renamed function. |
164 | 164 | give_get_donation_cc_info(); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param int $zip |
176 | 176 | * @param string $country_code |
177 | 177 | */ |
178 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
178 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
179 | 179 | |
180 | 180 | $backtrace = debug_backtrace(); |
181 | 181 | |
182 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_cc_zip', $backtrace ); |
|
182 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_cc_zip', $backtrace); |
|
183 | 183 | |
184 | 184 | // Call new renamed function. |
185 | - give_donation_form_validate_cc_zip( $zip, $country_code ); |
|
185 | + give_donation_form_validate_cc_zip($zip, $country_code); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | |
197 | 197 | $backtrace = debug_backtrace(); |
198 | 198 | |
199 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_user_login', $backtrace ); |
|
199 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_user_login', $backtrace); |
|
200 | 200 | |
201 | 201 | // Call new renamed function. |
202 | 202 | give_donation_form_validate_user_login(); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | $backtrace = debug_backtrace(); |
215 | 215 | |
216 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_guest_user', $backtrace ); |
|
216 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_guest_user', $backtrace); |
|
217 | 217 | |
218 | 218 | // Call new renamed function. |
219 | 219 | give_donation_form_validate_guest_user(); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | $backtrace = debug_backtrace(); |
232 | 232 | |
233 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_donation_form_validate_new_user', $backtrace ); |
|
233 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_donation_form_validate_new_user', $backtrace); |
|
234 | 234 | |
235 | 235 | // Call new renamed function. |
236 | 236 | give_donation_form_validate_new_user(); |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @param array $valid_data |
248 | 248 | */ |
249 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
249 | +function give_get_purchase_form_user($valid_data = array()) { |
|
250 | 250 | |
251 | 251 | $backtrace = debug_backtrace(); |
252 | 252 | |
253 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_get_donation_form_user', $backtrace ); |
|
253 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_get_donation_form_user', $backtrace); |
|
254 | 254 | |
255 | 255 | // Call new renamed function. |
256 | - give_get_donation_form_user( $valid_data ); |
|
256 | + give_get_donation_form_user($valid_data); |
|
257 | 257 | |
258 | 258 | } |
259 | 259 | |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return string |
271 | 271 | */ |
272 | -function give_checkout_button_purchase( $form_id ) { |
|
272 | +function give_checkout_button_purchase($form_id) { |
|
273 | 273 | $backtrace = debug_backtrace(); |
274 | 274 | |
275 | - _give_deprecated_function( __FUNCTION__, '1.8.8', 'give_get_donation_form_submit_button', $backtrace ); |
|
275 | + _give_deprecated_function(__FUNCTION__, '1.8.8', 'give_get_donation_form_submit_button', $backtrace); |
|
276 | 276 | |
277 | - return give_get_donation_form_submit_button( $form_id ); |
|
277 | + return give_get_donation_form_submit_button($form_id); |
|
278 | 278 | |
279 | 279 | } |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | |
8 | 8 | $give_map_deprecated_filters = give_deprecated_filters(); |
9 | 9 | |
10 | -foreach ( $give_map_deprecated_filters as $new => $old ) { |
|
11 | - add_filter( $new, 'give_deprecated_filter_mapping', 10, 4 ); |
|
10 | +foreach ($give_map_deprecated_filters as $new => $old) { |
|
11 | + add_filter($new, 'give_deprecated_filter_mapping', 10, 4); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -57,20 +57,20 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return mixed |
59 | 59 | */ |
60 | -function give_deprecated_filter_mapping( $data, $arg_1 = '', $arg_2 = '', $arg_3 = '' ) { |
|
60 | +function give_deprecated_filter_mapping($data, $arg_1 = '', $arg_2 = '', $arg_3 = '') { |
|
61 | 61 | $give_map_deprecated_filters = give_deprecated_filters(); |
62 | 62 | $filter = current_filter(); |
63 | 63 | |
64 | - if ( isset( $give_map_deprecated_filters[ $filter ] ) ) { |
|
65 | - if ( has_filter( $give_map_deprecated_filters[ $filter ] ) ) { |
|
66 | - $data = apply_filters( $give_map_deprecated_filters[ $filter ], $data, $arg_1, $arg_2, $arg_3 ); |
|
64 | + if (isset($give_map_deprecated_filters[$filter])) { |
|
65 | + if (has_filter($give_map_deprecated_filters[$filter])) { |
|
66 | + $data = apply_filters($give_map_deprecated_filters[$filter], $data, $arg_1, $arg_2, $arg_3); |
|
67 | 67 | |
68 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
68 | + if ( ! defined('DOING_AJAX')) { |
|
69 | 69 | _give_deprecated_function( |
70 | 70 | sprintf( |
71 | 71 | /* translators: %s: filter name */ |
72 | - __( 'The %s filter' ), |
|
73 | - $give_map_deprecated_filters[ $filter ] |
|
72 | + __('The %s filter'), |
|
73 | + $give_map_deprecated_filters[$filter] |
|
74 | 74 | ), |
75 | 75 | '1.7', |
76 | 76 | $filter |
@@ -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 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @since 1.0 |
32 | 32 | */ |
33 | - do_action( 'give_pre_process_donation' ); |
|
33 | + do_action('give_pre_process_donation'); |
|
34 | 34 | |
35 | 35 | // Validate the form $_POST data |
36 | 36 | $valid_data = give_donation_form_validate_fields(); |
@@ -45,26 +45,26 @@ discard block |
||
45 | 45 | * @param bool|array $valid_data Validate fields. |
46 | 46 | * @param array $_POST Array of variables passed via the HTTP POST. |
47 | 47 | */ |
48 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
48 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
49 | 49 | |
50 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
50 | + $is_ajax = isset($_POST['give_ajax']); |
|
51 | 51 | |
52 | 52 | // Process the login form |
53 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
53 | + if (isset($_POST['give_login_submit'])) { |
|
54 | 54 | give_process_form_login(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Validate the user |
58 | - $user = give_get_donation_form_user( $valid_data ); |
|
58 | + $user = give_get_donation_form_user($valid_data); |
|
59 | 59 | |
60 | - if ( false === $valid_data || give_get_errors() || ! $user ) { |
|
61 | - if ( $is_ajax ) { |
|
60 | + if (false === $valid_data || give_get_errors() || ! $user) { |
|
61 | + if ($is_ajax) { |
|
62 | 62 | /** |
63 | 63 | * Fires when AJAX sends back errors from the donation form. |
64 | 64 | * |
65 | 65 | * @since 1.0 |
66 | 66 | */ |
67 | - do_action( 'give_ajax_donation_errors' ); |
|
67 | + do_action('give_ajax_donation_errors'); |
|
68 | 68 | give_die(); |
69 | 69 | } else { |
70 | 70 | return false; |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | // If AJAX send back success to proceed with form submission |
75 | - if ( $is_ajax ) { |
|
75 | + if ($is_ajax) { |
|
76 | 76 | echo 'success'; |
77 | 77 | give_die(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | // After AJAX: Setup session if not using php_sessions |
81 | - if ( ! Give()->session->use_php_sessions() ) { |
|
81 | + if ( ! Give()->session->use_php_sessions()) { |
|
82 | 82 | // Double-check that set_cookie is publicly accessible; |
83 | 83 | // we're using a slightly modified class-wp-sessions.php |
84 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
85 | - if ( $session_reflection->isPublic() ) { |
|
84 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
85 | + if ($session_reflection->isPublic()) { |
|
86 | 86 | // Manually set the cookie. |
87 | 87 | Give()->session->init()->set_cookie(); |
88 | 88 | } |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | 'address' => $user['address'], |
98 | 98 | ); |
99 | 99 | |
100 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
100 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
101 | 101 | |
102 | - $price = isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00'; |
|
103 | - $purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); |
|
102 | + $price = isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'; |
|
103 | + $purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); |
|
104 | 104 | |
105 | 105 | // Setup donation information |
106 | 106 | $donation_data = array( |
107 | 107 | 'price' => $price, |
108 | 108 | 'purchase_key' => $purchase_key, |
109 | 109 | 'user_email' => $user['user_email'], |
110 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
111 | - 'user_info' => stripslashes_deep( $user_info ), |
|
110 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
111 | + 'user_info' => stripslashes_deep($user_info), |
|
112 | 112 | 'post_data' => $_POST, |
113 | 113 | 'gateway' => $valid_data['gateway'], |
114 | 114 | 'card_info' => $valid_data['cc_info'], |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | * @param array $user_info Array containing basic user information. |
129 | 129 | * @param bool|array $valid_data Validate fields. |
130 | 130 | */ |
131 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
131 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
132 | 132 | |
133 | 133 | // Sanity check for price |
134 | - if ( ! $donation_data['price'] ) { |
|
134 | + if ( ! $donation_data['price']) { |
|
135 | 135 | // Revert to manual |
136 | 136 | $donation_data['gateway'] = 'manual'; |
137 | 137 | $_POST['give-gateway'] = 'manual'; |
@@ -142,27 +142,27 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @since 1.7 |
144 | 144 | */ |
145 | - $donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data ); |
|
145 | + $donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data); |
|
146 | 146 | |
147 | 147 | // Setup the data we're storing in the donation session |
148 | 148 | $session_data = $donation_data; |
149 | 149 | |
150 | 150 | // Make sure credit card numbers are never stored in sessions |
151 | - unset( $session_data['card_info']['card_number'] ); |
|
152 | - unset( $session_data['post_data']['card_number'] ); |
|
151 | + unset($session_data['card_info']['card_number']); |
|
152 | + unset($session_data['post_data']['card_number']); |
|
153 | 153 | |
154 | 154 | // Used for showing data to non logged-in users after donation, and for other plugins needing donation data. |
155 | - give_set_purchase_session( $session_data ); |
|
155 | + give_set_purchase_session($session_data); |
|
156 | 156 | |
157 | 157 | // Send info to the gateway for payment processing |
158 | - give_send_to_gateway( $donation_data['gateway'], $donation_data ); |
|
158 | + give_send_to_gateway($donation_data['gateway'], $donation_data); |
|
159 | 159 | give_die(); |
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | -add_action( 'give_purchase', 'give_process_donation_form' ); |
|
164 | -add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' ); |
|
165 | -add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' ); |
|
163 | +add_action('give_purchase', 'give_process_donation_form'); |
|
164 | +add_action('wp_ajax_give_process_donation', 'give_process_donation_form'); |
|
165 | +add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form'); |
|
166 | 166 | |
167 | 167 | |
168 | 168 | /** |
@@ -175,29 +175,29 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return void |
177 | 177 | */ |
178 | -function give_check_logged_in_user_for_existing_email( $valid_data, $post ) { |
|
178 | +function give_check_logged_in_user_for_existing_email($valid_data, $post) { |
|
179 | 179 | |
180 | 180 | // Verify that the email address belongs to this customer. |
181 | - if ( is_user_logged_in() ) { |
|
181 | + if (is_user_logged_in()) { |
|
182 | 182 | |
183 | - $submitted_email = $valid_data['logged_in_user']['user_email']; |
|
184 | - $customer = new Give_Customer( get_current_user_id(), true ); |
|
183 | + $submitted_email = $valid_data['logged_in_user']['user_email']; |
|
184 | + $customer = new Give_Customer(get_current_user_id(), true); |
|
185 | 185 | |
186 | 186 | // If this email address is not registered with this customer, see if it belongs to any other customer |
187 | 187 | if ( |
188 | 188 | $submitted_email !== $customer->email |
189 | - && ( is_array( $customer->emails ) && ! in_array( $submitted_email, $customer->emails ) ) |
|
189 | + && (is_array($customer->emails) && ! in_array($submitted_email, $customer->emails)) |
|
190 | 190 | ) { |
191 | - $found_customer = new Give_Customer( $submitted_email ); |
|
191 | + $found_customer = new Give_Customer($submitted_email); |
|
192 | 192 | |
193 | - if ( $found_customer->id > 0 ) { |
|
194 | - give_set_error( 'give-customer-email-exists', sprintf( __( 'You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.' ), $customer->email, $submitted_email ) ); |
|
193 | + if ($found_customer->id > 0) { |
|
194 | + give_set_error('give-customer-email-exists', sprintf(__('You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.'), $customer->email, $submitted_email)); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2 ); |
|
200 | +add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2); |
|
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Process the checkout login form |
@@ -208,37 +208,37 @@ discard block |
||
208 | 208 | */ |
209 | 209 | function give_process_form_login() { |
210 | 210 | |
211 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
211 | + $is_ajax = isset($_POST['give_ajax']); |
|
212 | 212 | |
213 | 213 | $user_data = give_donation_form_validate_user_login(); |
214 | 214 | |
215 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
216 | - if ( $is_ajax ) { |
|
215 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
216 | + if ($is_ajax) { |
|
217 | 217 | /** |
218 | 218 | * Fires when AJAX sends back errors from the donation form. |
219 | 219 | * |
220 | 220 | * @since 1.0 |
221 | 221 | */ |
222 | - do_action( 'give_ajax_donation_errors' ); |
|
222 | + do_action('give_ajax_donation_errors'); |
|
223 | 223 | give_die(); |
224 | 224 | } else { |
225 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
225 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
230 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
231 | 231 | |
232 | - if ( $is_ajax ) { |
|
232 | + if ($is_ajax) { |
|
233 | 233 | echo 'success'; |
234 | 234 | give_die(); |
235 | 235 | } else { |
236 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
236 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | -add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' ); |
|
241 | -add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' ); |
|
240 | +add_action('wp_ajax_give_process_donation_login', 'give_process_form_login'); |
|
241 | +add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login'); |
|
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Donation Form Validate Fields. |
@@ -250,55 +250,55 @@ discard block |
||
250 | 250 | function give_donation_form_validate_fields() { |
251 | 251 | |
252 | 252 | // Check if there is $_POST |
253 | - if ( empty( $_POST ) ) { |
|
253 | + if (empty($_POST)) { |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | |
257 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
257 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
258 | 258 | |
259 | 259 | // Start an array to collect valid data |
260 | 260 | $valid_data = array( |
261 | 261 | 'gateway' => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here) |
262 | - 'need_new_user' => false, // New user flag |
|
263 | - 'need_user_login' => false, // Login user flag |
|
264 | - 'logged_user_data' => array(), // Logged user collected data |
|
265 | - 'new_user_data' => array(), // New user collected data |
|
266 | - 'login_user_data' => array(), // Login user collected data |
|
267 | - 'guest_user_data' => array(), // Guest user collected data |
|
268 | - 'cc_info' => give_donation_form_validate_cc(),// Credit card info |
|
262 | + 'need_new_user' => false, // New user flag |
|
263 | + 'need_user_login' => false, // Login user flag |
|
264 | + 'logged_user_data' => array(), // Logged user collected data |
|
265 | + 'new_user_data' => array(), // New user collected data |
|
266 | + 'login_user_data' => array(), // Login user collected data |
|
267 | + 'guest_user_data' => array(), // Guest user collected data |
|
268 | + 'cc_info' => give_donation_form_validate_cc(), // Credit card info |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | // Validate Honeypot First |
272 | - if ( ! empty( $_POST['give-honeypot'] ) ) { |
|
273 | - give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) ); |
|
272 | + if ( ! empty($_POST['give-honeypot'])) { |
|
273 | + give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give')); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | // Validate agree to terms |
277 | - if ( give_is_terms_enabled( $form_id ) ) { |
|
277 | + if (give_is_terms_enabled($form_id)) { |
|
278 | 278 | give_donation_form_validate_agree_to_terms(); |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Stop processing donor registration, if donor registration is optional and donor can do guest checkout. |
282 | 282 | // If registration form username field is empty that means donor do not want to registration instead want guest checkout. |
283 | 283 | if ( |
284 | - ! give_logged_in_only( $form_id ) |
|
285 | - && isset( $_POST['give-purchase-var'] ) |
|
284 | + ! give_logged_in_only($form_id) |
|
285 | + && isset($_POST['give-purchase-var']) |
|
286 | 286 | && $_POST['give-purchase-var'] == 'needs-to-register' |
287 | - && empty( $_POST['give_user_login'] ) |
|
287 | + && empty($_POST['give_user_login']) |
|
288 | 288 | ) { |
289 | - unset( $_POST['give-purchase-var'] ); |
|
289 | + unset($_POST['give-purchase-var']); |
|
290 | 290 | } |
291 | 291 | |
292 | - if ( is_user_logged_in() ) { |
|
292 | + if (is_user_logged_in()) { |
|
293 | 293 | // Collect logged in user data. |
294 | 294 | $valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user(); |
295 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
295 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
296 | 296 | // Set new user registration as required. |
297 | 297 | $valid_data['need_new_user'] = true; |
298 | 298 | // Validate new user data. |
299 | 299 | $valid_data['new_user_data'] = give_donation_form_validate_new_user(); |
300 | 300 | // Check if login validation is needed. |
301 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
301 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
302 | 302 | // Set user login as required. |
303 | 303 | $valid_data['need_user_login'] = true; |
304 | 304 | // Validate users login info. |
@@ -323,41 +323,41 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function give_donation_form_validate_gateway() { |
325 | 325 | |
326 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
327 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
328 | - $gateway = give_get_default_gateway( $form_id ); |
|
326 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
327 | + $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
328 | + $gateway = give_get_default_gateway($form_id); |
|
329 | 329 | |
330 | 330 | // Check if a gateway value is present. |
331 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
331 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
332 | 332 | |
333 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
333 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
334 | 334 | |
335 | 335 | // Is amount being donated in LIVE mode 0.00? If so, error: |
336 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
336 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
337 | 337 | |
338 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
338 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
339 | 339 | |
340 | 340 | } // End if(). |
341 | - elseif ( ! give_verify_minimum_price() ) { |
|
341 | + elseif ( ! give_verify_minimum_price()) { |
|
342 | 342 | // translators: %s: minimum donation amount. |
343 | 343 | give_set_error( |
344 | 344 | 'invalid_donation_minimum', |
345 | 345 | sprintf( |
346 | 346 | /* translators: %s: minimum donation amount */ |
347 | - __( 'This form has a minimum donation amount of %s.', 'give' ), |
|
348 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) ) |
|
347 | + __('This form has a minimum donation amount of %s.', 'give'), |
|
348 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))) |
|
349 | 349 | ) |
350 | 350 | ); |
351 | 351 | |
352 | 352 | } //Is this test mode zero donation? Let it through but set to manual gateway. |
353 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
353 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
354 | 354 | |
355 | 355 | $gateway = 'manual'; |
356 | 356 | |
357 | 357 | } //Check if this gateway is active. |
358 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
358 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
359 | 359 | |
360 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
360 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give')); |
|
361 | 361 | |
362 | 362 | } |
363 | 363 | } |
@@ -375,21 +375,21 @@ discard block |
||
375 | 375 | */ |
376 | 376 | function give_verify_minimum_price() { |
377 | 377 | |
378 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
379 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
380 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : null; |
|
381 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
378 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
379 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
380 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : null; |
|
381 | + $variable_prices = give_has_variable_prices($form_id); |
|
382 | 382 | |
383 | - if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ) ) ) { |
|
383 | + if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id))) { |
|
384 | 384 | |
385 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
385 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
386 | 386 | |
387 | - if ( $price_level_amount == $amount ) { |
|
387 | + if ($price_level_amount == $amount) { |
|
388 | 388 | return true; |
389 | 389 | } |
390 | 390 | } |
391 | 391 | |
392 | - if ( give_get_form_minimum_price( $form_id ) > $amount ) { |
|
392 | + if (give_get_form_minimum_price($form_id) > $amount) { |
|
393 | 393 | return false; |
394 | 394 | } |
395 | 395 | |
@@ -405,9 +405,9 @@ discard block |
||
405 | 405 | */ |
406 | 406 | function give_donation_form_validate_agree_to_terms() { |
407 | 407 | // Validate agree to terms. |
408 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
408 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
409 | 409 | // User did not agree. |
410 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
410 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give'))); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
@@ -421,43 +421,43 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @return array |
423 | 423 | */ |
424 | -function give_get_required_fields( $form_id ) { |
|
424 | +function give_get_required_fields($form_id) { |
|
425 | 425 | |
426 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
426 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
427 | 427 | |
428 | 428 | $required_fields = array( |
429 | 429 | 'give_email' => array( |
430 | 430 | 'error_id' => 'invalid_email', |
431 | - 'error_message' => __( 'Please enter a valid email address.', 'give' ), |
|
431 | + 'error_message' => __('Please enter a valid email address.', 'give'), |
|
432 | 432 | ), |
433 | 433 | 'give_first' => array( |
434 | 434 | 'error_id' => 'invalid_first_name', |
435 | - 'error_message' => __( 'Please enter your first name.', 'give' ), |
|
435 | + 'error_message' => __('Please enter your first name.', 'give'), |
|
436 | 436 | ), |
437 | 437 | ); |
438 | 438 | |
439 | - $require_address = give_require_billing_address( $payment_mode ); |
|
439 | + $require_address = give_require_billing_address($payment_mode); |
|
440 | 440 | |
441 | - if ( $require_address ) { |
|
442 | - $required_fields['card_address'] = array( |
|
441 | + if ($require_address) { |
|
442 | + $required_fields['card_address'] = array( |
|
443 | 443 | 'error_id' => 'invalid_card_address', |
444 | - 'error_message' => __( 'Please enter your primary billing address.', 'give' ), |
|
444 | + 'error_message' => __('Please enter your primary billing address.', 'give'), |
|
445 | 445 | ); |
446 | - $required_fields['card_zip'] = array( |
|
446 | + $required_fields['card_zip'] = array( |
|
447 | 447 | 'error_id' => 'invalid_zip_code', |
448 | - 'error_message' => __( 'Please enter your zip / postal code.', 'give' ), |
|
448 | + 'error_message' => __('Please enter your zip / postal code.', 'give'), |
|
449 | 449 | ); |
450 | - $required_fields['card_city'] = array( |
|
450 | + $required_fields['card_city'] = array( |
|
451 | 451 | 'error_id' => 'invalid_city', |
452 | - 'error_message' => __( 'Please enter your billing city.', 'give' ), |
|
452 | + 'error_message' => __('Please enter your billing city.', 'give'), |
|
453 | 453 | ); |
454 | 454 | $required_fields['billing_country'] = array( |
455 | 455 | 'error_id' => 'invalid_country', |
456 | - 'error_message' => __( 'Please select your billing country.', 'give' ), |
|
456 | + 'error_message' => __('Please select your billing country.', 'give'), |
|
457 | 457 | ); |
458 | - $required_fields['card_state'] = array( |
|
458 | + $required_fields['card_state'] = array( |
|
459 | 459 | 'error_id' => 'invalid_state', |
460 | - 'error_message' => __( 'Please enter billing state / province.', 'give' ), |
|
460 | + 'error_message' => __('Please enter billing state / province.', 'give'), |
|
461 | 461 | ); |
462 | 462 | } |
463 | 463 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @since 1.7 |
468 | 468 | */ |
469 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
469 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
470 | 470 | |
471 | 471 | return $required_fields; |
472 | 472 | |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return bool |
483 | 483 | */ |
484 | -function give_require_billing_address( $payment_mode ) { |
|
484 | +function give_require_billing_address($payment_mode) { |
|
485 | 485 | |
486 | 486 | $return = false; |
487 | 487 | |
488 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
488 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
489 | 489 | $return = true; |
490 | 490 | } |
491 | 491 | |
492 | 492 | // Let payment gateways and other extensions determine if address fields should be required. |
493 | - return apply_filters( 'give_require_billing_address', $return ); |
|
493 | + return apply_filters('give_require_billing_address', $return); |
|
494 | 494 | |
495 | 495 | } |
496 | 496 | |
@@ -504,42 +504,42 @@ discard block |
||
504 | 504 | function give_donation_form_validate_logged_in_user() { |
505 | 505 | global $user_ID; |
506 | 506 | |
507 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
507 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
508 | 508 | |
509 | 509 | // Start empty array to collect valid user data. |
510 | 510 | $valid_user_data = array( |
511 | 511 | // Assume there will be errors. |
512 | - 'user_id' => - 1, |
|
512 | + 'user_id' => -1, |
|
513 | 513 | ); |
514 | 514 | |
515 | 515 | // Verify there is a user_ID. |
516 | - if ( $user_ID > 0 ) { |
|
516 | + if ($user_ID > 0) { |
|
517 | 517 | // Get the logged in user data. |
518 | - $user_data = get_userdata( $user_ID ); |
|
518 | + $user_data = get_userdata($user_ID); |
|
519 | 519 | |
520 | 520 | // Loop through required fields and show error messages. |
521 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
522 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
523 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
521 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
522 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
523 | + give_set_error($value['error_id'], $value['error_message']); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
527 | 527 | // Verify data. |
528 | - if ( $user_data ) { |
|
528 | + if ($user_data) { |
|
529 | 529 | // Collected logged in user data. |
530 | 530 | $valid_user_data = array( |
531 | 531 | 'user_id' => $user_ID, |
532 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
533 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
534 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
532 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
533 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
534 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
535 | 535 | ); |
536 | 536 | |
537 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
538 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
537 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
538 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
539 | 539 | } |
540 | 540 | } else { |
541 | 541 | // Set invalid user error. |
542 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
542 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | // Default user data. |
559 | 559 | $default_user_data = array( |
560 | 560 | 'give-form-id' => '', |
561 | - 'user_id' => - 1, // Assume there will be errors. |
|
561 | + 'user_id' => -1, // Assume there will be errors. |
|
562 | 562 | 'user_first' => '', |
563 | 563 | 'user_last' => '', |
564 | 564 | 'give_user_login' => false, |
@@ -568,14 +568,14 @@ discard block |
||
568 | 568 | ); |
569 | 569 | |
570 | 570 | // Get user data. |
571 | - $user_data = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data ); |
|
571 | + $user_data = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data); |
|
572 | 572 | $registering_new_user = false; |
573 | - $form_id = absint( $user_data['give-form-id'] ); |
|
573 | + $form_id = absint($user_data['give-form-id']); |
|
574 | 574 | |
575 | 575 | // Start an empty array to collect valid user data. |
576 | 576 | $valid_user_data = array( |
577 | 577 | // Assume there will be errors. |
578 | - 'user_id' => - 1, |
|
578 | + 'user_id' => -1, |
|
579 | 579 | |
580 | 580 | // Get first name. |
581 | 581 | 'user_first' => $user_data['give_first'], |
@@ -585,25 +585,25 @@ discard block |
||
585 | 585 | ); |
586 | 586 | |
587 | 587 | // Loop through required fields and show error messages. |
588 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
589 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
590 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
588 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
589 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
590 | + give_set_error($value['error_id'], $value['error_message']); |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
594 | 594 | // Check if we have an username to register. |
595 | - if ( give_validate_username( $user_data['give_user_login'] ) ) { |
|
595 | + if (give_validate_username($user_data['give_user_login'])) { |
|
596 | 596 | $registering_new_user = true; |
597 | 597 | $valid_user_data['user_login'] = $user_data['give_user_login']; |
598 | 598 | } |
599 | 599 | |
600 | 600 | // Check if we have an email to verify. |
601 | - if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
601 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
602 | 602 | $valid_user_data['user_email'] = $user_data['give_email']; |
603 | 603 | } |
604 | 604 | |
605 | 605 | // Check password. |
606 | - if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) { |
|
606 | + if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) { |
|
607 | 607 | // All is good to go. |
608 | 608 | $valid_user_data['user_pass'] = $user_data['give_user_pass']; |
609 | 609 | } |
@@ -623,36 +623,36 @@ discard block |
||
623 | 623 | // Start an array to collect valid user data. |
624 | 624 | $valid_user_data = array( |
625 | 625 | // Assume there will be errors. |
626 | - 'user_id' => - 1, |
|
626 | + 'user_id' => -1, |
|
627 | 627 | ); |
628 | 628 | |
629 | 629 | // Username. |
630 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
631 | - give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) ); |
|
630 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
631 | + give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give')); |
|
632 | 632 | |
633 | 633 | return $valid_user_data; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // Get the user by login. |
637 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
637 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
638 | 638 | |
639 | 639 | // Check if user exists. |
640 | - if ( $user_data ) { |
|
640 | + if ($user_data) { |
|
641 | 641 | // Get password. |
642 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
642 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
643 | 643 | |
644 | 644 | // Check user_pass. |
645 | - if ( $user_pass ) { |
|
645 | + if ($user_pass) { |
|
646 | 646 | // Check if password is valid. |
647 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
647 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
648 | 648 | // Incorrect password. |
649 | 649 | give_set_error( |
650 | 650 | 'password_incorrect', |
651 | 651 | sprintf( |
652 | 652 | '%1$s <a href="%2$s">%3$s</a>', |
653 | - __( 'The password you entered is incorrect.', 'give' ), |
|
654 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
655 | - __( 'Reset Password', 'give' ) |
|
653 | + __('The password you entered is incorrect.', 'give'), |
|
654 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
655 | + __('Reset Password', 'give') |
|
656 | 656 | ) |
657 | 657 | ); |
658 | 658 | // All is correct. |
@@ -669,11 +669,11 @@ discard block |
||
669 | 669 | } |
670 | 670 | } else { |
671 | 671 | // Empty password. |
672 | - give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
|
672 | + give_set_error('password_empty', __('Enter a password.', 'give')); |
|
673 | 673 | } |
674 | 674 | } else { |
675 | 675 | // No username. |
676 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
676 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
677 | 677 | }// End if(). |
678 | 678 | |
679 | 679 | return $valid_user_data; |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | */ |
689 | 689 | function give_donation_form_validate_guest_user() { |
690 | 690 | |
691 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
691 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
692 | 692 | |
693 | 693 | // Start an array to collect valid user data. |
694 | 694 | $valid_user_data = array( |
@@ -697,38 +697,38 @@ discard block |
||
697 | 697 | ); |
698 | 698 | |
699 | 699 | // Show error message if user must be logged in. |
700 | - if ( give_logged_in_only( $form_id ) ) { |
|
701 | - give_set_error( 'logged_in_only', __( 'You must be logged in to donate.', 'give' ) ); |
|
700 | + if (give_logged_in_only($form_id)) { |
|
701 | + give_set_error('logged_in_only', __('You must be logged in to donate.', 'give')); |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | // Get the guest email. |
705 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
705 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
706 | 706 | |
707 | 707 | // Check email. |
708 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
708 | + if ($guest_email && strlen($guest_email) > 0) { |
|
709 | 709 | // Validate email. |
710 | - if ( ! is_email( $guest_email ) ) { |
|
710 | + if ( ! is_email($guest_email)) { |
|
711 | 711 | // Invalid email. |
712 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
712 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
713 | 713 | } else { |
714 | 714 | // All is good to go. |
715 | 715 | $valid_user_data['user_email'] = $guest_email; |
716 | 716 | |
717 | 717 | // Get user_id from donor if exist. |
718 | - $donor = new Give_Customer( $guest_email ); |
|
719 | - if ( $donor->id && $donor->user_id ) { |
|
718 | + $donor = new Give_Customer($guest_email); |
|
719 | + if ($donor->id && $donor->user_id) { |
|
720 | 720 | $valid_user_data['user_id'] = $donor->user_id; |
721 | 721 | } |
722 | 722 | } |
723 | 723 | } else { |
724 | 724 | // No email. |
725 | - give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
|
725 | + give_set_error('email_empty', __('Enter an email.', 'give')); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | // Loop through required fields and show error messages. |
729 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
730 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
731 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
729 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
730 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
731 | + give_set_error($value['error_id'], $value['error_message']); |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
@@ -744,36 +744,36 @@ discard block |
||
744 | 744 | * @since 1.0 |
745 | 745 | * @return integer |
746 | 746 | */ |
747 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
747 | +function give_register_and_login_new_user($user_data = array()) { |
|
748 | 748 | // Verify the array. |
749 | - if ( empty( $user_data ) ) { |
|
750 | - return - 1; |
|
749 | + if (empty($user_data)) { |
|
750 | + return -1; |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( give_get_errors() ) { |
|
754 | - return - 1; |
|
753 | + if (give_get_errors()) { |
|
754 | + return -1; |
|
755 | 755 | } |
756 | 756 | |
757 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
758 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
759 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
760 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
761 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
762 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
763 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
764 | - 'role' => get_option( 'default_role' ), |
|
765 | - ), $user_data ); |
|
757 | + $user_args = apply_filters('give_insert_user_args', array( |
|
758 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
759 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
760 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
761 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
762 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
763 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
764 | + 'role' => get_option('default_role'), |
|
765 | + ), $user_data); |
|
766 | 766 | |
767 | 767 | // Insert new user. |
768 | - $user_id = wp_insert_user( $user_args ); |
|
768 | + $user_id = wp_insert_user($user_args); |
|
769 | 769 | |
770 | 770 | // Validate inserted user. |
771 | - if ( is_wp_error( $user_id ) ) { |
|
772 | - return - 1; |
|
771 | + if (is_wp_error($user_id)) { |
|
772 | + return -1; |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | // Allow themes and plugins to filter the user data. |
776 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
776 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
777 | 777 | |
778 | 778 | /** |
779 | 779 | * Fires after inserting user. |
@@ -783,10 +783,10 @@ discard block |
||
783 | 783 | * @param int $user_id User id. |
784 | 784 | * @param array $user_data Array containing user data. |
785 | 785 | */ |
786 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
786 | + do_action('give_insert_user', $user_id, $user_data); |
|
787 | 787 | |
788 | 788 | // Login new user. |
789 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
789 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
790 | 790 | |
791 | 791 | // Return user id. |
792 | 792 | return $user_id; |
@@ -801,27 +801,27 @@ discard block |
||
801 | 801 | * @since 1.0 |
802 | 802 | * @return array|bool |
803 | 803 | */ |
804 | -function give_get_donation_form_user( $valid_data = array() ) { |
|
804 | +function give_get_donation_form_user($valid_data = array()) { |
|
805 | 805 | |
806 | 806 | // Initialize user. |
807 | 807 | $user = false; |
808 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
808 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
809 | 809 | |
810 | - if ( $is_ajax ) { |
|
810 | + if ($is_ajax) { |
|
811 | 811 | // Do not create or login the user during the ajax submission (check for errors only). |
812 | 812 | return true; |
813 | - } elseif ( is_user_logged_in() ) { |
|
813 | + } elseif (is_user_logged_in()) { |
|
814 | 814 | // Set the valid user as the logged in collected data. |
815 | 815 | $user = $valid_data['logged_in_user']; |
816 | - } elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
816 | + } elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
817 | 817 | // New user registration. |
818 | - if ( $valid_data['need_new_user'] === true ) { |
|
818 | + if ($valid_data['need_new_user'] === true) { |
|
819 | 819 | // Set user. |
820 | 820 | $user = $valid_data['new_user_data']; |
821 | 821 | // Register and login new user. |
822 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
822 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
823 | 823 | // User login |
824 | - } elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
824 | + } elseif ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
825 | 825 | |
826 | 826 | /** |
827 | 827 | * The login form is now processed in the give_process_donation_login() function. |
@@ -833,48 +833,48 @@ discard block |
||
833 | 833 | // Set user. |
834 | 834 | $user = $valid_data['login_user_data']; |
835 | 835 | // Login user. |
836 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
836 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | // Check guest checkout. |
841 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
841 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
842 | 842 | // Set user |
843 | 843 | $user = $valid_data['guest_user_data']; |
844 | 844 | } |
845 | 845 | |
846 | 846 | // Verify we have an user. |
847 | - if ( false === $user || empty( $user ) ) { |
|
847 | + if (false === $user || empty($user)) { |
|
848 | 848 | // Return false. |
849 | 849 | return false; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Get user first name. |
853 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
854 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
853 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
854 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | // Get user last name. |
858 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
859 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
858 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
859 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | // Get the user's billing address details. |
863 | 863 | $user['address'] = array(); |
864 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
865 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
866 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
867 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
868 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
869 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
870 | - |
|
871 | - if ( empty( $user['address']['country'] ) ) { |
|
864 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
865 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
866 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
867 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
868 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
869 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
870 | + |
|
871 | + if (empty($user['address']['country'])) { |
|
872 | 872 | $user['address'] = false; |
873 | 873 | } // End if(). |
874 | 874 | |
875 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
875 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
876 | 876 | // Store the address in the user's meta so the donation form can be pre-populated with it on return donation. |
877 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
877 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | // Return valid user. |
@@ -893,16 +893,16 @@ discard block |
||
893 | 893 | $card_data = give_get_donation_cc_info(); |
894 | 894 | |
895 | 895 | // Validate the card zip. |
896 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
897 | - if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
898 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
896 | + if ( ! empty($card_data['card_zip'])) { |
|
897 | + if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
898 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
899 | 899 | } |
900 | 900 | } |
901 | 901 | |
902 | 902 | // Ensure no spaces. |
903 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
904 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs |
|
905 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
903 | + if ( ! empty($card_data['card_number'])) { |
|
904 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs |
|
905 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | // This should validate card numbers at some point too. |
@@ -919,17 +919,17 @@ discard block |
||
919 | 919 | function give_get_donation_cc_info() { |
920 | 920 | |
921 | 921 | $cc_info = array(); |
922 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
923 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
924 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
925 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
926 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
927 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
928 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
929 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
930 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
931 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
932 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
922 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
923 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
924 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
925 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
926 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
927 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
928 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
929 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
930 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
931 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
932 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
933 | 933 | |
934 | 934 | // Return cc info. |
935 | 935 | return $cc_info; |
@@ -945,14 +945,14 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @return bool|mixed |
947 | 947 | */ |
948 | -function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
948 | +function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
949 | 949 | $ret = false; |
950 | 950 | |
951 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
951 | + if (empty($zip) || empty($country_code)) { |
|
952 | 952 | return $ret; |
953 | 953 | } |
954 | 954 | |
955 | - $country_code = strtoupper( $country_code ); |
|
955 | + $country_code = strtoupper($country_code); |
|
956 | 956 | |
957 | 957 | $zip_regex = array( |
958 | 958 | 'AD' => 'AD\d{3}', |
@@ -1112,11 +1112,11 @@ discard block |
||
1112 | 1112 | 'ZM' => '\d{5}', |
1113 | 1113 | ); |
1114 | 1114 | |
1115 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
1115 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
1116 | 1116 | $ret = true; |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1119 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | |
@@ -1130,36 +1130,36 @@ discard block |
||
1130 | 1130 | * |
1131 | 1131 | * @return bool |
1132 | 1132 | */ |
1133 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1133 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1134 | 1134 | /* @var Give_Donate_Form $form */ |
1135 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1135 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1136 | 1136 | |
1137 | 1137 | $donation_level_matched = false; |
1138 | 1138 | |
1139 | - if ( $form->is_multi_type_donation_form() ) { |
|
1139 | + if ($form->is_multi_type_donation_form()) { |
|
1140 | 1140 | |
1141 | 1141 | // Bailout. |
1142 | - if ( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1142 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1143 | 1143 | return false; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | 1146 | // Sanitize donation amount. |
1147 | - $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1147 | + $data['give-amount'] = give_sanitize_amount($data['give-amount']); |
|
1148 | 1148 | |
1149 | 1149 | // Get number of decimals. |
1150 | 1150 | $default_decimals = give_get_price_decimals(); |
1151 | 1151 | |
1152 | - if ( $data['give-amount'] === give_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ), $default_decimals ) ) { |
|
1152 | + if ($data['give-amount'] === give_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']), $default_decimals)) { |
|
1153 | 1153 | return true; |
1154 | 1154 | } |
1155 | 1155 | |
1156 | 1156 | // Find correct donation level from all donation levels. |
1157 | - foreach ( $variable_prices as $variable_price ) { |
|
1157 | + foreach ($variable_prices as $variable_price) { |
|
1158 | 1158 | // Sanitize level amount. |
1159 | - $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'], $default_decimals ); |
|
1159 | + $variable_price['_give_amount'] = give_sanitize_amount($variable_price['_give_amount'], $default_decimals); |
|
1160 | 1160 | |
1161 | 1161 | // Set first match donation level ID. |
1162 | - if ( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1162 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1163 | 1163 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1164 | 1164 | $donation_level_matched = true; |
1165 | 1165 | break; |
@@ -1170,19 +1170,19 @@ discard block |
||
1170 | 1170 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1171 | 1171 | if ( |
1172 | 1172 | ! $donation_level_matched |
1173 | - && ( give_is_setting_enabled( give_get_meta( $data['give-form-id'], '_give_custom_amount', true ) ) ) |
|
1173 | + && (give_is_setting_enabled(give_get_meta($data['give-form-id'], '_give_custom_amount', true))) |
|
1174 | 1174 | ) { |
1175 | 1175 | // Sanitize custom minimum amount. |
1176 | - $custom_minimum_amount = give_sanitize_amount( give_get_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ), $default_decimals ); |
|
1176 | + $custom_minimum_amount = give_sanitize_amount(give_get_meta($data['give-form-id'], '_give_custom_amount_minimum', true), $default_decimals); |
|
1177 | 1177 | |
1178 | - if ( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1178 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1179 | 1179 | $_POST['give-price-id'] = 'custom'; |
1180 | 1180 | $donation_level_matched = true; |
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | }// End if(). |
1184 | 1184 | |
1185 | - return ( $donation_level_matched ? true : false ); |
|
1185 | + return ($donation_level_matched ? true : false); |
|
1186 | 1186 | } |
1187 | 1187 | |
1188 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1188 | +add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2); |