@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -26,39 +26,39 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return void |
28 | 28 | */ |
29 | -function give_email_donation_receipt( $payment_id, $admin_notice = true ) { |
|
29 | +function give_email_donation_receipt($payment_id, $admin_notice = true) { |
|
30 | 30 | |
31 | - $payment_data = give_get_payment_meta( $payment_id ); |
|
31 | + $payment_data = give_get_payment_meta($payment_id); |
|
32 | 32 | |
33 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
34 | - $from_name = apply_filters( 'give_purchase_from_name', $from_name, $payment_id, $payment_data ); |
|
33 | + $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
34 | + $from_name = apply_filters('give_purchase_from_name', $from_name, $payment_id, $payment_data); |
|
35 | 35 | |
36 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
|
37 | - $from_email = apply_filters( 'give_purchase_from_address', $from_email, $payment_id, $payment_data ); |
|
36 | + $from_email = give_get_option('from_email', get_bloginfo('admin_email')); |
|
37 | + $from_email = apply_filters('give_purchase_from_address', $from_email, $payment_id, $payment_data); |
|
38 | 38 | |
39 | - $to_email = give_get_payment_user_email( $payment_id ); |
|
39 | + $to_email = give_get_payment_user_email($payment_id); |
|
40 | 40 | |
41 | - $subject = give_get_option( 'donation_subject', esc_html__( 'Donation Receipt', 'give' ) ); |
|
42 | - $subject = apply_filters( 'give_donation_subject', wp_strip_all_tags( $subject ), $payment_id ); |
|
43 | - $subject = give_do_email_tags( $subject, $payment_id ); |
|
41 | + $subject = give_get_option('donation_subject', esc_html__('Donation Receipt', 'give')); |
|
42 | + $subject = apply_filters('give_donation_subject', wp_strip_all_tags($subject), $payment_id); |
|
43 | + $subject = give_do_email_tags($subject, $payment_id); |
|
44 | 44 | |
45 | - $attachments = apply_filters( 'give_receipt_attachments', array(), $payment_id, $payment_data ); |
|
46 | - $message = give_do_email_tags( give_get_email_body_content( $payment_id, $payment_data ), $payment_id ); |
|
45 | + $attachments = apply_filters('give_receipt_attachments', array(), $payment_id, $payment_data); |
|
46 | + $message = give_do_email_tags(give_get_email_body_content($payment_id, $payment_data), $payment_id); |
|
47 | 47 | |
48 | 48 | $emails = Give()->emails; |
49 | 49 | |
50 | - $emails->__set( 'from_name', $from_name ); |
|
51 | - $emails->__set( 'from_email', $from_email ); |
|
52 | - $emails->__set( 'heading', esc_html__( 'Donation Receipt', 'give' ) ); |
|
50 | + $emails->__set('from_name', $from_name); |
|
51 | + $emails->__set('from_email', $from_email); |
|
52 | + $emails->__set('heading', esc_html__('Donation Receipt', 'give')); |
|
53 | 53 | |
54 | 54 | |
55 | - $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data ); |
|
56 | - $emails->__set( 'headers', $headers ); |
|
55 | + $headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); |
|
56 | + $emails->__set('headers', $headers); |
|
57 | 57 | |
58 | - $emails->send( $to_email, $subject, $message, $attachments ); |
|
58 | + $emails->send($to_email, $subject, $message, $attachments); |
|
59 | 59 | |
60 | - if ( $admin_notice && ! give_admin_notices_disabled( $payment_id ) ) { |
|
61 | - do_action( 'give_admin_sale_notice', $payment_id, $payment_data ); |
|
60 | + if ($admin_notice && ! give_admin_notices_disabled($payment_id)) { |
|
61 | + do_action('give_admin_sale_notice', $payment_id, $payment_data); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -71,29 +71,29 @@ discard block |
||
71 | 71 | */ |
72 | 72 | function give_email_test_donation_receipt() { |
73 | 73 | |
74 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
75 | - $from_name = apply_filters( 'give_purchase_from_name', $from_name, 0, array() ); |
|
74 | + $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
75 | + $from_name = apply_filters('give_purchase_from_name', $from_name, 0, array()); |
|
76 | 76 | |
77 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
|
78 | - $from_email = apply_filters( 'give_purchase_from_address', $from_email, 0, array() ); |
|
77 | + $from_email = give_get_option('from_email', get_bloginfo('admin_email')); |
|
78 | + $from_email = apply_filters('give_purchase_from_address', $from_email, 0, array()); |
|
79 | 79 | |
80 | - $subject = give_get_option( 'donation_subject', esc_html__( 'Donation Receipt', 'give' ) ); |
|
81 | - $subject = apply_filters( 'give_donation_subject', wp_strip_all_tags( $subject ), 0 ); |
|
82 | - $subject = give_do_email_tags( $subject, 0 ); |
|
80 | + $subject = give_get_option('donation_subject', esc_html__('Donation Receipt', 'give')); |
|
81 | + $subject = apply_filters('give_donation_subject', wp_strip_all_tags($subject), 0); |
|
82 | + $subject = give_do_email_tags($subject, 0); |
|
83 | 83 | |
84 | - $attachments = apply_filters( 'give_receipt_attachments', array(), 0, array() ); |
|
84 | + $attachments = apply_filters('give_receipt_attachments', array(), 0, array()); |
|
85 | 85 | |
86 | - $message = give_email_preview_template_tags( give_get_email_body_content( 0, array() ) ); |
|
86 | + $message = give_email_preview_template_tags(give_get_email_body_content(0, array())); |
|
87 | 87 | |
88 | 88 | $emails = Give()->emails; |
89 | - $emails->__set( 'from_name', $from_name ); |
|
90 | - $emails->__set( 'from_email', $from_email ); |
|
91 | - $emails->__set( 'heading', esc_html__( 'Donation Receipt', 'give' ) ); |
|
89 | + $emails->__set('from_name', $from_name); |
|
90 | + $emails->__set('from_email', $from_email); |
|
91 | + $emails->__set('heading', esc_html__('Donation Receipt', 'give')); |
|
92 | 92 | |
93 | - $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), 0, array() ); |
|
94 | - $emails->__set( 'headers', $headers ); |
|
93 | + $headers = apply_filters('give_receipt_headers', $emails->get_headers(), 0, array()); |
|
94 | + $emails->__set('headers', $headers); |
|
95 | 95 | |
96 | - $emails->send( give_get_admin_notice_emails(), $subject, $message, $attachments ); |
|
96 | + $emails->send(give_get_admin_notice_emails(), $subject, $message, $attachments); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -107,50 +107,50 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return void |
109 | 109 | */ |
110 | -function give_admin_email_notice( $payment_id = 0, $payment_data = array() ) { |
|
110 | +function give_admin_email_notice($payment_id = 0, $payment_data = array()) { |
|
111 | 111 | |
112 | - $payment_id = absint( $payment_id ); |
|
112 | + $payment_id = absint($payment_id); |
|
113 | 113 | |
114 | - if ( empty( $payment_id ) ) { |
|
114 | + if (empty($payment_id)) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - if ( ! give_get_payment_by( 'id', $payment_id ) ) { |
|
118 | + if ( ! give_get_payment_by('id', $payment_id)) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
123 | - $from_name = apply_filters( 'give_purchase_from_name', $from_name, $payment_id, $payment_data ); |
|
122 | + $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
123 | + $from_name = apply_filters('give_purchase_from_name', $from_name, $payment_id, $payment_data); |
|
124 | 124 | |
125 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
|
126 | - $from_email = apply_filters( 'give_purchase_from_address', $from_email, $payment_id, $payment_data ); |
|
125 | + $from_email = give_get_option('from_email', get_bloginfo('admin_email')); |
|
126 | + $from_email = apply_filters('give_purchase_from_address', $from_email, $payment_id, $payment_data); |
|
127 | 127 | |
128 | 128 | /* translators: %s: payment id */ |
129 | - $subject = give_get_option( 'donation_notification_subject', sprintf( esc_html__( 'New Donation - Payment #%s', 'give' ), $payment_id ) ); |
|
130 | - $subject = apply_filters( 'give_admin_donation_notification_subject', wp_strip_all_tags( $subject ), $payment_id ); |
|
131 | - $subject = give_do_email_tags( $subject, $payment_id ); |
|
129 | + $subject = give_get_option('donation_notification_subject', sprintf(esc_html__('New Donation - Payment #%s', 'give'), $payment_id)); |
|
130 | + $subject = apply_filters('give_admin_donation_notification_subject', wp_strip_all_tags($subject), $payment_id); |
|
131 | + $subject = give_do_email_tags($subject, $payment_id); |
|
132 | 132 | |
133 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
134 | - $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
133 | + $headers = "From: ".stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8'))." <$from_email>\r\n"; |
|
134 | + $headers .= "Reply-To: ".$from_email."\r\n"; |
|
135 | 135 | //$headers .= "MIME-Version: 1.0\r\n"; |
136 | 136 | $headers .= "Content-Type: text/html; charset=utf-8\r\n"; |
137 | - $headers = apply_filters( 'give_admin_donation_notification_headers', $headers, $payment_id, $payment_data ); |
|
137 | + $headers = apply_filters('give_admin_donation_notification_headers', $headers, $payment_id, $payment_data); |
|
138 | 138 | |
139 | - $attachments = apply_filters( 'give_admin_donation_notification_attachments', array(), $payment_id, $payment_data ); |
|
139 | + $attachments = apply_filters('give_admin_donation_notification_attachments', array(), $payment_id, $payment_data); |
|
140 | 140 | |
141 | - $message = give_get_donation_notification_body_content( $payment_id, $payment_data ); |
|
141 | + $message = give_get_donation_notification_body_content($payment_id, $payment_data); |
|
142 | 142 | |
143 | 143 | $emails = Give()->emails; |
144 | - $emails->__set( 'from_name', $from_name ); |
|
145 | - $emails->__set( 'from_email', $from_email ); |
|
146 | - $emails->__set( 'headers', $headers ); |
|
147 | - $emails->__set( 'heading', esc_html__( 'New Donation!', 'give' ) ); |
|
144 | + $emails->__set('from_name', $from_name); |
|
145 | + $emails->__set('from_email', $from_email); |
|
146 | + $emails->__set('headers', $headers); |
|
147 | + $emails->__set('heading', esc_html__('New Donation!', 'give')); |
|
148 | 148 | |
149 | - $emails->send( give_get_admin_notice_emails(), $subject, $message, $attachments ); |
|
149 | + $emails->send(give_get_admin_notice_emails(), $subject, $message, $attachments); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
153 | -add_action( 'give_admin_sale_notice', 'give_admin_email_notice', 10, 2 ); |
|
153 | +add_action('give_admin_sale_notice', 'give_admin_email_notice', 10, 2); |
|
154 | 154 | |
155 | 155 | /** |
156 | 156 | * Retrieves the emails for which admin notifications are sent to (these can be |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | function give_get_admin_notice_emails() { |
164 | 164 | global $give_options; |
165 | 165 | |
166 | - $emails = isset( $give_options['admin_notice_emails'] ) && strlen( trim( $give_options['admin_notice_emails'] ) ) > 0 ? $give_options['admin_notice_emails'] : get_bloginfo( 'admin_email' ); |
|
167 | - $emails = array_map( 'trim', explode( "\n", $emails ) ); |
|
166 | + $emails = isset($give_options['admin_notice_emails']) && strlen(trim($give_options['admin_notice_emails'])) > 0 ? $give_options['admin_notice_emails'] : get_bloginfo('admin_email'); |
|
167 | + $emails = array_map('trim', explode("\n", $emails)); |
|
168 | 168 | |
169 | - return apply_filters( 'give_admin_notice_emails', $emails ); |
|
169 | + return apply_filters('give_admin_notice_emails', $emails); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return mixed |
180 | 180 | */ |
181 | -function give_admin_notices_disabled( $payment_id = 0 ) { |
|
181 | +function give_admin_notices_disabled($payment_id = 0) { |
|
182 | 182 | |
183 | - $retval = give_get_option( 'disable_admin_notices' ); |
|
183 | + $retval = give_get_option('disable_admin_notices'); |
|
184 | 184 | |
185 | - return apply_filters( 'give_admin_notices_disabled', $retval, $payment_id ); |
|
185 | + return apply_filters('give_admin_notices_disabled', $retval, $payment_id); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -195,18 +195,18 @@ discard block |
||
195 | 195 | */ |
196 | 196 | function give_get_default_donation_notification_email() { |
197 | 197 | |
198 | - $default_email_body = esc_html__( 'Hi there,', 'give' ) . "\n\n"; |
|
199 | - $default_email_body .= esc_html__( 'This email is to inform you that a new donation has been made on your website: ', 'give' ) . '<a href="' . get_bloginfo( 'url' ) . '" target="_blank">' . get_bloginfo( 'url' ) . '</a>' . ".\n\n"; |
|
200 | - $default_email_body .= '<strong>' . esc_html__( 'Donor: ', 'give' ) . '</strong> ' . ' {name}' . "\n"; |
|
201 | - $default_email_body .= '<strong>' . esc_html__( 'Donation: ', 'give' ) . '</strong> ' . ' {donation}' . "\n"; |
|
202 | - $default_email_body .= '<strong>' . esc_html__( 'Amount: ', 'give' ) . '</strong> ' . ' {price}' . "\n"; |
|
203 | - $default_email_body .= '<strong>' . esc_html__( 'Payment Method: ', 'give' ) . '</strong> ' . ' {payment_method}' . "\n\n"; |
|
204 | - $default_email_body .= esc_html__( 'Thank you,', 'give' ) . "\n\n" . '{sitename}'; |
|
198 | + $default_email_body = esc_html__('Hi there,', 'give')."\n\n"; |
|
199 | + $default_email_body .= esc_html__('This email is to inform you that a new donation has been made on your website: ', 'give').'<a href="'.get_bloginfo('url').'" target="_blank">'.get_bloginfo('url').'</a>'.".\n\n"; |
|
200 | + $default_email_body .= '<strong>'.esc_html__('Donor: ', 'give').'</strong> '.' {name}'."\n"; |
|
201 | + $default_email_body .= '<strong>'.esc_html__('Donation: ', 'give').'</strong> '.' {donation}'."\n"; |
|
202 | + $default_email_body .= '<strong>'.esc_html__('Amount: ', 'give').'</strong> '.' {price}'."\n"; |
|
203 | + $default_email_body .= '<strong>'.esc_html__('Payment Method: ', 'give').'</strong> '.' {payment_method}'."\n\n"; |
|
204 | + $default_email_body .= esc_html__('Thank you,', 'give')."\n\n".'{sitename}'; |
|
205 | 205 | |
206 | - $custom_message = give_get_option( 'donation_notification' ); |
|
207 | - $message = ! empty( $custom_message ) ? $custom_message : $default_email_body; |
|
206 | + $custom_message = give_get_option('donation_notification'); |
|
207 | + $message = ! empty($custom_message) ? $custom_message : $default_email_body; |
|
208 | 208 | |
209 | - return apply_filters( 'give_default_donation_notification_email', $message ); |
|
209 | + return apply_filters('give_default_donation_notification_email', $message); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | |
@@ -220,26 +220,26 @@ discard block |
||
220 | 220 | */ |
221 | 221 | function give_get_default_donation_receipt_email() { |
222 | 222 | |
223 | - $default_email_body = esc_html__( 'Dear', 'give' ) . " {name},\n\n"; |
|
224 | - $default_email_body .= esc_html__( 'Thank you for your donation. Your generosity is appreciated! Here are the details of your donation:', 'give' ) . "\n\n"; |
|
225 | - $default_email_body .= '<strong>' . esc_html__( 'Donor', 'give' ) . ':</strong> ' . '{fullname}' . "\n"; |
|
226 | - $default_email_body .= '<strong>' . esc_html__( 'Donation', 'give' ) . ':</strong> ' . '{donation}' . "\n"; |
|
227 | - $default_email_body .= '<strong>' . esc_html__( 'Donation Date', 'give' ) . ':</strong> ' . '{date}' . "\n"; |
|
228 | - $default_email_body .= '<strong>' . esc_html__( 'Amount', 'give' ) . ':</strong> ' . '{price}' . "\n"; |
|
229 | - $default_email_body .= '<strong>' . esc_html__( 'Payment Method', 'give' ) . ':</strong> ' . '{payment_method}' . "\n"; |
|
230 | - $default_email_body .= '<strong>' . esc_html__( 'Payment ID', 'give' ) . ':</strong> ' . '{payment_id}' . "\n"; |
|
231 | - $default_email_body .= '<strong>' . esc_html__( 'Receipt ID', 'give' ) . ':</strong> ' . '{receipt_id}' . "\n\n"; |
|
232 | - $default_email_body .= '{receipt_link}' . "\n\n"; |
|
223 | + $default_email_body = esc_html__('Dear', 'give')." {name},\n\n"; |
|
224 | + $default_email_body .= esc_html__('Thank you for your donation. Your generosity is appreciated! Here are the details of your donation:', 'give')."\n\n"; |
|
225 | + $default_email_body .= '<strong>'.esc_html__('Donor', 'give').':</strong> '.'{fullname}'."\n"; |
|
226 | + $default_email_body .= '<strong>'.esc_html__('Donation', 'give').':</strong> '.'{donation}'."\n"; |
|
227 | + $default_email_body .= '<strong>'.esc_html__('Donation Date', 'give').':</strong> '.'{date}'."\n"; |
|
228 | + $default_email_body .= '<strong>'.esc_html__('Amount', 'give').':</strong> '.'{price}'."\n"; |
|
229 | + $default_email_body .= '<strong>'.esc_html__('Payment Method', 'give').':</strong> '.'{payment_method}'."\n"; |
|
230 | + $default_email_body .= '<strong>'.esc_html__('Payment ID', 'give').':</strong> '.'{payment_id}'."\n"; |
|
231 | + $default_email_body .= '<strong>'.esc_html__('Receipt ID', 'give').':</strong> '.'{receipt_id}'."\n\n"; |
|
232 | + $default_email_body .= '{receipt_link}'."\n\n"; |
|
233 | 233 | |
234 | 234 | $default_email_body .= "\n\n"; |
235 | - $default_email_body .= esc_html__( 'Sincerely,', 'give' ); |
|
236 | - $default_email_body .= "\n" . '{sitename}' . "\n"; |
|
235 | + $default_email_body .= esc_html__('Sincerely,', 'give'); |
|
236 | + $default_email_body .= "\n".'{sitename}'."\n"; |
|
237 | 237 | |
238 | - $custom_message = give_get_option( 'donation_receipt' ); |
|
238 | + $custom_message = give_get_option('donation_receipt'); |
|
239 | 239 | |
240 | - $message = ! empty( $custom_message ) ? $custom_message : $default_email_body; |
|
240 | + $message = ! empty($custom_message) ? $custom_message : $default_email_body; |
|
241 | 241 | |
242 | - return apply_filters( 'give_default_donation_receipt_email', $message ); |
|
242 | + return apply_filters('give_default_donation_receipt_email', $message); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -251,19 +251,19 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return array $email_names |
253 | 253 | */ |
254 | -function give_get_email_names( $user_info ) { |
|
254 | +function give_get_email_names($user_info) { |
|
255 | 255 | $email_names = array(); |
256 | - $user_info = maybe_unserialize( $user_info ); |
|
256 | + $user_info = maybe_unserialize($user_info); |
|
257 | 257 | |
258 | 258 | $email_names['fullname'] = ''; |
259 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 && isset( $user_info['first_name'] ) ) { |
|
260 | - $user_data = get_userdata( $user_info['id'] ); |
|
259 | + if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) { |
|
260 | + $user_data = get_userdata($user_info['id']); |
|
261 | 261 | $email_names['name'] = $user_info['first_name']; |
262 | - $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
262 | + $email_names['fullname'] = $user_info['first_name'].' '.$user_info['last_name']; |
|
263 | 263 | $email_names['username'] = $user_data->user_login; |
264 | - } elseif ( isset( $user_info['first_name'] ) ) { |
|
264 | + } elseif (isset($user_info['first_name'])) { |
|
265 | 265 | $email_names['name'] = $user_info['first_name']; |
266 | - $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
266 | + $email_names['fullname'] = $user_info['first_name'].' '.$user_info['last_name']; |
|
267 | 267 | $email_names['username'] = $user_info['first_name']; |
268 | 268 | } else { |
269 | 269 | $email_names['name'] = $user_info['email']; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -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 | /** |
@@ -54,40 +54,40 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string $message Fully formatted message |
56 | 56 | */ |
57 | -function give_email_preview_template_tags( $message ) { |
|
57 | +function give_email_preview_template_tags($message) { |
|
58 | 58 | |
59 | - $price = give_currency_filter( give_format_amount( 10.50 ) ); |
|
59 | + $price = give_currency_filter(give_format_amount(10.50)); |
|
60 | 60 | |
61 | 61 | $gateway = 'PayPal'; |
62 | 62 | |
63 | - $receipt_id = strtolower( md5( uniqid() ) ); |
|
63 | + $receipt_id = strtolower(md5(uniqid())); |
|
64 | 64 | |
65 | - $notes = esc_html__( 'These are some sample notes added to a donation.', 'give' ); |
|
65 | + $notes = esc_html__('These are some sample notes added to a donation.', 'give'); |
|
66 | 66 | |
67 | - $payment_id = rand( 1, 100 ); |
|
67 | + $payment_id = rand(1, 100); |
|
68 | 68 | |
69 | 69 | $receipt_link = sprintf( |
70 | 70 | '<a href="%1$s">%2$s</a>', |
71 | - esc_url( add_query_arg( array( 'payment_key' => $receipt_id, 'give_action' => 'view_receipt' ), home_url() ) ), |
|
72 | - esc_html__( 'View the receipt in your browser', 'give' ) |
|
71 | + esc_url(add_query_arg(array('payment_key' => $receipt_id, 'give_action' => 'view_receipt'), home_url())), |
|
72 | + esc_html__('View the receipt in your browser', 'give') |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | $user = wp_get_current_user(); |
76 | 76 | |
77 | - $message = str_replace( '{name}', $user->display_name, $message ); |
|
78 | - $message = str_replace( '{fullname}', $user->display_name, $message ); |
|
79 | - $message = str_replace( '{username}', $user->user_login, $message ); |
|
80 | - $message = str_replace( '{date}', date( get_option( 'date_format' ), current_time( 'timestamp' ) ), $message ); |
|
81 | - $message = str_replace( '{price}', $price, $message ); |
|
82 | - $message = str_replace( '{donation}', 'Sample Donation Form Title', $message ); |
|
83 | - $message = str_replace( '{receipt_id}', $receipt_id, $message ); |
|
84 | - $message = str_replace( '{payment_method}', $gateway, $message ); |
|
85 | - $message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message ); |
|
86 | - $message = str_replace( '{product_notes}', $notes, $message ); |
|
87 | - $message = str_replace( '{payment_id}', $payment_id, $message ); |
|
88 | - $message = str_replace( '{receipt_link}', $receipt_link, $message ); |
|
89 | - |
|
90 | - return wpautop( apply_filters( 'give_email_preview_template_tags', $message ) ); |
|
77 | + $message = str_replace('{name}', $user->display_name, $message); |
|
78 | + $message = str_replace('{fullname}', $user->display_name, $message); |
|
79 | + $message = str_replace('{username}', $user->user_login, $message); |
|
80 | + $message = str_replace('{date}', date(get_option('date_format'), current_time('timestamp')), $message); |
|
81 | + $message = str_replace('{price}', $price, $message); |
|
82 | + $message = str_replace('{donation}', 'Sample Donation Form Title', $message); |
|
83 | + $message = str_replace('{receipt_id}', $receipt_id, $message); |
|
84 | + $message = str_replace('{payment_method}', $gateway, $message); |
|
85 | + $message = str_replace('{sitename}', get_bloginfo('name'), $message); |
|
86 | + $message = str_replace('{product_notes}', $notes, $message); |
|
87 | + $message = str_replace('{payment_id}', $payment_id, $message); |
|
88 | + $message = str_replace('{receipt_link}', $receipt_link, $message); |
|
89 | + |
|
90 | + return wpautop(apply_filters('give_email_preview_template_tags', $message)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,20 +100,20 @@ discard block |
||
100 | 100 | * @since 1.0 |
101 | 101 | * @return array|bool |
102 | 102 | */ |
103 | -add_filter( 'give_settings_emails', 'give_email_template_preview' ); |
|
103 | +add_filter('give_settings_emails', 'give_email_template_preview'); |
|
104 | 104 | |
105 | -function give_email_template_preview( $array ) { |
|
105 | +function give_email_template_preview($array) { |
|
106 | 106 | |
107 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
107 | + if ( ! current_user_can('manage_give_settings')) { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | $custom_field = array( |
111 | - 'name' => esc_html__( 'Preview Email', 'give' ), |
|
112 | - 'desc' => esc_html__( 'Click the buttons to preview emails.', 'give' ), |
|
111 | + 'name' => esc_html__('Preview Email', 'give'), |
|
112 | + 'desc' => esc_html__('Click the buttons to preview emails.', 'give'), |
|
113 | 113 | 'id' => 'give_email_preview_buttons', |
114 | 114 | 'type' => 'email_preview_buttons' |
115 | 115 | ); |
116 | - array_splice( $array, 5, 0, array( $custom_field ) ); |
|
116 | + array_splice($array, 5, 0, array($custom_field)); |
|
117 | 117 | |
118 | 118 | return $array; // splice in at position 3; |
119 | 119 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | function give_email_preview_buttons_callback() { |
130 | 130 | ob_start(); |
131 | 131 | ?> |
132 | - <a href="<?php echo esc_url( add_query_arg( array( 'give_action' => 'preview_email' ), home_url() ) ); ?>" class="button-secondary" target="_blank" title="<?php esc_attr_e( 'Donation Receipt Preview', 'give' ); ?> "><?php esc_html_e( 'Preview Donation Receipt', 'give' ); ?></a> |
|
133 | - <a href="<?php echo wp_nonce_url( add_query_arg( array( |
|
132 | + <a href="<?php echo esc_url(add_query_arg(array('give_action' => 'preview_email'), home_url())); ?>" class="button-secondary" target="_blank" title="<?php esc_attr_e('Donation Receipt Preview', 'give'); ?> "><?php esc_html_e('Preview Donation Receipt', 'give'); ?></a> |
|
133 | + <a href="<?php echo wp_nonce_url(add_query_arg(array( |
|
134 | 134 | 'give_action' => 'send_test_email', |
135 | 135 | 'give-message' => 'sent-test-email' |
136 | - ) ), 'give-test-email' ); ?>" title="<?php esc_attr_e( 'This will send a demo donation receipt to the emails listed below.', 'give' ); ?>" class="button-secondary"><?php esc_html_e( 'Send Test Email', 'give' ); ?></a> |
|
136 | + )), 'give-test-email'); ?>" title="<?php esc_attr_e('This will send a demo donation receipt to the emails listed below.', 'give'); ?>" class="button-secondary"><?php esc_html_e('Send Test Email', 'give'); ?></a> |
|
137 | 137 | <?php |
138 | 138 | echo ob_get_clean(); |
139 | 139 | } |
@@ -146,27 +146,27 @@ discard block |
||
146 | 146 | */ |
147 | 147 | function give_display_email_template_preview() { |
148 | 148 | |
149 | - if ( empty( $_GET['give_action'] ) ) { |
|
149 | + if (empty($_GET['give_action'])) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - if ( 'preview_email' !== $_GET['give_action'] ) { |
|
153 | + if ('preview_email' !== $_GET['give_action']) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
157 | + if ( ! current_user_can('manage_give_settings')) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - Give()->emails->heading = esc_html__( 'Donation Receipt', 'give' ); |
|
161 | + Give()->emails->heading = esc_html__('Donation Receipt', 'give'); |
|
162 | 162 | |
163 | - echo Give()->emails->build_email( give_email_preview_template_tags( give_get_email_body_content( 0, array() ) ) ); |
|
163 | + echo Give()->emails->build_email(give_email_preview_template_tags(give_get_email_body_content(0, array()))); |
|
164 | 164 | |
165 | 165 | exit; |
166 | 166 | |
167 | 167 | } |
168 | 168 | |
169 | -add_action( 'template_redirect', 'give_display_email_template_preview' ); |
|
169 | +add_action('template_redirect', 'give_display_email_template_preview'); |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Email Template Body |
@@ -178,19 +178,19 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return string $email_body Body of the email |
180 | 180 | */ |
181 | -function give_get_email_body_content( $payment_id = 0, $payment_data = array() ) { |
|
181 | +function give_get_email_body_content($payment_id = 0, $payment_data = array()) { |
|
182 | 182 | |
183 | 183 | global $give_options; |
184 | 184 | |
185 | 185 | $default_email_body = give_get_default_donation_receipt_email(); |
186 | 186 | |
187 | - $email = isset( $give_options['donation_receipt'] ) ? stripslashes( $give_options['donation_receipt'] ) : $default_email_body; |
|
187 | + $email = isset($give_options['donation_receipt']) ? stripslashes($give_options['donation_receipt']) : $default_email_body; |
|
188 | 188 | |
189 | - $email_body = wpautop( $email ); |
|
189 | + $email_body = wpautop($email); |
|
190 | 190 | |
191 | - $email_body = apply_filters( 'give_donation_receipt_' . Give()->emails->get_template(), $email_body, $payment_id, $payment_data ); |
|
191 | + $email_body = apply_filters('give_donation_receipt_'.Give()->emails->get_template(), $email_body, $payment_id, $payment_data); |
|
192 | 192 | |
193 | - return apply_filters( 'give_donation_receipt', $email_body, $payment_id, $payment_data ); |
|
193 | + return apply_filters('give_donation_receipt', $email_body, $payment_id, $payment_data); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -206,42 +206,42 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return string $email_body Body of the email |
208 | 208 | */ |
209 | -function give_get_donation_notification_body_content( $payment_id = 0, $payment_data = array() ) { |
|
209 | +function give_get_donation_notification_body_content($payment_id = 0, $payment_data = array()) { |
|
210 | 210 | global $give_options; |
211 | 211 | |
212 | - $user_info = maybe_unserialize( $payment_data['user_info'] ); |
|
213 | - $email = give_get_payment_user_email( $payment_id ); |
|
212 | + $user_info = maybe_unserialize($payment_data['user_info']); |
|
213 | + $email = give_get_payment_user_email($payment_id); |
|
214 | 214 | |
215 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { |
|
216 | - $user_data = get_userdata( $user_info['id'] ); |
|
215 | + if (isset($user_info['id']) && $user_info['id'] > 0) { |
|
216 | + $user_data = get_userdata($user_info['id']); |
|
217 | 217 | $name = $user_data->display_name; |
218 | - } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { |
|
219 | - $name = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
218 | + } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { |
|
219 | + $name = $user_info['first_name'].' '.$user_info['last_name']; |
|
220 | 220 | } else { |
221 | 221 | $name = $email; |
222 | 222 | } |
223 | 223 | |
224 | - $gateway = give_get_gateway_admin_label( get_post_meta( $payment_id, '_give_payment_gateway', true ) ); |
|
224 | + $gateway = give_get_gateway_admin_label(get_post_meta($payment_id, '_give_payment_gateway', true)); |
|
225 | 225 | |
226 | - $default_email_body = esc_html__( 'Hello', 'give' ) . "\n\n"; |
|
227 | - $default_email_body .= esc_html__( 'A donation has been made', 'give' ) . ".\n\n"; |
|
226 | + $default_email_body = esc_html__('Hello', 'give')."\n\n"; |
|
227 | + $default_email_body .= esc_html__('A donation has been made', 'give').".\n\n"; |
|
228 | 228 | $default_email_body .= sprintf( |
229 | 229 | /* translators: %s: form plural label */ |
230 | - esc_html__( '%s sold:', 'give' ), |
|
230 | + esc_html__('%s sold:', 'give'), |
|
231 | 231 | give_get_forms_label_plural() |
232 | - ) . "\n\n"; |
|
232 | + )."\n\n"; |
|
233 | 233 | |
234 | - $default_email_body .= esc_html__( 'Donor: ', 'give' ) . " " . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n"; |
|
235 | - $default_email_body .= esc_html__( 'Amount: ', 'give' ) . " " . html_entity_decode( give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ) ) ), ENT_COMPAT, 'UTF-8' ) . "\n"; |
|
236 | - $default_email_body .= esc_html__( 'Payment Method: ', 'give' ) . " " . $gateway . "\n\n"; |
|
234 | + $default_email_body .= esc_html__('Donor: ', 'give')." ".html_entity_decode($name, ENT_COMPAT, 'UTF-8')."\n"; |
|
235 | + $default_email_body .= esc_html__('Amount: ', 'give')." ".html_entity_decode(give_currency_filter(give_format_amount(give_get_payment_amount($payment_id))), ENT_COMPAT, 'UTF-8')."\n"; |
|
236 | + $default_email_body .= esc_html__('Payment Method: ', 'give')." ".$gateway."\n\n"; |
|
237 | 237 | |
238 | - $default_email_body .= esc_html__( 'Thank you', 'give' ); |
|
238 | + $default_email_body .= esc_html__('Thank you', 'give'); |
|
239 | 239 | |
240 | - $email = isset( $give_options['donation_notification'] ) ? stripslashes( $give_options['donation_notification'] ) : $default_email_body; |
|
240 | + $email = isset($give_options['donation_notification']) ? stripslashes($give_options['donation_notification']) : $default_email_body; |
|
241 | 241 | |
242 | - $email_body = give_do_email_tags( $email, $payment_id ); |
|
242 | + $email_body = give_do_email_tags($email, $payment_id); |
|
243 | 243 | |
244 | - return apply_filters( 'give_donation_notification', wpautop( $email_body ), $payment_id, $payment_data ); |
|
244 | + return apply_filters('give_donation_notification', wpautop($email_body), $payment_id, $payment_data); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -254,15 +254,15 @@ discard block |
||
254 | 254 | * @since 1.0 |
255 | 255 | */ |
256 | 256 | function give_render_receipt_in_browser() { |
257 | - if ( ! isset( $_GET['payment_key'] ) ) { |
|
258 | - wp_die( esc_html__( 'Missing donation payment key.', 'give' ), esc_html__( 'Error', 'give' ) ); |
|
257 | + if ( ! isset($_GET['payment_key'])) { |
|
258 | + wp_die(esc_html__('Missing donation payment key.', 'give'), esc_html__('Error', 'give')); |
|
259 | 259 | } |
260 | 260 | |
261 | - $key = urlencode( $_GET['payment_key'] ); |
|
261 | + $key = urlencode($_GET['payment_key']); |
|
262 | 262 | |
263 | 263 | ob_start(); |
264 | 264 | //Disallows caching of the page |
265 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
265 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
266 | 266 | header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 |
267 | 267 | header("Cache-Control: post-check=0, pre-check=0", false); |
268 | 268 | header("Pragma: no-cache"); // HTTP/1.0 |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | <!DOCTYPE html> |
272 | 272 | <html lang="en"> |
273 | 273 | <head> |
274 | - <title><?php esc_html_e( 'Donation Receipt', 'give' ); ?></title> |
|
274 | + <title><?php esc_html_e('Donation Receipt', 'give'); ?></title> |
|
275 | 275 | <meta charset="utf-8" /> |
276 | 276 | |
277 | 277 | <!-- Further disallowing of caching of this page --> |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | |
286 | 286 | <?php wp_head(); ?> |
287 | 287 | </head> |
288 | - <body class="<?php echo apply_filters( 'give_receipt_page_body_class', 'give_receipt_page' ); ?>"> |
|
288 | + <body class="<?php echo apply_filters('give_receipt_page_body_class', 'give_receipt_page'); ?>"> |
|
289 | 289 | |
290 | 290 | <div id="give_receipt_wrapper"> |
291 | - <?php do_action( 'give_render_receipt_in_browser_before' ); ?> |
|
292 | - <?php echo do_shortcode( '[give_receipt payment_key=' . $key . ']' ); ?> |
|
293 | - <?php do_action( 'give_render_receipt_in_browser_after' ); ?> |
|
291 | + <?php do_action('give_render_receipt_in_browser_before'); ?> |
|
292 | + <?php echo do_shortcode('[give_receipt payment_key='.$key.']'); ?> |
|
293 | + <?php do_action('give_render_receipt_in_browser_after'); ?> |
|
294 | 294 | </div> |
295 | 295 | |
296 | 296 | <?php wp_footer(); ?> |
@@ -301,4 +301,4 @@ discard block |
||
301 | 301 | die(); |
302 | 302 | } |
303 | 303 | |
304 | -add_action( 'give_view_receipt', 'give_render_receipt_in_browser' ); |
|
304 | +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,8 +29,8 @@ discard block |
||
29 | 29 | * @see Give_Cron::weekly_events() |
30 | 30 | */ |
31 | 31 | public function __construct() { |
32 | - add_filter( 'cron_schedules', array( $this, 'add_schedules' ) ); |
|
33 | - add_action( 'wp', array( $this, 'schedule_Events' ) ); |
|
32 | + add_filter('cron_schedules', array($this, 'add_schedules')); |
|
33 | + add_action('wp', array($this, 'schedule_Events')); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public function add_schedules( $schedules = array() ) { |
|
45 | + public function add_schedules($schedules = array()) { |
|
46 | 46 | // Adds once weekly to the existing schedules. |
47 | 47 | $schedules['weekly'] = array( |
48 | 48 | 'interval' => 604800, |
49 | - 'display' => esc_html__( 'Once Weekly', 'give' ) |
|
49 | + 'display' => esc_html__('Once Weekly', 'give') |
|
50 | 50 | ); |
51 | 51 | |
52 | 52 | return $schedules; |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * @return void |
73 | 73 | */ |
74 | 74 | private function weekly_events() { |
75 | - if ( ! wp_next_scheduled( 'give_weekly_scheduled_events' ) ) { |
|
76 | - wp_schedule_event( current_time( 'timestamp' ), 'weekly', 'give_weekly_scheduled_events' ); |
|
75 | + if ( ! wp_next_scheduled('give_weekly_scheduled_events')) { |
|
76 | + wp_schedule_event(current_time('timestamp'), 'weekly', 'give_weekly_scheduled_events'); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @return void |
86 | 86 | */ |
87 | 87 | private function daily_events() { |
88 | - if ( ! wp_next_scheduled( 'give_daily_scheduled_events' ) ) { |
|
89 | - wp_schedule_event( current_time( 'timestamp' ), 'daily', 'give_daily_scheduled_events' ); |
|
88 | + if ( ! wp_next_scheduled('give_daily_scheduled_events')) { |
|
89 | + wp_schedule_event(current_time('timestamp'), 'daily', 'give_daily_scheduled_events'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 |
@@ -1070,56 +1070,56 @@ |
||
1070 | 1070 | * @return bool |
1071 | 1071 | */ |
1072 | 1072 | function give_validate_multi_donation_form_level( $valid_data, $data ) { |
1073 | - /* @var Give_Donate_Form $form*/ |
|
1074 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1073 | + /* @var Give_Donate_Form $form*/ |
|
1074 | + $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1075 | 1075 | |
1076 | - $donation_level_matched = false; |
|
1076 | + $donation_level_matched = false; |
|
1077 | 1077 | |
1078 | - if( $form->is_multi_type_donation_form() ) { |
|
1078 | + if( $form->is_multi_type_donation_form() ) { |
|
1079 | 1079 | |
1080 | - // Bailout. |
|
1081 | - if( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1082 | - return false; |
|
1083 | - } |
|
1080 | + // Bailout. |
|
1081 | + if( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1082 | + return false; |
|
1083 | + } |
|
1084 | 1084 | |
1085 | - // Sanitize donation amount. |
|
1086 | - $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1085 | + // Sanitize donation amount. |
|
1086 | + $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1087 | 1087 | |
1088 | - // Do not auto select level for donation amount if we already have correct price id and donation amount. |
|
1089 | - if( $data['give-amount'] === give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ){ |
|
1090 | - return true; |
|
1091 | - } |
|
1088 | + // Do not auto select level for donation amount if we already have correct price id and donation amount. |
|
1089 | + if( $data['give-amount'] === give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ){ |
|
1090 | + return true; |
|
1091 | + } |
|
1092 | 1092 | |
1093 | 1093 | |
1094 | - // Find correct donation level from all donation levels. |
|
1095 | - foreach ( $variable_prices as $variable_price ) { |
|
1096 | - // Sanitize level amount. |
|
1097 | - $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'] ); |
|
1098 | - |
|
1099 | - // Set first match donation level ID. |
|
1100 | - if( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1101 | - $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
|
1102 | - $donation_level_matched = true; |
|
1103 | - break; |
|
1104 | - } |
|
1105 | - } |
|
1106 | - |
|
1107 | - // If donation amount is not find in donation levels then check if form has custom donation feature enable or not. |
|
1108 | - // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
|
1109 | - if( |
|
1110 | - ! $donation_level_matched |
|
1111 | - && ( 'yes' === get_post_meta( $data['give-form-id'], '_give_custom_amount', true ) ) |
|
1112 | - ) { |
|
1113 | - // Sanitize custom minimum amount. |
|
1114 | - $custom_minimum_amount = give_sanitize_amount( get_post_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) ); |
|
1115 | - |
|
1116 | - if( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1117 | - $_POST['give-price-id'] = 'custom'; |
|
1118 | - $donation_level_matched = true; |
|
1119 | - } |
|
1120 | - } |
|
1121 | - } |
|
1122 | - |
|
1123 | - return ( $donation_level_matched ? true : false ); |
|
1094 | + // Find correct donation level from all donation levels. |
|
1095 | + foreach ( $variable_prices as $variable_price ) { |
|
1096 | + // Sanitize level amount. |
|
1097 | + $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'] ); |
|
1098 | + |
|
1099 | + // Set first match donation level ID. |
|
1100 | + if( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1101 | + $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
|
1102 | + $donation_level_matched = true; |
|
1103 | + break; |
|
1104 | + } |
|
1105 | + } |
|
1106 | + |
|
1107 | + // If donation amount is not find in donation levels then check if form has custom donation feature enable or not. |
|
1108 | + // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
|
1109 | + if( |
|
1110 | + ! $donation_level_matched |
|
1111 | + && ( 'yes' === get_post_meta( $data['give-form-id'], '_give_custom_amount', true ) ) |
|
1112 | + ) { |
|
1113 | + // Sanitize custom minimum amount. |
|
1114 | + $custom_minimum_amount = give_sanitize_amount( get_post_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) ); |
|
1115 | + |
|
1116 | + if( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1117 | + $_POST['give-price-id'] = 'custom'; |
|
1118 | + $donation_level_matched = true; |
|
1119 | + } |
|
1120 | + } |
|
1121 | + } |
|
1122 | + |
|
1123 | + return ( $donation_level_matched ? true : false ); |
|
1124 | 1124 | } |
1125 | 1125 | add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
1126 | 1126 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -25,27 +25,27 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_process_purchase_form() { |
27 | 27 | |
28 | - do_action( 'give_pre_process_purchase' ); |
|
28 | + do_action('give_pre_process_purchase'); |
|
29 | 29 | |
30 | 30 | // Validate the form $_POST data |
31 | 31 | $valid_data = give_purchase_form_validate_fields(); |
32 | 32 | |
33 | 33 | // Allow themes and plugins to hook to errors |
34 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
34 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
35 | 35 | |
36 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
36 | + $is_ajax = isset($_POST['give_ajax']); |
|
37 | 37 | |
38 | 38 | // Process the login form |
39 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
39 | + if (isset($_POST['give_login_submit'])) { |
|
40 | 40 | give_process_form_login(); |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Validate the user |
44 | - $user = give_get_purchase_form_user( $valid_data ); |
|
44 | + $user = give_get_purchase_form_user($valid_data); |
|
45 | 45 | |
46 | - if ( false === $valid_data || give_get_errors() || ! $user ) { |
|
47 | - if ( $is_ajax ) { |
|
48 | - do_action( 'give_ajax_checkout_errors' ); |
|
46 | + if (false === $valid_data || give_get_errors() || ! $user) { |
|
47 | + if ($is_ajax) { |
|
48 | + do_action('give_ajax_checkout_errors'); |
|
49 | 49 | give_die(); |
50 | 50 | } else { |
51 | 51 | return false; |
@@ -53,17 +53,17 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | //If AJAX send back success to proceed with form submission |
56 | - if ( $is_ajax ) { |
|
56 | + if ($is_ajax) { |
|
57 | 57 | echo 'success'; |
58 | 58 | give_die(); |
59 | 59 | } |
60 | 60 | |
61 | 61 | //After AJAX: Setup session if not using php_sessions |
62 | - if ( ! Give()->session->use_php_sessions() ) { |
|
62 | + if ( ! Give()->session->use_php_sessions()) { |
|
63 | 63 | //Double-check that set_cookie is publicly accessible; |
64 | 64 | // we're using a slightly modified class-wp-sessions.php |
65 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
66 | - if ( $session_reflection->isPublic() ) { |
|
65 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
66 | + if ($session_reflection->isPublic()) { |
|
67 | 67 | // Manually set the cookie. |
68 | 68 | Give()->session->init()->set_cookie(); |
69 | 69 | } |
@@ -78,18 +78,18 @@ discard block |
||
78 | 78 | 'address' => $user['address'] |
79 | 79 | ); |
80 | 80 | |
81 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
81 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
82 | 82 | |
83 | - $price = isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00'; |
|
84 | - $purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); |
|
83 | + $price = isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'; |
|
84 | + $purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); |
|
85 | 85 | |
86 | 86 | // Setup purchase information |
87 | 87 | $purchase_data = array( |
88 | 88 | 'price' => $price, |
89 | 89 | 'purchase_key' => $purchase_key, |
90 | 90 | 'user_email' => $user['user_email'], |
91 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
92 | - 'user_info' => stripslashes_deep( $user_info ), |
|
91 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
92 | + 'user_info' => stripslashes_deep($user_info), |
|
93 | 93 | 'post_data' => $_POST, |
94 | 94 | 'gateway' => $valid_data['gateway'], |
95 | 95 | 'card_info' => $valid_data['cc_info'] |
@@ -99,37 +99,37 @@ discard block |
||
99 | 99 | $valid_data['user'] = $user; |
100 | 100 | |
101 | 101 | // Allow themes and plugins to hook before the gateway |
102 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
102 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
103 | 103 | |
104 | 104 | //Sanity check for price |
105 | - if ( ! $purchase_data['price'] ) { |
|
105 | + if ( ! $purchase_data['price']) { |
|
106 | 106 | // Revert to manual |
107 | 107 | $purchase_data['gateway'] = 'manual'; |
108 | 108 | $_POST['give-gateway'] = 'manual'; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Allow the purchase data to be modified before it is sent to the gateway |
112 | - $purchase_data = apply_filters( 'give_purchase_data_before_gateway', $purchase_data, $valid_data ); |
|
112 | + $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); |
|
113 | 113 | |
114 | 114 | // Setup the data we're storing in the purchase session |
115 | 115 | $session_data = $purchase_data; |
116 | 116 | |
117 | 117 | // Make sure credit card numbers are never stored in sessions |
118 | - unset( $session_data['card_info']['card_number'] ); |
|
119 | - unset( $session_data['post_data']['card_number'] ); |
|
118 | + unset($session_data['card_info']['card_number']); |
|
119 | + unset($session_data['post_data']['card_number']); |
|
120 | 120 | |
121 | 121 | // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. |
122 | - give_set_purchase_session( $session_data ); |
|
122 | + give_set_purchase_session($session_data); |
|
123 | 123 | |
124 | 124 | // Send info to the gateway for payment processing |
125 | - give_send_to_gateway( $purchase_data['gateway'], $purchase_data ); |
|
125 | + give_send_to_gateway($purchase_data['gateway'], $purchase_data); |
|
126 | 126 | give_die(); |
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -add_action( 'give_purchase', 'give_process_purchase_form' ); |
|
131 | -add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' ); |
|
132 | -add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' ); |
|
130 | +add_action('give_purchase', 'give_process_purchase_form'); |
|
131 | +add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form'); |
|
132 | +add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form'); |
|
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Process the checkout login form |
@@ -140,32 +140,32 @@ discard block |
||
140 | 140 | */ |
141 | 141 | function give_process_form_login() { |
142 | 142 | |
143 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
143 | + $is_ajax = isset($_POST['give_ajax']); |
|
144 | 144 | |
145 | 145 | $user_data = give_purchase_form_validate_user_login(); |
146 | 146 | |
147 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
148 | - if ( $is_ajax ) { |
|
149 | - do_action( 'give_ajax_checkout_errors' ); |
|
147 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
148 | + if ($is_ajax) { |
|
149 | + do_action('give_ajax_checkout_errors'); |
|
150 | 150 | give_die(); |
151 | 151 | } else { |
152 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
152 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
153 | 153 | exit; |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
157 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
158 | 158 | |
159 | - if ( $is_ajax ) { |
|
159 | + if ($is_ajax) { |
|
160 | 160 | echo 'success'; |
161 | 161 | give_die(); |
162 | 162 | } else { |
163 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
163 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | -add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' ); |
|
168 | -add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' ); |
|
167 | +add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login'); |
|
168 | +add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login'); |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Purchase Form Validate Fields |
@@ -177,45 +177,45 @@ discard block |
||
177 | 177 | function give_purchase_form_validate_fields() { |
178 | 178 | |
179 | 179 | // Check if there is $_POST |
180 | - if ( empty( $_POST ) ) { |
|
180 | + if (empty($_POST)) { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
184 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
184 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
185 | 185 | |
186 | 186 | // Start an array to collect valid data |
187 | 187 | $valid_data = array( |
188 | 188 | 'gateway' => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here) |
189 | - 'need_new_user' => false, // New user flag |
|
190 | - 'need_user_login' => false, // Login user flag |
|
191 | - 'logged_user_data' => array(), // Logged user collected data |
|
192 | - 'new_user_data' => array(), // New user collected data |
|
193 | - 'login_user_data' => array(), // Login user collected data |
|
194 | - 'guest_user_data' => array(), // Guest user collected data |
|
189 | + 'need_new_user' => false, // New user flag |
|
190 | + 'need_user_login' => false, // Login user flag |
|
191 | + 'logged_user_data' => array(), // Logged user collected data |
|
192 | + 'new_user_data' => array(), // New user collected data |
|
193 | + 'login_user_data' => array(), // Login user collected data |
|
194 | + 'guest_user_data' => array(), // Guest user collected data |
|
195 | 195 | 'cc_info' => give_purchase_form_validate_cc() // Credit card info |
196 | 196 | ); |
197 | 197 | |
198 | 198 | //Validate Honeypot First |
199 | - if ( ! empty( $_POST['give-honeypot'] ) ) { |
|
200 | - give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) ); |
|
199 | + if ( ! empty($_POST['give-honeypot'])) { |
|
200 | + give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give')); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Validate agree to terms |
204 | - $terms_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
205 | - if ( isset( $terms_option ) && $terms_option === 'yes' ) { |
|
204 | + $terms_option = get_post_meta($form_id, '_give_terms_option', true); |
|
205 | + if (isset($terms_option) && $terms_option === 'yes') { |
|
206 | 206 | give_purchase_form_validate_agree_to_terms(); |
207 | 207 | } |
208 | 208 | |
209 | - if ( is_user_logged_in() ) { |
|
209 | + if (is_user_logged_in()) { |
|
210 | 210 | // Collect logged in user data |
211 | 211 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
212 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
212 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
213 | 213 | // Set new user registration as required |
214 | 214 | $valid_data['need_new_user'] = true; |
215 | 215 | // Validate new user data |
216 | 216 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
217 | 217 | // Check if login validation is needed |
218 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
218 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
219 | 219 | // Set user login as required |
220 | 220 | $valid_data['need_user_login'] = true; |
221 | 221 | // Validate users login info |
@@ -240,41 +240,41 @@ discard block |
||
240 | 240 | */ |
241 | 241 | function give_purchase_form_validate_gateway() { |
242 | 242 | |
243 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
244 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
245 | - $gateway = give_get_default_gateway( $form_id ); |
|
243 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
244 | + $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
245 | + $gateway = give_get_default_gateway($form_id); |
|
246 | 246 | |
247 | 247 | // Check if a gateway value is present |
248 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
248 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
249 | 249 | |
250 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
250 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
251 | 251 | |
252 | 252 | //Is amount being donated in LIVE mode 0.00? If so, error: |
253 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
253 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
254 | 254 | |
255 | - give_set_error( 'invalid_donation_amount', esc_html__( 'Please insert a valid donation amount.', 'give' ) ); |
|
255 | + give_set_error('invalid_donation_amount', esc_html__('Please insert a valid donation amount.', 'give')); |
|
256 | 256 | |
257 | 257 | } //Check for a minimum custom amount |
258 | - elseif ( ! give_verify_minimum_price() ) { |
|
258 | + elseif ( ! give_verify_minimum_price()) { |
|
259 | 259 | |
260 | 260 | give_set_error( |
261 | 261 | 'invalid_donation_minimum', |
262 | 262 | sprintf( |
263 | 263 | /* translators: %s: minimum donation amount */ |
264 | - esc_html__( 'This form has a minimum donation amount of %s.', 'give' ), |
|
265 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) ) |
|
264 | + esc_html__('This form has a minimum donation amount of %s.', 'give'), |
|
265 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))) |
|
266 | 266 | ) |
267 | 267 | ); |
268 | 268 | |
269 | 269 | } //Is this test mode zero donation? Let it through but set to manual gateway |
270 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
270 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
271 | 271 | |
272 | 272 | $gateway = 'manual'; |
273 | 273 | |
274 | 274 | } //Check if this gateway is active |
275 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
275 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
276 | 276 | |
277 | - give_set_error( 'invalid_gateway', esc_html__( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
277 | + give_set_error('invalid_gateway', esc_html__('The selected payment gateway is not enabled.', 'give')); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -293,23 +293,23 @@ discard block |
||
293 | 293 | */ |
294 | 294 | function give_verify_minimum_price() { |
295 | 295 | |
296 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
297 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
298 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
299 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
296 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
297 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
298 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
299 | + $variable_prices = give_has_variable_prices($form_id); |
|
300 | 300 | |
301 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
301 | + if ($variable_prices && ! empty($price_id)) { |
|
302 | 302 | |
303 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
303 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
304 | 304 | |
305 | - if ( $price_level_amount == $amount ) { |
|
305 | + if ($price_level_amount == $amount) { |
|
306 | 306 | return true; |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
310 | + $minimum = give_get_form_minimum_price($form_id); |
|
311 | 311 | |
312 | - if ( $minimum > $amount ) { |
|
312 | + if ($minimum > $amount) { |
|
313 | 313 | return false; |
314 | 314 | } |
315 | 315 | |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | */ |
326 | 326 | function give_purchase_form_validate_agree_to_terms() { |
327 | 327 | // Validate agree to terms |
328 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
328 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
329 | 329 | // User did not agree |
330 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', esc_html__( 'You must agree to the terms of use.', 'give' ) ) ); |
|
330 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', esc_html__('You must agree to the terms of use.', 'give'))); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -341,47 +341,47 @@ discard block |
||
341 | 341 | * |
342 | 342 | * @return array |
343 | 343 | */ |
344 | -function give_purchase_form_required_fields( $form_id ) { |
|
344 | +function give_purchase_form_required_fields($form_id) { |
|
345 | 345 | |
346 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
346 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
347 | 347 | |
348 | 348 | $required_fields = array( |
349 | 349 | 'give_email' => array( |
350 | 350 | 'error_id' => 'invalid_email', |
351 | - 'error_message' => esc_html__( 'Please enter a valid email address.', 'give' ) |
|
351 | + 'error_message' => esc_html__('Please enter a valid email address.', 'give') |
|
352 | 352 | ), |
353 | 353 | 'give_first' => array( |
354 | 354 | 'error_id' => 'invalid_first_name', |
355 | - 'error_message' => esc_html__( 'Please enter your first name.', 'give' ) |
|
355 | + 'error_message' => esc_html__('Please enter your first name.', 'give') |
|
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | |
359 | - $require_address = give_require_billing_address( $payment_mode ); |
|
359 | + $require_address = give_require_billing_address($payment_mode); |
|
360 | 360 | |
361 | - if ( $require_address ) { |
|
362 | - $required_fields['card_address'] = array( |
|
361 | + if ($require_address) { |
|
362 | + $required_fields['card_address'] = array( |
|
363 | 363 | 'error_id' => 'invalid_card_address', |
364 | - 'error_message' => esc_html__( 'Please enter your primary billing address.', 'give' ) |
|
364 | + 'error_message' => esc_html__('Please enter your primary billing address.', 'give') |
|
365 | 365 | ); |
366 | - $required_fields['card_zip'] = array( |
|
366 | + $required_fields['card_zip'] = array( |
|
367 | 367 | 'error_id' => 'invalid_zip_code', |
368 | - 'error_message' => esc_html__( 'Please enter your zip / postal code.', 'give' ) |
|
368 | + 'error_message' => esc_html__('Please enter your zip / postal code.', 'give') |
|
369 | 369 | ); |
370 | - $required_fields['card_city'] = array( |
|
370 | + $required_fields['card_city'] = array( |
|
371 | 371 | 'error_id' => 'invalid_city', |
372 | - 'error_message' => esc_html__( 'Please enter your billing city.', 'give' ) |
|
372 | + 'error_message' => esc_html__('Please enter your billing city.', 'give') |
|
373 | 373 | ); |
374 | 374 | $required_fields['billing_country'] = array( |
375 | 375 | 'error_id' => 'invalid_country', |
376 | - 'error_message' => esc_html__( 'Please select your billing country.', 'give' ) |
|
376 | + 'error_message' => esc_html__('Please select your billing country.', 'give') |
|
377 | 377 | ); |
378 | - $required_fields['card_state'] = array( |
|
378 | + $required_fields['card_state'] = array( |
|
379 | 379 | 'error_id' => 'invalid_state', |
380 | - 'error_message' => esc_html__( 'Please enter billing state / province.', 'give' ) |
|
380 | + 'error_message' => esc_html__('Please enter billing state / province.', 'give') |
|
381 | 381 | ); |
382 | 382 | } |
383 | 383 | |
384 | - return apply_filters( 'give_purchase_form_required_fields', $required_fields, $form_id ); |
|
384 | + return apply_filters('give_purchase_form_required_fields', $required_fields, $form_id); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @return mixed|void |
396 | 396 | */ |
397 | -function give_require_billing_address( $payment_mode ) { |
|
397 | +function give_require_billing_address($payment_mode) { |
|
398 | 398 | |
399 | 399 | $return = false; |
400 | 400 | |
401 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
401 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
402 | 402 | $return = true; |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Let payment gateways and other extensions determine if address fields should be required |
406 | - return apply_filters( 'give_require_billing_address', $return ); |
|
406 | + return apply_filters('give_require_billing_address', $return); |
|
407 | 407 | |
408 | 408 | } |
409 | 409 | |
@@ -417,43 +417,43 @@ discard block |
||
417 | 417 | function give_purchase_form_validate_logged_in_user() { |
418 | 418 | global $user_ID; |
419 | 419 | |
420 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
420 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
421 | 421 | |
422 | 422 | // Start empty array to collect valid user data |
423 | 423 | $valid_user_data = array( |
424 | 424 | // Assume there will be errors |
425 | - 'user_id' => - 1 |
|
425 | + 'user_id' => -1 |
|
426 | 426 | ); |
427 | 427 | |
428 | 428 | // Verify there is a user_ID |
429 | - if ( $user_ID > 0 ) { |
|
429 | + if ($user_ID > 0) { |
|
430 | 430 | // Get the logged in user data |
431 | - $user_data = get_userdata( $user_ID ); |
|
431 | + $user_data = get_userdata($user_ID); |
|
432 | 432 | |
433 | 433 | // Loop through required fields and show error messages |
434 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
435 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
436 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
434 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
435 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
436 | + give_set_error($value['error_id'], $value['error_message']); |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
440 | 440 | // Verify data |
441 | - if ( $user_data ) { |
|
441 | + if ($user_data) { |
|
442 | 442 | // Collected logged in user data |
443 | 443 | $valid_user_data = array( |
444 | 444 | 'user_id' => $user_ID, |
445 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
446 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
447 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
445 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
446 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
447 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
448 | 448 | ); |
449 | 449 | |
450 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
451 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email', 'give' ) ); |
|
450 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
451 | + give_set_error('email_invalid', esc_html__('Invalid email', 'give')); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | } else { |
455 | 455 | // Set invalid user error |
456 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
456 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
@@ -471,90 +471,90 @@ discard block |
||
471 | 471 | function give_purchase_form_validate_new_user() { |
472 | 472 | |
473 | 473 | $registering_new_user = false; |
474 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
474 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
475 | 475 | |
476 | 476 | // Start an empty array to collect valid user data |
477 | 477 | $valid_user_data = array( |
478 | 478 | // Assume there will be errors |
479 | - 'user_id' => - 1, |
|
479 | + 'user_id' => -1, |
|
480 | 480 | // Get first name |
481 | - 'user_first' => isset( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : '', |
|
481 | + 'user_first' => isset($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : '', |
|
482 | 482 | // Get last name |
483 | - 'user_last' => isset( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : '', |
|
483 | + 'user_last' => isset($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : '', |
|
484 | 484 | ); |
485 | 485 | |
486 | 486 | // Check the new user's credentials against existing ones |
487 | - $user_login = isset( $_POST['give_user_login'] ) ? trim( $_POST['give_user_login'] ) : false; |
|
488 | - $user_email = isset( $_POST['give_email'] ) ? trim( $_POST['give_email'] ) : false; |
|
489 | - $user_pass = isset( $_POST['give_user_pass'] ) ? trim( $_POST['give_user_pass'] ) : false; |
|
490 | - $pass_confirm = isset( $_POST['give_user_pass_confirm'] ) ? trim( $_POST['give_user_pass_confirm'] ) : false; |
|
487 | + $user_login = isset($_POST['give_user_login']) ? trim($_POST['give_user_login']) : false; |
|
488 | + $user_email = isset($_POST['give_email']) ? trim($_POST['give_email']) : false; |
|
489 | + $user_pass = isset($_POST['give_user_pass']) ? trim($_POST['give_user_pass']) : false; |
|
490 | + $pass_confirm = isset($_POST['give_user_pass_confirm']) ? trim($_POST['give_user_pass_confirm']) : false; |
|
491 | 491 | |
492 | 492 | // Loop through required fields and show error messages |
493 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
494 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
495 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
493 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
494 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
495 | + give_set_error($value['error_id'], $value['error_message']); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | |
499 | 499 | // Check if we have an username to register |
500 | - if ( $user_login && strlen( $user_login ) > 0 ) { |
|
500 | + if ($user_login && strlen($user_login) > 0) { |
|
501 | 501 | $registering_new_user = true; |
502 | 502 | |
503 | 503 | // We have an user name, check if it already exists |
504 | - if ( username_exists( $user_login ) ) { |
|
504 | + if (username_exists($user_login)) { |
|
505 | 505 | // Username already registered |
506 | - give_set_error( 'username_unavailable', esc_html__( 'Username already taken.', 'give' ) ); |
|
506 | + give_set_error('username_unavailable', esc_html__('Username already taken.', 'give')); |
|
507 | 507 | // Check if it's valid |
508 | - } else if ( ! give_validate_username( $user_login ) ) { |
|
508 | + } else if ( ! give_validate_username($user_login)) { |
|
509 | 509 | // Invalid username |
510 | - if ( is_multisite() ) { |
|
511 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) ); |
|
510 | + if (is_multisite()) { |
|
511 | + give_set_error('username_invalid', esc_html__('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give')); |
|
512 | 512 | } else { |
513 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username.', 'give' ) ); |
|
513 | + give_set_error('username_invalid', esc_html__('Invalid username.', 'give')); |
|
514 | 514 | } |
515 | 515 | } else { |
516 | 516 | // All the checks have run and it's good to go |
517 | 517 | $valid_user_data['user_login'] = $user_login; |
518 | 518 | } |
519 | - } elseif ( give_logged_in_only( $form_id ) ) { |
|
520 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation.', 'give' ) ); |
|
519 | + } elseif (give_logged_in_only($form_id)) { |
|
520 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation.', 'give')); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | // Check if we have an email to verify |
524 | - if ( $user_email && strlen( $user_email ) > 0 ) { |
|
524 | + if ($user_email && strlen($user_email) > 0) { |
|
525 | 525 | // Validate email |
526 | - if ( ! is_email( $user_email ) ) { |
|
527 | - give_set_error( 'email_invalid', esc_html__( 'Sorry, that email is invalid.', 'give' ) ); |
|
526 | + if ( ! is_email($user_email)) { |
|
527 | + give_set_error('email_invalid', esc_html__('Sorry, that email is invalid.', 'give')); |
|
528 | 528 | // Check if email exists |
529 | - } else if ( email_exists( $user_email ) && $registering_new_user ) { |
|
530 | - give_set_error( 'email_used', esc_html__( 'Sorry, that email already active for another user.', 'give' ) ); |
|
529 | + } else if (email_exists($user_email) && $registering_new_user) { |
|
530 | + give_set_error('email_used', esc_html__('Sorry, that email already active for another user.', 'give')); |
|
531 | 531 | } else { |
532 | 532 | // All the checks have run and it's good to go |
533 | 533 | $valid_user_data['user_email'] = $user_email; |
534 | 534 | } |
535 | 535 | } else { |
536 | 536 | // No email |
537 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
537 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | // Check password |
541 | - if ( $user_pass && $pass_confirm ) { |
|
541 | + if ($user_pass && $pass_confirm) { |
|
542 | 542 | // Verify confirmation matches |
543 | - if ( $user_pass != $pass_confirm ) { |
|
543 | + if ($user_pass != $pass_confirm) { |
|
544 | 544 | // Passwords do not match |
545 | - give_set_error( 'password_mismatch', esc_html__( 'Passwords don\'t match.', 'give' ) ); |
|
545 | + give_set_error('password_mismatch', esc_html__('Passwords don\'t match.', 'give')); |
|
546 | 546 | } else { |
547 | 547 | // All is good to go |
548 | 548 | $valid_user_data['user_pass'] = $user_pass; |
549 | 549 | } |
550 | 550 | } else { |
551 | 551 | // Password or confirmation missing |
552 | - if ( ! $user_pass && $registering_new_user ) { |
|
552 | + if ( ! $user_pass && $registering_new_user) { |
|
553 | 553 | // The password is invalid |
554 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
555 | - } else if ( ! $pass_confirm && $registering_new_user ) { |
|
554 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
555 | + } else if ( ! $pass_confirm && $registering_new_user) { |
|
556 | 556 | // Confirmation password is invalid |
557 | - give_set_error( 'confirmation_empty', esc_html__( 'Enter the password confirmation.', 'give' ) ); |
|
557 | + give_set_error('confirmation_empty', esc_html__('Enter the password confirmation.', 'give')); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -573,36 +573,36 @@ discard block |
||
573 | 573 | // Start an array to collect valid user data |
574 | 574 | $valid_user_data = array( |
575 | 575 | // Assume there will be errors |
576 | - 'user_id' => - 1 |
|
576 | + 'user_id' => -1 |
|
577 | 577 | ); |
578 | 578 | |
579 | 579 | // Username |
580 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
581 | - give_set_error( 'must_log_in', esc_html__( 'You must login or register to complete your donation.', 'give' ) ); |
|
580 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
581 | + give_set_error('must_log_in', esc_html__('You must login or register to complete your donation.', 'give')); |
|
582 | 582 | |
583 | 583 | return $valid_user_data; |
584 | 584 | } |
585 | 585 | |
586 | 586 | // Get the user by login |
587 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
587 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
588 | 588 | |
589 | 589 | // Check if user exists |
590 | - if ( $user_data ) { |
|
590 | + if ($user_data) { |
|
591 | 591 | // Get password |
592 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
592 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
593 | 593 | |
594 | 594 | // Check user_pass |
595 | - if ( $user_pass ) { |
|
595 | + if ($user_pass) { |
|
596 | 596 | // Check if password is valid |
597 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
597 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
598 | 598 | // Incorrect password |
599 | 599 | give_set_error( |
600 | 600 | 'password_incorrect', |
601 | 601 | sprintf( |
602 | 602 | '%1$s <a href="%2$s">%3$s</a>', |
603 | - esc_html__( 'The password you entered is incorrect.', 'give' ), |
|
604 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
605 | - esc_html__( 'Reset Password', 'give' ) |
|
603 | + esc_html__('The password you entered is incorrect.', 'give'), |
|
604 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
605 | + esc_html__('Reset Password', 'give') |
|
606 | 606 | ) |
607 | 607 | ); |
608 | 608 | // All is correct |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | } |
620 | 620 | } else { |
621 | 621 | // Empty password |
622 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
622 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
623 | 623 | } |
624 | 624 | } else { |
625 | 625 | // no username |
626 | - give_set_error( 'username_incorrect', esc_html__( 'The username you entered does not exist.', 'give' ) ); |
|
626 | + give_set_error('username_incorrect', esc_html__('The username you entered does not exist.', 'give')); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | return $valid_user_data; |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | */ |
639 | 639 | function give_purchase_form_validate_guest_user() { |
640 | 640 | |
641 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
641 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
642 | 642 | |
643 | 643 | // Start an array to collect valid user data |
644 | 644 | $valid_user_data = array( |
@@ -647,32 +647,32 @@ discard block |
||
647 | 647 | ); |
648 | 648 | |
649 | 649 | // Show error message if user must be logged in |
650 | - if ( give_logged_in_only( $form_id ) ) { |
|
651 | - give_set_error( 'logged_in_only', esc_html__( 'You must be logged into to donate.', 'give' ) ); |
|
650 | + if (give_logged_in_only($form_id)) { |
|
651 | + give_set_error('logged_in_only', esc_html__('You must be logged into to donate.', 'give')); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | // Get the guest email |
655 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
655 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
656 | 656 | |
657 | 657 | // Check email |
658 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
658 | + if ($guest_email && strlen($guest_email) > 0) { |
|
659 | 659 | // Validate email |
660 | - if ( ! is_email( $guest_email ) ) { |
|
660 | + if ( ! is_email($guest_email)) { |
|
661 | 661 | // Invalid email |
662 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
662 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
663 | 663 | } else { |
664 | 664 | // All is good to go |
665 | 665 | $valid_user_data['user_email'] = $guest_email; |
666 | 666 | } |
667 | 667 | } else { |
668 | 668 | // No email |
669 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
669 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Loop through required fields and show error messages |
673 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
674 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
675 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
673 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
674 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
675 | + give_set_error($value['error_id'], $value['error_message']); |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
@@ -688,42 +688,42 @@ discard block |
||
688 | 688 | * @since 1.0 |
689 | 689 | * @return integer |
690 | 690 | */ |
691 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
691 | +function give_register_and_login_new_user($user_data = array()) { |
|
692 | 692 | // Verify the array |
693 | - if ( empty( $user_data ) ) { |
|
694 | - return - 1; |
|
693 | + if (empty($user_data)) { |
|
694 | + return -1; |
|
695 | 695 | } |
696 | 696 | |
697 | - if ( give_get_errors() ) { |
|
698 | - return - 1; |
|
697 | + if (give_get_errors()) { |
|
698 | + return -1; |
|
699 | 699 | } |
700 | 700 | |
701 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
702 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
703 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
704 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
705 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
706 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
707 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
708 | - 'role' => get_option( 'default_role' ) |
|
709 | - ), $user_data ); |
|
701 | + $user_args = apply_filters('give_insert_user_args', array( |
|
702 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
703 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
704 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
705 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
706 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
707 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
708 | + 'role' => get_option('default_role') |
|
709 | + ), $user_data); |
|
710 | 710 | |
711 | 711 | // Insert new user |
712 | - $user_id = wp_insert_user( $user_args ); |
|
712 | + $user_id = wp_insert_user($user_args); |
|
713 | 713 | |
714 | 714 | // Validate inserted user |
715 | - if ( is_wp_error( $user_id ) ) { |
|
716 | - return - 1; |
|
715 | + if (is_wp_error($user_id)) { |
|
716 | + return -1; |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | // Allow themes and plugins to filter the user data |
720 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
720 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
721 | 721 | |
722 | 722 | // Allow themes and plugins to hook |
723 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
723 | + do_action('give_insert_user', $user_id, $user_data); |
|
724 | 724 | |
725 | 725 | // Login new user |
726 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
726 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
727 | 727 | |
728 | 728 | // Return user id |
729 | 729 | return $user_id; |
@@ -738,27 +738,27 @@ discard block |
||
738 | 738 | * @since 1.0 |
739 | 739 | * @return array |
740 | 740 | */ |
741 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
741 | +function give_get_purchase_form_user($valid_data = array()) { |
|
742 | 742 | |
743 | 743 | // Initialize user |
744 | 744 | $user = false; |
745 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
745 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
746 | 746 | |
747 | - if ( $is_ajax ) { |
|
747 | + if ($is_ajax) { |
|
748 | 748 | // Do not create or login the user during the ajax submission (check for errors only) |
749 | 749 | return true; |
750 | - } else if ( is_user_logged_in() ) { |
|
750 | + } else if (is_user_logged_in()) { |
|
751 | 751 | // Set the valid user as the logged in collected data |
752 | 752 | $user = $valid_data['logged_in_user']; |
753 | - } else if ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
753 | + } else if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
754 | 754 | // New user registration |
755 | - if ( $valid_data['need_new_user'] === true ) { |
|
755 | + if ($valid_data['need_new_user'] === true) { |
|
756 | 756 | // Set user |
757 | 757 | $user = $valid_data['new_user_data']; |
758 | 758 | // Register and login new user |
759 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
759 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
760 | 760 | // User login |
761 | - } else if ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
761 | + } else if ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
762 | 762 | |
763 | 763 | /* |
764 | 764 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -773,48 +773,48 @@ discard block |
||
773 | 773 | // Set user |
774 | 774 | $user = $valid_data['login_user_data']; |
775 | 775 | // Login user |
776 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
776 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
777 | 777 | } |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Check guest checkout |
781 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
781 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
782 | 782 | // Set user |
783 | 783 | $user = $valid_data['guest_user_data']; |
784 | 784 | } |
785 | 785 | |
786 | 786 | // Verify we have an user |
787 | - if ( false === $user || empty( $user ) ) { |
|
787 | + if (false === $user || empty($user)) { |
|
788 | 788 | // Return false |
789 | 789 | return false; |
790 | 790 | } |
791 | 791 | |
792 | 792 | // Get user first name |
793 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
794 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
793 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
794 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | // Get user last name |
798 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
799 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
798 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
799 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | // Get the user's billing address details |
803 | 803 | $user['address'] = array(); |
804 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
805 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
806 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
807 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
808 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
809 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
810 | - |
|
811 | - if ( empty( $user['address']['country'] ) ) { |
|
804 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
805 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
806 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
807 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
808 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
809 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
810 | + |
|
811 | + if (empty($user['address']['country'])) { |
|
812 | 812 | $user['address'] = false; |
813 | 813 | } // Country will always be set if address fields are present |
814 | 814 | |
815 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
815 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
816 | 816 | // Store the address in the user's meta so the donation form can be pre-populated with it on return purchases |
817 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
817 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | // Return valid user |
@@ -833,16 +833,16 @@ discard block |
||
833 | 833 | $card_data = give_get_purchase_cc_info(); |
834 | 834 | |
835 | 835 | // Validate the card zip |
836 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
837 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
838 | - give_set_error( 'invalid_cc_zip', esc_html__( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
836 | + if ( ! empty($card_data['card_zip'])) { |
|
837 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
838 | + give_set_error('invalid_cc_zip', esc_html__('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
839 | 839 | } |
840 | 840 | } |
841 | 841 | |
842 | 842 | //Ensure no spaces |
843 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
844 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); //no "+" signs |
|
845 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
843 | + if ( ! empty($card_data['card_number'])) { |
|
844 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); //no "+" signs |
|
845 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | // This should validate card numbers at some point too |
@@ -858,17 +858,17 @@ discard block |
||
858 | 858 | */ |
859 | 859 | function give_get_purchase_cc_info() { |
860 | 860 | $cc_info = array(); |
861 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
862 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
863 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
864 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
865 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
866 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
867 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
868 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
869 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
870 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
871 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
861 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
862 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
863 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
864 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
865 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
866 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
867 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
868 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
869 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
870 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
871 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
872 | 872 | |
873 | 873 | // Return cc info |
874 | 874 | return $cc_info; |
@@ -884,14 +884,14 @@ discard block |
||
884 | 884 | * |
885 | 885 | * @return bool|mixed|void |
886 | 886 | */ |
887 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
887 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
888 | 888 | $ret = false; |
889 | 889 | |
890 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
890 | + if (empty($zip) || empty($country_code)) { |
|
891 | 891 | return $ret; |
892 | 892 | } |
893 | 893 | |
894 | - $country_code = strtoupper( $country_code ); |
|
894 | + $country_code = strtoupper($country_code); |
|
895 | 895 | |
896 | 896 | $zip_regex = array( |
897 | 897 | "AD" => "AD\d{3}", |
@@ -1051,11 +1051,11 @@ discard block |
||
1051 | 1051 | "ZM" => "\d{5}" |
1052 | 1052 | ); |
1053 | 1053 | |
1054 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
1054 | + if ( ! isset ($zip_regex[$country_code]) || preg_match("/".$zip_regex[$country_code]."/i", $zip)) { |
|
1055 | 1055 | $ret = true; |
1056 | 1056 | } |
1057 | 1057 | |
1058 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1058 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | |
@@ -1069,35 +1069,35 @@ discard block |
||
1069 | 1069 | * |
1070 | 1070 | * @return bool |
1071 | 1071 | */ |
1072 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1072 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1073 | 1073 | /* @var Give_Donate_Form $form*/ |
1074 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1074 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1075 | 1075 | |
1076 | 1076 | $donation_level_matched = false; |
1077 | 1077 | |
1078 | - if( $form->is_multi_type_donation_form() ) { |
|
1078 | + if ($form->is_multi_type_donation_form()) { |
|
1079 | 1079 | |
1080 | 1080 | // Bailout. |
1081 | - if( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1081 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1082 | 1082 | return false; |
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | // Sanitize donation amount. |
1086 | - $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1086 | + $data['give-amount'] = give_sanitize_amount($data['give-amount']); |
|
1087 | 1087 | |
1088 | 1088 | // Do not auto select level for donation amount if we already have correct price id and donation amount. |
1089 | - if( $data['give-amount'] === give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ){ |
|
1089 | + if ($data['give-amount'] === give_get_price_option_amount($data['give-form-id'], $data['give-price-id'])) { |
|
1090 | 1090 | return true; |
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
1094 | 1094 | // Find correct donation level from all donation levels. |
1095 | - foreach ( $variable_prices as $variable_price ) { |
|
1095 | + foreach ($variable_prices as $variable_price) { |
|
1096 | 1096 | // Sanitize level amount. |
1097 | - $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'] ); |
|
1097 | + $variable_price['_give_amount'] = give_sanitize_amount($variable_price['_give_amount']); |
|
1098 | 1098 | |
1099 | 1099 | // Set first match donation level ID. |
1100 | - if( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1100 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1101 | 1101 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1102 | 1102 | $donation_level_matched = true; |
1103 | 1103 | break; |
@@ -1106,20 +1106,20 @@ discard block |
||
1106 | 1106 | |
1107 | 1107 | // If donation amount is not find in donation levels then check if form has custom donation feature enable or not. |
1108 | 1108 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1109 | - if( |
|
1109 | + if ( |
|
1110 | 1110 | ! $donation_level_matched |
1111 | - && ( 'yes' === get_post_meta( $data['give-form-id'], '_give_custom_amount', true ) ) |
|
1111 | + && ('yes' === get_post_meta($data['give-form-id'], '_give_custom_amount', true)) |
|
1112 | 1112 | ) { |
1113 | 1113 | // Sanitize custom minimum amount. |
1114 | - $custom_minimum_amount = give_sanitize_amount( get_post_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) ); |
|
1114 | + $custom_minimum_amount = give_sanitize_amount(get_post_meta($data['give-form-id'], '_give_custom_amount_minimum', true)); |
|
1115 | 1115 | |
1116 | - if( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1116 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1117 | 1117 | $_POST['give-price-id'] = 'custom'; |
1118 | - $donation_level_matched = true; |
|
1118 | + $donation_level_matched = true; |
|
1119 | 1119 | } |
1120 | 1120 | } |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - return ( $donation_level_matched ? true : false ); |
|
1123 | + return ($donation_level_matched ? true : false); |
|
1124 | 1124 | } |
1125 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1126 | 1125 | \ No newline at end of file |
1126 | +add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2); |
|
1127 | 1127 | \ No newline at end of file |