@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | // Exit if accessed directly |
16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
16 | +if ( ! defined('ABSPATH')) { |
|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 | |
@@ -25,18 +25,18 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_show_upgrade_notices() { |
27 | 27 | |
28 | - if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-upgrades' ) { |
|
28 | + if (isset($_GET['page']) && $_GET['page'] == 'give-upgrades') { |
|
29 | 29 | return; |
30 | 30 | } // Don't show notices on the upgrades page |
31 | 31 | |
32 | - $give_version = get_option( 'give_version' ); |
|
32 | + $give_version = get_option('give_version'); |
|
33 | 33 | |
34 | - if ( ! $give_version ) { |
|
34 | + if ( ! $give_version) { |
|
35 | 35 | // 1.0 is the first version to use this option so we must add it |
36 | 36 | $give_version = '1.0'; |
37 | 37 | } |
38 | 38 | |
39 | - $give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
|
39 | + $give_version = preg_replace('/[^0-9.].*/', '', $give_version); |
|
40 | 40 | |
41 | 41 | /* |
42 | 42 | * NOTICE: |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | */ |
48 | 48 | |
49 | 49 | //v1.3.2 Upgrades |
50 | - if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) { |
|
50 | + if (version_compare($give_version, '1.3.2', '<') || ! give_has_upgrade_completed('upgrade_give_payment_customer_id')) { |
|
51 | 51 | printf( |
52 | - '<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>', |
|
53 | - esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) ) |
|
52 | + '<div class="updated"><p>'.__('Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>', |
|
53 | + esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id')) |
|
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | //v1.3.4 Upgrades //ensure the user has gone through 1.3.4 |
58 | - if ( version_compare( $give_version, '1.3.4', '<' ) || ( ! give_has_upgrade_completed( 'upgrade_give_offline_status' ) && give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) ) { |
|
58 | + if (version_compare($give_version, '1.3.4', '<') || ( ! give_has_upgrade_completed('upgrade_give_offline_status') && give_has_upgrade_completed('upgrade_give_payment_customer_id'))) { |
|
59 | 59 | printf( |
60 | - '<div class="updated"><p>' . __( 'Give needs to upgrade the transaction database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>', |
|
61 | - esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) ) |
|
60 | + '<div class="updated"><p>'.__('Give needs to upgrade the transaction database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>', |
|
61 | + esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status')) |
|
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | } |
70 | 70 | |
71 | -add_action( 'admin_notices', 'give_show_upgrade_notices' ); |
|
71 | +add_action('admin_notices', 'give_show_upgrade_notices'); |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Triggers all upgrade functions |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function give_trigger_upgrades() { |
82 | 82 | |
83 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
84 | - wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
83 | + if ( ! current_user_can('manage_give_settings')) { |
|
84 | + wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
85 | 85 | } |
86 | 86 | |
87 | - $give_version = get_option( 'give_version' ); |
|
87 | + $give_version = get_option('give_version'); |
|
88 | 88 | |
89 | - if ( ! $give_version ) { |
|
89 | + if ( ! $give_version) { |
|
90 | 90 | // 1.0 is the first version to use this option so we must add it |
91 | 91 | $give_version = '1.0'; |
92 | - add_option( 'give_version', $give_version ); |
|
92 | + add_option('give_version', $give_version); |
|
93 | 93 | } |
94 | 94 | |
95 | - update_option( 'give_version', GIVE_VERSION ); |
|
95 | + update_option('give_version', GIVE_VERSION); |
|
96 | 96 | |
97 | - if ( DOING_AJAX ) { |
|
98 | - die( 'complete' ); |
|
97 | + if (DOING_AJAX) { |
|
98 | + die('complete'); |
|
99 | 99 | } // Let AJAX know that the upgrade is complete |
100 | 100 | } |
101 | 101 | |
102 | -add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' ); |
|
102 | +add_action('wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades'); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Check if the upgrade routine has been run for a specific action |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return bool If the action has been added to the completed actions array |
112 | 112 | */ |
113 | -function give_has_upgrade_completed( $upgrade_action = '' ) { |
|
113 | +function give_has_upgrade_completed($upgrade_action = '') { |
|
114 | 114 | |
115 | - if ( empty( $upgrade_action ) ) { |
|
115 | + if (empty($upgrade_action)) { |
|
116 | 116 | return false; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $completed_upgrades = give_get_completed_upgrades(); |
120 | 120 | |
121 | - return in_array( $upgrade_action, $completed_upgrades ); |
|
121 | + return in_array($upgrade_action, $completed_upgrades); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return bool If the function was successfully added |
133 | 133 | */ |
134 | -function give_set_upgrade_complete( $upgrade_action = '' ) { |
|
134 | +function give_set_upgrade_complete($upgrade_action = '') { |
|
135 | 135 | |
136 | - if ( empty( $upgrade_action ) ) { |
|
136 | + if (empty($upgrade_action)) { |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | $completed_upgrades[] = $upgrade_action; |
142 | 142 | |
143 | 143 | // Remove any blanks, and only show uniques |
144 | - $completed_upgrades = array_unique( array_values( $completed_upgrades ) ); |
|
144 | + $completed_upgrades = array_unique(array_values($completed_upgrades)); |
|
145 | 145 | |
146 | - return update_option( 'give_completed_upgrades', $completed_upgrades ); |
|
146 | + return update_option('give_completed_upgrades', $completed_upgrades); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | */ |
155 | 155 | function give_get_completed_upgrades() { |
156 | 156 | |
157 | - $completed_upgrades = get_option( 'give_completed_upgrades' ); |
|
157 | + $completed_upgrades = get_option('give_completed_upgrades'); |
|
158 | 158 | |
159 | - if ( false === $completed_upgrades ) { |
|
159 | + if (false === $completed_upgrades) { |
|
160 | 160 | $completed_upgrades = array(); |
161 | 161 | } |
162 | 162 | |
@@ -175,30 +175,30 @@ discard block |
||
175 | 175 | */ |
176 | 176 | function give_v132_upgrade_give_payment_customer_id() { |
177 | 177 | global $wpdb; |
178 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
179 | - wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
178 | + if ( ! current_user_can('manage_give_settings')) { |
|
179 | + wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
180 | 180 | } |
181 | 181 | |
182 | - ignore_user_abort( true ); |
|
182 | + ignore_user_abort(true); |
|
183 | 183 | |
184 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
185 | - @set_time_limit( 0 ); |
|
184 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
185 | + @set_time_limit(0); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | //UPDATE DB METAKEYS |
189 | 189 | $sql = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'"; |
190 | - $query = $wpdb->query( $sql ); |
|
190 | + $query = $wpdb->query($sql); |
|
191 | 191 | |
192 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
193 | - give_set_upgrade_complete( 'upgrade_give_payment_customer_id' ); |
|
194 | - delete_option( 'give_doing_upgrade' ); |
|
195 | - wp_redirect( admin_url() ); |
|
192 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
193 | + give_set_upgrade_complete('upgrade_give_payment_customer_id'); |
|
194 | + delete_option('give_doing_upgrade'); |
|
195 | + wp_redirect(admin_url()); |
|
196 | 196 | exit; |
197 | 197 | |
198 | 198 | |
199 | 199 | } |
200 | 200 | |
201 | -add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' ); |
|
201 | +add_action('give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id'); |
|
202 | 202 | |
203 | 203 | /** |
204 | 204 | * Upgrades the Offline Status |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | |
213 | 213 | global $wpdb; |
214 | 214 | |
215 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
216 | - wp_die( __( 'You do not have permission to do Give upgrades.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
215 | + if ( ! current_user_can('manage_give_settings')) { |
|
216 | + wp_die(__('You do not have permission to do Give upgrades.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
217 | 217 | } |
218 | 218 | |
219 | - ignore_user_abort( true ); |
|
219 | + ignore_user_abort(true); |
|
220 | 220 | |
221 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
222 | - @set_time_limit( 0 ); |
|
221 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
222 | + @set_time_limit(0); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Get abandoned offline payments |
@@ -229,35 +229,35 @@ discard block |
||
229 | 229 | $where .= "AND ( p.post_status = 'abandoned' )"; |
230 | 230 | $where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; |
231 | 231 | |
232 | - $sql = $select . $join . $where; |
|
233 | - $found_payments = $wpdb->get_col( $sql ); |
|
232 | + $sql = $select.$join.$where; |
|
233 | + $found_payments = $wpdb->get_col($sql); |
|
234 | 234 | |
235 | 235 | |
236 | - foreach ( $found_payments as $payment ) { |
|
236 | + foreach ($found_payments as $payment) { |
|
237 | 237 | |
238 | 238 | //Only change ones marked abandoned since our release last week |
239 | 239 | //because the admin may have marked some abandoned themselves |
240 | - $modified_time = get_post_modified_time( 'U', false, $payment ); |
|
240 | + $modified_time = get_post_modified_time('U', false, $payment); |
|
241 | 241 | |
242 | 242 | //1450124863 = 12/10/2015 20:42:25 |
243 | - if ( $modified_time >= 1450124863 ) { |
|
243 | + if ($modified_time >= 1450124863) { |
|
244 | 244 | |
245 | - give_update_payment_status( $payment, 'pending' ); |
|
245 | + give_update_payment_status($payment, 'pending'); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
252 | - give_set_upgrade_complete( 'upgrade_give_offline_status' ); |
|
253 | - delete_option( 'give_doing_upgrade' ); |
|
254 | - wp_redirect( admin_url() ); |
|
251 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
252 | + give_set_upgrade_complete('upgrade_give_offline_status'); |
|
253 | + delete_option('give_doing_upgrade'); |
|
254 | + wp_redirect(admin_url()); |
|
255 | 255 | exit; |
256 | 256 | |
257 | 257 | |
258 | 258 | } |
259 | 259 | |
260 | -add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' ); |
|
260 | +add_action('give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status'); |
|
261 | 261 | |
262 | 262 | |
263 | 263 | /** |
@@ -269,17 +269,17 @@ discard block |
||
269 | 269 | */ |
270 | 270 | function give_v152_cleanup_users() { |
271 | 271 | |
272 | - $give_version = get_option( 'give_version' ); |
|
272 | + $give_version = get_option('give_version'); |
|
273 | 273 | |
274 | - if ( ! $give_version ) { |
|
274 | + if ( ! $give_version) { |
|
275 | 275 | // 1.0 is the first version to use this option so we must add it |
276 | 276 | $give_version = '1.0'; |
277 | 277 | } |
278 | 278 | |
279 | - $give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
|
279 | + $give_version = preg_replace('/[^0-9.].*/', '', $give_version); |
|
280 | 280 | |
281 | 281 | //v1.5.2 Upgrades |
282 | - if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) { |
|
282 | + if (version_compare($give_version, '1.5.2', '<') || ! give_has_upgrade_completed('upgrade_give_user_caps_cleanup')) { |
|
283 | 283 | |
284 | 284 | //Delete all caps with "ss" |
285 | 285 | //Also delete all unused "campaign" roles |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | ); |
327 | 327 | |
328 | 328 | global $wp_roles; |
329 | - foreach ( $delete_caps as $cap ) { |
|
330 | - foreach ( array_keys( $wp_roles->roles ) as $role ) { |
|
331 | - $wp_roles->remove_cap( $role, $cap ); |
|
329 | + foreach ($delete_caps as $cap) { |
|
330 | + foreach (array_keys($wp_roles->roles) as $role) { |
|
331 | + $wp_roles->remove_cap($role, $cap); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | $roles->add_caps(); |
339 | 339 | |
340 | 340 | //The Update Ran |
341 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
342 | - give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' ); |
|
343 | - delete_option( 'give_doing_upgrade' ); |
|
341 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
342 | + give_set_upgrade_complete('upgrade_give_user_caps_cleanup'); |
|
343 | + delete_option('give_doing_upgrade'); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
347 | 347 | } |
348 | 348 | |
349 | -add_action( 'admin_init', 'give_v152_cleanup_users' ); |
|
350 | 349 | \ No newline at end of file |
350 | +add_action('admin_init', 'give_v152_cleanup_users'); |
|
351 | 351 | \ 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 | |
@@ -23,17 +23,17 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return void |
25 | 25 | */ |
26 | -function give_trigger_donation_receipt( $payment_id ) { |
|
26 | +function give_trigger_donation_receipt($payment_id) { |
|
27 | 27 | // Make sure we don't send a purchase receipt while editing a payment |
28 | - if ( isset( $_POST['give-action'] ) && 'edit_payment' == $_POST['give-action'] ) { |
|
28 | + if (isset($_POST['give-action']) && 'edit_payment' == $_POST['give-action']) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | 32 | // Send email |
33 | - give_email_donation_receipt( $payment_id ); |
|
33 | + give_email_donation_receipt($payment_id); |
|
34 | 34 | } |
35 | 35 | |
36 | -add_action( 'give_complete_purchase', 'give_trigger_donation_receipt', 999, 1 ); |
|
36 | +add_action('give_complete_purchase', 'give_trigger_donation_receipt', 999, 1); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Resend the Email Purchase Receipt. (This can be done from the Payment History page) |
@@ -44,29 +44,29 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return void |
46 | 46 | */ |
47 | -function give_resend_donation_receipt( $data ) { |
|
47 | +function give_resend_donation_receipt($data) { |
|
48 | 48 | |
49 | - $purchase_id = absint( $data['purchase_id'] ); |
|
49 | + $purchase_id = absint($data['purchase_id']); |
|
50 | 50 | |
51 | - if ( empty( $purchase_id ) ) { |
|
51 | + if (empty($purchase_id)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | - if ( ! current_user_can( 'edit_give_payments', $purchase_id ) ) { |
|
56 | - wp_die( __( 'You do not have permission to edit payment records.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
55 | + if ( ! current_user_can('edit_give_payments', $purchase_id)) { |
|
56 | + wp_die(__('You do not have permission to edit payment records.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
57 | 57 | } |
58 | 58 | |
59 | - give_email_donation_receipt( $purchase_id, false ); |
|
59 | + give_email_donation_receipt($purchase_id, false); |
|
60 | 60 | |
61 | - wp_redirect( add_query_arg( array( |
|
61 | + wp_redirect(add_query_arg(array( |
|
62 | 62 | 'give-message' => 'email_sent', |
63 | 63 | 'give-action' => false, |
64 | 64 | 'purchase_id' => false |
65 | - ) ) ); |
|
65 | + ))); |
|
66 | 66 | exit; |
67 | 67 | } |
68 | 68 | |
69 | -add_action( 'give_email_links', 'give_resend_donation_receipt' ); |
|
69 | +add_action('give_email_links', 'give_resend_donation_receipt'); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Trigger the sending of a Test Email |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return void |
79 | 79 | */ |
80 | -function give_send_test_email( $data ) { |
|
81 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give-test-email' ) ) { |
|
80 | +function give_send_test_email($data) { |
|
81 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give-test-email')) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | give_email_test_donation_receipt(); |
87 | 87 | |
88 | 88 | // Remove the test email query arg |
89 | - wp_redirect( remove_query_arg( 'give_action' ) ); |
|
89 | + wp_redirect(remove_query_arg('give_action')); |
|
90 | 90 | exit; |
91 | 91 | } |
92 | 92 | |
93 | -add_action( 'give_send_test_email', 'give_send_test_email' ); |
|
93 | +add_action('give_send_test_email', 'give_send_test_email'); |
@@ -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 | |
@@ -97,29 +97,29 @@ discard block |
||
97 | 97 | * @param bool $_id_or_email |
98 | 98 | * @param bool $by_user_id |
99 | 99 | */ |
100 | - public function __construct( $_id_or_email = false, $by_user_id = false ) { |
|
100 | + public function __construct($_id_or_email = false, $by_user_id = false) { |
|
101 | 101 | |
102 | 102 | $this->db = new Give_DB_Customers; |
103 | 103 | |
104 | - if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) ) ) { |
|
104 | + if (false === $_id_or_email || (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | - $by_user_id = is_bool( $by_user_id ) ? $by_user_id : false; |
|
108 | + $by_user_id = is_bool($by_user_id) ? $by_user_id : false; |
|
109 | 109 | |
110 | - if ( is_numeric( $_id_or_email ) ) { |
|
110 | + if (is_numeric($_id_or_email)) { |
|
111 | 111 | $field = $by_user_id ? 'user_id' : 'id'; |
112 | 112 | } else { |
113 | 113 | $field = 'email'; |
114 | 114 | } |
115 | 115 | |
116 | - $customer = $this->db->get_customer_by( $field, $_id_or_email ); |
|
116 | + $customer = $this->db->get_customer_by($field, $_id_or_email); |
|
117 | 117 | |
118 | - if ( empty( $customer ) || ! is_object( $customer ) ) { |
|
118 | + if (empty($customer) || ! is_object($customer)) { |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | - $this->setup_customer( $customer ); |
|
122 | + $this->setup_customer($customer); |
|
123 | 123 | |
124 | 124 | } |
125 | 125 | |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return bool If the setup was successful or not |
134 | 134 | */ |
135 | - private function setup_customer( $customer ) { |
|
135 | + private function setup_customer($customer) { |
|
136 | 136 | |
137 | - if ( ! is_object( $customer ) ) { |
|
137 | + if ( ! is_object($customer)) { |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | |
141 | - foreach ( $customer as $key => $value ) { |
|
141 | + foreach ($customer as $key => $value) { |
|
142 | 142 | |
143 | - switch ( $key ) { |
|
143 | + switch ($key) { |
|
144 | 144 | |
145 | 145 | case 'notes': |
146 | 146 | $this->$key = $this->get_notes(); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | // Customer ID and email are the only things that are necessary, make sure they exist |
158 | - if ( ! empty( $this->id ) && ! empty( $this->email ) ) { |
|
158 | + if ( ! empty($this->id) && ! empty($this->email)) { |
|
159 | 159 | return true; |
160 | 160 | } |
161 | 161 | |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @since 1.0 |
170 | 170 | */ |
171 | - public function __get( $key ) { |
|
171 | + public function __get($key) { |
|
172 | 172 | |
173 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
173 | + if (method_exists($this, 'get_'.$key)) { |
|
174 | 174 | |
175 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
175 | + return call_user_func(array($this, 'get_'.$key)); |
|
176 | 176 | |
177 | 177 | } else { |
178 | 178 | |
179 | - return new WP_Error( 'give-customer-invalid-property', sprintf( __( 'Can\'t get property %s.', 'give' ), $key ) ); |
|
179 | + return new WP_Error('give-customer-invalid-property', sprintf(__('Can\'t get property %s.', 'give'), $key)); |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return mixed False if not a valid creation, Customer ID if user is found or valid creation |
193 | 193 | */ |
194 | - public function create( $data = array() ) { |
|
194 | + public function create($data = array()) { |
|
195 | 195 | |
196 | - if ( $this->id != 0 || empty( $data ) ) { |
|
196 | + if ($this->id != 0 || empty($data)) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
@@ -201,34 +201,34 @@ discard block |
||
201 | 201 | 'payment_ids' => '' |
202 | 202 | ); |
203 | 203 | |
204 | - $args = wp_parse_args( $data, $defaults ); |
|
205 | - $args = $this->sanitize_columns( $args ); |
|
204 | + $args = wp_parse_args($data, $defaults); |
|
205 | + $args = $this->sanitize_columns($args); |
|
206 | 206 | |
207 | - if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) { |
|
207 | + if (empty($args['email']) || ! is_email($args['email'])) { |
|
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | |
211 | - if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) { |
|
212 | - $args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) ); |
|
211 | + if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) { |
|
212 | + $args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids']))); |
|
213 | 213 | } |
214 | 214 | |
215 | - do_action( 'give_customer_pre_create', $args ); |
|
215 | + do_action('give_customer_pre_create', $args); |
|
216 | 216 | |
217 | 217 | $created = false; |
218 | 218 | |
219 | 219 | // The DB class 'add' implies an update if the customer being asked to be created already exists |
220 | - if ( $this->db->add( $data ) ) { |
|
220 | + if ($this->db->add($data)) { |
|
221 | 221 | |
222 | 222 | // We've successfully added/updated the customer, reset the class vars with the new data |
223 | - $customer = $this->db->get_customer_by( 'email', $args['email'] ); |
|
223 | + $customer = $this->db->get_customer_by('email', $args['email']); |
|
224 | 224 | |
225 | 225 | // Setup the customer data with the values from DB |
226 | - $this->setup_customer( $customer ); |
|
226 | + $this->setup_customer($customer); |
|
227 | 227 | |
228 | 228 | $created = $this->id; |
229 | 229 | } |
230 | 230 | |
231 | - do_action( 'give_customer_post_create', $created, $args ); |
|
231 | + do_action('give_customer_post_create', $created, $args); |
|
232 | 232 | |
233 | 233 | return $created; |
234 | 234 | |
@@ -243,27 +243,27 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @return bool If the update was successful or not |
245 | 245 | */ |
246 | - public function update( $data = array() ) { |
|
246 | + public function update($data = array()) { |
|
247 | 247 | |
248 | - if ( empty( $data ) ) { |
|
248 | + if (empty($data)) { |
|
249 | 249 | return false; |
250 | 250 | } |
251 | 251 | |
252 | - $data = $this->sanitize_columns( $data ); |
|
252 | + $data = $this->sanitize_columns($data); |
|
253 | 253 | |
254 | - do_action( 'give_customer_pre_update', $this->id, $data ); |
|
254 | + do_action('give_customer_pre_update', $this->id, $data); |
|
255 | 255 | |
256 | 256 | $updated = false; |
257 | 257 | |
258 | - if ( $this->db->update( $this->id, $data ) ) { |
|
258 | + if ($this->db->update($this->id, $data)) { |
|
259 | 259 | |
260 | - $customer = $this->db->get_customer_by( 'id', $this->id ); |
|
261 | - $this->setup_customer( $customer ); |
|
260 | + $customer = $this->db->get_customer_by('id', $this->id); |
|
261 | + $this->setup_customer($customer); |
|
262 | 262 | |
263 | 263 | $updated = true; |
264 | 264 | } |
265 | 265 | |
266 | - do_action( 'give_customer_post_update', $updated, $this->id, $data ); |
|
266 | + do_action('give_customer_post_update', $updated, $this->id, $data); |
|
267 | 267 | |
268 | 268 | return $updated; |
269 | 269 | } |
@@ -279,44 +279,44 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return bool If the attachment was successfuly |
281 | 281 | */ |
282 | - public function attach_payment( $payment_id = 0, $update_stats = true ) { |
|
282 | + public function attach_payment($payment_id = 0, $update_stats = true) { |
|
283 | 283 | |
284 | - if ( empty( $payment_id ) ) { |
|
284 | + if (empty($payment_id)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - if ( empty( $this->payment_ids ) ) { |
|
288 | + if (empty($this->payment_ids)) { |
|
289 | 289 | |
290 | 290 | $new_payment_ids = $payment_id; |
291 | 291 | |
292 | 292 | } else { |
293 | 293 | |
294 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
294 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
295 | 295 | |
296 | - if ( in_array( $payment_id, $payment_ids ) ) { |
|
296 | + if (in_array($payment_id, $payment_ids)) { |
|
297 | 297 | $update_stats = false; |
298 | 298 | } |
299 | 299 | |
300 | 300 | $payment_ids[] = $payment_id; |
301 | 301 | |
302 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
302 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | - do_action( 'give_customer_pre_attach_payment', $payment_id, $this->id ); |
|
306 | + do_action('give_customer_pre_attach_payment', $payment_id, $this->id); |
|
307 | 307 | |
308 | - $payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
308 | + $payment_added = $this->update(array('payment_ids' => $new_payment_ids)); |
|
309 | 309 | |
310 | - if ( $payment_added ) { |
|
310 | + if ($payment_added) { |
|
311 | 311 | |
312 | 312 | $this->payment_ids = $new_payment_ids; |
313 | 313 | |
314 | 314 | // We added this payment successfully, increment the stats |
315 | - if ( $update_stats ) { |
|
316 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
315 | + if ($update_stats) { |
|
316 | + $payment_amount = give_get_payment_amount($payment_id); |
|
317 | 317 | |
318 | - if ( ! empty( $payment_amount ) ) { |
|
319 | - $this->increase_value( $payment_amount ); |
|
318 | + if ( ! empty($payment_amount)) { |
|
319 | + $this->increase_value($payment_amount); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | $this->increase_purchase_count(); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | |
325 | 325 | } |
326 | 326 | |
327 | - do_action( 'give_customer_post_attach_payment', $payment_added, $payment_id, $this->id ); |
|
327 | + do_action('give_customer_post_attach_payment', $payment_added, $payment_id, $this->id); |
|
328 | 328 | |
329 | 329 | return $payment_added; |
330 | 330 | } |
@@ -340,50 +340,50 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @return boolean If the removal was successful |
342 | 342 | */ |
343 | - public function remove_payment( $payment_id = 0, $update_stats = true ) { |
|
343 | + public function remove_payment($payment_id = 0, $update_stats = true) { |
|
344 | 344 | |
345 | - if ( empty( $payment_id ) ) { |
|
345 | + if (empty($payment_id)) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - $payment = new Give_Payment( $payment_id ); |
|
349 | + $payment = new Give_Payment($payment_id); |
|
350 | 350 | |
351 | - if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) { |
|
351 | + if ('publish' !== $payment->status && 'revoked' !== $payment->status) { |
|
352 | 352 | $update_stats = false; |
353 | 353 | } |
354 | 354 | |
355 | 355 | $new_payment_ids = ''; |
356 | 356 | |
357 | - if ( ! empty( $this->payment_ids ) ) { |
|
357 | + if ( ! empty($this->payment_ids)) { |
|
358 | 358 | |
359 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
359 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
360 | 360 | |
361 | - $pos = array_search( $payment_id, $payment_ids ); |
|
362 | - if ( false === $pos ) { |
|
361 | + $pos = array_search($payment_id, $payment_ids); |
|
362 | + if (false === $pos) { |
|
363 | 363 | return false; |
364 | 364 | } |
365 | 365 | |
366 | - unset( $payment_ids[ $pos ] ); |
|
367 | - $payment_ids = array_filter( $payment_ids ); |
|
366 | + unset($payment_ids[$pos]); |
|
367 | + $payment_ids = array_filter($payment_ids); |
|
368 | 368 | |
369 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
369 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | - do_action( 'give_customer_pre_remove_payment', $payment_id, $this->id ); |
|
373 | + do_action('give_customer_pre_remove_payment', $payment_id, $this->id); |
|
374 | 374 | |
375 | - $payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
375 | + $payment_removed = $this->update(array('payment_ids' => $new_payment_ids)); |
|
376 | 376 | |
377 | - if ( $payment_removed ) { |
|
377 | + if ($payment_removed) { |
|
378 | 378 | |
379 | 379 | $this->payment_ids = $new_payment_ids; |
380 | 380 | |
381 | - if ( $update_stats ) { |
|
381 | + if ($update_stats) { |
|
382 | 382 | // We removed this payment successfully, decrement the stats |
383 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
383 | + $payment_amount = give_get_payment_amount($payment_id); |
|
384 | 384 | |
385 | - if ( ! empty( $payment_amount ) ) { |
|
386 | - $this->decrease_value( $payment_amount ); |
|
385 | + if ( ! empty($payment_amount)) { |
|
386 | + $this->decrease_value($payment_amount); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | $this->decrease_purchase_count(); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | |
392 | 392 | } |
393 | 393 | |
394 | - do_action( 'give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id ); |
|
394 | + do_action('give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id); |
|
395 | 395 | |
396 | 396 | return $payment_removed; |
397 | 397 | |
@@ -406,22 +406,22 @@ discard block |
||
406 | 406 | * |
407 | 407 | * @return int The purchase count |
408 | 408 | */ |
409 | - public function increase_purchase_count( $count = 1 ) { |
|
409 | + public function increase_purchase_count($count = 1) { |
|
410 | 410 | |
411 | 411 | // Make sure it's numeric and not negative |
412 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
412 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
413 | 413 | return false; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $new_total = (int) $this->purchase_count + (int) $count; |
417 | 417 | |
418 | - do_action( 'give_customer_pre_increase_purchase_count', $count, $this->id ); |
|
418 | + do_action('give_customer_pre_increase_purchase_count', $count, $this->id); |
|
419 | 419 | |
420 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
420 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
421 | 421 | $this->purchase_count = $new_total; |
422 | 422 | } |
423 | 423 | |
424 | - do_action( 'give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id ); |
|
424 | + do_action('give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id); |
|
425 | 425 | |
426 | 426 | return $this->purchase_count; |
427 | 427 | } |
@@ -435,26 +435,26 @@ discard block |
||
435 | 435 | * |
436 | 436 | * @return mixed If successful, the new count, otherwise false |
437 | 437 | */ |
438 | - public function decrease_purchase_count( $count = 1 ) { |
|
438 | + public function decrease_purchase_count($count = 1) { |
|
439 | 439 | |
440 | 440 | // Make sure it's numeric and not negative |
441 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
441 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
442 | 442 | return false; |
443 | 443 | } |
444 | 444 | |
445 | 445 | $new_total = (int) $this->purchase_count - (int) $count; |
446 | 446 | |
447 | - if ( $new_total < 0 ) { |
|
447 | + if ($new_total < 0) { |
|
448 | 448 | $new_total = 0; |
449 | 449 | } |
450 | 450 | |
451 | - do_action( 'give_customer_pre_decrease_purchase_count', $count, $this->id ); |
|
451 | + do_action('give_customer_pre_decrease_purchase_count', $count, $this->id); |
|
452 | 452 | |
453 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
453 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
454 | 454 | $this->purchase_count = $new_total; |
455 | 455 | } |
456 | 456 | |
457 | - do_action( 'give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id ); |
|
457 | + do_action('give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id); |
|
458 | 458 | |
459 | 459 | return $this->purchase_count; |
460 | 460 | } |
@@ -468,17 +468,17 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @return mixed If successful, the new value, otherwise false |
470 | 470 | */ |
471 | - public function increase_value( $value = 0.00 ) { |
|
471 | + public function increase_value($value = 0.00) { |
|
472 | 472 | |
473 | - $new_value = floatval( $this->purchase_value ) + $value; |
|
473 | + $new_value = floatval($this->purchase_value) + $value; |
|
474 | 474 | |
475 | - do_action( 'give_customer_pre_increase_value', $value, $this->id ); |
|
475 | + do_action('give_customer_pre_increase_value', $value, $this->id); |
|
476 | 476 | |
477 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
477 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
478 | 478 | $this->purchase_value = $new_value; |
479 | 479 | } |
480 | 480 | |
481 | - do_action( 'give_customer_post_increase_value', $this->purchase_value, $value, $this->id ); |
|
481 | + do_action('give_customer_post_increase_value', $this->purchase_value, $value, $this->id); |
|
482 | 482 | |
483 | 483 | return $this->purchase_value; |
484 | 484 | } |
@@ -492,21 +492,21 @@ discard block |
||
492 | 492 | * |
493 | 493 | * @return mixed If successful, the new value, otherwise false |
494 | 494 | */ |
495 | - public function decrease_value( $value = 0.00 ) { |
|
495 | + public function decrease_value($value = 0.00) { |
|
496 | 496 | |
497 | - $new_value = floatval( $this->purchase_value ) - $value; |
|
497 | + $new_value = floatval($this->purchase_value) - $value; |
|
498 | 498 | |
499 | - if ( $new_value < 0 ) { |
|
499 | + if ($new_value < 0) { |
|
500 | 500 | $new_value = 0.00; |
501 | 501 | } |
502 | 502 | |
503 | - do_action( 'give_customer_pre_decrease_value', $value, $this->id ); |
|
503 | + do_action('give_customer_pre_decrease_value', $value, $this->id); |
|
504 | 504 | |
505 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
505 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
506 | 506 | $this->purchase_value = $new_value; |
507 | 507 | } |
508 | 508 | |
509 | - do_action( 'give_customer_post_decrease_value', $this->purchase_value, $value, $this->id ); |
|
509 | + do_action('give_customer_post_decrease_value', $this->purchase_value, $value, $this->id); |
|
510 | 510 | |
511 | 511 | return $this->purchase_value; |
512 | 512 | } |
@@ -521,15 +521,15 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @return array The notes requsted |
523 | 523 | */ |
524 | - public function get_notes( $length = 20, $paged = 1 ) { |
|
524 | + public function get_notes($length = 20, $paged = 1) { |
|
525 | 525 | |
526 | - $length = is_numeric( $length ) ? $length : 20; |
|
527 | - $offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0; |
|
526 | + $length = is_numeric($length) ? $length : 20; |
|
527 | + $offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0; |
|
528 | 528 | |
529 | 529 | $all_notes = $this->get_raw_notes(); |
530 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
530 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
531 | 531 | |
532 | - $desired_notes = array_slice( $notes_array, $offset, $length ); |
|
532 | + $desired_notes = array_slice($notes_array, $offset, $length); |
|
533 | 533 | |
534 | 534 | return $desired_notes; |
535 | 535 | |
@@ -544,9 +544,9 @@ discard block |
||
544 | 544 | public function get_notes_count() { |
545 | 545 | |
546 | 546 | $all_notes = $this->get_raw_notes(); |
547 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
547 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
548 | 548 | |
549 | - return count( $notes_array ); |
|
549 | + return count($notes_array); |
|
550 | 550 | |
551 | 551 | } |
552 | 552 | |
@@ -559,32 +559,32 @@ discard block |
||
559 | 559 | * |
560 | 560 | * @return string|boolean The new note if added succesfully, false otherwise |
561 | 561 | */ |
562 | - public function add_note( $note = '' ) { |
|
562 | + public function add_note($note = '') { |
|
563 | 563 | |
564 | - $note = trim( $note ); |
|
565 | - if ( empty( $note ) ) { |
|
564 | + $note = trim($note); |
|
565 | + if (empty($note)) { |
|
566 | 566 | return false; |
567 | 567 | } |
568 | 568 | |
569 | 569 | $notes = $this->get_raw_notes(); |
570 | 570 | |
571 | - if ( empty( $notes ) ) { |
|
571 | + if (empty($notes)) { |
|
572 | 572 | $notes = ''; |
573 | 573 | } |
574 | 574 | |
575 | - $note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note; |
|
576 | - $new_note = apply_filters( 'give_customer_add_note_string', $note_string ); |
|
577 | - $notes .= "\n\n" . $new_note; |
|
575 | + $note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note; |
|
576 | + $new_note = apply_filters('give_customer_add_note_string', $note_string); |
|
577 | + $notes .= "\n\n".$new_note; |
|
578 | 578 | |
579 | - do_action( 'give_customer_pre_add_note', $new_note, $this->id ); |
|
579 | + do_action('give_customer_pre_add_note', $new_note, $this->id); |
|
580 | 580 | |
581 | - $updated = $this->update( array( 'notes' => $notes ) ); |
|
581 | + $updated = $this->update(array('notes' => $notes)); |
|
582 | 582 | |
583 | - if ( $updated ) { |
|
583 | + if ($updated) { |
|
584 | 584 | $this->notes = $this->get_notes(); |
585 | 585 | } |
586 | 586 | |
587 | - do_action( 'give_customer_post_add_note', $this->notes, $new_note, $this->id ); |
|
587 | + do_action('give_customer_post_add_note', $this->notes, $new_note, $this->id); |
|
588 | 588 | |
589 | 589 | // Return the formatted note, so we can test, as well as update any displays |
590 | 590 | return $new_note; |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | */ |
600 | 600 | private function get_raw_notes() { |
601 | 601 | |
602 | - $all_notes = $this->db->get_column( 'notes', $this->id ); |
|
602 | + $all_notes = $this->db->get_column('notes', $this->id); |
|
603 | 603 | |
604 | 604 | return $all_notes; |
605 | 605 | |
@@ -614,51 +614,51 @@ discard block |
||
614 | 614 | * |
615 | 615 | * @return array The sanitized data, based off column defaults |
616 | 616 | */ |
617 | - private function sanitize_columns( $data ) { |
|
617 | + private function sanitize_columns($data) { |
|
618 | 618 | |
619 | 619 | $columns = $this->db->get_columns(); |
620 | 620 | $default_values = $this->db->get_column_defaults(); |
621 | 621 | |
622 | - foreach ( $columns as $key => $type ) { |
|
622 | + foreach ($columns as $key => $type) { |
|
623 | 623 | |
624 | 624 | // Only sanitize data that we were provided |
625 | - if ( ! array_key_exists( $key, $data ) ) { |
|
625 | + if ( ! array_key_exists($key, $data)) { |
|
626 | 626 | continue; |
627 | 627 | } |
628 | 628 | |
629 | - switch ( $type ) { |
|
629 | + switch ($type) { |
|
630 | 630 | |
631 | 631 | case '%s': |
632 | - if ( 'email' == $key ) { |
|
633 | - $data[ $key ] = sanitize_email( $data[ $key ] ); |
|
634 | - } elseif ( 'notes' == $key ) { |
|
635 | - $data[ $key ] = strip_tags( $data[ $key ] ); |
|
632 | + if ('email' == $key) { |
|
633 | + $data[$key] = sanitize_email($data[$key]); |
|
634 | + } elseif ('notes' == $key) { |
|
635 | + $data[$key] = strip_tags($data[$key]); |
|
636 | 636 | } else { |
637 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
637 | + $data[$key] = sanitize_text_field($data[$key]); |
|
638 | 638 | } |
639 | 639 | break; |
640 | 640 | |
641 | 641 | case '%d': |
642 | - if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) { |
|
643 | - $data[ $key ] = $default_values[ $key ]; |
|
642 | + if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) { |
|
643 | + $data[$key] = $default_values[$key]; |
|
644 | 644 | } else { |
645 | - $data[ $key ] = absint( $data[ $key ] ); |
|
645 | + $data[$key] = absint($data[$key]); |
|
646 | 646 | } |
647 | 647 | break; |
648 | 648 | |
649 | 649 | case '%f': |
650 | 650 | // Convert what was given to a float |
651 | - $value = floatval( $data[ $key ] ); |
|
651 | + $value = floatval($data[$key]); |
|
652 | 652 | |
653 | - if ( ! is_float( $value ) ) { |
|
654 | - $data[ $key ] = $default_values[ $key ]; |
|
653 | + if ( ! is_float($value)) { |
|
654 | + $data[$key] = $default_values[$key]; |
|
655 | 655 | } else { |
656 | - $data[ $key ] = $value; |
|
656 | + $data[$key] = $value; |
|
657 | 657 | } |
658 | 658 | break; |
659 | 659 | |
660 | 660 | default: |
661 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
661 | + $data[$key] = sanitize_text_field($data[$key]); |
|
662 | 662 | break; |
663 | 663 | |
664 | 664 | } |
@@ -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,94 +28,94 @@ discard block |
||
28 | 28 | |
29 | 29 | global $give_options; |
30 | 30 | |
31 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/frontend/'; |
|
32 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
33 | - $scripts_footer = ( give_get_option( 'scripts_footer' ) == 'on' ) ? true : false; |
|
31 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/frontend/'; |
|
32 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
33 | + $scripts_footer = (give_get_option('scripts_footer') == 'on') ? true : false; |
|
34 | 34 | |
35 | 35 | // Use minified libraries if SCRIPT_DEBUG is turned off |
36 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
36 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
37 | 37 | |
38 | 38 | //Localize / PHP to AJAX vars |
39 | - $localize_give_checkout = apply_filters( 'give_global_script_vars', array( |
|
39 | + $localize_give_checkout = apply_filters('give_global_script_vars', array( |
|
40 | 40 | 'ajaxurl' => give_get_ajax_url(), |
41 | - 'checkout_nonce' => wp_create_nonce( 'give_checkout_nonce' ), |
|
42 | - 'currency_sign' => give_currency_filter( '' ), |
|
41 | + 'checkout_nonce' => wp_create_nonce('give_checkout_nonce'), |
|
42 | + 'currency_sign' => give_currency_filter(''), |
|
43 | 43 | 'currency_pos' => give_get_currency_position(), |
44 | - 'thousands_separator' => isset( $give_options['thousands_separator'] ) ? $give_options['thousands_separator'] : ',', |
|
45 | - 'decimal_separator' => isset( $give_options['decimal_separator'] ) ? $give_options['decimal_separator'] : '.', |
|
46 | - 'no_gateway' => __( 'Please select a payment method.', 'give' ), |
|
47 | - 'bad_minimum' => __( 'The minimum donation amount for this form is', 'give' ), |
|
48 | - 'general_loading' => __( 'Loading...', 'give' ), |
|
49 | - 'purchase_loading' => __( 'Please Wait...', 'give' ), |
|
50 | - 'number_decimals' => apply_filters( 'give_format_amount_decimals', 2 ), |
|
44 | + 'thousands_separator' => isset($give_options['thousands_separator']) ? $give_options['thousands_separator'] : ',', |
|
45 | + 'decimal_separator' => isset($give_options['decimal_separator']) ? $give_options['decimal_separator'] : '.', |
|
46 | + 'no_gateway' => __('Please select a payment method.', 'give'), |
|
47 | + 'bad_minimum' => __('The minimum donation amount for this form is', 'give'), |
|
48 | + 'general_loading' => __('Loading...', 'give'), |
|
49 | + 'purchase_loading' => __('Please Wait...', 'give'), |
|
50 | + 'number_decimals' => apply_filters('give_format_amount_decimals', 2), |
|
51 | 51 | 'give_version' => GIVE_VERSION |
52 | - ) ); |
|
53 | - $localize_give_ajax = apply_filters( 'give_global_ajax_vars', array( |
|
52 | + )); |
|
53 | + $localize_give_ajax = apply_filters('give_global_ajax_vars', array( |
|
54 | 54 | 'ajaxurl' => give_get_ajax_url(), |
55 | - 'loading' => __( 'Loading', 'give' ), |
|
55 | + 'loading' => __('Loading', 'give'), |
|
56 | 56 | // General loading message |
57 | - 'select_option' => __( 'Please select an option', 'give' ), |
|
57 | + 'select_option' => __('Please select an option', 'give'), |
|
58 | 58 | // Variable pricing error with multi-purchase option enabled |
59 | - 'default_gateway' => give_get_default_gateway( null ), |
|
60 | - 'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0', |
|
61 | - 'number_decimals' => apply_filters( 'give_format_amount_decimals', 2 ) |
|
62 | - ) ); |
|
59 | + 'default_gateway' => give_get_default_gateway(null), |
|
60 | + 'permalinks' => get_option('permalink_structure') ? '1' : '0', |
|
61 | + 'number_decimals' => apply_filters('give_format_amount_decimals', 2) |
|
62 | + )); |
|
63 | 63 | |
64 | 64 | //DEBUG is On |
65 | - if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
|
65 | + if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { |
|
66 | 66 | |
67 | - if ( give_is_cc_verify_enabled() ) { |
|
68 | - wp_register_script( 'give-cc-validator', $js_plugins . 'jquery.payment' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
69 | - wp_enqueue_script( 'give-cc-validator' ); |
|
67 | + if (give_is_cc_verify_enabled()) { |
|
68 | + wp_register_script('give-cc-validator', $js_plugins.'jquery.payment'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
69 | + wp_enqueue_script('give-cc-validator'); |
|
70 | 70 | } |
71 | 71 | |
72 | - wp_register_script( 'give-float-labels', $js_plugins . 'float-labels' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
73 | - wp_enqueue_script( 'give-float-labels' ); |
|
72 | + wp_register_script('give-float-labels', $js_plugins.'float-labels'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
73 | + wp_enqueue_script('give-float-labels'); |
|
74 | 74 | |
75 | - wp_register_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
76 | - wp_enqueue_script( 'give-blockui' ); |
|
75 | + wp_register_script('give-blockui', $js_plugins.'jquery.blockUI'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
76 | + wp_enqueue_script('give-blockui'); |
|
77 | 77 | |
78 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
79 | - wp_enqueue_script( 'give-qtip' ); |
|
78 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
79 | + wp_enqueue_script('give-qtip'); |
|
80 | 80 | |
81 | - wp_register_script( 'give-accounting', $js_plugins . 'accounting' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
82 | - wp_enqueue_script( 'give-accounting' ); |
|
81 | + wp_register_script('give-accounting', $js_plugins.'accounting'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
82 | + wp_enqueue_script('give-accounting'); |
|
83 | 83 | |
84 | - wp_register_script( 'give-magnific', $js_plugins . 'jquery.magnific-popup' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
85 | - wp_enqueue_script( 'give-magnific' ); |
|
84 | + wp_register_script('give-magnific', $js_plugins.'jquery.magnific-popup'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
85 | + wp_enqueue_script('give-magnific'); |
|
86 | 86 | |
87 | - wp_register_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
88 | - wp_enqueue_script( 'give-checkout-global' ); |
|
87 | + wp_register_script('give-checkout-global', $js_dir.'give-checkout-global'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
88 | + wp_enqueue_script('give-checkout-global'); |
|
89 | 89 | |
90 | 90 | //General scripts |
91 | - wp_register_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
92 | - wp_enqueue_script( 'give-scripts' ); |
|
91 | + wp_register_script('give-scripts', $js_dir.'give'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
92 | + wp_enqueue_script('give-scripts'); |
|
93 | 93 | |
94 | 94 | // Load AJAX scripts, if enabled |
95 | - wp_register_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
96 | - wp_enqueue_script( 'give-ajax' ); |
|
95 | + wp_register_script('give-ajax', $js_dir.'give-ajax'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
96 | + wp_enqueue_script('give-ajax'); |
|
97 | 97 | |
98 | 98 | //Localize / Pass AJAX vars from PHP |
99 | - wp_localize_script( 'give-checkout-global', 'give_global_vars', $localize_give_checkout ); |
|
100 | - wp_localize_script( 'give-ajax', 'give_scripts', $localize_give_ajax ); |
|
99 | + wp_localize_script('give-checkout-global', 'give_global_vars', $localize_give_checkout); |
|
100 | + wp_localize_script('give-ajax', 'give_scripts', $localize_give_ajax); |
|
101 | 101 | |
102 | 102 | |
103 | 103 | } else { |
104 | 104 | |
105 | 105 | //DEBUG is OFF (one JS file to rule them all!) |
106 | - wp_register_script( 'give', $js_dir . 'give.all.min.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
107 | - wp_enqueue_script( 'give' ); |
|
106 | + wp_register_script('give', $js_dir.'give.all.min.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
107 | + wp_enqueue_script('give'); |
|
108 | 108 | |
109 | 109 | //Localize / Pass AJAX vars from PHP |
110 | - wp_localize_script( 'give', 'give_global_vars', $localize_give_checkout ); |
|
111 | - wp_localize_script( 'give', 'give_scripts', $localize_give_ajax ); |
|
110 | + wp_localize_script('give', 'give_global_vars', $localize_give_checkout); |
|
111 | + wp_localize_script('give', 'give_scripts', $localize_give_ajax); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | 116 | } |
117 | 117 | |
118 | -add_action( 'wp_enqueue_scripts', 'give_load_scripts' ); |
|
118 | +add_action('wp_enqueue_scripts', 'give_load_scripts'); |
|
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Register Styles |
@@ -127,47 +127,47 @@ discard block |
||
127 | 127 | */ |
128 | 128 | function give_register_styles() { |
129 | 129 | |
130 | - if ( give_get_option( 'disable_css', false ) ) { |
|
130 | + if (give_get_option('disable_css', false)) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | // Use minified libraries if SCRIPT_DEBUG is turned off |
135 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
135 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
136 | 136 | |
137 | - $file = 'give' . $suffix . '.css'; |
|
137 | + $file = 'give'.$suffix.'.css'; |
|
138 | 138 | $templates_dir = give_get_theme_template_dir_name(); |
139 | 139 | |
140 | - $child_theme_style_sheet = trailingslashit( get_stylesheet_directory() ) . $templates_dir . $file; |
|
141 | - $child_theme_style_sheet_2 = trailingslashit( get_stylesheet_directory() ) . $templates_dir . 'give.css'; |
|
142 | - $parent_theme_style_sheet = trailingslashit( get_template_directory() ) . $templates_dir . $file; |
|
143 | - $parent_theme_style_sheet_2 = trailingslashit( get_template_directory() ) . $templates_dir . 'give.css'; |
|
144 | - $give_plugin_style_sheet = trailingslashit( give_get_templates_dir() ) . $file; |
|
140 | + $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()).$templates_dir.$file; |
|
141 | + $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()).$templates_dir.'give.css'; |
|
142 | + $parent_theme_style_sheet = trailingslashit(get_template_directory()).$templates_dir.$file; |
|
143 | + $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()).$templates_dir.'give.css'; |
|
144 | + $give_plugin_style_sheet = trailingslashit(give_get_templates_dir()).$file; |
|
145 | 145 | |
146 | 146 | // Look in the child theme directory first, followed by the parent theme, followed by the Give core templates directory |
147 | 147 | // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. |
148 | 148 | // This allows users to copy just give.css to their theme |
149 | - if ( file_exists( $child_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $child_theme_style_sheet_2 ) ) ) ) { |
|
150 | - if ( ! empty( $nonmin ) ) { |
|
151 | - $url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . 'give.css'; |
|
149 | + if (file_exists($child_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2)))) { |
|
150 | + if ( ! empty($nonmin)) { |
|
151 | + $url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.'give.css'; |
|
152 | 152 | } else { |
153 | - $url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . $file; |
|
153 | + $url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.$file; |
|
154 | 154 | } |
155 | - } elseif ( file_exists( $parent_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $parent_theme_style_sheet_2 ) ) ) ) { |
|
156 | - if ( ! empty( $nonmin ) ) { |
|
157 | - $url = trailingslashit( get_template_directory_uri() ) . $templates_dir . 'give.css'; |
|
155 | + } elseif (file_exists($parent_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2)))) { |
|
156 | + if ( ! empty($nonmin)) { |
|
157 | + $url = trailingslashit(get_template_directory_uri()).$templates_dir.'give.css'; |
|
158 | 158 | } else { |
159 | - $url = trailingslashit( get_template_directory_uri() ) . $templates_dir . $file; |
|
159 | + $url = trailingslashit(get_template_directory_uri()).$templates_dir.$file; |
|
160 | 160 | } |
161 | - } elseif ( file_exists( $give_plugin_style_sheet ) || file_exists( $give_plugin_style_sheet ) ) { |
|
162 | - $url = trailingslashit( give_get_templates_url() ) . $file; |
|
161 | + } elseif (file_exists($give_plugin_style_sheet) || file_exists($give_plugin_style_sheet)) { |
|
162 | + $url = trailingslashit(give_get_templates_url()).$file; |
|
163 | 163 | } |
164 | 164 | |
165 | - wp_register_style( 'give-styles', $url, array(), GIVE_VERSION, 'all' ); |
|
166 | - wp_enqueue_style( 'give-styles' ); |
|
165 | + wp_register_style('give-styles', $url, array(), GIVE_VERSION, 'all'); |
|
166 | + wp_enqueue_style('give-styles'); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | -add_action( 'wp_enqueue_scripts', 'give_register_styles' ); |
|
170 | +add_action('wp_enqueue_scripts', 'give_register_styles'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Load Admin Scripts |
@@ -181,103 +181,103 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return void |
183 | 183 | */ |
184 | -function give_load_admin_scripts( $hook ) { |
|
184 | +function give_load_admin_scripts($hook) { |
|
185 | 185 | |
186 | 186 | global $wp_version, $post, $post_type; |
187 | 187 | |
188 | 188 | //Directories of assets |
189 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
190 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
191 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
189 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
190 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
191 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
192 | 192 | |
193 | 193 | // Use minified libraries if SCRIPT_DEBUG is turned off |
194 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
194 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
195 | 195 | |
196 | 196 | //Global Admin: |
197 | - wp_register_style( 'give-admin-bar-notification', $css_dir . 'adminbar-style.css' ); |
|
198 | - wp_enqueue_style( 'give-admin-bar-notification' ); |
|
197 | + wp_register_style('give-admin-bar-notification', $css_dir.'adminbar-style.css'); |
|
198 | + wp_enqueue_style('give-admin-bar-notification'); |
|
199 | 199 | |
200 | 200 | //Give Admin Only: |
201 | - if ( ! apply_filters( 'give_load_admin_scripts', give_is_admin_page(), $hook ) ) { |
|
201 | + if ( ! apply_filters('give_load_admin_scripts', give_is_admin_page(), $hook)) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | //CSS |
206 | - wp_register_style( 'jquery-ui-css', $css_dir . 'jquery-ui-fresh' . $suffix . '.css' ); |
|
207 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
208 | - wp_register_style( 'give-admin', $css_dir . 'give-admin' . $suffix . '.css', GIVE_VERSION ); |
|
209 | - wp_enqueue_style( 'give-admin' ); |
|
210 | - wp_register_style( 'jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), GIVE_VERSION ); |
|
211 | - wp_enqueue_style( 'jquery-chosen' ); |
|
212 | - wp_enqueue_style( 'thickbox' ); |
|
206 | + wp_register_style('jquery-ui-css', $css_dir.'jquery-ui-fresh'.$suffix.'.css'); |
|
207 | + wp_enqueue_style('jquery-ui-css'); |
|
208 | + wp_register_style('give-admin', $css_dir.'give-admin'.$suffix.'.css', GIVE_VERSION); |
|
209 | + wp_enqueue_style('give-admin'); |
|
210 | + wp_register_style('jquery-chosen', $css_dir.'chosen'.$suffix.'.css', array(), GIVE_VERSION); |
|
211 | + wp_enqueue_style('jquery-chosen'); |
|
212 | + wp_enqueue_style('thickbox'); |
|
213 | 213 | |
214 | 214 | //JS |
215 | - wp_register_script( 'jquery-chosen', $js_plugins . 'chosen.jquery' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
216 | - wp_enqueue_script( 'jquery-chosen' ); |
|
215 | + wp_register_script('jquery-chosen', $js_plugins.'chosen.jquery'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
216 | + wp_enqueue_script('jquery-chosen'); |
|
217 | 217 | |
218 | - wp_register_script( 'give-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
219 | - wp_enqueue_script( 'give-admin-scripts' ); |
|
218 | + wp_register_script('give-admin-scripts', $js_dir.'admin-scripts'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
219 | + wp_enqueue_script('give-admin-scripts'); |
|
220 | 220 | |
221 | - wp_register_script( 'jquery-flot', $js_plugins . 'jquery.flot' . $suffix . '.js' ); |
|
222 | - wp_enqueue_script( 'jquery-flot' ); |
|
221 | + wp_register_script('jquery-flot', $js_plugins.'jquery.flot'.$suffix.'.js'); |
|
222 | + wp_enqueue_script('jquery-flot'); |
|
223 | 223 | |
224 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
225 | - wp_enqueue_script( 'give-qtip' ); |
|
224 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
225 | + wp_enqueue_script('give-qtip'); |
|
226 | 226 | |
227 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
228 | - wp_enqueue_script( 'thickbox' ); |
|
227 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
228 | + wp_enqueue_script('thickbox'); |
|
229 | 229 | |
230 | 230 | //Forms CPT Script |
231 | - if ( $post_type === 'give_forms' ) { |
|
232 | - wp_register_script( 'give-admin-forms-scripts', $js_dir . 'admin-forms' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
233 | - wp_enqueue_script( 'give-admin-forms-scripts' ); |
|
231 | + if ($post_type === 'give_forms') { |
|
232 | + wp_register_script('give-admin-forms-scripts', $js_dir.'admin-forms'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
233 | + wp_enqueue_script('give-admin-forms-scripts'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | //Settings Scripts |
237 | - if (isset($_GET['page']) && $_GET['page'] == 'give-settings' ) { |
|
237 | + if (isset($_GET['page']) && $_GET['page'] == 'give-settings') { |
|
238 | 238 | wp_enqueue_script('jquery-ui-sortable'); |
239 | - wp_register_script( 'give-admin-settings-scripts', $js_dir . 'admin-settings' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
240 | - wp_enqueue_script( 'give-admin-settings-scripts' ); |
|
239 | + wp_register_script('give-admin-settings-scripts', $js_dir.'admin-settings'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
240 | + wp_enqueue_script('give-admin-settings-scripts'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | //Localize strings & variables for JS |
244 | - wp_localize_script( 'give-admin-scripts', 'give_vars', array( |
|
245 | - 'post_id' => isset( $post->ID ) ? $post->ID : null, |
|
244 | + wp_localize_script('give-admin-scripts', 'give_vars', array( |
|
245 | + 'post_id' => isset($post->ID) ? $post->ID : null, |
|
246 | 246 | 'give_version' => GIVE_VERSION, |
247 | - 'quick_edit_warning' => __( 'Sorry, not available for variable priced forms.', 'give' ), |
|
248 | - 'delete_payment' => __( 'Are you sure you wish to delete this payment?', 'give' ), |
|
249 | - 'delete_payment_note' => __( 'Are you sure you wish to delete this note?', 'give' ), |
|
250 | - 'revoke_api_key' => __( 'Are you sure you wish to revoke this API key?', 'give' ), |
|
251 | - 'regenerate_api_key' => __( 'Are you sure you wish to regenerate this API key?', 'give' ), |
|
252 | - 'resend_receipt' => __( 'Are you sure you wish to resend the donation receipt?', 'give' ), |
|
253 | - 'copy_download_link_text' => __( 'Copy these links to your clipboard and give them to your donor.', 'give' ), |
|
254 | - 'delete_payment_download' => sprintf( __( 'Are you sure you wish to delete this %s?', 'give' ), give_get_forms_label_singular() ), |
|
255 | - 'one_price_min' => __( 'You must have at least one price.', 'give' ), |
|
256 | - 'one_file_min' => __( 'You must have at least one file.', 'give' ), |
|
257 | - 'one_field_min' => __( 'You must have at least one field.', 'give' ), |
|
258 | - 'one_option' => sprintf( __( 'Choose a %s', 'give' ), give_get_forms_label_singular() ), |
|
259 | - 'one_or_more_option' => sprintf( __( 'Choose one or more %s', 'give' ), give_get_forms_label_plural() ), |
|
260 | - 'numeric_item_price' => __( 'Item price must be numeric.', 'give' ), |
|
261 | - 'numeric_quantity' => __( 'Quantity must be numeric.', 'give' ), |
|
262 | - 'currency_sign' => give_currency_filter( '' ), |
|
263 | - 'currency_pos' => isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before', |
|
247 | + 'quick_edit_warning' => __('Sorry, not available for variable priced forms.', 'give'), |
|
248 | + 'delete_payment' => __('Are you sure you wish to delete this payment?', 'give'), |
|
249 | + 'delete_payment_note' => __('Are you sure you wish to delete this note?', 'give'), |
|
250 | + 'revoke_api_key' => __('Are you sure you wish to revoke this API key?', 'give'), |
|
251 | + 'regenerate_api_key' => __('Are you sure you wish to regenerate this API key?', 'give'), |
|
252 | + 'resend_receipt' => __('Are you sure you wish to resend the donation receipt?', 'give'), |
|
253 | + 'copy_download_link_text' => __('Copy these links to your clipboard and give them to your donor.', 'give'), |
|
254 | + 'delete_payment_download' => sprintf(__('Are you sure you wish to delete this %s?', 'give'), give_get_forms_label_singular()), |
|
255 | + 'one_price_min' => __('You must have at least one price.', 'give'), |
|
256 | + 'one_file_min' => __('You must have at least one file.', 'give'), |
|
257 | + 'one_field_min' => __('You must have at least one field.', 'give'), |
|
258 | + 'one_option' => sprintf(__('Choose a %s', 'give'), give_get_forms_label_singular()), |
|
259 | + 'one_or_more_option' => sprintf(__('Choose one or more %s', 'give'), give_get_forms_label_plural()), |
|
260 | + 'numeric_item_price' => __('Item price must be numeric.', 'give'), |
|
261 | + 'numeric_quantity' => __('Quantity must be numeric.', 'give'), |
|
262 | + 'currency_sign' => give_currency_filter(''), |
|
263 | + 'currency_pos' => isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before', |
|
264 | 264 | 'currency_decimals' => give_currency_decimal_filter(), |
265 | - 'new_media_ui' => apply_filters( 'give_use_35_media_ui', 1 ), |
|
266 | - 'remove_text' => __( 'Remove', 'give' ), |
|
267 | - 'type_to_search' => sprintf( __( 'Type to search %s', 'give' ), give_get_forms_label_plural() ), |
|
268 | - 'batch_export_no_class' => __( 'You must choose a method.', 'give' ), |
|
269 | - 'batch_export_no_reqs' => __( 'Required fields not completed.', 'give' ), |
|
270 | - 'reset_stats_warn' => __( 'Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give' ), |
|
271 | - ) ); |
|
272 | - |
|
273 | - if ( function_exists( 'wp_enqueue_media' ) && version_compare( $wp_version, '3.5', '>=' ) ) { |
|
265 | + 'new_media_ui' => apply_filters('give_use_35_media_ui', 1), |
|
266 | + 'remove_text' => __('Remove', 'give'), |
|
267 | + 'type_to_search' => sprintf(__('Type to search %s', 'give'), give_get_forms_label_plural()), |
|
268 | + 'batch_export_no_class' => __('You must choose a method.', 'give'), |
|
269 | + 'batch_export_no_reqs' => __('Required fields not completed.', 'give'), |
|
270 | + 'reset_stats_warn' => __('Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give'), |
|
271 | + )); |
|
272 | + |
|
273 | + if (function_exists('wp_enqueue_media') && version_compare($wp_version, '3.5', '>=')) { |
|
274 | 274 | //call for new media manager |
275 | 275 | wp_enqueue_media(); |
276 | 276 | } |
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | -add_action( 'admin_enqueue_scripts', 'give_load_admin_scripts', 100 ); |
|
280 | +add_action('admin_enqueue_scripts', 'give_load_admin_scripts', 100); |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * Admin Give Icon |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | ?> |
295 | 295 | <style type="text/css" media="screen"> |
296 | 296 | |
297 | - <?php if( version_compare( $wp_version, '3.8-RC', '>=' ) || version_compare( $wp_version, '3.8', '>=' ) ) { ?> |
|
297 | + <?php if (version_compare($wp_version, '3.8-RC', '>=') || version_compare($wp_version, '3.8', '>=')) { ?> |
|
298 | 298 | @font-face { |
299 | 299 | font-family: 'give-icomoon'; |
300 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
301 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
302 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
303 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
304 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
300 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
301 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
302 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
303 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
304 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
305 | 305 | font-weight: normal; |
306 | 306 | font-style: normal; |
307 | 307 | } |
@@ -320,4 +320,4 @@ discard block |
||
320 | 320 | <?php |
321 | 321 | } |
322 | 322 | |
323 | -add_action( 'admin_head', 'give_admin_icon' ); |
|
323 | +add_action('admin_head', 'give_admin_icon'); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 1.0 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @access private |
22 | 22 | * @since 1.0 |
23 | 23 | */ |
24 | -add_action( 'give_paypal_cc_form', '__return_false' ); |
|
24 | +add_action('give_paypal_cc_form', '__return_false'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Process PayPal Purchase |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return void |
34 | 34 | */ |
35 | -function give_process_paypal_purchase( $purchase_data ) { |
|
35 | +function give_process_paypal_purchase($purchase_data) { |
|
36 | 36 | |
37 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
38 | - wp_die( __( 'Nonce verification has failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(__('Nonce verification has failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | - $form_id = intval( $purchase_data['post_data']['give-form-id'] ); |
|
41 | + $form_id = intval($purchase_data['post_data']['give-form-id']); |
|
42 | 42 | $price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : ''; |
43 | 43 | |
44 | 44 | // Collect payment data |
@@ -57,59 +57,59 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Record the pending payment |
60 | - $payment = give_insert_payment( $payment_data ); |
|
60 | + $payment = give_insert_payment($payment_data); |
|
61 | 61 | |
62 | 62 | // Check payment |
63 | - if ( ! $payment ) { |
|
63 | + if ( ! $payment) { |
|
64 | 64 | // Record the error |
65 | - give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment ); |
|
65 | + give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment); |
|
66 | 66 | // Problems? send back |
67 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
67 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
68 | 68 | } else { |
69 | 69 | // Only send to PayPal if the pending payment is created successfully |
70 | - $listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) ); |
|
70 | + $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php')); |
|
71 | 71 | |
72 | 72 | // Get the success url |
73 | - $return_url = add_query_arg( array( |
|
73 | + $return_url = add_query_arg(array( |
|
74 | 74 | 'payment-confirmation' => 'paypal', |
75 | 75 | 'payment-id' => $payment |
76 | 76 | |
77 | - ), get_permalink( give_get_option( 'success_page' ) ) ); |
|
77 | + ), get_permalink(give_get_option('success_page'))); |
|
78 | 78 | |
79 | 79 | // Get the PayPal redirect uri |
80 | - $paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?'; |
|
80 | + $paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?'; |
|
81 | 81 | |
82 | 82 | //Item name - pass level name if variable priced |
83 | 83 | $item_name = $purchase_data['post_data']['give-form-title']; |
84 | 84 | |
85 | 85 | //Verify has variable prices |
86 | - if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) { |
|
86 | + if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) { |
|
87 | 87 | |
88 | - $item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
88 | + $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']); |
|
89 | 89 | |
90 | - $price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
90 | + $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']); |
|
91 | 91 | |
92 | 92 | //Donation given doesn't match selected level (must be a custom amount) |
93 | - if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) { |
|
94 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
93 | + if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) { |
|
94 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
95 | 95 | //user custom amount text if any, fallback to default if not |
96 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) ); |
|
96 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
97 | 97 | |
98 | 98 | } //Is there any donation level text? |
99 | - elseif ( ! empty( $item_price_level_text ) ) { |
|
100 | - $item_name .= ' - ' . $item_price_level_text; |
|
99 | + elseif ( ! empty($item_price_level_text)) { |
|
100 | + $item_name .= ' - '.$item_price_level_text; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | } //Single donation: Custom Amount |
104 | - elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) { |
|
105 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
104 | + elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) { |
|
105 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
106 | 106 | //user custom amount text if any, fallback to default if not |
107 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) ); |
|
107 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | // Setup PayPal arguments |
111 | 111 | $paypal_args = array( |
112 | - 'business' => give_get_option( 'paypal_email', false ), |
|
112 | + 'business' => give_get_option('paypal_email', false), |
|
113 | 113 | 'email' => $purchase_data['user_email'], |
114 | 114 | 'invoice' => $purchase_data['purchase_key'], |
115 | 115 | 'amount' => $purchase_data['price'], |
@@ -120,25 +120,25 @@ discard block |
||
120 | 120 | 'shipping' => '0', |
121 | 121 | 'no_note' => '1', |
122 | 122 | 'currency_code' => give_get_currency(), |
123 | - 'charset' => get_bloginfo( 'charset' ), |
|
123 | + 'charset' => get_bloginfo('charset'), |
|
124 | 124 | 'custom' => $payment, |
125 | 125 | 'rm' => '2', |
126 | 126 | 'return' => $return_url, |
127 | - 'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ), |
|
127 | + 'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment), |
|
128 | 128 | 'notify_url' => $listener_url, |
129 | 129 | 'page_style' => give_get_paypal_page_style(), |
130 | - 'cbt' => get_bloginfo( 'name' ), |
|
130 | + 'cbt' => get_bloginfo('name'), |
|
131 | 131 | 'bn' => 'givewp_SP' |
132 | 132 | ); |
133 | 133 | |
134 | - if ( ! empty( $purchase_data['user_info']['address'] ) ) { |
|
134 | + if ( ! empty($purchase_data['user_info']['address'])) { |
|
135 | 135 | $paypal_args['address1'] = $purchase_data['user_info']['address']['line1']; |
136 | 136 | $paypal_args['address2'] = $purchase_data['user_info']['address']['line2']; |
137 | 137 | $paypal_args['city'] = $purchase_data['user_info']['address']['city']; |
138 | 138 | $paypal_args['country'] = $purchase_data['user_info']['address']['country']; |
139 | 139 | } |
140 | 140 | |
141 | - if ( give_get_option( 'paypal_button_type' ) === 'standard' ) { |
|
141 | + if (give_get_option('paypal_button_type') === 'standard') { |
|
142 | 142 | $paypal_extra_args = array( |
143 | 143 | 'cmd' => '_xclick', |
144 | 144 | ); |
@@ -148,23 +148,23 @@ discard block |
||
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
151 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
152 | - $paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data ); |
|
151 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
152 | + $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data); |
|
153 | 153 | |
154 | 154 | // Build query |
155 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
155 | + $paypal_redirect .= http_build_query($paypal_args); |
|
156 | 156 | |
157 | 157 | // Fix for some sites that encode the entities |
158 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
158 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
159 | 159 | |
160 | 160 | // Redirect to PayPal |
161 | - wp_redirect( $paypal_redirect ); |
|
161 | + wp_redirect($paypal_redirect); |
|
162 | 162 | exit; |
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | -add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' ); |
|
167 | +add_action('give_gateway_paypal', 'give_process_paypal_purchase'); |
|
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Listens for a PayPal IPN requests and then sends to the processing function |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | */ |
175 | 175 | function give_listen_for_paypal_ipn() { |
176 | 176 | // Regular PayPal IPN |
177 | - if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) { |
|
178 | - do_action( 'give_verify_paypal_ipn' ); |
|
177 | + if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') { |
|
178 | + do_action('give_verify_paypal_ipn'); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | -add_action( 'init', 'give_listen_for_paypal_ipn' ); |
|
182 | +add_action('init', 'give_listen_for_paypal_ipn'); |
|
183 | 183 | |
184 | 184 | /** |
185 | 185 | * Process PayPal IPN |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | function give_process_paypal_ipn() { |
191 | 191 | |
192 | 192 | // Check the request method is POST |
193 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
193 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
194 | 194 | return; |
195 | 195 | } |
196 | 196 | |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | $post_data = ''; |
199 | 199 | |
200 | 200 | // Fallback just in case post_max_size is lower than needed |
201 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
202 | - $post_data = file_get_contents( 'php://input' ); |
|
201 | + if (ini_get('allow_url_fopen')) { |
|
202 | + $post_data = file_get_contents('php://input'); |
|
203 | 203 | } else { |
204 | 204 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
205 | - ini_set( 'post_max_size', '12M' ); |
|
205 | + ini_set('post_max_size', '12M'); |
|
206 | 206 | } |
207 | 207 | // Start the encoded data collection with notification command |
208 | 208 | $encoded_data = 'cmd=_notify-validate'; |
@@ -211,40 +211,40 @@ discard block |
||
211 | 211 | $arg_separator = give_get_php_arg_separator_output(); |
212 | 212 | |
213 | 213 | // Verify there is a post_data |
214 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
214 | + if ($post_data || strlen($post_data) > 0) { |
|
215 | 215 | // Append the data |
216 | - $encoded_data .= $arg_separator . $post_data; |
|
216 | + $encoded_data .= $arg_separator.$post_data; |
|
217 | 217 | } else { |
218 | 218 | // Check if POST is empty |
219 | - if ( empty( $_POST ) ) { |
|
219 | + if (empty($_POST)) { |
|
220 | 220 | // Nothing to do |
221 | 221 | return; |
222 | 222 | } else { |
223 | 223 | // Loop through each POST |
224 | - foreach ( $_POST as $key => $value ) { |
|
224 | + foreach ($_POST as $key => $value) { |
|
225 | 225 | // Encode the value and append the data |
226 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
226 | + $encoded_data .= $arg_separator."$key=".urlencode($value); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | 231 | // Convert collected post data to an array |
232 | - parse_str( $encoded_data, $encoded_data_array ); |
|
232 | + parse_str($encoded_data, $encoded_data_array); |
|
233 | 233 | |
234 | - foreach ( $encoded_data_array as $key => $value ) { |
|
234 | + foreach ($encoded_data_array as $key => $value) { |
|
235 | 235 | |
236 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
237 | - $new_key = str_replace( '&', '&', $key ); |
|
238 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
236 | + if (false !== strpos($key, 'amp;')) { |
|
237 | + $new_key = str_replace('&', '&', $key); |
|
238 | + $new_key = str_replace('amp;', '&', $new_key); |
|
239 | 239 | |
240 | - unset( $encoded_data_array[ $key ] ); |
|
241 | - $encoded_data_array[ $new_key ] = $value; |
|
240 | + unset($encoded_data_array[$key]); |
|
241 | + $encoded_data_array[$new_key] = $value; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | } |
245 | 245 | |
246 | 246 | //Validate IPN request w/ PayPal if user hasn't disabled this security measure |
247 | - if ( ! give_get_option( 'disable_paypal_verification' ) ) { |
|
247 | + if ( ! give_get_option('disable_paypal_verification')) { |
|
248 | 248 | |
249 | 249 | $remote_post_vars = array( |
250 | 250 | 'method' => 'POST', |
@@ -264,22 +264,22 @@ discard block |
||
264 | 264 | ); |
265 | 265 | |
266 | 266 | // Validate the IPN |
267 | - $api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars ); |
|
267 | + $api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars); |
|
268 | 268 | |
269 | - if ( is_wp_error( $api_response ) ) { |
|
270 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
269 | + if (is_wp_error($api_response)) { |
|
270 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response))); |
|
271 | 271 | return; // Something went wrong |
272 | 272 | } |
273 | 273 | |
274 | - if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) { |
|
275 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
274 | + if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) { |
|
275 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response))); |
|
276 | 276 | return; // Response not okay |
277 | 277 | } |
278 | 278 | |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Check if $post_data_array has been populated |
282 | - if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) { |
|
282 | + if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
@@ -288,21 +288,21 @@ discard block |
||
288 | 288 | 'payment_status' => '' |
289 | 289 | ); |
290 | 290 | |
291 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
291 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
292 | 292 | |
293 | - $payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
293 | + $payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
294 | 294 | |
295 | - if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
295 | + if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) { |
|
296 | 296 | // Allow PayPal IPN types to be processed separately |
297 | - do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id ); |
|
297 | + do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id); |
|
298 | 298 | } else { |
299 | 299 | // Fallback to web accept just in case the txn_type isn't present |
300 | - do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id ); |
|
300 | + do_action('give_paypal_web_accept', $encoded_data_array, $payment_id); |
|
301 | 301 | } |
302 | 302 | exit; |
303 | 303 | } |
304 | 304 | |
305 | -add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' ); |
|
305 | +add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn'); |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Process web accept (one time) payment IPNs |
@@ -313,185 +313,185 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @return void |
315 | 315 | */ |
316 | -function give_process_paypal_web_accept_and_cart( $data, $payment_id ) { |
|
316 | +function give_process_paypal_web_accept_and_cart($data, $payment_id) { |
|
317 | 317 | |
318 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
318 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
319 | 319 | return; |
320 | 320 | } |
321 | 321 | |
322 | - if ( empty( $payment_id ) ) { |
|
322 | + if (empty($payment_id)) { |
|
323 | 323 | return; |
324 | 324 | } |
325 | 325 | |
326 | 326 | // Collect payment details |
327 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
327 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
328 | 328 | $paypal_amount = $data['mc_gross']; |
329 | - $payment_status = strtolower( $data['payment_status'] ); |
|
330 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
331 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
332 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
329 | + $payment_status = strtolower($data['payment_status']); |
|
330 | + $currency_code = strtolower($data['mc_currency']); |
|
331 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
332 | + $payment_meta = give_get_payment_meta($payment_id); |
|
333 | 333 | |
334 | 334 | |
335 | - if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) { |
|
335 | + if (give_get_payment_gateway($payment_id) != 'paypal') { |
|
336 | 336 | return; // this isn't a PayPal standard IPN |
337 | 337 | } |
338 | 338 | |
339 | 339 | // Verify payment recipient |
340 | - if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) { |
|
340 | + if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) { |
|
341 | 341 | |
342 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
343 | - give_update_payment_status( $payment_id, 'failed' ); |
|
344 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) ); |
|
342 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
343 | + give_update_payment_status($payment_id, 'failed'); |
|
344 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give')); |
|
345 | 345 | |
346 | 346 | return; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Verify payment currency |
350 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
350 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
351 | 351 | |
352 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
353 | - give_update_payment_status( $payment_id, 'failed' ); |
|
354 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) ); |
|
352 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
353 | + give_update_payment_status($payment_id, 'failed'); |
|
354 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give')); |
|
355 | 355 | |
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - if ( ! give_get_payment_user_email( $payment_id ) ) { |
|
359 | + if ( ! give_get_payment_user_email($payment_id)) { |
|
360 | 360 | |
361 | 361 | // No email associated with purchase, so store from PayPal |
362 | - give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] ); |
|
362 | + give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']); |
|
363 | 363 | |
364 | 364 | // Setup and store the donors's details |
365 | 365 | $address = array(); |
366 | - $address['line1'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
367 | - $address['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
368 | - $address['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
369 | - $address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
370 | - $address['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
366 | + $address['line1'] = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
367 | + $address['city'] = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
368 | + $address['state'] = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
369 | + $address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
370 | + $address['zip'] = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
371 | 371 | |
372 | 372 | $user_info = array( |
373 | 373 | 'id' => '-1', |
374 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
375 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
376 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
374 | + 'email' => sanitize_text_field($data['payer_email']), |
|
375 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
376 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
377 | 377 | 'discount' => '', |
378 | 378 | 'address' => $address |
379 | 379 | ); |
380 | 380 | |
381 | 381 | $payment_meta['user_info'] = $user_info; |
382 | - give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta ); |
|
382 | + give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
385 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
386 | 386 | |
387 | 387 | // Process a refund |
388 | - give_process_paypal_refund( $data, $payment_id ); |
|
388 | + give_process_paypal_refund($data, $payment_id); |
|
389 | 389 | |
390 | 390 | } else { |
391 | 391 | |
392 | - if ( get_post_status( $payment_id ) == 'publish' ) { |
|
392 | + if (get_post_status($payment_id) == 'publish') { |
|
393 | 393 | return; // Only complete payments once |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Retrieve the total purchase amount (before PayPal) |
397 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
397 | + $payment_amount = give_get_payment_amount($payment_id); |
|
398 | 398 | |
399 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
399 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
400 | 400 | // The prices don't match |
401 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
402 | - give_update_payment_status( $payment_id, 'failed' ); |
|
403 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) ); |
|
401 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
402 | + give_update_payment_status($payment_id, 'failed'); |
|
403 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give')); |
|
404 | 404 | |
405 | 405 | return; |
406 | 406 | } |
407 | - if ( $purchase_key != give_get_payment_key( $payment_id ) ) { |
|
407 | + if ($purchase_key != give_get_payment_key($payment_id)) { |
|
408 | 408 | // Purchase keys don't match |
409 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
410 | - give_update_payment_status( $payment_id, 'failed' ); |
|
411 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) ); |
|
409 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
410 | + give_update_payment_status($payment_id, 'failed'); |
|
411 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give')); |
|
412 | 412 | |
413 | 413 | return; |
414 | 414 | } |
415 | 415 | |
416 | - if ( $payment_status == 'completed' || give_is_test_mode() ) { |
|
417 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
418 | - give_set_payment_transaction_id( $payment_id, $data['txn_id'] ); |
|
419 | - give_update_payment_status( $payment_id, 'publish' ); |
|
420 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
416 | + if ($payment_status == 'completed' || give_is_test_mode()) { |
|
417 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id'])); |
|
418 | + give_set_payment_transaction_id($payment_id, $data['txn_id']); |
|
419 | + give_update_payment_status($payment_id, 'publish'); |
|
420 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
421 | 421 | |
422 | 422 | // Look for possible pending reasons, such as an echeck |
423 | 423 | |
424 | 424 | $note = ''; |
425 | 425 | |
426 | - switch ( strtolower( $data['pending_reason'] ) ) { |
|
426 | + switch (strtolower($data['pending_reason'])) { |
|
427 | 427 | |
428 | 428 | case 'echeck' : |
429 | 429 | |
430 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' ); |
|
430 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days.', 'give'); |
|
431 | 431 | |
432 | 432 | break; |
433 | 433 | |
434 | 434 | case 'address' : |
435 | 435 | |
436 | - $note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' ); |
|
436 | + $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give'); |
|
437 | 437 | |
438 | 438 | break; |
439 | 439 | |
440 | 440 | case 'intl' : |
441 | 441 | |
442 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' ); |
|
442 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations.', 'give'); |
|
443 | 443 | |
444 | 444 | break; |
445 | 445 | |
446 | 446 | case 'multi-currency' : |
447 | 447 | |
448 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' ); |
|
448 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give'); |
|
449 | 449 | |
450 | 450 | break; |
451 | 451 | |
452 | 452 | case 'paymentreview' : |
453 | 453 | case 'regulatory_review' : |
454 | 454 | |
455 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' ); |
|
455 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give'); |
|
456 | 456 | |
457 | 457 | break; |
458 | 458 | |
459 | 459 | case 'unilateral' : |
460 | 460 | |
461 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' ); |
|
461 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give'); |
|
462 | 462 | |
463 | 463 | break; |
464 | 464 | |
465 | 465 | case 'upgrade' : |
466 | 466 | |
467 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted.', 'give' ); |
|
467 | + $note = __('PayPal account must be upgraded before this payment can be accepted.', 'give'); |
|
468 | 468 | |
469 | 469 | break; |
470 | 470 | |
471 | 471 | case 'verify' : |
472 | 472 | |
473 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment.', 'give' ); |
|
473 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment.', 'give'); |
|
474 | 474 | |
475 | 475 | break; |
476 | 476 | |
477 | 477 | case 'other' : |
478 | 478 | |
479 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' ); |
|
479 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give'); |
|
480 | 480 | |
481 | 481 | break; |
482 | 482 | |
483 | 483 | } |
484 | 484 | |
485 | - if ( ! empty( $note ) ) { |
|
485 | + if ( ! empty($note)) { |
|
486 | 486 | |
487 | - give_insert_payment_note( $payment_id, $note ); |
|
487 | + give_insert_payment_note($payment_id, $note); |
|
488 | 488 | |
489 | 489 | } |
490 | 490 | } |
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | -add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 ); |
|
494 | +add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2); |
|
495 | 495 | |
496 | 496 | /** |
497 | 497 | * Process PayPal IPN Refunds |
@@ -502,32 +502,32 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return void |
504 | 504 | */ |
505 | -function give_process_paypal_refund( $data, $payment_id = 0 ) { |
|
505 | +function give_process_paypal_refund($data, $payment_id = 0) { |
|
506 | 506 | |
507 | 507 | // Collect payment details |
508 | 508 | |
509 | - if ( empty( $payment_id ) ) { |
|
509 | + if (empty($payment_id)) { |
|
510 | 510 | return; |
511 | 511 | } |
512 | 512 | |
513 | - if ( get_post_status( $payment_id ) == 'refunded' ) { |
|
513 | + if (get_post_status($payment_id) == 'refunded') { |
|
514 | 514 | return; // Only refund payments once |
515 | 515 | } |
516 | 516 | |
517 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
517 | + $payment_amount = give_get_payment_amount($payment_id); |
|
518 | 518 | $refund_amount = $data['payment_gross'] * - 1; |
519 | 519 | |
520 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
520 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
521 | 521 | |
522 | - give_insert_payment_note( $payment_id, sprintf( __( 'Partial PayPal refund processed: %s', 'give' ), $data['parent_txn_id'] ) ); |
|
522 | + give_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id'])); |
|
523 | 523 | |
524 | 524 | return; // This is a partial refund |
525 | 525 | |
526 | 526 | } |
527 | 527 | |
528 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
529 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
530 | - give_update_payment_status( $payment_id, 'refunded' ); |
|
528 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code'])); |
|
529 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id'])); |
|
530 | + give_update_payment_status($payment_id, 'refunded'); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -539,24 +539,24 @@ discard block |
||
539 | 539 | * |
540 | 540 | * @return string |
541 | 541 | */ |
542 | -function give_get_paypal_redirect( $ssl_check = false ) { |
|
542 | +function give_get_paypal_redirect($ssl_check = false) { |
|
543 | 543 | |
544 | - if ( is_ssl() || ! $ssl_check ) { |
|
544 | + if (is_ssl() || ! $ssl_check) { |
|
545 | 545 | $protocal = 'https://'; |
546 | 546 | } else { |
547 | 547 | $protocal = 'http://'; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Check the current payment mode |
551 | - if ( give_is_test_mode() ) { |
|
551 | + if (give_is_test_mode()) { |
|
552 | 552 | // Test mode |
553 | - $paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
553 | + $paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
554 | 554 | } else { |
555 | 555 | // Live mode |
556 | - $paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr'; |
|
556 | + $paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr'; |
|
557 | 557 | } |
558 | 558 | |
559 | - return apply_filters( 'give_paypal_uri', $paypal_uri ); |
|
559 | + return apply_filters('give_paypal_uri', $paypal_uri); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
@@ -566,8 +566,8 @@ discard block |
||
566 | 566 | * @return string |
567 | 567 | */ |
568 | 568 | function give_get_paypal_page_style() { |
569 | - $page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) ); |
|
570 | - return apply_filters( 'give_paypal_page_style', $page_style ); |
|
569 | + $page_style = trim(give_get_option('paypal_page_style', 'PayPal')); |
|
570 | + return apply_filters('give_paypal_page_style', $page_style); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -582,27 +582,27 @@ discard block |
||
582 | 582 | * @return string |
583 | 583 | * |
584 | 584 | */ |
585 | -function give_paypal_success_page_content( $content ) { |
|
585 | +function give_paypal_success_page_content($content) { |
|
586 | 586 | |
587 | - if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) { |
|
587 | + if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) { |
|
588 | 588 | return $content; |
589 | 589 | } |
590 | 590 | |
591 | - $payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false; |
|
591 | + $payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false; |
|
592 | 592 | |
593 | - if ( ! $payment_id ) { |
|
593 | + if ( ! $payment_id) { |
|
594 | 594 | $session = give_get_purchase_session(); |
595 | - $payment_id = give_get_purchase_id_by_key( $session['purchase_key'] ); |
|
595 | + $payment_id = give_get_purchase_id_by_key($session['purchase_key']); |
|
596 | 596 | } |
597 | 597 | |
598 | - $payment = get_post( $payment_id ); |
|
598 | + $payment = get_post($payment_id); |
|
599 | 599 | |
600 | - if ( $payment && 'pending' == $payment->post_status ) { |
|
600 | + if ($payment && 'pending' == $payment->post_status) { |
|
601 | 601 | |
602 | 602 | // Payment is still pending so show processing indicator to fix the Race Condition |
603 | 603 | ob_start(); |
604 | 604 | |
605 | - give_get_template_part( 'payment', 'processing' ); |
|
605 | + give_get_template_part('payment', 'processing'); |
|
606 | 606 | |
607 | 607 | $content = ob_get_clean(); |
608 | 608 | |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | |
613 | 613 | } |
614 | 614 | |
615 | -add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' ); |
|
615 | +add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content'); |
|
616 | 616 | |
617 | 617 | /** |
618 | 618 | * Given a Payment ID, extract the transaction ID |
@@ -623,22 +623,22 @@ discard block |
||
623 | 623 | * |
624 | 624 | * @return string Transaction ID |
625 | 625 | */ |
626 | -function give_paypal_get_payment_transaction_id( $payment_id ) { |
|
626 | +function give_paypal_get_payment_transaction_id($payment_id) { |
|
627 | 627 | |
628 | 628 | $transaction_id = ''; |
629 | - $notes = give_get_payment_notes( $payment_id ); |
|
629 | + $notes = give_get_payment_notes($payment_id); |
|
630 | 630 | |
631 | - foreach ( $notes as $note ) { |
|
632 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
631 | + foreach ($notes as $note) { |
|
632 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
633 | 633 | $transaction_id = $match[1]; |
634 | 634 | continue; |
635 | 635 | } |
636 | 636 | } |
637 | 637 | |
638 | - return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
638 | + return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id); |
|
639 | 639 | } |
640 | 640 | |
641 | -add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 ); |
|
641 | +add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1); |
|
642 | 642 | |
643 | 643 | /** |
644 | 644 | * Given a transaction ID, generate a link to the PayPal transaction ID details |
@@ -650,13 +650,13 @@ discard block |
||
650 | 650 | * |
651 | 651 | * @return string A link to the PayPal transaction details |
652 | 652 | */ |
653 | -function give_paypal_link_transaction_id( $transaction_id, $payment_id ) { |
|
653 | +function give_paypal_link_transaction_id($transaction_id, $payment_id) { |
|
654 | 654 | |
655 | 655 | $paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id='; |
656 | - $transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
656 | + $transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>'; |
|
657 | 657 | |
658 | - return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url ); |
|
658 | + return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url); |
|
659 | 659 | |
660 | 660 | } |
661 | 661 | |
662 | -add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 ); |
|
662 | +add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param $data |
23 | 23 | */ |
24 | -function give_process_gateway_select( $data ) { |
|
25 | - if ( isset( $_POST['gateway_submit'] ) ) { |
|
26 | - wp_redirect( esc_url( add_query_arg( 'payment-mode', $_POST['payment-mode'] ) ) ); |
|
24 | +function give_process_gateway_select($data) { |
|
25 | + if (isset($_POST['gateway_submit'])) { |
|
26 | + wp_redirect(esc_url(add_query_arg('payment-mode', $_POST['payment-mode']))); |
|
27 | 27 | exit; |
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | -add_action( 'give_gateway_select', 'give_process_gateway_select' ); |
|
31 | +add_action('give_gateway_select', 'give_process_gateway_select'); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Loads a payment gateway via AJAX |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * @return void |
38 | 38 | */ |
39 | 39 | function give_load_ajax_gateway() { |
40 | - if ( isset( $_POST['give_payment_mode'] ) ) { |
|
41 | - do_action( 'give_purchase_form', $_POST['give_form_id'] ); |
|
40 | + if (isset($_POST['give_payment_mode'])) { |
|
41 | + do_action('give_purchase_form', $_POST['give_form_id']); |
|
42 | 42 | exit(); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | -add_action( 'wp_ajax_give_load_gateway', 'give_load_ajax_gateway' ); |
|
47 | -add_action( 'wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway' ); |
|
46 | +add_action('wp_ajax_give_load_gateway', 'give_load_ajax_gateway'); |
|
47 | +add_action('wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway'); |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Sets an error on checkout if no gateways are enabled |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | function give_no_gateway_error() { |
56 | 56 | $gateways = give_get_enabled_payment_gateways(); |
57 | 57 | |
58 | - if ( empty( $gateways ) ) { |
|
59 | - give_set_error( 'no_gateways', __( 'You must enable a payment gateway to use Give.', 'give' ) ); |
|
58 | + if (empty($gateways)) { |
|
59 | + give_set_error('no_gateways', __('You must enable a payment gateway to use Give.', 'give')); |
|
60 | 60 | } else { |
61 | - give_unset_error( 'no_gateways' ); |
|
61 | + give_unset_error('no_gateways'); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | -add_action( 'init', 'give_no_gateway_error' ); |
|
66 | 65 | \ No newline at end of file |
66 | +add_action('init', 'give_no_gateway_error'); |
|
67 | 67 | \ No newline at end of file |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
15 | -if ( ! class_exists( 'Give_License' ) ) : |
|
15 | +if ( ! class_exists('Give_License')) : |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Give_License Class |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * @param string $_optname |
39 | 39 | * @param string $_api_url |
40 | 40 | */ |
41 | - public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null ) { |
|
41 | + public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null) { |
|
42 | 42 | global $give_options; |
43 | 43 | |
44 | 44 | $this->file = $_file; |
45 | 45 | $this->item_name = $_item_name; |
46 | - $this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); |
|
46 | + $this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); |
|
47 | 47 | $this->version = $_version; |
48 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
48 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
49 | 49 | $this->author = $_author; |
50 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
50 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
51 | 51 | |
52 | 52 | |
53 | 53 | // Setup hooks |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | */ |
65 | 65 | private function includes() { |
66 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
66 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
67 | 67 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
68 | 68 | } |
69 | 69 | } |
@@ -77,18 +77,18 @@ discard block |
||
77 | 77 | private function hooks() { |
78 | 78 | |
79 | 79 | // Register settings |
80 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
80 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
81 | 81 | |
82 | 82 | // Activate license key on settings save |
83 | - add_action( 'admin_init', array( $this, 'activate_license' ) ); |
|
83 | + add_action('admin_init', array($this, 'activate_license')); |
|
84 | 84 | |
85 | 85 | // Deactivate license key |
86 | - add_action( 'admin_init', array( $this, 'deactivate_license' ) ); |
|
86 | + add_action('admin_init', array($this, 'deactivate_license')); |
|
87 | 87 | |
88 | 88 | // Updater |
89 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
89 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
90 | 90 | |
91 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
91 | + add_action('admin_notices', array($this, 'notices')); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function auto_updater() { |
102 | 102 | |
103 | - if ( 'valid' !== get_option( $this->item_shortname . '_license_active' ) ) { |
|
103 | + if ('valid' !== get_option($this->item_shortname.'_license_active')) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
@@ -127,20 +127,20 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @return array |
129 | 129 | */ |
130 | - public function settings( $settings ) { |
|
130 | + public function settings($settings) { |
|
131 | 131 | |
132 | 132 | $give_license_settings = array( |
133 | 133 | array( |
134 | 134 | 'name' => $this->item_name, |
135 | - 'id' => $this->item_shortname . '_license_key', |
|
135 | + 'id' => $this->item_shortname.'_license_key', |
|
136 | 136 | 'desc' => '', |
137 | 137 | 'type' => 'license_key', |
138 | - 'options' => array( 'is_valid_license_option' => $this->item_shortname . '_license_active' ), |
|
138 | + 'options' => array('is_valid_license_option' => $this->item_shortname.'_license_active'), |
|
139 | 139 | 'size' => 'regular' |
140 | 140 | ) |
141 | 141 | ); |
142 | 142 | |
143 | - return array_merge( $settings, $give_license_settings ); |
|
143 | + return array_merge($settings, $give_license_settings); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -152,18 +152,18 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - public function license_settings_content( $settings ) { |
|
155 | + public function license_settings_content($settings) { |
|
156 | 156 | |
157 | 157 | $give_license_settings = array( |
158 | 158 | array( |
159 | - 'name' => __( 'Add-on Licenses', 'give' ), |
|
159 | + 'name' => __('Add-on Licenses', 'give'), |
|
160 | 160 | 'desc' => '<hr>', |
161 | 161 | 'type' => 'give_title', |
162 | 162 | 'id' => 'give_title' |
163 | 163 | ), |
164 | 164 | ); |
165 | 165 | |
166 | - return array_merge( $settings, $give_license_settings ); |
|
166 | + return array_merge($settings, $give_license_settings); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -175,34 +175,34 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function activate_license() { |
177 | 177 | |
178 | - if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
178 | + if ( ! isset($_POST[$this->item_shortname.'_license_key'])) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | - foreach ( $_POST as $key => $value ) { |
|
183 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
182 | + foreach ($_POST as $key => $value) { |
|
183 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
184 | 184 | // Don't activate a key when deactivating a different key |
185 | 185 | return; |
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) { |
|
189 | + if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) { |
|
190 | 190 | |
191 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
191 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
195 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
195 | + if ( ! current_user_can('manage_give_settings')) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | - if ( 'valid' === get_option( $this->item_shortname . '_license_active' ) ) { |
|
199 | + if ('valid' === get_option($this->item_shortname.'_license_active')) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | - $license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
203 | + $license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
204 | 204 | |
205 | - if ( empty( $license ) ) { |
|
205 | + if (empty($license)) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $api_params = array( |
211 | 211 | 'edd_action' => 'activate_license', //never change from "edd_" to "give_"! |
212 | 212 | 'license' => $license, |
213 | - 'item_name' => urlencode( $this->item_name ), |
|
213 | + 'item_name' => urlencode($this->item_name), |
|
214 | 214 | 'url' => home_url() |
215 | 215 | ); |
216 | 216 | |
@@ -225,22 +225,22 @@ discard block |
||
225 | 225 | ); |
226 | 226 | |
227 | 227 | // Make sure there are no errors |
228 | - if ( is_wp_error( $response ) ) { |
|
228 | + if (is_wp_error($response)) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Tell WordPress to look for updates |
233 | - set_site_transient( 'update_plugins', null ); |
|
233 | + set_site_transient('update_plugins', null); |
|
234 | 234 | |
235 | 235 | // Decode license data |
236 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
236 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
237 | 237 | |
238 | - update_option( $this->item_shortname . '_license_active', $license_data->license ); |
|
238 | + update_option($this->item_shortname.'_license_active', $license_data->license); |
|
239 | 239 | |
240 | - if ( ! (bool) $license_data->success ) { |
|
241 | - set_transient( 'give_license_error', $license_data, 1000 ); |
|
240 | + if ( ! (bool) $license_data->success) { |
|
241 | + set_transient('give_license_error', $license_data, 1000); |
|
242 | 242 | } else { |
243 | - delete_transient( 'give_license_error' ); |
|
243 | + delete_transient('give_license_error'); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -253,28 +253,28 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function deactivate_license() { |
255 | 255 | |
256 | - if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) { |
|
256 | + if ( ! isset($_POST[$this->item_shortname.'_license_key'])) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | 259 | |
260 | - if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) { |
|
260 | + if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) { |
|
261 | 261 | |
262 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
262 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
266 | + if ( ! current_user_can('manage_give_settings')) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | 270 | // Run on deactivate button press |
271 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
271 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
272 | 272 | |
273 | 273 | // Data to send to the API |
274 | 274 | $api_params = array( |
275 | 275 | 'edd_action' => 'deactivate_license', //never change from "edd_" to "give_"! |
276 | 276 | 'license' => $this->license, |
277 | - 'item_name' => urlencode( $this->item_name ), |
|
277 | + 'item_name' => urlencode($this->item_name), |
|
278 | 278 | 'url' => home_url() |
279 | 279 | ); |
280 | 280 | |
@@ -290,19 +290,19 @@ discard block |
||
290 | 290 | |
291 | 291 | |
292 | 292 | // Make sure there are no errors |
293 | - if ( is_wp_error( $response ) ) { |
|
293 | + if (is_wp_error($response)) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Decode the license data |
298 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
298 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
299 | 299 | |
300 | - delete_option( $this->item_shortname . '_license_active' ); |
|
300 | + delete_option($this->item_shortname.'_license_active'); |
|
301 | 301 | |
302 | - if ( ! (bool) $license_data->success ) { |
|
303 | - set_transient( 'give_license_error', $license_data, 1000 ); |
|
302 | + if ( ! (bool) $license_data->success) { |
|
303 | + set_transient('give_license_error', $license_data, 1000); |
|
304 | 304 | } else { |
305 | - delete_transient( 'give_license_error' ); |
|
305 | + delete_transient('give_license_error'); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | } |
@@ -316,57 +316,57 @@ discard block |
||
316 | 316 | */ |
317 | 317 | public function notices() { |
318 | 318 | |
319 | - if ( ! isset( $_GET['page'] ) || 'give-settings' !== $_GET['page'] ) { |
|
319 | + if ( ! isset($_GET['page']) || 'give-settings' !== $_GET['page']) { |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | - if ( ! isset( $_GET['tab'] ) || 'licenses' !== $_GET['tab'] ) { |
|
323 | + if ( ! isset($_GET['tab']) || 'licenses' !== $_GET['tab']) { |
|
324 | 324 | return; |
325 | 325 | } |
326 | 326 | |
327 | - $license_error = get_transient( 'give_license_error' ); |
|
327 | + $license_error = get_transient('give_license_error'); |
|
328 | 328 | |
329 | - if ( false === $license_error ) { |
|
329 | + if (false === $license_error) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
333 | - if ( ! empty( $license_error->error ) ) { |
|
333 | + if ( ! empty($license_error->error)) { |
|
334 | 334 | |
335 | - switch ( $license_error->error ) { |
|
335 | + switch ($license_error->error) { |
|
336 | 336 | |
337 | 337 | case 'item_name_mismatch' : |
338 | 338 | |
339 | - $message = __( 'This license does not belong to the product you have entered it for.', 'give' ); |
|
339 | + $message = __('This license does not belong to the product you have entered it for.', 'give'); |
|
340 | 340 | break; |
341 | 341 | |
342 | 342 | case 'no_activations_left' : |
343 | 343 | |
344 | - $message = __( 'This license does not have any activations left.', 'give' ); |
|
344 | + $message = __('This license does not have any activations left.', 'give'); |
|
345 | 345 | break; |
346 | 346 | |
347 | 347 | case 'expired' : |
348 | 348 | |
349 | - $message = __( 'This license key is expired. Please renew it.', 'give' ); |
|
349 | + $message = __('This license key is expired. Please renew it.', 'give'); |
|
350 | 350 | break; |
351 | 351 | |
352 | 352 | default : |
353 | 353 | |
354 | - $message = sprintf( __( 'There was a problem activating your license key, please try again or contact support. Error code: %s', 'give' ), $license_error->error ); |
|
354 | + $message = sprintf(__('There was a problem activating your license key, please try again or contact support. Error code: %s', 'give'), $license_error->error); |
|
355 | 355 | break; |
356 | 356 | |
357 | 357 | } |
358 | 358 | |
359 | 359 | } |
360 | 360 | |
361 | - if ( ! empty( $message ) ) { |
|
361 | + if ( ! empty($message)) { |
|
362 | 362 | |
363 | 363 | echo '<div class="error">'; |
364 | - echo '<p>' . $message . '</p>'; |
|
364 | + echo '<p>'.$message.'</p>'; |
|
365 | 365 | echo '</div>'; |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - delete_transient( 'give_license_error' ); |
|
369 | + delete_transient('give_license_error'); |
|
370 | 370 | |
371 | 371 | } |
372 | 372 | } |
@@ -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 | * @return string Login form |
27 | 27 | */ |
28 | -function give_login_form( $redirect = '' ) { |
|
28 | +function give_login_form($redirect = '') { |
|
29 | 29 | global $give_login_redirect; |
30 | 30 | |
31 | - if ( empty( $redirect ) ) { |
|
31 | + if (empty($redirect)) { |
|
32 | 32 | $redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url()); |
33 | 33 | } |
34 | 34 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | |
37 | 37 | ob_start(); |
38 | 38 | |
39 | - give_get_template_part( 'shortcode', 'login' ); |
|
39 | + give_get_template_part('shortcode', 'login'); |
|
40 | 40 | |
41 | - return apply_filters( 'give_login_form', ob_get_clean() ); |
|
41 | + return apply_filters('give_login_form', ob_get_clean()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return string Register form |
54 | 54 | */ |
55 | -function give_register_form( $redirect = '' ) { |
|
55 | +function give_register_form($redirect = '') { |
|
56 | 56 | global $give_options, $give_register_redirect; |
57 | 57 | |
58 | - if ( empty( $redirect ) ) { |
|
58 | + if (empty($redirect)) { |
|
59 | 59 | $redirect = give_get_current_page_url(); |
60 | 60 | } |
61 | 61 | |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | |
64 | 64 | ob_start(); |
65 | 65 | |
66 | - if ( ! is_user_logged_in() ) { |
|
67 | - give_get_template_part( 'shortcode', 'register' ); |
|
66 | + if ( ! is_user_logged_in()) { |
|
67 | + give_get_template_part('shortcode', 'register'); |
|
68 | 68 | } |
69 | 69 | |
70 | - return apply_filters( 'give_register_form', ob_get_clean() ); |
|
70 | + return apply_filters('give_register_form', ob_get_clean()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -79,34 +79,34 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return void |
81 | 81 | */ |
82 | -function give_process_login_form( $data ) { |
|
83 | - if ( wp_verify_nonce( $data['give_login_nonce'], 'give-login-nonce' ) ) { |
|
84 | - $user_data = get_user_by( 'login', $data['give_user_login'] ); |
|
85 | - if ( ! $user_data ) { |
|
86 | - $user_data = get_user_by( 'email', $data['give_user_login'] ); |
|
82 | +function give_process_login_form($data) { |
|
83 | + if (wp_verify_nonce($data['give_login_nonce'], 'give-login-nonce')) { |
|
84 | + $user_data = get_user_by('login', $data['give_user_login']); |
|
85 | + if ( ! $user_data) { |
|
86 | + $user_data = get_user_by('email', $data['give_user_login']); |
|
87 | 87 | } |
88 | - if ( $user_data ) { |
|
88 | + if ($user_data) { |
|
89 | 89 | $user_ID = $user_data->ID; |
90 | 90 | $user_email = $user_data->user_email; |
91 | - if ( wp_check_password( $data['give_user_pass'], $user_data->user_pass, $user_data->ID ) ) { |
|
92 | - give_log_user_in( $user_data->ID, $data['give_user_login'], $data['give_user_pass'] ); |
|
91 | + if (wp_check_password($data['give_user_pass'], $user_data->user_pass, $user_data->ID)) { |
|
92 | + give_log_user_in($user_data->ID, $data['give_user_login'], $data['give_user_pass']); |
|
93 | 93 | } else { |
94 | - give_set_error( 'password_incorrect', __( 'The password you entered is incorrect.', 'give' ) ); |
|
94 | + give_set_error('password_incorrect', __('The password you entered is incorrect.', 'give')); |
|
95 | 95 | } |
96 | 96 | } else { |
97 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
97 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
98 | 98 | } |
99 | 99 | // Check for errors and redirect if none present |
100 | 100 | $errors = give_get_errors(); |
101 | - if ( ! $errors ) { |
|
102 | - $redirect = apply_filters( 'give_login_redirect', $data['give_redirect'], $user_ID ); |
|
103 | - wp_redirect( $redirect ); |
|
101 | + if ( ! $errors) { |
|
102 | + $redirect = apply_filters('give_login_redirect', $data['give_redirect'], $user_ID); |
|
103 | + wp_redirect($redirect); |
|
104 | 104 | give_die(); |
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | -add_action( 'give_user_login', 'give_process_login_form' ); |
|
109 | +add_action('give_user_login', 'give_process_login_form'); |
|
110 | 110 | |
111 | 111 | /** |
112 | 112 | * Log User In |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return void |
121 | 121 | */ |
122 | -function give_log_user_in( $user_id, $user_login, $user_pass ) { |
|
123 | - if ( $user_id < 1 ) { |
|
122 | +function give_log_user_in($user_id, $user_login, $user_pass) { |
|
123 | + if ($user_id < 1) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - wp_set_auth_cookie( $user_id ); |
|
128 | - wp_set_current_user( $user_id, $user_login ); |
|
129 | - do_action( 'wp_login', $user_login, get_userdata( $user_id ) ); |
|
130 | - do_action( 'give_log_user_in', $user_id, $user_login, $user_pass ); |
|
127 | + wp_set_auth_cookie($user_id); |
|
128 | + wp_set_current_user($user_id, $user_login); |
|
129 | + do_action('wp_login', $user_login, get_userdata($user_id)); |
|
130 | + do_action('give_log_user_in', $user_id, $user_login, $user_pass); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -140,70 +140,70 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return void |
142 | 142 | */ |
143 | -function give_process_register_form( $data ) { |
|
143 | +function give_process_register_form($data) { |
|
144 | 144 | |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | - if ( empty( $_POST['give_register_submit'] ) ) { |
|
149 | + if (empty($_POST['give_register_submit'])) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - do_action( 'give_pre_process_register_form' ); |
|
153 | + do_action('give_pre_process_register_form'); |
|
154 | 154 | |
155 | - if ( empty( $data['give_user_login'] ) ) { |
|
156 | - give_set_error( 'empty_username', __( 'Invalid username.', 'give' ) ); |
|
155 | + if (empty($data['give_user_login'])) { |
|
156 | + give_set_error('empty_username', __('Invalid username.', 'give')); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( username_exists( $data['give_user_login'] ) ) { |
|
160 | - give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) ); |
|
159 | + if (username_exists($data['give_user_login'])) { |
|
160 | + give_set_error('username_unavailable', __('Username already taken.', 'give')); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! validate_username( $data['give_user_login'] ) ) { |
|
164 | - give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) ); |
|
163 | + if ( ! validate_username($data['give_user_login'])) { |
|
164 | + give_set_error('username_invalid', __('Invalid username.', 'give')); |
|
165 | 165 | } |
166 | 166 | |
167 | - if ( email_exists( $data['give_user_email'] ) ) { |
|
168 | - give_set_error( 'email_unavailable', __( 'Email address already taken.', 'give' ) ); |
|
167 | + if (email_exists($data['give_user_email'])) { |
|
168 | + give_set_error('email_unavailable', __('Email address already taken.', 'give')); |
|
169 | 169 | } |
170 | 170 | |
171 | - if ( empty( $data['give_user_email'] ) || ! is_email( $data['give_user_email'] ) ) { |
|
172 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
171 | + if (empty($data['give_user_email']) || ! is_email($data['give_user_email'])) { |
|
172 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
173 | 173 | } |
174 | 174 | |
175 | - if ( ! empty( $data['give_payment_email'] ) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email( $data['give_payment_email'] ) ) { |
|
176 | - give_set_error( 'payment_email_invalid', __( 'Invalid payment email.', 'give' ) ); |
|
175 | + if ( ! empty($data['give_payment_email']) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email($data['give_payment_email'])) { |
|
176 | + give_set_error('payment_email_invalid', __('Invalid payment email.', 'give')); |
|
177 | 177 | } |
178 | 178 | |
179 | - if ( empty( $_POST['give_user_pass'] ) ) { |
|
180 | - give_set_error( 'empty_password', __( 'Please enter a password.', 'give' ) ); |
|
179 | + if (empty($_POST['give_user_pass'])) { |
|
180 | + give_set_error('empty_password', __('Please enter a password.', 'give')); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( ( ! empty( $_POST['give_user_pass'] ) && empty( $_POST['give_user_pass2'] ) ) || ( $_POST['give_user_pass'] !== $_POST['give_user_pass2'] ) ) { |
|
184 | - give_set_error( 'password_mismatch', __( 'Passwords don\'t match.', 'give' ) ); |
|
183 | + if (( ! empty($_POST['give_user_pass']) && empty($_POST['give_user_pass2'])) || ($_POST['give_user_pass'] !== $_POST['give_user_pass2'])) { |
|
184 | + give_set_error('password_mismatch', __('Passwords don\'t match.', 'give')); |
|
185 | 185 | } |
186 | 186 | |
187 | - do_action( 'give_process_register_form' ); |
|
187 | + do_action('give_process_register_form'); |
|
188 | 188 | |
189 | 189 | // Check for errors and redirect if none present |
190 | 190 | $errors = give_get_errors(); |
191 | 191 | |
192 | - if ( empty( $errors ) ) { |
|
192 | + if (empty($errors)) { |
|
193 | 193 | |
194 | - $redirect = apply_filters( 'give_register_redirect', $data['give_redirect'] ); |
|
194 | + $redirect = apply_filters('give_register_redirect', $data['give_redirect']); |
|
195 | 195 | |
196 | - give_register_and_login_new_user( array( |
|
196 | + give_register_and_login_new_user(array( |
|
197 | 197 | 'user_login' => $data['give_user_login'], |
198 | 198 | 'user_pass' => $data['give_user_pass'], |
199 | 199 | 'user_email' => $data['give_user_email'], |
200 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
201 | - 'role' => get_option( 'default_role' ) |
|
202 | - ) ); |
|
200 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
201 | + 'role' => get_option('default_role') |
|
202 | + )); |
|
203 | 203 | |
204 | - wp_redirect( $redirect ); |
|
204 | + wp_redirect($redirect); |
|
205 | 205 | give_die(); |
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | -add_action( 'give_user_register', 'give_process_register_form' ); |
|
210 | 209 | \ No newline at end of file |
210 | +add_action('give_user_register', 'give_process_register_form'); |
|
211 | 211 | \ 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 | |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array $output Response messages |
25 | 25 | */ |
26 | -function give_edit_customer( $args ) { |
|
26 | +function give_edit_customer($args) { |
|
27 | 27 | |
28 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
28 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
29 | 29 | |
30 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
31 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ) ); |
|
30 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
31 | + wp_die(__('You do not have permission to edit this donor.', 'give')); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( empty( $args ) ) { |
|
34 | + if (empty($args)) { |
|
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | $customer_id = (int) $args['customerinfo']['id']; |
40 | 40 | $nonce = $args['_wpnonce']; |
41 | 41 | |
42 | - if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) { |
|
43 | - wp_die( __( 'Cheatin\' eh?!', 'give' ) ); |
|
42 | + if ( ! wp_verify_nonce($nonce, 'edit-customer')) { |
|
43 | + wp_die(__('Cheatin\' eh?!', 'give')); |
|
44 | 44 | } |
45 | 45 | |
46 | - $customer = new Give_Customer( $customer_id ); |
|
47 | - if ( empty( $customer->id ) ) { |
|
46 | + $customer = new Give_Customer($customer_id); |
|
47 | + if (empty($customer->id)) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | 'user_id' => 0 |
55 | 55 | ); |
56 | 56 | |
57 | - $customer_info = wp_parse_args( $customer_info, $defaults ); |
|
57 | + $customer_info = wp_parse_args($customer_info, $defaults); |
|
58 | 58 | |
59 | - if ( ! is_email( $customer_info['email'] ) ) { |
|
60 | - give_set_error( 'give-invalid-email', __( 'Please enter a valid email address.', 'give' ) ); |
|
59 | + if ( ! is_email($customer_info['email'])) { |
|
60 | + give_set_error('give-invalid-email', __('Please enter a valid email address.', 'give')); |
|
61 | 61 | } |
62 | 62 | |
63 | - if ( (int) $customer_info['user_id'] != (int) $customer->user_id ) { |
|
63 | + if ((int) $customer_info['user_id'] != (int) $customer->user_id) { |
|
64 | 64 | |
65 | 65 | // Make sure we don't already have this user attached to a customer |
66 | - if ( ! empty( $customer_info['user_id'] ) && false !== Give()->customers->get_customer_by( 'user_id', $customer_info['user_id'] ) ) { |
|
67 | - give_set_error( 'give-invalid-customer-user_id', sprintf( __( 'The User ID %d is already associated with a different donor.', 'give' ), $customer_info['user_id'] ) ); |
|
66 | + if ( ! empty($customer_info['user_id']) && false !== Give()->customers->get_customer_by('user_id', $customer_info['user_id'])) { |
|
67 | + give_set_error('give-invalid-customer-user_id', sprintf(__('The User ID %d is already associated with a different donor.', 'give'), $customer_info['user_id'])); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Make sure it's actually a user |
71 | - $user = get_user_by( 'id', $customer_info['user_id'] ); |
|
72 | - if ( ! empty( $customer_info['user_id'] ) && false === $user ) { |
|
73 | - give_set_error( 'give-invalid-user_id', sprintf( __( 'The User ID %d does not exist. Please assign an existing user.', 'give' ), $customer_info['user_id'] ) ); |
|
71 | + $user = get_user_by('id', $customer_info['user_id']); |
|
72 | + if ( ! empty($customer_info['user_id']) && false === $user) { |
|
73 | + give_set_error('give-invalid-user_id', sprintf(__('The User ID %d does not exist. Please assign an existing user.', 'give'), $customer_info['user_id'])); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | } |
@@ -78,82 +78,82 @@ discard block |
||
78 | 78 | // Record this for later |
79 | 79 | $previous_user_id = $customer->user_id; |
80 | 80 | |
81 | - if ( give_get_errors() ) { |
|
81 | + if (give_get_errors()) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Setup the customer address, if present |
86 | 86 | $address = array(); |
87 | - if ( intval( $customer_info['user_id'] ) > 0 ) { |
|
87 | + if (intval($customer_info['user_id']) > 0) { |
|
88 | 88 | |
89 | - $current_address = get_user_meta( $customer_info['user_id'], '_give_user_address', true ); |
|
89 | + $current_address = get_user_meta($customer_info['user_id'], '_give_user_address', true); |
|
90 | 90 | |
91 | - if ( false === $current_address ) { |
|
92 | - $address['line1'] = isset( $customer_info['line1'] ) ? $customer_info['line1'] : ''; |
|
93 | - $address['line2'] = isset( $customer_info['line2'] ) ? $customer_info['line2'] : ''; |
|
94 | - $address['city'] = isset( $customer_info['city'] ) ? $customer_info['city'] : ''; |
|
95 | - $address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : ''; |
|
96 | - $address['zip'] = isset( $customer_info['zip'] ) ? $customer_info['zip'] : ''; |
|
97 | - $address['state'] = isset( $customer_info['state'] ) ? $customer_info['state'] : ''; |
|
91 | + if (false === $current_address) { |
|
92 | + $address['line1'] = isset($customer_info['line1']) ? $customer_info['line1'] : ''; |
|
93 | + $address['line2'] = isset($customer_info['line2']) ? $customer_info['line2'] : ''; |
|
94 | + $address['city'] = isset($customer_info['city']) ? $customer_info['city'] : ''; |
|
95 | + $address['country'] = isset($customer_info['country']) ? $customer_info['country'] : ''; |
|
96 | + $address['zip'] = isset($customer_info['zip']) ? $customer_info['zip'] : ''; |
|
97 | + $address['state'] = isset($customer_info['state']) ? $customer_info['state'] : ''; |
|
98 | 98 | } else { |
99 | - $current_address = wp_parse_args( $current_address, array( |
|
99 | + $current_address = wp_parse_args($current_address, array( |
|
100 | 100 | 'line1', |
101 | 101 | 'line2', |
102 | 102 | 'city', |
103 | 103 | 'zip', |
104 | 104 | 'state', |
105 | 105 | 'country' |
106 | - ) ); |
|
107 | - $address['line1'] = isset( $customer_info['line1'] ) ? $customer_info['line1'] : $current_address['line1']; |
|
108 | - $address['line2'] = isset( $customer_info['line2'] ) ? $customer_info['line2'] : $current_address['line2']; |
|
109 | - $address['city'] = isset( $customer_info['city'] ) ? $customer_info['city'] : $current_address['city']; |
|
110 | - $address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : $current_address['country']; |
|
111 | - $address['zip'] = isset( $customer_info['zip'] ) ? $customer_info['zip'] : $current_address['zip']; |
|
112 | - $address['state'] = isset( $customer_info['state'] ) ? $customer_info['state'] : $current_address['state']; |
|
106 | + )); |
|
107 | + $address['line1'] = isset($customer_info['line1']) ? $customer_info['line1'] : $current_address['line1']; |
|
108 | + $address['line2'] = isset($customer_info['line2']) ? $customer_info['line2'] : $current_address['line2']; |
|
109 | + $address['city'] = isset($customer_info['city']) ? $customer_info['city'] : $current_address['city']; |
|
110 | + $address['country'] = isset($customer_info['country']) ? $customer_info['country'] : $current_address['country']; |
|
111 | + $address['zip'] = isset($customer_info['zip']) ? $customer_info['zip'] : $current_address['zip']; |
|
112 | + $address['state'] = isset($customer_info['state']) ? $customer_info['state'] : $current_address['state']; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | 117 | // Sanitize the inputs |
118 | 118 | $customer_data = array(); |
119 | - $customer_data['name'] = strip_tags( stripslashes( $customer_info['name'] ) ); |
|
119 | + $customer_data['name'] = strip_tags(stripslashes($customer_info['name'])); |
|
120 | 120 | $customer_data['email'] = $customer_info['email']; |
121 | 121 | $customer_data['user_id'] = $customer_info['user_id']; |
122 | 122 | |
123 | - $customer_data = apply_filters( 'give_edit_customer_info', $customer_data, $customer_id ); |
|
124 | - $address = apply_filters( 'give_edit_customer_address', $address, $customer_id ); |
|
123 | + $customer_data = apply_filters('give_edit_customer_info', $customer_data, $customer_id); |
|
124 | + $address = apply_filters('give_edit_customer_address', $address, $customer_id); |
|
125 | 125 | |
126 | - $customer_data = array_map( 'sanitize_text_field', $customer_data ); |
|
127 | - $address = array_map( 'sanitize_text_field', $address ); |
|
126 | + $customer_data = array_map('sanitize_text_field', $customer_data); |
|
127 | + $address = array_map('sanitize_text_field', $address); |
|
128 | 128 | |
129 | - do_action( 'give_pre_edit_customer', $customer_id, $customer_data, $address ); |
|
129 | + do_action('give_pre_edit_customer', $customer_id, $customer_data, $address); |
|
130 | 130 | |
131 | 131 | $output = array(); |
132 | 132 | $previous_email = $customer->email; |
133 | 133 | |
134 | - if ( $customer->update( $customer_data ) ) { |
|
134 | + if ($customer->update($customer_data)) { |
|
135 | 135 | |
136 | - if ( ! empty( $customer->user_id ) && $customer->user_id > 0 ) { |
|
137 | - update_user_meta( $customer->user_id, '_give_user_address', $address ); |
|
136 | + if ( ! empty($customer->user_id) && $customer->user_id > 0) { |
|
137 | + update_user_meta($customer->user_id, '_give_user_address', $address); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // Update some payment meta if we need to |
141 | - $payments_array = explode( ',', $customer->payment_ids ); |
|
141 | + $payments_array = explode(',', $customer->payment_ids); |
|
142 | 142 | |
143 | - if ( $customer->email != $previous_email ) { |
|
144 | - foreach ( $payments_array as $payment_id ) { |
|
145 | - give_update_payment_meta( $payment_id, 'email', $customer->email ); |
|
143 | + if ($customer->email != $previous_email) { |
|
144 | + foreach ($payments_array as $payment_id) { |
|
145 | + give_update_payment_meta($payment_id, 'email', $customer->email); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if ( $customer->user_id != $previous_user_id ) { |
|
150 | - foreach ( $payments_array as $payment_id ) { |
|
151 | - give_update_payment_meta( $payment_id, '_give_payment_user_id', $customer->user_id ); |
|
149 | + if ($customer->user_id != $previous_user_id) { |
|
150 | + foreach ($payments_array as $payment_id) { |
|
151 | + give_update_payment_meta($payment_id, '_give_payment_user_id', $customer->user_id); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | 155 | $output['success'] = true; |
156 | - $customer_data = array_merge( $customer_data, $address ); |
|
156 | + $customer_data = array_merge($customer_data, $address); |
|
157 | 157 | $output['customer_info'] = $customer_data; |
158 | 158 | |
159 | 159 | } else { |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'give_post_edit_customer', $customer_id, $customer_data ); |
|
165 | + do_action('give_post_edit_customer', $customer_id, $customer_data); |
|
166 | 166 | |
167 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
168 | - header( 'Content-Type: application/json' ); |
|
169 | - echo json_encode( $output ); |
|
167 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
168 | + header('Content-Type: application/json'); |
|
169 | + echo json_encode($output); |
|
170 | 170 | wp_die(); |
171 | 171 | } |
172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | } |
176 | 176 | |
177 | -add_action( 'give_edit-customer', 'give_edit_customer', 10, 1 ); |
|
177 | +add_action('give_edit-customer', 'give_edit_customer', 10, 1); |
|
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Save a customer note being added |
@@ -185,53 +185,53 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return int The Note ID that was saved, or 0 if nothing was saved |
187 | 187 | */ |
188 | -function give_customer_save_note( $args ) { |
|
188 | +function give_customer_save_note($args) { |
|
189 | 189 | |
190 | - $customer_view_role = apply_filters( 'give_view_customers_role', 'view_give_reports' ); |
|
190 | + $customer_view_role = apply_filters('give_view_customers_role', 'view_give_reports'); |
|
191 | 191 | |
192 | - if ( ! is_admin() || ! current_user_can( $customer_view_role ) ) { |
|
193 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ) ); |
|
192 | + if ( ! is_admin() || ! current_user_can($customer_view_role)) { |
|
193 | + wp_die(__('You do not have permission to edit this donor.', 'give')); |
|
194 | 194 | } |
195 | 195 | |
196 | - if ( empty( $args ) ) { |
|
196 | + if (empty($args)) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | - $customer_note = trim( sanitize_text_field( $args['customer_note'] ) ); |
|
200 | + $customer_note = trim(sanitize_text_field($args['customer_note'])); |
|
201 | 201 | $customer_id = (int) $args['customer_id']; |
202 | 202 | $nonce = $args['add_customer_note_nonce']; |
203 | 203 | |
204 | - if ( ! wp_verify_nonce( $nonce, 'add-customer-note' ) ) { |
|
205 | - wp_die( __( 'Cheatin\' eh?!', 'give' ) ); |
|
204 | + if ( ! wp_verify_nonce($nonce, 'add-customer-note')) { |
|
205 | + wp_die(__('Cheatin\' eh?!', 'give')); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( empty( $customer_note ) ) { |
|
209 | - give_set_error( 'empty-customer-note', __( 'A note is required.', 'give' ) ); |
|
208 | + if (empty($customer_note)) { |
|
209 | + give_set_error('empty-customer-note', __('A note is required.', 'give')); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( give_get_errors() ) { |
|
212 | + if (give_get_errors()) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - $customer = new Give_Customer( $customer_id ); |
|
217 | - $new_note = $customer->add_note( $customer_note ); |
|
216 | + $customer = new Give_Customer($customer_id); |
|
217 | + $new_note = $customer->add_note($customer_note); |
|
218 | 218 | |
219 | - do_action( 'give_pre_insert_customer_note', $customer_id, $new_note ); |
|
219 | + do_action('give_pre_insert_customer_note', $customer_id, $new_note); |
|
220 | 220 | |
221 | - if ( ! empty( $new_note ) && ! empty( $customer->id ) ) { |
|
221 | + if ( ! empty($new_note) && ! empty($customer->id)) { |
|
222 | 222 | |
223 | 223 | ob_start(); |
224 | 224 | ?> |
225 | 225 | <div class="customer-note-wrapper dashboard-comment-wrap comment-item"> |
226 | 226 | <span class="note-content-wrap"> |
227 | - <?php echo stripslashes( $new_note ); ?> |
|
227 | + <?php echo stripslashes($new_note); ?> |
|
228 | 228 | </span> |
229 | 229 | </div> |
230 | 230 | <?php |
231 | 231 | $output = ob_get_contents(); |
232 | 232 | ob_end_clean(); |
233 | 233 | |
234 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
234 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
235 | 235 | echo $output; |
236 | 236 | exit; |
237 | 237 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | } |
246 | 246 | |
247 | -add_action( 'give_add-customer-note', 'give_customer_save_note', 10, 1 ); |
|
247 | +add_action('give_add-customer-note', 'give_customer_save_note', 10, 1); |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Delete a customer |
@@ -255,87 +255,87 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return int Whether it was a successful deletion |
257 | 257 | */ |
258 | -function give_customer_delete( $args ) { |
|
258 | +function give_customer_delete($args) { |
|
259 | 259 | |
260 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
260 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
261 | 261 | |
262 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
263 | - wp_die( __( 'You do not have permission to delete donors.', 'give' ) ); |
|
262 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
263 | + wp_die(__('You do not have permission to delete donors.', 'give')); |
|
264 | 264 | } |
265 | 265 | |
266 | - if ( empty( $args ) ) { |
|
266 | + if (empty($args)) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $customer_id = (int) $args['customer_id']; |
271 | - $confirm = ! empty( $args['give-customer-delete-confirm'] ) ? true : false; |
|
272 | - $remove_data = ! empty( $args['give-customer-delete-records'] ) ? true : false; |
|
271 | + $confirm = ! empty($args['give-customer-delete-confirm']) ? true : false; |
|
272 | + $remove_data = ! empty($args['give-customer-delete-records']) ? true : false; |
|
273 | 273 | $nonce = $args['_wpnonce']; |
274 | 274 | |
275 | - if ( ! wp_verify_nonce( $nonce, 'delete-customer' ) ) { |
|
276 | - wp_die( __( 'Cheatin\' eh?!', 'give' ) ); |
|
275 | + if ( ! wp_verify_nonce($nonce, 'delete-customer')) { |
|
276 | + wp_die(__('Cheatin\' eh?!', 'give')); |
|
277 | 277 | } |
278 | 278 | |
279 | - if ( ! $confirm ) { |
|
280 | - give_set_error( 'customer-delete-no-confirm', __( 'Please confirm you want to delete this donor.', 'give' ) ); |
|
279 | + if ( ! $confirm) { |
|
280 | + give_set_error('customer-delete-no-confirm', __('Please confirm you want to delete this donor.', 'give')); |
|
281 | 281 | } |
282 | 282 | |
283 | - if ( give_get_errors() ) { |
|
284 | - wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id ) ); |
|
283 | + if (give_get_errors()) { |
|
284 | + wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer_id)); |
|
285 | 285 | exit; |
286 | 286 | } |
287 | 287 | |
288 | - $customer = new Give_Customer( $customer_id ); |
|
288 | + $customer = new Give_Customer($customer_id); |
|
289 | 289 | |
290 | - do_action( 'give_pre_delete_customer', $customer_id, $confirm, $remove_data ); |
|
290 | + do_action('give_pre_delete_customer', $customer_id, $confirm, $remove_data); |
|
291 | 291 | |
292 | 292 | $success = false; |
293 | 293 | |
294 | - if ( $customer->id > 0 ) { |
|
294 | + if ($customer->id > 0) { |
|
295 | 295 | |
296 | - $payments_array = explode( ',', $customer->payment_ids ); |
|
297 | - $success = Give()->customers->delete( $customer->id ); |
|
296 | + $payments_array = explode(',', $customer->payment_ids); |
|
297 | + $success = Give()->customers->delete($customer->id); |
|
298 | 298 | |
299 | - if ( $success ) { |
|
299 | + if ($success) { |
|
300 | 300 | |
301 | - if ( $remove_data ) { |
|
301 | + if ($remove_data) { |
|
302 | 302 | |
303 | 303 | // Remove all payments, logs, etc |
304 | - foreach ( $payments_array as $payment_id ) { |
|
305 | - give_delete_purchase( $payment_id ); |
|
304 | + foreach ($payments_array as $payment_id) { |
|
305 | + give_delete_purchase($payment_id); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | } else { |
309 | 309 | |
310 | 310 | // Just set the payments to customer_id of 0 |
311 | - foreach ( $payments_array as $payment_id ) { |
|
312 | - give_update_payment_meta( $payment_id, '_give_payment_customer_id', 0 ); |
|
311 | + foreach ($payments_array as $payment_id) { |
|
312 | + give_update_payment_meta($payment_id, '_give_payment_customer_id', 0); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | } |
316 | 316 | |
317 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted' ); |
|
317 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted'); |
|
318 | 318 | |
319 | 319 | } else { |
320 | 320 | |
321 | - give_set_error( 'give-donor-delete-failed', __( 'Error deleting donor.', 'give' ) ); |
|
322 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $customer_id ); |
|
321 | + give_set_error('give-donor-delete-failed', __('Error deleting donor.', 'give')); |
|
322 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$customer_id); |
|
323 | 323 | |
324 | 324 | } |
325 | 325 | |
326 | 326 | } else { |
327 | 327 | |
328 | - give_set_error( 'give-customer-delete-invalid-id', __( 'Invalid Donor ID.', 'give' ) ); |
|
329 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); |
|
328 | + give_set_error('give-customer-delete-invalid-id', __('Invalid Donor ID.', 'give')); |
|
329 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors'); |
|
330 | 330 | |
331 | 331 | } |
332 | 332 | |
333 | - wp_redirect( $redirect ); |
|
333 | + wp_redirect($redirect); |
|
334 | 334 | exit; |
335 | 335 | |
336 | 336 | } |
337 | 337 | |
338 | -add_action( 'give_delete-customer', 'give_customer_delete', 10, 1 ); |
|
338 | +add_action('give_delete-customer', 'give_customer_delete', 10, 1); |
|
339 | 339 | |
340 | 340 | /** |
341 | 341 | * Disconnect a user ID from a donor |
@@ -346,39 +346,39 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return bool If the disconnect was successful |
348 | 348 | */ |
349 | -function give_disconnect_customer_user_id( $args ) { |
|
349 | +function give_disconnect_customer_user_id($args) { |
|
350 | 350 | |
351 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
351 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
352 | 352 | |
353 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
354 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ) ); |
|
353 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
354 | + wp_die(__('You do not have permission to edit this donor.', 'give')); |
|
355 | 355 | } |
356 | 356 | |
357 | - if ( empty( $args ) ) { |
|
357 | + if (empty($args)) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $customer_id = (int) $args['customer_id']; |
362 | 362 | $nonce = $args['_wpnonce']; |
363 | 363 | |
364 | - if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) { |
|
365 | - wp_die( __( 'Cheatin\' eh?!', 'give' ) ); |
|
364 | + if ( ! wp_verify_nonce($nonce, 'edit-customer')) { |
|
365 | + wp_die(__('Cheatin\' eh?!', 'give')); |
|
366 | 366 | } |
367 | 367 | |
368 | - $customer = new Give_Customer( $customer_id ); |
|
369 | - if ( empty( $customer->id ) ) { |
|
368 | + $customer = new Give_Customer($customer_id); |
|
369 | + if (empty($customer->id)) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | - do_action( 'give_pre_customer_disconnect_user_id', $customer_id, $customer->user_id ); |
|
373 | + do_action('give_pre_customer_disconnect_user_id', $customer_id, $customer->user_id); |
|
374 | 374 | |
375 | - $customer_args = array( 'user_id' => 0 ); |
|
375 | + $customer_args = array('user_id' => 0); |
|
376 | 376 | |
377 | - if ( $customer->update( $customer_args ) ) { |
|
377 | + if ($customer->update($customer_args)) { |
|
378 | 378 | global $wpdb; |
379 | 379 | |
380 | - if ( ! empty( $customer->payment_ids ) ) { |
|
381 | - $wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )" ); |
|
380 | + if ( ! empty($customer->payment_ids)) { |
|
381 | + $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )"); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $output['success'] = true; |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | } else { |
387 | 387 | |
388 | 388 | $output['success'] = false; |
389 | - give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) ); |
|
389 | + give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor.', 'give')); |
|
390 | 390 | } |
391 | 391 | |
392 | - do_action( 'give_post_customer_disconnect_user_id', $customer_id ); |
|
392 | + do_action('give_post_customer_disconnect_user_id', $customer_id); |
|
393 | 393 | |
394 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
395 | - header( 'Content-Type: application/json' ); |
|
396 | - echo json_encode( $output ); |
|
394 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
395 | + header('Content-Type: application/json'); |
|
396 | + echo json_encode($output); |
|
397 | 397 | wp_die(); |
398 | 398 | } |
399 | 399 | |
@@ -401,4 +401,4 @@ discard block |
||
401 | 401 | |
402 | 402 | } |
403 | 403 | |
404 | -add_action( 'give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1 ); |
|
404 | +add_action('give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1); |