@@ -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 | |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string $message Fully formatted message |
43 | 43 | */ |
44 | -function give_email_template_tags( $message, $payment_data, $payment_id, $admin_notice = false ) { |
|
45 | - return give_do_email_tags( $message, $payment_id ); |
|
44 | +function give_email_template_tags($message, $payment_data, $payment_id, $admin_notice = false) { |
|
45 | + return give_do_email_tags($message, $payment_id); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -55,37 +55,37 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string $message Fully formatted message |
57 | 57 | */ |
58 | -function give_email_preview_template_tags( $message ) { |
|
58 | +function give_email_preview_template_tags($message) { |
|
59 | 59 | global $give_options; |
60 | 60 | |
61 | - $price = give_currency_filter( give_format_amount( 10.50 ) ); |
|
61 | + $price = give_currency_filter(give_format_amount(10.50)); |
|
62 | 62 | |
63 | 63 | $gateway = 'PayPal'; |
64 | 64 | |
65 | - $receipt_id = strtolower( md5( uniqid() ) ); |
|
65 | + $receipt_id = strtolower(md5(uniqid())); |
|
66 | 66 | |
67 | - $notes = __( 'These are some sample notes added to a donation.', 'give' ); |
|
67 | + $notes = __('These are some sample notes added to a donation.', 'give'); |
|
68 | 68 | |
69 | - $payment_id = rand( 1, 100 ); |
|
69 | + $payment_id = rand(1, 100); |
|
70 | 70 | |
71 | 71 | $user = wp_get_current_user(); |
72 | 72 | |
73 | - $message = str_replace( '{name}', $user->display_name, $message ); |
|
74 | - $message = str_replace( '{fullname}', $user->display_name, $message ); |
|
75 | - $message = str_replace( '{username}', $user->user_login, $message ); |
|
76 | - $message = str_replace( '{date}', date( get_option( 'date_format' ), current_time( 'timestamp' ) ), $message ); |
|
77 | - $message = str_replace( '{price}', $price, $message ); |
|
78 | - $message = str_replace( '{receipt_id}', $receipt_id, $message ); |
|
79 | - $message = str_replace( '{payment_method}', $gateway, $message ); |
|
80 | - $message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message ); |
|
81 | - $message = str_replace( '{product_notes}', $notes, $message ); |
|
82 | - $message = str_replace( '{payment_id}', $payment_id, $message ); |
|
83 | - $message = str_replace( '{receipt_link}', sprintf( __( '%1$sView it in your browser.%2$s', 'give' ), '<a href="' . esc_url( add_query_arg( array( |
|
73 | + $message = str_replace('{name}', $user->display_name, $message); |
|
74 | + $message = str_replace('{fullname}', $user->display_name, $message); |
|
75 | + $message = str_replace('{username}', $user->user_login, $message); |
|
76 | + $message = str_replace('{date}', date(get_option('date_format'), current_time('timestamp')), $message); |
|
77 | + $message = str_replace('{price}', $price, $message); |
|
78 | + $message = str_replace('{receipt_id}', $receipt_id, $message); |
|
79 | + $message = str_replace('{payment_method}', $gateway, $message); |
|
80 | + $message = str_replace('{sitename}', get_bloginfo('name'), $message); |
|
81 | + $message = str_replace('{product_notes}', $notes, $message); |
|
82 | + $message = str_replace('{payment_id}', $payment_id, $message); |
|
83 | + $message = str_replace('{receipt_link}', sprintf(__('%1$sView it in your browser.%2$s', 'give'), '<a href="'.esc_url(add_query_arg(array( |
|
84 | 84 | 'payment_key' => $receipt_id, |
85 | 85 | 'give_action' => 'view_receipt' |
86 | - ), home_url() ) ) . '">', '</a>' ), $message ); |
|
86 | + ), home_url())).'">', '</a>'), $message); |
|
87 | 87 | |
88 | - return wpautop( apply_filters( 'give_email_preview_template_tags', $message ) ); |
|
88 | + return wpautop(apply_filters('give_email_preview_template_tags', $message)); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -98,20 +98,20 @@ discard block |
||
98 | 98 | * @since 1.0 |
99 | 99 | * @return array|bool |
100 | 100 | */ |
101 | -add_filter( 'give_settings_emails', 'give_email_template_preview' ); |
|
101 | +add_filter('give_settings_emails', 'give_email_template_preview'); |
|
102 | 102 | |
103 | -function give_email_template_preview( $array ) { |
|
103 | +function give_email_template_preview($array) { |
|
104 | 104 | |
105 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
105 | + if ( ! current_user_can('manage_give_settings')) { |
|
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | $custom_field = array( |
109 | - 'name' => __( 'Preview Email', 'give' ), |
|
110 | - 'desc' => __( 'Click the buttons to preview emails.', 'give' ), |
|
109 | + 'name' => __('Preview Email', 'give'), |
|
110 | + 'desc' => __('Click the buttons to preview emails.', 'give'), |
|
111 | 111 | 'id' => 'give_email_preview_buttons', |
112 | 112 | 'type' => 'email_preview_buttons' |
113 | 113 | ); |
114 | - array_splice( $array, 5, 0, array( $custom_field ) ); |
|
114 | + array_splice($array, 5, 0, array($custom_field)); |
|
115 | 115 | |
116 | 116 | return $array; // splice in at position 3; |
117 | 117 | } |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | function give_email_preview_buttons_callback() { |
128 | 128 | ob_start(); |
129 | 129 | ?> |
130 | - <a href="<?php echo esc_url( add_query_arg( array( 'give_action' => 'preview_email' ), home_url() ) ); ?>" class="button-secondary" target="_blank" title="<?php _e( 'Donation Receipt Preview', 'give' ); ?> "><?php _e( 'Preview Donation Receipt', 'give' ); ?></a> |
|
131 | - <a href="<?php echo wp_nonce_url( add_query_arg( array( |
|
130 | + <a href="<?php echo esc_url(add_query_arg(array('give_action' => 'preview_email'), home_url())); ?>" class="button-secondary" target="_blank" title="<?php _e('Donation Receipt Preview', 'give'); ?> "><?php _e('Preview Donation Receipt', 'give'); ?></a> |
|
131 | + <a href="<?php echo wp_nonce_url(add_query_arg(array( |
|
132 | 132 | 'give_action' => 'send_test_email', |
133 | 133 | 'give-message' => 'sent-test-email' |
134 | - ) ), 'give-test-email' ); ?>" title="<?php _e( 'This will send a demo donation receipt to the emails listed below.', 'give' ); ?>" class="button-secondary"><?php _e( 'Send Test Email', 'give' ); ?></a> |
|
134 | + )), 'give-test-email'); ?>" title="<?php _e('This will send a demo donation receipt to the emails listed below.', 'give'); ?>" class="button-secondary"><?php _e('Send Test Email', 'give'); ?></a> |
|
135 | 135 | <?php |
136 | 136 | echo ob_get_clean(); |
137 | 137 | } |
@@ -144,27 +144,27 @@ discard block |
||
144 | 144 | */ |
145 | 145 | function give_display_email_template_preview() { |
146 | 146 | |
147 | - if ( empty( $_GET['give_action'] ) ) { |
|
147 | + if (empty($_GET['give_action'])) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | - if ( 'preview_email' !== $_GET['give_action'] ) { |
|
151 | + if ('preview_email' !== $_GET['give_action']) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | |
155 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
155 | + if ( ! current_user_can('manage_give_settings')) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | - Give()->emails->heading = __( 'Donation Receipt', 'give' ); |
|
159 | + Give()->emails->heading = __('Donation Receipt', 'give'); |
|
160 | 160 | |
161 | - echo Give()->emails->build_email( give_email_preview_template_tags( give_get_email_body_content( 0, array() ) ) ); |
|
161 | + echo Give()->emails->build_email(give_email_preview_template_tags(give_get_email_body_content(0, array()))); |
|
162 | 162 | |
163 | 163 | exit; |
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | -add_action( 'template_redirect', 'give_display_email_template_preview' ); |
|
167 | +add_action('template_redirect', 'give_display_email_template_preview'); |
|
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Email Template Body |
@@ -176,20 +176,20 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return string $email_body Body of the email |
178 | 178 | */ |
179 | -function give_get_email_body_content( $payment_id = 0, $payment_data = array() ) { |
|
179 | +function give_get_email_body_content($payment_id = 0, $payment_data = array()) { |
|
180 | 180 | global $give_options; |
181 | 181 | |
182 | - $default_email_body = __( "Dear", "give" ) . " {name},\n\n"; |
|
183 | - $default_email_body .= __( "Thank you for your donation. Your generosity is appreciated! Please click on the link below to view your receipt.", "give" ) . "\n\n" . '{receipt_link}'; |
|
182 | + $default_email_body = __("Dear", "give")." {name},\n\n"; |
|
183 | + $default_email_body .= __("Thank you for your donation. Your generosity is appreciated! Please click on the link below to view your receipt.", "give")."\n\n".'{receipt_link}'; |
|
184 | 184 | $default_email_body .= "\n\nSincerely,\n{sitename}"; |
185 | 185 | |
186 | - $email = isset( $give_options['donation_receipt'] ) ? stripslashes( $give_options['donation_receipt'] ) : $default_email_body; |
|
186 | + $email = isset($give_options['donation_receipt']) ? stripslashes($give_options['donation_receipt']) : $default_email_body; |
|
187 | 187 | |
188 | - $email_body = wpautop( $email ); |
|
188 | + $email_body = wpautop($email); |
|
189 | 189 | |
190 | - $email_body = apply_filters( 'give_donation_receipt_' . Give()->emails->get_template(), $email_body, $payment_id, $payment_data ); |
|
190 | + $email_body = apply_filters('give_donation_receipt_'.Give()->emails->get_template(), $email_body, $payment_id, $payment_data); |
|
191 | 191 | |
192 | - return apply_filters( 'give_donation_receipt', $email_body, $payment_id, $payment_data ); |
|
192 | + return apply_filters('give_donation_receipt', $email_body, $payment_id, $payment_data); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -202,37 +202,37 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return string $email_body Body of the email |
204 | 204 | */ |
205 | -function give_get_donation_notification_body_content( $payment_id = 0, $payment_data = array() ) { |
|
205 | +function give_get_donation_notification_body_content($payment_id = 0, $payment_data = array()) { |
|
206 | 206 | global $give_options; |
207 | 207 | |
208 | - $user_info = maybe_unserialize( $payment_data['user_info'] ); |
|
209 | - $email = give_get_payment_user_email( $payment_id ); |
|
208 | + $user_info = maybe_unserialize($payment_data['user_info']); |
|
209 | + $email = give_get_payment_user_email($payment_id); |
|
210 | 210 | |
211 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { |
|
212 | - $user_data = get_userdata( $user_info['id'] ); |
|
211 | + if (isset($user_info['id']) && $user_info['id'] > 0) { |
|
212 | + $user_data = get_userdata($user_info['id']); |
|
213 | 213 | $name = $user_data->display_name; |
214 | - } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { |
|
215 | - $name = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
214 | + } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { |
|
215 | + $name = $user_info['first_name'].' '.$user_info['last_name']; |
|
216 | 216 | } else { |
217 | 217 | $name = $email; |
218 | 218 | } |
219 | 219 | |
220 | - $gateway = give_get_gateway_admin_label( get_post_meta( $payment_id, '_give_payment_gateway', true ) ); |
|
220 | + $gateway = give_get_gateway_admin_label(get_post_meta($payment_id, '_give_payment_gateway', true)); |
|
221 | 221 | |
222 | - $default_email_body = __( 'Hello', 'give' ) . "\n\n" . __( 'A donation has been made', 'give' ) . ".\n\n"; |
|
223 | - $default_email_body .= sprintf( __( '%s sold:', 'give' ), give_get_forms_label_plural() ) . "\n\n"; |
|
222 | + $default_email_body = __('Hello', 'give')."\n\n".__('A donation has been made', 'give').".\n\n"; |
|
223 | + $default_email_body .= sprintf(__('%s sold:', 'give'), give_get_forms_label_plural())."\n\n"; |
|
224 | 224 | |
225 | - $default_email_body .= __( 'Donor: ', 'give' ) . " " . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n"; |
|
226 | - $default_email_body .= __( 'Amount: ', 'give' ) . " " . html_entity_decode( give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ) ) ), ENT_COMPAT, 'UTF-8' ) . "\n"; |
|
227 | - $default_email_body .= __( 'Payment Method: ', 'give' ) . " " . $gateway . "\n\n"; |
|
225 | + $default_email_body .= __('Donor: ', 'give')." ".html_entity_decode($name, ENT_COMPAT, 'UTF-8')."\n"; |
|
226 | + $default_email_body .= __('Amount: ', 'give')." ".html_entity_decode(give_currency_filter(give_format_amount(give_get_payment_amount($payment_id))), ENT_COMPAT, 'UTF-8')."\n"; |
|
227 | + $default_email_body .= __('Payment Method: ', 'give')." ".$gateway."\n\n"; |
|
228 | 228 | |
229 | - $default_email_body .= __( 'Thank you', 'give' ); |
|
229 | + $default_email_body .= __('Thank you', 'give'); |
|
230 | 230 | |
231 | - $email = isset( $give_options['donation_notification'] ) ? stripslashes( $give_options['donation_notification'] ) : $default_email_body; |
|
231 | + $email = isset($give_options['donation_notification']) ? stripslashes($give_options['donation_notification']) : $default_email_body; |
|
232 | 232 | |
233 | - $email_body = give_do_email_tags( $email, $payment_id ); |
|
233 | + $email_body = give_do_email_tags($email, $payment_id); |
|
234 | 234 | |
235 | - return apply_filters( 'give_donation_notification', wpautop( $email_body ), $payment_id, $payment_data ); |
|
235 | + return apply_filters('give_donation_notification', wpautop($email_body), $payment_id, $payment_data); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | * @since 1.0 |
246 | 246 | */ |
247 | 247 | function give_render_receipt_in_browser() { |
248 | - if ( ! isset( $_GET['payment_key'] ) ) { |
|
249 | - wp_die( __( 'Missing donation key.', 'give' ), __( 'Error', 'give' ) ); |
|
248 | + if ( ! isset($_GET['payment_key'])) { |
|
249 | + wp_die(__('Missing donation key.', 'give'), __('Error', 'give')); |
|
250 | 250 | } |
251 | 251 | |
252 | - $key = urlencode( $_GET['payment_key'] ); |
|
252 | + $key = urlencode($_GET['payment_key']); |
|
253 | 253 | |
254 | 254 | ob_start(); |
255 | 255 | //Disallows caching of the page |
256 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
256 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
257 | 257 | header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 |
258 | 258 | header("Cache-Control: post-check=0, pre-check=0", false); |
259 | 259 | header("Pragma: no-cache"); // HTTP/1.0 |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | <!DOCTYPE html> |
263 | 263 | <html lang="en"> |
264 | 264 | <head> |
265 | - <title><?php _e( 'Donation Receipt', 'give' ); ?></title> |
|
265 | + <title><?php _e('Donation Receipt', 'give'); ?></title> |
|
266 | 266 | <meta charset="utf-8" /> |
267 | 267 | |
268 | 268 | <!-- Further disallowing of caching of this page --> |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | |
277 | 277 | <?php wp_head(); ?> |
278 | 278 | </head> |
279 | - <body class="<?php echo apply_filters( 'give_receipt_page_body_class', 'give_receipt_page' ); ?>"> |
|
279 | + <body class="<?php echo apply_filters('give_receipt_page_body_class', 'give_receipt_page'); ?>"> |
|
280 | 280 | |
281 | 281 | <div id="give_receipt_wrapper"> |
282 | - <?php do_action( 'give_render_receipt_in_browser_before' ); ?> |
|
283 | - <?php echo do_shortcode( '[give_receipt payment_key=' . $key . ']' ); ?> |
|
284 | - <?php do_action( 'give_render_receipt_in_browser_after' ); ?> |
|
282 | + <?php do_action('give_render_receipt_in_browser_before'); ?> |
|
283 | + <?php echo do_shortcode('[give_receipt payment_key='.$key.']'); ?> |
|
284 | + <?php do_action('give_render_receipt_in_browser_after'); ?> |
|
285 | 285 | </div> |
286 | 286 | |
287 | 287 | <?php wp_footer(); ?> |
@@ -292,4 +292,4 @@ discard block |
||
292 | 292 | die(); |
293 | 293 | } |
294 | 294 | |
295 | -add_action( 'give_view_receipt', 'give_render_receipt_in_browser' ); |
|
295 | +add_action('give_view_receipt', 'give_render_receipt_in_browser'); |
@@ -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 | |
@@ -29,33 +29,33 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return void |
31 | 31 | */ |
32 | -function give_print_errors( $form_id ) { |
|
32 | +function give_print_errors($form_id) { |
|
33 | 33 | |
34 | 34 | $errors = give_get_errors(); |
35 | 35 | |
36 | - $request_form_id = isset( $_REQUEST['form-id'] ) ? intval( $_REQUEST['form-id'] ) : 0; |
|
36 | + $request_form_id = isset($_REQUEST['form-id']) ? intval($_REQUEST['form-id']) : 0; |
|
37 | 37 | |
38 | 38 | //Sanity checks first: Ensure that gateway returned errors display on the appropriate form |
39 | - if ( ! isset( $_POST['give_ajax'] ) && $request_form_id !== $form_id ) { |
|
39 | + if ( ! isset($_POST['give_ajax']) && $request_form_id !== $form_id) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - if ( $errors ) { |
|
44 | - $classes = apply_filters( 'give_error_class', array( |
|
43 | + if ($errors) { |
|
44 | + $classes = apply_filters('give_error_class', array( |
|
45 | 45 | 'give_errors' |
46 | - ) ); |
|
47 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
46 | + )); |
|
47 | + echo '<div class="'.implode(' ', $classes).'">'; |
|
48 | 48 | // Loop error codes and display errors |
49 | - foreach ( $errors as $error_id => $error ) { |
|
50 | - echo '<div class="give_error" id="give_error_' . $error_id . '"><p><strong>' . __( 'Error', 'give' ) . '</strong>: ' . $error . '</p></div>'; |
|
49 | + foreach ($errors as $error_id => $error) { |
|
50 | + echo '<div class="give_error" id="give_error_'.$error_id.'"><p><strong>'.__('Error', 'give').'</strong>: '.$error.'</p></div>'; |
|
51 | 51 | } |
52 | 52 | echo '</div>'; |
53 | 53 | give_clear_errors(); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | -add_action( 'give_purchase_form_before_personal_info', 'give_print_errors' ); |
|
58 | -add_action( 'give_ajax_checkout_errors', 'give_print_errors' ); |
|
57 | +add_action('give_purchase_form_before_personal_info', 'give_print_errors'); |
|
58 | +add_action('give_ajax_checkout_errors', 'give_print_errors'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Get Errors |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return mixed array if errors are present, false if none found |
69 | 69 | */ |
70 | 70 | function give_get_errors() { |
71 | - return Give()->session->get( 'give_errors' ); |
|
71 | + return Give()->session->get('give_errors'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return void |
86 | 86 | */ |
87 | -function give_set_error( $error_id, $error_message ) { |
|
87 | +function give_set_error($error_id, $error_message) { |
|
88 | 88 | $errors = give_get_errors(); |
89 | - if ( ! $errors ) { |
|
89 | + if ( ! $errors) { |
|
90 | 90 | $errors = array(); |
91 | 91 | } |
92 | - $errors[ $error_id ] = $error_message; |
|
93 | - Give()->session->set( 'give_errors', $errors ); |
|
92 | + $errors[$error_id] = $error_message; |
|
93 | + Give()->session->set('give_errors', $errors); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return void |
102 | 102 | */ |
103 | 103 | function give_clear_errors() { |
104 | - Give()->session->set( 'give_errors', null ); |
|
104 | + Give()->session->set('give_errors', null); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string |
116 | 116 | */ |
117 | -function give_unset_error( $error_id ) { |
|
117 | +function give_unset_error($error_id) { |
|
118 | 118 | $errors = give_get_errors(); |
119 | - if ( $errors ) { |
|
120 | - unset( $errors[ $error_id ] ); |
|
121 | - Give()->session->set( 'give_errors', $errors ); |
|
119 | + if ($errors) { |
|
120 | + unset($errors[$error_id]); |
|
121 | + Give()->session->set('give_errors', $errors); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return void |
130 | 130 | */ |
131 | 131 | function _give_die_handler() { |
132 | - if ( defined( 'GIVE_UNIT_TESTS' ) ) { |
|
132 | + if (defined('GIVE_UNIT_TESTS')) { |
|
133 | 133 | return '_give_die_handler'; |
134 | 134 | } else { |
135 | 135 | die(); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @since 1.0 |
145 | 145 | * @return void |
146 | 146 | */ |
147 | -function give_die( $message = '', $title = '', $status = 400 ) { |
|
148 | - add_filter( 'wp_die_ajax_handler', '_give_die_handler', 10, 3 ); |
|
149 | - add_filter( 'wp_die_handler', '_give_die_handler', 10, 3 ); |
|
150 | - wp_die( $message, $title, array( 'response' => $status ) ); |
|
147 | +function give_die($message = '', $title = '', $status = 400) { |
|
148 | + add_filter('wp_die_ajax_handler', '_give_die_handler', 10, 3); |
|
149 | + add_filter('wp_die_handler', '_give_die_handler', 10, 3); |
|
150 | + wp_die($message, $title, array('response' => $status)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return string $error |
164 | 164 | */ |
165 | -function give_output_error( $message, $echo = true, $error_id = 'warning' ) { |
|
166 | - $error = '<div class="give_errors" id="give_error_' . $error_id . '"><p class="give_error give_' . $error_id . '">' . $message . '</p></div>'; |
|
165 | +function give_output_error($message, $echo = true, $error_id = 'warning') { |
|
166 | + $error = '<div class="give_errors" id="give_error_'.$error_id.'"><p class="give_error give_'.$error_id.'">'.$message.'</p></div>'; |
|
167 | 167 | |
168 | - if ( $echo ) { |
|
168 | + if ($echo) { |
|
169 | 169 | echo $error; |
170 | 170 | } else { |
171 | 171 | return $error; |
@@ -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,37 +25,37 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return string $amount Newly sanitized amount |
27 | 27 | */ |
28 | -function give_sanitize_amount( $amount ) { |
|
28 | +function give_sanitize_amount($amount) { |
|
29 | 29 | $is_negative = false; |
30 | - $thousands_sep = give_get_option( 'thousands_separator', ',' ); |
|
31 | - $decimal_sep = give_get_option( 'decimal_separator', '.' ); |
|
30 | + $thousands_sep = give_get_option('thousands_separator', ','); |
|
31 | + $decimal_sep = give_get_option('decimal_separator', '.'); |
|
32 | 32 | |
33 | 33 | // Sanitize the amount |
34 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
35 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
36 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
37 | - } elseif ( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
38 | - $amount = str_replace( '.', '', $amount ); |
|
34 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
35 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
36 | + $amount = str_replace($thousands_sep, '', $amount); |
|
37 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
38 | + $amount = str_replace('.', '', $amount); |
|
39 | 39 | } |
40 | 40 | |
41 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
42 | - } elseif ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
43 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
41 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
42 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
43 | + $amount = str_replace($thousands_sep, '', $amount); |
|
44 | 44 | } |
45 | 45 | |
46 | - if ( $amount < 0 ) { |
|
46 | + if ($amount < 0) { |
|
47 | 47 | $is_negative = true; |
48 | 48 | } |
49 | 49 | |
50 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
51 | - $decimals = apply_filters( 'give_sanitize_amount_decimals', 2, $amount ); |
|
52 | - $amount = number_format( (double) $amount, $decimals, '.', '' ); |
|
50 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
51 | + $decimals = apply_filters('give_sanitize_amount_decimals', 2, $amount); |
|
52 | + $amount = number_format((double) $amount, $decimals, '.', ''); |
|
53 | 53 | |
54 | - if ( $is_negative ) { |
|
54 | + if ($is_negative) { |
|
55 | 55 | $amount *= - 1; |
56 | 56 | } |
57 | 57 | |
58 | - return apply_filters( 'give_sanitize_amount', $amount ); |
|
58 | + return apply_filters('give_sanitize_amount', $amount); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -68,47 +68,47 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string $amount Newly formatted amount or Price Not Available |
70 | 70 | */ |
71 | -function give_format_amount( $amount, $decimals = true ) { |
|
71 | +function give_format_amount($amount, $decimals = true) { |
|
72 | 72 | |
73 | - $thousands_sep = give_get_option( 'thousands_separator', ',' ); |
|
74 | - $decimal_sep = give_get_option( 'decimal_separator', '.' ); |
|
73 | + $thousands_sep = give_get_option('thousands_separator', ','); |
|
74 | + $decimal_sep = give_get_option('decimal_separator', '.'); |
|
75 | 75 | |
76 | 76 | // Format the amount |
77 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
78 | - $whole = substr( $amount, 0, $sep_found ); |
|
79 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
80 | - $amount = $whole . '.' . $part; |
|
77 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
78 | + $whole = substr($amount, 0, $sep_found); |
|
79 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
80 | + $amount = $whole.'.'.$part; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Strip , from the amount (if set as the thousands separator) |
84 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
85 | - $amount = str_replace( ',', '', $amount ); |
|
84 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
85 | + $amount = str_replace(',', '', $amount); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Strip . from the amount (if set as the thousands separator) AND , set to decimal separator |
89 | - if ( $thousands_sep == '.' && $decimal_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
90 | - $amount = explode( '.', $amount ); |
|
91 | - $array_count = count( $amount ); |
|
92 | - if ( $decimals == true ) { |
|
93 | - unset( $amount[ $array_count - 1 ] ); |
|
89 | + if ($thousands_sep == '.' && $decimal_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
90 | + $amount = explode('.', $amount); |
|
91 | + $array_count = count($amount); |
|
92 | + if ($decimals == true) { |
|
93 | + unset($amount[$array_count - 1]); |
|
94 | 94 | } |
95 | - $amount = implode( '', $amount ); |
|
95 | + $amount = implode('', $amount); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Strip ' ' from the amount (if set as the thousands separator) |
99 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
100 | - $amount = str_replace( ' ', '', $amount ); |
|
99 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
100 | + $amount = str_replace(' ', '', $amount); |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( empty( $amount ) ) { |
|
103 | + if (empty($amount)) { |
|
104 | 104 | $amount = 0; |
105 | 105 | } |
106 | 106 | |
107 | - $decimals = apply_filters( 'give_format_amount_decimals', $decimals ? 2 : 0, $amount ); |
|
107 | + $decimals = apply_filters('give_format_amount_decimals', $decimals ? 2 : 0, $amount); |
|
108 | 108 | |
109 | - $formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
109 | + $formatted = number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
110 | 110 | |
111 | - return apply_filters( 'give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
111 | + return apply_filters('give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | * @param $field_args |
120 | 120 | * @param $field |
121 | 121 | */ |
122 | -function give_format_admin_multilevel_amount( $field_args, $field ) { |
|
122 | +function give_format_admin_multilevel_amount($field_args, $field) { |
|
123 | 123 | |
124 | - if ( empty( $field->value ) ) { |
|
124 | + if (empty($field->value)) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | - $field->value = give_format_amount( $field->value ); |
|
128 | + $field->value = give_format_amount($field->value); |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
@@ -138,25 +138,25 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return array $currency Currencies displayed correctly |
140 | 140 | */ |
141 | -function give_currency_filter( $price = '', $currency = '' ) { |
|
142 | - if ( empty( $currency ) ) { |
|
141 | +function give_currency_filter($price = '', $currency = '') { |
|
142 | + if (empty($currency)) { |
|
143 | 143 | |
144 | 144 | $currency = give_get_currency(); |
145 | 145 | |
146 | 146 | } |
147 | 147 | |
148 | - $position = give_get_option( 'currency_position', 'before' ); |
|
148 | + $position = give_get_option('currency_position', 'before'); |
|
149 | 149 | |
150 | 150 | $negative = $price < 0; |
151 | 151 | |
152 | - if ( $negative ) { |
|
153 | - $price = substr( $price, 1 ); // Remove proceeding "-" - |
|
152 | + if ($negative) { |
|
153 | + $price = substr($price, 1); // Remove proceeding "-" - |
|
154 | 154 | } |
155 | 155 | |
156 | - $symbol = give_currency_symbol( $currency ); |
|
156 | + $symbol = give_currency_symbol($currency); |
|
157 | 157 | |
158 | - if ( $position == 'before' ): |
|
159 | - switch ( $currency ): |
|
158 | + if ($position == 'before'): |
|
159 | + switch ($currency): |
|
160 | 160 | case "GBP" : |
161 | 161 | case "BRL" : |
162 | 162 | case "EUR" : |
@@ -168,18 +168,18 @@ discard block |
||
168 | 168 | case "NZD" : |
169 | 169 | case "SGD" : |
170 | 170 | case "JPY" : |
171 | - $formatted = $symbol . $price; |
|
171 | + $formatted = $symbol.$price; |
|
172 | 172 | break; |
173 | 173 | case "NOK" : |
174 | - $formatted = $symbol . ' ' . $price; |
|
174 | + $formatted = $symbol.' '.$price; |
|
175 | 175 | break; |
176 | 176 | default : |
177 | - $formatted = $currency . ' ' . $price; |
|
177 | + $formatted = $currency.' '.$price; |
|
178 | 178 | break; |
179 | 179 | endswitch; |
180 | - $formatted = apply_filters( 'give_' . strtolower( $currency ) . '_currency_filter_before', $formatted, $currency, $price ); |
|
180 | + $formatted = apply_filters('give_'.strtolower($currency).'_currency_filter_before', $formatted, $currency, $price); |
|
181 | 181 | else : |
182 | - switch ( $currency ) : |
|
182 | + switch ($currency) : |
|
183 | 183 | case "GBP" : |
184 | 184 | case "BRL" : |
185 | 185 | case "EUR" : |
@@ -190,18 +190,18 @@ discard block |
||
190 | 190 | case "MXN" : |
191 | 191 | case "SGD" : |
192 | 192 | case "JPY" : |
193 | - $formatted = $price . $symbol; |
|
193 | + $formatted = $price.$symbol; |
|
194 | 194 | break; |
195 | 195 | default : |
196 | - $formatted = $price . ' ' . $currency; |
|
196 | + $formatted = $price.' '.$currency; |
|
197 | 197 | break; |
198 | 198 | endswitch; |
199 | - $formatted = apply_filters( 'give_' . strtolower( $currency ) . '_currency_filter_after', $formatted, $currency, $price ); |
|
199 | + $formatted = apply_filters('give_'.strtolower($currency).'_currency_filter_after', $formatted, $currency, $price); |
|
200 | 200 | endif; |
201 | 201 | |
202 | - if ( $negative ) { |
|
202 | + if ($negative) { |
|
203 | 203 | // Prepend the mins sign before the currency sign |
204 | - $formatted = '-' . $formatted; |
|
204 | + $formatted = '-'.$formatted; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $formatted; |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return int $decimals |
218 | 218 | */ |
219 | -function give_currency_decimal_filter( $decimals = 2 ) { |
|
219 | +function give_currency_decimal_filter($decimals = 2) { |
|
220 | 220 | |
221 | 221 | $currency = give_get_currency(); |
222 | 222 | |
223 | - switch ( $currency ) { |
|
223 | + switch ($currency) { |
|
224 | 224 | case 'RIAL' : |
225 | 225 | case 'JPY' : |
226 | 226 | case 'TWD' : |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | break; |
231 | 231 | } |
232 | 232 | |
233 | - return apply_filters( 'give_currency_decimal_count', $decimals, $currency ); |
|
233 | + return apply_filters('give_currency_decimal_count', $decimals, $currency); |
|
234 | 234 | } |
235 | 235 | |
236 | -add_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' ); |
|
237 | -add_filter( 'give_format_amount_decimals', 'give_currency_decimal_filter' ); |
|
238 | 236 | \ No newline at end of file |
237 | +add_filter('give_sanitize_amount_decimals', 'give_currency_decimal_filter'); |
|
238 | +add_filter('give_format_amount_decimals', 'give_currency_decimal_filter'); |
|
239 | 239 | \ No newline at end of file |
@@ -142,8 +142,10 @@ |
||
142 | 142 | |
143 | 143 | if ( is_front_page() ) : |
144 | 144 | $page_url = home_url(); |
145 | - else : |
|
145 | + else { |
|
146 | + : |
|
146 | 147 | $page_url = 'http'; |
148 | + } |
|
147 | 149 | |
148 | 150 | if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) { |
149 | 151 | $page_url .= "s"; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -defined( 'ABSPATH' ) or exit; |
|
13 | +defined('ABSPATH') or exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Give Form widget |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct() |
33 | 33 | { |
34 | - $this->self = get_class( $this ); |
|
34 | + $this->self = get_class($this); |
|
35 | 35 | |
36 | 36 | parent::__construct( |
37 | - strtolower( $this->self ), |
|
38 | - __( 'Give - Donation Form', 'give' ), |
|
37 | + strtolower($this->self), |
|
38 | + __('Give - Donation Form', 'give'), |
|
39 | 39 | array( |
40 | - 'description' => __( 'Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give' ) |
|
40 | + 'description' => __('Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give') |
|
41 | 41 | ) |
42 | 42 | ); |
43 | 43 | |
44 | - add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
45 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) ); |
|
44 | + add_action('widgets_init', array($this, 'widget_init')); |
|
45 | + add_action('admin_enqueue_scripts', array($this, 'admin_widget_scripts')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,24 +52,24 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function admin_widget_scripts( $hook ) |
|
55 | + public function admin_widget_scripts($hook) |
|
56 | 56 | { |
57 | 57 | // Directories of assets |
58 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
59 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
60 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
58 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
59 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
60 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
61 | 61 | |
62 | 62 | // Use minified libraries if SCRIPT_DEBUG is turned off |
63 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
63 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
64 | 64 | |
65 | 65 | // Widget Script |
66 | - if ( $hook == 'widgets.php' ) { |
|
66 | + if ($hook == 'widgets.php') { |
|
67 | 67 | |
68 | - wp_enqueue_style( 'give-qtip-css', $css_dir . 'jquery.qtip' . $suffix . '.css' ); |
|
68 | + wp_enqueue_style('give-qtip-css', $css_dir.'jquery.qtip'.$suffix.'.css'); |
|
69 | 69 | |
70 | - wp_enqueue_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
70 | + wp_enqueue_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
71 | 71 | |
72 | - wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
72 | + wp_enqueue_script('give-admin-widgets-scripts', $js_dir.'admin-widgets'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -80,24 +80,24 @@ discard block |
||
80 | 80 | * before_widget, and after_widget. |
81 | 81 | * @param array $instance The settings for the particular instance of the widget. |
82 | 82 | */ |
83 | - public function widget( $args, $instance ) |
|
83 | + public function widget($args, $instance) |
|
84 | 84 | { |
85 | - extract( $args ); |
|
85 | + extract($args); |
|
86 | 86 | |
87 | - $title = !empty( $instance['title'] ) ? $instance['title'] : ''; |
|
88 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
87 | + $title = ! empty($instance['title']) ? $instance['title'] : ''; |
|
88 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
89 | 89 | |
90 | 90 | echo $before_widget; |
91 | 91 | |
92 | - do_action( 'give_before_forms_widget' ); |
|
92 | + do_action('give_before_forms_widget'); |
|
93 | 93 | |
94 | - echo $title ? $before_title . $title . $after_title : ''; |
|
94 | + echo $title ? $before_title.$title.$after_title : ''; |
|
95 | 95 | |
96 | - give_get_donation_form( $instance ); |
|
96 | + give_get_donation_form($instance); |
|
97 | 97 | |
98 | 98 | echo $after_widget; |
99 | 99 | |
100 | - do_action( 'give_after_forms_widget' ); |
|
100 | + do_action('give_after_forms_widget'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string |
109 | 109 | */ |
110 | - public function form( $instance ) |
|
110 | + public function form($instance) |
|
111 | 111 | { |
112 | 112 | $defaults = array( |
113 | 113 | 'title' => '', |
@@ -115,51 +115,51 @@ discard block |
||
115 | 115 | 'float_labels' => '', |
116 | 116 | ); |
117 | 117 | |
118 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
118 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
119 | 119 | |
120 | - extract( $instance ); |
|
120 | + extract($instance); |
|
121 | 121 | |
122 | 122 | // Query Give Forms |
123 | 123 | |
124 | 124 | $args = array( |
125 | 125 | 'post_type' => 'give_forms', |
126 | - 'posts_per_page' => - 1, |
|
126 | + 'posts_per_page' => -1, |
|
127 | 127 | 'post_status' => 'publish', |
128 | 128 | ); |
129 | 129 | |
130 | - $give_forms = get_posts( $args ); |
|
130 | + $give_forms = get_posts($args); |
|
131 | 131 | |
132 | 132 | // Widget: Title |
133 | 133 | |
134 | 134 | ?><p> |
135 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'give' ); ?></label> |
|
136 | - <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" /><br> |
|
137 | - <small><?php _e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
|
135 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'give'); ?></label> |
|
136 | + <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>" /><br> |
|
137 | + <small><?php _e('Leave blank to hide the widget title.', 'give'); ?></small> |
|
138 | 138 | </p><?php |
139 | 139 | |
140 | 140 | // Widget: Give Form |
141 | 141 | |
142 | 142 | ?><p> |
143 | - <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php printf( __( 'Give %s:', 'give' ), give_get_forms_label_singular() ); ?></label> |
|
144 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> |
|
145 | - <option value="current"><?php _e( '— Select —', 'give' ); ?></option> |
|
146 | - <?php foreach ( $give_forms as $give_form ) { ?> |
|
147 | - <option <?php selected( absint( $id ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo $give_form->post_title; ?></option> |
|
143 | + <label for="<?php echo esc_attr($this->get_field_id('id')); ?>"><?php printf(__('Give %s:', 'give'), give_get_forms_label_singular()); ?></label> |
|
144 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('id')); ?>" id="<?php echo esc_attr($this->get_field_id('id')); ?>"> |
|
145 | + <option value="current"><?php _e('— Select —', 'give'); ?></option> |
|
146 | + <?php foreach ($give_forms as $give_form) { ?> |
|
147 | + <option <?php selected(absint($id), $give_form->ID); ?> value="<?php echo esc_attr($give_form->ID); ?>"><?php echo $give_form->post_title; ?></option> |
|
148 | 148 | <?php } ?> |
149 | 149 | </select><br> |
150 | - <small><?php _e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small> |
|
150 | + <small><?php _e('Select a Give Form to embed in this widget.', 'give'); ?></small> |
|
151 | 151 | </p><?php |
152 | 152 | |
153 | 153 | // Widget: Floating Labels |
154 | 154 | |
155 | 155 | ?><p> |
156 | - <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php _e( 'Floating Labels (optional):', 'give' ); ?></label> |
|
157 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"> |
|
158 | - <option value="" <?php selected( esc_attr( $float_labels ), '' ) ?>>– <?php _e( 'Select', 'give' ); ?> –</option> |
|
159 | - <option value="enabled" <?php selected( esc_attr( $float_labels ), 'enabled' ) ?>><?php _e( 'Enabled', 'give' ); ?></option> |
|
160 | - <option value="disabled" <?php selected( esc_attr( $float_labels ), 'disabled' ) ?>><?php _e( 'Disabled', 'give' ); ?></option> |
|
156 | + <label for="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"><?php _e('Floating Labels (optional):', 'give'); ?></label> |
|
157 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('float_labels')); ?>" id="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"> |
|
158 | + <option value="" <?php selected(esc_attr($float_labels), '') ?>>– <?php _e('Select', 'give'); ?> –</option> |
|
159 | + <option value="enabled" <?php selected(esc_attr($float_labels), 'enabled') ?>><?php _e('Enabled', 'give'); ?></option> |
|
160 | + <option value="disabled" <?php selected(esc_attr($float_labels), 'disabled') ?>><?php _e('Disabled', 'give'); ?></option> |
|
161 | 161 | </select><br> |
162 | - <small><?php printf( __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give' ), esc_url( "http://bradfrost.com/blog/post/float-label-pattern/" ) ); ?></small> |
|
162 | + <small><?php printf(__('Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give'), esc_url("http://bradfrost.com/blog/post/float-label-pattern/")); ?></small> |
|
163 | 163 | </p><?php |
164 | 164 | } |
165 | 165 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | function widget_init() |
172 | 172 | { |
173 | - register_widget( $this->self ); |
|
173 | + register_widget($this->self); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return array |
183 | 183 | */ |
184 | - public function update( $new_instance, $old_instance ) |
|
184 | + public function update($new_instance, $old_instance) |
|
185 | 185 | { |
186 | 186 | $this->flush_widget_cache(); |
187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function flush_widget_cache() |
197 | 197 | { |
198 | - wp_cache_delete( $this->self, 'widget' ); |
|
198 | + wp_cache_delete($this->self, 'widget'); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 |
@@ -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 |
@@ -97,10 +97,10 @@ |
||
97 | 97 | |
98 | 98 | //Single Form settings varies compared to the Global default settings |
99 | 99 | if ( ! empty( $form_default ) && |
100 | - $form_id !== null && |
|
101 | - $default !== $form_default && |
|
102 | - $form_default !== 'global' && |
|
103 | - give_is_gateway_active( $form_default ) |
|
100 | + $form_id !== null && |
|
101 | + $default !== $form_default && |
|
102 | + $form_default !== 'global' && |
|
103 | + give_is_gateway_active( $form_default ) |
|
104 | 104 | ) { |
105 | 105 | $default = $form_default; |
106 | 106 | } |
@@ -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 | |
@@ -24,17 +24,17 @@ discard block |
||
24 | 24 | // Default, built-in gateways |
25 | 25 | $gateways = array( |
26 | 26 | 'paypal' => array( |
27 | - 'admin_label' => __( 'PayPal Standard', 'give' ), |
|
28 | - 'checkout_label' => __( 'PayPal', 'give' ), |
|
29 | - 'supports' => array( 'buy_now' ) |
|
27 | + 'admin_label' => __('PayPal Standard', 'give'), |
|
28 | + 'checkout_label' => __('PayPal', 'give'), |
|
29 | + 'supports' => array('buy_now') |
|
30 | 30 | ), |
31 | 31 | 'manual' => array( |
32 | - 'admin_label' => __( 'Test Payment', 'give' ), |
|
33 | - 'checkout_label' => __( 'Test Payment', 'give' ) |
|
32 | + 'admin_label' => __('Test Payment', 'give'), |
|
33 | + 'checkout_label' => __('Test Payment', 'give') |
|
34 | 34 | ), |
35 | 35 | ); |
36 | 36 | |
37 | - return apply_filters( 'give_payment_gateways', $gateways ); |
|
37 | + return apply_filters('give_payment_gateways', $gateways); |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | global $give_options; |
49 | 49 | |
50 | 50 | $gateways = give_get_payment_gateways(); |
51 | - $enabled = isset( $give_options['gateways'] ) ? $give_options['gateways'] : false; |
|
51 | + $enabled = isset($give_options['gateways']) ? $give_options['gateways'] : false; |
|
52 | 52 | |
53 | 53 | $gateway_list = array(); |
54 | 54 | |
55 | - foreach ( $gateways as $key => $gateway ) { |
|
56 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
57 | - $gateway_list[ $key ] = $gateway; |
|
55 | + foreach ($gateways as $key => $gateway) { |
|
56 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
57 | + $gateway_list[$key] = $gateway; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - return apply_filters( 'give_enabled_payment_gateways', $gateway_list ); |
|
61 | + return apply_filters('give_enabled_payment_gateways', $gateway_list); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return boolean true if enabled, false otherwise |
72 | 72 | */ |
73 | -function give_is_gateway_active( $gateway ) { |
|
73 | +function give_is_gateway_active($gateway) { |
|
74 | 74 | $gateways = give_get_enabled_payment_gateways(); |
75 | 75 | |
76 | - $ret = array_key_exists( $gateway, $gateways ); |
|
76 | + $ret = array_key_exists($gateway, $gateways); |
|
77 | 77 | |
78 | - return apply_filters( 'give_is_gateway_active', $ret, $gateway, $gateways ); |
|
78 | + return apply_filters('give_is_gateway_active', $ret, $gateway, $gateways); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -88,24 +88,24 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string Gateway ID |
90 | 90 | */ |
91 | -function give_get_default_gateway( $form_id ) { |
|
91 | +function give_get_default_gateway($form_id) { |
|
92 | 92 | |
93 | 93 | global $give_options; |
94 | 94 | |
95 | - $default = isset( $give_options['default_gateway'] ) && give_is_gateway_active( $give_options['default_gateway'] ) ? $give_options['default_gateway'] : 'paypal'; |
|
96 | - $form_default = get_post_meta( $form_id, '_give_default_gateway', true ); |
|
95 | + $default = isset($give_options['default_gateway']) && give_is_gateway_active($give_options['default_gateway']) ? $give_options['default_gateway'] : 'paypal'; |
|
96 | + $form_default = get_post_meta($form_id, '_give_default_gateway', true); |
|
97 | 97 | |
98 | 98 | //Single Form settings varies compared to the Global default settings |
99 | - if ( ! empty( $form_default ) && |
|
99 | + if ( ! empty($form_default) && |
|
100 | 100 | $form_id !== null && |
101 | 101 | $default !== $form_default && |
102 | 102 | $form_default !== 'global' && |
103 | - give_is_gateway_active( $form_default ) |
|
103 | + give_is_gateway_active($form_default) |
|
104 | 104 | ) { |
105 | 105 | $default = $form_default; |
106 | 106 | } |
107 | 107 | |
108 | - return apply_filters( 'give_default_gateway', $default ); |
|
108 | + return apply_filters('give_default_gateway', $default); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return string Gateway admin label |
119 | 119 | */ |
120 | -function give_get_gateway_admin_label( $gateway ) { |
|
120 | +function give_get_gateway_admin_label($gateway) { |
|
121 | 121 | $gateways = give_get_enabled_payment_gateways(); |
122 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
123 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
122 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
123 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
124 | 124 | |
125 | - if ( $gateway == 'manual' && $payment ) { |
|
126 | - if ( give_get_payment_amount( $payment ) == 0 ) { |
|
127 | - $label = __( 'Test Donation', 'give' ); |
|
125 | + if ($gateway == 'manual' && $payment) { |
|
126 | + if (give_get_payment_amount($payment) == 0) { |
|
127 | + $label = __('Test Donation', 'give'); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | - return apply_filters( 'give_gateway_admin_label', $label, $gateway ); |
|
131 | + return apply_filters('give_gateway_admin_label', $label, $gateway); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return string Checkout label for the gateway |
142 | 142 | */ |
143 | -function give_get_gateway_checkout_label( $gateway ) { |
|
143 | +function give_get_gateway_checkout_label($gateway) { |
|
144 | 144 | $gateways = give_get_enabled_payment_gateways(); |
145 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
145 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
146 | 146 | |
147 | - if ( $gateway == 'manual' ) { |
|
148 | - $label = __( 'Test Donation', 'give' ); |
|
147 | + if ($gateway == 'manual') { |
|
148 | + $label = __('Test Donation', 'give'); |
|
149 | 149 | } |
150 | 150 | |
151 | - return apply_filters( 'give_gateway_checkout_label', $label, $gateway ); |
|
151 | + return apply_filters('give_gateway_checkout_label', $label, $gateway); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return array Options the gateway supports |
162 | 162 | */ |
163 | -function give_get_gateway_supports( $gateway ) { |
|
163 | +function give_get_gateway_supports($gateway) { |
|
164 | 164 | $gateways = give_get_enabled_payment_gateways(); |
165 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
165 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
166 | 166 | |
167 | - return apply_filters( 'give_gateway_supports', $supports, $gateway ); |
|
167 | + return apply_filters('give_gateway_supports', $supports, $gateway); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return bool |
178 | 178 | */ |
179 | -function give_gateway_supports_buy_now( $gateway ) { |
|
180 | - $supports = give_get_gateway_supports( $gateway ); |
|
181 | - $ret = in_array( 'buy_now', $supports ); |
|
179 | +function give_gateway_supports_buy_now($gateway) { |
|
180 | + $supports = give_get_gateway_supports($gateway); |
|
181 | + $ret = in_array('buy_now', $supports); |
|
182 | 182 | |
183 | - return apply_filters( 'give_gateway_supports_buy_now', $ret, $gateway ); |
|
183 | + return apply_filters('give_gateway_supports_buy_now', $ret, $gateway); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -193,16 +193,16 @@ discard block |
||
193 | 193 | $gateways = give_get_enabled_payment_gateways(); |
194 | 194 | $ret = false; |
195 | 195 | |
196 | - if ( $gateways ) { |
|
197 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
198 | - if ( give_gateway_supports_buy_now( $gateway_id ) ) { |
|
196 | + if ($gateways) { |
|
197 | + foreach ($gateways as $gateway_id => $gateway) { |
|
198 | + if (give_gateway_supports_buy_now($gateway_id)) { |
|
199 | 199 | $ret = true; |
200 | 200 | break; |
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - return apply_filters( 'give_give_supports_buy_now', $ret ); |
|
205 | + return apply_filters('give_give_supports_buy_now', $ret); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return void |
217 | 217 | */ |
218 | -function give_send_to_gateway( $gateway, $payment_data ) { |
|
218 | +function give_send_to_gateway($gateway, $payment_data) { |
|
219 | 219 | |
220 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'give-gateway' ); |
|
220 | + $payment_data['gateway_nonce'] = wp_create_nonce('give-gateway'); |
|
221 | 221 | |
222 | 222 | // $gateway must match the ID used when registering the gateway |
223 | - do_action( 'give_gateway_' . $gateway, $payment_data ); |
|
223 | + do_action('give_gateway_'.$gateway, $payment_data); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -237,32 +237,32 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return string $enabled_gateway The slug of the gateway |
239 | 239 | */ |
240 | -function give_get_chosen_gateway( $form_id ) { |
|
240 | +function give_get_chosen_gateway($form_id) { |
|
241 | 241 | $gateways = give_get_enabled_payment_gateways(); |
242 | - $request_form_id = isset( $_REQUEST['give_form_id'] ) ? $_REQUEST['give_form_id'] : 0; |
|
243 | - if ( empty( $request_form_id ) ) { |
|
244 | - $request_form_id = isset( $_REQUEST['form-id'] ) ? $_REQUEST['form-id'] : 0; |
|
242 | + $request_form_id = isset($_REQUEST['give_form_id']) ? $_REQUEST['give_form_id'] : 0; |
|
243 | + if (empty($request_form_id)) { |
|
244 | + $request_form_id = isset($_REQUEST['form-id']) ? $_REQUEST['form-id'] : 0; |
|
245 | 245 | } |
246 | - $chosen = give_get_default_gateway( $form_id ); |
|
246 | + $chosen = give_get_default_gateway($form_id); |
|
247 | 247 | $enabled_gateway = ''; |
248 | 248 | |
249 | 249 | //Take into account request Form ID args |
250 | - if ( ! empty( $request_form_id ) && $form_id == $request_form_id ) { |
|
250 | + if ( ! empty($request_form_id) && $form_id == $request_form_id) { |
|
251 | 251 | $chosen = $_REQUEST['payment-mode']; |
252 | 252 | } |
253 | 253 | |
254 | - if ( $chosen ) { |
|
255 | - $enabled_gateway = urldecode( $chosen ); |
|
256 | - } else if ( count( $gateways ) >= 1 && ! $chosen ) { |
|
257 | - foreach ( $gateways as $gateway_id => $gateway ): |
|
254 | + if ($chosen) { |
|
255 | + $enabled_gateway = urldecode($chosen); |
|
256 | + } else if (count($gateways) >= 1 && ! $chosen) { |
|
257 | + foreach ($gateways as $gateway_id => $gateway): |
|
258 | 258 | $enabled_gateway = $gateway_id; |
259 | 259 | endforeach; |
260 | 260 | } else { |
261 | - $enabled_gateway = give_get_default_gateway( $form_id ); |
|
261 | + $enabled_gateway = give_get_default_gateway($form_id); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | |
265 | - return apply_filters( 'give_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters('give_chosen_gateway', $enabled_gateway); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return int ID of the new log entry |
281 | 281 | */ |
282 | -function give_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
283 | - return give_record_log( $title, $message, $parent, 'gateway_error' ); |
|
282 | +function give_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
283 | + return give_record_log($title, $message, $parent, 'gateway_error'); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return int |
295 | 295 | */ |
296 | -function give_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
296 | +function give_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
297 | 297 | |
298 | 298 | $ret = 0; |
299 | 299 | $args = array( |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | 'fields' => 'ids' |
306 | 306 | ); |
307 | 307 | |
308 | - $payments = new WP_Query( $args ); |
|
308 | + $payments = new WP_Query($args); |
|
309 | 309 | |
310 | - if ( $payments ) { |
|
310 | + if ($payments) { |
|
311 | 311 | $ret = $payments->post_count; |
312 | 312 | } |
313 | 313 |
@@ -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 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @since 1.0 |
21 | 21 | * @return void |
22 | 22 | */ |
23 | -add_action( 'give_manual_cc_form', '__return_false' ); |
|
23 | +add_action('give_manual_cc_form', '__return_false'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Processes the purchase data and uses the Manual Payment gateway to record |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return void |
35 | 35 | */ |
36 | -function give_manual_payment( $purchase_data ) { |
|
36 | +function give_manual_payment($purchase_data) { |
|
37 | 37 | |
38 | 38 | global $give_options; |
39 | 39 | |
40 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
41 | - wp_die( __( 'Nonce verification has failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
40 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
41 | + wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /* |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $payment_data = array( |
48 | 48 | 'price' => $purchase_data['price'], |
49 | 49 | 'give_form_title' => $purchase_data['post_data']['give-form-title'], |
50 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
|
50 | + 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), |
|
51 | 51 | 'date' => $purchase_data['date'], |
52 | 52 | 'user_email' => $purchase_data['user_email'], |
53 | 53 | 'purchase_key' => $purchase_data['purchase_key'], |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | 'status' => 'pending' |
57 | 57 | ); |
58 | 58 | // Record the pending payment |
59 | - $payment = give_insert_payment( $payment_data ); |
|
59 | + $payment = give_insert_payment($payment_data); |
|
60 | 60 | |
61 | - if ( $payment ) { |
|
62 | - give_update_payment_status( $payment, 'publish' ); |
|
61 | + if ($payment) { |
|
62 | + give_update_payment_status($payment, 'publish'); |
|
63 | 63 | give_send_to_success_page(); |
64 | 64 | } else { |
65 | - give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment ); |
|
65 | + give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'give'), json_encode($payment_data)), $payment); |
|
66 | 66 | // If errors are present, send the user back to the purchase page so they can be corrected |
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 | } |
69 | 69 | } |
70 | 70 | |
71 | -add_action( 'give_gateway_manual', 'give_manual_payment' ); |
|
71 | +add_action('give_gateway_manual', 'give_manual_payment'); |
@@ -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 | |
43 | 43 | // Collect payment data |
44 | 44 | $payment_data = array( |
@@ -55,59 +55,59 @@ discard block |
||
55 | 55 | ); |
56 | 56 | |
57 | 57 | // Record the pending payment |
58 | - $payment = give_insert_payment( $payment_data ); |
|
58 | + $payment = give_insert_payment($payment_data); |
|
59 | 59 | |
60 | 60 | // Check payment |
61 | - if ( ! $payment ) { |
|
61 | + if ( ! $payment) { |
|
62 | 62 | // Record the error |
63 | - 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 ); |
|
63 | + give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment); |
|
64 | 64 | // Problems? send back |
65 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
65 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
66 | 66 | } else { |
67 | 67 | // Only send to PayPal if the pending payment is created successfully |
68 | - $listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) ); |
|
68 | + $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php')); |
|
69 | 69 | |
70 | 70 | // Get the success url |
71 | - $return_url = add_query_arg( array( |
|
71 | + $return_url = add_query_arg(array( |
|
72 | 72 | 'payment-confirmation' => 'paypal', |
73 | 73 | 'payment-id' => $payment |
74 | 74 | |
75 | - ), get_permalink( give_get_option( 'success_page' ) ) ); |
|
75 | + ), get_permalink(give_get_option('success_page'))); |
|
76 | 76 | |
77 | 77 | // Get the PayPal redirect uri |
78 | - $paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?'; |
|
78 | + $paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?'; |
|
79 | 79 | |
80 | 80 | //Item name - pass level name if variable priced |
81 | 81 | $item_name = $purchase_data['post_data']['give-form-title']; |
82 | 82 | |
83 | 83 | //Verify has variable prices |
84 | - if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) { |
|
84 | + if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) { |
|
85 | 85 | |
86 | - $item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
86 | + $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']); |
|
87 | 87 | |
88 | - $price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
88 | + $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']); |
|
89 | 89 | |
90 | 90 | //Donation given doesn't match selected level (must be a custom amount) |
91 | - if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) { |
|
92 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
91 | + if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) { |
|
92 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
93 | 93 | //user custom amount text if any, fallback to default if not |
94 | - $item_name .= ' - ' . (! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' )); |
|
94 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
95 | 95 | |
96 | 96 | } //Is there any donation level text? |
97 | - elseif ( ! empty( $item_price_level_text ) ) { |
|
98 | - $item_name .= ' - ' . $item_price_level_text; |
|
97 | + elseif ( ! empty($item_price_level_text)) { |
|
98 | + $item_name .= ' - '.$item_price_level_text; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | } //Single donation: Custom Amount |
102 | - elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) { |
|
103 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
102 | + elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) { |
|
103 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
104 | 104 | //user custom amount text if any, fallback to default if not |
105 | - $item_name .= ' - ' . (! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' )); |
|
105 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Setup PayPal arguments |
109 | 109 | $paypal_args = array( |
110 | - 'business' => give_get_option( 'paypal_email', false ), |
|
110 | + 'business' => give_get_option('paypal_email', false), |
|
111 | 111 | 'email' => $purchase_data['user_email'], |
112 | 112 | 'invoice' => $purchase_data['purchase_key'], |
113 | 113 | 'amount' => $purchase_data['price'], |
@@ -118,25 +118,25 @@ discard block |
||
118 | 118 | 'shipping' => '0', |
119 | 119 | 'no_note' => '1', |
120 | 120 | 'currency_code' => give_get_currency(), |
121 | - 'charset' => get_bloginfo( 'charset' ), |
|
121 | + 'charset' => get_bloginfo('charset'), |
|
122 | 122 | 'custom' => $payment, |
123 | 123 | 'rm' => '2', |
124 | 124 | 'return' => $return_url, |
125 | - 'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ), |
|
125 | + 'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment), |
|
126 | 126 | 'notify_url' => $listener_url, |
127 | 127 | 'page_style' => give_get_paypal_page_style(), |
128 | - 'cbt' => get_bloginfo( 'name' ), |
|
128 | + 'cbt' => get_bloginfo('name'), |
|
129 | 129 | 'bn' => 'givewp_SP' |
130 | 130 | ); |
131 | 131 | |
132 | - if ( ! empty( $purchase_data['user_info']['address'] ) ) { |
|
132 | + if ( ! empty($purchase_data['user_info']['address'])) { |
|
133 | 133 | $paypal_args['address1'] = $purchase_data['user_info']['address']['line1']; |
134 | 134 | $paypal_args['address2'] = $purchase_data['user_info']['address']['line2']; |
135 | 135 | $paypal_args['city'] = $purchase_data['user_info']['address']['city']; |
136 | 136 | $paypal_args['country'] = $purchase_data['user_info']['address']['country']; |
137 | 137 | } |
138 | 138 | |
139 | - if ( give_get_option( 'paypal_button_type' ) === 'standard' ) { |
|
139 | + if (give_get_option('paypal_button_type') === 'standard') { |
|
140 | 140 | $paypal_extra_args = array( |
141 | 141 | 'cmd' => '_xclick', |
142 | 142 | ); |
@@ -146,25 +146,25 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
149 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
150 | 150 | |
151 | 151 | |
152 | - $paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data ); |
|
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,27 +211,27 @@ 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 | - if ( ! give_get_option( 'disable_paypal_verification' ) ) { |
|
234 | + if ( ! give_get_option('disable_paypal_verification')) { |
|
235 | 235 | |
236 | 236 | // Validate the IPN |
237 | 237 | |
@@ -253,16 +253,16 @@ discard block |
||
253 | 253 | ); |
254 | 254 | |
255 | 255 | // Get response |
256 | - $api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars ); |
|
256 | + $api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars); |
|
257 | 257 | |
258 | - if ( is_wp_error( $api_response ) ) { |
|
259 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
258 | + if (is_wp_error($api_response)) { |
|
259 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response))); |
|
260 | 260 | |
261 | 261 | return; // Something went wrong |
262 | 262 | } |
263 | 263 | |
264 | - if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) { |
|
265 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) ); |
|
264 | + if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) { |
|
265 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response))); |
|
266 | 266 | |
267 | 267 | return; // Response not okay |
268 | 268 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | // Check if $post_data_array has been populated |
273 | - if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) { |
|
273 | + if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) { |
|
274 | 274 | return; |
275 | 275 | } |
276 | 276 | |
@@ -279,21 +279,21 @@ discard block |
||
279 | 279 | 'payment_status' => '' |
280 | 280 | ); |
281 | 281 | |
282 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
282 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
283 | 283 | |
284 | - $payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
284 | + $payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
285 | 285 | |
286 | - if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
286 | + if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) { |
|
287 | 287 | // Allow PayPal IPN types to be processed separately |
288 | - do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id ); |
|
288 | + do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id); |
|
289 | 289 | } else { |
290 | 290 | // Fallback to web accept just in case the txn_type isn't present |
291 | - do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id ); |
|
291 | + do_action('give_paypal_web_accept', $encoded_data_array, $payment_id); |
|
292 | 292 | } |
293 | 293 | exit; |
294 | 294 | } |
295 | 295 | |
296 | -add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' ); |
|
296 | +add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn'); |
|
297 | 297 | |
298 | 298 | /** |
299 | 299 | * Process web accept (one time) payment IPNs |
@@ -304,185 +304,185 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return void |
306 | 306 | */ |
307 | -function give_process_paypal_web_accept_and_cart( $data, $payment_id ) { |
|
307 | +function give_process_paypal_web_accept_and_cart($data, $payment_id) { |
|
308 | 308 | |
309 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
309 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
310 | 310 | return; |
311 | 311 | } |
312 | 312 | |
313 | - if ( empty( $payment_id ) ) { |
|
313 | + if (empty($payment_id)) { |
|
314 | 314 | return; |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Collect payment details |
318 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
318 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
319 | 319 | $paypal_amount = $data['mc_gross']; |
320 | - $payment_status = strtolower( $data['payment_status'] ); |
|
321 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
322 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
323 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
320 | + $payment_status = strtolower($data['payment_status']); |
|
321 | + $currency_code = strtolower($data['mc_currency']); |
|
322 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
323 | + $payment_meta = give_get_payment_meta($payment_id); |
|
324 | 324 | |
325 | 325 | |
326 | - if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) { |
|
326 | + if (give_get_payment_gateway($payment_id) != 'paypal') { |
|
327 | 327 | return; // this isn't a PayPal standard IPN |
328 | 328 | } |
329 | 329 | |
330 | 330 | // Verify payment recipient |
331 | - if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) { |
|
331 | + if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) { |
|
332 | 332 | |
333 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
334 | - give_update_payment_status( $payment_id, 'failed' ); |
|
335 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) ); |
|
333 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
334 | + give_update_payment_status($payment_id, 'failed'); |
|
335 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give')); |
|
336 | 336 | |
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // Verify payment currency |
341 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
341 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
342 | 342 | |
343 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
344 | - give_update_payment_status( $payment_id, 'failed' ); |
|
345 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) ); |
|
343 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
344 | + give_update_payment_status($payment_id, 'failed'); |
|
345 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give')); |
|
346 | 346 | |
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
350 | - if ( ! give_get_payment_user_email( $payment_id ) ) { |
|
350 | + if ( ! give_get_payment_user_email($payment_id)) { |
|
351 | 351 | |
352 | 352 | // No email associated with purchase, so store from PayPal |
353 | - give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] ); |
|
353 | + give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']); |
|
354 | 354 | |
355 | 355 | // Setup and store the donors's details |
356 | 356 | $address = array(); |
357 | - $address['line1'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
358 | - $address['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
359 | - $address['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
360 | - $address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
361 | - $address['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
357 | + $address['line1'] = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
358 | + $address['city'] = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
359 | + $address['state'] = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
360 | + $address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
361 | + $address['zip'] = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
362 | 362 | |
363 | 363 | $user_info = array( |
364 | 364 | 'id' => '-1', |
365 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
366 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
367 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
365 | + 'email' => sanitize_text_field($data['payer_email']), |
|
366 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
367 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
368 | 368 | 'discount' => '', |
369 | 369 | 'address' => $address |
370 | 370 | ); |
371 | 371 | |
372 | 372 | $payment_meta['user_info'] = $user_info; |
373 | - give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta ); |
|
373 | + give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta); |
|
374 | 374 | } |
375 | 375 | |
376 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
376 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
377 | 377 | |
378 | 378 | // Process a refund |
379 | - give_process_paypal_refund( $data, $payment_id ); |
|
379 | + give_process_paypal_refund($data, $payment_id); |
|
380 | 380 | |
381 | 381 | } else { |
382 | 382 | |
383 | - if ( get_post_status( $payment_id ) == 'publish' ) { |
|
383 | + if (get_post_status($payment_id) == 'publish') { |
|
384 | 384 | return; // Only complete payments once |
385 | 385 | } |
386 | 386 | |
387 | 387 | // Retrieve the total purchase amount (before PayPal) |
388 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
388 | + $payment_amount = give_get_payment_amount($payment_id); |
|
389 | 389 | |
390 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
390 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
391 | 391 | // The prices don't match |
392 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
393 | - give_update_payment_status( $payment_id, 'failed' ); |
|
394 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) ); |
|
392 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
393 | + give_update_payment_status($payment_id, 'failed'); |
|
394 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give')); |
|
395 | 395 | |
396 | 396 | return; |
397 | 397 | } |
398 | - if ( $purchase_key != give_get_payment_key( $payment_id ) ) { |
|
398 | + if ($purchase_key != give_get_payment_key($payment_id)) { |
|
399 | 399 | // Purchase keys don't match |
400 | - give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id ); |
|
401 | - give_update_payment_status( $payment_id, 'failed' ); |
|
402 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) ); |
|
400 | + give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id); |
|
401 | + give_update_payment_status($payment_id, 'failed'); |
|
402 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give')); |
|
403 | 403 | |
404 | 404 | return; |
405 | 405 | } |
406 | 406 | |
407 | - if ( $payment_status == 'completed' || give_is_test_mode() ) { |
|
408 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
409 | - give_set_payment_transaction_id( $payment_id, $data['txn_id'] ); |
|
410 | - give_update_payment_status( $payment_id, 'publish' ); |
|
411 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
407 | + if ($payment_status == 'completed' || give_is_test_mode()) { |
|
408 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id'])); |
|
409 | + give_set_payment_transaction_id($payment_id, $data['txn_id']); |
|
410 | + give_update_payment_status($payment_id, 'publish'); |
|
411 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
412 | 412 | |
413 | 413 | // Look for possible pending reasons, such as an echeck |
414 | 414 | |
415 | 415 | $note = ''; |
416 | 416 | |
417 | - switch ( strtolower( $data['pending_reason'] ) ) { |
|
417 | + switch (strtolower($data['pending_reason'])) { |
|
418 | 418 | |
419 | 419 | case 'echeck' : |
420 | 420 | |
421 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'give' ); |
|
421 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'give'); |
|
422 | 422 | |
423 | 423 | break; |
424 | 424 | |
425 | 425 | case 'address' : |
426 | 426 | |
427 | - $note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give' ); |
|
427 | + $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give'); |
|
428 | 428 | |
429 | 429 | break; |
430 | 430 | |
431 | 431 | case 'intl' : |
432 | 432 | |
433 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'give' ); |
|
433 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'give'); |
|
434 | 434 | |
435 | 435 | break; |
436 | 436 | |
437 | 437 | case 'multi-currency' : |
438 | 438 | |
439 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'give' ); |
|
439 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'give'); |
|
440 | 440 | |
441 | 441 | break; |
442 | 442 | |
443 | 443 | case 'paymentreview' : |
444 | 444 | case 'regulatory_review' : |
445 | 445 | |
446 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give' ); |
|
446 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give'); |
|
447 | 447 | |
448 | 448 | break; |
449 | 449 | |
450 | 450 | case 'unilateral' : |
451 | 451 | |
452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' ); |
|
452 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give'); |
|
453 | 453 | |
454 | 454 | break; |
455 | 455 | |
456 | 456 | case 'upgrade' : |
457 | 457 | |
458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'give' ); |
|
458 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'give'); |
|
459 | 459 | |
460 | 460 | break; |
461 | 461 | |
462 | 462 | case 'verify' : |
463 | 463 | |
464 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'give' ); |
|
464 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'give'); |
|
465 | 465 | |
466 | 466 | break; |
467 | 467 | |
468 | 468 | case 'other' : |
469 | 469 | |
470 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give' ); |
|
470 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give'); |
|
471 | 471 | |
472 | 472 | break; |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | - if ( ! empty( $note ) ) { |
|
476 | + if ( ! empty($note)) { |
|
477 | 477 | |
478 | - give_insert_payment_note( $payment_id, $note ); |
|
478 | + give_insert_payment_note($payment_id, $note); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | } |
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | -add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 ); |
|
485 | +add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2); |
|
486 | 486 | |
487 | 487 | /** |
488 | 488 | * Process PayPal IPN Refunds |
@@ -493,32 +493,32 @@ discard block |
||
493 | 493 | * |
494 | 494 | * @return void |
495 | 495 | */ |
496 | -function give_process_paypal_refund( $data, $payment_id = 0 ) { |
|
496 | +function give_process_paypal_refund($data, $payment_id = 0) { |
|
497 | 497 | |
498 | 498 | // Collect payment details |
499 | 499 | |
500 | - if ( empty( $payment_id ) ) { |
|
500 | + if (empty($payment_id)) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
504 | - if ( get_post_status( $payment_id ) == 'refunded' ) { |
|
504 | + if (get_post_status($payment_id) == 'refunded') { |
|
505 | 505 | return; // Only refund payments once |
506 | 506 | } |
507 | 507 | |
508 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
508 | + $payment_amount = give_get_payment_amount($payment_id); |
|
509 | 509 | $refund_amount = $data['payment_gross'] * - 1; |
510 | 510 | |
511 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
511 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
512 | 512 | |
513 | - give_insert_payment_note( $payment_id, sprintf( __( 'Partial PayPal refund processed: %s', 'give' ), $data['parent_txn_id'] ) ); |
|
513 | + give_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id'])); |
|
514 | 514 | |
515 | 515 | return; // This is a partial refund |
516 | 516 | |
517 | 517 | } |
518 | 518 | |
519 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
520 | - give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'give' ), $data['txn_id'] ) ); |
|
521 | - give_update_payment_status( $payment_id, 'refunded' ); |
|
519 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code'])); |
|
520 | + give_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id'])); |
|
521 | + give_update_payment_status($payment_id, 'refunded'); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | * |
531 | 531 | * @return string |
532 | 532 | */ |
533 | -function give_get_paypal_redirect( $ssl_check = false ) { |
|
533 | +function give_get_paypal_redirect($ssl_check = false) { |
|
534 | 534 | |
535 | - if ( is_ssl() || ! $ssl_check ) { |
|
535 | + if (is_ssl() || ! $ssl_check) { |
|
536 | 536 | $protocal = 'https://'; |
537 | 537 | } else { |
538 | 538 | $protocal = 'http://'; |
539 | 539 | } |
540 | 540 | |
541 | 541 | // Check the current payment mode |
542 | - if ( give_is_test_mode() ) { |
|
542 | + if (give_is_test_mode()) { |
|
543 | 543 | // Test mode |
544 | - $paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
544 | + $paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
545 | 545 | } else { |
546 | 546 | // Live mode |
547 | - $paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr'; |
|
547 | + $paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr'; |
|
548 | 548 | } |
549 | 549 | |
550 | - return apply_filters( 'give_paypal_uri', $paypal_uri ); |
|
550 | + return apply_filters('give_paypal_uri', $paypal_uri); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -558,9 +558,9 @@ discard block |
||
558 | 558 | */ |
559 | 559 | function give_get_paypal_page_style() { |
560 | 560 | |
561 | - $page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) ); |
|
561 | + $page_style = trim(give_get_option('paypal_page_style', 'PayPal')); |
|
562 | 562 | |
563 | - return apply_filters( 'give_paypal_page_style', $page_style ); |
|
563 | + return apply_filters('give_paypal_page_style', $page_style); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -571,27 +571,27 @@ discard block |
||
571 | 571 | * @since 1.0 |
572 | 572 | * @return string |
573 | 573 | */ |
574 | -function give_paypal_success_page_content( $content ) { |
|
574 | +function give_paypal_success_page_content($content) { |
|
575 | 575 | |
576 | - if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) { |
|
576 | + if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) { |
|
577 | 577 | return $content; |
578 | 578 | } |
579 | 579 | |
580 | - $payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false; |
|
580 | + $payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false; |
|
581 | 581 | |
582 | - if ( ! $payment_id ) { |
|
582 | + if ( ! $payment_id) { |
|
583 | 583 | $session = give_get_purchase_session(); |
584 | - $payment_id = give_get_purchase_id_by_key( $session['purchase_key'] ); |
|
584 | + $payment_id = give_get_purchase_id_by_key($session['purchase_key']); |
|
585 | 585 | } |
586 | 586 | |
587 | - $payment = get_post( $payment_id ); |
|
587 | + $payment = get_post($payment_id); |
|
588 | 588 | |
589 | - if ( $payment && 'pending' == $payment->post_status ) { |
|
589 | + if ($payment && 'pending' == $payment->post_status) { |
|
590 | 590 | |
591 | 591 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
592 | 592 | ob_start(); |
593 | 593 | |
594 | - give_get_template_part( 'payment', 'processing' ); |
|
594 | + give_get_template_part('payment', 'processing'); |
|
595 | 595 | |
596 | 596 | $content = ob_get_clean(); |
597 | 597 | |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | |
602 | 602 | } |
603 | 603 | |
604 | -add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' ); |
|
604 | +add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content'); |
|
605 | 605 | |
606 | 606 | /** |
607 | 607 | * Given a Payment ID, extract the transaction ID |
@@ -612,22 +612,22 @@ discard block |
||
612 | 612 | * |
613 | 613 | * @return string Transaction ID |
614 | 614 | */ |
615 | -function give_paypal_get_payment_transaction_id( $payment_id ) { |
|
615 | +function give_paypal_get_payment_transaction_id($payment_id) { |
|
616 | 616 | |
617 | 617 | $transaction_id = ''; |
618 | - $notes = give_get_payment_notes( $payment_id ); |
|
618 | + $notes = give_get_payment_notes($payment_id); |
|
619 | 619 | |
620 | - foreach ( $notes as $note ) { |
|
621 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
620 | + foreach ($notes as $note) { |
|
621 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
622 | 622 | $transaction_id = $match[1]; |
623 | 623 | continue; |
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
627 | + return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id); |
|
628 | 628 | } |
629 | 629 | |
630 | -add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 ); |
|
630 | +add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1); |
|
631 | 631 | |
632 | 632 | /** |
633 | 633 | * Given a transaction ID, generate a link to the PayPal transaction ID details |
@@ -639,13 +639,13 @@ discard block |
||
639 | 639 | * |
640 | 640 | * @return string A link to the PayPal transaction details |
641 | 641 | */ |
642 | -function give_paypal_link_transaction_id( $transaction_id, $payment_id ) { |
|
642 | +function give_paypal_link_transaction_id($transaction_id, $payment_id) { |
|
643 | 643 | |
644 | 644 | $paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id='; |
645 | - $transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
645 | + $transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>'; |
|
646 | 646 | |
647 | - return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url ); |
|
647 | + return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url); |
|
648 | 648 | |
649 | 649 | } |
650 | 650 | |
651 | -add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 ); |
|
651 | +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 | |
@@ -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_options, $give_login_redirect; |
30 | 30 | |
31 | - if ( empty( $redirect ) ) { |
|
31 | + if (empty($redirect)) { |
|
32 | 32 | $redirect = 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 do not 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 do not 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 |