@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @since 1.0 |
21 | 21 | * @return void |
22 | 22 | */ |
23 | -add_action( 'give_manual_cc_form', '__return_false' ); |
|
23 | +add_action('give_manual_cc_form', '__return_false'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Processes the purchase data and uses the Manual Payment gateway to record |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return void |
34 | 34 | */ |
35 | -function give_manual_payment( $purchase_data ) { |
|
35 | +function give_manual_payment($purchase_data) { |
|
36 | 36 | |
37 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
38 | - wp_die( esc_html__( 'Nonce verification has failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(esc_html__('Nonce verification has failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | //Create payment_data array |
42 | 42 | $payment_data = array( |
43 | 43 | 'price' => $purchase_data['price'], |
44 | 44 | 'give_form_title' => $purchase_data['post_data']['give-form-title'], |
45 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
|
45 | + 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), |
|
46 | 46 | 'give_price_id' => isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '', |
47 | 47 | 'date' => $purchase_data['date'], |
48 | 48 | 'user_email' => $purchase_data['user_email'], |
@@ -52,24 +52,24 @@ discard block |
||
52 | 52 | 'status' => 'pending' |
53 | 53 | ); |
54 | 54 | // Record the pending payment |
55 | - $payment = give_insert_payment( $payment_data ); |
|
55 | + $payment = give_insert_payment($payment_data); |
|
56 | 56 | |
57 | - if ( $payment ) { |
|
58 | - give_update_payment_status( $payment, 'publish' ); |
|
57 | + if ($payment) { |
|
58 | + give_update_payment_status($payment, 'publish'); |
|
59 | 59 | give_send_to_success_page(); |
60 | 60 | } else { |
61 | 61 | give_record_gateway_error( |
62 | - esc_html__( 'Payment Error', 'give' ), |
|
62 | + esc_html__('Payment Error', 'give'), |
|
63 | 63 | sprintf( |
64 | 64 | /* translators: %s: payment data */ |
65 | - esc_html__( 'The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give' ), |
|
66 | - json_encode( $payment_data ) |
|
65 | + esc_html__('The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give'), |
|
66 | + json_encode($payment_data) |
|
67 | 67 | ), |
68 | 68 | $payment |
69 | 69 | ); |
70 | 70 | // If errors are present, send the user back to the purchase page so they can be corrected |
71 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
71 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | -add_action( 'give_gateway_manual', 'give_manual_payment' ); |
|
75 | +add_action('give_gateway_manual', 'give_manual_payment'); |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return array |
20 | 20 | */ |
21 | -function give_offline_register_gateway( $gateways ) { |
|
21 | +function give_offline_register_gateway($gateways) { |
|
22 | 22 | // Format: ID => Name |
23 | 23 | $gateways['offline'] = array( |
24 | - 'admin_label' => esc_attr__( 'Offline Donation', 'give' ), |
|
25 | - 'checkout_label' => esc_attr__( 'Offline Donation', 'give' ) |
|
24 | + 'admin_label' => esc_attr__('Offline Donation', 'give'), |
|
25 | + 'checkout_label' => esc_attr__('Offline Donation', 'give') |
|
26 | 26 | ); |
27 | 27 | |
28 | 28 | return $gateways; |
29 | 29 | } |
30 | 30 | |
31 | -add_filter( 'give_payment_gateways', 'give_offline_register_gateway', 1 ); |
|
31 | +add_filter('give_payment_gateways', 'give_offline_register_gateway', 1); |
|
32 | 32 | |
33 | 33 | |
34 | 34 | /** |
@@ -40,56 +40,56 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return void |
42 | 42 | */ |
43 | -function give_offline_payment_cc_form( $form_id ) { |
|
43 | +function give_offline_payment_cc_form($form_id) { |
|
44 | 44 | |
45 | - $post_offline_customization_option = get_post_meta( $form_id, '_give_customize_offline_donations', true ); |
|
46 | - $post_offline_instructions = get_post_meta( $form_id, '_give_offline_checkout_notes', true ); |
|
47 | - $global_offline_instruction = give_get_option( 'global_offline_donation_content' ); |
|
45 | + $post_offline_customization_option = get_post_meta($form_id, '_give_customize_offline_donations', true); |
|
46 | + $post_offline_instructions = get_post_meta($form_id, '_give_offline_checkout_notes', true); |
|
47 | + $global_offline_instruction = give_get_option('global_offline_donation_content'); |
|
48 | 48 | $offline_instructions = $global_offline_instruction; |
49 | 49 | |
50 | - if ( $post_offline_customization_option == 'yes' ) { |
|
50 | + if ($post_offline_customization_option == 'yes') { |
|
51 | 51 | $offline_instructions = $post_offline_instructions; |
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | 55 | ob_start(); ?> |
56 | - <?php do_action( 'give_before_offline_info_fields', $form_id ); ?> |
|
56 | + <?php do_action('give_before_offline_info_fields', $form_id); ?> |
|
57 | 57 | <fieldset id="give_offline_payment_info"> |
58 | 58 | <?php |
59 | - $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' ); |
|
59 | + $settings_url = admin_url('post.php?post='.$form_id.'&action=edit&message=1'); |
|
60 | 60 | /* translators: %s: form settings url */ |
61 | - $offline_instructions = ! empty( $offline_instructions ) ? $offline_instructions : sprintf( esc_attr__( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), $settings_url ); |
|
62 | - echo wpautop( stripslashes( $offline_instructions ) ); |
|
61 | + $offline_instructions = ! empty($offline_instructions) ? $offline_instructions : sprintf(esc_attr__('Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give'), $settings_url); |
|
62 | + echo wpautop(stripslashes($offline_instructions)); |
|
63 | 63 | ?> |
64 | 64 | </fieldset> |
65 | - <?php do_action( 'give_after_offline_info_fields', $form_id ); ?> |
|
65 | + <?php do_action('give_after_offline_info_fields', $form_id); ?> |
|
66 | 66 | <?php |
67 | 67 | echo ob_get_clean(); |
68 | 68 | } |
69 | 69 | |
70 | -add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' ); |
|
70 | +add_action('give_offline_cc_form', 'give_offline_payment_cc_form'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Give Offline Billing Field |
74 | 74 | * |
75 | 75 | * @param $form_id |
76 | 76 | */ |
77 | -function give_offline_billing_fields( $form_id ) { |
|
77 | +function give_offline_billing_fields($form_id) { |
|
78 | 78 | //Enable Default CC fields (billing info) |
79 | - $post_offline_cc_fields = get_post_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ); |
|
80 | - $post_offline_customize_option = get_post_meta( $form_id, '_give_customize_offline_donations', true ); |
|
79 | + $post_offline_cc_fields = get_post_meta($form_id, '_give_offline_donation_enable_billing_fields_single', true); |
|
80 | + $post_offline_customize_option = get_post_meta($form_id, '_give_customize_offline_donations', true); |
|
81 | 81 | |
82 | - $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); |
|
82 | + $global_offline_cc_fields = give_get_option('give_offline_donation_enable_billing_fields'); |
|
83 | 83 | |
84 | 84 | //Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options |
85 | - if ( $global_offline_cc_fields == 'on' && $post_offline_customize_option !== 'yes' ) { |
|
86 | - give_default_cc_address_fields( $form_id ); |
|
87 | - } elseif($post_offline_customize_option == 'yes' && $post_offline_cc_fields == 'on') { |
|
88 | - give_default_cc_address_fields( $form_id ); |
|
85 | + if ($global_offline_cc_fields == 'on' && $post_offline_customize_option !== 'yes') { |
|
86 | + give_default_cc_address_fields($form_id); |
|
87 | + } elseif ($post_offline_customize_option == 'yes' && $post_offline_cc_fields == 'on') { |
|
88 | + give_default_cc_address_fields($form_id); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | -add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 ); |
|
92 | +add_action('give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1); |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * Process the payment |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return void |
102 | 102 | */ |
103 | -function give_offline_process_payment( $purchase_data ) { |
|
103 | +function give_offline_process_payment($purchase_data) { |
|
104 | 104 | |
105 | - $purchase_summary = give_get_purchase_summary( $purchase_data ); |
|
105 | + $purchase_summary = give_get_purchase_summary($purchase_data); |
|
106 | 106 | |
107 | 107 | // setup the payment details |
108 | 108 | $payment_data = array( |
109 | 109 | 'price' => $purchase_data['price'], |
110 | 110 | 'give_form_title' => $purchase_data['post_data']['give-form-title'], |
111 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
|
112 | - 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '', |
|
111 | + 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), |
|
112 | + 'give_price_id' => isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '', |
|
113 | 113 | 'date' => $purchase_data['date'], |
114 | 114 | 'user_email' => $purchase_data['user_email'], |
115 | 115 | 'purchase_key' => $purchase_data['purchase_key'], |
@@ -121,20 +121,20 @@ discard block |
||
121 | 121 | |
122 | 122 | |
123 | 123 | // record the pending payment |
124 | - $payment = give_insert_payment( $payment_data ); |
|
124 | + $payment = give_insert_payment($payment_data); |
|
125 | 125 | |
126 | - if ( $payment ) { |
|
127 | - give_offline_send_admin_notice( $payment ); |
|
128 | - give_offline_send_donor_instructions( $payment ); |
|
126 | + if ($payment) { |
|
127 | + give_offline_send_admin_notice($payment); |
|
128 | + give_offline_send_donor_instructions($payment); |
|
129 | 129 | give_send_to_success_page(); |
130 | 130 | } else { |
131 | 131 | // if errors are present, send the user back to the donation form so they can be corrected |
132 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
132 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | } |
136 | 136 | |
137 | -add_action( 'give_gateway_offline', 'give_offline_process_payment' ); |
|
137 | +add_action('give_gateway_offline', 'give_offline_process_payment'); |
|
138 | 138 | |
139 | 139 | |
140 | 140 | /** |
@@ -147,47 +147,47 @@ discard block |
||
147 | 147 | * @since 1.0 |
148 | 148 | * @return void |
149 | 149 | */ |
150 | -function give_offline_send_donor_instructions( $payment_id = 0 ) { |
|
150 | +function give_offline_send_donor_instructions($payment_id = 0) { |
|
151 | 151 | |
152 | - $payment_data = give_get_payment_meta( $payment_id ); |
|
153 | - $post_offline_customization_option = get_post_meta( $payment_data['form_id'], '_give_customize_offline_donations', true ); |
|
152 | + $payment_data = give_get_payment_meta($payment_id); |
|
153 | + $post_offline_customization_option = get_post_meta($payment_data['form_id'], '_give_customize_offline_donations', true); |
|
154 | 154 | |
155 | 155 | //Customize email content depending on whether the single form has been customized |
156 | - $email_content = give_get_option( 'global_offline_donation_email' ); |
|
156 | + $email_content = give_get_option('global_offline_donation_email'); |
|
157 | 157 | |
158 | - if ( $post_offline_customization_option === 'yes' ) { |
|
159 | - $email_content = get_post_meta( $payment_data['form_id'], '_give_offline_donation_email', true ); |
|
158 | + if ($post_offline_customization_option === 'yes') { |
|
159 | + $email_content = get_post_meta($payment_data['form_id'], '_give_offline_donation_email', true); |
|
160 | 160 | } |
161 | 161 | |
162 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
163 | - $from_name = apply_filters( 'give_purchase_from_name', $from_name, $payment_id, $payment_data ); |
|
162 | + $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
163 | + $from_name = apply_filters('give_purchase_from_name', $from_name, $payment_id, $payment_data); |
|
164 | 164 | |
165 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
|
166 | - $from_email = apply_filters( 'give_purchase_from_address', $from_email, $payment_id, $payment_data ); |
|
165 | + $from_email = give_get_option('from_email', get_bloginfo('admin_email')); |
|
166 | + $from_email = apply_filters('give_purchase_from_address', $from_email, $payment_id, $payment_data); |
|
167 | 167 | |
168 | - $to_email = give_get_payment_user_email( $payment_id ); |
|
168 | + $to_email = give_get_payment_user_email($payment_id); |
|
169 | 169 | |
170 | - $subject = give_get_option( 'offline_donation_subject', esc_html__( 'Offline Donation Instructions', 'give' ) ); |
|
171 | - if ( $post_offline_customization_option === 'yes' ) { |
|
172 | - $subject = get_post_meta( $payment_data['form_id'], '_give_offline_donation_subject', true ); |
|
170 | + $subject = give_get_option('offline_donation_subject', esc_html__('Offline Donation Instructions', 'give')); |
|
171 | + if ($post_offline_customization_option === 'yes') { |
|
172 | + $subject = get_post_meta($payment_data['form_id'], '_give_offline_donation_subject', true); |
|
173 | 173 | } |
174 | 174 | |
175 | - $subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id ); |
|
176 | - $subject = give_do_email_tags( $subject, $payment_id ); |
|
175 | + $subject = apply_filters('give_offline_donation_subject', wp_strip_all_tags($subject), $payment_id); |
|
176 | + $subject = give_do_email_tags($subject, $payment_id); |
|
177 | 177 | |
178 | - $attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data ); |
|
179 | - $message = give_do_email_tags( $email_content, $payment_id ); |
|
178 | + $attachments = apply_filters('give_offline_donation_attachments', array(), $payment_id, $payment_data); |
|
179 | + $message = give_do_email_tags($email_content, $payment_id); |
|
180 | 180 | |
181 | 181 | $emails = Give()->emails; |
182 | 182 | |
183 | - $emails->__set( 'from_name', $from_name ); |
|
184 | - $emails->__set( 'from_email', $from_email ); |
|
185 | - $emails->__set( 'heading', esc_html__( 'Offline Donation Instructions', 'give' ) ); |
|
183 | + $emails->__set('from_name', $from_name); |
|
184 | + $emails->__set('from_email', $from_email); |
|
185 | + $emails->__set('heading', esc_html__('Offline Donation Instructions', 'give')); |
|
186 | 186 | |
187 | - $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data ); |
|
188 | - $emails->__set( 'headers', $headers ); |
|
187 | + $headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); |
|
188 | + $emails->__set('headers', $headers); |
|
189 | 189 | |
190 | - $emails->send( $to_email, $subject, $message, $attachments ); |
|
190 | + $emails->send($to_email, $subject, $message, $attachments); |
|
191 | 191 | |
192 | 192 | } |
193 | 193 | |
@@ -204,52 +204,52 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * |
206 | 206 | */ |
207 | -function give_offline_send_admin_notice( $payment_id = 0 ) { |
|
207 | +function give_offline_send_admin_notice($payment_id = 0) { |
|
208 | 208 | |
209 | 209 | /* Send an email notification to the admin */ |
210 | 210 | $admin_email = give_get_admin_notice_emails(); |
211 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
211 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
212 | 212 | |
213 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { |
|
214 | - $user_data = get_userdata( $user_info['id'] ); |
|
213 | + if (isset($user_info['id']) && $user_info['id'] > 0) { |
|
214 | + $user_data = get_userdata($user_info['id']); |
|
215 | 215 | $name = $user_data->display_name; |
216 | - } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { |
|
217 | - $name = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
216 | + } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { |
|
217 | + $name = $user_info['first_name'].' '.$user_info['last_name']; |
|
218 | 218 | } else { |
219 | 219 | $name = $user_info['email']; |
220 | 220 | } |
221 | 221 | |
222 | - $amount = give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ) ) ); |
|
222 | + $amount = give_currency_filter(give_format_amount(give_get_payment_amount($payment_id))); |
|
223 | 223 | |
224 | - $admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', esc_attr__( 'New Pending Donation', 'give' ), $payment_id ); |
|
224 | + $admin_subject = apply_filters('give_offline_admin_donation_notification_subject', esc_attr__('New Pending Donation', 'give'), $payment_id); |
|
225 | 225 | |
226 | - $admin_message = esc_attr__( 'Dear Admin,', 'give' ) . "\n\n"; |
|
227 | - $admin_message .= esc_attr__( 'An offline donation has been made on your website:', 'give' ) . ' ' . get_bloginfo( 'name' ) . ' '; |
|
228 | - $admin_message .= esc_attr__( 'Hooray! The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n"; |
|
226 | + $admin_message = esc_attr__('Dear Admin,', 'give')."\n\n"; |
|
227 | + $admin_message .= esc_attr__('An offline donation has been made on your website:', 'give').' '.get_bloginfo('name').' '; |
|
228 | + $admin_message .= esc_attr__('Hooray! The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give')."\n\n"; |
|
229 | 229 | |
230 | 230 | |
231 | - $admin_message .= '<strong>' . esc_attr__( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n"; |
|
232 | - $admin_message .= '<strong>' . esc_attr__( 'Amount:', 'give' ) . '</strong> {price}' . "\n\n"; |
|
231 | + $admin_message .= '<strong>'.esc_attr__('Donor:', 'give').'</strong> {fullname}'."\n"; |
|
232 | + $admin_message .= '<strong>'.esc_attr__('Amount:', 'give').'</strong> {price}'."\n\n"; |
|
233 | 233 | |
234 | 234 | $admin_message .= sprintf( |
235 | 235 | '<a href="%1$s">%2$s</a>', |
236 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $payment_id ), |
|
237 | - esc_html__( 'Click Here to View and/or Update Donation Details', 'give' ) |
|
238 | - ) . "\n\n"; |
|
236 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id='.$payment_id), |
|
237 | + esc_html__('Click Here to View and/or Update Donation Details', 'give') |
|
238 | + )."\n\n"; |
|
239 | 239 | |
240 | - $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id ); |
|
241 | - $admin_message = give_do_email_tags( $admin_message, $payment_id ); |
|
240 | + $admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id); |
|
241 | + $admin_message = give_do_email_tags($admin_message, $payment_id); |
|
242 | 242 | |
243 | - $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id ); |
|
244 | - $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id ); |
|
243 | + $attachments = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id); |
|
244 | + $admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id); |
|
245 | 245 | |
246 | 246 | //Send Email |
247 | 247 | $emails = Give()->emails; |
248 | - if ( ! empty( $admin_headers ) ) { |
|
249 | - $emails->__set( 'headers', $admin_headers ); |
|
248 | + if ( ! empty($admin_headers)) { |
|
249 | + $emails->__set('headers', $admin_headers); |
|
250 | 250 | } |
251 | 251 | |
252 | - $emails->send( $admin_email, $admin_subject, $admin_message, $attachments ); |
|
252 | + $emails->send($admin_email, $admin_subject, $admin_message, $attachments); |
|
253 | 253 | |
254 | 254 | } |
255 | 255 | |
@@ -260,15 +260,15 @@ discard block |
||
260 | 260 | * @since 1.0 |
261 | 261 | * @return array |
262 | 262 | */ |
263 | -function give_offline_add_settings( $settings ) { |
|
263 | +function give_offline_add_settings($settings) { |
|
264 | 264 | |
265 | 265 | //Vars |
266 | 266 | $prefix = '_give_'; |
267 | 267 | |
268 | - $is_gateway_active = give_is_gateway_active( 'offline' ); |
|
268 | + $is_gateway_active = give_is_gateway_active('offline'); |
|
269 | 269 | |
270 | 270 | //this gateway isn't active |
271 | - if ( ! $is_gateway_active ) { |
|
271 | + if ( ! $is_gateway_active) { |
|
272 | 272 | //return settings and bounce |
273 | 273 | return $settings; |
274 | 274 | } |
@@ -277,27 +277,27 @@ discard block |
||
277 | 277 | $check_settings = array( |
278 | 278 | |
279 | 279 | array( |
280 | - 'name' => esc_attr__( 'Customize Offline Donations', 'give' ), |
|
281 | - 'desc' => esc_attr__( 'If you would like to customize the donation instructions for this specific forms check this option.', 'give' ), |
|
282 | - 'id' => $prefix . 'customize_offline_donations', |
|
280 | + 'name' => esc_attr__('Customize Offline Donations', 'give'), |
|
281 | + 'desc' => esc_attr__('If you would like to customize the donation instructions for this specific forms check this option.', 'give'), |
|
282 | + 'id' => $prefix.'customize_offline_donations', |
|
283 | 283 | 'type' => 'radio_inline', |
284 | 284 | 'default' => 'no', |
285 | 285 | 'options' => array( |
286 | - 'yes' => esc_attr__( 'Yes', 'give' ), |
|
287 | - 'no' => esc_attr__( 'No', 'give' ), |
|
286 | + 'yes' => esc_attr__('Yes', 'give'), |
|
287 | + 'no' => esc_attr__('No', 'give'), |
|
288 | 288 | ), |
289 | 289 | ), |
290 | 290 | array( |
291 | - 'name' => esc_attr__( 'Request Billing Information', 'give' ), |
|
292 | - 'desc' => esc_attr__( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ), |
|
293 | - 'id' => $prefix . 'offline_donation_enable_billing_fields_single', |
|
291 | + 'name' => esc_attr__('Request Billing Information', 'give'), |
|
292 | + 'desc' => esc_attr__('This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give'), |
|
293 | + 'id' => $prefix.'offline_donation_enable_billing_fields_single', |
|
294 | 294 | 'row_classes' => 'give-subfield', |
295 | 295 | 'type' => 'checkbox' |
296 | 296 | ), |
297 | 297 | array( |
298 | - 'id' => $prefix . 'offline_checkout_notes', |
|
299 | - 'name' => esc_attr__( 'Offline Donation Instructions', 'give' ), |
|
300 | - 'desc' => esc_attr__( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ), |
|
298 | + 'id' => $prefix.'offline_checkout_notes', |
|
299 | + 'name' => esc_attr__('Offline Donation Instructions', 'give'), |
|
300 | + 'desc' => esc_attr__('Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give'), |
|
301 | 301 | 'default' => give_get_default_offline_donation_content(), |
302 | 302 | 'type' => 'wysiwyg', |
303 | 303 | 'row_classes' => 'give-subfield', |
@@ -306,17 +306,17 @@ discard block |
||
306 | 306 | ) |
307 | 307 | ), |
308 | 308 | array( |
309 | - 'id' => $prefix . 'offline_donation_subject', |
|
310 | - 'name' => esc_attr__( 'Offline Donation Email Instructions Subject', 'give' ), |
|
311 | - 'desc' => esc_attr__( 'Enter the subject line for the donation receipt email.', 'give' ), |
|
312 | - 'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), |
|
309 | + 'id' => $prefix.'offline_donation_subject', |
|
310 | + 'name' => esc_attr__('Offline Donation Email Instructions Subject', 'give'), |
|
311 | + 'desc' => esc_attr__('Enter the subject line for the donation receipt email.', 'give'), |
|
312 | + 'default' => esc_attr__('{donation} - Offline Donation Instructions', 'give'), |
|
313 | 313 | 'row_classes' => 'give-subfield', |
314 | 314 | 'type' => 'text' |
315 | 315 | ), |
316 | 316 | array( |
317 | - 'id' => $prefix . 'offline_donation_email', |
|
318 | - 'name' => esc_attr__( 'Offline Donation Email Instructions', 'give' ), |
|
319 | - 'desc' => esc_attr__( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ), |
|
317 | + 'id' => $prefix.'offline_donation_email', |
|
318 | + 'name' => esc_attr__('Offline Donation Email Instructions', 'give'), |
|
319 | + 'desc' => esc_attr__('Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give'), |
|
320 | 320 | 'default' => give_get_default_offline_donation_email_content(), |
321 | 321 | 'type' => 'wysiwyg', |
322 | 322 | 'row_classes' => 'give-subfield', |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | ) |
327 | 327 | ); |
328 | 328 | |
329 | - return array_merge( $settings, $check_settings ); |
|
329 | + return array_merge($settings, $check_settings); |
|
330 | 330 | } |
331 | 331 | |
332 | -add_filter( 'give_forms_display_options_metabox_fields', 'give_offline_add_settings' ); |
|
332 | +add_filter('give_forms_display_options_metabox_fields', 'give_offline_add_settings'); |
|
333 | 333 | |
334 | 334 | |
335 | 335 | /** |
@@ -341,32 +341,32 @@ discard block |
||
341 | 341 | */ |
342 | 342 | function give_get_default_offline_donation_content() { |
343 | 343 | |
344 | - $sitename = get_bloginfo( 'sitename' ); |
|
344 | + $sitename = get_bloginfo('sitename'); |
|
345 | 345 | |
346 | - $default_text = '<p>' . esc_attr__( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>'; |
|
346 | + $default_text = '<p>'.esc_attr__('In order to make an offline donation we ask that you please follow these instructions', 'give').': </p>'; |
|
347 | 347 | $default_text .= '<ol>'; |
348 | 348 | $default_text .= '<li>'; |
349 | 349 | $default_text .= sprintf( |
350 | 350 | /* translators: %s: site name */ |
351 | - esc_html__( 'Make a check payable to "%s"', 'give' ), |
|
351 | + esc_html__('Make a check payable to "%s"', 'give'), |
|
352 | 352 | $sitename |
353 | 353 | ); |
354 | 354 | $default_text .= '</li>'; |
355 | 355 | $default_text .= '<li>'; |
356 | 356 | $default_text .= sprintf( |
357 | 357 | /* translators: %s: site name */ |
358 | - esc_html__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ), |
|
358 | + esc_html__('On the memo line of the check, please indicate that the donation is for "%s"', 'give'), |
|
359 | 359 | $sitename |
360 | 360 | ); |
361 | 361 | $default_text .= '</li>'; |
362 | - $default_text .= '<li>' . esc_html__( 'Please mail your check to:', 'give' ) . '</li>'; |
|
362 | + $default_text .= '<li>'.esc_html__('Please mail your check to:', 'give').'</li>'; |
|
363 | 363 | $default_text .= '</ol>'; |
364 | - $default_text .= ' <em>' . $sitename . '</em><br>'; |
|
364 | + $default_text .= ' <em>'.$sitename.'</em><br>'; |
|
365 | 365 | $default_text .= ' <em>123 G Street </em><br>'; |
366 | 366 | $default_text .= ' <em>San Diego, CA 92101 </em><br>'; |
367 | - $default_text .= '<p>' . esc_attr__( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>'; |
|
367 | + $default_text .= '<p>'.esc_attr__('All contributions will be gratefully acknowledged and are tax deductible.', 'give').'</p>'; |
|
368 | 368 | |
369 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
369 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
370 | 370 | |
371 | 371 | } |
372 | 372 | |
@@ -379,33 +379,33 @@ discard block |
||
379 | 379 | */ |
380 | 380 | function give_get_default_offline_donation_email_content() { |
381 | 381 | |
382 | - $sitename = get_bloginfo( 'sitename' ); |
|
383 | - $default_text = '<p>' . esc_html__( 'Dear {name},', 'give' ) . '</p>'; |
|
384 | - $default_text .= '<p>' . esc_html__( 'Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give' ) . '</p>'; |
|
382 | + $sitename = get_bloginfo('sitename'); |
|
383 | + $default_text = '<p>'.esc_html__('Dear {name},', 'give').'</p>'; |
|
384 | + $default_text .= '<p>'.esc_html__('Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give').'</p>'; |
|
385 | 385 | $default_text .= '<ol>'; |
386 | 386 | $default_text .= '<li>'; |
387 | 387 | $default_text .= sprintf( |
388 | 388 | /* translators: %s: site name */ |
389 | - esc_html__( 'Make a check payable to "%s"', 'give' ), |
|
389 | + esc_html__('Make a check payable to "%s"', 'give'), |
|
390 | 390 | $sitename |
391 | 391 | ); |
392 | 392 | $default_text .= '</li>'; |
393 | 393 | $default_text .= '<li>'; |
394 | 394 | $default_text .= sprintf( |
395 | 395 | /* translators: %s: site name */ |
396 | - esc_html__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ), |
|
396 | + esc_html__('On the memo line of the check, please indicate that the donation is for "%s"', 'give'), |
|
397 | 397 | $sitename |
398 | 398 | ); |
399 | 399 | $default_text .= '</li>'; |
400 | - $default_text .= '<li>' . esc_html__( 'Please mail your check to:', 'give' ) . '</li>'; |
|
400 | + $default_text .= '<li>'.esc_html__('Please mail your check to:', 'give').'</li>'; |
|
401 | 401 | $default_text .= '</ol>'; |
402 | - $default_text .= ' <em>' . $sitename . '</em><br>'; |
|
402 | + $default_text .= ' <em>'.$sitename.'</em><br>'; |
|
403 | 403 | $default_text .= ' <em>123 G Street </em><br>'; |
404 | 404 | $default_text .= ' <em>San Diego, CA 92101 </em><br>'; |
405 | - $default_text .= '<p>' . esc_html__( 'Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>'; |
|
406 | - $default_text .= '<p>' . esc_html__( 'Sincerely,', 'give' ) . '</p>'; |
|
407 | - $default_text .= '<p>' . $sitename . '</p>'; |
|
405 | + $default_text .= '<p>'.esc_html__('Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give').'</p>'; |
|
406 | + $default_text .= '<p>'.esc_html__('Sincerely,', 'give').'</p>'; |
|
407 | + $default_text .= '<p>'.$sitename.'</p>'; |
|
408 | 408 | |
409 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
409 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
410 | 410 | |
411 | 411 | } |
@@ -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,94 +26,94 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function give_load_scripts() { |
28 | 28 | |
29 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/frontend/'; |
|
30 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
31 | - $scripts_footer = ( give_get_option( 'scripts_footer' ) == 'on' ) ? true : false; |
|
29 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/frontend/'; |
|
30 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
31 | + $scripts_footer = (give_get_option('scripts_footer') == 'on') ? true : false; |
|
32 | 32 | |
33 | 33 | // Use minified libraries if SCRIPT_DEBUG is turned off |
34 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
34 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
35 | 35 | |
36 | 36 | //Localize / PHP to AJAX vars |
37 | - $localize_give_checkout = apply_filters( 'give_global_script_vars', array( |
|
37 | + $localize_give_checkout = apply_filters('give_global_script_vars', array( |
|
38 | 38 | 'ajaxurl' => give_get_ajax_url(), |
39 | - 'checkout_nonce' => wp_create_nonce( 'give_checkout_nonce' ), |
|
40 | - 'currency_sign' => give_currency_filter( '' ), |
|
39 | + 'checkout_nonce' => wp_create_nonce('give_checkout_nonce'), |
|
40 | + 'currency_sign' => give_currency_filter(''), |
|
41 | 41 | 'currency_pos' => give_get_currency_position(), |
42 | 42 | 'thousands_separator' => give_get_price_thousand_separator(), |
43 | 43 | 'decimal_separator' => give_get_price_decimal_separator(), |
44 | - 'no_gateway' => esc_html__( 'Please select a payment method.', 'give' ), |
|
45 | - 'bad_minimum' => esc_html__( 'The minimum donation amount for this form is', 'give' ), |
|
46 | - 'general_loading' => esc_html__( 'Loading...', 'give' ), |
|
47 | - 'purchase_loading' => esc_html__( 'Please Wait...', 'give' ), |
|
44 | + 'no_gateway' => esc_html__('Please select a payment method.', 'give'), |
|
45 | + 'bad_minimum' => esc_html__('The minimum donation amount for this form is', 'give'), |
|
46 | + 'general_loading' => esc_html__('Loading...', 'give'), |
|
47 | + 'purchase_loading' => esc_html__('Please Wait...', 'give'), |
|
48 | 48 | 'number_decimals' => give_get_price_decimals(), |
49 | 49 | 'give_version' => GIVE_VERSION |
50 | - ) ); |
|
51 | - $localize_give_ajax = apply_filters( 'give_global_ajax_vars', array( |
|
50 | + )); |
|
51 | + $localize_give_ajax = apply_filters('give_global_ajax_vars', array( |
|
52 | 52 | 'ajaxurl' => give_get_ajax_url(), |
53 | - 'loading' => esc_html__( 'Loading', 'give' ), |
|
53 | + 'loading' => esc_html__('Loading', 'give'), |
|
54 | 54 | // General loading message |
55 | - 'select_option' => esc_html__( 'Please select an option', 'give' ), |
|
55 | + 'select_option' => esc_html__('Please select an option', 'give'), |
|
56 | 56 | // Variable pricing error with multi-purchase option enabled |
57 | - 'default_gateway' => give_get_default_gateway( null ), |
|
58 | - 'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0', |
|
57 | + 'default_gateway' => give_get_default_gateway(null), |
|
58 | + 'permalinks' => get_option('permalink_structure') ? '1' : '0', |
|
59 | 59 | 'number_decimals' => give_get_price_decimals() |
60 | - ) ); |
|
60 | + )); |
|
61 | 61 | |
62 | 62 | //DEBUG is On |
63 | - if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
|
63 | + if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { |
|
64 | 64 | |
65 | - if ( give_is_cc_verify_enabled() ) { |
|
66 | - wp_register_script( 'give-cc-validator', $js_plugins . 'jquery.payment' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
67 | - wp_enqueue_script( 'give-cc-validator' ); |
|
65 | + if (give_is_cc_verify_enabled()) { |
|
66 | + wp_register_script('give-cc-validator', $js_plugins.'jquery.payment'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
67 | + wp_enqueue_script('give-cc-validator'); |
|
68 | 68 | } |
69 | 69 | |
70 | - wp_register_script( 'give-float-labels', $js_plugins . 'float-labels' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
71 | - wp_enqueue_script( 'give-float-labels' ); |
|
70 | + wp_register_script('give-float-labels', $js_plugins.'float-labels'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
71 | + wp_enqueue_script('give-float-labels'); |
|
72 | 72 | |
73 | - wp_register_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
74 | - wp_enqueue_script( 'give-blockui' ); |
|
73 | + wp_register_script('give-blockui', $js_plugins.'jquery.blockUI'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
74 | + wp_enqueue_script('give-blockui'); |
|
75 | 75 | |
76 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
77 | - wp_enqueue_script( 'give-qtip' ); |
|
76 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
77 | + wp_enqueue_script('give-qtip'); |
|
78 | 78 | |
79 | - wp_register_script( 'give-accounting', $js_plugins . 'accounting' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
80 | - wp_enqueue_script( 'give-accounting' ); |
|
79 | + wp_register_script('give-accounting', $js_plugins.'accounting'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
80 | + wp_enqueue_script('give-accounting'); |
|
81 | 81 | |
82 | - wp_register_script( 'give-magnific', $js_plugins . 'jquery.magnific-popup' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
83 | - wp_enqueue_script( 'give-magnific' ); |
|
82 | + wp_register_script('give-magnific', $js_plugins.'jquery.magnific-popup'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
83 | + wp_enqueue_script('give-magnific'); |
|
84 | 84 | |
85 | - wp_register_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
86 | - wp_enqueue_script( 'give-checkout-global' ); |
|
85 | + wp_register_script('give-checkout-global', $js_dir.'give-checkout-global'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
86 | + wp_enqueue_script('give-checkout-global'); |
|
87 | 87 | |
88 | 88 | //General scripts |
89 | - wp_register_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
90 | - wp_enqueue_script( 'give-scripts' ); |
|
89 | + wp_register_script('give-scripts', $js_dir.'give'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
90 | + wp_enqueue_script('give-scripts'); |
|
91 | 91 | |
92 | 92 | // Load AJAX scripts, if enabled |
93 | - wp_register_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
94 | - wp_enqueue_script( 'give-ajax' ); |
|
93 | + wp_register_script('give-ajax', $js_dir.'give-ajax'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
94 | + wp_enqueue_script('give-ajax'); |
|
95 | 95 | |
96 | 96 | //Localize / Pass AJAX vars from PHP |
97 | - wp_localize_script( 'give-checkout-global', 'give_global_vars', $localize_give_checkout ); |
|
98 | - wp_localize_script( 'give-ajax', 'give_scripts', $localize_give_ajax ); |
|
97 | + wp_localize_script('give-checkout-global', 'give_global_vars', $localize_give_checkout); |
|
98 | + wp_localize_script('give-ajax', 'give_scripts', $localize_give_ajax); |
|
99 | 99 | |
100 | 100 | |
101 | 101 | } else { |
102 | 102 | |
103 | 103 | //DEBUG is OFF (one JS file to rule them all!) |
104 | - wp_register_script( 'give', $js_dir . 'give.all.min.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
105 | - wp_enqueue_script( 'give' ); |
|
104 | + wp_register_script('give', $js_dir.'give.all.min.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
105 | + wp_enqueue_script('give'); |
|
106 | 106 | |
107 | 107 | //Localize / Pass AJAX vars from PHP |
108 | - wp_localize_script( 'give', 'give_global_vars', $localize_give_checkout ); |
|
109 | - wp_localize_script( 'give', 'give_scripts', $localize_give_ajax ); |
|
108 | + wp_localize_script('give', 'give_global_vars', $localize_give_checkout); |
|
109 | + wp_localize_script('give', 'give_scripts', $localize_give_ajax); |
|
110 | 110 | |
111 | 111 | } |
112 | 112 | |
113 | 113 | |
114 | 114 | } |
115 | 115 | |
116 | -add_action( 'wp_enqueue_scripts', 'give_load_scripts' ); |
|
116 | +add_action('wp_enqueue_scripts', 'give_load_scripts'); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Register styles. |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | */ |
126 | 126 | function give_register_styles() { |
127 | 127 | |
128 | - if ( give_get_option( 'disable_css', false ) ) { |
|
128 | + if (give_get_option('disable_css', false)) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - wp_register_style( 'give-styles', give_get_stylesheet_uri(), array(), GIVE_VERSION, 'all' ); |
|
133 | - wp_enqueue_style( 'give-styles' ); |
|
132 | + wp_register_style('give-styles', give_get_stylesheet_uri(), array(), GIVE_VERSION, 'all'); |
|
133 | + wp_enqueue_style('give-styles'); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
137 | -add_action( 'wp_enqueue_scripts', 'give_register_styles' ); |
|
137 | +add_action('wp_enqueue_scripts', 'give_register_styles'); |
|
138 | 138 | |
139 | 139 | |
140 | 140 | /** |
@@ -146,39 +146,39 @@ discard block |
||
146 | 146 | function give_get_stylesheet_uri() { |
147 | 147 | |
148 | 148 | // Use minified libraries if SCRIPT_DEBUG is turned off |
149 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
149 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
150 | 150 | |
151 | - $file = 'give' . $suffix . '.css'; |
|
151 | + $file = 'give'.$suffix.'.css'; |
|
152 | 152 | $templates_dir = give_get_theme_template_dir_name(); |
153 | 153 | |
154 | - $child_theme_style_sheet = trailingslashit( get_stylesheet_directory() ) . $templates_dir . $file; |
|
155 | - $child_theme_style_sheet_2 = trailingslashit( get_stylesheet_directory() ) . $templates_dir . 'give.css'; |
|
156 | - $parent_theme_style_sheet = trailingslashit( get_template_directory() ) . $templates_dir . $file; |
|
157 | - $parent_theme_style_sheet_2 = trailingslashit( get_template_directory() ) . $templates_dir . 'give.css'; |
|
158 | - $give_plugin_style_sheet = trailingslashit( give_get_templates_dir() ) . $file; |
|
154 | + $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()).$templates_dir.$file; |
|
155 | + $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()).$templates_dir.'give.css'; |
|
156 | + $parent_theme_style_sheet = trailingslashit(get_template_directory()).$templates_dir.$file; |
|
157 | + $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()).$templates_dir.'give.css'; |
|
158 | + $give_plugin_style_sheet = trailingslashit(give_get_templates_dir()).$file; |
|
159 | 159 | |
160 | 160 | $uri = false; |
161 | 161 | |
162 | 162 | // Look in the child theme directory first, followed by the parent theme, followed by the Give core templates directory |
163 | 163 | // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. |
164 | 164 | // This allows users to copy just give.css to their theme |
165 | - if ( file_exists( $child_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $child_theme_style_sheet_2 ) ) ) ) { |
|
166 | - if ( ! empty( $nonmin ) ) { |
|
167 | - $uri = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . 'give.css'; |
|
165 | + if (file_exists($child_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2)))) { |
|
166 | + if ( ! empty($nonmin)) { |
|
167 | + $uri = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.'give.css'; |
|
168 | 168 | } else { |
169 | - $uri = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . $file; |
|
169 | + $uri = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.$file; |
|
170 | 170 | } |
171 | - } elseif ( file_exists( $parent_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $parent_theme_style_sheet_2 ) ) ) ) { |
|
172 | - if ( ! empty( $nonmin ) ) { |
|
173 | - $uri = trailingslashit( get_template_directory_uri() ) . $templates_dir . 'give.css'; |
|
171 | + } elseif (file_exists($parent_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2)))) { |
|
172 | + if ( ! empty($nonmin)) { |
|
173 | + $uri = trailingslashit(get_template_directory_uri()).$templates_dir.'give.css'; |
|
174 | 174 | } else { |
175 | - $uri = trailingslashit( get_template_directory_uri() ) . $templates_dir . $file; |
|
175 | + $uri = trailingslashit(get_template_directory_uri()).$templates_dir.$file; |
|
176 | 176 | } |
177 | - } elseif ( file_exists( $give_plugin_style_sheet ) || file_exists( $give_plugin_style_sheet ) ) { |
|
178 | - $uri = trailingslashit( give_get_templates_url() ) . $file; |
|
177 | + } elseif (file_exists($give_plugin_style_sheet) || file_exists($give_plugin_style_sheet)) { |
|
178 | + $uri = trailingslashit(give_get_templates_url()).$file; |
|
179 | 179 | } |
180 | 180 | |
181 | - return apply_filters( 'give_get_stylesheet_uri', $uri ); |
|
181 | + return apply_filters('give_get_stylesheet_uri', $uri); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
@@ -196,65 +196,65 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return void |
198 | 198 | */ |
199 | -function give_load_admin_scripts( $hook ) { |
|
199 | +function give_load_admin_scripts($hook) { |
|
200 | 200 | |
201 | 201 | global $wp_version, $post, $post_type, $give_options; |
202 | 202 | |
203 | 203 | //Directories of assets |
204 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
205 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
206 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
204 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
205 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
206 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
207 | 207 | |
208 | 208 | // Use minified libraries if SCRIPT_DEBUG is turned off |
209 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
209 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
210 | 210 | |
211 | 211 | //Global Admin: |
212 | - wp_register_style( 'give-admin-bar-notification', $css_dir . 'adminbar-style.css' ); |
|
213 | - wp_enqueue_style( 'give-admin-bar-notification' ); |
|
212 | + wp_register_style('give-admin-bar-notification', $css_dir.'adminbar-style.css'); |
|
213 | + wp_enqueue_style('give-admin-bar-notification'); |
|
214 | 214 | |
215 | 215 | //Give Admin Only: |
216 | - if ( ! apply_filters( 'give_load_admin_scripts', give_is_admin_page(), $hook ) ) { |
|
216 | + if ( ! apply_filters('give_load_admin_scripts', give_is_admin_page(), $hook)) { |
|
217 | 217 | return; |
218 | 218 | } |
219 | 219 | |
220 | 220 | //CSS |
221 | - wp_register_style( 'jquery-ui-css', $css_dir . 'jquery-ui-fresh' . $suffix . '.css' ); |
|
222 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
223 | - wp_register_style( 'give-admin', $css_dir . 'give-admin' . $suffix . '.css', GIVE_VERSION ); |
|
224 | - wp_enqueue_style( 'give-admin' ); |
|
225 | - wp_register_style( 'jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), GIVE_VERSION ); |
|
226 | - wp_enqueue_style( 'jquery-chosen' ); |
|
227 | - wp_enqueue_style( 'thickbox' ); |
|
221 | + wp_register_style('jquery-ui-css', $css_dir.'jquery-ui-fresh'.$suffix.'.css'); |
|
222 | + wp_enqueue_style('jquery-ui-css'); |
|
223 | + wp_register_style('give-admin', $css_dir.'give-admin'.$suffix.'.css', GIVE_VERSION); |
|
224 | + wp_enqueue_style('give-admin'); |
|
225 | + wp_register_style('jquery-chosen', $css_dir.'chosen'.$suffix.'.css', array(), GIVE_VERSION); |
|
226 | + wp_enqueue_style('jquery-chosen'); |
|
227 | + wp_enqueue_style('thickbox'); |
|
228 | 228 | |
229 | 229 | //JS |
230 | - wp_register_script( 'jquery-chosen', $js_plugins . 'chosen.jquery' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
231 | - wp_enqueue_script( 'jquery-chosen' ); |
|
230 | + wp_register_script('jquery-chosen', $js_plugins.'chosen.jquery'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
231 | + wp_enqueue_script('jquery-chosen'); |
|
232 | 232 | |
233 | - wp_register_script( 'give-accounting', $js_plugins . 'accounting' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
234 | - wp_enqueue_script( 'give-accounting' ); |
|
233 | + wp_register_script('give-accounting', $js_plugins.'accounting'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
234 | + wp_enqueue_script('give-accounting'); |
|
235 | 235 | |
236 | - wp_register_script( 'give-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
237 | - wp_enqueue_script( 'give-admin-scripts' ); |
|
236 | + wp_register_script('give-admin-scripts', $js_dir.'admin-scripts'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
237 | + wp_enqueue_script('give-admin-scripts'); |
|
238 | 238 | |
239 | - wp_register_script( 'jquery-flot', $js_plugins . 'jquery.flot' . $suffix . '.js' ); |
|
240 | - wp_enqueue_script( 'jquery-flot' ); |
|
239 | + wp_register_script('jquery-flot', $js_plugins.'jquery.flot'.$suffix.'.js'); |
|
240 | + wp_enqueue_script('jquery-flot'); |
|
241 | 241 | |
242 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
243 | - wp_enqueue_script( 'give-qtip' ); |
|
242 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
243 | + wp_enqueue_script('give-qtip'); |
|
244 | 244 | |
245 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
246 | - wp_enqueue_script( 'thickbox' ); |
|
245 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
246 | + wp_enqueue_script('thickbox'); |
|
247 | 247 | |
248 | 248 | // Forms CPT Script. |
249 | - if ( $post_type === 'give_forms' ) { |
|
250 | - wp_register_script( 'give-admin-forms-scripts', $js_dir . 'admin-forms' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
251 | - wp_enqueue_script( 'give-admin-forms-scripts' ); |
|
249 | + if ($post_type === 'give_forms') { |
|
250 | + wp_register_script('give-admin-forms-scripts', $js_dir.'admin-forms'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
251 | + wp_enqueue_script('give-admin-forms-scripts'); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | //Settings Scripts |
255 | - if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-settings' ) { |
|
256 | - wp_register_script( 'give-admin-settings-scripts', $js_dir . 'admin-settings' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
257 | - wp_enqueue_script( 'give-admin-settings-scripts' ); |
|
255 | + if (isset($_GET['page']) && $_GET['page'] == 'give-settings') { |
|
256 | + wp_register_script('give-admin-settings-scripts', $js_dir.'admin-settings'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
257 | + wp_enqueue_script('give-admin-settings-scripts'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | // Price Separators. |
@@ -262,50 +262,50 @@ discard block |
||
262 | 262 | $decimal_separator = give_get_price_decimal_separator(); |
263 | 263 | |
264 | 264 | //Localize strings & variables for JS |
265 | - wp_localize_script( 'give-admin-scripts', 'give_vars', array( |
|
266 | - 'post_id' => isset( $post->ID ) ? $post->ID : null, |
|
265 | + wp_localize_script('give-admin-scripts', 'give_vars', array( |
|
266 | + 'post_id' => isset($post->ID) ? $post->ID : null, |
|
267 | 267 | 'give_version' => GIVE_VERSION, |
268 | 268 | 'thousands_separator' => $thousand_separator, |
269 | 269 | 'decimal_separator' => $decimal_separator, |
270 | - 'quick_edit_warning' => esc_html__( 'Not available for variable priced forms.', 'give' ), |
|
271 | - 'delete_payment' => esc_html__( 'Are you sure you wish to delete this payment?', 'give' ), |
|
272 | - 'delete_payment_note' => esc_html__( 'Are you sure you wish to delete this note?', 'give' ), |
|
273 | - 'revoke_api_key' => esc_html__( 'Are you sure you wish to revoke this API key?', 'give' ), |
|
274 | - 'regenerate_api_key' => esc_html__( 'Are you sure you wish to regenerate this API key?', 'give' ), |
|
275 | - 'resend_receipt' => esc_html__( 'Are you sure you wish to resend the donation receipt?', 'give' ), |
|
276 | - 'copy_download_link_text' => esc_html__( 'Copy these links to your clipboard and give them to your donor.', 'give' ), |
|
270 | + 'quick_edit_warning' => esc_html__('Not available for variable priced forms.', 'give'), |
|
271 | + 'delete_payment' => esc_html__('Are you sure you wish to delete this payment?', 'give'), |
|
272 | + 'delete_payment_note' => esc_html__('Are you sure you wish to delete this note?', 'give'), |
|
273 | + 'revoke_api_key' => esc_html__('Are you sure you wish to revoke this API key?', 'give'), |
|
274 | + 'regenerate_api_key' => esc_html__('Are you sure you wish to regenerate this API key?', 'give'), |
|
275 | + 'resend_receipt' => esc_html__('Are you sure you wish to resend the donation receipt?', 'give'), |
|
276 | + 'copy_download_link_text' => esc_html__('Copy these links to your clipboard and give them to your donor.', 'give'), |
|
277 | 277 | /* translators: %s: form singular label */ |
278 | - 'delete_payment_download' => sprintf( esc_html__( 'Are you sure you wish to delete this %s?', 'give' ), give_get_forms_label_singular() ), |
|
279 | - 'one_price_min' => esc_html__( 'You must have at least one price.', 'give' ), |
|
280 | - 'one_file_min' => esc_html__( 'You must have at least one file.', 'give' ), |
|
281 | - 'one_field_min' => esc_html__( 'You must have at least one field.', 'give' ), |
|
278 | + 'delete_payment_download' => sprintf(esc_html__('Are you sure you wish to delete this %s?', 'give'), give_get_forms_label_singular()), |
|
279 | + 'one_price_min' => esc_html__('You must have at least one price.', 'give'), |
|
280 | + 'one_file_min' => esc_html__('You must have at least one file.', 'give'), |
|
281 | + 'one_field_min' => esc_html__('You must have at least one field.', 'give'), |
|
282 | 282 | /* translators: %s: form singular label */ |
283 | - 'one_option' => sprintf( esc_html__( 'Choose a %s', 'give' ), give_get_forms_label_singular() ), |
|
283 | + 'one_option' => sprintf(esc_html__('Choose a %s', 'give'), give_get_forms_label_singular()), |
|
284 | 284 | /* translators: %s: form plural label */ |
285 | - 'one_or_more_option' => sprintf( esc_html__( 'Choose one or more %s', 'give' ), give_get_forms_label_plural() ), |
|
286 | - 'numeric_item_price' => esc_html__( 'Item price must be numeric.', 'give' ), |
|
287 | - 'numeric_quantity' => esc_html__( 'Quantity must be numeric.', 'give' ), |
|
288 | - 'currency_sign' => give_currency_filter( '' ), |
|
289 | - 'currency_pos' => isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before', |
|
290 | - 'currency_decimals' => give_currency_decimal_filter( give_get_price_decimals() ), |
|
291 | - 'new_media_ui' => apply_filters( 'give_use_35_media_ui', 1 ), |
|
292 | - 'remove_text' => esc_html__( 'Remove', 'give' ), |
|
285 | + 'one_or_more_option' => sprintf(esc_html__('Choose one or more %s', 'give'), give_get_forms_label_plural()), |
|
286 | + 'numeric_item_price' => esc_html__('Item price must be numeric.', 'give'), |
|
287 | + 'numeric_quantity' => esc_html__('Quantity must be numeric.', 'give'), |
|
288 | + 'currency_sign' => give_currency_filter(''), |
|
289 | + 'currency_pos' => isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before', |
|
290 | + 'currency_decimals' => give_currency_decimal_filter(give_get_price_decimals()), |
|
291 | + 'new_media_ui' => apply_filters('give_use_35_media_ui', 1), |
|
292 | + 'remove_text' => esc_html__('Remove', 'give'), |
|
293 | 293 | /* translators: %s: form plural label */ |
294 | - 'type_to_search' => sprintf( esc_html__( 'Type to search %s', 'give' ), give_get_forms_label_plural() ), |
|
295 | - 'batch_export_no_class' => esc_html__( 'You must choose a method.', 'give' ), |
|
296 | - 'batch_export_no_reqs' => esc_html__( 'Required fields not completed.', 'give' ), |
|
297 | - 'reset_stats_warn' => __( 'Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give' ), |
|
298 | - 'price_format_guide' => sprintf( esc_html__( 'Please enter amount in monetary decimal ( %1$s ) format without thousand separator ( %2$s ) .', 'give' ), $decimal_separator, $thousand_separator ) |
|
299 | - ) ); |
|
300 | - |
|
301 | - if ( function_exists( 'wp_enqueue_media' ) && version_compare( $wp_version, '3.5', '>=' ) ) { |
|
294 | + 'type_to_search' => sprintf(esc_html__('Type to search %s', 'give'), give_get_forms_label_plural()), |
|
295 | + 'batch_export_no_class' => esc_html__('You must choose a method.', 'give'), |
|
296 | + 'batch_export_no_reqs' => esc_html__('Required fields not completed.', 'give'), |
|
297 | + 'reset_stats_warn' => __('Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give'), |
|
298 | + 'price_format_guide' => sprintf(esc_html__('Please enter amount in monetary decimal ( %1$s ) format without thousand separator ( %2$s ) .', 'give'), $decimal_separator, $thousand_separator) |
|
299 | + )); |
|
300 | + |
|
301 | + if (function_exists('wp_enqueue_media') && version_compare($wp_version, '3.5', '>=')) { |
|
302 | 302 | //call for new media manager |
303 | 303 | wp_enqueue_media(); |
304 | 304 | } |
305 | 305 | |
306 | 306 | } |
307 | 307 | |
308 | -add_action( 'admin_enqueue_scripts', 'give_load_admin_scripts', 100 ); |
|
308 | +add_action('admin_enqueue_scripts', 'give_load_admin_scripts', 100); |
|
309 | 309 | |
310 | 310 | /** |
311 | 311 | * Admin Give Icon |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | ?> |
323 | 323 | <style type="text/css" media="screen"> |
324 | 324 | |
325 | - <?php if( version_compare( $wp_version, '3.8-RC', '>=' ) || version_compare( $wp_version, '3.8', '>=' ) ) { ?> |
|
325 | + <?php if (version_compare($wp_version, '3.8-RC', '>=') || version_compare($wp_version, '3.8', '>=')) { ?> |
|
326 | 326 | @font-face { |
327 | 327 | font-family: 'give-icomoon'; |
328 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
329 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
330 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
331 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
332 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
328 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
329 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
330 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
331 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
332 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
333 | 333 | font-weight: normal; |
334 | 334 | font-style: normal; |
335 | 335 | } |
@@ -348,4 +348,4 @@ discard block |
||
348 | 348 | <?php |
349 | 349 | } |
350 | 350 | |
351 | -add_action( 'admin_head', 'give_admin_icon' ); |
|
351 | +add_action('admin_head', 'give_admin_icon'); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | 'v1' => 'GIVE_API_V1', |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $this->get_versions() as $version => $class ) { |
|
144 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
143 | + foreach ($this->get_versions() as $version => $class) { |
|
144 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
145 | 145 | } |
146 | 146 | |
147 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
148 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
149 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
150 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
154 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
147 | + add_action('init', array($this, 'add_endpoint')); |
|
148 | + add_action('wp', array($this, 'process_query'), - 1); |
|
149 | + add_filter('query_vars', array($this, 'query_vars')); |
|
150 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('personal_options_update', array($this, 'update_key')); |
|
153 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
154 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
155 | 155 | |
156 | 156 | // Setup a backwards compatibility check for user API Keys |
157 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
157 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
158 | 158 | |
159 | 159 | // Determine if JSON_PRETTY_PRINT is available |
160 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
160 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
161 | 161 | |
162 | 162 | // Allow API request logging to be turned off |
163 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
163 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
164 | 164 | |
165 | 165 | // Setup Give_Payment_Stats instance |
166 | 166 | $this->stats = new Give_Payment_Stats; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @since 1.1 |
178 | 178 | */ |
179 | - public function add_endpoint( $rewrite_rules ) { |
|
180 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
179 | + public function add_endpoint($rewrite_rules) { |
|
180 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] $vars New query vars |
192 | 192 | */ |
193 | - public function query_vars( $vars ) { |
|
193 | + public function query_vars($vars) { |
|
194 | 194 | |
195 | 195 | $vars[] = 'token'; |
196 | 196 | $vars[] = 'key'; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function get_default_version() { |
243 | 243 | |
244 | - $version = get_option( 'give_default_api_version' ); |
|
244 | + $version = get_option('give_default_api_version'); |
|
245 | 245 | |
246 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
246 | + if (defined('GIVE_API_VERSION')) { |
|
247 | 247 | $version = GIVE_API_VERSION; |
248 | - } elseif ( ! $version ) { |
|
248 | + } elseif ( ! $version) { |
|
249 | 249 | $version = 'v1'; |
250 | 250 | } |
251 | 251 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | $version = $wp_query->query_vars['give-api']; |
268 | 268 | |
269 | - if ( strpos( $version, '/' ) ) { |
|
269 | + if (strpos($version, '/')) { |
|
270 | 270 | |
271 | - $version = explode( '/', $version ); |
|
272 | - $version = strtolower( $version[0] ); |
|
271 | + $version = explode('/', $version); |
|
272 | + $version = strtolower($version[0]); |
|
273 | 273 | |
274 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
274 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
275 | 275 | |
276 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
276 | + if (array_key_exists($version, $this->versions)) { |
|
277 | 277 | |
278 | 278 | $this->queried_version = $version; |
279 | 279 | |
@@ -310,32 +310,32 @@ discard block |
||
310 | 310 | $this->override = false; |
311 | 311 | |
312 | 312 | // Make sure we have both user and api key |
313 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
313 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
314 | 314 | |
315 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
315 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
316 | 316 | $this->missing_auth(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Retrieve the user by public API key and ensure they exist |
320 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
320 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
321 | 321 | |
322 | 322 | $this->invalid_key(); |
323 | 323 | |
324 | 324 | } else { |
325 | 325 | |
326 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
327 | - $secret = $this->get_user_secret_key( $user ); |
|
328 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
326 | + $token = urldecode($wp_query->query_vars['token']); |
|
327 | + $secret = $this->get_user_secret_key($user); |
|
328 | + $public = urldecode($wp_query->query_vars['key']); |
|
329 | 329 | |
330 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
330 | + if (hash_equals(md5($secret.$public), $token)) { |
|
331 | 331 | $this->is_valid_request = true; |
332 | 332 | } else { |
333 | 333 | $this->invalid_auth(); |
334 | 334 | } |
335 | 335 | } |
336 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
336 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
337 | 337 | $this->is_valid_request = true; |
338 | - $wp_query->set( 'key', 'public' ); |
|
338 | + $wp_query->set('key', 'public'); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
@@ -351,25 +351,25 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return bool if user ID is found, false otherwise |
353 | 353 | */ |
354 | - public function get_user( $key = '' ) { |
|
354 | + public function get_user($key = '') { |
|
355 | 355 | global $wpdb, $wp_query; |
356 | 356 | |
357 | - if ( empty( $key ) ) { |
|
358 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
357 | + if (empty($key)) { |
|
358 | + $key = urldecode($wp_query->query_vars['key']); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( empty( $key ) ) { |
|
361 | + if (empty($key)) { |
|
362 | 362 | return false; |
363 | 363 | } |
364 | 364 | |
365 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
365 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
366 | 366 | |
367 | - if ( false === $user ) { |
|
368 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
369 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
367 | + if (false === $user) { |
|
368 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
369 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
370 | 370 | } |
371 | 371 | |
372 | - if ( $user != null ) { |
|
372 | + if ($user != null) { |
|
373 | 373 | $this->user_id = $user; |
374 | 374 | |
375 | 375 | return $user; |
@@ -378,37 +378,37 @@ discard block |
||
378 | 378 | return false; |
379 | 379 | } |
380 | 380 | |
381 | - public function get_user_public_key( $user_id = 0 ) { |
|
381 | + public function get_user_public_key($user_id = 0) { |
|
382 | 382 | global $wpdb; |
383 | 383 | |
384 | - if ( empty( $user_id ) ) { |
|
384 | + if (empty($user_id)) { |
|
385 | 385 | return ''; |
386 | 386 | } |
387 | 387 | |
388 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
389 | - $user_public_key = get_transient( $cache_key ); |
|
388 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
389 | + $user_public_key = get_transient($cache_key); |
|
390 | 390 | |
391 | - if ( empty( $user_public_key ) ) { |
|
392 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
393 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
391 | + if (empty($user_public_key)) { |
|
392 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
393 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $user_public_key; |
397 | 397 | } |
398 | 398 | |
399 | - public function get_user_secret_key( $user_id = 0 ) { |
|
399 | + public function get_user_secret_key($user_id = 0) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - if ( empty( $user_id ) ) { |
|
402 | + if (empty($user_id)) { |
|
403 | 403 | return ''; |
404 | 404 | } |
405 | 405 | |
406 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
407 | - $user_secret_key = get_transient( $cache_key ); |
|
406 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
407 | + $user_secret_key = get_transient($cache_key); |
|
408 | 408 | |
409 | - if ( empty( $user_secret_key ) ) { |
|
410 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
411 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
409 | + if (empty($user_secret_key)) { |
|
410 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
411 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return $user_secret_key; |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | */ |
425 | 425 | private function missing_auth() { |
426 | 426 | $error = array(); |
427 | - $error['error'] = esc_html__( 'You must specify both a token and API key.', 'give' ); |
|
427 | + $error['error'] = esc_html__('You must specify both a token and API key.', 'give'); |
|
428 | 428 | |
429 | 429 | $this->data = $error; |
430 | - $this->output( 401 ); |
|
430 | + $this->output(401); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -441,10 +441,10 @@ discard block |
||
441 | 441 | */ |
442 | 442 | private function invalid_auth() { |
443 | 443 | $error = array(); |
444 | - $error['error'] = esc_html__( 'Your request could not be authenticated.', 'give' ); |
|
444 | + $error['error'] = esc_html__('Your request could not be authenticated.', 'give'); |
|
445 | 445 | |
446 | 446 | $this->data = $error; |
447 | - $this->output( 403 ); |
|
447 | + $this->output(403); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | */ |
459 | 459 | private function invalid_key() { |
460 | 460 | $error = array(); |
461 | - $error['error'] = esc_html__( 'Invalid API key.', 'give' ); |
|
461 | + $error['error'] = esc_html__('Invalid API key.', 'give'); |
|
462 | 462 | |
463 | 463 | $this->data = $error; |
464 | - $this->output( 403 ); |
|
464 | + $this->output(403); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -474,10 +474,10 @@ discard block |
||
474 | 474 | */ |
475 | 475 | private function invalid_version() { |
476 | 476 | $error = array(); |
477 | - $error['error'] = esc_html__( 'Invalid API version.', 'give' ); |
|
477 | + $error['error'] = esc_html__('Invalid API version.', 'give'); |
|
478 | 478 | |
479 | 479 | $this->data = $error; |
480 | - $this->output( 404 ); |
|
480 | + $this->output(404); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -493,10 +493,10 @@ discard block |
||
493 | 493 | global $wp_query; |
494 | 494 | |
495 | 495 | // Start logging how long the request takes for logging |
496 | - $before = microtime( true ); |
|
496 | + $before = microtime(true); |
|
497 | 497 | |
498 | 498 | // Check for give-api var. Get out if not present |
499 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
499 | + if (empty($wp_query->query_vars['give-api'])) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
@@ -510,45 +510,45 @@ discard block |
||
510 | 510 | $this->validate_request(); |
511 | 511 | |
512 | 512 | // Only proceed if no errors have been noted |
513 | - if ( ! $this->is_valid_request ) { |
|
513 | + if ( ! $this->is_valid_request) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
518 | - define( 'GIVE_DOING_API', true ); |
|
517 | + if ( ! defined('GIVE_DOING_API')) { |
|
518 | + define('GIVE_DOING_API', true); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | $data = array(); |
522 | 522 | $this->routes = new $this->versions[$this->get_queried_version()]; |
523 | 523 | $this->routes->validate_request(); |
524 | 524 | |
525 | - switch ( $this->endpoint ) : |
|
525 | + switch ($this->endpoint) : |
|
526 | 526 | |
527 | 527 | case 'stats' : |
528 | 528 | |
529 | - $data = $this->routes->get_stats( array( |
|
530 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
531 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
532 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
533 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
534 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
535 | - ) ); |
|
529 | + $data = $this->routes->get_stats(array( |
|
530 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
531 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
532 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
533 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
534 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
535 | + )); |
|
536 | 536 | |
537 | 537 | break; |
538 | 538 | |
539 | 539 | case 'forms' : |
540 | 540 | |
541 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
541 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
542 | 542 | |
543 | - $data = $this->routes->get_forms( $form ); |
|
543 | + $data = $this->routes->get_forms($form); |
|
544 | 544 | |
545 | 545 | break; |
546 | 546 | |
547 | 547 | case 'donors' : |
548 | 548 | |
549 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
549 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
550 | 550 | |
551 | - $data = $this->routes->get_customers( $customer ); |
|
551 | + $data = $this->routes->get_customers($customer); |
|
552 | 552 | |
553 | 553 | break; |
554 | 554 | |
@@ -561,14 +561,14 @@ discard block |
||
561 | 561 | endswitch; |
562 | 562 | |
563 | 563 | // Allow extensions to setup their own return data |
564 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
564 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
565 | 565 | |
566 | - $after = microtime( true ); |
|
567 | - $request_time = ( $after - $before ); |
|
566 | + $after = microtime(true); |
|
567 | + $request_time = ($after - $before); |
|
568 | 568 | $this->data['request_speed'] = $request_time; |
569 | 569 | |
570 | 570 | // Log this API request, if enabled. We log it here because we have access to errors. |
571 | - $this->log_request( $this->data ); |
|
571 | + $this->log_request($this->data); |
|
572 | 572 | |
573 | 573 | // Send out data to the output function |
574 | 574 | $this->output(); |
@@ -598,25 +598,25 @@ discard block |
||
598 | 598 | global $wp_query; |
599 | 599 | |
600 | 600 | // Whitelist our query options |
601 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
601 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
602 | 602 | 'stats', |
603 | 603 | 'forms', |
604 | 604 | 'donors', |
605 | 605 | 'donations' |
606 | - ) ); |
|
606 | + )); |
|
607 | 607 | |
608 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
609 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
608 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
609 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
610 | 610 | |
611 | 611 | $error = array(); |
612 | 612 | |
613 | 613 | // Make sure our query is valid |
614 | - if ( ! in_array( $query, $accepted ) ) { |
|
615 | - $error['error'] = esc_html__( 'Invalid query.', 'give' ); |
|
614 | + if ( ! in_array($query, $accepted)) { |
|
615 | + $error['error'] = esc_html__('Invalid query.', 'give'); |
|
616 | 616 | |
617 | 617 | $this->data = $error; |
618 | 618 | // 400 is Bad Request |
619 | - $this->output( 400 ); |
|
619 | + $this->output(400); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | $this->endpoint = $query; |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | public function get_paged() { |
634 | 634 | global $wp_query; |
635 | 635 | |
636 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
636 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | public function per_page() { |
649 | 649 | global $wp_query; |
650 | 650 | |
651 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
651 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
652 | 652 | |
653 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
653 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
654 | 654 | $per_page = 99999999; |
655 | 655 | } // Customers query doesn't support -1 |
656 | 656 | |
657 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
657 | + return apply_filters('give_api_results_per_page', $per_page); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | * |
668 | 668 | * @return array $dates |
669 | 669 | */ |
670 | - public function get_dates( $args = array() ) { |
|
670 | + public function get_dates($args = array()) { |
|
671 | 671 | $dates = array(); |
672 | 672 | |
673 | 673 | $defaults = array( |
@@ -678,60 +678,60 @@ discard block |
||
678 | 678 | 'enddate' => null |
679 | 679 | ); |
680 | 680 | |
681 | - $args = wp_parse_args( $args, $defaults ); |
|
681 | + $args = wp_parse_args($args, $defaults); |
|
682 | 682 | |
683 | - $current_time = current_time( 'timestamp' ); |
|
683 | + $current_time = current_time('timestamp'); |
|
684 | 684 | |
685 | - if ( 'range' === $args['date'] ) { |
|
686 | - $startdate = strtotime( $args['startdate'] ); |
|
687 | - $enddate = strtotime( $args['enddate'] ); |
|
688 | - $dates['day_start'] = date( 'd', $startdate ); |
|
689 | - $dates['day_end'] = date( 'd', $enddate ); |
|
690 | - $dates['m_start'] = date( 'n', $startdate ); |
|
691 | - $dates['m_end'] = date( 'n', $enddate ); |
|
692 | - $dates['year'] = date( 'Y', $startdate ); |
|
693 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
685 | + if ('range' === $args['date']) { |
|
686 | + $startdate = strtotime($args['startdate']); |
|
687 | + $enddate = strtotime($args['enddate']); |
|
688 | + $dates['day_start'] = date('d', $startdate); |
|
689 | + $dates['day_end'] = date('d', $enddate); |
|
690 | + $dates['m_start'] = date('n', $startdate); |
|
691 | + $dates['m_end'] = date('n', $enddate); |
|
692 | + $dates['year'] = date('Y', $startdate); |
|
693 | + $dates['year_end'] = date('Y', $enddate); |
|
694 | 694 | } else { |
695 | 695 | // Modify dates based on predefined ranges |
696 | - switch ( $args['date'] ) : |
|
696 | + switch ($args['date']) : |
|
697 | 697 | |
698 | 698 | case 'this_month' : |
699 | 699 | $dates['day'] = null; |
700 | - $dates['m_start'] = date( 'n', $current_time ); |
|
701 | - $dates['m_end'] = date( 'n', $current_time ); |
|
702 | - $dates['year'] = date( 'Y', $current_time ); |
|
700 | + $dates['m_start'] = date('n', $current_time); |
|
701 | + $dates['m_end'] = date('n', $current_time); |
|
702 | + $dates['year'] = date('Y', $current_time); |
|
703 | 703 | break; |
704 | 704 | |
705 | 705 | case 'last_month' : |
706 | 706 | $dates['day'] = null; |
707 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
707 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
708 | 708 | $dates['m_end'] = $dates['m_start']; |
709 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
709 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
710 | 710 | break; |
711 | 711 | |
712 | 712 | case 'today' : |
713 | - $dates['day'] = date( 'd', $current_time ); |
|
714 | - $dates['m_start'] = date( 'n', $current_time ); |
|
715 | - $dates['m_end'] = date( 'n', $current_time ); |
|
716 | - $dates['year'] = date( 'Y', $current_time ); |
|
713 | + $dates['day'] = date('d', $current_time); |
|
714 | + $dates['m_start'] = date('n', $current_time); |
|
715 | + $dates['m_end'] = date('n', $current_time); |
|
716 | + $dates['year'] = date('Y', $current_time); |
|
717 | 717 | break; |
718 | 718 | |
719 | 719 | case 'yesterday' : |
720 | 720 | |
721 | - $year = date( 'Y', $current_time ); |
|
722 | - $month = date( 'n', $current_time ); |
|
723 | - $day = date( 'd', $current_time ); |
|
721 | + $year = date('Y', $current_time); |
|
722 | + $month = date('n', $current_time); |
|
723 | + $day = date('d', $current_time); |
|
724 | 724 | |
725 | - if ( $month == 1 && $day == 1 ) { |
|
725 | + if ($month == 1 && $day == 1) { |
|
726 | 726 | |
727 | 727 | $year -= 1; |
728 | 728 | $month = 12; |
729 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
729 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
730 | 730 | |
731 | - } elseif ( $month > 1 && $day == 1 ) { |
|
731 | + } elseif ($month > 1 && $day == 1) { |
|
732 | 732 | |
733 | 733 | $month -= 1; |
734 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
734 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
735 | 735 | |
736 | 736 | } else { |
737 | 737 | |
@@ -747,65 +747,65 @@ discard block |
||
747 | 747 | break; |
748 | 748 | |
749 | 749 | case 'this_quarter' : |
750 | - $month_now = date( 'n', $current_time ); |
|
750 | + $month_now = date('n', $current_time); |
|
751 | 751 | |
752 | 752 | $dates['day'] = null; |
753 | 753 | |
754 | - if ( $month_now <= 3 ) { |
|
754 | + if ($month_now <= 3) { |
|
755 | 755 | |
756 | 756 | $dates['m_start'] = 1; |
757 | 757 | $dates['m_end'] = 3; |
758 | - $dates['year'] = date( 'Y', $current_time ); |
|
758 | + $dates['year'] = date('Y', $current_time); |
|
759 | 759 | |
760 | - } else if ( $month_now <= 6 ) { |
|
760 | + } else if ($month_now <= 6) { |
|
761 | 761 | |
762 | 762 | $dates['m_start'] = 4; |
763 | 763 | $dates['m_end'] = 6; |
764 | - $dates['year'] = date( 'Y', $current_time ); |
|
764 | + $dates['year'] = date('Y', $current_time); |
|
765 | 765 | |
766 | - } else if ( $month_now <= 9 ) { |
|
766 | + } else if ($month_now <= 9) { |
|
767 | 767 | |
768 | 768 | $dates['m_start'] = 7; |
769 | 769 | $dates['m_end'] = 9; |
770 | - $dates['year'] = date( 'Y', $current_time ); |
|
770 | + $dates['year'] = date('Y', $current_time); |
|
771 | 771 | |
772 | 772 | } else { |
773 | 773 | |
774 | 774 | $dates['m_start'] = 10; |
775 | 775 | $dates['m_end'] = 12; |
776 | - $dates['year'] = date( 'Y', $current_time ); |
|
776 | + $dates['year'] = date('Y', $current_time); |
|
777 | 777 | |
778 | 778 | } |
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'last_quarter' : |
782 | - $month_now = date( 'n', $current_time ); |
|
782 | + $month_now = date('n', $current_time); |
|
783 | 783 | |
784 | 784 | $dates['day'] = null; |
785 | 785 | |
786 | - if ( $month_now <= 3 ) { |
|
786 | + if ($month_now <= 3) { |
|
787 | 787 | |
788 | 788 | $dates['m_start'] = 10; |
789 | 789 | $dates['m_end'] = 12; |
790 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
790 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
791 | 791 | |
792 | - } else if ( $month_now <= 6 ) { |
|
792 | + } else if ($month_now <= 6) { |
|
793 | 793 | |
794 | 794 | $dates['m_start'] = 1; |
795 | 795 | $dates['m_end'] = 3; |
796 | - $dates['year'] = date( 'Y', $current_time ); |
|
796 | + $dates['year'] = date('Y', $current_time); |
|
797 | 797 | |
798 | - } else if ( $month_now <= 9 ) { |
|
798 | + } else if ($month_now <= 9) { |
|
799 | 799 | |
800 | 800 | $dates['m_start'] = 4; |
801 | 801 | $dates['m_end'] = 6; |
802 | - $dates['year'] = date( 'Y', $current_time ); |
|
802 | + $dates['year'] = date('Y', $current_time); |
|
803 | 803 | |
804 | 804 | } else { |
805 | 805 | |
806 | 806 | $dates['m_start'] = 7; |
807 | 807 | $dates['m_end'] = 9; |
808 | - $dates['year'] = date( 'Y', $current_time ); |
|
808 | + $dates['year'] = date('Y', $current_time); |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | break; |
@@ -814,14 +814,14 @@ discard block |
||
814 | 814 | $dates['day'] = null; |
815 | 815 | $dates['m_start'] = null; |
816 | 816 | $dates['m_end'] = null; |
817 | - $dates['year'] = date( 'Y', $current_time ); |
|
817 | + $dates['year'] = date('Y', $current_time); |
|
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'last_year' : |
821 | 821 | $dates['day'] = null; |
822 | 822 | $dates['m_start'] = null; |
823 | 823 | $dates['m_end'] = null; |
824 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
824 | + $dates['year'] = date('Y', $current_time) - 1; |
|
825 | 825 | break; |
826 | 826 | |
827 | 827 | endswitch; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @param object $dates The dates used for retrieving earnings/donations |
836 | 836 | */ |
837 | 837 | |
838 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
838 | + return apply_filters('give_api_stat_dates', $dates); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -850,11 +850,11 @@ discard block |
||
850 | 850 | * |
851 | 851 | * @return array $customers Multidimensional array of the customers |
852 | 852 | */ |
853 | - public function get_customers( $customer = null ) { |
|
853 | + public function get_customers($customer = null) { |
|
854 | 854 | |
855 | 855 | $customers = array(); |
856 | 856 | $error = array(); |
857 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
857 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
858 | 858 | return $customers; |
859 | 859 | } |
860 | 860 | |
@@ -862,64 +862,64 @@ discard block |
||
862 | 862 | |
863 | 863 | $paged = $this->get_paged(); |
864 | 864 | $per_page = $this->per_page(); |
865 | - $offset = $per_page * ( $paged - 1 ); |
|
865 | + $offset = $per_page * ($paged - 1); |
|
866 | 866 | |
867 | - if ( is_numeric( $customer ) ) { |
|
867 | + if (is_numeric($customer)) { |
|
868 | 868 | $field = 'id'; |
869 | 869 | } else { |
870 | 870 | $field = 'email'; |
871 | 871 | } |
872 | 872 | |
873 | - $customer_query = Give()->customers->get_customers( array( |
|
873 | + $customer_query = Give()->customers->get_customers(array( |
|
874 | 874 | 'number' => $per_page, |
875 | 875 | 'offset' => $offset, |
876 | 876 | $field => $customer |
877 | - ) ); |
|
877 | + )); |
|
878 | 878 | $customer_count = 0; |
879 | 879 | |
880 | - if ( $customer_query ) { |
|
880 | + if ($customer_query) { |
|
881 | 881 | |
882 | - foreach ( $customer_query as $customer_obj ) { |
|
882 | + foreach ($customer_query as $customer_obj) { |
|
883 | 883 | |
884 | - $names = explode( ' ', $customer_obj->name ); |
|
885 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
884 | + $names = explode(' ', $customer_obj->name); |
|
885 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
886 | 886 | $last_name = ''; |
887 | - if ( ! empty( $names[1] ) ) { |
|
888 | - unset( $names[0] ); |
|
889 | - $last_name = implode( ' ', $names ); |
|
887 | + if ( ! empty($names[1])) { |
|
888 | + unset($names[0]); |
|
889 | + $last_name = implode(' ', $names); |
|
890 | 890 | } |
891 | 891 | |
892 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
894 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
895 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
896 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
897 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
898 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
892 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
894 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
895 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
896 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
897 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
898 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
899 | 899 | |
900 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
900 | + if ( ! empty($customer_obj->user_id)) { |
|
901 | 901 | |
902 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
902 | + $user_data = get_userdata($customer_obj->user_id); |
|
903 | 903 | |
904 | 904 | // Customer with registered account |
905 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
906 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
907 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
905 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
906 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
907 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
908 | 908 | |
909 | 909 | } |
910 | 910 | |
911 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
911 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
913 | 913 | |
914 | - $customer_count ++; |
|
914 | + $customer_count++; |
|
915 | 915 | |
916 | 916 | } |
917 | 917 | |
918 | - } elseif ( $customer ) { |
|
918 | + } elseif ($customer) { |
|
919 | 919 | |
920 | 920 | $error['error'] = sprintf( |
921 | 921 | /* translators: %s: customer */ |
922 | - esc_html__( 'Donor %s not found.', 'give' ), |
|
922 | + esc_html__('Donor %s not found.', 'give'), |
|
923 | 923 | $customer |
924 | 924 | ); |
925 | 925 | |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | |
928 | 928 | } else { |
929 | 929 | |
930 | - $error['error'] = esc_html__( 'No donors found.', 'give' ); |
|
930 | + $error['error'] = esc_html__('No donors found.', 'give'); |
|
931 | 931 | |
932 | 932 | return $error; |
933 | 933 | |
@@ -946,38 +946,38 @@ discard block |
||
946 | 946 | * |
947 | 947 | * @return array $customers Multidimensional array of the forms |
948 | 948 | */ |
949 | - public function get_forms( $form = null ) { |
|
949 | + public function get_forms($form = null) { |
|
950 | 950 | |
951 | 951 | $forms = array(); |
952 | 952 | $error = array(); |
953 | 953 | |
954 | - if ( $form == null ) { |
|
954 | + if ($form == null) { |
|
955 | 955 | $forms['forms'] = array(); |
956 | 956 | |
957 | - $form_list = get_posts( array( |
|
957 | + $form_list = get_posts(array( |
|
958 | 958 | 'post_type' => 'give_forms', |
959 | 959 | 'posts_per_page' => $this->per_page(), |
960 | 960 | 'suppress_filters' => true, |
961 | 961 | 'paged' => $this->get_paged() |
962 | - ) ); |
|
962 | + )); |
|
963 | 963 | |
964 | - if ( $form_list ) { |
|
964 | + if ($form_list) { |
|
965 | 965 | $i = 0; |
966 | - foreach ( $form_list as $form_info ) { |
|
967 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
968 | - $i ++; |
|
966 | + foreach ($form_list as $form_info) { |
|
967 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
968 | + $i++; |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | } else { |
972 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
973 | - $form_info = get_post( $form ); |
|
972 | + if (get_post_type($form) == 'give_forms') { |
|
973 | + $form_info = get_post($form); |
|
974 | 974 | |
975 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
975 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
976 | 976 | |
977 | 977 | } else { |
978 | 978 | $error['error'] = sprintf( |
979 | 979 | /* translators: %s: form */ |
980 | - esc_html__( 'Form %s not found.', 'give' ), |
|
980 | + esc_html__('Form %s not found.', 'give'), |
|
981 | 981 | $form |
982 | 982 | ); |
983 | 983 | |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | * |
998 | 998 | * @return array Array of post data to return back in the API |
999 | 999 | */ |
1000 | - private function get_form_data( $form_info ) { |
|
1000 | + private function get_form_data($form_info) { |
|
1001 | 1001 | |
1002 | 1002 | $form = array(); |
1003 | 1003 | |
@@ -1007,46 +1007,46 @@ discard block |
||
1007 | 1007 | $form['info']['create_date'] = $form_info->post_date; |
1008 | 1008 | $form['info']['modified_date'] = $form_info->post_modified; |
1009 | 1009 | $form['info']['status'] = $form_info->post_status; |
1010 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1011 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1012 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1010 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1011 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1012 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1013 | 1013 | |
1014 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
1015 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1016 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1014 | + if (give_get_option('enable_categories') == 'on') { |
|
1015 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1016 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1017 | 1017 | } |
1018 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
1019 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1018 | + if (give_get_option('enable_tags') == 'on') { |
|
1019 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1023 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1024 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1025 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1026 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1022 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1023 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1024 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1025 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1026 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | $counter = 0; |
1030 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1031 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1032 | - $counter ++; |
|
1030 | + if (give_has_variable_prices($form_info->ID)) { |
|
1031 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1032 | + $counter++; |
|
1033 | 1033 | //muli-level item |
1034 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1035 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1034 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1035 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1036 | 1036 | |
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1039 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1042 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1043 | 1043 | |
1044 | 1044 | //Sensitive data here |
1045 | - do_action( 'give_api_sensitive_data' ); |
|
1045 | + do_action('give_api_sensitive_data'); |
|
1046 | 1046 | |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1049 | + return apply_filters('give_api_forms_form', $form); |
|
1050 | 1050 | |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | * |
1062 | 1062 | * @return array |
1063 | 1063 | */ |
1064 | - public function get_stats( $args = array() ) { |
|
1064 | + public function get_stats($args = array()) { |
|
1065 | 1065 | $defaults = array( |
1066 | 1066 | 'type' => null, |
1067 | 1067 | 'form' => null, |
@@ -1070,9 +1070,9 @@ discard block |
||
1070 | 1070 | 'enddate' => null |
1071 | 1071 | ); |
1072 | 1072 | |
1073 | - $args = wp_parse_args( $args, $defaults ); |
|
1073 | + $args = wp_parse_args($args, $defaults); |
|
1074 | 1074 | |
1075 | - $dates = $this->get_dates( $args ); |
|
1075 | + $dates = $this->get_dates($args); |
|
1076 | 1076 | |
1077 | 1077 | $stats = array(); |
1078 | 1078 | $earnings = array( |
@@ -1083,41 +1083,41 @@ discard block |
||
1083 | 1083 | ); |
1084 | 1084 | $error = array(); |
1085 | 1085 | |
1086 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1086 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1087 | 1087 | return $stats; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - if ( $args['type'] == 'donations' ) { |
|
1090 | + if ($args['type'] == 'donations') { |
|
1091 | 1091 | |
1092 | - if ( $args['form'] == null ) { |
|
1093 | - if ( $args['date'] == null ) { |
|
1092 | + if ($args['form'] == null) { |
|
1093 | + if ($args['date'] == null) { |
|
1094 | 1094 | $sales = $this->get_default_sales_stats(); |
1095 | - } elseif ( $args['date'] === 'range' ) { |
|
1095 | + } elseif ($args['date'] === 'range') { |
|
1096 | 1096 | // Return sales for a date range |
1097 | 1097 | |
1098 | 1098 | // Ensure the end date is later than the start date |
1099 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1100 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1099 | + if ($args['enddate'] < $args['startdate']) { |
|
1100 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Ensure both the start and end date are specified |
1104 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1105 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1104 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1105 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $total = 0; |
1109 | 1109 | |
1110 | 1110 | // Loop through the years |
1111 | 1111 | $y = $dates['year']; |
1112 | - while ( $y <= $dates['year_end'] ) : |
|
1112 | + while ($y <= $dates['year_end']) : |
|
1113 | 1113 | |
1114 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1114 | + if ($dates['year'] == $dates['year_end']) { |
|
1115 | 1115 | $month_start = $dates['m_start']; |
1116 | 1116 | $month_end = $dates['m_end']; |
1117 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1117 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1118 | 1118 | $month_start = $dates['m_start']; |
1119 | 1119 | $month_end = 12; |
1120 | - } elseif ( $y == $dates['year_end'] ) { |
|
1120 | + } elseif ($y == $dates['year_end']) { |
|
1121 | 1121 | $month_start = 1; |
1122 | 1122 | $month_end = $dates['m_end']; |
1123 | 1123 | } else { |
@@ -1126,113 +1126,113 @@ discard block |
||
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | $i = $month_start; |
1129 | - while ( $i <= $month_end ) : |
|
1129 | + while ($i <= $month_end) : |
|
1130 | 1130 | |
1131 | - if ( $i == $dates['m_start'] ) { |
|
1131 | + if ($i == $dates['m_start']) { |
|
1132 | 1132 | $d = $dates['day_start']; |
1133 | 1133 | } else { |
1134 | 1134 | $d = 1; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if ( $i == $dates['m_end'] ) { |
|
1137 | + if ($i == $dates['m_end']) { |
|
1138 | 1138 | $num_of_days = $dates['day_end']; |
1139 | 1139 | } else { |
1140 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1140 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - while ( $d <= $num_of_days ) : |
|
1144 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1145 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1146 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1147 | - $sales['sales'][ $date_key ] = 0; |
|
1143 | + while ($d <= $num_of_days) : |
|
1144 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1145 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1146 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1147 | + $sales['sales'][$date_key] = 0; |
|
1148 | 1148 | } |
1149 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1149 | + $sales['sales'][$date_key] += $sale_count; |
|
1150 | 1150 | $total += $sale_count; |
1151 | - $d ++; |
|
1151 | + $d++; |
|
1152 | 1152 | endwhile; |
1153 | - $i ++; |
|
1153 | + $i++; |
|
1154 | 1154 | endwhile; |
1155 | 1155 | |
1156 | - $y ++; |
|
1156 | + $y++; |
|
1157 | 1157 | endwhile; |
1158 | 1158 | |
1159 | 1159 | $sales['totals'] = $total; |
1160 | 1160 | } else { |
1161 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1161 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1162 | 1162 | $sales_count = 0; |
1163 | 1163 | |
1164 | 1164 | // Loop through the months |
1165 | 1165 | $month = $dates['m_start']; |
1166 | 1166 | |
1167 | - while ( $month <= $dates['m_end'] ) : |
|
1168 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1169 | - $month ++; |
|
1167 | + while ($month <= $dates['m_end']) : |
|
1168 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1169 | + $month++; |
|
1170 | 1170 | endwhile; |
1171 | 1171 | |
1172 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1172 | + $sales['donations'][$args['date']] = $sales_count; |
|
1173 | 1173 | } else { |
1174 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1174 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1175 | 1175 | } |
1176 | 1176 | } |
1177 | - } elseif ( $args['form'] == 'all' ) { |
|
1178 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1177 | + } elseif ($args['form'] == 'all') { |
|
1178 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1179 | 1179 | $i = 0; |
1180 | - foreach ( $forms as $form_info ) { |
|
1181 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1182 | - $i ++; |
|
1180 | + foreach ($forms as $form_info) { |
|
1181 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1182 | + $i++; |
|
1183 | 1183 | } |
1184 | 1184 | } else { |
1185 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1186 | - $form_info = get_post( $args['form'] ); |
|
1187 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1185 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1186 | + $form_info = get_post($args['form']); |
|
1187 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1188 | 1188 | } else { |
1189 | 1189 | $error['error'] = sprintf( |
1190 | 1190 | /* translators: %s: form */ |
1191 | - esc_html__( 'Product %s not found.', 'give' ), |
|
1191 | + esc_html__('Product %s not found.', 'give'), |
|
1192 | 1192 | $args['form'] |
1193 | 1193 | ); |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( ! empty( $error ) ) { |
|
1197 | + if ( ! empty($error)) { |
|
1198 | 1198 | return $error; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | return $sales; |
1202 | 1202 | |
1203 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1204 | - if ( $args['form'] == null ) { |
|
1205 | - if ( $args['date'] == null ) { |
|
1203 | + } elseif ($args['type'] == 'earnings') { |
|
1204 | + if ($args['form'] == null) { |
|
1205 | + if ($args['date'] == null) { |
|
1206 | 1206 | $earnings = $this->get_default_earnings_stats(); |
1207 | - } elseif ( $args['date'] === 'range' ) { |
|
1207 | + } elseif ($args['date'] === 'range') { |
|
1208 | 1208 | // Return sales for a date range |
1209 | 1209 | |
1210 | 1210 | // Ensure the end date is later than the start date |
1211 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1212 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1211 | + if ($args['enddate'] < $args['startdate']) { |
|
1212 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // Ensure both the start and end date are specified |
1216 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1217 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1216 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1217 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | $total = (float) 0.00; |
1221 | 1221 | |
1222 | 1222 | // Loop through the years |
1223 | 1223 | $y = $dates['year']; |
1224 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1224 | + if ( ! isset($earnings['earnings'])) { |
|
1225 | 1225 | $earnings['earnings'] = array(); |
1226 | 1226 | } |
1227 | - while ( $y <= $dates['year_end'] ) : |
|
1227 | + while ($y <= $dates['year_end']) : |
|
1228 | 1228 | |
1229 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1229 | + if ($dates['year'] == $dates['year_end']) { |
|
1230 | 1230 | $month_start = $dates['m_start']; |
1231 | 1231 | $month_end = $dates['m_end']; |
1232 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1232 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1233 | 1233 | $month_start = $dates['m_start']; |
1234 | 1234 | $month_end = 12; |
1235 | - } elseif ( $y == $dates['year_end'] ) { |
|
1235 | + } elseif ($y == $dates['year_end']) { |
|
1236 | 1236 | $month_start = 1; |
1237 | 1237 | $month_end = $dates['m_end']; |
1238 | 1238 | } else { |
@@ -1241,92 +1241,92 @@ discard block |
||
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | $i = $month_start; |
1244 | - while ( $i <= $month_end ) : |
|
1244 | + while ($i <= $month_end) : |
|
1245 | 1245 | |
1246 | - if ( $i == $dates['m_start'] ) { |
|
1246 | + if ($i == $dates['m_start']) { |
|
1247 | 1247 | $d = $dates['day_start']; |
1248 | 1248 | } else { |
1249 | 1249 | $d = 1; |
1250 | 1250 | } |
1251 | 1251 | |
1252 | - if ( $i == $dates['m_end'] ) { |
|
1252 | + if ($i == $dates['m_end']) { |
|
1253 | 1253 | $num_of_days = $dates['day_end']; |
1254 | 1254 | } else { |
1255 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1255 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | - while ( $d <= $num_of_days ) : |
|
1259 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1260 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1261 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1262 | - $earnings['earnings'][ $date_key ] = 0; |
|
1258 | + while ($d <= $num_of_days) : |
|
1259 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1260 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1261 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1262 | + $earnings['earnings'][$date_key] = 0; |
|
1263 | 1263 | } |
1264 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1264 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1265 | 1265 | $total += $earnings_stat; |
1266 | - $d ++; |
|
1266 | + $d++; |
|
1267 | 1267 | endwhile; |
1268 | 1268 | |
1269 | - $i ++; |
|
1269 | + $i++; |
|
1270 | 1270 | endwhile; |
1271 | 1271 | |
1272 | - $y ++; |
|
1272 | + $y++; |
|
1273 | 1273 | endwhile; |
1274 | 1274 | |
1275 | 1275 | $earnings['totals'] = $total; |
1276 | 1276 | } else { |
1277 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1277 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1278 | 1278 | $earnings_count = (float) 0.00; |
1279 | 1279 | |
1280 | 1280 | // Loop through the months |
1281 | 1281 | $month = $dates['m_start']; |
1282 | 1282 | |
1283 | - while ( $month <= $dates['m_end'] ) : |
|
1284 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1285 | - $month ++; |
|
1283 | + while ($month <= $dates['m_end']) : |
|
1284 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1285 | + $month++; |
|
1286 | 1286 | endwhile; |
1287 | 1287 | |
1288 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1288 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1289 | 1289 | } else { |
1290 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1290 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1291 | 1291 | } |
1292 | 1292 | } |
1293 | - } elseif ( $args['form'] == 'all' ) { |
|
1294 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1293 | + } elseif ($args['form'] == 'all') { |
|
1294 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1295 | 1295 | |
1296 | 1296 | $i = 0; |
1297 | - foreach ( $forms as $form_info ) { |
|
1298 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1299 | - $i ++; |
|
1297 | + foreach ($forms as $form_info) { |
|
1298 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1299 | + $i++; |
|
1300 | 1300 | } |
1301 | 1301 | } else { |
1302 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1303 | - $form_info = get_post( $args['form'] ); |
|
1304 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1302 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1303 | + $form_info = get_post($args['form']); |
|
1304 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1305 | 1305 | } else { |
1306 | 1306 | $error['error'] = sprintf( |
1307 | 1307 | /* translators: %s: form */ |
1308 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1308 | + esc_html__('Form %s not found.', 'give'), |
|
1309 | 1309 | $args['form'] |
1310 | 1310 | ); |
1311 | 1311 | } |
1312 | 1312 | } |
1313 | 1313 | |
1314 | - if ( ! empty( $error ) ) { |
|
1314 | + if ( ! empty($error)) { |
|
1315 | 1315 | return $error; |
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | return $earnings; |
1319 | - } elseif ( $args['type'] == 'donors' ) { |
|
1319 | + } elseif ($args['type'] == 'donors') { |
|
1320 | 1320 | $customers = new Give_DB_Customers(); |
1321 | 1321 | $stats['donations']['total_donors'] = $customers->count(); |
1322 | 1322 | |
1323 | 1323 | return $stats; |
1324 | 1324 | |
1325 | - } elseif ( empty( $args['type'] ) ) { |
|
1326 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1327 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1325 | + } elseif (empty($args['type'])) { |
|
1326 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1327 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1328 | 1328 | |
1329 | - return array( 'stats' => $stats ); |
|
1329 | + return array('stats' => $stats); |
|
1330 | 1330 | } |
1331 | 1331 | } |
1332 | 1332 | |
@@ -1342,18 +1342,18 @@ discard block |
||
1342 | 1342 | |
1343 | 1343 | $sales = array(); |
1344 | 1344 | |
1345 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1345 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1346 | 1346 | return $sales; |
1347 | 1347 | } |
1348 | 1348 | |
1349 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1349 | + if (isset($wp_query->query_vars['id'])) { |
|
1350 | 1350 | $query = array(); |
1351 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1352 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1351 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1352 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1353 | 1353 | $query = array(); |
1354 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1355 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1356 | - $args = array( |
|
1354 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1355 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1356 | + $args = array( |
|
1357 | 1357 | 'fields' => 'ids', |
1358 | 1358 | 'meta_key' => '_give_payment_user_email', |
1359 | 1359 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | 'page' => $this->get_paged(), |
1362 | 1362 | 'status' => 'publish' |
1363 | 1363 | ); |
1364 | - $query = give_get_payments( $args ); |
|
1364 | + $query = give_get_payments($args); |
|
1365 | 1365 | } else { |
1366 | 1366 | $args = array( |
1367 | 1367 | 'fields' => 'ids', |
@@ -1369,14 +1369,14 @@ discard block |
||
1369 | 1369 | 'page' => $this->get_paged(), |
1370 | 1370 | 'status' => 'publish' |
1371 | 1371 | ); |
1372 | - $query = give_get_payments( $args ); |
|
1372 | + $query = give_get_payments($args); |
|
1373 | 1373 | } |
1374 | - if ( $query ) { |
|
1374 | + if ($query) { |
|
1375 | 1375 | $i = 0; |
1376 | - foreach ( $query as $payment ) { |
|
1376 | + foreach ($query as $payment) { |
|
1377 | 1377 | |
1378 | - if ( is_numeric( $payment ) ) { |
|
1379 | - $payment = new Give_Payment( $payment ); |
|
1378 | + if (is_numeric($payment)) { |
|
1379 | + $payment = new Give_Payment($payment); |
|
1380 | 1380 | $payment_meta = $payment->get_meta(); |
1381 | 1381 | $user_info = $payment->user_info; |
1382 | 1382 | } else { |
@@ -1386,40 +1386,40 @@ discard block |
||
1386 | 1386 | $payment_meta = $payment->get_meta(); |
1387 | 1387 | $user_info = $payment->user_info; |
1388 | 1388 | |
1389 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1390 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1391 | - |
|
1392 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1393 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1394 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1395 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1396 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1397 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1398 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1399 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1400 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1401 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1402 | - |
|
1403 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1404 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1405 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1406 | - |
|
1407 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1408 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1409 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1410 | - |
|
1411 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1412 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1413 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1414 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1415 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1416 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1389 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1390 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1391 | + |
|
1392 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1393 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1394 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1395 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1396 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1397 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1398 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1399 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1400 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1401 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1402 | + |
|
1403 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1404 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1405 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1406 | + |
|
1407 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1408 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1409 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1410 | + |
|
1411 | + if (give_has_variable_prices($form_id)) { |
|
1412 | + if (isset($payment_meta['price_id'])) { |
|
1413 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1414 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1415 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1416 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1417 | 1417 | |
1418 | 1418 | } |
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | //Add custom meta to API |
1422 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1422 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1423 | 1423 | |
1424 | 1424 | $exceptions = array( |
1425 | 1425 | 'form_title', |
@@ -1432,19 +1432,19 @@ discard block |
||
1432 | 1432 | ); |
1433 | 1433 | |
1434 | 1434 | //Don't clutter up results with dupes |
1435 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1435 | + if (in_array($meta_key, $exceptions)) { |
|
1436 | 1436 | continue; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1439 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1440 | 1440 | |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - $i ++; |
|
1443 | + $i++; |
|
1444 | 1444 | } |
1445 | 1445 | } |
1446 | 1446 | |
1447 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1447 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1460,9 +1460,9 @@ discard block |
||
1460 | 1460 | public function get_output_format() { |
1461 | 1461 | global $wp_query; |
1462 | 1462 | |
1463 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1463 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1464 | 1464 | |
1465 | - return apply_filters( 'give_api_output_format', $format ); |
|
1465 | + return apply_filters('give_api_output_format', $format); |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | |
@@ -1479,8 +1479,8 @@ discard block |
||
1479 | 1479 | * |
1480 | 1480 | * @return void |
1481 | 1481 | */ |
1482 | - private function log_request( $data = array() ) { |
|
1483 | - if ( ! $this->log_requests ) { |
|
1482 | + private function log_request($data = array()) { |
|
1483 | + if ( ! $this->log_requests) { |
|
1484 | 1484 | return; |
1485 | 1485 | } |
1486 | 1486 | |
@@ -1496,36 +1496,36 @@ discard block |
||
1496 | 1496 | |
1497 | 1497 | $query = array( |
1498 | 1498 | 'give-api' => $wp_query->query_vars['give-api'], |
1499 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1500 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1501 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1502 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1503 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1504 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1505 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1506 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1507 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1508 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1509 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1510 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1499 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1500 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1501 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1502 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1503 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1504 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1505 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1506 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1507 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1508 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1509 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1510 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1511 | 1511 | ); |
1512 | 1512 | |
1513 | 1513 | $log_data = array( |
1514 | 1514 | 'log_type' => 'api_request', |
1515 | - 'post_excerpt' => http_build_query( $query ), |
|
1516 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1515 | + 'post_excerpt' => http_build_query($query), |
|
1516 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1517 | 1517 | ); |
1518 | 1518 | |
1519 | 1519 | $log_meta = array( |
1520 | 1520 | 'request_ip' => give_get_ip(), |
1521 | 1521 | 'user' => $this->user_id, |
1522 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1523 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1522 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1523 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1524 | 1524 | 'time' => $data['request_speed'], |
1525 | 1525 | 'version' => $this->get_queried_version() |
1526 | 1526 | ); |
1527 | 1527 | |
1528 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1528 | + $give_logs->insert_log($log_data, $log_meta); |
|
1529 | 1529 | } |
1530 | 1530 | |
1531 | 1531 | |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | * |
1550 | 1550 | * @param int $status_code |
1551 | 1551 | */ |
1552 | - public function output( $status_code = 200 ) { |
|
1552 | + public function output($status_code = 200) { |
|
1553 | 1553 | /** |
1554 | 1554 | * @var WP_Query $wp_query |
1555 | 1555 | */ |
@@ -1557,27 +1557,27 @@ discard block |
||
1557 | 1557 | |
1558 | 1558 | $format = $this->get_output_format(); |
1559 | 1559 | |
1560 | - status_header( $status_code ); |
|
1560 | + status_header($status_code); |
|
1561 | 1561 | |
1562 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1562 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1563 | 1563 | |
1564 | - switch ( $format ) : |
|
1564 | + switch ($format) : |
|
1565 | 1565 | |
1566 | 1566 | case 'xml' : |
1567 | 1567 | |
1568 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1569 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1568 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1569 | + $xml = Array2XML::createXML('give', $this->data); |
|
1570 | 1570 | echo $xml->saveXML(); |
1571 | 1571 | |
1572 | 1572 | break; |
1573 | 1573 | |
1574 | 1574 | case 'json' : |
1575 | 1575 | |
1576 | - header( 'Content-Type: application/json' ); |
|
1577 | - if ( ! empty( $this->pretty_print ) ) { |
|
1578 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1576 | + header('Content-Type: application/json'); |
|
1577 | + if ( ! empty($this->pretty_print)) { |
|
1578 | + echo json_encode($this->data, $this->pretty_print); |
|
1579 | 1579 | } else { |
1580 | - echo json_encode( $this->data ); |
|
1580 | + echo json_encode($this->data); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | break; |
@@ -1586,13 +1586,13 @@ discard block |
||
1586 | 1586 | default : |
1587 | 1587 | |
1588 | 1588 | // Allow other formats to be added via extensions |
1589 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
1589 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
1590 | 1590 | |
1591 | 1591 | break; |
1592 | 1592 | |
1593 | 1593 | endswitch; |
1594 | 1594 | |
1595 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1595 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1596 | 1596 | |
1597 | 1597 | give_die(); |
1598 | 1598 | } |
@@ -1609,37 +1609,37 @@ discard block |
||
1609 | 1609 | * |
1610 | 1610 | * @return void |
1611 | 1611 | */ |
1612 | - function user_key_field( $user ) { |
|
1612 | + function user_key_field($user) { |
|
1613 | 1613 | |
1614 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1615 | - $user = get_userdata( $user->ID ); |
|
1614 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1615 | + $user = get_userdata($user->ID); |
|
1616 | 1616 | ?> |
1617 | 1617 | <table class="form-table"> |
1618 | 1618 | <tbody> |
1619 | 1619 | <tr> |
1620 | 1620 | <th> |
1621 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1621 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1622 | 1622 | </th> |
1623 | 1623 | <td> |
1624 | 1624 | <?php |
1625 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1626 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1625 | + $public_key = $this->get_user_public_key($user->ID); |
|
1626 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1627 | 1627 | ?> |
1628 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1628 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1629 | 1629 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1630 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1630 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1631 | 1631 | <?php } else { ?> |
1632 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> </strong> |
|
1633 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1632 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> </strong> |
|
1633 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1634 | 1634 | <br/> |
1635 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> </strong> |
|
1636 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1635 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> </strong> |
|
1636 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1637 | 1637 | <br/> |
1638 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> </strong> |
|
1639 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1638 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> </strong> |
|
1639 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1640 | 1640 | <br/> |
1641 | 1641 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1642 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1642 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1643 | 1643 | <?php } ?> |
1644 | 1644 | </td> |
1645 | 1645 | </tr> |
@@ -1658,69 +1658,69 @@ discard block |
||
1658 | 1658 | * |
1659 | 1659 | * @return void |
1660 | 1660 | */ |
1661 | - public function process_api_key( $args ) { |
|
1661 | + public function process_api_key($args) { |
|
1662 | 1662 | |
1663 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1663 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1664 | 1664 | |
1665 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1665 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
1666 | 1666 | |
1667 | 1667 | } |
1668 | 1668 | |
1669 | - if ( empty( $args['user_id'] ) ) { |
|
1670 | - wp_die( esc_html__( 'User ID Required.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1669 | + if (empty($args['user_id'])) { |
|
1670 | + wp_die(esc_html__('User ID Required.', 'give'), esc_html__('Error', 'give'), array('response' => 401)); |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1674 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1673 | + if (is_numeric($args['user_id'])) { |
|
1674 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1675 | 1675 | } else { |
1676 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1676 | + $userdata = get_user_by('login', $args['user_id']); |
|
1677 | 1677 | $user_id = $userdata->ID; |
1678 | 1678 | } |
1679 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1679 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1680 | 1680 | |
1681 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1681 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1682 | 1682 | wp_die( |
1683 | 1683 | sprintf( |
1684 | 1684 | /* translators: %s: process */ |
1685 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1685 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1686 | 1686 | $process |
1687 | 1687 | ), |
1688 | - esc_html__( 'Error', 'give' ), |
|
1689 | - array( 'response' => 403 ) |
|
1688 | + esc_html__('Error', 'give'), |
|
1689 | + array('response' => 403) |
|
1690 | 1690 | ); |
1691 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1691 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1692 | 1692 | wp_die( |
1693 | 1693 | sprintf( |
1694 | 1694 | /* translators: %s: process */ |
1695 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1695 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1696 | 1696 | $process |
1697 | 1697 | ), |
1698 | - esc_html__( 'Error', 'give' ), |
|
1699 | - array( 'response' => 403 ) |
|
1698 | + esc_html__('Error', 'give'), |
|
1699 | + array('response' => 403) |
|
1700 | 1700 | ); |
1701 | 1701 | } |
1702 | 1702 | |
1703 | - switch ( $process ) { |
|
1703 | + switch ($process) { |
|
1704 | 1704 | case 'generate': |
1705 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1706 | - delete_transient( 'give_total_api_keys' ); |
|
1707 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1705 | + if ($this->generate_api_key($user_id)) { |
|
1706 | + delete_transient('give_total_api_keys'); |
|
1707 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1708 | 1708 | exit(); |
1709 | 1709 | } else { |
1710 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1710 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1711 | 1711 | exit(); |
1712 | 1712 | } |
1713 | 1713 | break; |
1714 | 1714 | case 'regenerate': |
1715 | - $this->generate_api_key( $user_id, true ); |
|
1716 | - delete_transient( 'give_total_api_keys' ); |
|
1717 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1715 | + $this->generate_api_key($user_id, true); |
|
1716 | + delete_transient('give_total_api_keys'); |
|
1717 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1718 | 1718 | exit(); |
1719 | 1719 | break; |
1720 | 1720 | case 'revoke': |
1721 | - $this->revoke_api_key( $user_id ); |
|
1722 | - delete_transient( 'give_total_api_keys' ); |
|
1723 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1721 | + $this->revoke_api_key($user_id); |
|
1722 | + delete_transient('give_total_api_keys'); |
|
1723 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1724 | 1724 | exit(); |
1725 | 1725 | break; |
1726 | 1726 | default; |
@@ -1739,34 +1739,34 @@ discard block |
||
1739 | 1739 | * |
1740 | 1740 | * @return boolean True if (re)generated succesfully, false otherwise. |
1741 | 1741 | */ |
1742 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1742 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1743 | 1743 | |
1744 | - if ( empty( $user_id ) ) { |
|
1744 | + if (empty($user_id)) { |
|
1745 | 1745 | return false; |
1746 | 1746 | } |
1747 | 1747 | |
1748 | - $user = get_userdata( $user_id ); |
|
1748 | + $user = get_userdata($user_id); |
|
1749 | 1749 | |
1750 | - if ( ! $user ) { |
|
1750 | + if ( ! $user) { |
|
1751 | 1751 | return false; |
1752 | 1752 | } |
1753 | 1753 | |
1754 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1755 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1754 | + $public_key = $this->get_user_public_key($user_id); |
|
1755 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1756 | 1756 | |
1757 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1758 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1759 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1757 | + if (empty($public_key) || $regenerate == true) { |
|
1758 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1759 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1760 | 1760 | } else { |
1761 | 1761 | return false; |
1762 | 1762 | } |
1763 | 1763 | |
1764 | - if ( $regenerate == true ) { |
|
1765 | - $this->revoke_api_key( $user->ID ); |
|
1764 | + if ($regenerate == true) { |
|
1765 | + $this->revoke_api_key($user->ID); |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1769 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1768 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1769 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1770 | 1770 | |
1771 | 1771 | return true; |
1772 | 1772 | } |
@@ -1781,26 +1781,26 @@ discard block |
||
1781 | 1781 | * |
1782 | 1782 | * @return string |
1783 | 1783 | */ |
1784 | - public function revoke_api_key( $user_id = 0 ) { |
|
1784 | + public function revoke_api_key($user_id = 0) { |
|
1785 | 1785 | |
1786 | - if ( empty( $user_id ) ) { |
|
1786 | + if (empty($user_id)) { |
|
1787 | 1787 | return false; |
1788 | 1788 | } |
1789 | 1789 | |
1790 | - $user = get_userdata( $user_id ); |
|
1790 | + $user = get_userdata($user_id); |
|
1791 | 1791 | |
1792 | - if ( ! $user ) { |
|
1792 | + if ( ! $user) { |
|
1793 | 1793 | return false; |
1794 | 1794 | } |
1795 | 1795 | |
1796 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1797 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1798 | - if ( ! empty( $public_key ) ) { |
|
1799 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
1800 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
1801 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
1802 | - delete_user_meta( $user_id, $public_key ); |
|
1803 | - delete_user_meta( $user_id, $secret_key ); |
|
1796 | + $public_key = $this->get_user_public_key($user_id); |
|
1797 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1798 | + if ( ! empty($public_key)) { |
|
1799 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
1800 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
1801 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
1802 | + delete_user_meta($user_id, $public_key); |
|
1803 | + delete_user_meta($user_id, $secret_key); |
|
1804 | 1804 | } else { |
1805 | 1805 | return false; |
1806 | 1806 | } |
@@ -1825,22 +1825,22 @@ discard block |
||
1825 | 1825 | * |
1826 | 1826 | * @return void |
1827 | 1827 | */ |
1828 | - public function update_key( $user_id ) { |
|
1829 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1828 | + public function update_key($user_id) { |
|
1829 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1830 | 1830 | |
1831 | - $user = get_userdata( $user_id ); |
|
1831 | + $user = get_userdata($user_id); |
|
1832 | 1832 | |
1833 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1834 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1833 | + $public_key = $this->get_user_public_key($user_id); |
|
1834 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1835 | 1835 | |
1836 | - if ( empty( $public_key ) ) { |
|
1837 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1838 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1836 | + if (empty($public_key)) { |
|
1837 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1838 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1839 | 1839 | |
1840 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1841 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1840 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1841 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1842 | 1842 | } else { |
1843 | - $this->revoke_api_key( $user_id ); |
|
1843 | + $this->revoke_api_key($user_id); |
|
1844 | 1844 | } |
1845 | 1845 | } |
1846 | 1846 | } |
@@ -1855,9 +1855,9 @@ discard block |
||
1855 | 1855 | * |
1856 | 1856 | * @return string |
1857 | 1857 | */ |
1858 | - private function generate_public_key( $user_email = '' ) { |
|
1859 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1860 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1858 | + private function generate_public_key($user_email = '') { |
|
1859 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1860 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1861 | 1861 | |
1862 | 1862 | return $public; |
1863 | 1863 | } |
@@ -1872,9 +1872,9 @@ discard block |
||
1872 | 1872 | * |
1873 | 1873 | * @return string |
1874 | 1874 | */ |
1875 | - private function generate_private_key( $user_id = 0 ) { |
|
1876 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1877 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1875 | + private function generate_private_key($user_id = 0) { |
|
1876 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1877 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1878 | 1878 | |
1879 | 1879 | return $secret; |
1880 | 1880 | } |
@@ -1889,8 +1889,8 @@ discard block |
||
1889 | 1889 | * |
1890 | 1890 | * @return string |
1891 | 1891 | */ |
1892 | - public function get_token( $user_id = 0 ) { |
|
1893 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1892 | + public function get_token($user_id = 0) { |
|
1893 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1894 | 1894 | } |
1895 | 1895 | |
1896 | 1896 | /** |
@@ -1904,9 +1904,9 @@ discard block |
||
1904 | 1904 | |
1905 | 1905 | // Default sales return |
1906 | 1906 | $sales = array(); |
1907 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1908 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1909 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1907 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1908 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1909 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1910 | 1910 | $sales['donations']['totals'] = give_get_total_sales(); |
1911 | 1911 | |
1912 | 1912 | return $sales; |
@@ -1923,9 +1923,9 @@ discard block |
||
1923 | 1923 | |
1924 | 1924 | // Default earnings return |
1925 | 1925 | $earnings = array(); |
1926 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1927 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1928 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1926 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1927 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1928 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1929 | 1929 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1930 | 1930 | |
1931 | 1931 | return $earnings; |
@@ -1945,25 +1945,25 @@ discard block |
||
1945 | 1945 | * |
1946 | 1946 | * @return string The API key/secret for the user supplied |
1947 | 1947 | */ |
1948 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1948 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1949 | 1949 | |
1950 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1950 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1951 | 1951 | return $check; |
1952 | 1952 | } |
1953 | 1953 | |
1954 | 1954 | $return = $check; |
1955 | 1955 | |
1956 | - switch ( $meta_key ) { |
|
1956 | + switch ($meta_key) { |
|
1957 | 1957 | case 'give_user_public_key': |
1958 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1958 | + $return = Give()->api->get_user_public_key($object_id); |
|
1959 | 1959 | break; |
1960 | 1960 | case 'give_user_secret_key': |
1961 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1961 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1962 | 1962 | break; |
1963 | 1963 | } |
1964 | 1964 | |
1965 | - if ( ! $single ) { |
|
1966 | - $return = array( $return ); |
|
1965 | + if ( ! $single) { |
|
1966 | + $return = array($return); |
|
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | return $return; |
@@ -10,14 +10,14 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -defined( 'ABSPATH' ) or exit; |
|
13 | +defined('ABSPATH') or exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Give Form widget |
17 | 17 | * |
18 | 18 | * @since 1.0 |
19 | 19 | */ |
20 | -class Give_Forms_Widget extends WP_Widget{ |
|
20 | +class Give_Forms_Widget extends WP_Widget { |
|
21 | 21 | /** |
22 | 22 | * The widget class name |
23 | 23 | * |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Instantiate the class |
30 | 30 | */ |
31 | - public function __construct(){ |
|
32 | - $this->self = get_class( $this ); |
|
31 | + public function __construct() { |
|
32 | + $this->self = get_class($this); |
|
33 | 33 | |
34 | 34 | parent::__construct( |
35 | - strtolower( $this->self ), |
|
36 | - esc_html__( 'Give - Donation Form', 'give' ), |
|
35 | + strtolower($this->self), |
|
36 | + esc_html__('Give - Donation Form', 'give'), |
|
37 | 37 | array( |
38 | - 'description' => esc_html__( 'Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give' ) |
|
38 | + 'description' => esc_html__('Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give') |
|
39 | 39 | ) |
40 | 40 | ); |
41 | 41 | |
42 | - add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
43 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) ); |
|
42 | + add_action('widgets_init', array($this, 'widget_init')); |
|
43 | + add_action('admin_enqueue_scripts', array($this, 'admin_widget_scripts')); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -50,23 +50,23 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return void |
52 | 52 | */ |
53 | - public function admin_widget_scripts( $hook ){ |
|
53 | + public function admin_widget_scripts($hook) { |
|
54 | 54 | // Directories of assets |
55 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
56 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
57 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
55 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
56 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
57 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
58 | 58 | |
59 | 59 | // Use minified libraries if SCRIPT_DEBUG is turned off |
60 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
60 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
61 | 61 | |
62 | 62 | // Widget Script |
63 | - if ( $hook == 'widgets.php' ) { |
|
63 | + if ($hook == 'widgets.php') { |
|
64 | 64 | |
65 | - wp_enqueue_style( 'give-qtip-css', $css_dir . 'jquery.qtip' . $suffix . '.css' ); |
|
65 | + wp_enqueue_style('give-qtip-css', $css_dir.'jquery.qtip'.$suffix.'.css'); |
|
66 | 66 | |
67 | - wp_enqueue_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
67 | + wp_enqueue_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
68 | 68 | |
69 | - wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
69 | + wp_enqueue_script('give-admin-widgets-scripts', $js_dir.'admin-widgets'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * before_widget, and after_widget. |
78 | 78 | * @param array $instance The settings for the particular instance of the widget. |
79 | 79 | */ |
80 | - public function widget( $args, $instance ){ |
|
81 | - $title = !empty( $instance['title'] ) ? $instance['title'] : ''; |
|
82 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
80 | + public function widget($args, $instance) { |
|
81 | + $title = ! empty($instance['title']) ? $instance['title'] : ''; |
|
82 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
83 | 83 | |
84 | 84 | echo $args['before_widget']; |
85 | 85 | |
86 | - do_action( 'give_before_forms_widget' ); |
|
86 | + do_action('give_before_forms_widget'); |
|
87 | 87 | |
88 | - echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; |
|
88 | + echo $title ? $args['before_title'].$title.$args['after_title'] : ''; |
|
89 | 89 | |
90 | - give_get_donation_form( $instance ); |
|
90 | + give_get_donation_form($instance); |
|
91 | 91 | |
92 | 92 | echo $args['after_widget']; |
93 | 93 | |
94 | - do_action( 'give_after_forms_widget' ); |
|
94 | + do_action('give_after_forms_widget'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,61 +101,61 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - public function form( $instance ){ |
|
104 | + public function form($instance) { |
|
105 | 105 | $defaults = array( |
106 | 106 | 'title' => '', |
107 | 107 | 'id' => '', |
108 | 108 | 'float_labels' => '', |
109 | 109 | ); |
110 | 110 | |
111 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
111 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
112 | 112 | |
113 | 113 | // Query Give Forms |
114 | 114 | $args = array( |
115 | 115 | 'post_type' => 'give_forms', |
116 | - 'posts_per_page' => - 1, |
|
116 | + 'posts_per_page' => -1, |
|
117 | 117 | 'post_status' => 'publish', |
118 | 118 | ); |
119 | 119 | |
120 | - $give_forms = get_posts( $args ); |
|
120 | + $give_forms = get_posts($args); |
|
121 | 121 | |
122 | 122 | // Widget: Title |
123 | 123 | |
124 | 124 | ?><p> |
125 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label> |
|
126 | - <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php esc_attr_e( $instance['title'] ); ?>" /><br> |
|
127 | - <small><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
|
125 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('Title:', 'give'); ?></label> |
|
126 | + <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php esc_attr_e($instance['title']); ?>" /><br> |
|
127 | + <small><?php esc_html_e('Leave blank to hide the widget title.', 'give'); ?></small> |
|
128 | 128 | </p><?php |
129 | 129 | |
130 | 130 | // Widget: Give Form |
131 | 131 | |
132 | 132 | ?><p> |
133 | - <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php |
|
133 | + <label for="<?php echo esc_attr($this->get_field_id('id')); ?>"><?php |
|
134 | 134 | printf( |
135 | 135 | /* translators: %s: form singular label */ |
136 | - esc_html__( 'Give %s:', 'give' ), |
|
136 | + esc_html__('Give %s:', 'give'), |
|
137 | 137 | give_get_forms_label_singular() |
138 | 138 | ); |
139 | 139 | ?></label> |
140 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> |
|
141 | - <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option> |
|
142 | - <?php foreach ( $give_forms as $give_form ) { ?> |
|
143 | - <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo $give_form->post_title; ?></option> |
|
140 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('id')); ?>" id="<?php echo esc_attr($this->get_field_id('id')); ?>"> |
|
141 | + <option value="current"><?php esc_html_e('- Select -', 'give'); ?></option> |
|
142 | + <?php foreach ($give_forms as $give_form) { ?> |
|
143 | + <option <?php selected(absint($instance['id']), $give_form->ID); ?> value="<?php echo esc_attr($give_form->ID); ?>"><?php echo $give_form->post_title; ?></option> |
|
144 | 144 | <?php } ?> |
145 | 145 | </select><br> |
146 | - <small><?php esc_html_e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small> |
|
146 | + <small><?php esc_html_e('Select a Give Form to embed in this widget.', 'give'); ?></small> |
|
147 | 147 | </p><?php |
148 | 148 | |
149 | 149 | // Widget: Floating Labels |
150 | 150 | |
151 | 151 | ?><p> |
152 | - <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels:', 'give' ); ?></label> |
|
153 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"> |
|
154 | - <option value="" <?php selected( esc_attr( $instance['float_labels'] ), '' ) ?>><?php esc_html_e( '- Select -', 'give' ); ?></option> |
|
155 | - <option value="enabled" <?php selected( esc_attr( $instance['float_labels'] ), 'enabled' ) ?>><?php esc_html_e( 'Enabled', 'give' ); ?></option> |
|
156 | - <option value="disabled" <?php selected( esc_attr( $instance['float_labels'] ), 'disabled' ) ?>><?php esc_html_e( 'Disabled', 'give' ); ?></option> |
|
152 | + <label for="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"><?php esc_html_e('Floating Labels:', 'give'); ?></label> |
|
153 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('float_labels')); ?>" id="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"> |
|
154 | + <option value="" <?php selected(esc_attr($instance['float_labels']), '') ?>><?php esc_html_e('- Select -', 'give'); ?></option> |
|
155 | + <option value="enabled" <?php selected(esc_attr($instance['float_labels']), 'enabled') ?>><?php esc_html_e('Enabled', 'give'); ?></option> |
|
156 | + <option value="disabled" <?php selected(esc_attr($instance['float_labels']), 'disabled') ?>><?php esc_html_e('Disabled', 'give'); ?></option> |
|
157 | 157 | </select><br> |
158 | - <small><?php esc_html_e( 'Override the default floating labels setting for this form.', 'give' ); ?></small> |
|
158 | + <small><?php esc_html_e('Override the default floating labels setting for this form.', 'give'); ?></small> |
|
159 | 159 | </p><?php |
160 | 160 | } |
161 | 161 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return void |
166 | 166 | */ |
167 | - function widget_init(){ |
|
168 | - register_widget( $this->self ); |
|
167 | + function widget_init() { |
|
168 | + register_widget($this->self); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return array |
178 | 178 | */ |
179 | - public function update( $new_instance, $old_instance ){ |
|
179 | + public function update($new_instance, $old_instance) { |
|
180 | 180 | $this->flush_widget_cache(); |
181 | 181 | |
182 | 182 | return $new_instance; |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @return void |
189 | 189 | */ |
190 | - public function flush_widget_cache(){ |
|
191 | - wp_cache_delete( $this->self, 'widget' ); |
|
190 | + public function flush_widget_cache() { |
|
191 | + wp_cache_delete($this->self, 'widget'); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 |