@@ -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 | |
@@ -71,43 +71,43 @@ discard block |
||
71 | 71 | public function __construct() { |
72 | 72 | |
73 | 73 | $this->use_php_sessions = $this->use_php_sessions(); |
74 | - $this->exp_option = give_get_option( 'session_lifetime' ); |
|
74 | + $this->exp_option = give_get_option('session_lifetime'); |
|
75 | 75 | |
76 | - if ( $this->use_php_sessions ) { |
|
76 | + if ($this->use_php_sessions) { |
|
77 | 77 | |
78 | - if ( is_multisite() ) { |
|
78 | + if (is_multisite()) { |
|
79 | 79 | |
80 | - $this->prefix = '_' . get_current_blog_id(); |
|
80 | + $this->prefix = '_'.get_current_blog_id(); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'give_pre_process_purchase', array( $this, 'maybe_start_session' ), - 2 ); |
|
84 | + add_action('give_pre_process_purchase', array($this, 'maybe_start_session'), - 2); |
|
85 | 85 | |
86 | 86 | } else { |
87 | 87 | |
88 | 88 | // Use WP_Session (default) |
89 | - if ( ! defined( 'WP_SESSION_COOKIE' ) ) { |
|
90 | - define( 'WP_SESSION_COOKIE', 'give_wp_session' ); |
|
89 | + if ( ! defined('WP_SESSION_COOKIE')) { |
|
90 | + define('WP_SESSION_COOKIE', 'give_wp_session'); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( ! class_exists( 'Recursive_ArrayAccess' ) ) { |
|
94 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/sessions/class-recursive-arrayaccess.php'; |
|
93 | + if ( ! class_exists('Recursive_ArrayAccess')) { |
|
94 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/sessions/class-recursive-arrayaccess.php'; |
|
95 | 95 | } |
96 | 96 | |
97 | - if ( ! class_exists( 'WP_Session' ) ) { |
|
98 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/sessions/class-wp-session.php'; |
|
99 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/sessions/wp-session.php'; |
|
97 | + if ( ! class_exists('WP_Session')) { |
|
98 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/sessions/class-wp-session.php'; |
|
99 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/sessions/wp-session.php'; |
|
100 | 100 | } |
101 | 101 | |
102 | - add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 ); |
|
103 | - add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 ); |
|
102 | + add_filter('wp_session_expiration_variant', array($this, 'set_expiration_variant_time'), 99999); |
|
103 | + add_filter('wp_session_expiration', array($this, 'set_expiration_time'), 99999); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | |
107 | - if ( empty( $this->session ) && ! $this->use_php_sessions ) { |
|
108 | - add_action( 'plugins_loaded', array( $this, 'init' ), - 1 ); |
|
107 | + if (empty($this->session) && ! $this->use_php_sessions) { |
|
108 | + add_action('plugins_loaded', array($this, 'init'), - 1); |
|
109 | 109 | } else { |
110 | - add_action( 'init', array( $this, 'init' ), - 1 ); |
|
110 | + add_action('init', array($this, 'init'), - 1); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function init() { |
123 | 123 | |
124 | - if ( $this->use_php_sessions ) { |
|
125 | - $this->session = isset( $_SESSION[ 'give' . $this->prefix ] ) && is_array( $_SESSION[ 'give' . $this->prefix ] ) ? $_SESSION[ 'give' . $this->prefix ] : array(); |
|
124 | + if ($this->use_php_sessions) { |
|
125 | + $this->session = isset($_SESSION['give'.$this->prefix]) && is_array($_SESSION['give'.$this->prefix]) ? $_SESSION['give'.$this->prefix] : array(); |
|
126 | 126 | } else { |
127 | 127 | $this->session = WP_Session::get_instance(); |
128 | 128 | } |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return string Session variable |
155 | 155 | */ |
156 | - public function get( $key ) { |
|
157 | - $key = sanitize_key( $key ); |
|
156 | + public function get($key) { |
|
157 | + $key = sanitize_key($key); |
|
158 | 158 | |
159 | - return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false; |
|
159 | + return isset($this->session[$key]) ? maybe_unserialize($this->session[$key]) : false; |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return mixed Session variable |
172 | 172 | */ |
173 | - public function set( $key, $value ) { |
|
173 | + public function set($key, $value) { |
|
174 | 174 | |
175 | - $key = sanitize_key( $key ); |
|
175 | + $key = sanitize_key($key); |
|
176 | 176 | |
177 | - if ( is_array( $value ) ) { |
|
178 | - $this->session[ $key ] = serialize( $value ); |
|
177 | + if (is_array($value)) { |
|
178 | + $this->session[$key] = serialize($value); |
|
179 | 179 | } else { |
180 | - $this->session[ $key ] = $value; |
|
180 | + $this->session[$key] = $value; |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( $this->use_php_sessions ) { |
|
184 | - $_SESSION[ 'give' . $this->prefix ] = $this->session; |
|
183 | + if ($this->use_php_sessions) { |
|
184 | + $_SESSION['give'.$this->prefix] = $this->session; |
|
185 | 185 | } |
186 | 186 | |
187 | - return $this->session[ $key ]; |
|
187 | + return $this->session[$key]; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function set_expiration_variant_time() { |
201 | 201 | |
202 | - return ( ! empty( $this->exp_option ) ? ( intval( $this->exp_option ) - 3600 ) : 30 * 60 * 23 ); |
|
202 | + return ( ! empty($this->exp_option) ? (intval($this->exp_option) - 3600) : 30 * 60 * 23); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function set_expiration_time() { |
216 | 216 | |
217 | - return ( ! empty( $this->exp_option ) ? intval( $this->exp_option ) : 30 * 60 * 24 ); |
|
217 | + return ( ! empty($this->exp_option) ? intval($this->exp_option) : 30 * 60 * 24); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -232,21 +232,21 @@ discard block |
||
232 | 232 | $ret = false; |
233 | 233 | |
234 | 234 | // If the database variable is already set, no need to run autodetection |
235 | - $give_use_php_sessions = (bool) get_option( 'give_use_php_sessions' ); |
|
235 | + $give_use_php_sessions = (bool) get_option('give_use_php_sessions'); |
|
236 | 236 | |
237 | - if ( ! $give_use_php_sessions ) { |
|
237 | + if ( ! $give_use_php_sessions) { |
|
238 | 238 | |
239 | 239 | // Attempt to detect if the server supports PHP sessions |
240 | - if ( function_exists( 'session_start' ) && ! ini_get( 'safe_mode' ) ) { |
|
240 | + if (function_exists('session_start') && ! ini_get('safe_mode')) { |
|
241 | 241 | |
242 | - $this->set( 'give_use_php_sessions', 1 ); |
|
242 | + $this->set('give_use_php_sessions', 1); |
|
243 | 243 | |
244 | - if ( $this->get( 'give_use_php_sessions' ) ) { |
|
244 | + if ($this->get('give_use_php_sessions')) { |
|
245 | 245 | |
246 | 246 | $ret = true; |
247 | 247 | |
248 | 248 | // Set the database option |
249 | - update_option( 'give_use_php_sessions', true ); |
|
249 | + update_option('give_use_php_sessions', true); |
|
250 | 250 | |
251 | 251 | } |
252 | 252 | |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | // Enable or disable PHP Sessions based on the GIVE_USE_PHP_SESSIONS constant |
261 | - if ( defined( 'GIVE_USE_PHP_SESSIONS' ) && GIVE_USE_PHP_SESSIONS ) { |
|
261 | + if (defined('GIVE_USE_PHP_SESSIONS') && GIVE_USE_PHP_SESSIONS) { |
|
262 | 262 | $ret = true; |
263 | - } else if ( defined( 'GIVE_USE_PHP_SESSIONS' ) && ! GIVE_USE_PHP_SESSIONS ) { |
|
263 | + } else if (defined('GIVE_USE_PHP_SESSIONS') && ! GIVE_USE_PHP_SESSIONS) { |
|
264 | 264 | $ret = false; |
265 | 265 | } |
266 | 266 | |
267 | - return (bool) apply_filters( 'give_use_php_sessions', $ret ); |
|
267 | + return (bool) apply_filters('give_use_php_sessions', $ret); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | |
278 | 278 | // session_destroy(); //Uncomment for testing ONLY |
279 | 279 | |
280 | - if ( ! session_id() && ! headers_sent() ) { |
|
281 | - $lifetime = current_time( 'timestamp' ) + $this->set_expiration_time(); |
|
280 | + if ( ! session_id() && ! headers_sent()) { |
|
281 | + $lifetime = current_time('timestamp') + $this->set_expiration_time(); |
|
282 | 282 | session_start(); |
283 | - setcookie( session_name(), session_id(), $lifetime ); // |
|
284 | - setcookie( session_name() . '_expiration', $lifetime, $lifetime ); |
|
283 | + setcookie(session_name(), session_id(), $lifetime); // |
|
284 | + setcookie(session_name().'_expiration', $lifetime, $lifetime); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | |
297 | 297 | $expiration = false; |
298 | 298 | |
299 | - if ( session_id() && isset( $_COOKIE[ session_name() . '_expiration' ] ) ) { |
|
299 | + if (session_id() && isset($_COOKIE[session_name().'_expiration'])) { |
|
300 | 300 | |
301 | - $expiration = date( 'D, d M Y h:i:s', intval( $_COOKIE[ session_name() . '_expiration' ] ) ); |
|
301 | + $expiration = date('D, d M Y h:i:s', intval($_COOKIE[session_name().'_expiration'])); |
|
302 | 302 | |
303 | 303 | } |
304 | 304 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -28,68 +28,68 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return void |
30 | 30 | */ |
31 | -function give_complete_purchase( $payment_id, $new_status, $old_status ) { |
|
31 | +function give_complete_purchase($payment_id, $new_status, $old_status) { |
|
32 | 32 | |
33 | 33 | // Make sure that payments are only completed once |
34 | - if ( $old_status == 'publish' || $old_status == 'complete' ) { |
|
34 | + if ($old_status == 'publish' || $old_status == 'complete') { |
|
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | 38 | // Make sure the payment completion is only processed when new status is complete |
39 | - if ( $new_status != 'publish' && $new_status != 'complete' ) { |
|
39 | + if ($new_status != 'publish' && $new_status != 'complete') { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
44 | - $creation_date = get_post_field( 'post_date', $payment_id, 'raw' ); |
|
45 | - $completed_date = give_get_payment_completed_date( $payment_id ); |
|
46 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
47 | - $donor_id = give_get_payment_customer_id( $payment_id ); |
|
48 | - $amount = give_get_payment_amount( $payment_id ); |
|
43 | + $payment_meta = give_get_payment_meta($payment_id); |
|
44 | + $creation_date = get_post_field('post_date', $payment_id, 'raw'); |
|
45 | + $completed_date = give_get_payment_completed_date($payment_id); |
|
46 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
47 | + $donor_id = give_get_payment_customer_id($payment_id); |
|
48 | + $amount = give_get_payment_amount($payment_id); |
|
49 | 49 | |
50 | - do_action( 'give_pre_complete_purchase', $payment_id ); |
|
50 | + do_action('give_pre_complete_purchase', $payment_id); |
|
51 | 51 | |
52 | - $price_id = isset( $_POST['give-price-id'] ) ? (int) $_POST['give-price-id'] : false; |
|
52 | + $price_id = isset($_POST['give-price-id']) ? (int) $_POST['give-price-id'] : false; |
|
53 | 53 | |
54 | 54 | // Ensure these actions only run once, ever |
55 | - if ( empty( $completed_date ) ) { |
|
55 | + if (empty($completed_date)) { |
|
56 | 56 | |
57 | - if ( ! give_is_test_mode() || apply_filters( 'give_log_test_payment_stats', false ) ) { |
|
57 | + if ( ! give_is_test_mode() || apply_filters('give_log_test_payment_stats', false)) { |
|
58 | 58 | |
59 | - give_record_sale_in_log( $payment_meta['form_id'], $payment_id, $price_id, $creation_date ); |
|
60 | - give_increase_purchase_count( $payment_meta['form_id'] ); |
|
61 | - give_increase_earnings( $payment_meta['form_id'], $amount ); |
|
59 | + give_record_sale_in_log($payment_meta['form_id'], $payment_id, $price_id, $creation_date); |
|
60 | + give_increase_purchase_count($payment_meta['form_id']); |
|
61 | + give_increase_earnings($payment_meta['form_id'], $amount); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | |
65 | - do_action( 'give_complete_form_donation', $payment_meta['form_id'], $payment_id, $payment_meta ); |
|
65 | + do_action('give_complete_form_donation', $payment_meta['form_id'], $payment_id, $payment_meta); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | 69 | // Clear the total earnings cache |
70 | - delete_transient( 'give_earnings_total' ); |
|
70 | + delete_transient('give_earnings_total'); |
|
71 | 71 | // Clear the This Month earnings (this_monththis_month is NOT a typo) |
72 | - delete_transient( md5( 'give_earnings_this_monththis_month' ) ); |
|
73 | - delete_transient( md5( 'give_earnings_todaytoday' ) ); |
|
72 | + delete_transient(md5('give_earnings_this_monththis_month')); |
|
73 | + delete_transient(md5('give_earnings_todaytoday')); |
|
74 | 74 | |
75 | 75 | |
76 | 76 | // Increase the donor's purchase stats |
77 | - Give()->customers->increment_stats( $donor_id, $amount ); |
|
77 | + Give()->customers->increment_stats($donor_id, $amount); |
|
78 | 78 | |
79 | - give_increase_total_earnings( $amount ); |
|
79 | + give_increase_total_earnings($amount); |
|
80 | 80 | |
81 | 81 | // Ensure this action only runs once ever |
82 | - if ( empty( $completed_date ) ) { |
|
82 | + if (empty($completed_date)) { |
|
83 | 83 | |
84 | 84 | // Save the completed date |
85 | - give_update_payment_meta( $payment_id, '_give_completed_date', current_time( 'mysql' ) ); |
|
85 | + give_update_payment_meta($payment_id, '_give_completed_date', current_time('mysql')); |
|
86 | 86 | |
87 | - do_action( 'give_complete_purchase', $payment_id ); |
|
87 | + do_action('give_complete_purchase', $payment_id); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | } |
91 | 91 | |
92 | -add_action( 'give_update_payment_status', 'give_complete_purchase', 100, 3 ); |
|
92 | +add_action('give_update_payment_status', 'give_complete_purchase', 100, 3); |
|
93 | 93 | |
94 | 94 | |
95 | 95 | /** |
@@ -103,19 +103,19 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return void |
105 | 105 | */ |
106 | -function give_record_status_change( $payment_id, $new_status, $old_status ) { |
|
106 | +function give_record_status_change($payment_id, $new_status, $old_status) { |
|
107 | 107 | |
108 | 108 | // Get the list of statuses so that status in the payment note can be translated |
109 | 109 | $stati = give_get_payment_statuses(); |
110 | - $old_status = isset( $stati[ $old_status ] ) ? $stati[ $old_status ] : $old_status; |
|
111 | - $new_status = isset( $stati[ $new_status ] ) ? $stati[ $new_status ] : $new_status; |
|
110 | + $old_status = isset($stati[$old_status]) ? $stati[$old_status] : $old_status; |
|
111 | + $new_status = isset($stati[$new_status]) ? $stati[$new_status] : $new_status; |
|
112 | 112 | |
113 | - $status_change = sprintf( __( 'Status changed from %s to %s', 'give' ), $old_status, $new_status ); |
|
113 | + $status_change = sprintf(__('Status changed from %s to %s', 'give'), $old_status, $new_status); |
|
114 | 114 | |
115 | - give_insert_payment_note( $payment_id, $status_change ); |
|
115 | + give_insert_payment_note($payment_id, $status_change); |
|
116 | 116 | } |
117 | 117 | |
118 | -add_action( 'give_update_payment_status', 'give_record_status_change', 100, 3 ); |
|
118 | +add_action('give_update_payment_status', 'give_record_status_change', 100, 3); |
|
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Reduces earnings and donation stats when a donation is refunded |
@@ -128,40 +128,40 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return void |
130 | 130 | */ |
131 | -function give_undo_donation_on_refund( $payment_id, $new_status, $old_status ) { |
|
131 | +function give_undo_donation_on_refund($payment_id, $new_status, $old_status) { |
|
132 | 132 | |
133 | - if ( 'publish' != $old_status && 'revoked' != $old_status ) { |
|
133 | + if ('publish' != $old_status && 'revoked' != $old_status) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - if ( 'refunded' != $new_status ) { |
|
137 | + if ('refunded' != $new_status) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Set necessary vars |
142 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
143 | - $amount = give_get_payment_amount( $payment_id ); |
|
142 | + $payment_meta = give_get_payment_meta($payment_id); |
|
143 | + $amount = give_get_payment_amount($payment_id); |
|
144 | 144 | |
145 | 145 | // Undo this purchase |
146 | - give_undo_purchase( $payment_meta['form_id'], $payment_id ); |
|
146 | + give_undo_purchase($payment_meta['form_id'], $payment_id); |
|
147 | 147 | |
148 | 148 | // Decrease total earnings |
149 | - give_decrease_total_earnings( $amount ); |
|
149 | + give_decrease_total_earnings($amount); |
|
150 | 150 | |
151 | 151 | // Decrement the stats for the donor |
152 | - $donor_id = give_get_payment_customer_id( $payment_id ); |
|
152 | + $donor_id = give_get_payment_customer_id($payment_id); |
|
153 | 153 | |
154 | - if ( $donor_id ) { |
|
154 | + if ($donor_id) { |
|
155 | 155 | |
156 | - Give()->customers->decrement_stats( $donor_id, $amount ); |
|
156 | + Give()->customers->decrement_stats($donor_id, $amount); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
160 | 160 | // Clear the This Month earnings (this_monththis_month is NOT a typo) |
161 | - delete_transient( md5( 'give_earnings_this_monththis_month' ) ); |
|
161 | + delete_transient(md5('give_earnings_this_monththis_month')); |
|
162 | 162 | } |
163 | 163 | |
164 | -add_action( 'give_update_payment_status', 'give_undo_donation_on_refund', 100, 3 ); |
|
164 | +add_action('give_update_payment_status', 'give_undo_donation_on_refund', 100, 3); |
|
165 | 165 | |
166 | 166 | |
167 | 167 | /** |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @param $new_status the status of the payment, probably "publish" |
175 | 175 | * @param $old_status the status of the payment prior to being marked as "complete", probably "pending" |
176 | 176 | */ |
177 | -function give_clear_user_history_cache( $payment_id, $new_status, $old_status ) { |
|
178 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
177 | +function give_clear_user_history_cache($payment_id, $new_status, $old_status) { |
|
178 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
179 | 179 | |
180 | - delete_transient( 'give_user_' . $user_info['id'] . '_purchases' ); |
|
180 | + delete_transient('give_user_'.$user_info['id'].'_purchases'); |
|
181 | 181 | } |
182 | 182 | |
183 | -add_action( 'give_update_payment_status', 'give_clear_user_history_cache', 10, 3 ); |
|
183 | +add_action('give_update_payment_status', 'give_clear_user_history_cache', 10, 3); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Updates all old payments, prior to 1.2, with new |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return void |
196 | 196 | */ |
197 | -function give_update_old_payments_with_totals( $data ) { |
|
198 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_upgrade_payments_nonce' ) ) { |
|
197 | +function give_update_old_payments_with_totals($data) { |
|
198 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give_upgrade_payments_nonce')) { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | |
202 | - if ( get_option( 'give_payment_totals_upgraded' ) ) { |
|
202 | + if (get_option('give_payment_totals_upgraded')) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - $payments = give_get_payments( array( |
|
206 | + $payments = give_get_payments(array( |
|
207 | 207 | 'offset' => 0, |
208 | - 'number' => - 1, |
|
208 | + 'number' => -1, |
|
209 | 209 | 'mode' => 'all' |
210 | - ) ); |
|
210 | + )); |
|
211 | 211 | |
212 | - if ( $payments ) { |
|
213 | - foreach ( $payments as $payment ) { |
|
214 | - $meta = give_get_payment_meta( $payment->ID ); |
|
215 | - give_update_payment_meta( $payment->ID, '_give_payment_total', $meta['amount'] ); |
|
212 | + if ($payments) { |
|
213 | + foreach ($payments as $payment) { |
|
214 | + $meta = give_get_payment_meta($payment->ID); |
|
215 | + give_update_payment_meta($payment->ID, '_give_payment_total', $meta['amount']); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - add_option( 'give_payment_totals_upgraded', 1 ); |
|
219 | + add_option('give_payment_totals_upgraded', 1); |
|
220 | 220 | } |
221 | 221 | |
222 | -add_action( 'give_upgrade_payments', 'give_update_old_payments_with_totals' ); |
|
222 | +add_action('give_upgrade_payments', 'give_update_old_payments_with_totals'); |
|
223 | 223 | |
224 | 224 | /** |
225 | 225 | * Updates week-old+ 'pending' orders to 'abandoned' |
@@ -228,29 +228,29 @@ discard block |
||
228 | 228 | * @return void |
229 | 229 | */ |
230 | 230 | function give_mark_abandoned_donations() { |
231 | - $args = array( |
|
231 | + $args = array( |
|
232 | 232 | 'status' => 'pending', |
233 | - 'number' => - 1, |
|
233 | + 'number' => -1, |
|
234 | 234 | 'fields' => 'ids' |
235 | 235 | ); |
236 | 236 | |
237 | - add_filter( 'posts_where', 'give_filter_where_older_than_week' ); |
|
237 | + add_filter('posts_where', 'give_filter_where_older_than_week'); |
|
238 | 238 | |
239 | - $payments = give_get_payments( $args ); |
|
239 | + $payments = give_get_payments($args); |
|
240 | 240 | |
241 | - remove_filter( 'posts_where', 'give_filter_where_older_than_week' ); |
|
241 | + remove_filter('posts_where', 'give_filter_where_older_than_week'); |
|
242 | 242 | |
243 | - if ( $payments ) { |
|
244 | - foreach ( $payments as $payment ) { |
|
245 | - $gateway = give_get_payment_gateway( $payment ); |
|
243 | + if ($payments) { |
|
244 | + foreach ($payments as $payment) { |
|
245 | + $gateway = give_get_payment_gateway($payment); |
|
246 | 246 | //Skip offline gateway payments |
247 | - if ( $gateway == 'offline' ) { |
|
247 | + if ($gateway == 'offline') { |
|
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | //Non-offline get marked as 'abandoned' |
251 | - give_update_payment_status( $payment, 'abandoned' ); |
|
251 | + give_update_payment_status($payment, 'abandoned'); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | -add_action( 'give_weekly_scheduled_events', 'give_mark_abandoned_donations' ); |
|
257 | 256 | \ No newline at end of file |
257 | +add_action('give_weekly_scheduled_events', 'give_mark_abandoned_donations'); |
|
258 | 258 | \ No newline at end of file |
@@ -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,10 +25,10 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_process_purchase_form() { |
27 | 27 | |
28 | - do_action( 'give_pre_process_purchase' ); |
|
28 | + do_action('give_pre_process_purchase'); |
|
29 | 29 | |
30 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
31 | - if( $session_reflection->isPublic() ){ |
|
30 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
31 | + if ($session_reflection->isPublic()) { |
|
32 | 32 | // Manually set the cookie. |
33 | 33 | Give()->session->init()->set_cookie(); |
34 | 34 | } |
@@ -37,28 +37,28 @@ discard block |
||
37 | 37 | $valid_data = give_purchase_form_validate_fields(); |
38 | 38 | |
39 | 39 | // Allow themes and plugins to hook to errors |
40 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
40 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
41 | 41 | |
42 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
42 | + $is_ajax = isset($_POST['give_ajax']); |
|
43 | 43 | |
44 | 44 | // Process the login form |
45 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
45 | + if (isset($_POST['give_login_submit'])) { |
|
46 | 46 | give_process_form_login(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | // Validate the user |
50 | - $user = give_get_purchase_form_user( $valid_data ); |
|
50 | + $user = give_get_purchase_form_user($valid_data); |
|
51 | 51 | |
52 | - if ( give_get_errors() || ! $user ) { |
|
53 | - if ( $is_ajax ) { |
|
54 | - do_action( 'give_ajax_checkout_errors' ); |
|
52 | + if (give_get_errors() || ! $user) { |
|
53 | + if ($is_ajax) { |
|
54 | + do_action('give_ajax_checkout_errors'); |
|
55 | 55 | give_die(); |
56 | 56 | } else { |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - if ( $is_ajax ) { |
|
61 | + if ($is_ajax) { |
|
62 | 62 | echo 'success'; |
63 | 63 | give_die(); |
64 | 64 | } |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | 'address' => $user['address'] |
73 | 73 | ); |
74 | 74 | |
75 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
75 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
76 | 76 | |
77 | 77 | // Setup purchase information |
78 | 78 | $purchase_data = array( |
79 | - 'price' => ( isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00' ), |
|
80 | - 'purchase_key' => strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ), |
|
79 | + 'price' => (isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'), |
|
80 | + 'purchase_key' => strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))), |
|
81 | 81 | 'user_email' => $user['user_email'], |
82 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
83 | - 'user_info' => stripslashes_deep( $user_info ), |
|
82 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
83 | + 'user_info' => stripslashes_deep($user_info), |
|
84 | 84 | 'post_data' => $_POST, |
85 | 85 | 'gateway' => $valid_data['gateway'], |
86 | 86 | 'card_info' => $valid_data['cc_info'] |
@@ -90,36 +90,36 @@ discard block |
||
90 | 90 | $valid_data['user'] = $user; |
91 | 91 | |
92 | 92 | // Allow themes and plugins to hook before the gateway |
93 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
93 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
94 | 94 | |
95 | 95 | //Sanity check for price |
96 | - if ( ! $purchase_data['price'] ) { |
|
96 | + if ( ! $purchase_data['price']) { |
|
97 | 97 | // Revert to manual |
98 | 98 | $purchase_data['gateway'] = 'manual'; |
99 | 99 | $_POST['give-gateway'] = 'manual'; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Allow the purchase data to be modified before it is sent to the gateway |
103 | - $purchase_data = apply_filters( 'give_purchase_data_before_gateway', $purchase_data, $valid_data ); |
|
103 | + $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); |
|
104 | 104 | |
105 | 105 | // Setup the data we're storing in the purchase session |
106 | 106 | $session_data = $purchase_data; |
107 | 107 | |
108 | 108 | // Make sure credit card numbers are never stored in sessions |
109 | - unset( $session_data['card_info']['card_number'] ); |
|
109 | + unset($session_data['card_info']['card_number']); |
|
110 | 110 | |
111 | 111 | // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. |
112 | - give_set_purchase_session( $session_data ); |
|
112 | + give_set_purchase_session($session_data); |
|
113 | 113 | |
114 | 114 | // Send info to the gateway for payment processing |
115 | - give_send_to_gateway( $purchase_data['gateway'], $purchase_data ); |
|
115 | + give_send_to_gateway($purchase_data['gateway'], $purchase_data); |
|
116 | 116 | give_die(); |
117 | 117 | |
118 | 118 | } |
119 | 119 | |
120 | -add_action( 'give_purchase', 'give_process_purchase_form' ); |
|
121 | -add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' ); |
|
122 | -add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' ); |
|
120 | +add_action('give_purchase', 'give_process_purchase_form'); |
|
121 | +add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form'); |
|
122 | +add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form'); |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * Process the checkout login form |
@@ -130,32 +130,32 @@ discard block |
||
130 | 130 | */ |
131 | 131 | function give_process_form_login() { |
132 | 132 | |
133 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
133 | + $is_ajax = isset($_POST['give_ajax']); |
|
134 | 134 | |
135 | 135 | $user_data = give_purchase_form_validate_user_login(); |
136 | 136 | |
137 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
138 | - if ( $is_ajax ) { |
|
139 | - do_action( 'give_ajax_checkout_errors' ); |
|
137 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
138 | + if ($is_ajax) { |
|
139 | + do_action('give_ajax_checkout_errors'); |
|
140 | 140 | give_die(); |
141 | 141 | } else { |
142 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
142 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
143 | 143 | exit; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
147 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
148 | 148 | |
149 | - if ( $is_ajax ) { |
|
149 | + if ($is_ajax) { |
|
150 | 150 | echo 'success'; |
151 | 151 | give_die(); |
152 | 152 | } else { |
153 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
153 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | -add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' ); |
|
158 | -add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' ); |
|
157 | +add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login'); |
|
158 | +add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login'); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Purchase Form Validate Fields |
@@ -167,40 +167,40 @@ discard block |
||
167 | 167 | function give_purchase_form_validate_fields() { |
168 | 168 | |
169 | 169 | // Check if there is $_POST |
170 | - if ( empty( $_POST ) ) { |
|
170 | + if (empty($_POST)) { |
|
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | |
174 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
174 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
175 | 175 | |
176 | 176 | // Start an array to collect valid data |
177 | 177 | $valid_data = array( |
178 | 178 | 'gateway' => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here) |
179 | - 'need_new_user' => false, // New user flag |
|
180 | - 'need_user_login' => false, // Login user flag |
|
181 | - 'logged_user_data' => array(), // Logged user collected data |
|
182 | - 'new_user_data' => array(), // New user collected data |
|
183 | - 'login_user_data' => array(), // Login user collected data |
|
184 | - 'guest_user_data' => array(), // Guest user collected data |
|
179 | + 'need_new_user' => false, // New user flag |
|
180 | + 'need_user_login' => false, // Login user flag |
|
181 | + 'logged_user_data' => array(), // Logged user collected data |
|
182 | + 'new_user_data' => array(), // New user collected data |
|
183 | + 'login_user_data' => array(), // Login user collected data |
|
184 | + 'guest_user_data' => array(), // Guest user collected data |
|
185 | 185 | 'cc_info' => give_purchase_form_validate_cc() // Credit card info |
186 | 186 | ); |
187 | 187 | |
188 | 188 | // Validate agree to terms |
189 | - $terms_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
190 | - if ( isset( $terms_option ) && $terms_option === 'yes' ) { |
|
189 | + $terms_option = get_post_meta($form_id, '_give_terms_option', true); |
|
190 | + if (isset($terms_option) && $terms_option === 'yes') { |
|
191 | 191 | give_purchase_form_validate_agree_to_terms(); |
192 | 192 | } |
193 | 193 | |
194 | - if ( is_user_logged_in() ) { |
|
194 | + if (is_user_logged_in()) { |
|
195 | 195 | // Collect logged in user data |
196 | 196 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
197 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
197 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
198 | 198 | // Set new user registration as required |
199 | 199 | $valid_data['need_new_user'] = true; |
200 | 200 | // Validate new user data |
201 | 201 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
202 | 202 | // Check if login validation is needed |
203 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
203 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
204 | 204 | // Set user login as required |
205 | 205 | $valid_data['need_user_login'] = true; |
206 | 206 | // Validate users login info |
@@ -223,35 +223,35 @@ discard block |
||
223 | 223 | */ |
224 | 224 | function give_purchase_form_validate_gateway() { |
225 | 225 | |
226 | - $gateway = give_get_default_gateway( $_REQUEST['give-form-id'] ); |
|
226 | + $gateway = give_get_default_gateway($_REQUEST['give-form-id']); |
|
227 | 227 | |
228 | 228 | // Check if a gateway value is present |
229 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
229 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
230 | 230 | |
231 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
231 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
232 | 232 | |
233 | 233 | //Is amount being donated in LIVE mode above 0.00? |
234 | - if ( '0.00' == $_REQUEST['give-amount'] && ! give_is_test_mode() ) { |
|
234 | + if ('0.00' == $_REQUEST['give-amount'] && ! give_is_test_mode()) { |
|
235 | 235 | |
236 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
236 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
237 | 237 | |
238 | 238 | } //Check for a minimum custom amount |
239 | - elseif ( ! give_verify_minimum_price() ) { |
|
239 | + elseif ( ! give_verify_minimum_price()) { |
|
240 | 240 | |
241 | - $minimum = give_currency_filter( give_format_amount( give_get_form_minimum_price( $_REQUEST['give-form-id'] ) ) ); |
|
242 | - $error_message = __( 'This form has a minimum donation amount of %s', 'give' ); |
|
241 | + $minimum = give_currency_filter(give_format_amount(give_get_form_minimum_price($_REQUEST['give-form-id']))); |
|
242 | + $error_message = __('This form has a minimum donation amount of %s', 'give'); |
|
243 | 243 | |
244 | - give_set_error( 'invalid_donation_minimum', sprintf( $error_message, $minimum ) ); |
|
244 | + give_set_error('invalid_donation_minimum', sprintf($error_message, $minimum)); |
|
245 | 245 | |
246 | 246 | } //Is this test mode zero donation? Let it through but set to manual gateway |
247 | - elseif ( '0.00' == $_REQUEST['give-amount'] && give_is_test_mode() ) { |
|
247 | + elseif ('0.00' == $_REQUEST['give-amount'] && give_is_test_mode()) { |
|
248 | 248 | |
249 | 249 | $gateway = 'manual'; |
250 | 250 | |
251 | 251 | } //Check if this gateway is active |
252 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
252 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
253 | 253 | |
254 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'give' ) ); |
|
254 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'give')); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 | |
@@ -270,23 +270,23 @@ discard block |
||
270 | 270 | */ |
271 | 271 | function give_verify_minimum_price() { |
272 | 272 | |
273 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
273 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
274 | 274 | $form_id = $_REQUEST['give-form-id']; |
275 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
276 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
275 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
276 | + $variable_prices = give_has_variable_prices($form_id); |
|
277 | 277 | |
278 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
278 | + if ($variable_prices && ! empty($price_id)) { |
|
279 | 279 | |
280 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
280 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
281 | 281 | |
282 | - if ( $price_level_amount == $amount ) { |
|
282 | + if ($price_level_amount == $amount) { |
|
283 | 283 | return true; |
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
287 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
287 | + $minimum = give_get_form_minimum_price($form_id); |
|
288 | 288 | |
289 | - if ( $minimum > $amount ) { |
|
289 | + if ($minimum > $amount) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | */ |
303 | 303 | function give_purchase_form_validate_agree_to_terms() { |
304 | 304 | // Validate agree to terms |
305 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
305 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
306 | 306 | // User did not agree |
307 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms of use', 'give' ) ) ); |
|
307 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms of use', 'give'))); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
@@ -318,47 +318,47 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return array |
320 | 320 | */ |
321 | -function give_purchase_form_required_fields( $form_id ) { |
|
321 | +function give_purchase_form_required_fields($form_id) { |
|
322 | 322 | |
323 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
323 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
324 | 324 | |
325 | 325 | $required_fields = array( |
326 | 326 | 'give_email' => array( |
327 | 327 | 'error_id' => 'invalid_email', |
328 | - 'error_message' => __( 'Please enter a valid email address', 'give' ) |
|
328 | + 'error_message' => __('Please enter a valid email address', 'give') |
|
329 | 329 | ), |
330 | 330 | 'give_first' => array( |
331 | 331 | 'error_id' => 'invalid_first_name', |
332 | - 'error_message' => __( 'Please enter your first name', 'give' ) |
|
332 | + 'error_message' => __('Please enter your first name', 'give') |
|
333 | 333 | ) |
334 | 334 | ); |
335 | 335 | |
336 | - $require_address = give_require_billing_address( $payment_mode ); |
|
336 | + $require_address = give_require_billing_address($payment_mode); |
|
337 | 337 | |
338 | - if ( $require_address ) { |
|
339 | - $required_fields['card_address'] = array( |
|
338 | + if ($require_address) { |
|
339 | + $required_fields['card_address'] = array( |
|
340 | 340 | 'error_id' => 'invalid_card_address', |
341 | - 'error_message' => __( 'Please enter your primary billing address', 'give' ) |
|
341 | + 'error_message' => __('Please enter your primary billing address', 'give') |
|
342 | 342 | ); |
343 | - $required_fields['card_zip'] = array( |
|
343 | + $required_fields['card_zip'] = array( |
|
344 | 344 | 'error_id' => 'invalid_zip_code', |
345 | - 'error_message' => __( 'Please enter your zip / postal code', 'give' ) |
|
345 | + 'error_message' => __('Please enter your zip / postal code', 'give') |
|
346 | 346 | ); |
347 | - $required_fields['card_city'] = array( |
|
347 | + $required_fields['card_city'] = array( |
|
348 | 348 | 'error_id' => 'invalid_city', |
349 | - 'error_message' => __( 'Please enter your billing city', 'give' ) |
|
349 | + 'error_message' => __('Please enter your billing city', 'give') |
|
350 | 350 | ); |
351 | 351 | $required_fields['billing_country'] = array( |
352 | 352 | 'error_id' => 'invalid_country', |
353 | - 'error_message' => __( 'Please select your billing country', 'give' ) |
|
353 | + 'error_message' => __('Please select your billing country', 'give') |
|
354 | 354 | ); |
355 | - $required_fields['card_state'] = array( |
|
355 | + $required_fields['card_state'] = array( |
|
356 | 356 | 'error_id' => 'invalid_state', |
357 | - 'error_message' => __( 'Please enter billing state / province', 'give' ) |
|
357 | + 'error_message' => __('Please enter billing state / province', 'give') |
|
358 | 358 | ); |
359 | 359 | } |
360 | 360 | |
361 | - return apply_filters( 'give_purchase_form_required_fields', $required_fields, $form_id ); |
|
361 | + return apply_filters('give_purchase_form_required_fields', $required_fields, $form_id); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -371,16 +371,16 @@ discard block |
||
371 | 371 | * |
372 | 372 | * @return mixed|void |
373 | 373 | */ |
374 | -function give_require_billing_address( $payment_mode ) { |
|
374 | +function give_require_billing_address($payment_mode) { |
|
375 | 375 | |
376 | 376 | $return = false; |
377 | 377 | |
378 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
378 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
379 | 379 | $return = true; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Let payment gateways and other extensions determine if address fields should be required |
383 | - return apply_filters( 'give_require_billing_address', $return ); |
|
383 | + return apply_filters('give_require_billing_address', $return); |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | |
@@ -394,43 +394,43 @@ discard block |
||
394 | 394 | function give_purchase_form_validate_logged_in_user() { |
395 | 395 | global $user_ID; |
396 | 396 | |
397 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
397 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
398 | 398 | |
399 | 399 | // Start empty array to collect valid user data |
400 | 400 | $valid_user_data = array( |
401 | 401 | // Assume there will be errors |
402 | - 'user_id' => - 1 |
|
402 | + 'user_id' => -1 |
|
403 | 403 | ); |
404 | 404 | |
405 | 405 | // Verify there is a user_ID |
406 | - if ( $user_ID > 0 ) { |
|
406 | + if ($user_ID > 0) { |
|
407 | 407 | // Get the logged in user data |
408 | - $user_data = get_userdata( $user_ID ); |
|
408 | + $user_data = get_userdata($user_ID); |
|
409 | 409 | |
410 | 410 | // Loop through required fields and show error messages |
411 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
412 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
413 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
411 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
412 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
413 | + give_set_error($value['error_id'], $value['error_message']); |
|
414 | 414 | } |
415 | 415 | } |
416 | 416 | |
417 | 417 | // Verify data |
418 | - if ( $user_data ) { |
|
418 | + if ($user_data) { |
|
419 | 419 | // Collected logged in user data |
420 | 420 | $valid_user_data = array( |
421 | 421 | 'user_id' => $user_ID, |
422 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
423 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
424 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
422 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
423 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
424 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
425 | 425 | ); |
426 | 426 | |
427 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
428 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
427 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
428 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | } else { |
432 | 432 | // Set invalid user error |
433 | - give_set_error( 'invalid_user', __( 'The user information is invalid', 'give' ) ); |
|
433 | + give_set_error('invalid_user', __('The user information is invalid', 'give')); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
@@ -448,92 +448,92 @@ discard block |
||
448 | 448 | function give_purchase_form_validate_new_user() { |
449 | 449 | |
450 | 450 | $registering_new_user = false; |
451 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
451 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
452 | 452 | |
453 | 453 | // Start an empty array to collect valid user data |
454 | 454 | $valid_user_data = array( |
455 | 455 | // Assume there will be errors |
456 | - 'user_id' => - 1, |
|
456 | + 'user_id' => -1, |
|
457 | 457 | // Get first name |
458 | - 'user_first' => isset( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : '', |
|
458 | + 'user_first' => isset($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : '', |
|
459 | 459 | // Get last name |
460 | - 'user_last' => isset( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : '', |
|
460 | + 'user_last' => isset($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : '', |
|
461 | 461 | ); |
462 | 462 | |
463 | 463 | // Check the new user's credentials against existing ones |
464 | - $user_login = isset( $_POST['give_user_login'] ) ? trim( $_POST['give_user_login'] ) : false; |
|
465 | - $user_email = isset( $_POST['give_email'] ) ? trim( $_POST['give_email'] ) : false; |
|
466 | - $user_pass = isset( $_POST['give_user_pass'] ) ? trim( $_POST['give_user_pass'] ) : false; |
|
467 | - $pass_confirm = isset( $_POST['give_user_pass_confirm'] ) ? trim( $_POST['give_user_pass_confirm'] ) : false; |
|
464 | + $user_login = isset($_POST['give_user_login']) ? trim($_POST['give_user_login']) : false; |
|
465 | + $user_email = isset($_POST['give_email']) ? trim($_POST['give_email']) : false; |
|
466 | + $user_pass = isset($_POST['give_user_pass']) ? trim($_POST['give_user_pass']) : false; |
|
467 | + $pass_confirm = isset($_POST['give_user_pass_confirm']) ? trim($_POST['give_user_pass_confirm']) : false; |
|
468 | 468 | |
469 | 469 | // Loop through required fields and show error messages |
470 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
471 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
472 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
470 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
471 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
472 | + give_set_error($value['error_id'], $value['error_message']); |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
476 | 476 | // Check if we have an username to register |
477 | - if ( $user_login && strlen( $user_login ) > 0 ) { |
|
477 | + if ($user_login && strlen($user_login) > 0) { |
|
478 | 478 | $registering_new_user = true; |
479 | 479 | |
480 | 480 | // We have an user name, check if it already exists |
481 | - if ( username_exists( $user_login ) ) { |
|
481 | + if (username_exists($user_login)) { |
|
482 | 482 | // Username already registered |
483 | - give_set_error( 'username_unavailable', __( 'Username already taken', 'give' ) ); |
|
483 | + give_set_error('username_unavailable', __('Username already taken', 'give')); |
|
484 | 484 | // Check if it's valid |
485 | - } else if ( ! give_validate_username( $user_login ) ) { |
|
485 | + } else if ( ! give_validate_username($user_login)) { |
|
486 | 486 | // Invalid username |
487 | - if ( is_multisite() ) { |
|
488 | - give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give' ) ); |
|
487 | + if (is_multisite()) { |
|
488 | + give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give')); |
|
489 | 489 | } else { |
490 | - give_set_error( 'username_invalid', __( 'Invalid username', 'give' ) ); |
|
490 | + give_set_error('username_invalid', __('Invalid username', 'give')); |
|
491 | 491 | } |
492 | 492 | } else { |
493 | 493 | // All the checks have run and it's good to go |
494 | 494 | $valid_user_data['user_login'] = $user_login; |
495 | 495 | } |
496 | 496 | } else { |
497 | - if ( give_no_guest_checkout( $form_id ) ) { |
|
498 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation', 'give' ) ); |
|
497 | + if (give_no_guest_checkout($form_id)) { |
|
498 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation', 'give')); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
502 | 502 | // Check if we have an email to verify |
503 | - if ( $user_email && strlen( $user_email ) > 0 ) { |
|
503 | + if ($user_email && strlen($user_email) > 0) { |
|
504 | 504 | // Validate email |
505 | - if ( ! is_email( $user_email ) ) { |
|
506 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
505 | + if ( ! is_email($user_email)) { |
|
506 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
507 | 507 | // Check if email exists |
508 | - } else if ( email_exists( $user_email ) && $registering_new_user ) { |
|
509 | - give_set_error( 'email_used', __( 'Email already used', 'give' ) ); |
|
508 | + } else if (email_exists($user_email) && $registering_new_user) { |
|
509 | + give_set_error('email_used', __('Email already used', 'give')); |
|
510 | 510 | } else { |
511 | 511 | // All the checks have run and it's good to go |
512 | 512 | $valid_user_data['user_email'] = $user_email; |
513 | 513 | } |
514 | 514 | } else { |
515 | 515 | // No email |
516 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
516 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | // Check password |
520 | - if ( $user_pass && $pass_confirm ) { |
|
520 | + if ($user_pass && $pass_confirm) { |
|
521 | 521 | // Verify confirmation matches |
522 | - if ( $user_pass != $pass_confirm ) { |
|
522 | + if ($user_pass != $pass_confirm) { |
|
523 | 523 | // Passwords do not match |
524 | - give_set_error( 'password_mismatch', __( 'Passwords don\'t match', 'give' ) ); |
|
524 | + give_set_error('password_mismatch', __('Passwords don\'t match', 'give')); |
|
525 | 525 | } else { |
526 | 526 | // All is good to go |
527 | 527 | $valid_user_data['user_pass'] = $user_pass; |
528 | 528 | } |
529 | 529 | } else { |
530 | 530 | // Password or confirmation missing |
531 | - if ( ! $user_pass && $registering_new_user ) { |
|
531 | + if ( ! $user_pass && $registering_new_user) { |
|
532 | 532 | // The password is invalid |
533 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
534 | - } else if ( ! $pass_confirm && $registering_new_user ) { |
|
533 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
534 | + } else if ( ! $pass_confirm && $registering_new_user) { |
|
535 | 535 | // Confirmation password is invalid |
536 | - give_set_error( 'confirmation_empty', __( 'Enter the password confirmation', 'give' ) ); |
|
536 | + give_set_error('confirmation_empty', __('Enter the password confirmation', 'give')); |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | |
@@ -552,34 +552,34 @@ discard block |
||
552 | 552 | // Start an array to collect valid user data |
553 | 553 | $valid_user_data = array( |
554 | 554 | // Assume there will be errors |
555 | - 'user_id' => - 1 |
|
555 | + 'user_id' => -1 |
|
556 | 556 | ); |
557 | 557 | |
558 | 558 | // Username |
559 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
560 | - give_set_error( 'must_log_in', __( 'You must login or register to complete your donation', 'give' ) ); |
|
559 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
560 | + give_set_error('must_log_in', __('You must login or register to complete your donation', 'give')); |
|
561 | 561 | |
562 | 562 | return $valid_user_data; |
563 | 563 | } |
564 | 564 | |
565 | 565 | // Get the user by login |
566 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
566 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
567 | 567 | |
568 | 568 | // Check if user exists |
569 | - if ( $user_data ) { |
|
569 | + if ($user_data) { |
|
570 | 570 | // Get password |
571 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
571 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
572 | 572 | |
573 | 573 | // Check user_pass |
574 | - if ( $user_pass ) { |
|
574 | + if ($user_pass) { |
|
575 | 575 | // Check if password is valid |
576 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
576 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
577 | 577 | // Incorrect password |
578 | 578 | give_set_error( |
579 | 579 | 'password_incorrect', |
580 | 580 | sprintf( |
581 | - __( 'The password you entered is incorrect. %sReset Password%s', 'give' ), |
|
582 | - '<a href="' . wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) . '" title="' . __( 'Lost Password', 'give' ) . '">', |
|
581 | + __('The password you entered is incorrect. %sReset Password%s', 'give'), |
|
582 | + '<a href="'.wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]").'" title="'.__('Lost Password', 'give').'">', |
|
583 | 583 | '</a>' |
584 | 584 | ) |
585 | 585 | ); |
@@ -597,11 +597,11 @@ discard block |
||
597 | 597 | } |
598 | 598 | } else { |
599 | 599 | // Empty password |
600 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
600 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
601 | 601 | } |
602 | 602 | } else { |
603 | 603 | // no username |
604 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist', 'give' ) ); |
|
604 | + give_set_error('username_incorrect', __('The username you entered does not exist', 'give')); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | return $valid_user_data; |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | */ |
617 | 617 | function give_purchase_form_validate_guest_user() { |
618 | 618 | |
619 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
619 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
620 | 620 | |
621 | 621 | // Start an array to collect valid user data |
622 | 622 | $valid_user_data = array( |
@@ -625,32 +625,32 @@ discard block |
||
625 | 625 | ); |
626 | 626 | |
627 | 627 | // Show error message if user must be logged in |
628 | - if ( give_logged_in_only() ) { |
|
629 | - give_set_error( 'logged_in_only', __( 'You must be logged into an account to donation', 'give' ) ); |
|
628 | + if (give_logged_in_only()) { |
|
629 | + give_set_error('logged_in_only', __('You must be logged into an account to donation', 'give')); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | // Get the guest email |
633 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
633 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
634 | 634 | |
635 | 635 | // Check email |
636 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
636 | + if ($guest_email && strlen($guest_email) > 0) { |
|
637 | 637 | // Validate email |
638 | - if ( ! is_email( $guest_email ) ) { |
|
638 | + if ( ! is_email($guest_email)) { |
|
639 | 639 | // Invalid email |
640 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
640 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
641 | 641 | } else { |
642 | 642 | // All is good to go |
643 | 643 | $valid_user_data['user_email'] = $guest_email; |
644 | 644 | } |
645 | 645 | } else { |
646 | 646 | // No email |
647 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
647 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Loop through required fields and show error messages |
651 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
652 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
653 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
651 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
652 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
653 | + give_set_error($value['error_id'], $value['error_message']); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
@@ -666,42 +666,42 @@ discard block |
||
666 | 666 | * @since 1.0 |
667 | 667 | * @return integer |
668 | 668 | */ |
669 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
669 | +function give_register_and_login_new_user($user_data = array()) { |
|
670 | 670 | // Verify the array |
671 | - if ( empty( $user_data ) ) { |
|
672 | - return - 1; |
|
671 | + if (empty($user_data)) { |
|
672 | + return -1; |
|
673 | 673 | } |
674 | 674 | |
675 | - if ( give_get_errors() ) { |
|
676 | - return - 1; |
|
675 | + if (give_get_errors()) { |
|
676 | + return -1; |
|
677 | 677 | } |
678 | 678 | |
679 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
680 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
681 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
682 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
683 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
684 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
685 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
686 | - 'role' => get_option( 'default_role' ) |
|
687 | - ), $user_data ); |
|
679 | + $user_args = apply_filters('give_insert_user_args', array( |
|
680 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
681 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
682 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
683 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
684 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
685 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
686 | + 'role' => get_option('default_role') |
|
687 | + ), $user_data); |
|
688 | 688 | |
689 | 689 | // Insert new user |
690 | - $user_id = wp_insert_user( $user_args ); |
|
690 | + $user_id = wp_insert_user($user_args); |
|
691 | 691 | |
692 | 692 | // Validate inserted user |
693 | - if ( is_wp_error( $user_id ) ) { |
|
694 | - return - 1; |
|
693 | + if (is_wp_error($user_id)) { |
|
694 | + return -1; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | // Allow themes and plugins to filter the user data |
698 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
698 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
699 | 699 | |
700 | 700 | // Allow themes and plugins to hook |
701 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
701 | + do_action('give_insert_user', $user_id, $user_data); |
|
702 | 702 | |
703 | 703 | // Login new user |
704 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
704 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
705 | 705 | |
706 | 706 | // Return user id |
707 | 707 | return $user_id; |
@@ -716,26 +716,26 @@ discard block |
||
716 | 716 | * @since 1.0 |
717 | 717 | * @return array |
718 | 718 | */ |
719 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
719 | +function give_get_purchase_form_user($valid_data = array()) { |
|
720 | 720 | // Initialize user |
721 | 721 | $user = false; |
722 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
722 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
723 | 723 | |
724 | - if ( $is_ajax ) { |
|
724 | + if ($is_ajax) { |
|
725 | 725 | // Do not create or login the user during the ajax submission (check for errors only) |
726 | 726 | return true; |
727 | - } else if ( is_user_logged_in() ) { |
|
727 | + } else if (is_user_logged_in()) { |
|
728 | 728 | // Set the valid user as the logged in collected data |
729 | 729 | $user = $valid_data['logged_in_user']; |
730 | - } else if ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
730 | + } else if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
731 | 731 | // New user registration |
732 | - if ( $valid_data['need_new_user'] === true ) { |
|
732 | + if ($valid_data['need_new_user'] === true) { |
|
733 | 733 | // Set user |
734 | 734 | $user = $valid_data['new_user_data']; |
735 | 735 | // Register and login new user |
736 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
736 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
737 | 737 | // User login |
738 | - } else if ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
738 | + } else if ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
739 | 739 | |
740 | 740 | /* |
741 | 741 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -750,48 +750,48 @@ discard block |
||
750 | 750 | // Set user |
751 | 751 | $user = $valid_data['login_user_data']; |
752 | 752 | // Login user |
753 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
753 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
754 | 754 | } |
755 | 755 | } |
756 | 756 | |
757 | 757 | // Check guest checkout |
758 | - if ( false === $user && false === give_no_guest_checkout( $_POST['give-form-id'] ) ) { |
|
758 | + if (false === $user && false === give_no_guest_checkout($_POST['give-form-id'])) { |
|
759 | 759 | // Set user |
760 | 760 | $user = $valid_data['guest_user_data']; |
761 | 761 | } |
762 | 762 | |
763 | 763 | // Verify we have an user |
764 | - if ( false === $user || empty( $user ) ) { |
|
764 | + if (false === $user || empty($user)) { |
|
765 | 765 | // Return false |
766 | 766 | return false; |
767 | 767 | } |
768 | 768 | |
769 | 769 | // Get user first name |
770 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
771 | - $user['user_first'] = isset( $_POST["give_first"] ) ? strip_tags( trim( $_POST["give_first"] ) ) : ''; |
|
770 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
771 | + $user['user_first'] = isset($_POST["give_first"]) ? strip_tags(trim($_POST["give_first"])) : ''; |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | // Get user last name |
775 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
776 | - $user['user_last'] = isset( $_POST["give_last"] ) ? strip_tags( trim( $_POST["give_last"] ) ) : ''; |
|
775 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
776 | + $user['user_last'] = isset($_POST["give_last"]) ? strip_tags(trim($_POST["give_last"])) : ''; |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | // Get the user's billing address details |
780 | 780 | $user['address'] = array(); |
781 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
782 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
783 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
784 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
785 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
786 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
787 | - |
|
788 | - if ( empty( $user['address']['country'] ) ) { |
|
781 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
782 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
783 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
784 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
785 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
786 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
787 | + |
|
788 | + if (empty($user['address']['country'])) { |
|
789 | 789 | $user['address'] = false; |
790 | 790 | } // Country will always be set if address fields are present |
791 | 791 | |
792 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
792 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
793 | 793 | // Store the address in the user's meta so the cart can be pre-populated with it on return purchases |
794 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
794 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | // Return valid user |
@@ -810,16 +810,16 @@ discard block |
||
810 | 810 | $card_data = give_get_purchase_cc_info(); |
811 | 811 | |
812 | 812 | // Validate the card zip |
813 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
814 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
815 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid', 'give' ) ); |
|
813 | + if ( ! empty($card_data['card_zip'])) { |
|
814 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
815 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid', 'give')); |
|
816 | 816 | } |
817 | 817 | } |
818 | 818 | |
819 | 819 | //Ensure no spaces |
820 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
821 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); //no "+" signs |
|
822 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
820 | + if ( ! empty($card_data['card_number'])) { |
|
821 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); //no "+" signs |
|
822 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | // This should validate card numbers at some point too |
@@ -835,17 +835,17 @@ discard block |
||
835 | 835 | */ |
836 | 836 | function give_get_purchase_cc_info() { |
837 | 837 | $cc_info = array(); |
838 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
839 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
840 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
841 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
842 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
843 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
844 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
845 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
846 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
847 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
848 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
838 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
839 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
840 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
841 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
842 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
843 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
844 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
845 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
846 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
847 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
848 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
849 | 849 | |
850 | 850 | // Return cc info |
851 | 851 | return $cc_info; |
@@ -861,14 +861,14 @@ discard block |
||
861 | 861 | * |
862 | 862 | * @return bool|mixed|void |
863 | 863 | */ |
864 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
864 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
865 | 865 | $ret = false; |
866 | 866 | |
867 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
867 | + if (empty($zip) || empty($country_code)) { |
|
868 | 868 | return $ret; |
869 | 869 | } |
870 | 870 | |
871 | - $country_code = strtoupper( $country_code ); |
|
871 | + $country_code = strtoupper($country_code); |
|
872 | 872 | |
873 | 873 | $zip_regex = array( |
874 | 874 | "AD" => "AD\d{3}", |
@@ -1028,11 +1028,11 @@ discard block |
||
1028 | 1028 | "ZM" => "\d{5}" |
1029 | 1029 | ); |
1030 | 1030 | |
1031 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
1031 | + if ( ! isset ($zip_regex[$country_code]) || preg_match("/".$zip_regex[$country_code]."/i", $zip)) { |
|
1032 | 1032 | $ret = true; |
1033 | 1033 | } |
1034 | 1034 | |
1035 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1035 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | |
@@ -1042,48 +1042,48 @@ discard block |
||
1042 | 1042 | * @since 1.0 |
1043 | 1043 | * @return void |
1044 | 1044 | */ |
1045 | -function give_check_purchase_email( $valid_data, $posted ) { |
|
1045 | +function give_check_purchase_email($valid_data, $posted) { |
|
1046 | 1046 | $is_banned = false; |
1047 | 1047 | $banned = give_get_banned_emails(); |
1048 | 1048 | |
1049 | - if ( empty( $banned ) ) { |
|
1049 | + if (empty($banned)) { |
|
1050 | 1050 | return; |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - if ( is_user_logged_in() ) { |
|
1053 | + if (is_user_logged_in()) { |
|
1054 | 1054 | |
1055 | 1055 | // The user is logged in, check that their account email is not banned |
1056 | - $user_data = get_userdata( get_current_user_id() ); |
|
1057 | - if ( give_is_email_banned( $user_data->user_email ) ) { |
|
1056 | + $user_data = get_userdata(get_current_user_id()); |
|
1057 | + if (give_is_email_banned($user_data->user_email)) { |
|
1058 | 1058 | |
1059 | 1059 | $is_banned = true; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
1062 | + if (give_is_email_banned($posted['give_email'])) { |
|
1063 | 1063 | $is_banned = true; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - } elseif ( isset( $posted['give-purchase-var'] ) && $posted['give-purchase-var'] == 'needs-to-login' ) { |
|
1066 | + } elseif (isset($posted['give-purchase-var']) && $posted['give-purchase-var'] == 'needs-to-login') { |
|
1067 | 1067 | |
1068 | 1068 | // The user is logging in, check that their email is not banned |
1069 | - $user_data = get_user_by( 'login', $posted['give_user_login'] ); |
|
1070 | - if ( $user_data && give_is_email_banned( $user_data->user_email ) ) { |
|
1069 | + $user_data = get_user_by('login', $posted['give_user_login']); |
|
1070 | + if ($user_data && give_is_email_banned($user_data->user_email)) { |
|
1071 | 1071 | $is_banned = true; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | } else { |
1075 | 1075 | |
1076 | 1076 | // Guest purchase, check that the email is not banned |
1077 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
1077 | + if (give_is_email_banned($posted['give_email'])) { |
|
1078 | 1078 | $is_banned = true; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - if ( $is_banned ) { |
|
1083 | + if ($is_banned) { |
|
1084 | 1084 | // Set an error and give the donor a general error (don't alert them that they were banned) |
1085 | - give_set_error( 'email_banned', __( 'An internal error has occurred, please try again or contact support.', 'give' ) ); |
|
1085 | + give_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'give')); |
|
1086 | 1086 | } |
1087 | 1087 | } |
1088 | 1088 | |
1089 | -add_action( 'give_checkout_error_checks', 'give_check_purchase_email', 10, 2 ); |
|
1089 | +add_action('give_checkout_error_checks', 'give_check_purchase_email', 10, 2); |