@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -23,40 +23,40 @@ discard block |
||
23 | 23 | function give_setup_post_types() { |
24 | 24 | |
25 | 25 | /** Give Forms Post Type */ |
26 | - $give_forms_singular = give_get_option( 'disable_forms_singular' ) !== 'on' ? true : false; |
|
26 | + $give_forms_singular = give_get_option('disable_forms_singular') !== 'on' ? true : false; |
|
27 | 27 | |
28 | - $give_forms_archives = give_get_option( 'disable_forms_archives' ) !== 'on' ? true : false; |
|
28 | + $give_forms_archives = give_get_option('disable_forms_archives') !== 'on' ? true : false; |
|
29 | 29 | |
30 | - $give_forms_slug = defined( 'GIVE_SLUG' ) ? GIVE_SLUG : 'donations'; |
|
30 | + $give_forms_slug = defined('GIVE_SLUG') ? GIVE_SLUG : 'donations'; |
|
31 | 31 | //support for old 'GIVE_FORMS_SLUG' constant |
32 | - if ( defined( 'GIVE_FORMS_SLUG' ) ) { |
|
32 | + if (defined('GIVE_FORMS_SLUG')) { |
|
33 | 33 | $give_forms_slug = GIVE_FORMS_SLUG; |
34 | 34 | } |
35 | 35 | |
36 | - $give_forms_rewrite = defined( 'GIVE_DISABLE_FORMS_REWRITE' ) && GIVE_DISABLE_FORMS_REWRITE ? false : array( |
|
36 | + $give_forms_rewrite = defined('GIVE_DISABLE_FORMS_REWRITE') && GIVE_DISABLE_FORMS_REWRITE ? false : array( |
|
37 | 37 | 'slug' => $give_forms_slug, |
38 | 38 | 'with_front' => false |
39 | 39 | ); |
40 | 40 | |
41 | - $give_forms_labels = apply_filters( 'give_forms_labels', array( |
|
42 | - 'name' => __( 'Donation %2$s', 'give' ), |
|
41 | + $give_forms_labels = apply_filters('give_forms_labels', array( |
|
42 | + 'name' => __('Donation %2$s', 'give'), |
|
43 | 43 | 'singular_name' => '%1$s', |
44 | - 'add_new' => __( 'Add %1$s', 'give' ), |
|
45 | - 'add_new_item' => __( 'Add New Donation %1$s', 'give' ), |
|
46 | - 'edit_item' => __( 'Edit Donation %1$s', 'give' ), |
|
47 | - 'new_item' => __( 'New %1$s', 'give' ), |
|
48 | - 'all_items' => __( 'All %2$s', 'give' ), |
|
49 | - 'view_item' => __( 'View %1$s', 'give' ), |
|
50 | - 'search_items' => __( 'Search %2$s', 'give' ), |
|
51 | - 'not_found' => __( 'No %2$s found', 'give' ), |
|
52 | - 'not_found_in_trash' => __( 'No %2$s found in Trash', 'give' ), |
|
44 | + 'add_new' => __('Add %1$s', 'give'), |
|
45 | + 'add_new_item' => __('Add New Donation %1$s', 'give'), |
|
46 | + 'edit_item' => __('Edit Donation %1$s', 'give'), |
|
47 | + 'new_item' => __('New %1$s', 'give'), |
|
48 | + 'all_items' => __('All %2$s', 'give'), |
|
49 | + 'view_item' => __('View %1$s', 'give'), |
|
50 | + 'search_items' => __('Search %2$s', 'give'), |
|
51 | + 'not_found' => __('No %2$s found', 'give'), |
|
52 | + 'not_found_in_trash' => __('No %2$s found in Trash', 'give'), |
|
53 | 53 | 'parent_item_colon' => '', |
54 | - 'menu_name' => apply_filters( 'give_menu_name', __( 'Donations', 'give' ) ), |
|
55 | - 'name_admin_bar' => apply_filters( 'give_name_admin_bar_name', __( 'Donation Form', 'give' ) ) |
|
56 | - ) ); |
|
54 | + 'menu_name' => apply_filters('give_menu_name', __('Donations', 'give')), |
|
55 | + 'name_admin_bar' => apply_filters('give_name_admin_bar_name', __('Donation Form', 'give')) |
|
56 | + )); |
|
57 | 57 | |
58 | - foreach ( $give_forms_labels as $key => $value ) { |
|
59 | - $give_forms_labels[ $key ] = sprintf( $value, give_get_forms_label_singular(), give_get_forms_label_plural() ); |
|
58 | + foreach ($give_forms_labels as $key => $value) { |
|
59 | + $give_forms_labels[$key] = sprintf($value, give_get_forms_label_singular(), give_get_forms_label_plural()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | //Default give_forms supports |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | ); |
70 | 70 | |
71 | 71 | //Has the user disabled the excerpt |
72 | - if ( give_get_option( 'disable_forms_excerpt' ) === 'on' ) { |
|
73 | - unset( $give_form_supports[2] ); |
|
72 | + if (give_get_option('disable_forms_excerpt') === 'on') { |
|
73 | + unset($give_form_supports[2]); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | //Has user disabled the featured image? |
77 | - if ( give_get_option( 'disable_form_featured_img' ) === 'on' ) { |
|
78 | - unset( $give_form_supports[1] ); |
|
79 | - remove_action( 'give_before_single_form_summary', 'give_show_form_images' ); |
|
77 | + if (give_get_option('disable_form_featured_img') === 'on') { |
|
78 | + unset($give_form_supports[1]); |
|
79 | + remove_action('give_before_single_form_summary', 'give_show_form_images'); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $give_forms_args = array( |
@@ -92,42 +92,42 @@ discard block |
||
92 | 92 | 'has_archive' => $give_forms_archives, |
93 | 93 | 'menu_icon' => 'dashicons-give', |
94 | 94 | 'hierarchical' => false, |
95 | - 'supports' => apply_filters( 'give_forms_supports', $give_form_supports ), |
|
95 | + 'supports' => apply_filters('give_forms_supports', $give_form_supports), |
|
96 | 96 | ); |
97 | - register_post_type( 'give_forms', apply_filters( 'give_forms_post_type_args', $give_forms_args ) ); |
|
97 | + register_post_type('give_forms', apply_filters('give_forms_post_type_args', $give_forms_args)); |
|
98 | 98 | |
99 | 99 | /** Payment Post Type */ |
100 | 100 | $payment_labels = array( |
101 | - 'name' => _x( 'Donations', 'post type general name', 'give' ), |
|
102 | - 'singular_name' => _x( 'Donation', 'post type singular name', 'give' ), |
|
103 | - 'add_new' => __( 'Add New', 'give' ), |
|
104 | - 'add_new_item' => __( 'Add New Donation', 'give' ), |
|
105 | - 'edit_item' => __( 'Edit Donation', 'give' ), |
|
106 | - 'new_item' => __( 'New Donation', 'give' ), |
|
107 | - 'all_items' => __( 'All Donations', 'give' ), |
|
108 | - 'view_item' => __( 'View Donation', 'give' ), |
|
109 | - 'search_items' => __( 'Search Donations', 'give' ), |
|
110 | - 'not_found' => __( 'No Donations found', 'give' ), |
|
111 | - 'not_found_in_trash' => __( 'No Donations found in Trash', 'give' ), |
|
101 | + 'name' => _x('Donations', 'post type general name', 'give'), |
|
102 | + 'singular_name' => _x('Donation', 'post type singular name', 'give'), |
|
103 | + 'add_new' => __('Add New', 'give'), |
|
104 | + 'add_new_item' => __('Add New Donation', 'give'), |
|
105 | + 'edit_item' => __('Edit Donation', 'give'), |
|
106 | + 'new_item' => __('New Donation', 'give'), |
|
107 | + 'all_items' => __('All Donations', 'give'), |
|
108 | + 'view_item' => __('View Donation', 'give'), |
|
109 | + 'search_items' => __('Search Donations', 'give'), |
|
110 | + 'not_found' => __('No Donations found', 'give'), |
|
111 | + 'not_found_in_trash' => __('No Donations found in Trash', 'give'), |
|
112 | 112 | 'parent_item_colon' => '', |
113 | - 'menu_name' => __( 'Transactions', 'give' ) |
|
113 | + 'menu_name' => __('Transactions', 'give') |
|
114 | 114 | ); |
115 | 115 | |
116 | 116 | $payment_args = array( |
117 | - 'labels' => apply_filters( 'give_payment_labels', $payment_labels ), |
|
117 | + 'labels' => apply_filters('give_payment_labels', $payment_labels), |
|
118 | 118 | 'public' => false, |
119 | 119 | 'query_var' => false, |
120 | 120 | 'rewrite' => false, |
121 | 121 | 'map_meta_cap' => true, |
122 | 122 | 'capability_type' => 'give_payment', |
123 | - 'supports' => array( 'title' ), |
|
123 | + 'supports' => array('title'), |
|
124 | 124 | 'can_export' => true |
125 | 125 | ); |
126 | - register_post_type( 'give_payment', $payment_args ); |
|
126 | + register_post_type('give_payment', $payment_args); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -add_action( 'init', 'give_setup_post_types', 1 ); |
|
130 | +add_action('init', 'give_setup_post_types', 1); |
|
131 | 131 | |
132 | 132 | |
133 | 133 | /** |
@@ -140,32 +140,32 @@ discard block |
||
140 | 140 | */ |
141 | 141 | function give_setup_taxonomies() { |
142 | 142 | |
143 | - $slug = defined( 'GIVE_FORMS_SLUG' ) ? GIVE_FORMS_SLUG : 'donations'; |
|
143 | + $slug = defined('GIVE_FORMS_SLUG') ? GIVE_FORMS_SLUG : 'donations'; |
|
144 | 144 | |
145 | 145 | /** Categories */ |
146 | 146 | $category_labels = array( |
147 | 147 | /* translators: %s: form singular label */ |
148 | - 'name' => sprintf( _x( '%s Categories', 'taxonomy general name', 'give' ), give_get_forms_label_singular() ), |
|
149 | - 'singular_name' => _x( 'Category', 'taxonomy singular name', 'give' ), |
|
150 | - 'search_items' => __( 'Search Categories', 'give' ), |
|
151 | - 'all_items' => __( 'All Categories', 'give' ), |
|
152 | - 'parent_item' => __( 'Parent Category', 'give' ), |
|
153 | - 'parent_item_colon' => __( 'Parent Category:', 'give' ), |
|
154 | - 'edit_item' => __( 'Edit Category', 'give' ), |
|
155 | - 'update_item' => __( 'Update Category', 'give' ), |
|
148 | + 'name' => sprintf(_x('%s Categories', 'taxonomy general name', 'give'), give_get_forms_label_singular()), |
|
149 | + 'singular_name' => _x('Category', 'taxonomy singular name', 'give'), |
|
150 | + 'search_items' => __('Search Categories', 'give'), |
|
151 | + 'all_items' => __('All Categories', 'give'), |
|
152 | + 'parent_item' => __('Parent Category', 'give'), |
|
153 | + 'parent_item_colon' => __('Parent Category:', 'give'), |
|
154 | + 'edit_item' => __('Edit Category', 'give'), |
|
155 | + 'update_item' => __('Update Category', 'give'), |
|
156 | 156 | /* translators: %s: form singular label */ |
157 | - 'add_new_item' => sprintf( __( 'Add New %s Category', 'give' ), give_get_forms_label_singular() ), |
|
158 | - 'new_item_name' => __( 'New Category Name', 'give' ), |
|
159 | - 'menu_name' => __( 'Categories', 'give' ), |
|
157 | + 'add_new_item' => sprintf(__('Add New %s Category', 'give'), give_get_forms_label_singular()), |
|
158 | + 'new_item_name' => __('New Category Name', 'give'), |
|
159 | + 'menu_name' => __('Categories', 'give'), |
|
160 | 160 | ); |
161 | 161 | |
162 | - $category_args = apply_filters( 'give_forms_category_args', array( |
|
162 | + $category_args = apply_filters('give_forms_category_args', array( |
|
163 | 163 | 'hierarchical' => true, |
164 | - 'labels' => apply_filters( 'give_forms_category_labels', $category_labels ), |
|
164 | + 'labels' => apply_filters('give_forms_category_labels', $category_labels), |
|
165 | 165 | 'show_ui' => true, |
166 | 166 | 'query_var' => 'give_forms_category', |
167 | 167 | 'rewrite' => array( |
168 | - 'slug' => $slug . '/category', |
|
168 | + 'slug' => $slug.'/category', |
|
169 | 169 | 'with_front' => false, |
170 | 170 | 'hierarchical' => true |
171 | 171 | ), |
@@ -179,36 +179,36 @@ discard block |
||
179 | 179 | ); |
180 | 180 | |
181 | 181 | //Does the user want categories? |
182 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
183 | - register_taxonomy( 'give_forms_category', array( 'give_forms' ), $category_args ); |
|
184 | - register_taxonomy_for_object_type( 'give_forms_category', 'give_forms' ); |
|
182 | + if (give_get_option('enable_categories') == 'on') { |
|
183 | + register_taxonomy('give_forms_category', array('give_forms'), $category_args); |
|
184 | + register_taxonomy_for_object_type('give_forms_category', 'give_forms'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
188 | 188 | /** Tags */ |
189 | 189 | $tag_labels = array( |
190 | 190 | /* translators: %s: form singular label */ |
191 | - 'name' => sprintf( _x( '%s Tags', 'taxonomy general name', 'give' ), give_get_forms_label_singular() ), |
|
192 | - 'singular_name' => _x( 'Tag', 'taxonomy singular name', 'give' ), |
|
193 | - 'search_items' => __( 'Search Tags', 'give' ), |
|
194 | - 'all_items' => __( 'All Tags', 'give' ), |
|
195 | - 'parent_item' => __( 'Parent Tag', 'give' ), |
|
196 | - 'parent_item_colon' => __( 'Parent Tag:', 'give' ), |
|
197 | - 'edit_item' => __( 'Edit Tag', 'give' ), |
|
198 | - 'update_item' => __( 'Update Tag', 'give' ), |
|
199 | - 'add_new_item' => __( 'Add New Tag', 'give' ), |
|
200 | - 'new_item_name' => __( 'New Tag Name', 'give' ), |
|
201 | - 'menu_name' => __( 'Tags', 'give' ), |
|
191 | + 'name' => sprintf(_x('%s Tags', 'taxonomy general name', 'give'), give_get_forms_label_singular()), |
|
192 | + 'singular_name' => _x('Tag', 'taxonomy singular name', 'give'), |
|
193 | + 'search_items' => __('Search Tags', 'give'), |
|
194 | + 'all_items' => __('All Tags', 'give'), |
|
195 | + 'parent_item' => __('Parent Tag', 'give'), |
|
196 | + 'parent_item_colon' => __('Parent Tag:', 'give'), |
|
197 | + 'edit_item' => __('Edit Tag', 'give'), |
|
198 | + 'update_item' => __('Update Tag', 'give'), |
|
199 | + 'add_new_item' => __('Add New Tag', 'give'), |
|
200 | + 'new_item_name' => __('New Tag Name', 'give'), |
|
201 | + 'menu_name' => __('Tags', 'give'), |
|
202 | 202 | /* translators: %s: form singular label */ |
203 | - 'choose_from_most_used' => sprintf( __( 'Choose from most used %s tags.', 'give' ), give_get_forms_label_singular() ), |
|
203 | + 'choose_from_most_used' => sprintf(__('Choose from most used %s tags.', 'give'), give_get_forms_label_singular()), |
|
204 | 204 | ); |
205 | 205 | |
206 | - $tag_args = apply_filters( 'give_forms_tag_args', array( |
|
206 | + $tag_args = apply_filters('give_forms_tag_args', array( |
|
207 | 207 | 'hierarchical' => false, |
208 | - 'labels' => apply_filters( 'give_forms_tag_labels', $tag_labels ), |
|
208 | + 'labels' => apply_filters('give_forms_tag_labels', $tag_labels), |
|
209 | 209 | 'show_ui' => true, |
210 | 210 | 'query_var' => 'give_forms_tag', |
211 | - 'rewrite' => array( 'slug' => $slug . '/tag', 'with_front' => false, 'hierarchical' => true ), |
|
211 | + 'rewrite' => array('slug' => $slug.'/tag', 'with_front' => false, 'hierarchical' => true), |
|
212 | 212 | 'capabilities' => array( |
213 | 213 | 'manage_terms' => 'manage_give_forms_terms', |
214 | 214 | 'edit_terms' => 'edit_give_forms_terms', |
@@ -219,15 +219,15 @@ discard block |
||
219 | 219 | ) |
220 | 220 | ); |
221 | 221 | |
222 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
223 | - register_taxonomy( 'give_forms_tag', array( 'give_forms' ), $tag_args ); |
|
224 | - register_taxonomy_for_object_type( 'give_forms_tag', 'give_forms' ); |
|
222 | + if (give_get_option('enable_tags') == 'on') { |
|
223 | + register_taxonomy('give_forms_tag', array('give_forms'), $tag_args); |
|
224 | + register_taxonomy_for_object_type('give_forms_tag', 'give_forms'); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
228 | 228 | } |
229 | 229 | |
230 | -add_action( 'init', 'give_setup_taxonomies', 0 ); |
|
230 | +add_action('init', 'give_setup_taxonomies', 0); |
|
231 | 231 | |
232 | 232 | |
233 | 233 | /** |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | */ |
239 | 239 | function give_get_default_form_labels() { |
240 | 240 | $defaults = array( |
241 | - 'singular' => __( 'Form', 'give' ), |
|
242 | - 'plural' => __( 'Forms', 'give' ) |
|
241 | + 'singular' => __('Form', 'give'), |
|
242 | + 'plural' => __('Forms', 'give') |
|
243 | 243 | ); |
244 | 244 | |
245 | - return apply_filters( 'give_default_form_name', $defaults ); |
|
245 | + return apply_filters('give_default_form_name', $defaults); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return string $defaults['singular'] Singular label |
256 | 256 | */ |
257 | -function give_get_forms_label_singular( $lowercase = false ) { |
|
257 | +function give_get_forms_label_singular($lowercase = false) { |
|
258 | 258 | $defaults = give_get_default_form_labels(); |
259 | 259 | |
260 | - return ( $lowercase ) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
260 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | * @since 1.0 |
267 | 267 | * @return string $defaults['plural'] Plural label |
268 | 268 | */ |
269 | -function give_get_forms_label_plural( $lowercase = false ) { |
|
269 | +function give_get_forms_label_plural($lowercase = false) { |
|
270 | 270 | $defaults = give_get_default_form_labels(); |
271 | 271 | |
272 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
272 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @return string $title New placeholder text |
283 | 283 | */ |
284 | -function give_change_default_title( $title ) { |
|
284 | +function give_change_default_title($title) { |
|
285 | 285 | // If a frontend plugin uses this filter (check extensions before changing this function) |
286 | - if ( ! is_admin() ) { |
|
286 | + if ( ! is_admin()) { |
|
287 | 287 | $title = sprintf( |
288 | 288 | /* translators: %s: form singular label */ |
289 | - __( 'Enter %s title here', 'give' ), |
|
289 | + __('Enter %s title here', 'give'), |
|
290 | 290 | give_get_forms_label_singular() |
291 | 291 | ); |
292 | 292 | |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | |
296 | 296 | $screen = get_current_screen(); |
297 | 297 | |
298 | - if ( 'give_forms' == $screen->post_type ) { |
|
298 | + if ('give_forms' == $screen->post_type) { |
|
299 | 299 | $title = sprintf( |
300 | 300 | /* translators: %s: form singular label */ |
301 | - __( 'Enter %s title here', 'give' ), |
|
301 | + __('Enter %s title here', 'give'), |
|
302 | 302 | give_get_forms_label_singular() |
303 | 303 | ); |
304 | 304 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | return $title; |
307 | 307 | } |
308 | 308 | |
309 | -add_filter( 'enter_title_here', 'give_change_default_title' ); |
|
309 | +add_filter('enter_title_here', 'give_change_default_title'); |
|
310 | 310 | |
311 | 311 | /** |
312 | 312 | * Registers Custom Post Statuses which are used by the Payments |
@@ -316,50 +316,50 @@ discard block |
||
316 | 316 | */ |
317 | 317 | function give_register_post_type_statuses() { |
318 | 318 | // Payment Statuses |
319 | - register_post_status( 'refunded', array( |
|
320 | - 'label' => _x( 'Refunded', 'Refunded payment status', 'give' ), |
|
319 | + register_post_status('refunded', array( |
|
320 | + 'label' => _x('Refunded', 'Refunded payment status', 'give'), |
|
321 | 321 | 'public' => true, |
322 | 322 | 'exclude_from_search' => false, |
323 | 323 | 'show_in_admin_all_list' => true, |
324 | 324 | 'show_in_admin_status_list' => true, |
325 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'give' ) |
|
326 | - ) ); |
|
327 | - register_post_status( 'failed', array( |
|
328 | - 'label' => _x( 'Failed', 'Failed payment status', 'give' ), |
|
325 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'give') |
|
326 | + )); |
|
327 | + register_post_status('failed', array( |
|
328 | + 'label' => _x('Failed', 'Failed payment status', 'give'), |
|
329 | 329 | 'public' => true, |
330 | 330 | 'exclude_from_search' => false, |
331 | 331 | 'show_in_admin_all_list' => true, |
332 | 332 | 'show_in_admin_status_list' => true, |
333 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'give' ) |
|
334 | - ) ); |
|
335 | - register_post_status( 'revoked', array( |
|
336 | - 'label' => _x( 'Revoked', 'Revoked payment status', 'give' ), |
|
333 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'give') |
|
334 | + )); |
|
335 | + register_post_status('revoked', array( |
|
336 | + 'label' => _x('Revoked', 'Revoked payment status', 'give'), |
|
337 | 337 | 'public' => true, |
338 | 338 | 'exclude_from_search' => false, |
339 | 339 | 'show_in_admin_all_list' => true, |
340 | 340 | 'show_in_admin_status_list' => true, |
341 | - 'label_count' => _n_noop( 'Revoked <span class="count">(%s)</span>', 'Revoked <span class="count">(%s)</span>', 'give' ) |
|
342 | - ) ); |
|
343 | - register_post_status( 'cancelled', array( |
|
344 | - 'label' => _x( 'Cancelled', 'Cancelled payment status', 'give' ), |
|
341 | + 'label_count' => _n_noop('Revoked <span class="count">(%s)</span>', 'Revoked <span class="count">(%s)</span>', 'give') |
|
342 | + )); |
|
343 | + register_post_status('cancelled', array( |
|
344 | + 'label' => _x('Cancelled', 'Cancelled payment status', 'give'), |
|
345 | 345 | 'public' => true, |
346 | 346 | 'exclude_from_search' => false, |
347 | 347 | 'show_in_admin_all_list' => true, |
348 | 348 | 'show_in_admin_status_list' => true, |
349 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'give' ) |
|
350 | - ) ); |
|
351 | - register_post_status( 'abandoned', array( |
|
352 | - 'label' => _x( 'Abandoned', 'Abandoned payment status', 'give' ), |
|
349 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'give') |
|
350 | + )); |
|
351 | + register_post_status('abandoned', array( |
|
352 | + 'label' => _x('Abandoned', 'Abandoned payment status', 'give'), |
|
353 | 353 | 'public' => true, |
354 | 354 | 'exclude_from_search' => false, |
355 | 355 | 'show_in_admin_all_list' => true, |
356 | 356 | 'show_in_admin_status_list' => true, |
357 | - 'label_count' => _n_noop( 'Abandoned <span class="count">(%s)</span>', 'Abandoned <span class="count">(%s)</span>', 'give' ) |
|
358 | - ) ); |
|
357 | + 'label_count' => _n_noop('Abandoned <span class="count">(%s)</span>', 'Abandoned <span class="count">(%s)</span>', 'give') |
|
358 | + )); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
362 | -add_action( 'init', 'give_register_post_type_statuses' ); |
|
362 | +add_action('init', 'give_register_post_type_statuses'); |
|
363 | 363 | |
364 | 364 | /** |
365 | 365 | * Updated Messages |
@@ -372,43 +372,43 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @return array $messages New post updated messages |
374 | 374 | */ |
375 | -function give_updated_messages( $messages ) { |
|
375 | +function give_updated_messages($messages) { |
|
376 | 376 | global $post, $post_ID; |
377 | 377 | |
378 | - $url1 = '<a href="' . get_permalink( $post_ID ) . '">'; |
|
378 | + $url1 = '<a href="'.get_permalink($post_ID).'">'; |
|
379 | 379 | $url2 = give_get_forms_label_singular(); |
380 | 380 | $url3 = '</a>'; |
381 | 381 | |
382 | 382 | $messages['give_forms'] = array( |
383 | - 1 => sprintf( __( '%2$s updated. %1$sView %2$s%3$s.', 'give' ), $url1, $url2, $url3 ), |
|
384 | - 4 => sprintf( __( '%2$s updated. %1$sView %2$s%3$s.', 'give' ), $url1, $url2, $url3 ), |
|
385 | - 6 => sprintf( __( '%2$s published. %1$sView %2$s%3$s.', 'give' ), $url1, $url2, $url3 ), |
|
386 | - 7 => sprintf( __( '%2$s saved. %1$sView %2$s%3$s.', 'give' ), $url1, $url2, $url3 ), |
|
387 | - 8 => sprintf( __( '%2$s submitted. %1$sView %2$s%3$s.', 'give' ), $url1, $url2, $url3 ) |
|
383 | + 1 => sprintf(__('%2$s updated. %1$sView %2$s%3$s.', 'give'), $url1, $url2, $url3), |
|
384 | + 4 => sprintf(__('%2$s updated. %1$sView %2$s%3$s.', 'give'), $url1, $url2, $url3), |
|
385 | + 6 => sprintf(__('%2$s published. %1$sView %2$s%3$s.', 'give'), $url1, $url2, $url3), |
|
386 | + 7 => sprintf(__('%2$s saved. %1$sView %2$s%3$s.', 'give'), $url1, $url2, $url3), |
|
387 | + 8 => sprintf(__('%2$s submitted. %1$sView %2$s%3$s.', 'give'), $url1, $url2, $url3) |
|
388 | 388 | ); |
389 | 389 | |
390 | 390 | return $messages; |
391 | 391 | } |
392 | 392 | |
393 | -add_filter( 'post_updated_messages', 'give_updated_messages' ); |
|
393 | +add_filter('post_updated_messages', 'give_updated_messages'); |
|
394 | 394 | |
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Setup Post Type Images |
398 | 398 | */ |
399 | -add_action( 'after_setup_theme', 'give_add_thumbnail_support', 10 ); |
|
399 | +add_action('after_setup_theme', 'give_add_thumbnail_support', 10); |
|
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Ensure post thumbnail support is turned on |
403 | 403 | */ |
404 | 404 | function give_add_thumbnail_support() { |
405 | - if ( give_get_option( 'disable_form_featured_img' ) === 'on' ) { |
|
405 | + if (give_get_option('disable_form_featured_img') === 'on') { |
|
406 | 406 | return; |
407 | 407 | } |
408 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { |
|
409 | - add_theme_support( 'post-thumbnails' ); |
|
408 | + if ( ! current_theme_supports('post-thumbnails')) { |
|
409 | + add_theme_support('post-thumbnails'); |
|
410 | 410 | } |
411 | - add_post_type_support( 'give_forms', 'thumbnail' ); |
|
411 | + add_post_type_support('give_forms', 'thumbnail'); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -420,19 +420,19 @@ discard block |
||
420 | 420 | function give_widgets_init() { |
421 | 421 | |
422 | 422 | //Single Give Forms (disabled if single turned off in settings) |
423 | - if ( give_get_option( 'disable_forms_singular' ) !== 'on' && give_get_option( 'disable_form_sidebar' ) !== 'on' ) { |
|
423 | + if (give_get_option('disable_forms_singular') !== 'on' && give_get_option('disable_form_sidebar') !== 'on') { |
|
424 | 424 | |
425 | - register_sidebar( apply_filters( 'give_forms_single_sidebar', array( |
|
426 | - 'name' => __( 'Give Single Form Sidebar', 'give' ), |
|
425 | + register_sidebar(apply_filters('give_forms_single_sidebar', array( |
|
426 | + 'name' => __('Give Single Form Sidebar', 'give'), |
|
427 | 427 | 'id' => 'give-forms-sidebar', |
428 | - 'description' => __( 'Widgets in this area will be shown on the single Give forms aside area. This sidebar will not display for embedded forms.', 'give' ), |
|
428 | + 'description' => __('Widgets in this area will be shown on the single Give forms aside area. This sidebar will not display for embedded forms.', 'give'), |
|
429 | 429 | 'before_widget' => '<div id="%1$s" class="widget %2$s">', |
430 | 430 | 'after_widget' => '</div>', |
431 | 431 | 'before_title' => '<h3 class="widgettitle widget-title">', |
432 | 432 | 'after_title' => '</h3>', |
433 | - ) ) ); |
|
433 | + ))); |
|
434 | 434 | |
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | -add_action( 'widgets_init', 'give_widgets_init', 999 ); |
|
438 | +add_action('widgets_init', 'give_widgets_init', 999); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -28,94 +28,94 @@ discard block |
||
28 | 28 | |
29 | 29 | global $give_options; |
30 | 30 | |
31 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/frontend/'; |
|
32 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
33 | - $scripts_footer = ( give_get_option( 'scripts_footer' ) == 'on' ) ? true : false; |
|
31 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/frontend/'; |
|
32 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
33 | + $scripts_footer = (give_get_option('scripts_footer') == 'on') ? true : false; |
|
34 | 34 | |
35 | 35 | // Use minified libraries if SCRIPT_DEBUG is turned off |
36 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
36 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
37 | 37 | |
38 | 38 | //Localize / PHP to AJAX vars |
39 | - $localize_give_checkout = apply_filters( 'give_global_script_vars', array( |
|
39 | + $localize_give_checkout = apply_filters('give_global_script_vars', array( |
|
40 | 40 | 'ajaxurl' => give_get_ajax_url(), |
41 | - 'checkout_nonce' => wp_create_nonce( 'give_checkout_nonce' ), |
|
42 | - 'currency_sign' => give_currency_filter( '' ), |
|
41 | + 'checkout_nonce' => wp_create_nonce('give_checkout_nonce'), |
|
42 | + 'currency_sign' => give_currency_filter(''), |
|
43 | 43 | 'currency_pos' => give_get_currency_position(), |
44 | - 'thousands_separator' => isset( $give_options['thousands_separator'] ) ? $give_options['thousands_separator'] : ',', |
|
45 | - 'decimal_separator' => isset( $give_options['decimal_separator'] ) ? $give_options['decimal_separator'] : '.', |
|
46 | - 'no_gateway' => __( 'Please select a payment method.', 'give' ), |
|
47 | - 'bad_minimum' => __( 'The minimum donation amount for this form is', 'give' ), |
|
48 | - 'general_loading' => __( 'Loading...', 'give' ), |
|
49 | - 'purchase_loading' => __( 'Please Wait...', 'give' ), |
|
50 | - 'number_decimals' => apply_filters( 'give_format_amount_decimals', 2 ), |
|
44 | + 'thousands_separator' => isset($give_options['thousands_separator']) ? $give_options['thousands_separator'] : ',', |
|
45 | + 'decimal_separator' => isset($give_options['decimal_separator']) ? $give_options['decimal_separator'] : '.', |
|
46 | + 'no_gateway' => __('Please select a payment method.', 'give'), |
|
47 | + 'bad_minimum' => __('The minimum donation amount for this form is', 'give'), |
|
48 | + 'general_loading' => __('Loading...', 'give'), |
|
49 | + 'purchase_loading' => __('Please Wait...', 'give'), |
|
50 | + 'number_decimals' => apply_filters('give_format_amount_decimals', 2), |
|
51 | 51 | 'give_version' => GIVE_VERSION |
52 | - ) ); |
|
53 | - $localize_give_ajax = apply_filters( 'give_global_ajax_vars', array( |
|
52 | + )); |
|
53 | + $localize_give_ajax = apply_filters('give_global_ajax_vars', array( |
|
54 | 54 | 'ajaxurl' => give_get_ajax_url(), |
55 | - 'loading' => __( 'Loading', 'give' ), |
|
55 | + 'loading' => __('Loading', 'give'), |
|
56 | 56 | // General loading message |
57 | - 'select_option' => __( 'Please select an option', 'give' ), |
|
57 | + 'select_option' => __('Please select an option', 'give'), |
|
58 | 58 | // Variable pricing error with multi-purchase option enabled |
59 | - 'default_gateway' => give_get_default_gateway( null ), |
|
60 | - 'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0', |
|
61 | - 'number_decimals' => apply_filters( 'give_format_amount_decimals', 2 ) |
|
62 | - ) ); |
|
59 | + 'default_gateway' => give_get_default_gateway(null), |
|
60 | + 'permalinks' => get_option('permalink_structure') ? '1' : '0', |
|
61 | + 'number_decimals' => apply_filters('give_format_amount_decimals', 2) |
|
62 | + )); |
|
63 | 63 | |
64 | 64 | //DEBUG is On |
65 | - if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
|
65 | + if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { |
|
66 | 66 | |
67 | - if ( give_is_cc_verify_enabled() ) { |
|
68 | - wp_register_script( 'give-cc-validator', $js_plugins . 'jquery.payment' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
69 | - wp_enqueue_script( 'give-cc-validator' ); |
|
67 | + if (give_is_cc_verify_enabled()) { |
|
68 | + wp_register_script('give-cc-validator', $js_plugins.'jquery.payment'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
69 | + wp_enqueue_script('give-cc-validator'); |
|
70 | 70 | } |
71 | 71 | |
72 | - wp_register_script( 'give-float-labels', $js_plugins . 'float-labels' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
73 | - wp_enqueue_script( 'give-float-labels' ); |
|
72 | + wp_register_script('give-float-labels', $js_plugins.'float-labels'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
73 | + wp_enqueue_script('give-float-labels'); |
|
74 | 74 | |
75 | - wp_register_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
76 | - wp_enqueue_script( 'give-blockui' ); |
|
75 | + wp_register_script('give-blockui', $js_plugins.'jquery.blockUI'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
76 | + wp_enqueue_script('give-blockui'); |
|
77 | 77 | |
78 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
79 | - wp_enqueue_script( 'give-qtip' ); |
|
78 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
79 | + wp_enqueue_script('give-qtip'); |
|
80 | 80 | |
81 | - wp_register_script( 'give-accounting', $js_plugins . 'accounting' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
82 | - wp_enqueue_script( 'give-accounting' ); |
|
81 | + wp_register_script('give-accounting', $js_plugins.'accounting'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
82 | + wp_enqueue_script('give-accounting'); |
|
83 | 83 | |
84 | - wp_register_script( 'give-magnific', $js_plugins . 'jquery.magnific-popup' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
85 | - wp_enqueue_script( 'give-magnific' ); |
|
84 | + wp_register_script('give-magnific', $js_plugins.'jquery.magnific-popup'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
85 | + wp_enqueue_script('give-magnific'); |
|
86 | 86 | |
87 | - wp_register_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
88 | - wp_enqueue_script( 'give-checkout-global' ); |
|
87 | + wp_register_script('give-checkout-global', $js_dir.'give-checkout-global'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
88 | + wp_enqueue_script('give-checkout-global'); |
|
89 | 89 | |
90 | 90 | //General scripts |
91 | - wp_register_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
92 | - wp_enqueue_script( 'give-scripts' ); |
|
91 | + wp_register_script('give-scripts', $js_dir.'give'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
92 | + wp_enqueue_script('give-scripts'); |
|
93 | 93 | |
94 | 94 | // Load AJAX scripts, if enabled |
95 | - wp_register_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
96 | - wp_enqueue_script( 'give-ajax' ); |
|
95 | + wp_register_script('give-ajax', $js_dir.'give-ajax'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
96 | + wp_enqueue_script('give-ajax'); |
|
97 | 97 | |
98 | 98 | //Localize / Pass AJAX vars from PHP |
99 | - wp_localize_script( 'give-checkout-global', 'give_global_vars', $localize_give_checkout ); |
|
100 | - wp_localize_script( 'give-ajax', 'give_scripts', $localize_give_ajax ); |
|
99 | + wp_localize_script('give-checkout-global', 'give_global_vars', $localize_give_checkout); |
|
100 | + wp_localize_script('give-ajax', 'give_scripts', $localize_give_ajax); |
|
101 | 101 | |
102 | 102 | |
103 | 103 | } else { |
104 | 104 | |
105 | 105 | //DEBUG is OFF (one JS file to rule them all!) |
106 | - wp_register_script( 'give', $js_dir . 'give.all.min.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer ); |
|
107 | - wp_enqueue_script( 'give' ); |
|
106 | + wp_register_script('give', $js_dir.'give.all.min.js', array('jquery'), GIVE_VERSION, $scripts_footer); |
|
107 | + wp_enqueue_script('give'); |
|
108 | 108 | |
109 | 109 | //Localize / Pass AJAX vars from PHP |
110 | - wp_localize_script( 'give', 'give_global_vars', $localize_give_checkout ); |
|
111 | - wp_localize_script( 'give', 'give_scripts', $localize_give_ajax ); |
|
110 | + wp_localize_script('give', 'give_global_vars', $localize_give_checkout); |
|
111 | + wp_localize_script('give', 'give_scripts', $localize_give_ajax); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | 116 | } |
117 | 117 | |
118 | -add_action( 'wp_enqueue_scripts', 'give_load_scripts' ); |
|
118 | +add_action('wp_enqueue_scripts', 'give_load_scripts'); |
|
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Register Styles |
@@ -127,47 +127,47 @@ discard block |
||
127 | 127 | */ |
128 | 128 | function give_register_styles() { |
129 | 129 | |
130 | - if ( give_get_option( 'disable_css', false ) ) { |
|
130 | + if (give_get_option('disable_css', false)) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | // Use minified libraries if SCRIPT_DEBUG is turned off |
135 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
135 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
136 | 136 | |
137 | - $file = 'give' . $suffix . '.css'; |
|
137 | + $file = 'give'.$suffix.'.css'; |
|
138 | 138 | $templates_dir = give_get_theme_template_dir_name(); |
139 | 139 | |
140 | - $child_theme_style_sheet = trailingslashit( get_stylesheet_directory() ) . $templates_dir . $file; |
|
141 | - $child_theme_style_sheet_2 = trailingslashit( get_stylesheet_directory() ) . $templates_dir . 'give.css'; |
|
142 | - $parent_theme_style_sheet = trailingslashit( get_template_directory() ) . $templates_dir . $file; |
|
143 | - $parent_theme_style_sheet_2 = trailingslashit( get_template_directory() ) . $templates_dir . 'give.css'; |
|
144 | - $give_plugin_style_sheet = trailingslashit( give_get_templates_dir() ) . $file; |
|
140 | + $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()).$templates_dir.$file; |
|
141 | + $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()).$templates_dir.'give.css'; |
|
142 | + $parent_theme_style_sheet = trailingslashit(get_template_directory()).$templates_dir.$file; |
|
143 | + $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()).$templates_dir.'give.css'; |
|
144 | + $give_plugin_style_sheet = trailingslashit(give_get_templates_dir()).$file; |
|
145 | 145 | |
146 | 146 | // Look in the child theme directory first, followed by the parent theme, followed by the Give core templates directory |
147 | 147 | // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. |
148 | 148 | // This allows users to copy just give.css to their theme |
149 | - if ( file_exists( $child_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $child_theme_style_sheet_2 ) ) ) ) { |
|
150 | - if ( ! empty( $nonmin ) ) { |
|
151 | - $url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . 'give.css'; |
|
149 | + if (file_exists($child_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2)))) { |
|
150 | + if ( ! empty($nonmin)) { |
|
151 | + $url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.'give.css'; |
|
152 | 152 | } else { |
153 | - $url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . $file; |
|
153 | + $url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.$file; |
|
154 | 154 | } |
155 | - } elseif ( file_exists( $parent_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $parent_theme_style_sheet_2 ) ) ) ) { |
|
156 | - if ( ! empty( $nonmin ) ) { |
|
157 | - $url = trailingslashit( get_template_directory_uri() ) . $templates_dir . 'give.css'; |
|
155 | + } elseif (file_exists($parent_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2)))) { |
|
156 | + if ( ! empty($nonmin)) { |
|
157 | + $url = trailingslashit(get_template_directory_uri()).$templates_dir.'give.css'; |
|
158 | 158 | } else { |
159 | - $url = trailingslashit( get_template_directory_uri() ) . $templates_dir . $file; |
|
159 | + $url = trailingslashit(get_template_directory_uri()).$templates_dir.$file; |
|
160 | 160 | } |
161 | - } elseif ( file_exists( $give_plugin_style_sheet ) || file_exists( $give_plugin_style_sheet ) ) { |
|
162 | - $url = trailingslashit( give_get_templates_url() ) . $file; |
|
161 | + } elseif (file_exists($give_plugin_style_sheet) || file_exists($give_plugin_style_sheet)) { |
|
162 | + $url = trailingslashit(give_get_templates_url()).$file; |
|
163 | 163 | } |
164 | 164 | |
165 | - wp_register_style( 'give-styles', $url, array(), GIVE_VERSION, 'all' ); |
|
166 | - wp_enqueue_style( 'give-styles' ); |
|
165 | + wp_register_style('give-styles', $url, array(), GIVE_VERSION, 'all'); |
|
166 | + wp_enqueue_style('give-styles'); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | -add_action( 'wp_enqueue_scripts', 'give_register_styles' ); |
|
170 | +add_action('wp_enqueue_scripts', 'give_register_styles'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Load Admin Scripts |
@@ -181,107 +181,107 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return void |
183 | 183 | */ |
184 | -function give_load_admin_scripts( $hook ) { |
|
184 | +function give_load_admin_scripts($hook) { |
|
185 | 185 | |
186 | 186 | global $wp_version, $post, $post_type; |
187 | 187 | |
188 | 188 | //Directories of assets |
189 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
190 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
191 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
189 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
190 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
191 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
192 | 192 | |
193 | 193 | // Use minified libraries if SCRIPT_DEBUG is turned off |
194 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
194 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
195 | 195 | |
196 | 196 | //Global Admin: |
197 | - wp_register_style( 'give-admin-bar-notification', $css_dir . 'adminbar-style.css' ); |
|
198 | - wp_enqueue_style( 'give-admin-bar-notification' ); |
|
197 | + wp_register_style('give-admin-bar-notification', $css_dir.'adminbar-style.css'); |
|
198 | + wp_enqueue_style('give-admin-bar-notification'); |
|
199 | 199 | |
200 | 200 | //Give Admin Only: |
201 | - if ( ! apply_filters( 'give_load_admin_scripts', give_is_admin_page(), $hook ) ) { |
|
201 | + if ( ! apply_filters('give_load_admin_scripts', give_is_admin_page(), $hook)) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | //CSS |
206 | - wp_register_style( 'jquery-ui-css', $css_dir . 'jquery-ui-fresh' . $suffix . '.css' ); |
|
207 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
208 | - wp_register_style( 'give-admin', $css_dir . 'give-admin' . $suffix . '.css', GIVE_VERSION ); |
|
209 | - wp_enqueue_style( 'give-admin' ); |
|
210 | - wp_register_style( 'jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), GIVE_VERSION ); |
|
211 | - wp_enqueue_style( 'jquery-chosen' ); |
|
212 | - wp_enqueue_style( 'thickbox' ); |
|
206 | + wp_register_style('jquery-ui-css', $css_dir.'jquery-ui-fresh'.$suffix.'.css'); |
|
207 | + wp_enqueue_style('jquery-ui-css'); |
|
208 | + wp_register_style('give-admin', $css_dir.'give-admin'.$suffix.'.css', GIVE_VERSION); |
|
209 | + wp_enqueue_style('give-admin'); |
|
210 | + wp_register_style('jquery-chosen', $css_dir.'chosen'.$suffix.'.css', array(), GIVE_VERSION); |
|
211 | + wp_enqueue_style('jquery-chosen'); |
|
212 | + wp_enqueue_style('thickbox'); |
|
213 | 213 | |
214 | 214 | //JS |
215 | - wp_register_script( 'jquery-chosen', $js_plugins . 'chosen.jquery' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
216 | - wp_enqueue_script( 'jquery-chosen' ); |
|
215 | + wp_register_script('jquery-chosen', $js_plugins.'chosen.jquery'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
216 | + wp_enqueue_script('jquery-chosen'); |
|
217 | 217 | |
218 | - wp_register_script( 'give-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
219 | - wp_enqueue_script( 'give-admin-scripts' ); |
|
218 | + wp_register_script('give-admin-scripts', $js_dir.'admin-scripts'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
219 | + wp_enqueue_script('give-admin-scripts'); |
|
220 | 220 | |
221 | - wp_register_script( 'jquery-flot', $js_plugins . 'jquery.flot' . $suffix . '.js' ); |
|
222 | - wp_enqueue_script( 'jquery-flot' ); |
|
221 | + wp_register_script('jquery-flot', $js_plugins.'jquery.flot'.$suffix.'.js'); |
|
222 | + wp_enqueue_script('jquery-flot'); |
|
223 | 223 | |
224 | - wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
225 | - wp_enqueue_script( 'give-qtip' ); |
|
224 | + wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
225 | + wp_enqueue_script('give-qtip'); |
|
226 | 226 | |
227 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
228 | - wp_enqueue_script( 'thickbox' ); |
|
227 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
228 | + wp_enqueue_script('thickbox'); |
|
229 | 229 | |
230 | 230 | //Forms CPT Script |
231 | - if ( $post_type === 'give_forms' ) { |
|
232 | - wp_register_script( 'give-admin-forms-scripts', $js_dir . 'admin-forms' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
233 | - wp_enqueue_script( 'give-admin-forms-scripts' ); |
|
231 | + if ($post_type === 'give_forms') { |
|
232 | + wp_register_script('give-admin-forms-scripts', $js_dir.'admin-forms'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
233 | + wp_enqueue_script('give-admin-forms-scripts'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | //Settings Scripts |
237 | - if (isset($_GET['page']) && $_GET['page'] == 'give-settings' ) { |
|
237 | + if (isset($_GET['page']) && $_GET['page'] == 'give-settings') { |
|
238 | 238 | wp_enqueue_script('jquery-ui-sortable'); |
239 | - wp_register_script( 'give-admin-settings-scripts', $js_dir . 'admin-settings' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
240 | - wp_enqueue_script( 'give-admin-settings-scripts' ); |
|
239 | + wp_register_script('give-admin-settings-scripts', $js_dir.'admin-settings'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
240 | + wp_enqueue_script('give-admin-settings-scripts'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | //Localize strings & variables for JS |
244 | - wp_localize_script( 'give-admin-scripts', 'give_vars', array( |
|
245 | - 'post_id' => isset( $post->ID ) ? $post->ID : null, |
|
244 | + wp_localize_script('give-admin-scripts', 'give_vars', array( |
|
245 | + 'post_id' => isset($post->ID) ? $post->ID : null, |
|
246 | 246 | 'give_version' => GIVE_VERSION, |
247 | - 'quick_edit_warning' => __( 'Sorry, not available for variable priced forms.', 'give' ), |
|
248 | - 'delete_payment' => __( 'Are you sure you wish to delete this payment?', 'give' ), |
|
249 | - 'delete_payment_note' => __( 'Are you sure you wish to delete this note?', 'give' ), |
|
250 | - 'revoke_api_key' => __( 'Are you sure you wish to revoke this API key?', 'give' ), |
|
251 | - 'regenerate_api_key' => __( 'Are you sure you wish to regenerate this API key?', 'give' ), |
|
252 | - 'resend_receipt' => __( 'Are you sure you wish to resend the donation receipt?', 'give' ), |
|
253 | - 'copy_download_link_text' => __( 'Copy these links to your clipboard and give them to your donor.', 'give' ), |
|
247 | + 'quick_edit_warning' => __('Sorry, not available for variable priced forms.', 'give'), |
|
248 | + 'delete_payment' => __('Are you sure you wish to delete this payment?', 'give'), |
|
249 | + 'delete_payment_note' => __('Are you sure you wish to delete this note?', 'give'), |
|
250 | + 'revoke_api_key' => __('Are you sure you wish to revoke this API key?', 'give'), |
|
251 | + 'regenerate_api_key' => __('Are you sure you wish to regenerate this API key?', 'give'), |
|
252 | + 'resend_receipt' => __('Are you sure you wish to resend the donation receipt?', 'give'), |
|
253 | + 'copy_download_link_text' => __('Copy these links to your clipboard and give them to your donor.', 'give'), |
|
254 | 254 | /* translators: %s: form singular label */ |
255 | - 'delete_payment_download' => sprintf( __( 'Are you sure you wish to delete this %s?', 'give' ), give_get_forms_label_singular() ), |
|
256 | - 'one_price_min' => __( 'You must have at least one price.', 'give' ), |
|
257 | - 'one_file_min' => __( 'You must have at least one file.', 'give' ), |
|
258 | - 'one_field_min' => __( 'You must have at least one field.', 'give' ), |
|
255 | + 'delete_payment_download' => sprintf(__('Are you sure you wish to delete this %s?', 'give'), give_get_forms_label_singular()), |
|
256 | + 'one_price_min' => __('You must have at least one price.', 'give'), |
|
257 | + 'one_file_min' => __('You must have at least one file.', 'give'), |
|
258 | + 'one_field_min' => __('You must have at least one field.', 'give'), |
|
259 | 259 | /* translators: %s: form singular label */ |
260 | - 'one_option' => sprintf( __( 'Choose a %s', 'give' ), give_get_forms_label_singular() ), |
|
260 | + 'one_option' => sprintf(__('Choose a %s', 'give'), give_get_forms_label_singular()), |
|
261 | 261 | /* translators: %s: form plural label */ |
262 | - 'one_or_more_option' => sprintf( __( 'Choose one or more %s', 'give' ), give_get_forms_label_plural() ), |
|
263 | - 'numeric_item_price' => __( 'Item price must be numeric.', 'give' ), |
|
264 | - 'numeric_quantity' => __( 'Quantity must be numeric.', 'give' ), |
|
265 | - 'currency_sign' => give_currency_filter( '' ), |
|
266 | - 'currency_pos' => isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before', |
|
262 | + 'one_or_more_option' => sprintf(__('Choose one or more %s', 'give'), give_get_forms_label_plural()), |
|
263 | + 'numeric_item_price' => __('Item price must be numeric.', 'give'), |
|
264 | + 'numeric_quantity' => __('Quantity must be numeric.', 'give'), |
|
265 | + 'currency_sign' => give_currency_filter(''), |
|
266 | + 'currency_pos' => isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before', |
|
267 | 267 | 'currency_decimals' => give_currency_decimal_filter(), |
268 | - 'new_media_ui' => apply_filters( 'give_use_35_media_ui', 1 ), |
|
269 | - 'remove_text' => __( 'Remove', 'give' ), |
|
268 | + 'new_media_ui' => apply_filters('give_use_35_media_ui', 1), |
|
269 | + 'remove_text' => __('Remove', 'give'), |
|
270 | 270 | /* translators: %s: form plural label */ |
271 | - 'type_to_search' => sprintf( __( 'Type to search %s', 'give' ), give_get_forms_label_plural() ), |
|
272 | - 'batch_export_no_class' => __( 'You must choose a method.', 'give' ), |
|
273 | - 'batch_export_no_reqs' => __( 'Required fields not completed.', 'give' ), |
|
274 | - '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' ), |
|
275 | - ) ); |
|
271 | + 'type_to_search' => sprintf(__('Type to search %s', 'give'), give_get_forms_label_plural()), |
|
272 | + 'batch_export_no_class' => __('You must choose a method.', 'give'), |
|
273 | + 'batch_export_no_reqs' => __('Required fields not completed.', 'give'), |
|
274 | + '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'), |
|
275 | + )); |
|
276 | 276 | |
277 | - if ( function_exists( 'wp_enqueue_media' ) && version_compare( $wp_version, '3.5', '>=' ) ) { |
|
277 | + if (function_exists('wp_enqueue_media') && version_compare($wp_version, '3.5', '>=')) { |
|
278 | 278 | //call for new media manager |
279 | 279 | wp_enqueue_media(); |
280 | 280 | } |
281 | 281 | |
282 | 282 | } |
283 | 283 | |
284 | -add_action( 'admin_enqueue_scripts', 'give_load_admin_scripts', 100 ); |
|
284 | +add_action('admin_enqueue_scripts', 'give_load_admin_scripts', 100); |
|
285 | 285 | |
286 | 286 | /** |
287 | 287 | * Admin Give Icon |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | ?> |
299 | 299 | <style type="text/css" media="screen"> |
300 | 300 | |
301 | - <?php if( version_compare( $wp_version, '3.8-RC', '>=' ) || version_compare( $wp_version, '3.8', '>=' ) ) { ?> |
|
301 | + <?php if (version_compare($wp_version, '3.8-RC', '>=') || version_compare($wp_version, '3.8', '>=')) { ?> |
|
302 | 302 | @font-face { |
303 | 303 | font-family: 'give-icomoon'; |
304 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
305 | - src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
306 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
307 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
308 | - url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
304 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?-ngjl88'; ?>'); |
|
305 | + src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'), |
|
306 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'), |
|
307 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'), |
|
308 | + url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg'); |
|
309 | 309 | font-weight: normal; |
310 | 310 | font-style: normal; |
311 | 311 | } |
@@ -324,4 +324,4 @@ discard block |
||
324 | 324 | <?php |
325 | 325 | } |
326 | 326 | |
327 | -add_action( 'admin_head', 'give_admin_icon' ); |
|
327 | +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 | |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool|object List of all user purchases |
32 | 32 | */ |
33 | -function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
33 | +function give_get_users_purchases($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
34 | 34 | |
35 | - if ( empty( $user ) ) { |
|
35 | + if (empty($user)) { |
|
36 | 36 | $user = get_current_user_id(); |
37 | 37 | } |
38 | 38 | |
39 | - if ( 0 === $user && ! Give()->email_access->token_exists ) { |
|
39 | + if (0 === $user && ! Give()->email_access->token_exists) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $status = $status === 'complete' ? 'publish' : $status; |
44 | 44 | |
45 | - if ( $pagination ) { |
|
46 | - if ( get_query_var( 'paged' ) ) { |
|
47 | - $paged = get_query_var( 'paged' ); |
|
48 | - } else if ( get_query_var( 'page' ) ) { |
|
49 | - $paged = get_query_var( 'page' ); |
|
45 | + if ($pagination) { |
|
46 | + if (get_query_var('paged')) { |
|
47 | + $paged = get_query_var('paged'); |
|
48 | + } else if (get_query_var('page')) { |
|
49 | + $paged = get_query_var('page'); |
|
50 | 50 | } else { |
51 | 51 | $paged = 1; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - $args = apply_filters( 'give_get_users_purchases_args', array( |
|
55 | + $args = apply_filters('give_get_users_purchases_args', array( |
|
56 | 56 | 'user' => $user, |
57 | 57 | 'number' => $number, |
58 | 58 | 'status' => $status, |
59 | 59 | 'orderby' => 'date' |
60 | - ) ); |
|
60 | + )); |
|
61 | 61 | |
62 | - if ( $pagination ) { |
|
62 | + if ($pagination) { |
|
63 | 63 | |
64 | 64 | $args['page'] = $paged; |
65 | 65 | |
@@ -69,20 +69,20 @@ discard block |
||
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
73 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
72 | + $by_user_id = is_numeric($user) ? true : false; |
|
73 | + $customer = new Give_Customer($user, $by_user_id); |
|
74 | 74 | |
75 | - if ( ! empty( $customer->payment_ids ) ) { |
|
75 | + if ( ! empty($customer->payment_ids)) { |
|
76 | 76 | |
77 | - unset( $args['user'] ); |
|
78 | - $args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) ); |
|
77 | + unset($args['user']); |
|
78 | + $args['post__in'] = array_map('absint', explode(',', $customer->payment_ids)); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - $purchases = give_get_payments( apply_filters( 'give_get_users_purchases_args', $args ) ); |
|
82 | + $purchases = give_get_payments(apply_filters('give_get_users_purchases_args', $args)); |
|
83 | 83 | |
84 | 84 | // No purchases |
85 | - if ( ! $purchases ) { |
|
85 | + if ( ! $purchases) { |
|
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
@@ -101,65 +101,65 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return bool|object List of unique forms purchased by user |
103 | 103 | */ |
104 | -function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
|
105 | - if ( empty( $user ) ) { |
|
104 | +function give_get_users_completed_donations($user = 0, $status = 'complete') { |
|
105 | + if (empty($user)) { |
|
106 | 106 | $user = get_current_user_id(); |
107 | 107 | } |
108 | 108 | |
109 | - if ( empty( $user ) ) { |
|
109 | + if (empty($user)) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
113 | + $by_user_id = is_numeric($user) ? true : false; |
|
114 | 114 | |
115 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
115 | + $customer = new Give_Customer($user, $by_user_id); |
|
116 | 116 | |
117 | - if ( empty( $customer->payment_ids ) ) { |
|
117 | + if (empty($customer->payment_ids)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Get all the items purchased |
122 | - $payment_ids = array_reverse( explode( ',', $customer->payment_ids ) ); |
|
123 | - $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
|
124 | - if ( ! empty( $limit_payments ) ) { |
|
125 | - $payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
|
122 | + $payment_ids = array_reverse(explode(',', $customer->payment_ids)); |
|
123 | + $limit_payments = apply_filters('give_users_completed_donations_payments', 50); |
|
124 | + if ( ! empty($limit_payments)) { |
|
125 | + $payment_ids = array_slice($payment_ids, 0, $limit_payments); |
|
126 | 126 | } |
127 | 127 | $donation_data = array(); |
128 | - foreach ( $payment_ids as $payment_id ) { |
|
129 | - $donation_data[] = give_get_payment_meta( $payment_id ); |
|
128 | + foreach ($payment_ids as $payment_id) { |
|
129 | + $donation_data[] = give_get_payment_meta($payment_id); |
|
130 | 130 | } |
131 | 131 | |
132 | - if ( empty( $donation_data ) ) { |
|
132 | + if (empty($donation_data)) { |
|
133 | 133 | return false; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Grab only the post ids "form_id" of the forms purchased on this order |
137 | 137 | $completed_donations_ids = array(); |
138 | - foreach ( $donation_data as $purchase_meta ) { |
|
138 | + foreach ($donation_data as $purchase_meta) { |
|
139 | 139 | $completed_donations_ids[] = isset($purchase_meta['form_id']) ? $purchase_meta['form_id'] : ''; |
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $completed_donations_ids ) ) { |
|
142 | + if (empty($completed_donations_ids)) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Only include each product purchased once |
147 | - $form_ids = array_unique( $completed_donations_ids ); |
|
147 | + $form_ids = array_unique($completed_donations_ids); |
|
148 | 148 | |
149 | 149 | // Make sure we still have some products and a first item |
150 | - if ( empty ( $form_ids ) || ! isset( $form_ids[0] ) ) { |
|
150 | + if (empty ($form_ids) || ! isset($form_ids[0])) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | - $post_type = get_post_type( $form_ids[0] ); |
|
154 | + $post_type = get_post_type($form_ids[0]); |
|
155 | 155 | |
156 | - $args = apply_filters( 'give_get_users_completed_donations_args', array( |
|
156 | + $args = apply_filters('give_get_users_completed_donations_args', array( |
|
157 | 157 | 'include' => $form_ids, |
158 | 158 | 'post_type' => $post_type, |
159 | - 'posts_per_page' => - 1 |
|
160 | - ) ); |
|
159 | + 'posts_per_page' => -1 |
|
160 | + )); |
|
161 | 161 | |
162 | - return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
|
162 | + return apply_filters('give_users_completed_donations_list', get_posts($args)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return bool - true if has purchased, false other wise. |
177 | 177 | */ |
178 | -function give_has_purchases( $user_id = null ) { |
|
179 | - if ( empty( $user_id ) ) { |
|
178 | +function give_has_purchases($user_id = null) { |
|
179 | + if (empty($user_id)) { |
|
180 | 180 | $user_id = get_current_user_id(); |
181 | 181 | } |
182 | 182 | |
183 | - if ( give_get_users_purchases( $user_id, 1 ) ) { |
|
183 | + if (give_get_users_purchases($user_id, 1)) { |
|
184 | 184 | return true; // User has at least one purchase |
185 | 185 | } |
186 | 186 | |
@@ -200,32 +200,32 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return array |
202 | 202 | */ |
203 | -function give_get_purchase_stats_by_user( $user = '' ) { |
|
203 | +function give_get_purchase_stats_by_user($user = '') { |
|
204 | 204 | |
205 | - if ( is_email( $user ) ) { |
|
205 | + if (is_email($user)) { |
|
206 | 206 | |
207 | 207 | $field = 'email'; |
208 | 208 | |
209 | - } elseif ( is_numeric( $user ) ) { |
|
209 | + } elseif (is_numeric($user)) { |
|
210 | 210 | |
211 | 211 | $field = 'user_id'; |
212 | 212 | |
213 | 213 | } |
214 | 214 | |
215 | 215 | $stats = array(); |
216 | - $customer = Give()->customers->get_customer_by( $field, $user ); |
|
216 | + $customer = Give()->customers->get_customer_by($field, $user); |
|
217 | 217 | |
218 | - if ( $customer ) { |
|
218 | + if ($customer) { |
|
219 | 219 | |
220 | - $customer = new Give_Customer( $customer->id ); |
|
220 | + $customer = new Give_Customer($customer->id); |
|
221 | 221 | |
222 | - $stats['purchases'] = absint( $customer->purchase_count ); |
|
223 | - $stats['total_spent'] = give_sanitize_amount( $customer->purchase_value ); |
|
222 | + $stats['purchases'] = absint($customer->purchase_count); |
|
223 | + $stats['total_spent'] = give_sanitize_amount($customer->purchase_value); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
227 | 227 | |
228 | - return (array) apply_filters( 'give_purchase_stats_by_user', $stats, $user ); |
|
228 | + return (array) apply_filters('give_purchase_stats_by_user', $stats, $user); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -241,22 +241,22 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return int - the total number of purchases |
243 | 243 | */ |
244 | -function give_count_purchases_of_customer( $user = null ) { |
|
244 | +function give_count_purchases_of_customer($user = null) { |
|
245 | 245 | |
246 | 246 | //Logged in? |
247 | - if ( empty( $user ) ) { |
|
247 | + if (empty($user)) { |
|
248 | 248 | $user = get_current_user_id(); |
249 | 249 | } |
250 | 250 | |
251 | 251 | //Email access? |
252 | - if ( empty( $user ) && Give()->email_access->token_email ) { |
|
252 | + if (empty($user) && Give()->email_access->token_email) { |
|
253 | 253 | $user = Give()->email_access->token_email; |
254 | 254 | } |
255 | 255 | |
256 | 256 | |
257 | - $stats = ! empty( $user ) ? give_get_purchase_stats_by_user( $user ) : false; |
|
257 | + $stats = ! empty($user) ? give_get_purchase_stats_by_user($user) : false; |
|
258 | 258 | |
259 | - return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
|
259 | + return isset($stats['purchases']) ? $stats['purchases'] : 0; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return float - the total amount the user has spent |
271 | 271 | */ |
272 | -function give_purchase_total_of_user( $user = null ) { |
|
272 | +function give_purchase_total_of_user($user = null) { |
|
273 | 273 | |
274 | - $stats = give_get_purchase_stats_by_user( $user ); |
|
274 | + $stats = give_get_purchase_stats_by_user($user); |
|
275 | 275 | |
276 | 276 | return $stats['total_spent']; |
277 | 277 | } |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return bool |
289 | 289 | */ |
290 | -function give_validate_username( $username ) { |
|
291 | - $sanitized = sanitize_user( $username, false ); |
|
292 | - $valid = ( $sanitized == $username ); |
|
290 | +function give_validate_username($username) { |
|
291 | + $sanitized = sanitize_user($username, false); |
|
292 | + $valid = ($sanitized == $username); |
|
293 | 293 | |
294 | - return (bool) apply_filters( 'give_validate_username', $valid, $username ); |
|
294 | + return (bool) apply_filters('give_validate_username', $valid, $username); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | |
@@ -308,32 +308,32 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return void |
310 | 310 | */ |
311 | -function give_add_past_purchases_to_new_user( $user_id ) { |
|
311 | +function give_add_past_purchases_to_new_user($user_id) { |
|
312 | 312 | |
313 | - $email = get_the_author_meta( 'user_email', $user_id ); |
|
313 | + $email = get_the_author_meta('user_email', $user_id); |
|
314 | 314 | |
315 | - $payments = give_get_payments( array( 's' => $email ) ); |
|
315 | + $payments = give_get_payments(array('s' => $email)); |
|
316 | 316 | |
317 | - if ( $payments ) { |
|
318 | - foreach ( $payments as $payment ) { |
|
319 | - if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) { |
|
317 | + if ($payments) { |
|
318 | + foreach ($payments as $payment) { |
|
319 | + if (intval(give_get_payment_user_id($payment->ID)) > 0) { |
|
320 | 320 | continue; |
321 | 321 | } // This payment already associated with an account |
322 | 322 | |
323 | - $meta = give_get_payment_meta( $payment->ID ); |
|
324 | - $meta['user_info'] = maybe_unserialize( $meta['user_info'] ); |
|
323 | + $meta = give_get_payment_meta($payment->ID); |
|
324 | + $meta['user_info'] = maybe_unserialize($meta['user_info']); |
|
325 | 325 | $meta['user_info']['id'] = $user_id; |
326 | 326 | $meta['user_info'] = $meta['user_info']; |
327 | 327 | |
328 | 328 | // Store the updated user ID in the payment meta |
329 | - give_update_payment_meta( $payment->ID, '_give_payment_meta', $meta ); |
|
330 | - give_update_payment_meta( $payment->ID, '_give_payment_user_id', $user_id ); |
|
329 | + give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); |
|
330 | + give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
334 | 334 | } |
335 | 335 | |
336 | -add_action( 'user_register', 'give_add_past_purchases_to_new_user' ); |
|
336 | +add_action('user_register', 'give_add_past_purchases_to_new_user'); |
|
337 | 337 | |
338 | 338 | |
339 | 339 | /** |
@@ -355,34 +355,34 @@ discard block |
||
355 | 355 | * @since 1.0 |
356 | 356 | * @return array - The donor's address, if any |
357 | 357 | */ |
358 | -function give_get_donor_address( $user_id = 0 ) { |
|
359 | - if ( empty( $user_id ) ) { |
|
358 | +function give_get_donor_address($user_id = 0) { |
|
359 | + if (empty($user_id)) { |
|
360 | 360 | $user_id = get_current_user_id(); |
361 | 361 | } |
362 | 362 | |
363 | - $address = get_user_meta( $user_id, '_give_user_address', true ); |
|
363 | + $address = get_user_meta($user_id, '_give_user_address', true); |
|
364 | 364 | |
365 | - if ( ! isset( $address['line1'] ) ) { |
|
365 | + if ( ! isset($address['line1'])) { |
|
366 | 366 | $address['line1'] = ''; |
367 | 367 | } |
368 | 368 | |
369 | - if ( ! isset( $address['line2'] ) ) { |
|
369 | + if ( ! isset($address['line2'])) { |
|
370 | 370 | $address['line2'] = ''; |
371 | 371 | } |
372 | 372 | |
373 | - if ( ! isset( $address['city'] ) ) { |
|
373 | + if ( ! isset($address['city'])) { |
|
374 | 374 | $address['city'] = ''; |
375 | 375 | } |
376 | 376 | |
377 | - if ( ! isset( $address['zip'] ) ) { |
|
377 | + if ( ! isset($address['zip'])) { |
|
378 | 378 | $address['zip'] = ''; |
379 | 379 | } |
380 | 380 | |
381 | - if ( ! isset( $address['country'] ) ) { |
|
381 | + if ( ! isset($address['country'])) { |
|
382 | 382 | $address['country'] = ''; |
383 | 383 | } |
384 | 384 | |
385 | - if ( ! isset( $address['state'] ) ) { |
|
385 | + if ( ! isset($address['state'])) { |
|
386 | 386 | $address['state'] = ''; |
387 | 387 | } |
388 | 388 | |
@@ -402,42 +402,42 @@ discard block |
||
402 | 402 | * |
403 | 403 | * @return void |
404 | 404 | */ |
405 | -function give_new_user_notification( $user_id = 0, $user_data = array() ) { |
|
405 | +function give_new_user_notification($user_id = 0, $user_data = array()) { |
|
406 | 406 | |
407 | - if ( empty( $user_id ) || empty( $user_data ) ) { |
|
407 | + if (empty($user_id) || empty($user_data)) { |
|
408 | 408 | return; |
409 | 409 | } |
410 | - $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
410 | + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
411 | 411 | |
412 | 412 | /* translators: %s: site name */ |
413 | - $message = sprintf( esc_attr__( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; |
|
413 | + $message = sprintf(esc_attr__('New user registration on your site %s:'), $blogname)."\r\n\r\n"; |
|
414 | 414 | /* translators: %s: user login */ |
415 | - $message .= sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n\r\n"; |
|
415 | + $message .= sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n\r\n"; |
|
416 | 416 | /* translators: %s: user email */ |
417 | - $message .= sprintf( esc_attr__( 'E-mail: %s' ), $user_data['user_email'] ) . "\r\n"; |
|
417 | + $message .= sprintf(esc_attr__('E-mail: %s'), $user_data['user_email'])."\r\n"; |
|
418 | 418 | |
419 | 419 | @wp_mail( |
420 | - get_option( 'admin_email' ), |
|
420 | + get_option('admin_email'), |
|
421 | 421 | sprintf( |
422 | 422 | /* translators: %s: site name */ |
423 | - esc_attr__( '[%s] New User Registration' ), |
|
423 | + esc_attr__('[%s] New User Registration'), |
|
424 | 424 | $blogname |
425 | 425 | ), |
426 | 426 | $message |
427 | 427 | ); |
428 | 428 | |
429 | 429 | /* translators: %s: user login */ |
430 | - $message = sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n"; |
|
430 | + $message = sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n"; |
|
431 | 431 | /* translators: %s: paswword */ |
432 | - $message .= sprintf( esc_attr__( 'Password: %s' ), esc_attr__( '[Password entered during donation]', 'give' ) ) . "\r\n"; |
|
432 | + $message .= sprintf(esc_attr__('Password: %s'), esc_attr__('[Password entered during donation]', 'give'))."\r\n"; |
|
433 | 433 | |
434 | - $message .= '<a href="' . wp_login_url() . '"> ' . esc_attr__( 'Click Here to Login', 'give' ) . ' »</a>' . "\r\n"; |
|
434 | + $message .= '<a href="'.wp_login_url().'"> '.esc_attr__('Click Here to Login', 'give').' »</a>'."\r\n"; |
|
435 | 435 | |
436 | 436 | wp_mail( |
437 | 437 | $user_data['user_email'], |
438 | 438 | sprintf( |
439 | 439 | /* translators: %s: site name */ |
440 | - esc_attr__( '[%s] Your username and password' ), |
|
440 | + esc_attr__('[%s] Your username and password'), |
|
441 | 441 | $blogname |
442 | 442 | ), |
443 | 443 | $message |
@@ -445,4 +445,4 @@ discard block |
||
445 | 445 | |
446 | 446 | } |
447 | 447 | |
448 | -add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); |
|
448 | +add_action('give_insert_user', 'give_new_user_notification', 10, 2); |
@@ -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 | |
@@ -139,27 +139,27 @@ discard block |
||
139 | 139 | 'v1' => 'GIVE_API_V1', |
140 | 140 | ); |
141 | 141 | |
142 | - foreach ( $this->get_versions() as $version => $class ) { |
|
143 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
142 | + foreach ($this->get_versions() as $version => $class) { |
|
143 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
144 | 144 | } |
145 | 145 | |
146 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
147 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
148 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
149 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
150 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
152 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
146 | + add_action('init', array($this, 'add_endpoint')); |
|
147 | + add_action('wp', array($this, 'process_query'), - 1); |
|
148 | + add_filter('query_vars', array($this, 'query_vars')); |
|
149 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
150 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('personal_options_update', array($this, 'update_key')); |
|
152 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
153 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
154 | 154 | |
155 | 155 | // Setup a backwards compatibility check for user API Keys |
156 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
156 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
157 | 157 | |
158 | 158 | // Determine if JSON_PRETTY_PRINT is available |
159 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
159 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
160 | 160 | |
161 | 161 | // Allow API request logging to be turned off |
162 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
162 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
163 | 163 | |
164 | 164 | // Setup Give_Payment_Stats instance |
165 | 165 | $this->stats = new Give_Payment_Stats; |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @since 1.1 |
177 | 177 | */ |
178 | - public function add_endpoint( $rewrite_rules ) { |
|
179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
178 | + public function add_endpoint($rewrite_rules) { |
|
179 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return string[] $vars New query vars |
191 | 191 | */ |
192 | - public function query_vars( $vars ) { |
|
192 | + public function query_vars($vars) { |
|
193 | 193 | |
194 | 194 | $vars[] = 'token'; |
195 | 195 | $vars[] = 'key'; |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function get_default_version() { |
242 | 242 | |
243 | - $version = get_option( 'give_default_api_version' ); |
|
243 | + $version = get_option('give_default_api_version'); |
|
244 | 244 | |
245 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
245 | + if (defined('GIVE_API_VERSION')) { |
|
246 | 246 | $version = GIVE_API_VERSION; |
247 | - } elseif ( ! $version ) { |
|
247 | + } elseif ( ! $version) { |
|
248 | 248 | $version = 'v1'; |
249 | 249 | } |
250 | 250 | |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | |
266 | 266 | $version = $wp_query->query_vars['give-api']; |
267 | 267 | |
268 | - if ( strpos( $version, '/' ) ) { |
|
268 | + if (strpos($version, '/')) { |
|
269 | 269 | |
270 | - $version = explode( '/', $version ); |
|
271 | - $version = strtolower( $version[0] ); |
|
270 | + $version = explode('/', $version); |
|
271 | + $version = strtolower($version[0]); |
|
272 | 272 | |
273 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
273 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
274 | 274 | |
275 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
275 | + if (array_key_exists($version, $this->versions)) { |
|
276 | 276 | |
277 | 277 | $this->queried_version = $version; |
278 | 278 | |
@@ -309,32 +309,32 @@ discard block |
||
309 | 309 | $this->override = false; |
310 | 310 | |
311 | 311 | // Make sure we have both user and api key |
312 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
312 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
313 | 313 | |
314 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
314 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
315 | 315 | $this->missing_auth(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Retrieve the user by public API key and ensure they exist |
319 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
319 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
320 | 320 | |
321 | 321 | $this->invalid_key(); |
322 | 322 | |
323 | 323 | } else { |
324 | 324 | |
325 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
326 | - $secret = $this->get_user_secret_key( $user ); |
|
327 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
325 | + $token = urldecode($wp_query->query_vars['token']); |
|
326 | + $secret = $this->get_user_secret_key($user); |
|
327 | + $public = urldecode($wp_query->query_vars['key']); |
|
328 | 328 | |
329 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
329 | + if (hash_equals(md5($secret.$public), $token)) { |
|
330 | 330 | $this->is_valid_request = true; |
331 | 331 | } else { |
332 | 332 | $this->invalid_auth(); |
333 | 333 | } |
334 | 334 | } |
335 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
335 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
336 | 336 | $this->is_valid_request = true; |
337 | - $wp_query->set( 'key', 'public' ); |
|
337 | + $wp_query->set('key', 'public'); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
@@ -350,25 +350,25 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return bool if user ID is found, false otherwise |
352 | 352 | */ |
353 | - public function get_user( $key = '' ) { |
|
353 | + public function get_user($key = '') { |
|
354 | 354 | global $wpdb, $wp_query; |
355 | 355 | |
356 | - if ( empty( $key ) ) { |
|
357 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
356 | + if (empty($key)) { |
|
357 | + $key = urldecode($wp_query->query_vars['key']); |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( empty( $key ) ) { |
|
360 | + if (empty($key)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
364 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
364 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
365 | 365 | |
366 | - if ( false === $user ) { |
|
367 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
368 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
366 | + if (false === $user) { |
|
367 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
368 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $user != null ) { |
|
371 | + if ($user != null) { |
|
372 | 372 | $this->user_id = $user; |
373 | 373 | |
374 | 374 | return $user; |
@@ -377,37 +377,37 @@ discard block |
||
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | |
380 | - public function get_user_public_key( $user_id = 0 ) { |
|
380 | + public function get_user_public_key($user_id = 0) { |
|
381 | 381 | global $wpdb; |
382 | 382 | |
383 | - if ( empty( $user_id ) ) { |
|
383 | + if (empty($user_id)) { |
|
384 | 384 | return ''; |
385 | 385 | } |
386 | 386 | |
387 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
388 | - $user_public_key = get_transient( $cache_key ); |
|
387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
388 | + $user_public_key = get_transient($cache_key); |
|
389 | 389 | |
390 | - if ( empty( $user_public_key ) ) { |
|
391 | - $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 ) ); |
|
392 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
390 | + if (empty($user_public_key)) { |
|
391 | + $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)); |
|
392 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | return $user_public_key; |
396 | 396 | } |
397 | 397 | |
398 | - public function get_user_secret_key( $user_id = 0 ) { |
|
398 | + public function get_user_secret_key($user_id = 0) { |
|
399 | 399 | global $wpdb; |
400 | 400 | |
401 | - if ( empty( $user_id ) ) { |
|
401 | + if (empty($user_id)) { |
|
402 | 402 | return ''; |
403 | 403 | } |
404 | 404 | |
405 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
406 | - $user_secret_key = get_transient( $cache_key ); |
|
405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
406 | + $user_secret_key = get_transient($cache_key); |
|
407 | 407 | |
408 | - if ( empty( $user_secret_key ) ) { |
|
409 | - $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 ) ); |
|
410 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
408 | + if (empty($user_secret_key)) { |
|
409 | + $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)); |
|
410 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | */ |
424 | 424 | private function missing_auth() { |
425 | 425 | $error = array(); |
426 | - $error['error'] = esc_attr__( 'You must specify both a token and API key!', 'give' ); |
|
426 | + $error['error'] = esc_attr__('You must specify both a token and API key!', 'give'); |
|
427 | 427 | |
428 | 428 | $this->data = $error; |
429 | - $this->output( 401 ); |
|
429 | + $this->output(401); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | */ |
441 | 441 | private function invalid_auth() { |
442 | 442 | $error = array(); |
443 | - $error['error'] = esc_attr__( 'Your request could not be authenticated!', 'give' ); |
|
443 | + $error['error'] = esc_attr__('Your request could not be authenticated!', 'give'); |
|
444 | 444 | |
445 | 445 | $this->data = $error; |
446 | - $this->output( 403 ); |
|
446 | + $this->output(403); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function invalid_key() { |
459 | 459 | $error = array(); |
460 | - $error['error'] = esc_attr__( 'Invalid API key!', 'give' ); |
|
460 | + $error['error'] = esc_attr__('Invalid API key!', 'give'); |
|
461 | 461 | |
462 | 462 | $this->data = $error; |
463 | - $this->output( 403 ); |
|
463 | + $this->output(403); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | */ |
474 | 474 | private function invalid_version() { |
475 | 475 | $error = array(); |
476 | - $error['error'] = esc_attr__( 'Invalid API version!', 'give' ); |
|
476 | + $error['error'] = esc_attr__('Invalid API version!', 'give'); |
|
477 | 477 | |
478 | 478 | $this->data = $error; |
479 | - $this->output( 404 ); |
|
479 | + $this->output(404); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | global $wp_query; |
493 | 493 | |
494 | 494 | // Start logging how long the request takes for logging |
495 | - $before = microtime( true ); |
|
495 | + $before = microtime(true); |
|
496 | 496 | |
497 | 497 | // Check for give-api var. Get out if not present |
498 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
498 | + if (empty($wp_query->query_vars['give-api'])) { |
|
499 | 499 | return; |
500 | 500 | } |
501 | 501 | |
@@ -509,45 +509,45 @@ discard block |
||
509 | 509 | $this->validate_request(); |
510 | 510 | |
511 | 511 | // Only proceed if no errors have been noted |
512 | - if ( ! $this->is_valid_request ) { |
|
512 | + if ( ! $this->is_valid_request) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
517 | - define( 'GIVE_DOING_API', true ); |
|
516 | + if ( ! defined('GIVE_DOING_API')) { |
|
517 | + define('GIVE_DOING_API', true); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | $data = array(); |
521 | 521 | $this->routes = new $this->versions[$this->get_queried_version()]; |
522 | 522 | $this->routes->validate_request(); |
523 | 523 | |
524 | - switch ( $this->endpoint ) : |
|
524 | + switch ($this->endpoint) : |
|
525 | 525 | |
526 | 526 | case 'stats' : |
527 | 527 | |
528 | - $data = $this->routes->get_stats( array( |
|
529 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
530 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
531 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
532 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
533 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
534 | - ) ); |
|
528 | + $data = $this->routes->get_stats(array( |
|
529 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
530 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
531 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
532 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
533 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
534 | + )); |
|
535 | 535 | |
536 | 536 | break; |
537 | 537 | |
538 | 538 | case 'forms' : |
539 | 539 | |
540 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
540 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
541 | 541 | |
542 | - $data = $this->routes->get_forms( $form ); |
|
542 | + $data = $this->routes->get_forms($form); |
|
543 | 543 | |
544 | 544 | break; |
545 | 545 | |
546 | 546 | case 'donors' : |
547 | 547 | |
548 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
548 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
549 | 549 | |
550 | - $data = $this->routes->get_customers( $customer ); |
|
550 | + $data = $this->routes->get_customers($customer); |
|
551 | 551 | |
552 | 552 | break; |
553 | 553 | |
@@ -560,14 +560,14 @@ discard block |
||
560 | 560 | endswitch; |
561 | 561 | |
562 | 562 | // Allow extensions to setup their own return data |
563 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
563 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
564 | 564 | |
565 | - $after = microtime( true ); |
|
566 | - $request_time = ( $after - $before ); |
|
565 | + $after = microtime(true); |
|
566 | + $request_time = ($after - $before); |
|
567 | 567 | $this->data['request_speed'] = $request_time; |
568 | 568 | |
569 | 569 | // Log this API request, if enabled. We log it here because we have access to errors. |
570 | - $this->log_request( $this->data ); |
|
570 | + $this->log_request($this->data); |
|
571 | 571 | |
572 | 572 | // Send out data to the output function |
573 | 573 | $this->output(); |
@@ -597,25 +597,25 @@ discard block |
||
597 | 597 | global $wp_query; |
598 | 598 | |
599 | 599 | // Whitelist our query options |
600 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
600 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
601 | 601 | 'stats', |
602 | 602 | 'forms', |
603 | 603 | 'donors', |
604 | 604 | 'donations' |
605 | - ) ); |
|
605 | + )); |
|
606 | 606 | |
607 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
608 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
607 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
608 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
609 | 609 | |
610 | 610 | $error = array(); |
611 | 611 | |
612 | 612 | // Make sure our query is valid |
613 | - if ( ! in_array( $query, $accepted ) ) { |
|
614 | - $error['error'] = __( 'Invalid query!', 'give' ); |
|
613 | + if ( ! in_array($query, $accepted)) { |
|
614 | + $error['error'] = __('Invalid query!', 'give'); |
|
615 | 615 | |
616 | 616 | $this->data = $error; |
617 | 617 | // 400 is Bad Request |
618 | - $this->output( 400 ); |
|
618 | + $this->output(400); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $this->endpoint = $query; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | public function get_paged() { |
633 | 633 | global $wp_query; |
634 | 634 | |
635 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
635 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -647,13 +647,13 @@ discard block |
||
647 | 647 | public function per_page() { |
648 | 648 | global $wp_query; |
649 | 649 | |
650 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
650 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
651 | 651 | |
652 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
652 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
653 | 653 | $per_page = 99999999; |
654 | 654 | } // Customers query doesn't support -1 |
655 | 655 | |
656 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
656 | + return apply_filters('give_api_results_per_page', $per_page); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * |
667 | 667 | * @return array $dates |
668 | 668 | */ |
669 | - public function get_dates( $args = array() ) { |
|
669 | + public function get_dates($args = array()) { |
|
670 | 670 | $dates = array(); |
671 | 671 | |
672 | 672 | $defaults = array( |
@@ -677,60 +677,60 @@ discard block |
||
677 | 677 | 'enddate' => null |
678 | 678 | ); |
679 | 679 | |
680 | - $args = wp_parse_args( $args, $defaults ); |
|
680 | + $args = wp_parse_args($args, $defaults); |
|
681 | 681 | |
682 | - $current_time = current_time( 'timestamp' ); |
|
682 | + $current_time = current_time('timestamp'); |
|
683 | 683 | |
684 | - if ( 'range' === $args['date'] ) { |
|
685 | - $startdate = strtotime( $args['startdate'] ); |
|
686 | - $enddate = strtotime( $args['enddate'] ); |
|
687 | - $dates['day_start'] = date( 'd', $startdate ); |
|
688 | - $dates['day_end'] = date( 'd', $enddate ); |
|
689 | - $dates['m_start'] = date( 'n', $startdate ); |
|
690 | - $dates['m_end'] = date( 'n', $enddate ); |
|
691 | - $dates['year'] = date( 'Y', $startdate ); |
|
692 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
684 | + if ('range' === $args['date']) { |
|
685 | + $startdate = strtotime($args['startdate']); |
|
686 | + $enddate = strtotime($args['enddate']); |
|
687 | + $dates['day_start'] = date('d', $startdate); |
|
688 | + $dates['day_end'] = date('d', $enddate); |
|
689 | + $dates['m_start'] = date('n', $startdate); |
|
690 | + $dates['m_end'] = date('n', $enddate); |
|
691 | + $dates['year'] = date('Y', $startdate); |
|
692 | + $dates['year_end'] = date('Y', $enddate); |
|
693 | 693 | } else { |
694 | 694 | // Modify dates based on predefined ranges |
695 | - switch ( $args['date'] ) : |
|
695 | + switch ($args['date']) : |
|
696 | 696 | |
697 | 697 | case 'this_month' : |
698 | 698 | $dates['day'] = null; |
699 | - $dates['m_start'] = date( 'n', $current_time ); |
|
700 | - $dates['m_end'] = date( 'n', $current_time ); |
|
701 | - $dates['year'] = date( 'Y', $current_time ); |
|
699 | + $dates['m_start'] = date('n', $current_time); |
|
700 | + $dates['m_end'] = date('n', $current_time); |
|
701 | + $dates['year'] = date('Y', $current_time); |
|
702 | 702 | break; |
703 | 703 | |
704 | 704 | case 'last_month' : |
705 | 705 | $dates['day'] = null; |
706 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
706 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
707 | 707 | $dates['m_end'] = $dates['m_start']; |
708 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
708 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
709 | 709 | break; |
710 | 710 | |
711 | 711 | case 'today' : |
712 | - $dates['day'] = date( 'd', $current_time ); |
|
713 | - $dates['m_start'] = date( 'n', $current_time ); |
|
714 | - $dates['m_end'] = date( 'n', $current_time ); |
|
715 | - $dates['year'] = date( 'Y', $current_time ); |
|
712 | + $dates['day'] = date('d', $current_time); |
|
713 | + $dates['m_start'] = date('n', $current_time); |
|
714 | + $dates['m_end'] = date('n', $current_time); |
|
715 | + $dates['year'] = date('Y', $current_time); |
|
716 | 716 | break; |
717 | 717 | |
718 | 718 | case 'yesterday' : |
719 | 719 | |
720 | - $year = date( 'Y', $current_time ); |
|
721 | - $month = date( 'n', $current_time ); |
|
722 | - $day = date( 'd', $current_time ); |
|
720 | + $year = date('Y', $current_time); |
|
721 | + $month = date('n', $current_time); |
|
722 | + $day = date('d', $current_time); |
|
723 | 723 | |
724 | - if ( $month == 1 && $day == 1 ) { |
|
724 | + if ($month == 1 && $day == 1) { |
|
725 | 725 | |
726 | 726 | $year -= 1; |
727 | 727 | $month = 12; |
728 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
728 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
729 | 729 | |
730 | - } elseif ( $month > 1 && $day == 1 ) { |
|
730 | + } elseif ($month > 1 && $day == 1) { |
|
731 | 731 | |
732 | 732 | $month -= 1; |
733 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
733 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
734 | 734 | |
735 | 735 | } else { |
736 | 736 | |
@@ -746,65 +746,65 @@ discard block |
||
746 | 746 | break; |
747 | 747 | |
748 | 748 | case 'this_quarter' : |
749 | - $month_now = date( 'n', $current_time ); |
|
749 | + $month_now = date('n', $current_time); |
|
750 | 750 | |
751 | 751 | $dates['day'] = null; |
752 | 752 | |
753 | - if ( $month_now <= 3 ) { |
|
753 | + if ($month_now <= 3) { |
|
754 | 754 | |
755 | 755 | $dates['m_start'] = 1; |
756 | 756 | $dates['m_end'] = 3; |
757 | - $dates['year'] = date( 'Y', $current_time ); |
|
757 | + $dates['year'] = date('Y', $current_time); |
|
758 | 758 | |
759 | - } else if ( $month_now <= 6 ) { |
|
759 | + } else if ($month_now <= 6) { |
|
760 | 760 | |
761 | 761 | $dates['m_start'] = 4; |
762 | 762 | $dates['m_end'] = 6; |
763 | - $dates['year'] = date( 'Y', $current_time ); |
|
763 | + $dates['year'] = date('Y', $current_time); |
|
764 | 764 | |
765 | - } else if ( $month_now <= 9 ) { |
|
765 | + } else if ($month_now <= 9) { |
|
766 | 766 | |
767 | 767 | $dates['m_start'] = 7; |
768 | 768 | $dates['m_end'] = 9; |
769 | - $dates['year'] = date( 'Y', $current_time ); |
|
769 | + $dates['year'] = date('Y', $current_time); |
|
770 | 770 | |
771 | 771 | } else { |
772 | 772 | |
773 | 773 | $dates['m_start'] = 10; |
774 | 774 | $dates['m_end'] = 12; |
775 | - $dates['year'] = date( 'Y', $current_time ); |
|
775 | + $dates['year'] = date('Y', $current_time); |
|
776 | 776 | |
777 | 777 | } |
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'last_quarter' : |
781 | - $month_now = date( 'n', $current_time ); |
|
781 | + $month_now = date('n', $current_time); |
|
782 | 782 | |
783 | 783 | $dates['day'] = null; |
784 | 784 | |
785 | - if ( $month_now <= 3 ) { |
|
785 | + if ($month_now <= 3) { |
|
786 | 786 | |
787 | 787 | $dates['m_start'] = 10; |
788 | 788 | $dates['m_end'] = 12; |
789 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
789 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
790 | 790 | |
791 | - } else if ( $month_now <= 6 ) { |
|
791 | + } else if ($month_now <= 6) { |
|
792 | 792 | |
793 | 793 | $dates['m_start'] = 1; |
794 | 794 | $dates['m_end'] = 3; |
795 | - $dates['year'] = date( 'Y', $current_time ); |
|
795 | + $dates['year'] = date('Y', $current_time); |
|
796 | 796 | |
797 | - } else if ( $month_now <= 9 ) { |
|
797 | + } else if ($month_now <= 9) { |
|
798 | 798 | |
799 | 799 | $dates['m_start'] = 4; |
800 | 800 | $dates['m_end'] = 6; |
801 | - $dates['year'] = date( 'Y', $current_time ); |
|
801 | + $dates['year'] = date('Y', $current_time); |
|
802 | 802 | |
803 | 803 | } else { |
804 | 804 | |
805 | 805 | $dates['m_start'] = 7; |
806 | 806 | $dates['m_end'] = 9; |
807 | - $dates['year'] = date( 'Y', $current_time ); |
|
807 | + $dates['year'] = date('Y', $current_time); |
|
808 | 808 | |
809 | 809 | } |
810 | 810 | break; |
@@ -813,14 +813,14 @@ discard block |
||
813 | 813 | $dates['day'] = null; |
814 | 814 | $dates['m_start'] = null; |
815 | 815 | $dates['m_end'] = null; |
816 | - $dates['year'] = date( 'Y', $current_time ); |
|
816 | + $dates['year'] = date('Y', $current_time); |
|
817 | 817 | break; |
818 | 818 | |
819 | 819 | case 'last_year' : |
820 | 820 | $dates['day'] = null; |
821 | 821 | $dates['m_start'] = null; |
822 | 822 | $dates['m_end'] = null; |
823 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
823 | + $dates['year'] = date('Y', $current_time) - 1; |
|
824 | 824 | break; |
825 | 825 | |
826 | 826 | endswitch; |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | * @param object $dates The dates used for retreiving earnings/donations |
835 | 835 | */ |
836 | 836 | |
837 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
837 | + return apply_filters('give_api_stat_dates', $dates); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
@@ -849,11 +849,11 @@ discard block |
||
849 | 849 | * |
850 | 850 | * @return array $customers Multidimensional array of the customers |
851 | 851 | */ |
852 | - public function get_customers( $customer = null ) { |
|
852 | + public function get_customers($customer = null) { |
|
853 | 853 | |
854 | 854 | $customers = array(); |
855 | 855 | $error = array(); |
856 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
856 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
857 | 857 | return $customers; |
858 | 858 | } |
859 | 859 | |
@@ -861,64 +861,64 @@ discard block |
||
861 | 861 | |
862 | 862 | $paged = $this->get_paged(); |
863 | 863 | $per_page = $this->per_page(); |
864 | - $offset = $per_page * ( $paged - 1 ); |
|
864 | + $offset = $per_page * ($paged - 1); |
|
865 | 865 | |
866 | - if ( is_numeric( $customer ) ) { |
|
866 | + if (is_numeric($customer)) { |
|
867 | 867 | $field = 'id'; |
868 | 868 | } else { |
869 | 869 | $field = 'email'; |
870 | 870 | } |
871 | 871 | |
872 | - $customer_query = Give()->customers->get_customers( array( |
|
872 | + $customer_query = Give()->customers->get_customers(array( |
|
873 | 873 | 'number' => $per_page, |
874 | 874 | 'offset' => $offset, |
875 | 875 | $field => $customer |
876 | - ) ); |
|
876 | + )); |
|
877 | 877 | $customer_count = 0; |
878 | 878 | |
879 | - if ( $customer_query ) { |
|
879 | + if ($customer_query) { |
|
880 | 880 | |
881 | - foreach ( $customer_query as $customer_obj ) { |
|
881 | + foreach ($customer_query as $customer_obj) { |
|
882 | 882 | |
883 | - $names = explode( ' ', $customer_obj->name ); |
|
884 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
883 | + $names = explode(' ', $customer_obj->name); |
|
884 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
885 | 885 | $last_name = ''; |
886 | - if ( ! empty( $names[1] ) ) { |
|
887 | - unset( $names[0] ); |
|
888 | - $last_name = implode( ' ', $names ); |
|
886 | + if ( ! empty($names[1])) { |
|
887 | + unset($names[0]); |
|
888 | + $last_name = implode(' ', $names); |
|
889 | 889 | } |
890 | 890 | |
891 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
892 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
894 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
895 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
896 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
897 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
891 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
892 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
894 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
895 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
896 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
897 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
898 | 898 | |
899 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
899 | + if ( ! empty($customer_obj->user_id)) { |
|
900 | 900 | |
901 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
901 | + $user_data = get_userdata($customer_obj->user_id); |
|
902 | 902 | |
903 | 903 | // Customer with registered account |
904 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
905 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
906 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
904 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
905 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
906 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
907 | 907 | |
908 | 908 | } |
909 | 909 | |
910 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
911 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
910 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
911 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
912 | 912 | |
913 | - $customer_count ++; |
|
913 | + $customer_count++; |
|
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | - } elseif ( $customer ) { |
|
917 | + } elseif ($customer) { |
|
918 | 918 | |
919 | 919 | $error['error'] = sprintf( |
920 | 920 | /* translators: %s: customer */ |
921 | - __( 'Donor %s not found!', 'give' ), |
|
921 | + __('Donor %s not found!', 'give'), |
|
922 | 922 | $customer |
923 | 923 | ); |
924 | 924 | |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | |
927 | 927 | } else { |
928 | 928 | |
929 | - $error['error'] = __( 'No donors found!', 'give' ); |
|
929 | + $error['error'] = __('No donors found!', 'give'); |
|
930 | 930 | |
931 | 931 | return $error; |
932 | 932 | |
@@ -945,38 +945,38 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @return array $customers Multidimensional array of the forms |
947 | 947 | */ |
948 | - public function get_forms( $form = null ) { |
|
948 | + public function get_forms($form = null) { |
|
949 | 949 | |
950 | 950 | $forms = array(); |
951 | 951 | $error = array(); |
952 | 952 | |
953 | - if ( $form == null ) { |
|
953 | + if ($form == null) { |
|
954 | 954 | $forms['forms'] = array(); |
955 | 955 | |
956 | - $form_list = get_posts( array( |
|
956 | + $form_list = get_posts(array( |
|
957 | 957 | 'post_type' => 'give_forms', |
958 | 958 | 'posts_per_page' => $this->per_page(), |
959 | 959 | 'suppress_filters' => true, |
960 | 960 | 'paged' => $this->get_paged() |
961 | - ) ); |
|
961 | + )); |
|
962 | 962 | |
963 | - if ( $form_list ) { |
|
963 | + if ($form_list) { |
|
964 | 964 | $i = 0; |
965 | - foreach ( $form_list as $form_info ) { |
|
966 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
967 | - $i ++; |
|
965 | + foreach ($form_list as $form_info) { |
|
966 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
967 | + $i++; |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | } else { |
971 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
972 | - $form_info = get_post( $form ); |
|
971 | + if (get_post_type($form) == 'give_forms') { |
|
972 | + $form_info = get_post($form); |
|
973 | 973 | |
974 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
974 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
975 | 975 | |
976 | 976 | } else { |
977 | 977 | $error['error'] = sprintf( |
978 | 978 | /* translators: %s: form */ |
979 | - __( 'Form %s not found!', 'give' ), |
|
979 | + __('Form %s not found!', 'give'), |
|
980 | 980 | $form |
981 | 981 | ); |
982 | 982 | |
@@ -996,7 +996,7 @@ discard block |
||
996 | 996 | * |
997 | 997 | * @return array Array of post data to return back in the API |
998 | 998 | */ |
999 | - private function get_form_data( $form_info ) { |
|
999 | + private function get_form_data($form_info) { |
|
1000 | 1000 | |
1001 | 1001 | $form = array(); |
1002 | 1002 | |
@@ -1006,46 +1006,46 @@ discard block |
||
1006 | 1006 | $form['info']['create_date'] = $form_info->post_date; |
1007 | 1007 | $form['info']['modified_date'] = $form_info->post_modified; |
1008 | 1008 | $form['info']['status'] = $form_info->post_status; |
1009 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1010 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1011 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1009 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1010 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1011 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1012 | 1012 | |
1013 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
1014 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1015 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1013 | + if (give_get_option('enable_categories') == 'on') { |
|
1014 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1015 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1016 | 1016 | } |
1017 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
1018 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1017 | + if (give_get_option('enable_tags') == 'on') { |
|
1018 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1022 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1023 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1024 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1025 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1021 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1022 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1023 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1024 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1025 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | $counter = 0; |
1029 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1030 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1031 | - $counter ++; |
|
1029 | + if (give_has_variable_prices($form_info->ID)) { |
|
1030 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1031 | + $counter++; |
|
1032 | 1032 | //muli-level item |
1033 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1034 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1033 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1034 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1035 | 1035 | |
1036 | 1036 | } |
1037 | 1037 | } else { |
1038 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1038 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1041 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1042 | 1042 | |
1043 | 1043 | //Sensitive data here |
1044 | - do_action( 'give_api_sensitive_data' ); |
|
1044 | + do_action('give_api_sensitive_data'); |
|
1045 | 1045 | |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1048 | + return apply_filters('give_api_forms_form', $form); |
|
1049 | 1049 | |
1050 | 1050 | } |
1051 | 1051 | |
@@ -1060,7 +1060,7 @@ discard block |
||
1060 | 1060 | * |
1061 | 1061 | * @return array |
1062 | 1062 | */ |
1063 | - public function get_stats( $args = array() ) { |
|
1063 | + public function get_stats($args = array()) { |
|
1064 | 1064 | $defaults = array( |
1065 | 1065 | 'type' => null, |
1066 | 1066 | 'form' => null, |
@@ -1069,9 +1069,9 @@ discard block |
||
1069 | 1069 | 'enddate' => null |
1070 | 1070 | ); |
1071 | 1071 | |
1072 | - $args = wp_parse_args( $args, $defaults ); |
|
1072 | + $args = wp_parse_args($args, $defaults); |
|
1073 | 1073 | |
1074 | - $dates = $this->get_dates( $args ); |
|
1074 | + $dates = $this->get_dates($args); |
|
1075 | 1075 | |
1076 | 1076 | $stats = array(); |
1077 | 1077 | $earnings = array( |
@@ -1082,41 +1082,41 @@ discard block |
||
1082 | 1082 | ); |
1083 | 1083 | $error = array(); |
1084 | 1084 | |
1085 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1085 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1086 | 1086 | return $stats; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - if ( $args['type'] == 'donations' ) { |
|
1089 | + if ($args['type'] == 'donations') { |
|
1090 | 1090 | |
1091 | - if ( $args['form'] == null ) { |
|
1092 | - if ( $args['date'] == null ) { |
|
1091 | + if ($args['form'] == null) { |
|
1092 | + if ($args['date'] == null) { |
|
1093 | 1093 | $sales = $this->get_default_sales_stats(); |
1094 | - } elseif ( $args['date'] === 'range' ) { |
|
1094 | + } elseif ($args['date'] === 'range') { |
|
1095 | 1095 | // Return sales for a date range |
1096 | 1096 | |
1097 | 1097 | // Ensure the end date is later than the start date |
1098 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1099 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
1098 | + if ($args['enddate'] < $args['startdate']) { |
|
1099 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | // Ensure both the start and end date are specified |
1103 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1104 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
1103 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1104 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | $total = 0; |
1108 | 1108 | |
1109 | 1109 | // Loop through the years |
1110 | 1110 | $y = $dates['year']; |
1111 | - while ( $y <= $dates['year_end'] ) : |
|
1111 | + while ($y <= $dates['year_end']) : |
|
1112 | 1112 | |
1113 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1113 | + if ($dates['year'] == $dates['year_end']) { |
|
1114 | 1114 | $month_start = $dates['m_start']; |
1115 | 1115 | $month_end = $dates['m_end']; |
1116 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1116 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1117 | 1117 | $month_start = $dates['m_start']; |
1118 | 1118 | $month_end = 12; |
1119 | - } elseif ( $y == $dates['year_end'] ) { |
|
1119 | + } elseif ($y == $dates['year_end']) { |
|
1120 | 1120 | $month_start = 1; |
1121 | 1121 | $month_end = $dates['m_end']; |
1122 | 1122 | } else { |
@@ -1125,113 +1125,113 @@ discard block |
||
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | $i = $month_start; |
1128 | - while ( $i <= $month_end ) : |
|
1128 | + while ($i <= $month_end) : |
|
1129 | 1129 | |
1130 | - if ( $i == $dates['m_start'] ) { |
|
1130 | + if ($i == $dates['m_start']) { |
|
1131 | 1131 | $d = $dates['day_start']; |
1132 | 1132 | } else { |
1133 | 1133 | $d = 1; |
1134 | 1134 | } |
1135 | 1135 | |
1136 | - if ( $i == $dates['m_end'] ) { |
|
1136 | + if ($i == $dates['m_end']) { |
|
1137 | 1137 | $num_of_days = $dates['day_end']; |
1138 | 1138 | } else { |
1139 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1139 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | - while ( $d <= $num_of_days ) : |
|
1143 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1144 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1145 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1146 | - $sales['sales'][ $date_key ] = 0; |
|
1142 | + while ($d <= $num_of_days) : |
|
1143 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1144 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1145 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1146 | + $sales['sales'][$date_key] = 0; |
|
1147 | 1147 | } |
1148 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1148 | + $sales['sales'][$date_key] += $sale_count; |
|
1149 | 1149 | $total += $sale_count; |
1150 | - $d ++; |
|
1150 | + $d++; |
|
1151 | 1151 | endwhile; |
1152 | - $i ++; |
|
1152 | + $i++; |
|
1153 | 1153 | endwhile; |
1154 | 1154 | |
1155 | - $y ++; |
|
1155 | + $y++; |
|
1156 | 1156 | endwhile; |
1157 | 1157 | |
1158 | 1158 | $sales['totals'] = $total; |
1159 | 1159 | } else { |
1160 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1160 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1161 | 1161 | $sales_count = 0; |
1162 | 1162 | |
1163 | 1163 | // Loop through the months |
1164 | 1164 | $month = $dates['m_start']; |
1165 | 1165 | |
1166 | - while ( $month <= $dates['m_end'] ) : |
|
1167 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1168 | - $month ++; |
|
1166 | + while ($month <= $dates['m_end']) : |
|
1167 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1168 | + $month++; |
|
1169 | 1169 | endwhile; |
1170 | 1170 | |
1171 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1171 | + $sales['donations'][$args['date']] = $sales_count; |
|
1172 | 1172 | } else { |
1173 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1173 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1174 | 1174 | } |
1175 | 1175 | } |
1176 | - } elseif ( $args['form'] == 'all' ) { |
|
1177 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1176 | + } elseif ($args['form'] == 'all') { |
|
1177 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1178 | 1178 | $i = 0; |
1179 | - foreach ( $forms as $form_info ) { |
|
1180 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1181 | - $i ++; |
|
1179 | + foreach ($forms as $form_info) { |
|
1180 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1181 | + $i++; |
|
1182 | 1182 | } |
1183 | 1183 | } else { |
1184 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1185 | - $form_info = get_post( $args['form'] ); |
|
1186 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1184 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1185 | + $form_info = get_post($args['form']); |
|
1186 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1187 | 1187 | } else { |
1188 | 1188 | $error['error'] = sprintf( |
1189 | 1189 | /* translators: %s: form */ |
1190 | - __( 'Product %s not found!', 'give' ), |
|
1190 | + __('Product %s not found!', 'give'), |
|
1191 | 1191 | $args['form'] |
1192 | 1192 | ); |
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - if ( ! empty( $error ) ) { |
|
1196 | + if ( ! empty($error)) { |
|
1197 | 1197 | return $error; |
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | return $sales; |
1201 | 1201 | |
1202 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1203 | - if ( $args['form'] == null ) { |
|
1204 | - if ( $args['date'] == null ) { |
|
1202 | + } elseif ($args['type'] == 'earnings') { |
|
1203 | + if ($args['form'] == null) { |
|
1204 | + if ($args['date'] == null) { |
|
1205 | 1205 | $earnings = $this->get_default_earnings_stats(); |
1206 | - } elseif ( $args['date'] === 'range' ) { |
|
1206 | + } elseif ($args['date'] === 'range') { |
|
1207 | 1207 | // Return sales for a date range |
1208 | 1208 | |
1209 | 1209 | // Ensure the end date is later than the start date |
1210 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1211 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
1210 | + if ($args['enddate'] < $args['startdate']) { |
|
1211 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Ensure both the start and end date are specified |
1215 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1216 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
1215 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1216 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | $total = (float) 0.00; |
1220 | 1220 | |
1221 | 1221 | // Loop through the years |
1222 | 1222 | $y = $dates['year']; |
1223 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1223 | + if ( ! isset($earnings['earnings'])) { |
|
1224 | 1224 | $earnings['earnings'] = array(); |
1225 | 1225 | } |
1226 | - while ( $y <= $dates['year_end'] ) : |
|
1226 | + while ($y <= $dates['year_end']) : |
|
1227 | 1227 | |
1228 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1228 | + if ($dates['year'] == $dates['year_end']) { |
|
1229 | 1229 | $month_start = $dates['m_start']; |
1230 | 1230 | $month_end = $dates['m_end']; |
1231 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1231 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1232 | 1232 | $month_start = $dates['m_start']; |
1233 | 1233 | $month_end = 12; |
1234 | - } elseif ( $y == $dates['year_end'] ) { |
|
1234 | + } elseif ($y == $dates['year_end']) { |
|
1235 | 1235 | $month_start = 1; |
1236 | 1236 | $month_end = $dates['m_end']; |
1237 | 1237 | } else { |
@@ -1240,92 +1240,92 @@ discard block |
||
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | $i = $month_start; |
1243 | - while ( $i <= $month_end ) : |
|
1243 | + while ($i <= $month_end) : |
|
1244 | 1244 | |
1245 | - if ( $i == $dates['m_start'] ) { |
|
1245 | + if ($i == $dates['m_start']) { |
|
1246 | 1246 | $d = $dates['day_start']; |
1247 | 1247 | } else { |
1248 | 1248 | $d = 1; |
1249 | 1249 | } |
1250 | 1250 | |
1251 | - if ( $i == $dates['m_end'] ) { |
|
1251 | + if ($i == $dates['m_end']) { |
|
1252 | 1252 | $num_of_days = $dates['day_end']; |
1253 | 1253 | } else { |
1254 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1254 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | - while ( $d <= $num_of_days ) : |
|
1258 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1259 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1260 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1261 | - $earnings['earnings'][ $date_key ] = 0; |
|
1257 | + while ($d <= $num_of_days) : |
|
1258 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1259 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1260 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1261 | + $earnings['earnings'][$date_key] = 0; |
|
1262 | 1262 | } |
1263 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1263 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1264 | 1264 | $total += $earnings_stat; |
1265 | - $d ++; |
|
1265 | + $d++; |
|
1266 | 1266 | endwhile; |
1267 | 1267 | |
1268 | - $i ++; |
|
1268 | + $i++; |
|
1269 | 1269 | endwhile; |
1270 | 1270 | |
1271 | - $y ++; |
|
1271 | + $y++; |
|
1272 | 1272 | endwhile; |
1273 | 1273 | |
1274 | 1274 | $earnings['totals'] = $total; |
1275 | 1275 | } else { |
1276 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1276 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1277 | 1277 | $earnings_count = (float) 0.00; |
1278 | 1278 | |
1279 | 1279 | // Loop through the months |
1280 | 1280 | $month = $dates['m_start']; |
1281 | 1281 | |
1282 | - while ( $month <= $dates['m_end'] ) : |
|
1283 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1284 | - $month ++; |
|
1282 | + while ($month <= $dates['m_end']) : |
|
1283 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1284 | + $month++; |
|
1285 | 1285 | endwhile; |
1286 | 1286 | |
1287 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1287 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1288 | 1288 | } else { |
1289 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1289 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | - } elseif ( $args['form'] == 'all' ) { |
|
1293 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1292 | + } elseif ($args['form'] == 'all') { |
|
1293 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1294 | 1294 | |
1295 | 1295 | $i = 0; |
1296 | - foreach ( $forms as $form_info ) { |
|
1297 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1298 | - $i ++; |
|
1296 | + foreach ($forms as $form_info) { |
|
1297 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1298 | + $i++; |
|
1299 | 1299 | } |
1300 | 1300 | } else { |
1301 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1302 | - $form_info = get_post( $args['form'] ); |
|
1303 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1301 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1302 | + $form_info = get_post($args['form']); |
|
1303 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1304 | 1304 | } else { |
1305 | 1305 | $error['error'] = sprintf( |
1306 | 1306 | /* translators: %s: form */ |
1307 | - __( 'Form %s not found!', 'give' ), |
|
1307 | + __('Form %s not found!', 'give'), |
|
1308 | 1308 | $args['form'] |
1309 | 1309 | ); |
1310 | 1310 | } |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( ! empty( $error ) ) { |
|
1313 | + if ( ! empty($error)) { |
|
1314 | 1314 | return $error; |
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $earnings; |
1318 | - } elseif ( $args['type'] == 'donors' ) { |
|
1318 | + } elseif ($args['type'] == 'donors') { |
|
1319 | 1319 | $customers = new Give_DB_Customers(); |
1320 | 1320 | $stats['donations']['total_donors'] = $customers->count(); |
1321 | 1321 | |
1322 | 1322 | return $stats; |
1323 | 1323 | |
1324 | - } elseif ( empty( $args['type'] ) ) { |
|
1325 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1326 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1324 | + } elseif (empty($args['type'])) { |
|
1325 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1326 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1327 | 1327 | |
1328 | - return array( 'stats' => $stats ); |
|
1328 | + return array('stats' => $stats); |
|
1329 | 1329 | } |
1330 | 1330 | } |
1331 | 1331 | |
@@ -1341,18 +1341,18 @@ discard block |
||
1341 | 1341 | |
1342 | 1342 | $sales = array(); |
1343 | 1343 | |
1344 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1344 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1345 | 1345 | return $sales; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1348 | + if (isset($wp_query->query_vars['id'])) { |
|
1349 | 1349 | $query = array(); |
1350 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1351 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1350 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1351 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1352 | 1352 | $query = array(); |
1353 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1354 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1355 | - $args = array( |
|
1353 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1354 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1355 | + $args = array( |
|
1356 | 1356 | 'fields' => 'ids', |
1357 | 1357 | 'meta_key' => '_give_payment_user_email', |
1358 | 1358 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1360,7 +1360,7 @@ discard block |
||
1360 | 1360 | 'page' => $this->get_paged(), |
1361 | 1361 | 'status' => 'publish' |
1362 | 1362 | ); |
1363 | - $query = give_get_payments( $args ); |
|
1363 | + $query = give_get_payments($args); |
|
1364 | 1364 | } else { |
1365 | 1365 | $args = array( |
1366 | 1366 | 'fields' => 'ids', |
@@ -1368,14 +1368,14 @@ discard block |
||
1368 | 1368 | 'page' => $this->get_paged(), |
1369 | 1369 | 'status' => 'publish' |
1370 | 1370 | ); |
1371 | - $query = give_get_payments( $args ); |
|
1371 | + $query = give_get_payments($args); |
|
1372 | 1372 | } |
1373 | - if ( $query ) { |
|
1373 | + if ($query) { |
|
1374 | 1374 | $i = 0; |
1375 | - foreach ( $query as $payment ) { |
|
1375 | + foreach ($query as $payment) { |
|
1376 | 1376 | |
1377 | - if ( is_numeric( $payment ) ) { |
|
1378 | - $payment = new Give_Payment( $payment ); |
|
1377 | + if (is_numeric($payment)) { |
|
1378 | + $payment = new Give_Payment($payment); |
|
1379 | 1379 | $payment_meta = $payment->get_meta(); |
1380 | 1380 | $user_info = $payment->user_info; |
1381 | 1381 | } else { |
@@ -1385,40 +1385,40 @@ discard block |
||
1385 | 1385 | $payment_meta = $payment->get_meta(); |
1386 | 1386 | $user_info = $payment->user_info; |
1387 | 1387 | |
1388 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1389 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1390 | - |
|
1391 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1392 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1393 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1394 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1395 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1396 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1397 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1398 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1399 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1400 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1401 | - |
|
1402 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1404 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1405 | - |
|
1406 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1407 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1408 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1409 | - |
|
1410 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1411 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1412 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1413 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1414 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1415 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1388 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1389 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1390 | + |
|
1391 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1392 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1393 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1394 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1395 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1396 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1397 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1398 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1399 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1400 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1401 | + |
|
1402 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1404 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1405 | + |
|
1406 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1407 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1408 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1409 | + |
|
1410 | + if (give_has_variable_prices($form_id)) { |
|
1411 | + if (isset($payment_meta['price_id'])) { |
|
1412 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1413 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1414 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1415 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1416 | 1416 | |
1417 | 1417 | } |
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | //Add custom meta to API |
1421 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1421 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1422 | 1422 | |
1423 | 1423 | $exceptions = array( |
1424 | 1424 | 'form_title', |
@@ -1431,19 +1431,19 @@ discard block |
||
1431 | 1431 | ); |
1432 | 1432 | |
1433 | 1433 | //Don't clutter up results with dupes |
1434 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1434 | + if (in_array($meta_key, $exceptions)) { |
|
1435 | 1435 | continue; |
1436 | 1436 | } |
1437 | 1437 | |
1438 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1438 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1439 | 1439 | |
1440 | 1440 | } |
1441 | 1441 | |
1442 | - $i ++; |
|
1442 | + $i++; |
|
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1446 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | /** |
@@ -1458,9 +1458,9 @@ discard block |
||
1458 | 1458 | public function get_output_format() { |
1459 | 1459 | global $wp_query; |
1460 | 1460 | |
1461 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1461 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1462 | 1462 | |
1463 | - return apply_filters( 'give_api_output_format', $format ); |
|
1463 | + return apply_filters('give_api_output_format', $format); |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | |
@@ -1476,8 +1476,8 @@ discard block |
||
1476 | 1476 | * |
1477 | 1477 | * @return void |
1478 | 1478 | */ |
1479 | - private function log_request( $data = array() ) { |
|
1480 | - if ( ! $this->log_requests ) { |
|
1479 | + private function log_request($data = array()) { |
|
1480 | + if ( ! $this->log_requests) { |
|
1481 | 1481 | return; |
1482 | 1482 | } |
1483 | 1483 | |
@@ -1485,36 +1485,36 @@ discard block |
||
1485 | 1485 | |
1486 | 1486 | $query = array( |
1487 | 1487 | 'give-api' => $wp_query->query_vars['give-api'], |
1488 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1489 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1490 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1491 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1492 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1493 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1494 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1495 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1496 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1497 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1498 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1499 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1488 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1489 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1490 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1491 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1492 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1493 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1494 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1495 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1496 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1497 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1498 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1499 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1500 | 1500 | ); |
1501 | 1501 | |
1502 | 1502 | $log_data = array( |
1503 | 1503 | 'log_type' => 'api_request', |
1504 | - 'post_excerpt' => http_build_query( $query ), |
|
1505 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1504 | + 'post_excerpt' => http_build_query($query), |
|
1505 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1506 | 1506 | ); |
1507 | 1507 | |
1508 | 1508 | $log_meta = array( |
1509 | 1509 | 'request_ip' => give_get_ip(), |
1510 | 1510 | 'user' => $this->user_id, |
1511 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1512 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1511 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1512 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1513 | 1513 | 'time' => $data['request_speed'], |
1514 | 1514 | 'version' => $this->get_queried_version() |
1515 | 1515 | ); |
1516 | 1516 | |
1517 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1517 | + $give_logs->insert_log($log_data, $log_meta); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | |
@@ -1538,32 +1538,32 @@ discard block |
||
1538 | 1538 | * |
1539 | 1539 | * @param int $status_code |
1540 | 1540 | */ |
1541 | - public function output( $status_code = 200 ) { |
|
1541 | + public function output($status_code = 200) { |
|
1542 | 1542 | global $wp_query; |
1543 | 1543 | |
1544 | 1544 | $format = $this->get_output_format(); |
1545 | 1545 | |
1546 | - status_header( $status_code ); |
|
1546 | + status_header($status_code); |
|
1547 | 1547 | |
1548 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1548 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1549 | 1549 | |
1550 | - switch ( $format ) : |
|
1550 | + switch ($format) : |
|
1551 | 1551 | |
1552 | 1552 | case 'xml' : |
1553 | 1553 | |
1554 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1555 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1554 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1555 | + $xml = Array2XML::createXML('give', $this->data); |
|
1556 | 1556 | echo $xml->saveXML(); |
1557 | 1557 | |
1558 | 1558 | break; |
1559 | 1559 | |
1560 | 1560 | case 'json' : |
1561 | 1561 | |
1562 | - header( 'Content-Type: application/json' ); |
|
1563 | - if ( ! empty( $this->pretty_print ) ) { |
|
1564 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1562 | + header('Content-Type: application/json'); |
|
1563 | + if ( ! empty($this->pretty_print)) { |
|
1564 | + echo json_encode($this->data, $this->pretty_print); |
|
1565 | 1565 | } else { |
1566 | - echo json_encode( $this->data ); |
|
1566 | + echo json_encode($this->data); |
|
1567 | 1567 | } |
1568 | 1568 | |
1569 | 1569 | break; |
@@ -1572,13 +1572,13 @@ discard block |
||
1572 | 1572 | default : |
1573 | 1573 | |
1574 | 1574 | // Allow other formats to be added via extensions |
1575 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
1575 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
1576 | 1576 | |
1577 | 1577 | break; |
1578 | 1578 | |
1579 | 1579 | endswitch; |
1580 | 1580 | |
1581 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1581 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1582 | 1582 | |
1583 | 1583 | give_die(); |
1584 | 1584 | } |
@@ -1595,37 +1595,37 @@ discard block |
||
1595 | 1595 | * |
1596 | 1596 | * @return void |
1597 | 1597 | */ |
1598 | - function user_key_field( $user ) { |
|
1598 | + function user_key_field($user) { |
|
1599 | 1599 | |
1600 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1601 | - $user = get_userdata( $user->ID ); |
|
1600 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1601 | + $user = get_userdata($user->ID); |
|
1602 | 1602 | ?> |
1603 | 1603 | <table class="form-table"> |
1604 | 1604 | <tbody> |
1605 | 1605 | <tr> |
1606 | 1606 | <th> |
1607 | - <?php esc_attr_e( 'Give API Keys', 'give' ); ?> |
|
1607 | + <?php esc_attr_e('Give API Keys', 'give'); ?> |
|
1608 | 1608 | </th> |
1609 | 1609 | <td> |
1610 | 1610 | <?php |
1611 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1612 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1611 | + $public_key = $this->get_user_public_key($user->ID); |
|
1612 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1613 | 1613 | ?> |
1614 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1614 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1615 | 1615 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1616 | - <span class="description"><?php esc_attr_e( 'Generate API Key', 'give' ); ?></span> |
|
1616 | + <span class="description"><?php esc_attr_e('Generate API Key', 'give'); ?></span> |
|
1617 | 1617 | <?php } else { ?> |
1618 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> </strong> |
|
1619 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1618 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> </strong> |
|
1619 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1620 | 1620 | <br/> |
1621 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Secret key:', 'give' ); ?> </strong> |
|
1622 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1621 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Secret key:', 'give'); ?> </strong> |
|
1622 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1623 | 1623 | <br/> |
1624 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Token:', 'give' ); ?> </strong> |
|
1625 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1624 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Token:', 'give'); ?> </strong> |
|
1625 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1626 | 1626 | <br/> |
1627 | 1627 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1628 | - <span class="description"><label for="give_set_api_key"><?php esc_attr_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1628 | + <span class="description"><label for="give_set_api_key"><?php esc_attr_e('Revoke API Keys', 'give'); ?></label></span> |
|
1629 | 1629 | <?php } ?> |
1630 | 1630 | </td> |
1631 | 1631 | </tr> |
@@ -1644,69 +1644,69 @@ discard block |
||
1644 | 1644 | * |
1645 | 1645 | * @return void |
1646 | 1646 | */ |
1647 | - public function process_api_key( $args ) { |
|
1647 | + public function process_api_key($args) { |
|
1648 | 1648 | |
1649 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1649 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1650 | 1650 | |
1651 | - wp_die( esc_attr__( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1651 | + wp_die(esc_attr__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
1652 | 1652 | |
1653 | 1653 | } |
1654 | 1654 | |
1655 | - if ( empty( $args['user_id'] ) ) { |
|
1656 | - wp_die( esc_attr__( 'User ID Required.', 'give' ), esc_attr__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1655 | + if (empty($args['user_id'])) { |
|
1656 | + wp_die(esc_attr__('User ID Required.', 'give'), esc_attr__('Error', 'give'), array('response' => 401)); |
|
1657 | 1657 | } |
1658 | 1658 | |
1659 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1660 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1659 | + if (is_numeric($args['user_id'])) { |
|
1660 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1661 | 1661 | } else { |
1662 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1662 | + $userdata = get_user_by('login', $args['user_id']); |
|
1663 | 1663 | $user_id = $userdata->ID; |
1664 | 1664 | } |
1665 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1665 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1666 | 1666 | |
1667 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1667 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1668 | 1668 | wp_die( |
1669 | 1669 | sprintf( |
1670 | 1670 | /* translators: %s: process */ |
1671 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1671 | + __('You do not have permission to %s API keys for this user.', 'give'), |
|
1672 | 1672 | $process |
1673 | 1673 | ), |
1674 | - __( 'Error', 'give' ), |
|
1675 | - array( 'response' => 403 ) |
|
1674 | + __('Error', 'give'), |
|
1675 | + array('response' => 403) |
|
1676 | 1676 | ); |
1677 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1677 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1678 | 1678 | wp_die( |
1679 | 1679 | sprintf( |
1680 | 1680 | /* translators: %s: process */ |
1681 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1681 | + __('You do not have permission to %s API keys for this user.', 'give'), |
|
1682 | 1682 | $process |
1683 | 1683 | ), |
1684 | - __( 'Error', 'give' ), |
|
1685 | - array( 'response' => 403 ) |
|
1684 | + __('Error', 'give'), |
|
1685 | + array('response' => 403) |
|
1686 | 1686 | ); |
1687 | 1687 | } |
1688 | 1688 | |
1689 | - switch ( $process ) { |
|
1689 | + switch ($process) { |
|
1690 | 1690 | case 'generate': |
1691 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1692 | - delete_transient( 'give-total-api-keys' ); |
|
1693 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1691 | + if ($this->generate_api_key($user_id)) { |
|
1692 | + delete_transient('give-total-api-keys'); |
|
1693 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1694 | 1694 | exit(); |
1695 | 1695 | } else { |
1696 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1696 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1697 | 1697 | exit(); |
1698 | 1698 | } |
1699 | 1699 | break; |
1700 | 1700 | case 'regenerate': |
1701 | - $this->generate_api_key( $user_id, true ); |
|
1702 | - delete_transient( 'give-total-api-keys' ); |
|
1703 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1701 | + $this->generate_api_key($user_id, true); |
|
1702 | + delete_transient('give-total-api-keys'); |
|
1703 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1704 | 1704 | exit(); |
1705 | 1705 | break; |
1706 | 1706 | case 'revoke': |
1707 | - $this->revoke_api_key( $user_id ); |
|
1708 | - delete_transient( 'give-total-api-keys' ); |
|
1709 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1707 | + $this->revoke_api_key($user_id); |
|
1708 | + delete_transient('give-total-api-keys'); |
|
1709 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1710 | 1710 | exit(); |
1711 | 1711 | break; |
1712 | 1712 | default; |
@@ -1725,34 +1725,34 @@ discard block |
||
1725 | 1725 | * |
1726 | 1726 | * @return boolean True if (re)generated succesfully, false otherwise. |
1727 | 1727 | */ |
1728 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1728 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1729 | 1729 | |
1730 | - if ( empty( $user_id ) ) { |
|
1730 | + if (empty($user_id)) { |
|
1731 | 1731 | return false; |
1732 | 1732 | } |
1733 | 1733 | |
1734 | - $user = get_userdata( $user_id ); |
|
1734 | + $user = get_userdata($user_id); |
|
1735 | 1735 | |
1736 | - if ( ! $user ) { |
|
1736 | + if ( ! $user) { |
|
1737 | 1737 | return false; |
1738 | 1738 | } |
1739 | 1739 | |
1740 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1741 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1740 | + $public_key = $this->get_user_public_key($user_id); |
|
1741 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1742 | 1742 | |
1743 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1744 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1745 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1743 | + if (empty($public_key) || $regenerate == true) { |
|
1744 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1745 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1746 | 1746 | } else { |
1747 | 1747 | return false; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - if ( $regenerate == true ) { |
|
1751 | - $this->revoke_api_key( $user->ID ); |
|
1750 | + if ($regenerate == true) { |
|
1751 | + $this->revoke_api_key($user->ID); |
|
1752 | 1752 | } |
1753 | 1753 | |
1754 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1755 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1754 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1755 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1756 | 1756 | |
1757 | 1757 | return true; |
1758 | 1758 | } |
@@ -1767,26 +1767,26 @@ discard block |
||
1767 | 1767 | * |
1768 | 1768 | * @return string |
1769 | 1769 | */ |
1770 | - public function revoke_api_key( $user_id = 0 ) { |
|
1770 | + public function revoke_api_key($user_id = 0) { |
|
1771 | 1771 | |
1772 | - if ( empty( $user_id ) ) { |
|
1772 | + if (empty($user_id)) { |
|
1773 | 1773 | return false; |
1774 | 1774 | } |
1775 | 1775 | |
1776 | - $user = get_userdata( $user_id ); |
|
1776 | + $user = get_userdata($user_id); |
|
1777 | 1777 | |
1778 | - if ( ! $user ) { |
|
1778 | + if ( ! $user) { |
|
1779 | 1779 | return false; |
1780 | 1780 | } |
1781 | 1781 | |
1782 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1783 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1784 | - if ( ! empty( $public_key ) ) { |
|
1785 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
1786 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
1787 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
1788 | - delete_user_meta( $user_id, $public_key ); |
|
1789 | - delete_user_meta( $user_id, $secret_key ); |
|
1782 | + $public_key = $this->get_user_public_key($user_id); |
|
1783 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1784 | + if ( ! empty($public_key)) { |
|
1785 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
1786 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
1787 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
1788 | + delete_user_meta($user_id, $public_key); |
|
1789 | + delete_user_meta($user_id, $secret_key); |
|
1790 | 1790 | } else { |
1791 | 1791 | return false; |
1792 | 1792 | } |
@@ -1811,22 +1811,22 @@ discard block |
||
1811 | 1811 | * |
1812 | 1812 | * @return void |
1813 | 1813 | */ |
1814 | - public function update_key( $user_id ) { |
|
1815 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1814 | + public function update_key($user_id) { |
|
1815 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1816 | 1816 | |
1817 | - $user = get_userdata( $user_id ); |
|
1817 | + $user = get_userdata($user_id); |
|
1818 | 1818 | |
1819 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1820 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1819 | + $public_key = $this->get_user_public_key($user_id); |
|
1820 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1821 | 1821 | |
1822 | - if ( empty( $public_key ) ) { |
|
1823 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1824 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1822 | + if (empty($public_key)) { |
|
1823 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1824 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1825 | 1825 | |
1826 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1827 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1826 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1827 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1828 | 1828 | } else { |
1829 | - $this->revoke_api_key( $user_id ); |
|
1829 | + $this->revoke_api_key($user_id); |
|
1830 | 1830 | } |
1831 | 1831 | } |
1832 | 1832 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
1841 | 1841 | * |
1842 | 1842 | * @return string |
1843 | 1843 | */ |
1844 | - private function generate_public_key( $user_email = '' ) { |
|
1845 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1846 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1844 | + private function generate_public_key($user_email = '') { |
|
1845 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1846 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1847 | 1847 | |
1848 | 1848 | return $public; |
1849 | 1849 | } |
@@ -1858,9 +1858,9 @@ discard block |
||
1858 | 1858 | * |
1859 | 1859 | * @return string |
1860 | 1860 | */ |
1861 | - private function generate_private_key( $user_id = 0 ) { |
|
1862 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1863 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1861 | + private function generate_private_key($user_id = 0) { |
|
1862 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1863 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1864 | 1864 | |
1865 | 1865 | return $secret; |
1866 | 1866 | } |
@@ -1875,8 +1875,8 @@ discard block |
||
1875 | 1875 | * |
1876 | 1876 | * @return string |
1877 | 1877 | */ |
1878 | - public function get_token( $user_id = 0 ) { |
|
1879 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1878 | + public function get_token($user_id = 0) { |
|
1879 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1880 | 1880 | } |
1881 | 1881 | |
1882 | 1882 | /** |
@@ -1890,9 +1890,9 @@ discard block |
||
1890 | 1890 | |
1891 | 1891 | // Default sales return |
1892 | 1892 | $sales = array(); |
1893 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1894 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1895 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1893 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1894 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1895 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1896 | 1896 | $sales['donations']['totals'] = give_get_total_sales(); |
1897 | 1897 | |
1898 | 1898 | return $sales; |
@@ -1909,9 +1909,9 @@ discard block |
||
1909 | 1909 | |
1910 | 1910 | // Default earnings return |
1911 | 1911 | $earnings = array(); |
1912 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1913 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1914 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1912 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1913 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1914 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1915 | 1915 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1916 | 1916 | |
1917 | 1917 | return $earnings; |
@@ -1931,25 +1931,25 @@ discard block |
||
1931 | 1931 | * |
1932 | 1932 | * @return string The API key/secret for the user supplied |
1933 | 1933 | */ |
1934 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1934 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1935 | 1935 | |
1936 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1936 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1937 | 1937 | return $check; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | 1940 | $return = $check; |
1941 | 1941 | |
1942 | - switch ( $meta_key ) { |
|
1942 | + switch ($meta_key) { |
|
1943 | 1943 | case 'give_user_public_key': |
1944 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1944 | + $return = Give()->api->get_user_public_key($object_id); |
|
1945 | 1945 | break; |
1946 | 1946 | case 'give_user_secret_key': |
1947 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1947 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1948 | 1948 | break; |
1949 | 1949 | } |
1950 | 1950 | |
1951 | - if ( ! $single ) { |
|
1952 | - $return = array( $return ); |
|
1951 | + if ( ! $single) { |
|
1952 | + $return = array($return); |
|
1953 | 1953 | } |
1954 | 1954 | |
1955 | 1955 | return $return; |
@@ -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( __( 'Nonce verification has failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | 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 | - __( 'Payment Error', 'give' ), |
|
62 | + __('Payment Error', 'give'), |
|
63 | 63 | sprintf( |
64 | 64 | /* translators: %s: payment data */ |
65 | - __( 'The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give' ), |
|
66 | - json_encode( $payment_data ) |
|
65 | + __('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', __( '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', __('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', __( 'Offline Donation Instructions', 'give' ) ); |
|
183 | + $emails->__set('from_name', $from_name); |
|
184 | + $emails->__set('from_email', $from_email); |
|
185 | + $emails->__set('heading', __('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,50 +204,50 @@ 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>' . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n"; |
|
232 | - $admin_message .= '<strong>' . esc_attr__( 'Amount: ', 'give' ) . '</strong>' . html_entity_decode( $amount, ENT_COMPAT, 'UTF-8' ) . "\n\n"; |
|
231 | + $admin_message .= '<strong>'.esc_attr__('Donor: ', 'give').'</strong>'.html_entity_decode($name, ENT_COMPAT, 'UTF-8')."\n"; |
|
232 | + $admin_message .= '<strong>'.esc_attr__('Amount: ', 'give').'</strong>'.html_entity_decode($amount, ENT_COMPAT, 'UTF-8')."\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 | - __( '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 | + __('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 | - $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id ); |
|
242 | - $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id ); |
|
240 | + $admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id); |
|
241 | + $attachments = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id); |
|
242 | + $admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id); |
|
243 | 243 | |
244 | 244 | //Send Email |
245 | 245 | $emails = Give()->emails; |
246 | - if ( ! empty( $admin_headers ) ) { |
|
247 | - $emails->__set( 'headers', $admin_headers ); |
|
246 | + if ( ! empty($admin_headers)) { |
|
247 | + $emails->__set('headers', $admin_headers); |
|
248 | 248 | } |
249 | 249 | |
250 | - $emails->send( $admin_email, $admin_subject, $admin_message, $attachments ); |
|
250 | + $emails->send($admin_email, $admin_subject, $admin_message, $attachments); |
|
251 | 251 | |
252 | 252 | } |
253 | 253 | |
@@ -258,15 +258,15 @@ discard block |
||
258 | 258 | * @since 1.0 |
259 | 259 | * @return array |
260 | 260 | */ |
261 | -function give_offline_add_settings( $settings ) { |
|
261 | +function give_offline_add_settings($settings) { |
|
262 | 262 | |
263 | 263 | //Vars |
264 | 264 | $prefix = '_give_'; |
265 | 265 | |
266 | - $is_gateway_active = give_is_gateway_active( 'offline' ); |
|
266 | + $is_gateway_active = give_is_gateway_active('offline'); |
|
267 | 267 | |
268 | 268 | //this gateway isn't active |
269 | - if ( ! $is_gateway_active ) { |
|
269 | + if ( ! $is_gateway_active) { |
|
270 | 270 | //return settings and bounce |
271 | 271 | return $settings; |
272 | 272 | } |
@@ -275,27 +275,27 @@ discard block |
||
275 | 275 | $check_settings = array( |
276 | 276 | |
277 | 277 | array( |
278 | - 'name' => esc_attr__( 'Customize Offline Donations', 'give' ), |
|
279 | - 'desc' => esc_attr__( 'If you would like to customize the donation instructions for this specific forms check this option.', 'give' ), |
|
280 | - 'id' => $prefix . 'customize_offline_donations', |
|
278 | + 'name' => esc_attr__('Customize Offline Donations', 'give'), |
|
279 | + 'desc' => esc_attr__('If you would like to customize the donation instructions for this specific forms check this option.', 'give'), |
|
280 | + 'id' => $prefix.'customize_offline_donations', |
|
281 | 281 | 'type' => 'radio_inline', |
282 | 282 | 'default' => 'no', |
283 | 283 | 'options' => array( |
284 | - 'yes' => esc_attr__( 'Yes', 'give' ), |
|
285 | - 'no' => esc_attr__( 'No', 'give' ), |
|
284 | + 'yes' => esc_attr__('Yes', 'give'), |
|
285 | + 'no' => esc_attr__('No', 'give'), |
|
286 | 286 | ), |
287 | 287 | ), |
288 | 288 | array( |
289 | - 'name' => esc_attr__( 'Request Billing Information', 'give' ), |
|
290 | - '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' ), |
|
291 | - 'id' => $prefix . 'offline_donation_enable_billing_fields_single', |
|
289 | + 'name' => esc_attr__('Request Billing Information', 'give'), |
|
290 | + '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'), |
|
291 | + 'id' => $prefix.'offline_donation_enable_billing_fields_single', |
|
292 | 292 | 'row_classes' => 'give-subfield', |
293 | 293 | 'type' => 'checkbox' |
294 | 294 | ), |
295 | 295 | array( |
296 | - 'id' => $prefix . 'offline_checkout_notes', |
|
297 | - 'name' => esc_attr__( 'Offline Donation Instructions', 'give' ), |
|
298 | - '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' ), |
|
296 | + 'id' => $prefix.'offline_checkout_notes', |
|
297 | + 'name' => esc_attr__('Offline Donation Instructions', 'give'), |
|
298 | + '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'), |
|
299 | 299 | 'default' => give_get_default_offline_donation_content(), |
300 | 300 | 'type' => 'wysiwyg', |
301 | 301 | 'row_classes' => 'give-subfield', |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | ) |
305 | 305 | ), |
306 | 306 | array( |
307 | - 'id' => $prefix . 'offline_donation_subject', |
|
308 | - 'name' => esc_attr__( 'Offline Donation Email Instructions Subject', 'give' ), |
|
309 | - 'desc' => esc_attr__( 'Enter the subject line for the donation receipt email.', 'give' ), |
|
310 | - 'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), |
|
307 | + 'id' => $prefix.'offline_donation_subject', |
|
308 | + 'name' => esc_attr__('Offline Donation Email Instructions Subject', 'give'), |
|
309 | + 'desc' => esc_attr__('Enter the subject line for the donation receipt email.', 'give'), |
|
310 | + 'default' => esc_attr__('{donation} - Offline Donation Instructions', 'give'), |
|
311 | 311 | 'row_classes' => 'give-subfield', |
312 | 312 | 'type' => 'text' |
313 | 313 | ), |
314 | 314 | array( |
315 | - 'id' => $prefix . 'offline_donation_email', |
|
316 | - 'name' => esc_attr__( 'Offline Donation Email Instructions', 'give' ), |
|
317 | - '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' ), |
|
315 | + 'id' => $prefix.'offline_donation_email', |
|
316 | + 'name' => esc_attr__('Offline Donation Email Instructions', 'give'), |
|
317 | + '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'), |
|
318 | 318 | 'default' => give_get_default_offline_donation_email_content(), |
319 | 319 | 'type' => 'wysiwyg', |
320 | 320 | 'row_classes' => 'give-subfield', |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | ) |
325 | 325 | ); |
326 | 326 | |
327 | - return array_merge( $settings, $check_settings ); |
|
327 | + return array_merge($settings, $check_settings); |
|
328 | 328 | } |
329 | 329 | |
330 | -add_filter( 'give_forms_display_options_metabox_fields', 'give_offline_add_settings' ); |
|
330 | +add_filter('give_forms_display_options_metabox_fields', 'give_offline_add_settings'); |
|
331 | 331 | |
332 | 332 | |
333 | 333 | /** |
@@ -339,32 +339,32 @@ discard block |
||
339 | 339 | */ |
340 | 340 | function give_get_default_offline_donation_content() { |
341 | 341 | |
342 | - $sitename = get_bloginfo( 'sitename' ); |
|
342 | + $sitename = get_bloginfo('sitename'); |
|
343 | 343 | |
344 | - $default_text = '<p>' . esc_attr__( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>'; |
|
344 | + $default_text = '<p>'.esc_attr__('In order to make an offline donation we ask that you please follow these instructions', 'give').': </p>'; |
|
345 | 345 | $default_text .= '<ol>'; |
346 | 346 | $default_text .= '<li>'; |
347 | 347 | $default_text .= sprintf( |
348 | 348 | /* translators: %s: site name */ |
349 | - __( 'Make a check payable to "%s"', 'give' ), |
|
349 | + __('Make a check payable to "%s"', 'give'), |
|
350 | 350 | $sitename |
351 | 351 | ); |
352 | 352 | $default_text .= '</li>'; |
353 | 353 | $default_text .= '<li>'; |
354 | 354 | $default_text .= sprintf( |
355 | 355 | /* translators: %s: site name */ |
356 | - __( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ), |
|
356 | + __('On the memo line of the check, please indicate that the donation is for "%s"', 'give'), |
|
357 | 357 | $sitename |
358 | 358 | ); |
359 | 359 | $default_text .= '</li>'; |
360 | - $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>'; |
|
360 | + $default_text .= '<li>'.__('Please mail your check to:', 'give').'</li>'; |
|
361 | 361 | $default_text .= '</ol>'; |
362 | - $default_text .= ' <em>' . $sitename . '</em><br>'; |
|
362 | + $default_text .= ' <em>'.$sitename.'</em><br>'; |
|
363 | 363 | $default_text .= ' <em>123 G Street </em><br>'; |
364 | 364 | $default_text .= ' <em>San Diego, CA 92101 </em><br>'; |
365 | - $default_text .= '<p>' . esc_attr__( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>'; |
|
365 | + $default_text .= '<p>'.esc_attr__('All contributions will be gratefully acknowledged and are tax deductible.', 'give').'</p>'; |
|
366 | 366 | |
367 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
367 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
368 | 368 | |
369 | 369 | } |
370 | 370 | |
@@ -377,33 +377,33 @@ discard block |
||
377 | 377 | */ |
378 | 378 | function give_get_default_offline_donation_email_content() { |
379 | 379 | |
380 | - $sitename = get_bloginfo( 'sitename' ); |
|
381 | - $default_text = '<p>' . esc_attr__( 'Dear {name},', 'give' ) . '</p>'; |
|
382 | - $default_text .= '<p>' . esc_attr__( '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>'; |
|
380 | + $sitename = get_bloginfo('sitename'); |
|
381 | + $default_text = '<p>'.esc_attr__('Dear {name},', 'give').'</p>'; |
|
382 | + $default_text .= '<p>'.esc_attr__('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>'; |
|
383 | 383 | $default_text .= '<ol>'; |
384 | 384 | $default_text .= '<li>'; |
385 | 385 | $default_text .= sprintf( |
386 | 386 | /* translators: %s: site name */ |
387 | - __( 'Make a check payable to "%s"', 'give' ), |
|
387 | + __('Make a check payable to "%s"', 'give'), |
|
388 | 388 | $sitename |
389 | 389 | ); |
390 | 390 | $default_text .= '</li>'; |
391 | 391 | $default_text .= '<li>'; |
392 | 392 | $default_text .= sprintf( |
393 | 393 | /* translators: %s: site name */ |
394 | - __( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ), |
|
394 | + __('On the memo line of the check, please indicate that the donation is for "%s"', 'give'), |
|
395 | 395 | $sitename |
396 | 396 | ); |
397 | 397 | $default_text .= '</li>'; |
398 | - $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>'; |
|
398 | + $default_text .= '<li>'.__('Please mail your check to:', 'give').'</li>'; |
|
399 | 399 | $default_text .= '</ol>'; |
400 | - $default_text .= ' <em>' . $sitename . '</em><br>'; |
|
400 | + $default_text .= ' <em>'.$sitename.'</em><br>'; |
|
401 | 401 | $default_text .= ' <em>123 G Street </em><br>'; |
402 | 402 | $default_text .= ' <em>San Diego, CA 92101 </em><br>'; |
403 | - $default_text .= '<p>' . esc_attr__( '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>'; |
|
404 | - $default_text .= '<p>' . esc_attr__( 'Sincerely,', 'give' ) . '</p>'; |
|
405 | - $default_text .= '<p>' . $sitename . '</p>'; |
|
403 | + $default_text .= '<p>'.esc_attr__('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>'; |
|
404 | + $default_text .= '<p>'.esc_attr__('Sincerely,', 'give').'</p>'; |
|
405 | + $default_text .= '<p>'.$sitename.'</p>'; |
|
406 | 406 | |
407 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
407 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
408 | 408 | |
409 | 409 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 1.0 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @access private |
22 | 22 | * @since 1.0 |
23 | 23 | */ |
24 | -add_action( 'give_paypal_cc_form', '__return_false' ); |
|
24 | +add_action('give_paypal_cc_form', '__return_false'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Process PayPal Purchase |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return void |
34 | 34 | */ |
35 | -function give_process_paypal_purchase( $purchase_data ) { |
|
35 | +function give_process_paypal_purchase($purchase_data) { |
|
36 | 36 | |
37 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
38 | - wp_die( __( 'Nonce verification has failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(__('Nonce verification has failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | - $form_id = intval( $purchase_data['post_data']['give-form-id'] ); |
|
41 | + $form_id = intval($purchase_data['post_data']['give-form-id']); |
|
42 | 42 | $price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : ''; |
43 | 43 | |
44 | 44 | // Collect payment data |
@@ -57,67 +57,67 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Record the pending payment |
60 | - $payment = give_insert_payment( $payment_data ); |
|
60 | + $payment = give_insert_payment($payment_data); |
|
61 | 61 | |
62 | 62 | // Check payment |
63 | - if ( ! $payment ) { |
|
63 | + if ( ! $payment) { |
|
64 | 64 | // Record the error |
65 | 65 | give_record_gateway_error( |
66 | - __( 'Payment Error', 'give' ), |
|
66 | + __('Payment Error', 'give'), |
|
67 | 67 | sprintf( |
68 | 68 | /* translators: %s: payment data */ |
69 | - __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give' ), |
|
70 | - json_encode( $payment_data ) |
|
69 | + __('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), |
|
70 | + json_encode($payment_data) |
|
71 | 71 | ), |
72 | 72 | $payment |
73 | 73 | ); |
74 | 74 | // Problems? send back |
75 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
75 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
76 | 76 | } else { |
77 | 77 | // Only send to PayPal if the pending payment is created successfully |
78 | - $listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) ); |
|
78 | + $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php')); |
|
79 | 79 | |
80 | 80 | // Get the success url |
81 | - $return_url = add_query_arg( array( |
|
81 | + $return_url = add_query_arg(array( |
|
82 | 82 | 'payment-confirmation' => 'paypal', |
83 | 83 | 'payment-id' => $payment |
84 | 84 | |
85 | - ), get_permalink( give_get_option( 'success_page' ) ) ); |
|
85 | + ), get_permalink(give_get_option('success_page'))); |
|
86 | 86 | |
87 | 87 | // Get the PayPal redirect uri |
88 | - $paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?'; |
|
88 | + $paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?'; |
|
89 | 89 | |
90 | 90 | //Item name - pass level name if variable priced |
91 | 91 | $item_name = $purchase_data['post_data']['give-form-title']; |
92 | 92 | |
93 | 93 | //Verify has variable prices |
94 | - if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) { |
|
94 | + if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) { |
|
95 | 95 | |
96 | - $item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
96 | + $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']); |
|
97 | 97 | |
98 | - $price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
98 | + $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']); |
|
99 | 99 | |
100 | 100 | //Donation given doesn't match selected level (must be a custom amount) |
101 | - if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) { |
|
102 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
101 | + if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) { |
|
102 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
103 | 103 | //user custom amount text if any, fallback to default if not |
104 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) ); |
|
104 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
105 | 105 | |
106 | 106 | } //Is there any donation level text? |
107 | - elseif ( ! empty( $item_price_level_text ) ) { |
|
108 | - $item_name .= ' - ' . $item_price_level_text; |
|
107 | + elseif ( ! empty($item_price_level_text)) { |
|
108 | + $item_name .= ' - '.$item_price_level_text; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | } //Single donation: Custom Amount |
112 | - elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) { |
|
113 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
112 | + elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) { |
|
113 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
114 | 114 | //user custom amount text if any, fallback to default if not |
115 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) ); |
|
115 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give')); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Setup PayPal arguments |
119 | 119 | $paypal_args = array( |
120 | - 'business' => give_get_option( 'paypal_email', false ), |
|
120 | + 'business' => give_get_option('paypal_email', false), |
|
121 | 121 | 'email' => $purchase_data['user_email'], |
122 | 122 | 'invoice' => $purchase_data['purchase_key'], |
123 | 123 | 'amount' => $purchase_data['price'], |
@@ -128,25 +128,25 @@ discard block |
||
128 | 128 | 'shipping' => '0', |
129 | 129 | 'no_note' => '1', |
130 | 130 | 'currency_code' => give_get_currency(), |
131 | - 'charset' => get_bloginfo( 'charset' ), |
|
131 | + 'charset' => get_bloginfo('charset'), |
|
132 | 132 | 'custom' => $payment, |
133 | 133 | 'rm' => '2', |
134 | 134 | 'return' => $return_url, |
135 | - 'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ), |
|
135 | + 'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment), |
|
136 | 136 | 'notify_url' => $listener_url, |
137 | 137 | 'page_style' => give_get_paypal_page_style(), |
138 | - 'cbt' => get_bloginfo( 'name' ), |
|
138 | + 'cbt' => get_bloginfo('name'), |
|
139 | 139 | 'bn' => 'givewp_SP' |
140 | 140 | ); |
141 | 141 | |
142 | - if ( ! empty( $purchase_data['user_info']['address'] ) ) { |
|
142 | + if ( ! empty($purchase_data['user_info']['address'])) { |
|
143 | 143 | $paypal_args['address1'] = $purchase_data['user_info']['address']['line1']; |
144 | 144 | $paypal_args['address2'] = $purchase_data['user_info']['address']['line2']; |
145 | 145 | $paypal_args['city'] = $purchase_data['user_info']['address']['city']; |
146 | 146 | $paypal_args['country'] = $purchase_data['user_info']['address']['country']; |
147 | 147 | } |
148 | 148 | |
149 | - if ( give_get_option( 'paypal_button_type' ) === 'standard' ) { |
|
149 | + if (give_get_option('paypal_button_type') === 'standard') { |
|
150 | 150 | $paypal_extra_args = array( |
151 | 151 | 'cmd' => '_xclick', |
152 | 152 | ); |
@@ -156,23 +156,23 @@ discard block |
||
156 | 156 | ); |
157 | 157 | } |
158 | 158 | |
159 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
160 | - $paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data ); |
|
159 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
160 | + $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data); |
|
161 | 161 | |
162 | 162 | // Build query |
163 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
163 | + $paypal_redirect .= http_build_query($paypal_args); |
|
164 | 164 | |
165 | 165 | // Fix for some sites that encode the entities |
166 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
166 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
167 | 167 | |
168 | 168 | // Redirect to PayPal |
169 | - wp_redirect( $paypal_redirect ); |
|
169 | + wp_redirect($paypal_redirect); |
|
170 | 170 | exit; |
171 | 171 | } |
172 | 172 | |
173 | 173 | } |
174 | 174 | |
175 | -add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' ); |
|
175 | +add_action('give_gateway_paypal', 'give_process_paypal_purchase'); |
|
176 | 176 | |
177 | 177 | /** |
178 | 178 | * Listens for a PayPal IPN requests and then sends to the processing function |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | */ |
183 | 183 | function give_listen_for_paypal_ipn() { |
184 | 184 | // Regular PayPal IPN |
185 | - if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) { |
|
186 | - do_action( 'give_verify_paypal_ipn' ); |
|
185 | + if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') { |
|
186 | + do_action('give_verify_paypal_ipn'); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | -add_action( 'init', 'give_listen_for_paypal_ipn' ); |
|
190 | +add_action('init', 'give_listen_for_paypal_ipn'); |
|
191 | 191 | |
192 | 192 | /** |
193 | 193 | * Process PayPal IPN |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | function give_process_paypal_ipn() { |
199 | 199 | |
200 | 200 | // Check the request method is POST |
201 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
201 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | $post_data = ''; |
207 | 207 | |
208 | 208 | // Fallback just in case post_max_size is lower than needed |
209 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
210 | - $post_data = file_get_contents( 'php://input' ); |
|
209 | + if (ini_get('allow_url_fopen')) { |
|
210 | + $post_data = file_get_contents('php://input'); |
|
211 | 211 | } else { |
212 | 212 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
213 | - ini_set( 'post_max_size', '12M' ); |
|
213 | + ini_set('post_max_size', '12M'); |
|
214 | 214 | } |
215 | 215 | // Start the encoded data collection with notification command |
216 | 216 | $encoded_data = 'cmd=_notify-validate'; |
@@ -219,40 +219,40 @@ discard block |
||
219 | 219 | $arg_separator = give_get_php_arg_separator_output(); |
220 | 220 | |
221 | 221 | // Verify there is a post_data |
222 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
222 | + if ($post_data || strlen($post_data) > 0) { |
|
223 | 223 | // Append the data |
224 | - $encoded_data .= $arg_separator . $post_data; |
|
224 | + $encoded_data .= $arg_separator.$post_data; |
|
225 | 225 | } else { |
226 | 226 | // Check if POST is empty |
227 | - if ( empty( $_POST ) ) { |
|
227 | + if (empty($_POST)) { |
|
228 | 228 | // Nothing to do |
229 | 229 | return; |
230 | 230 | } else { |
231 | 231 | // Loop through each POST |
232 | - foreach ( $_POST as $key => $value ) { |
|
232 | + foreach ($_POST as $key => $value) { |
|
233 | 233 | // Encode the value and append the data |
234 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
234 | + $encoded_data .= $arg_separator."$key=".urlencode($value); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Convert collected post data to an array |
240 | - parse_str( $encoded_data, $encoded_data_array ); |
|
240 | + parse_str($encoded_data, $encoded_data_array); |
|
241 | 241 | |
242 | - foreach ( $encoded_data_array as $key => $value ) { |
|
242 | + foreach ($encoded_data_array as $key => $value) { |
|
243 | 243 | |
244 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
245 | - $new_key = str_replace( '&', '&', $key ); |
|
246 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
244 | + if (false !== strpos($key, 'amp;')) { |
|
245 | + $new_key = str_replace('&', '&', $key); |
|
246 | + $new_key = str_replace('amp;', '&', $new_key); |
|
247 | 247 | |
248 | - unset( $encoded_data_array[ $key ] ); |
|
249 | - $encoded_data_array[ $new_key ] = $value; |
|
248 | + unset($encoded_data_array[$key]); |
|
249 | + $encoded_data_array[$new_key] = $value; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | } |
253 | 253 | |
254 | 254 | //Validate IPN request w/ PayPal if user hasn't disabled this security measure |
255 | - if ( ! give_get_option( 'disable_paypal_verification' ) ) { |
|
255 | + if ( ! give_get_option('disable_paypal_verification')) { |
|
256 | 256 | |
257 | 257 | $remote_post_vars = array( |
258 | 258 | 'method' => 'POST', |
@@ -272,27 +272,27 @@ discard block |
||
272 | 272 | ); |
273 | 273 | |
274 | 274 | // Validate the IPN |
275 | - $api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars ); |
|
275 | + $api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars); |
|
276 | 276 | |
277 | - if ( is_wp_error( $api_response ) ) { |
|
277 | + if (is_wp_error($api_response)) { |
|
278 | 278 | give_record_gateway_error( |
279 | - __( 'IPN Error', 'give' ), |
|
279 | + __('IPN Error', 'give'), |
|
280 | 280 | sprintf( |
281 | 281 | /* translators: %s: Paypal IPN response */ |
282 | - __( 'Invalid IPN verification response. IPN data: %s', 'give' ), |
|
283 | - json_encode( $api_response ) |
|
282 | + __('Invalid IPN verification response. IPN data: %s', 'give'), |
|
283 | + json_encode($api_response) |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | return; // Something went wrong |
287 | 287 | } |
288 | 288 | |
289 | - if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) { |
|
289 | + if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) { |
|
290 | 290 | give_record_gateway_error( |
291 | - __( 'IPN Error', 'give' ), |
|
291 | + __('IPN Error', 'give'), |
|
292 | 292 | sprintf( |
293 | 293 | /* translators: %s: Paypal IPN response */ |
294 | - __( 'Invalid IPN verification response. IPN data: %s', 'give' ), |
|
295 | - json_encode( $api_response ) |
|
294 | + __('Invalid IPN verification response. IPN data: %s', 'give'), |
|
295 | + json_encode($api_response) |
|
296 | 296 | ) |
297 | 297 | ); |
298 | 298 | return; // Response not okay |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | // Check if $post_data_array has been populated |
304 | - if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) { |
|
304 | + if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
@@ -310,21 +310,21 @@ discard block |
||
310 | 310 | 'payment_status' => '' |
311 | 311 | ); |
312 | 312 | |
313 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
313 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
314 | 314 | |
315 | - $payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
315 | + $payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
316 | 316 | |
317 | - if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
317 | + if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) { |
|
318 | 318 | // Allow PayPal IPN types to be processed separately |
319 | - do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id ); |
|
319 | + do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id); |
|
320 | 320 | } else { |
321 | 321 | // Fallback to web accept just in case the txn_type isn't present |
322 | - do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id ); |
|
322 | + do_action('give_paypal_web_accept', $encoded_data_array, $payment_id); |
|
323 | 323 | } |
324 | 324 | exit; |
325 | 325 | } |
326 | 326 | |
327 | -add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' ); |
|
327 | +add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn'); |
|
328 | 328 | |
329 | 329 | /** |
330 | 330 | * Process web accept (one time) payment IPNs |
@@ -335,224 +335,224 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return void |
337 | 337 | */ |
338 | -function give_process_paypal_web_accept_and_cart( $data, $payment_id ) { |
|
338 | +function give_process_paypal_web_accept_and_cart($data, $payment_id) { |
|
339 | 339 | |
340 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
340 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - if ( empty( $payment_id ) ) { |
|
344 | + if (empty($payment_id)) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Collect payment details |
349 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
349 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
350 | 350 | $paypal_amount = $data['mc_gross']; |
351 | - $payment_status = strtolower( $data['payment_status'] ); |
|
352 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
353 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
354 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
351 | + $payment_status = strtolower($data['payment_status']); |
|
352 | + $currency_code = strtolower($data['mc_currency']); |
|
353 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
354 | + $payment_meta = give_get_payment_meta($payment_id); |
|
355 | 355 | |
356 | 356 | |
357 | - if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) { |
|
357 | + if (give_get_payment_gateway($payment_id) != 'paypal') { |
|
358 | 358 | return; // this isn't a PayPal standard IPN |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Verify payment recipient |
362 | - if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) { |
|
362 | + if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) { |
|
363 | 363 | |
364 | 364 | give_record_gateway_error( |
365 | - __( 'IPN Error', 'give' ), |
|
365 | + __('IPN Error', 'give'), |
|
366 | 366 | sprintf( |
367 | 367 | /* translators: %s: Paypal IPN response */ |
368 | - __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), |
|
369 | - json_encode( $data ) |
|
368 | + __('Invalid business email in IPN response. IPN data: %s', 'give'), |
|
369 | + json_encode($data) |
|
370 | 370 | ), |
371 | 371 | $payment_id |
372 | 372 | ); |
373 | - give_update_payment_status( $payment_id, 'failed' ); |
|
374 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) ); |
|
373 | + give_update_payment_status($payment_id, 'failed'); |
|
374 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give')); |
|
375 | 375 | |
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Verify payment currency |
380 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
380 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
381 | 381 | |
382 | 382 | give_record_gateway_error( |
383 | - __( 'IPN Error', 'give' ), |
|
383 | + __('IPN Error', 'give'), |
|
384 | 384 | sprintf( |
385 | 385 | /* translators: %s: Paypal IPN response */ |
386 | - __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), |
|
387 | - json_encode( $data ) |
|
386 | + __('Invalid currency in IPN response. IPN data: %s', 'give'), |
|
387 | + json_encode($data) |
|
388 | 388 | ), |
389 | 389 | $payment_id |
390 | 390 | ); |
391 | - give_update_payment_status( $payment_id, 'failed' ); |
|
392 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) ); |
|
391 | + give_update_payment_status($payment_id, 'failed'); |
|
392 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give')); |
|
393 | 393 | |
394 | 394 | return; |
395 | 395 | } |
396 | 396 | |
397 | - if ( ! give_get_payment_user_email( $payment_id ) ) { |
|
397 | + if ( ! give_get_payment_user_email($payment_id)) { |
|
398 | 398 | |
399 | 399 | // No email associated with purchase, so store from PayPal |
400 | - give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] ); |
|
400 | + give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']); |
|
401 | 401 | |
402 | 402 | // Setup and store the donors's details |
403 | 403 | $address = array(); |
404 | - $address['line1'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
405 | - $address['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
406 | - $address['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
407 | - $address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
408 | - $address['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
404 | + $address['line1'] = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
405 | + $address['city'] = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
406 | + $address['state'] = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
407 | + $address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
408 | + $address['zip'] = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
409 | 409 | |
410 | 410 | $user_info = array( |
411 | 411 | 'id' => '-1', |
412 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
413 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
414 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
412 | + 'email' => sanitize_text_field($data['payer_email']), |
|
413 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
414 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
415 | 415 | 'discount' => '', |
416 | 416 | 'address' => $address |
417 | 417 | ); |
418 | 418 | |
419 | 419 | $payment_meta['user_info'] = $user_info; |
420 | - give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta ); |
|
420 | + give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta); |
|
421 | 421 | } |
422 | 422 | |
423 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
423 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
424 | 424 | |
425 | 425 | // Process a refund |
426 | - give_process_paypal_refund( $data, $payment_id ); |
|
426 | + give_process_paypal_refund($data, $payment_id); |
|
427 | 427 | |
428 | 428 | } else { |
429 | 429 | |
430 | - if ( get_post_status( $payment_id ) == 'publish' ) { |
|
430 | + if (get_post_status($payment_id) == 'publish') { |
|
431 | 431 | return; // Only complete payments once |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Retrieve the total purchase amount (before PayPal) |
435 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
435 | + $payment_amount = give_get_payment_amount($payment_id); |
|
436 | 436 | |
437 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
437 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
438 | 438 | // The prices don't match |
439 | 439 | give_record_gateway_error( |
440 | - __( 'IPN Error', 'give' ), |
|
440 | + __('IPN Error', 'give'), |
|
441 | 441 | sprintf( |
442 | 442 | /* translators: %s: Paypal IPN response */ |
443 | - __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), |
|
444 | - json_encode( $data ) |
|
443 | + __('Invalid payment amount in IPN response. IPN data: %s', 'give'), |
|
444 | + json_encode($data) |
|
445 | 445 | ), |
446 | 446 | $payment_id |
447 | 447 | ); |
448 | - give_update_payment_status( $payment_id, 'failed' ); |
|
449 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) ); |
|
448 | + give_update_payment_status($payment_id, 'failed'); |
|
449 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give')); |
|
450 | 450 | |
451 | 451 | return; |
452 | 452 | } |
453 | - if ( $purchase_key != give_get_payment_key( $payment_id ) ) { |
|
453 | + if ($purchase_key != give_get_payment_key($payment_id)) { |
|
454 | 454 | // Purchase keys don't match |
455 | 455 | give_record_gateway_error( |
456 | - __( 'IPN Error', 'give' ), |
|
456 | + __('IPN Error', 'give'), |
|
457 | 457 | sprintf( |
458 | 458 | /* translators: %s: Paypal IPN response */ |
459 | - __( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), |
|
460 | - json_encode( $data ) |
|
459 | + __('Invalid purchase key in IPN response. IPN data: %s', 'give'), |
|
460 | + json_encode($data) |
|
461 | 461 | ), |
462 | 462 | $payment_id |
463 | 463 | ); |
464 | - give_update_payment_status( $payment_id, 'failed' ); |
|
465 | - give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) ); |
|
464 | + give_update_payment_status($payment_id, 'failed'); |
|
465 | + give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give')); |
|
466 | 466 | |
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - if ( $payment_status == 'completed' || give_is_test_mode() ) { |
|
470 | + if ($payment_status == 'completed' || give_is_test_mode()) { |
|
471 | 471 | give_insert_payment_note( |
472 | 472 | $payment_id, |
473 | 473 | sprintf( |
474 | 474 | /* translators: %s: Paypal transaction ID */ |
475 | - __( 'PayPal Transaction ID: %s', 'give' ), |
|
475 | + __('PayPal Transaction ID: %s', 'give'), |
|
476 | 476 | $data['txn_id'] |
477 | 477 | ) |
478 | 478 | ); |
479 | - give_set_payment_transaction_id( $payment_id, $data['txn_id'] ); |
|
480 | - give_update_payment_status( $payment_id, 'publish' ); |
|
481 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
479 | + give_set_payment_transaction_id($payment_id, $data['txn_id']); |
|
480 | + give_update_payment_status($payment_id, 'publish'); |
|
481 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
482 | 482 | |
483 | 483 | // Look for possible pending reasons, such as an echeck |
484 | 484 | |
485 | 485 | $note = ''; |
486 | 486 | |
487 | - switch ( strtolower( $data['pending_reason'] ) ) { |
|
487 | + switch (strtolower($data['pending_reason'])) { |
|
488 | 488 | |
489 | 489 | case 'echeck' : |
490 | 490 | |
491 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' ); |
|
491 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days.', 'give'); |
|
492 | 492 | |
493 | 493 | break; |
494 | 494 | |
495 | 495 | case 'address' : |
496 | 496 | |
497 | - $note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' ); |
|
497 | + $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give'); |
|
498 | 498 | |
499 | 499 | break; |
500 | 500 | |
501 | 501 | case 'intl' : |
502 | 502 | |
503 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' ); |
|
503 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations.', 'give'); |
|
504 | 504 | |
505 | 505 | break; |
506 | 506 | |
507 | 507 | case 'multi-currency' : |
508 | 508 | |
509 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' ); |
|
509 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give'); |
|
510 | 510 | |
511 | 511 | break; |
512 | 512 | |
513 | 513 | case 'paymentreview' : |
514 | 514 | case 'regulatory_review' : |
515 | 515 | |
516 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' ); |
|
516 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give'); |
|
517 | 517 | |
518 | 518 | break; |
519 | 519 | |
520 | 520 | case 'unilateral' : |
521 | 521 | |
522 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' ); |
|
522 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give'); |
|
523 | 523 | |
524 | 524 | break; |
525 | 525 | |
526 | 526 | case 'upgrade' : |
527 | 527 | |
528 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted.', 'give' ); |
|
528 | + $note = __('PayPal account must be upgraded before this payment can be accepted.', 'give'); |
|
529 | 529 | |
530 | 530 | break; |
531 | 531 | |
532 | 532 | case 'verify' : |
533 | 533 | |
534 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment.', 'give' ); |
|
534 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment.', 'give'); |
|
535 | 535 | |
536 | 536 | break; |
537 | 537 | |
538 | 538 | case 'other' : |
539 | 539 | |
540 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' ); |
|
540 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give'); |
|
541 | 541 | |
542 | 542 | break; |
543 | 543 | |
544 | 544 | } |
545 | 545 | |
546 | - if ( ! empty( $note ) ) { |
|
546 | + if ( ! empty($note)) { |
|
547 | 547 | |
548 | - give_insert_payment_note( $payment_id, $note ); |
|
548 | + give_insert_payment_note($payment_id, $note); |
|
549 | 549 | |
550 | 550 | } |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | -add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 ); |
|
555 | +add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2); |
|
556 | 556 | |
557 | 557 | /** |
558 | 558 | * Process PayPal IPN Refunds |
@@ -563,28 +563,28 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @return void |
565 | 565 | */ |
566 | -function give_process_paypal_refund( $data, $payment_id = 0 ) { |
|
566 | +function give_process_paypal_refund($data, $payment_id = 0) { |
|
567 | 567 | |
568 | 568 | // Collect payment details |
569 | 569 | |
570 | - if ( empty( $payment_id ) ) { |
|
570 | + if (empty($payment_id)) { |
|
571 | 571 | return; |
572 | 572 | } |
573 | 573 | |
574 | - if ( get_post_status( $payment_id ) == 'refunded' ) { |
|
574 | + if (get_post_status($payment_id) == 'refunded') { |
|
575 | 575 | return; // Only refund payments once |
576 | 576 | } |
577 | 577 | |
578 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
578 | + $payment_amount = give_get_payment_amount($payment_id); |
|
579 | 579 | $refund_amount = $data['payment_gross'] * - 1; |
580 | 580 | |
581 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
581 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
582 | 582 | |
583 | 583 | give_insert_payment_note( |
584 | 584 | $payment_id, |
585 | 585 | sprintf( |
586 | 586 | /* translators: %s: Paypal parent transaction ID */ |
587 | - __( 'Partial PayPal refund processed: %s', 'give' ), |
|
587 | + __('Partial PayPal refund processed: %s', 'give'), |
|
588 | 588 | $data['parent_txn_id'] |
589 | 589 | ) |
590 | 590 | ); |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | $payment_id, |
598 | 598 | sprintf( |
599 | 599 | /* translators: %s: Paypal parent transaction ID */ |
600 | - __( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), |
|
600 | + __('PayPal Payment #%s Refunded for reason: %s', 'give'), |
|
601 | 601 | $data['parent_txn_id'], $data['reason_code'] |
602 | 602 | ) |
603 | 603 | ); |
@@ -605,11 +605,11 @@ discard block |
||
605 | 605 | $payment_id, |
606 | 606 | sprintf( |
607 | 607 | /* translators: %s: Paypal transaction ID */ |
608 | - __( 'PayPal Refund Transaction ID: %s', 'give' ), |
|
608 | + __('PayPal Refund Transaction ID: %s', 'give'), |
|
609 | 609 | $data['txn_id'] |
610 | 610 | ) |
611 | 611 | ); |
612 | - give_update_payment_status( $payment_id, 'refunded' ); |
|
612 | + give_update_payment_status($payment_id, 'refunded'); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | /** |
@@ -621,24 +621,24 @@ discard block |
||
621 | 621 | * |
622 | 622 | * @return string |
623 | 623 | */ |
624 | -function give_get_paypal_redirect( $ssl_check = false ) { |
|
624 | +function give_get_paypal_redirect($ssl_check = false) { |
|
625 | 625 | |
626 | - if ( is_ssl() || ! $ssl_check ) { |
|
626 | + if (is_ssl() || ! $ssl_check) { |
|
627 | 627 | $protocal = 'https://'; |
628 | 628 | } else { |
629 | 629 | $protocal = 'http://'; |
630 | 630 | } |
631 | 631 | |
632 | 632 | // Check the current payment mode |
633 | - if ( give_is_test_mode() ) { |
|
633 | + if (give_is_test_mode()) { |
|
634 | 634 | // Test mode |
635 | - $paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
635 | + $paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
636 | 636 | } else { |
637 | 637 | // Live mode |
638 | - $paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr'; |
|
638 | + $paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr'; |
|
639 | 639 | } |
640 | 640 | |
641 | - return apply_filters( 'give_paypal_uri', $paypal_uri ); |
|
641 | + return apply_filters('give_paypal_uri', $paypal_uri); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
@@ -648,8 +648,8 @@ discard block |
||
648 | 648 | * @return string |
649 | 649 | */ |
650 | 650 | function give_get_paypal_page_style() { |
651 | - $page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) ); |
|
652 | - return apply_filters( 'give_paypal_page_style', $page_style ); |
|
651 | + $page_style = trim(give_get_option('paypal_page_style', 'PayPal')); |
|
652 | + return apply_filters('give_paypal_page_style', $page_style); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -664,27 +664,27 @@ discard block |
||
664 | 664 | * @return string |
665 | 665 | * |
666 | 666 | */ |
667 | -function give_paypal_success_page_content( $content ) { |
|
667 | +function give_paypal_success_page_content($content) { |
|
668 | 668 | |
669 | - if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) { |
|
669 | + if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) { |
|
670 | 670 | return $content; |
671 | 671 | } |
672 | 672 | |
673 | - $payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false; |
|
673 | + $payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false; |
|
674 | 674 | |
675 | - if ( ! $payment_id ) { |
|
675 | + if ( ! $payment_id) { |
|
676 | 676 | $session = give_get_purchase_session(); |
677 | - $payment_id = give_get_purchase_id_by_key( $session['purchase_key'] ); |
|
677 | + $payment_id = give_get_purchase_id_by_key($session['purchase_key']); |
|
678 | 678 | } |
679 | 679 | |
680 | - $payment = get_post( $payment_id ); |
|
680 | + $payment = get_post($payment_id); |
|
681 | 681 | |
682 | - if ( $payment && 'pending' == $payment->post_status ) { |
|
682 | + if ($payment && 'pending' == $payment->post_status) { |
|
683 | 683 | |
684 | 684 | // Payment is still pending so show processing indicator to fix the Race Condition |
685 | 685 | ob_start(); |
686 | 686 | |
687 | - give_get_template_part( 'payment', 'processing' ); |
|
687 | + give_get_template_part('payment', 'processing'); |
|
688 | 688 | |
689 | 689 | $content = ob_get_clean(); |
690 | 690 | |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | |
695 | 695 | } |
696 | 696 | |
697 | -add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' ); |
|
697 | +add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content'); |
|
698 | 698 | |
699 | 699 | /** |
700 | 700 | * Given a Payment ID, extract the transaction ID |
@@ -705,22 +705,22 @@ discard block |
||
705 | 705 | * |
706 | 706 | * @return string Transaction ID |
707 | 707 | */ |
708 | -function give_paypal_get_payment_transaction_id( $payment_id ) { |
|
708 | +function give_paypal_get_payment_transaction_id($payment_id) { |
|
709 | 709 | |
710 | 710 | $transaction_id = ''; |
711 | - $notes = give_get_payment_notes( $payment_id ); |
|
711 | + $notes = give_get_payment_notes($payment_id); |
|
712 | 712 | |
713 | - foreach ( $notes as $note ) { |
|
714 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
713 | + foreach ($notes as $note) { |
|
714 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
715 | 715 | $transaction_id = $match[1]; |
716 | 716 | continue; |
717 | 717 | } |
718 | 718 | } |
719 | 719 | |
720 | - return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
720 | + return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id); |
|
721 | 721 | } |
722 | 722 | |
723 | -add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 ); |
|
723 | +add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1); |
|
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Given a transaction ID, generate a link to the PayPal transaction ID details |
@@ -732,13 +732,13 @@ discard block |
||
732 | 732 | * |
733 | 733 | * @return string A link to the PayPal transaction details |
734 | 734 | */ |
735 | -function give_paypal_link_transaction_id( $transaction_id, $payment_id ) { |
|
735 | +function give_paypal_link_transaction_id($transaction_id, $payment_id) { |
|
736 | 736 | |
737 | 737 | $paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id='; |
738 | - $transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
738 | + $transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>'; |
|
739 | 739 | |
740 | - return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url ); |
|
740 | + return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url); |
|
741 | 741 | |
742 | 742 | } |
743 | 743 | |
744 | -add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 ); |
|
744 | +add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -50,50 +50,50 @@ discard block |
||
50 | 50 | */ |
51 | 51 | |
52 | 52 | // https://gist.github.com/justinph/5197810 |
53 | - function validate_gravatar( $id_or_email ) { |
|
53 | + function validate_gravatar($id_or_email) { |
|
54 | 54 | //id or email code borrowed from wp-includes/pluggable.php |
55 | 55 | $email = ''; |
56 | - if ( is_numeric( $id_or_email ) ) { |
|
56 | + if (is_numeric($id_or_email)) { |
|
57 | 57 | $id = (int) $id_or_email; |
58 | - $user = get_userdata( $id ); |
|
59 | - if ( $user ) { |
|
58 | + $user = get_userdata($id); |
|
59 | + if ($user) { |
|
60 | 60 | $email = $user->user_email; |
61 | 61 | } |
62 | - } elseif ( is_object( $id_or_email ) ) { |
|
62 | + } elseif (is_object($id_or_email)) { |
|
63 | 63 | // No avatar for pingbacks or trackbacks |
64 | - $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
|
65 | - if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) { |
|
64 | + $allowed_comment_types = apply_filters('get_avatar_comment_types', array('comment')); |
|
65 | + if ( ! empty($id_or_email->comment_type) && ! in_array($id_or_email->comment_type, (array) $allowed_comment_types)) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $id_or_email->user_id ) ) { |
|
69 | + if ( ! empty($id_or_email->user_id)) { |
|
70 | 70 | $id = (int) $id_or_email->user_id; |
71 | - $user = get_userdata( $id ); |
|
72 | - if ( $user ) { |
|
71 | + $user = get_userdata($id); |
|
72 | + if ($user) { |
|
73 | 73 | $email = $user->user_email; |
74 | 74 | } |
75 | - } elseif ( ! empty( $id_or_email->comment_author_email ) ) { |
|
75 | + } elseif ( ! empty($id_or_email->comment_author_email)) { |
|
76 | 76 | $email = $id_or_email->comment_author_email; |
77 | 77 | } |
78 | 78 | } else { |
79 | 79 | $email = $id_or_email; |
80 | 80 | } |
81 | 81 | |
82 | - $hashkey = md5( strtolower( trim( $email ) ) ); |
|
83 | - $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404'; |
|
82 | + $hashkey = md5(strtolower(trim($email))); |
|
83 | + $uri = 'http://www.gravatar.com/avatar/'.$hashkey.'?d=404'; |
|
84 | 84 | |
85 | - $data = wp_cache_get( $hashkey ); |
|
86 | - if ( false === $data ) { |
|
87 | - $response = wp_remote_head( $uri ); |
|
88 | - if ( is_wp_error( $response ) ) { |
|
85 | + $data = wp_cache_get($hashkey); |
|
86 | + if (false === $data) { |
|
87 | + $response = wp_remote_head($uri); |
|
88 | + if (is_wp_error($response)) { |
|
89 | 89 | $data = 'not200'; |
90 | 90 | } else { |
91 | 91 | $data = $response['response']['code']; |
92 | 92 | } |
93 | - wp_cache_set( $hashkey, $data, $group = '', $expire = 60 * 5 ); |
|
93 | + wp_cache_set($hashkey, $data, $group = '', $expire = 60 * 5); |
|
94 | 94 | |
95 | 95 | } |
96 | - if ( $data == '200' ) { |
|
96 | + if ($data == '200') { |
|
97 | 97 | return true; |
98 | 98 | } else { |
99 | 99 | return false; |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param int $form_id |
110 | 110 | */ |
111 | - function get_log_ids( $form_id = '' ) { |
|
111 | + function get_log_ids($form_id = '') { |
|
112 | 112 | |
113 | 113 | // get Give_Logging class |
114 | 114 | global $give_logs; |
115 | 115 | |
116 | 116 | // get log for this form |
117 | - $logs = $give_logs->get_logs( $form_id ); |
|
117 | + $logs = $give_logs->get_logs($form_id); |
|
118 | 118 | |
119 | - if ( $logs ) { |
|
119 | + if ($logs) { |
|
120 | 120 | // make an array with all the donor IDs |
121 | - foreach ( $logs as $log ) { |
|
121 | + foreach ($logs as $log) { |
|
122 | 122 | $log_ids[] = $log->ID; |
123 | 123 | } |
124 | 124 | |
@@ -135,49 +135,49 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @since 1.0 |
137 | 137 | */ |
138 | - function get_payment_ids( $form_id = '' ) { |
|
138 | + function get_payment_ids($form_id = '') { |
|
139 | 139 | |
140 | 140 | global $give_options; |
141 | 141 | |
142 | - $log_ids = $this->get_log_ids( $form_id ); |
|
142 | + $log_ids = $this->get_log_ids($form_id); |
|
143 | 143 | |
144 | - if ( $log_ids ) { |
|
144 | + if ($log_ids) { |
|
145 | 145 | |
146 | 146 | $payment_ids = array(); |
147 | 147 | |
148 | - foreach ( $log_ids as $id ) { |
|
148 | + foreach ($log_ids as $id) { |
|
149 | 149 | // get the payment ID for each corresponding log ID |
150 | - $payment_ids[] = get_post_meta( $id, '_give_log_payment_id', true ); |
|
150 | + $payment_ids[] = get_post_meta($id, '_give_log_payment_id', true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // remove donors who have purchased more than once so we can have unique avatars |
154 | 154 | $unique_emails = array(); |
155 | 155 | |
156 | - foreach ( $payment_ids as $key => $id ) { |
|
156 | + foreach ($payment_ids as $key => $id) { |
|
157 | 157 | |
158 | - $email = get_post_meta( $id, '_give_payment_user_email', true ); |
|
158 | + $email = get_post_meta($id, '_give_payment_user_email', true); |
|
159 | 159 | |
160 | - if ( isset ( $give_options['give_donators_gravatars_has_gravatar_account'] ) ) { |
|
161 | - if ( ! $this->validate_gravatar( $email ) ) { |
|
160 | + if (isset ($give_options['give_donators_gravatars_has_gravatar_account'])) { |
|
161 | + if ( ! $this->validate_gravatar($email)) { |
|
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - $unique_emails[ $id ] = get_post_meta( $id, '_give_payment_user_email', true ); |
|
166 | + $unique_emails[$id] = get_post_meta($id, '_give_payment_user_email', true); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | 170 | // strip duplicate emails |
171 | - $unique_emails = array_unique( $unique_emails ); |
|
171 | + $unique_emails = array_unique($unique_emails); |
|
172 | 172 | |
173 | 173 | // convert the unique IDs back into simple array |
174 | - foreach ( $unique_emails as $id => $email ) { |
|
174 | + foreach ($unique_emails as $id => $email) { |
|
175 | 175 | $unique_ids[] = $id; |
176 | 176 | } |
177 | 177 | |
178 | 178 | // randomize the payment IDs if enabled |
179 | - if ( isset( $give_options['give_donators_gravatars_random_gravatars'] ) ) { |
|
180 | - shuffle( $unique_ids ); |
|
179 | + if (isset($give_options['give_donators_gravatars_random_gravatars'])) { |
|
180 | + shuffle($unique_ids); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // return our unique IDs |
@@ -193,22 +193,22 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @since 1.0 |
195 | 195 | */ |
196 | - function gravatars( $form_id = false, $title = '' ) { |
|
196 | + function gravatars($form_id = false, $title = '') { |
|
197 | 197 | |
198 | 198 | // unique $payment_ids |
199 | - $payment_ids = $this->get_payment_ids( $form_id ); |
|
199 | + $payment_ids = $this->get_payment_ids($form_id); |
|
200 | 200 | |
201 | 201 | global $give_options; |
202 | 202 | |
203 | 203 | // return if no ID |
204 | - if ( ! $form_id ) { |
|
204 | + if ( ! $form_id) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // minimum amount of purchases before showing gravatars |
209 | 209 | // if the number of items in array is not greater or equal to the number specified, then exit |
210 | - if ( isset( $give_options['give_donators_gravatars_min_purchases_required'] ) && '' != $give_options['give_donators_gravatars_min_purchases_required'] ) { |
|
211 | - if ( ! ( count( $payment_ids ) >= $give_options['give_donators_gravatars_min_purchases_required'] ) ) { |
|
210 | + if (isset($give_options['give_donators_gravatars_min_purchases_required']) && '' != $give_options['give_donators_gravatars_min_purchases_required']) { |
|
211 | + if ( ! (count($payment_ids) >= $give_options['give_donators_gravatars_min_purchases_required'])) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | } |
@@ -219,51 +219,51 @@ discard block |
||
219 | 219 | echo '<div id="give-purchase-gravatars">'; |
220 | 220 | |
221 | 221 | |
222 | - if ( isset ( $title ) ) { |
|
222 | + if (isset ($title)) { |
|
223 | 223 | |
224 | - if ( $title ) { |
|
225 | - echo apply_filters( 'give_donators_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $title ) . '</h3>' ); |
|
226 | - } elseif ( isset( $give_options['give_donators_gravatars_heading'] ) ) { |
|
227 | - echo apply_filters( 'give_donators_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $give_options['give_donators_gravatars_heading'] ) . '</h2>' ); |
|
224 | + if ($title) { |
|
225 | + echo apply_filters('give_donators_gravatars_title', '<h3 class="give-gravatars-title">'.esc_attr($title).'</h3>'); |
|
226 | + } elseif (isset($give_options['give_donators_gravatars_heading'])) { |
|
227 | + echo apply_filters('give_donators_gravatars_title', '<h3 class="give-gravatars-title">'.esc_attr($give_options['give_donators_gravatars_heading']).'</h2>'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | } |
231 | 231 | echo '<ul class="give-purchase-gravatars-list">'; |
232 | 232 | $i = 0; |
233 | 233 | |
234 | - if ( $payment_ids ) { |
|
235 | - foreach ( $payment_ids as $id ) { |
|
234 | + if ($payment_ids) { |
|
235 | + foreach ($payment_ids as $id) { |
|
236 | 236 | |
237 | 237 | // Give saves a blank option even when the control is turned off, hence the extra check |
238 | - if ( isset( $give_options['give_donators_gravatars_maximum_number'] ) && '' != $give_options['give_donators_gravatars_maximum_number'] && $i == $give_options['give_donators_gravatars_maximum_number'] ) { |
|
238 | + if (isset($give_options['give_donators_gravatars_maximum_number']) && '' != $give_options['give_donators_gravatars_maximum_number'] && $i == $give_options['give_donators_gravatars_maximum_number']) { |
|
239 | 239 | continue; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // get the payment meta |
243 | - $payment_meta = get_post_meta( $id, '_give_payment_meta', true ); |
|
243 | + $payment_meta = get_post_meta($id, '_give_payment_meta', true); |
|
244 | 244 | |
245 | 245 | // unserialize the payment meta |
246 | - $user_info = maybe_unserialize( $payment_meta['user_info'] ); |
|
246 | + $user_info = maybe_unserialize($payment_meta['user_info']); |
|
247 | 247 | |
248 | 248 | // get donor's first name |
249 | 249 | $name = $user_info['first_name']; |
250 | 250 | |
251 | 251 | // get donor's email |
252 | - $email = get_post_meta( $id, '_give_payment_user_email', true ); |
|
252 | + $email = get_post_meta($id, '_give_payment_user_email', true); |
|
253 | 253 | |
254 | 254 | // set gravatar size and provide filter |
255 | - $size = isset( $give_options['give_donators_gravatars_gravatar_size'] ) ? apply_filters( 'give_donators_gravatars_gravatar_size', $give_options['give_donators_gravatars_gravatar_size'] ) : ''; |
|
255 | + $size = isset($give_options['give_donators_gravatars_gravatar_size']) ? apply_filters('give_donators_gravatars_gravatar_size', $give_options['give_donators_gravatars_gravatar_size']) : ''; |
|
256 | 256 | |
257 | 257 | // default image |
258 | - $default_image = apply_filters( 'give_donators_gravatars_gravatar_default_image', false ); |
|
258 | + $default_image = apply_filters('give_donators_gravatars_gravatar_default_image', false); |
|
259 | 259 | |
260 | 260 | // assemble output |
261 | 261 | $output .= '<li>'; |
262 | 262 | |
263 | - $output .= get_avatar( $email, $size, $default_image, $name ); |
|
263 | + $output .= get_avatar($email, $size, $default_image, $name); |
|
264 | 264 | $output .= '</li>'; |
265 | 265 | |
266 | - $i ++; |
|
266 | + $i++; |
|
267 | 267 | |
268 | 268 | } // end foreach |
269 | 269 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | echo '</ul>'; |
273 | 273 | echo '</div>'; |
274 | 274 | |
275 | - return apply_filters( 'give_donators_gravatars', ob_get_clean() ); |
|
275 | + return apply_filters('give_donators_gravatars', ob_get_clean()); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @since 1.0 |
282 | 282 | */ |
283 | 283 | function register_widget() { |
284 | - register_widget( 'Give_Donators_Gravatars_Widget' ); |
|
284 | + register_widget('Give_Donators_Gravatars_Widget'); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -290,19 +290,19 @@ discard block |
||
290 | 290 | * @since 1.0 |
291 | 291 | * @todo set the ID to get_the_ID() if ID parameter is not passed through. Otherwise it will incorrectly get other gravatars |
292 | 292 | */ |
293 | - function shortcode( $atts, $content = null ) { |
|
293 | + function shortcode($atts, $content = null) { |
|
294 | 294 | |
295 | - $atts = shortcode_atts( array( |
|
295 | + $atts = shortcode_atts(array( |
|
296 | 296 | 'id' => '', |
297 | 297 | 'title' => '' |
298 | - ), $atts, 'give_donators_gravatars' ); |
|
298 | + ), $atts, 'give_donators_gravatars'); |
|
299 | 299 | |
300 | 300 | // if no ID is passed on single give_forms pages, get the correct ID |
301 | - if ( is_singular( 'give_forms' ) ) { |
|
301 | + if (is_singular('give_forms')) { |
|
302 | 302 | $id = get_the_ID(); |
303 | 303 | } |
304 | 304 | |
305 | - $content = $this->gravatars( $atts['id'], $atts['title'] ); |
|
305 | + $content = $this->gravatars($atts['id'], $atts['title']); |
|
306 | 306 | |
307 | 307 | return $content; |
308 | 308 | |
@@ -313,57 +313,57 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @since 1.0 |
315 | 315 | */ |
316 | - function settings( $settings ) { |
|
316 | + function settings($settings) { |
|
317 | 317 | |
318 | 318 | $give_gravatar_settings = array( |
319 | 319 | array( |
320 | - 'name' => __( 'Donator Gravatars', 'give' ), |
|
320 | + 'name' => __('Donator Gravatars', 'give'), |
|
321 | 321 | 'desc' => '<hr>', |
322 | 322 | 'id' => 'give_title', |
323 | 323 | 'type' => 'give_title' |
324 | 324 | ), |
325 | 325 | array( |
326 | - 'name' => __( 'Heading', 'give' ), |
|
327 | - 'desc' => __( 'The heading to display above the Gravatars', 'give' ), |
|
326 | + 'name' => __('Heading', 'give'), |
|
327 | + 'desc' => __('The heading to display above the Gravatars', 'give'), |
|
328 | 328 | 'type' => 'text', |
329 | 329 | 'id' => 'give_donators_gravatars_heading' |
330 | 330 | ), |
331 | 331 | array( |
332 | - 'name' => __( 'Gravatar Size', 'give' ), |
|
333 | - 'desc' => __( 'The size of each Gravatar in pixels (512px maximum)', 'give' ), |
|
332 | + 'name' => __('Gravatar Size', 'give'), |
|
333 | + 'desc' => __('The size of each Gravatar in pixels (512px maximum)', 'give'), |
|
334 | 334 | 'type' => 'text_small', |
335 | 335 | 'id' => 'give_donators_gravatars_gravatar_size', |
336 | 336 | 'default' => '64' |
337 | 337 | ), |
338 | 338 | array( |
339 | - 'name' => __( 'Minimum Unique Purchases Required', 'give' ), |
|
339 | + 'name' => __('Minimum Unique Purchases Required', 'give'), |
|
340 | 340 | /* translators: %s: form singular label */ |
341 | - 'desc' => sprintf( __( 'The minimum number of unique purchases a %s must have before the Gravatars are shown. Leave blank for no minimum.', 'give' ), strtolower( give_get_forms_label_singular() ) ), |
|
341 | + 'desc' => sprintf(__('The minimum number of unique purchases a %s must have before the Gravatars are shown. Leave blank for no minimum.', 'give'), strtolower(give_get_forms_label_singular())), |
|
342 | 342 | 'type' => 'text_small', |
343 | 343 | 'id' => 'give_donators_gravatars_min_purchases_required', |
344 | 344 | ), |
345 | 345 | array( |
346 | - 'name' => __( 'Maximum Gravatars To Show', 'give' ), |
|
347 | - 'desc' => __( 'The maximum number of gravatars to show. Leave blank for no limit.', 'give' ), |
|
346 | + 'name' => __('Maximum Gravatars To Show', 'give'), |
|
347 | + 'desc' => __('The maximum number of gravatars to show. Leave blank for no limit.', 'give'), |
|
348 | 348 | 'type' => 'text', |
349 | 349 | 'id' => 'give_donators_gravatars_maximum_number', |
350 | 350 | 'default' => '20', |
351 | 351 | ), |
352 | 352 | array( |
353 | - 'name' => __( 'Gravatar Visibility', 'give' ), |
|
354 | - 'desc' => __( 'Only show donators with a Gravatar account', 'give' ), |
|
353 | + 'name' => __('Gravatar Visibility', 'give'), |
|
354 | + 'desc' => __('Only show donators with a Gravatar account', 'give'), |
|
355 | 355 | 'id' => 'give_donators_gravatars_has_gravatar_account', |
356 | 356 | 'type' => 'checkbox', |
357 | 357 | ), |
358 | 358 | array( |
359 | - 'name' => __( 'Randomize Gravatars', 'give' ), |
|
360 | - 'desc' => __( 'Randomize the Gravatars', 'give' ), |
|
359 | + 'name' => __('Randomize Gravatars', 'give'), |
|
360 | + 'desc' => __('Randomize the Gravatars', 'give'), |
|
361 | 361 | 'id' => 'give_donators_gravatars_random_gravatars', |
362 | 362 | 'type' => 'checkbox', |
363 | 363 | ), |
364 | 364 | ); |
365 | 365 | |
366 | - return array_merge( $settings, $give_gravatar_settings ); |
|
366 | + return array_merge($settings, $give_gravatar_settings); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | } |
@@ -381,13 +381,13 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function __construct() { |
383 | 383 | |
384 | - $give_label_singular = function_exists( 'give_get_forms_label_singular' ) ? strtolower( give_get_forms_label_singular() ) : null; |
|
384 | + $give_label_singular = function_exists('give_get_forms_label_singular') ? strtolower(give_get_forms_label_singular()) : null; |
|
385 | 385 | |
386 | 386 | // widget settings |
387 | 387 | $widget_ops = array( |
388 | 388 | 'classname' => 'give-donators-gravatars', |
389 | 389 | /* translators: 1: form singular label 2: form singular label */ |
390 | - 'description' => sprintf( __( 'Displays gravatars of people who have donated using your your %1$s. Will only show on the single %2$s page.', 'give' ), $give_label_singular, $give_label_singular ) |
|
390 | + 'description' => sprintf(__('Displays gravatars of people who have donated using your your %1$s. Will only show on the single %2$s page.', 'give'), $give_label_singular, $give_label_singular) |
|
391 | 391 | ); |
392 | 392 | |
393 | 393 | // widget control settings |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | // create the widget |
401 | 401 | parent::__construct( |
402 | 402 | 'give_donators_gravatars_widget', |
403 | - __( 'Give Donators Gravatars', 'give' ), |
|
403 | + __('Give Donators Gravatars', 'give'), |
|
404 | 404 | $widget_ops, |
405 | 405 | $control_ops |
406 | 406 | ); |
@@ -411,30 +411,30 @@ discard block |
||
411 | 411 | /* |
412 | 412 | * Outputs the content of the widget |
413 | 413 | */ |
414 | - function widget( $args, $instance ) { |
|
414 | + function widget($args, $instance) { |
|
415 | 415 | global $give_options; |
416 | 416 | |
417 | 417 | //@TODO: Don't extract it!!! |
418 | - extract( $args ); |
|
418 | + extract($args); |
|
419 | 419 | |
420 | - if ( ! is_singular( 'give_forms' ) ) { |
|
420 | + if ( ! is_singular('give_forms')) { |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Variables from widget settings |
425 | - $title = apply_filters( 'widget_title', $instance['title'] ); |
|
425 | + $title = apply_filters('widget_title', $instance['title']); |
|
426 | 426 | |
427 | 427 | // Used by themes. Opens the widget |
428 | 428 | echo $before_widget; |
429 | 429 | |
430 | 430 | // Display the widget title |
431 | - if ( $title ) { |
|
432 | - echo $before_title . $title . $after_title; |
|
431 | + if ($title) { |
|
432 | + echo $before_title.$title.$after_title; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $gravatars = new Give_Donators_Gravatars(); |
436 | 436 | |
437 | - echo $gravatars->gravatars( get_the_ID(), null ); // remove title |
|
437 | + echo $gravatars->gravatars(get_the_ID(), null); // remove title |
|
438 | 438 | |
439 | 439 | // Used by themes. Closes the widget |
440 | 440 | echo $after_widget; |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | /* |
445 | 445 | * Update function. Processes widget options to be saved |
446 | 446 | */ |
447 | - function update( $new_instance, $old_instance ) { |
|
447 | + function update($new_instance, $old_instance) { |
|
448 | 448 | |
449 | 449 | $instance = $old_instance; |
450 | 450 | |
451 | - $instance['title'] = strip_tags( $new_instance['title'] ); |
|
451 | + $instance['title'] = strip_tags($new_instance['title']); |
|
452 | 452 | |
453 | 453 | return $instance; |
454 | 454 | |
@@ -457,19 +457,19 @@ discard block |
||
457 | 457 | /* |
458 | 458 | * Form function. Displays the actual form on the widget page |
459 | 459 | */ |
460 | - function form( $instance ) { |
|
460 | + function form($instance) { |
|
461 | 461 | |
462 | 462 | // Set up some default widget settings. |
463 | 463 | $defaults = array( |
464 | 464 | 'title' => '', |
465 | 465 | ); |
466 | 466 | |
467 | - $instance = wp_parse_args( (array) $instance, $defaults ); ?> |
|
467 | + $instance = wp_parse_args((array) $instance, $defaults); ?> |
|
468 | 468 | |
469 | 469 | <!-- Title --> |
470 | 470 | <p> |
471 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'give' ) ?></label> |
|
472 | - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" /> |
|
471 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'give') ?></label> |
|
472 | + <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" /> |
|
473 | 473 | </p> |
474 | 474 | |
475 | 475 |
@@ -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 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return string $output Give forms dropdown |
35 | 35 | */ |
36 | - public function forms_dropdown( $args = array() ) { |
|
36 | + public function forms_dropdown($args = array()) { |
|
37 | 37 | |
38 | 38 | $defaults = array( |
39 | 39 | 'name' => 'forms', |
@@ -44,47 +44,47 @@ discard block |
||
44 | 44 | 'chosen' => false, |
45 | 45 | 'number' => 30, |
46 | 46 | /* translators: %s: form singular label */ |
47 | - 'placeholder' => sprintf( __( 'Select a %s', 'give' ), give_get_forms_label_singular() ) |
|
47 | + 'placeholder' => sprintf(__('Select a %s', 'give'), give_get_forms_label_singular()) |
|
48 | 48 | ); |
49 | 49 | |
50 | - $args = wp_parse_args( $args, $defaults ); |
|
50 | + $args = wp_parse_args($args, $defaults); |
|
51 | 51 | |
52 | - $forms = get_posts( array( |
|
52 | + $forms = get_posts(array( |
|
53 | 53 | 'post_type' => 'give_forms', |
54 | 54 | 'orderby' => 'title', |
55 | 55 | 'order' => 'ASC', |
56 | 56 | 'posts_per_page' => $args['number'] |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $options = array(); |
60 | 60 | |
61 | - if ( $forms ) { |
|
61 | + if ($forms) { |
|
62 | 62 | $options[0] = sprintf( |
63 | 63 | /* translators: %s: form singular label */ |
64 | - __( 'Select a %s', 'give' ), |
|
64 | + __('Select a %s', 'give'), |
|
65 | 65 | give_get_forms_label_singular() |
66 | 66 | ); |
67 | - foreach ( $forms as $form ) { |
|
68 | - $options[ absint( $form->ID ) ] = esc_html( $form->post_title ); |
|
67 | + foreach ($forms as $form) { |
|
68 | + $options[absint($form->ID)] = esc_html($form->post_title); |
|
69 | 69 | } |
70 | 70 | } else { |
71 | - $options[0] = __( 'No Give Forms Found', 'give' ); |
|
71 | + $options[0] = __('No Give Forms Found', 'give'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // This ensures that any selected forms are included in the drop down |
75 | - if ( is_array( $args['selected'] ) ) { |
|
76 | - foreach ( $args['selected'] as $item ) { |
|
77 | - if ( ! in_array( $item, $options ) ) { |
|
78 | - $options[ $item ] = get_the_title( $item ); |
|
75 | + if (is_array($args['selected'])) { |
|
76 | + foreach ($args['selected'] as $item) { |
|
77 | + if ( ! in_array($item, $options)) { |
|
78 | + $options[$item] = get_the_title($item); |
|
79 | 79 | } |
80 | 80 | } |
81 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
82 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
83 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
81 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
82 | + if ( ! in_array($args['selected'], $options)) { |
|
83 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - $output = $this->select( array( |
|
87 | + $output = $this->select(array( |
|
88 | 88 | 'name' => $args['name'], |
89 | 89 | 'selected' => $args['selected'], |
90 | 90 | 'id' => $args['id'], |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | 'placeholder' => $args['placeholder'], |
96 | 96 | 'show_option_all' => false, |
97 | 97 | 'show_option_none' => false |
98 | - ) ); |
|
98 | + )); |
|
99 | 99 | |
100 | 100 | return $output; |
101 | 101 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string $output Donor dropdown |
112 | 112 | */ |
113 | - public function donor_dropdown( $args = array() ) { |
|
113 | + public function donor_dropdown($args = array()) { |
|
114 | 114 | |
115 | 115 | $defaults = array( |
116 | 116 | 'name' => 'customers', |
@@ -119,38 +119,38 @@ discard block |
||
119 | 119 | 'multiple' => false, |
120 | 120 | 'selected' => 0, |
121 | 121 | 'chosen' => true, |
122 | - 'placeholder' => __( 'Select a Donor', 'give' ), |
|
122 | + 'placeholder' => __('Select a Donor', 'give'), |
|
123 | 123 | 'number' => 30 |
124 | 124 | ); |
125 | 125 | |
126 | - $args = wp_parse_args( $args, $defaults ); |
|
126 | + $args = wp_parse_args($args, $defaults); |
|
127 | 127 | |
128 | - $customers = Give()->customers->get_customers( array( |
|
128 | + $customers = Give()->customers->get_customers(array( |
|
129 | 129 | 'number' => $args['number'] |
130 | - ) ); |
|
130 | + )); |
|
131 | 131 | |
132 | 132 | $options = array(); |
133 | 133 | |
134 | - if ( $customers ) { |
|
135 | - $options[0] = __( 'No donor attached', 'give' ); |
|
136 | - foreach ( $customers as $customer ) { |
|
137 | - $options[ absint( $customer->id ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' ); |
|
134 | + if ($customers) { |
|
135 | + $options[0] = __('No donor attached', 'give'); |
|
136 | + foreach ($customers as $customer) { |
|
137 | + $options[absint($customer->id)] = esc_html($customer->name.' ('.$customer->email.')'); |
|
138 | 138 | } |
139 | 139 | } else { |
140 | - $options[0] = __( 'No donors found', 'give' ); |
|
140 | + $options[0] = __('No donors found', 'give'); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( ! empty( $args['selected'] ) ) { |
|
143 | + if ( ! empty($args['selected'])) { |
|
144 | 144 | |
145 | 145 | // If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed |
146 | 146 | |
147 | - if ( ! array_key_exists( $args['selected'], $options ) ) { |
|
147 | + if ( ! array_key_exists($args['selected'], $options)) { |
|
148 | 148 | |
149 | - $customer = new Give_Customer( $args['selected'] ); |
|
149 | + $customer = new Give_Customer($args['selected']); |
|
150 | 150 | |
151 | - if ( $customer ) { |
|
151 | + if ($customer) { |
|
152 | 152 | |
153 | - $options[ absint( $args['selected'] ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' ); |
|
153 | + $options[absint($args['selected'])] = esc_html($customer->name.' ('.$customer->email.')'); |
|
154 | 154 | |
155 | 155 | } |
156 | 156 | |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | |
159 | 159 | } |
160 | 160 | |
161 | - $output = $this->select( array( |
|
161 | + $output = $this->select(array( |
|
162 | 162 | 'name' => $args['name'], |
163 | 163 | 'selected' => $args['selected'], |
164 | 164 | 'id' => $args['id'], |
165 | - 'class' => $args['class'] . ' give-customer-select', |
|
165 | + 'class' => $args['class'].' give-customer-select', |
|
166 | 166 | 'options' => $options, |
167 | 167 | 'multiple' => $args['multiple'], |
168 | 168 | 'chosen' => $args['chosen'], |
169 | 169 | 'show_option_all' => false, |
170 | 170 | 'show_option_none' => false |
171 | - ) ); |
|
171 | + )); |
|
172 | 172 | |
173 | 173 | return $output; |
174 | 174 | } |
@@ -185,21 +185,21 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return string $output Category dropdown |
187 | 187 | */ |
188 | - public function category_dropdown( $name = 'give_forms_categories', $selected = 0 ) { |
|
189 | - $categories = get_terms( 'give_forms_category', apply_filters( 'give_forms_category_dropdown', array() ) ); |
|
188 | + public function category_dropdown($name = 'give_forms_categories', $selected = 0) { |
|
189 | + $categories = get_terms('give_forms_category', apply_filters('give_forms_category_dropdown', array())); |
|
190 | 190 | $options = array(); |
191 | 191 | |
192 | - foreach ( $categories as $category ) { |
|
193 | - $options[ absint( $category->term_id ) ] = esc_html( $category->name ); |
|
192 | + foreach ($categories as $category) { |
|
193 | + $options[absint($category->term_id)] = esc_html($category->name); |
|
194 | 194 | } |
195 | 195 | |
196 | - $output = $this->select( array( |
|
196 | + $output = $this->select(array( |
|
197 | 197 | 'name' => $name, |
198 | 198 | 'selected' => $selected, |
199 | 199 | 'options' => $options, |
200 | - 'show_option_all' => __( 'All Categories', 'give' ), |
|
200 | + 'show_option_all' => __('All Categories', 'give'), |
|
201 | 201 | 'show_option_none' => false |
202 | - ) ); |
|
202 | + )); |
|
203 | 203 | |
204 | 204 | return $output; |
205 | 205 | } |
@@ -217,25 +217,25 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @return string $output Year dropdown |
219 | 219 | */ |
220 | - public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
221 | - $current = date( 'Y' ); |
|
222 | - $start_year = $current - absint( $years_before ); |
|
223 | - $end_year = $current + absint( $years_after ); |
|
224 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
220 | + public function year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
221 | + $current = date('Y'); |
|
222 | + $start_year = $current - absint($years_before); |
|
223 | + $end_year = $current + absint($years_after); |
|
224 | + $selected = empty($selected) ? date('Y') : $selected; |
|
225 | 225 | $options = array(); |
226 | 226 | |
227 | - while ( $start_year <= $end_year ) { |
|
228 | - $options[ absint( $start_year ) ] = $start_year; |
|
229 | - $start_year ++; |
|
227 | + while ($start_year <= $end_year) { |
|
228 | + $options[absint($start_year)] = $start_year; |
|
229 | + $start_year++; |
|
230 | 230 | } |
231 | 231 | |
232 | - $output = $this->select( array( |
|
232 | + $output = $this->select(array( |
|
233 | 233 | 'name' => $name, |
234 | 234 | 'selected' => $selected, |
235 | 235 | 'options' => $options, |
236 | 236 | 'show_option_all' => false, |
237 | 237 | 'show_option_none' => false |
238 | - ) ); |
|
238 | + )); |
|
239 | 239 | |
240 | 240 | return $output; |
241 | 241 | } |
@@ -252,23 +252,23 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return string $output Month dropdown |
254 | 254 | */ |
255 | - public function month_dropdown( $name = 'month', $selected = 0 ) { |
|
255 | + public function month_dropdown($name = 'month', $selected = 0) { |
|
256 | 256 | $month = 1; |
257 | 257 | $options = array(); |
258 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
258 | + $selected = empty($selected) ? date('n') : $selected; |
|
259 | 259 | |
260 | - while ( $month <= 12 ) { |
|
261 | - $options[ absint( $month ) ] = give_month_num_to_name( $month ); |
|
262 | - $month ++; |
|
260 | + while ($month <= 12) { |
|
261 | + $options[absint($month)] = give_month_num_to_name($month); |
|
262 | + $month++; |
|
263 | 263 | } |
264 | 264 | |
265 | - $output = $this->select( array( |
|
265 | + $output = $this->select(array( |
|
266 | 266 | 'name' => $name, |
267 | 267 | 'selected' => $selected, |
268 | 268 | 'options' => $options, |
269 | 269 | 'show_option_all' => false, |
270 | 270 | 'show_option_none' => false |
271 | - ) ); |
|
271 | + )); |
|
272 | 272 | |
273 | 273 | return $output; |
274 | 274 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function select( $args = array() ) { |
|
285 | + public function select($args = array()) { |
|
286 | 286 | $defaults = array( |
287 | 287 | 'options' => array(), |
288 | 288 | 'name' => null, |
@@ -292,60 +292,60 @@ discard block |
||
292 | 292 | 'chosen' => false, |
293 | 293 | 'placeholder' => null, |
294 | 294 | 'multiple' => false, |
295 | - 'show_option_all' => __( 'All', 'give' ), |
|
296 | - 'show_option_none' => __( 'None', 'give' ) |
|
295 | + 'show_option_all' => __('All', 'give'), |
|
296 | + 'show_option_none' => __('None', 'give') |
|
297 | 297 | ); |
298 | 298 | |
299 | - $args = wp_parse_args( $args, $defaults ); |
|
299 | + $args = wp_parse_args($args, $defaults); |
|
300 | 300 | |
301 | 301 | |
302 | - if ( $args['multiple'] ) { |
|
302 | + if ($args['multiple']) { |
|
303 | 303 | $multiple = ' MULTIPLE'; |
304 | 304 | } else { |
305 | 305 | $multiple = ''; |
306 | 306 | } |
307 | 307 | |
308 | - if ( $args['chosen'] ) { |
|
308 | + if ($args['chosen']) { |
|
309 | 309 | $args['class'] .= ' give-select-chosen'; |
310 | 310 | } |
311 | 311 | |
312 | - if ( $args['placeholder'] ) { |
|
312 | + if ($args['placeholder']) { |
|
313 | 313 | $placeholder = $args['placeholder']; |
314 | 314 | } else { |
315 | 315 | $placeholder = ''; |
316 | 316 | } |
317 | 317 | |
318 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="give-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' data-placeholder="' . $placeholder . '">'; |
|
318 | + $output = '<select name="'.esc_attr($args['name']).'" id="'.esc_attr(sanitize_key(str_replace('-', '_', $args['id']))).'" class="give-select '.esc_attr($args['class']).'"'.$multiple.' data-placeholder="'.$placeholder.'">'; |
|
319 | 319 | |
320 | - if ( $args['show_option_all'] ) { |
|
321 | - if ( $args['multiple'] ) { |
|
322 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
320 | + if ($args['show_option_all']) { |
|
321 | + if ($args['multiple']) { |
|
322 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
323 | 323 | } else { |
324 | - $selected = selected( $args['selected'], 0, false ); |
|
324 | + $selected = selected($args['selected'], 0, false); |
|
325 | 325 | } |
326 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
326 | + $output .= '<option value="all"'.$selected.'>'.esc_html($args['show_option_all']).'</option>'; |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( ! empty( $args['options'] ) ) { |
|
329 | + if ( ! empty($args['options'])) { |
|
330 | 330 | |
331 | - if ( $args['show_option_none'] ) { |
|
332 | - if ( $args['multiple'] ) { |
|
333 | - $selected = selected( true, in_array( - 1, $args['selected'] ), false ); |
|
331 | + if ($args['show_option_none']) { |
|
332 | + if ($args['multiple']) { |
|
333 | + $selected = selected(true, in_array( -1, $args['selected'] ), false); |
|
334 | 334 | } else { |
335 | - $selected = selected( $args['selected'], - 1, false ); |
|
335 | + $selected = selected($args['selected'], - 1, false); |
|
336 | 336 | } |
337 | - $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
337 | + $output .= '<option value="-1"'.$selected.'>'.esc_html($args['show_option_none']).'</option>'; |
|
338 | 338 | } |
339 | 339 | |
340 | - foreach ( $args['options'] as $key => $option ) { |
|
340 | + foreach ($args['options'] as $key => $option) { |
|
341 | 341 | |
342 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
343 | - $selected = selected( true, in_array( $key, $args['selected'] ), false ); |
|
342 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
343 | + $selected = selected(true, in_array($key, $args['selected']), false); |
|
344 | 344 | } else { |
345 | - $selected = selected( $args['selected'], $key, false ); |
|
345 | + $selected = selected($args['selected'], $key, false); |
|
346 | 346 | } |
347 | 347 | |
348 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
348 | + $output .= '<option value="'.esc_attr($key).'"'.$selected.'>'.esc_html($option).'</option>'; |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - public function checkbox( $args = array() ) { |
|
366 | + public function checkbox($args = array()) { |
|
367 | 367 | $defaults = array( |
368 | 368 | 'name' => null, |
369 | 369 | 'current' => null, |
@@ -374,16 +374,16 @@ discard block |
||
374 | 374 | ) |
375 | 375 | ); |
376 | 376 | |
377 | - $args = wp_parse_args( $args, $defaults ); |
|
377 | + $args = wp_parse_args($args, $defaults); |
|
378 | 378 | |
379 | 379 | $options = ''; |
380 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
380 | + if ( ! empty($args['options']['disabled'])) { |
|
381 | 381 | $options .= ' disabled="disabled"'; |
382 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
382 | + } elseif ( ! empty($args['options']['readonly'])) { |
|
383 | 383 | $options .= ' readonly'; |
384 | 384 | } |
385 | 385 | |
386 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
386 | + $output = '<input type="checkbox"'.$options.' name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].' '.esc_attr($args['name']).'" '.checked(1, $args['current'], false).' />'; |
|
387 | 387 | |
388 | 388 | return $output; |
389 | 389 | } |
@@ -397,22 +397,22 @@ discard block |
||
397 | 397 | * |
398 | 398 | * @return string Text field |
399 | 399 | */ |
400 | - public function text( $args = array() ) { |
|
400 | + public function text($args = array()) { |
|
401 | 401 | // Backwards compatabliity |
402 | - if ( func_num_args() > 1 ) { |
|
402 | + if (func_num_args() > 1) { |
|
403 | 403 | $args = func_get_args(); |
404 | 404 | |
405 | 405 | $name = $args[0]; |
406 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
407 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
408 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
406 | + $value = isset($args[1]) ? $args[1] : ''; |
|
407 | + $label = isset($args[2]) ? $args[2] : ''; |
|
408 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | $defaults = array( |
412 | - 'name' => isset( $name ) ? $name : 'text', |
|
413 | - 'value' => isset( $value ) ? $value : null, |
|
414 | - 'label' => isset( $label ) ? $label : null, |
|
415 | - 'desc' => isset( $desc ) ? $desc : null, |
|
412 | + 'name' => isset($name) ? $name : 'text', |
|
413 | + 'value' => isset($value) ? $value : null, |
|
414 | + 'label' => isset($label) ? $label : null, |
|
415 | + 'desc' => isset($desc) ? $desc : null, |
|
416 | 416 | 'placeholder' => '', |
417 | 417 | 'class' => 'regular-text', |
418 | 418 | 'disabled' => false, |
@@ -420,29 +420,29 @@ discard block |
||
420 | 420 | 'data' => false |
421 | 421 | ); |
422 | 422 | |
423 | - $args = wp_parse_args( $args, $defaults ); |
|
423 | + $args = wp_parse_args($args, $defaults); |
|
424 | 424 | |
425 | 425 | $disabled = ''; |
426 | - if ( $args['disabled'] ) { |
|
426 | + if ($args['disabled']) { |
|
427 | 427 | $disabled = ' disabled="disabled"'; |
428 | 428 | } |
429 | 429 | |
430 | 430 | $data = ''; |
431 | - if ( ! empty( $args['data'] ) ) { |
|
432 | - foreach ( $args['data'] as $key => $value ) { |
|
433 | - $data .= 'data-' . $key . '="' . $value . '" '; |
|
431 | + if ( ! empty($args['data'])) { |
|
432 | + foreach ($args['data'] as $key => $value) { |
|
433 | + $data .= 'data-'.$key.'="'.$value.'" '; |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | - $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">'; |
|
437 | + $output = '<span id="give-'.sanitize_key($args['name']).'-wrap">'; |
|
438 | 438 | |
439 | - $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
439 | + $output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>'; |
|
440 | 440 | |
441 | - if ( ! empty( $args['desc'] ) ) { |
|
442 | - $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
441 | + if ( ! empty($args['desc'])) { |
|
442 | + $output .= '<span class="give-description">'.esc_html($args['desc']).'</span>'; |
|
443 | 443 | } |
444 | 444 | |
445 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $args['class'] . '" ' . $data . '' . $disabled . '/>'; |
|
445 | + $output .= '<input type="text" name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" autocomplete="'.esc_attr($args['autocomplete']).'" value="'.esc_attr($args['value']).'" placeholder="'.esc_attr($args['placeholder']).'" class="'.$args['class'].'" '.$data.''.$disabled.'/>'; |
|
446 | 446 | |
447 | 447 | $output .= '</span>'; |
448 | 448 | |
@@ -458,15 +458,15 @@ discard block |
||
458 | 458 | * |
459 | 459 | * @return string Datepicker field |
460 | 460 | */ |
461 | - public function date_field( $args = array() ) { |
|
461 | + public function date_field($args = array()) { |
|
462 | 462 | |
463 | - if ( empty( $args['class'] ) ) { |
|
463 | + if (empty($args['class'])) { |
|
464 | 464 | $args['class'] = 'give_datepicker'; |
465 | - } elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) { |
|
465 | + } elseif ( ! strpos($args['class'], 'give_datepicker')) { |
|
466 | 466 | $args['class'] .= ' give_datepicker'; |
467 | 467 | } |
468 | 468 | |
469 | - return $this->text( $args ); |
|
469 | + return $this->text($args); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return string textarea |
481 | 481 | */ |
482 | - public function textarea( $args = array() ) { |
|
482 | + public function textarea($args = array()) { |
|
483 | 483 | $defaults = array( |
484 | 484 | 'name' => 'textarea', |
485 | 485 | 'value' => null, |
@@ -489,21 +489,21 @@ discard block |
||
489 | 489 | 'disabled' => false |
490 | 490 | ); |
491 | 491 | |
492 | - $args = wp_parse_args( $args, $defaults ); |
|
492 | + $args = wp_parse_args($args, $defaults); |
|
493 | 493 | |
494 | 494 | $disabled = ''; |
495 | - if ( $args['disabled'] ) { |
|
495 | + if ($args['disabled']) { |
|
496 | 496 | $disabled = ' disabled="disabled"'; |
497 | 497 | } |
498 | 498 | |
499 | - $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">'; |
|
499 | + $output = '<span id="give-'.sanitize_key($args['name']).'-wrap">'; |
|
500 | 500 | |
501 | - $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
501 | + $output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>'; |
|
502 | 502 | |
503 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
503 | + $output .= '<textarea name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].'"'.$disabled.'>'.esc_attr($args['value']).'</textarea>'; |
|
504 | 504 | |
505 | - if ( ! empty( $args['desc'] ) ) { |
|
506 | - $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
505 | + if ( ! empty($args['desc'])) { |
|
506 | + $output .= '<span class="give-description">'.esc_html($args['desc']).'</span>'; |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | $output .= '</span>'; |
@@ -520,12 +520,12 @@ discard block |
||
520 | 520 | * |
521 | 521 | * @return string text field with ajax search |
522 | 522 | */ |
523 | - public function ajax_user_search( $args = array() ) { |
|
523 | + public function ajax_user_search($args = array()) { |
|
524 | 524 | |
525 | 525 | $defaults = array( |
526 | 526 | 'name' => 'user_id', |
527 | 527 | 'value' => null, |
528 | - 'placeholder' => __( 'Enter username', 'give' ), |
|
528 | + 'placeholder' => __('Enter username', 'give'), |
|
529 | 529 | 'label' => null, |
530 | 530 | 'desc' => null, |
531 | 531 | 'class' => '', |
@@ -534,13 +534,13 @@ discard block |
||
534 | 534 | 'data' => false |
535 | 535 | ); |
536 | 536 | |
537 | - $args = wp_parse_args( $args, $defaults ); |
|
537 | + $args = wp_parse_args($args, $defaults); |
|
538 | 538 | |
539 | - $args['class'] = 'give-ajax-user-search ' . $args['class']; |
|
539 | + $args['class'] = 'give-ajax-user-search '.$args['class']; |
|
540 | 540 | |
541 | 541 | $output = '<span class="give_user_search_wrap">'; |
542 | - $output .= $this->text( $args ); |
|
543 | - $output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="' . __( 'Cancel', 'give' ) . '" aria-label="' . __( 'Cancel', 'give' ) . '" href="#">x</a><span></span></span>'; |
|
542 | + $output .= $this->text($args); |
|
543 | + $output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="'.__('Cancel', 'give').'" aria-label="'.__('Cancel', 'give').'" href="#">x</a><span></span></span>'; |
|
544 | 544 | $output .= '</span>'; |
545 | 545 | |
546 | 546 | return $output; |