@@ -254,8 +254,8 @@ |
||
254 | 254 | $args = array( |
255 | 255 | 'id' => 'give-api-user-search', |
256 | 256 | 'name' => 'user_id', |
257 | - ); |
|
258 | - echo Give()->html->ajax_user_search($args); ?> |
|
257 | + ); |
|
258 | + echo Give()->html->ajax_user_search($args); ?> |
|
259 | 259 | <?php submit_button( esc_html__( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?> |
260 | 260 | <?php |
261 | 261 | $give_api_is_bottom = true; |
@@ -10,13 +10,13 @@ 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 | |
17 | 17 | // Load WP_List_Table if not loaded |
18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
18 | +if ( ! class_exists('WP_List_Table')) { |
|
19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | global $status, $page; |
54 | 54 | |
55 | 55 | // Set parent defaults |
56 | - parent::__construct( array( |
|
57 | - 'singular' => esc_html__( 'API Key', 'give' ), // Singular name of the listed records |
|
58 | - 'plural' => esc_html__( 'API Keys', 'give' ), // Plural name of the listed records |
|
59 | - 'ajax' => false,// Does this table support ajax? |
|
60 | - ) ); |
|
56 | + parent::__construct(array( |
|
57 | + 'singular' => esc_html__('API Key', 'give'), // Singular name of the listed records |
|
58 | + 'plural' => esc_html__('API Keys', 'give'), // Plural name of the listed records |
|
59 | + 'ajax' => false, // Does this table support ajax? |
|
60 | + )); |
|
61 | 61 | |
62 | 62 | $this->query(); |
63 | 63 | } |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string Column Name |
75 | 75 | */ |
76 | - public function column_default( $item, $column_name ) { |
|
77 | - return $item[ $column_name ]; |
|
76 | + public function column_default($item, $column_name) { |
|
77 | + return $item[$column_name]; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return string Column Name |
89 | 89 | */ |
90 | - public function column_key( $item ) { |
|
91 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>'; |
|
90 | + public function column_key($item) { |
|
91 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['key']).'"/>'; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return string Column Name |
103 | 103 | */ |
104 | - public function column_token( $item ) { |
|
105 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>'; |
|
104 | + public function column_token($item) { |
|
105 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['token']).'"/>'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string Column Name |
117 | 117 | */ |
118 | - public function column_secret( $item ) { |
|
119 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>'; |
|
118 | + public function column_secret($item) { |
|
119 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['secret']).'"/>'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,46 +126,46 @@ discard block |
||
126 | 126 | * @since 1.1 |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public function column_user( $item ) { |
|
129 | + public function column_user($item) { |
|
130 | 130 | |
131 | 131 | $actions = array(); |
132 | 132 | |
133 | - if ( apply_filters( 'give_api_log_requests', true ) ) { |
|
133 | + if (apply_filters('give_api_log_requests', true)) { |
|
134 | 134 | $actions['view'] = sprintf( |
135 | 135 | '<a href="%s">%s</a>', |
136 | - esc_url( add_query_arg( array( |
|
136 | + esc_url(add_query_arg(array( |
|
137 | 137 | 'section' => 'api_requests', |
138 | 138 | 'post_type' => 'give_forms', |
139 | 139 | 'page' => 'give-tools', |
140 | 140 | 'tab' => 'logs', |
141 | 141 | 's' => $item['email'], |
142 | - ), 'edit.php' ) ), |
|
143 | - esc_html__( 'View API Log', 'give' ) |
|
142 | + ), 'edit.php')), |
|
143 | + esc_html__('View API Log', 'give') |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
147 | 147 | $actions['reissue'] = sprintf( |
148 | 148 | '<a href="%s" class="give-regenerate-api-key">%s</a>', |
149 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
149 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
150 | 150 | 'user_id' => $item['id'], |
151 | 151 | 'give_action' => 'process_api_key', |
152 | 152 | 'give_api_process' => 'regenerate', |
153 | - ) ), 'give-api-nonce' ) ), |
|
154 | - esc_html__( 'Reissue', 'give' ) |
|
153 | + )), 'give-api-nonce')), |
|
154 | + esc_html__('Reissue', 'give') |
|
155 | 155 | ); |
156 | - $actions['revoke'] = sprintf( |
|
156 | + $actions['revoke'] = sprintf( |
|
157 | 157 | '<a href="%s" class="give-revoke-api-key give-delete">%s</a>', |
158 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
158 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
159 | 159 | 'user_id' => $item['id'], |
160 | 160 | 'give_action' => 'process_api_key', |
161 | 161 | 'give_api_process' => 'revoke', |
162 | - ) ), 'give-api-nonce' ) ), |
|
163 | - esc_html__( 'Revoke', 'give' ) |
|
162 | + )), 'give-api-nonce')), |
|
163 | + esc_html__('Revoke', 'give') |
|
164 | 164 | ); |
165 | 165 | |
166 | - $actions = apply_filters( 'give_api_row_actions', array_filter( $actions ) ); |
|
166 | + $actions = apply_filters('give_api_row_actions', array_filter($actions)); |
|
167 | 167 | |
168 | - return sprintf( '%1$s %2$s', $item['user'], $this->row_actions( $actions ) ); |
|
168 | + return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions)); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -189,10 +189,10 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function get_columns() { |
191 | 191 | $columns = array( |
192 | - 'user' => esc_html__( 'Username', 'give' ), |
|
193 | - 'key' => esc_html__( 'Public Key', 'give' ), |
|
194 | - 'token' => esc_html__( 'Token', 'give' ), |
|
195 | - 'secret' => esc_html__( 'Secret Key', 'give' ), |
|
192 | + 'user' => esc_html__('Username', 'give'), |
|
193 | + 'key' => esc_html__('Public Key', 'give'), |
|
194 | + 'token' => esc_html__('Token', 'give'), |
|
195 | + 'secret' => esc_html__('Secret Key', 'give'), |
|
196 | 196 | ); |
197 | 197 | |
198 | 198 | return $columns; |
@@ -206,20 +206,20 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @param string $which |
208 | 208 | */ |
209 | - protected function display_tablenav( $which ) { |
|
210 | - if ( 'top' === $which ) { |
|
211 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
209 | + protected function display_tablenav($which) { |
|
210 | + if ('top' === $which) { |
|
211 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
212 | 212 | } |
213 | 213 | ?> |
214 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
214 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
215 | 215 | |
216 | 216 | <div class="alignleft actions bulkactions"> |
217 | - <?php $this->bulk_actions( $which ); ?> |
|
217 | + <?php $this->bulk_actions($which); ?> |
|
218 | 218 | </div> |
219 | 219 | |
220 | 220 | <?php |
221 | - $this->extra_tablenav( $which ); |
|
222 | - $this->pagination( $which ); |
|
221 | + $this->extra_tablenav($which); |
|
222 | + $this->pagination($which); |
|
223 | 223 | ?> |
224 | 224 | |
225 | 225 | <br class="clear"/> |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return void |
239 | 239 | */ |
240 | - function bulk_actions( $which = '' ) { |
|
240 | + function bulk_actions($which = '') { |
|
241 | 241 | // These aren't really bulk actions but this outputs the markup in the right place. |
242 | 242 | static $give_api_is_bottom; |
243 | 243 | |
244 | - if ( $give_api_is_bottom ) { |
|
244 | + if ($give_api_is_bottom) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | ?> |
248 | 248 | <input type="hidden" name="give_action" value="process_api_key"/> |
249 | 249 | <input type="hidden" name="give_api_process" value="generate"/> |
250 | - <?php wp_nonce_field( 'give-api-nonce' ); |
|
250 | + <?php wp_nonce_field('give-api-nonce'); |
|
251 | 251 | /** |
252 | 252 | * API Key user search. |
253 | 253 | */ |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | 'name' => 'user_id', |
257 | 257 | ); |
258 | 258 | echo Give()->html->ajax_user_search($args); ?> |
259 | - <?php submit_button( esc_html__( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?> |
|
259 | + <?php submit_button(esc_html__('Generate New API Keys', 'give'), 'secondary', 'submit', false); ?> |
|
260 | 260 | <?php |
261 | 261 | $give_api_is_bottom = true; |
262 | 262 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @return int Current page number |
270 | 270 | */ |
271 | 271 | public function get_paged() { |
272 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
272 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -280,21 +280,21 @@ discard block |
||
280 | 280 | * @return array |
281 | 281 | */ |
282 | 282 | public function query() { |
283 | - $users = get_users( array( |
|
283 | + $users = get_users(array( |
|
284 | 284 | 'meta_value' => 'give_user_secret_key', |
285 | 285 | 'number' => $this->per_page, |
286 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
287 | - ) ); |
|
288 | - $keys = array(); |
|
289 | - |
|
290 | - foreach ( $users as $user ) { |
|
291 | - $keys[ $user->ID ]['id'] = $user->ID; |
|
292 | - $keys[ $user->ID ]['email'] = $user->user_email; |
|
293 | - $keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>'; |
|
294 | - |
|
295 | - $keys[ $user->ID ]['key'] = Give()->api->get_user_public_key( $user->ID ); |
|
296 | - $keys[ $user->ID ]['secret'] = Give()->api->get_user_secret_key( $user->ID ); |
|
297 | - $keys[ $user->ID ]['token'] = Give()->api->get_token( $user->ID ); |
|
286 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
287 | + )); |
|
288 | + $keys = array(); |
|
289 | + |
|
290 | + foreach ($users as $user) { |
|
291 | + $keys[$user->ID]['id'] = $user->ID; |
|
292 | + $keys[$user->ID]['email'] = $user->user_email; |
|
293 | + $keys[$user->ID]['user'] = '<a href="'.add_query_arg('user_id', $user->ID, 'user-edit.php').'"><strong>'.$user->user_login.'</strong></a>'; |
|
294 | + |
|
295 | + $keys[$user->ID]['key'] = Give()->api->get_user_public_key($user->ID); |
|
296 | + $keys[$user->ID]['secret'] = Give()->api->get_user_secret_key($user->ID); |
|
297 | + $keys[$user->ID]['token'] = Give()->api->get_token($user->ID); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $keys; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function total_items() { |
312 | 312 | global $wpdb; |
313 | 313 | |
314 | - if ( ! ( $total_items = Give_Cache::get( 'give_total_api_keys', true ) ) ) { |
|
314 | + if ( ! ($total_items = Give_Cache::get('give_total_api_keys', true))) { |
|
315 | 315 | $total_items = $wpdb->get_var( |
316 | 316 | $wpdb->prepare( |
317 | 317 | "SELECT count(user_id) |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | ) |
321 | 321 | ); |
322 | 322 | |
323 | - Give_Cache::set( 'give_total_api_keys', $total_items, HOUR_IN_SECONDS, true ); |
|
323 | + Give_Cache::set('give_total_api_keys', $total_items, HOUR_IN_SECONDS, true); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | return $total_items; |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | $hidden = array(); // No hidden columns |
340 | 340 | $sortable = array(); // Not sortable... for now |
341 | 341 | |
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
343 | 343 | |
344 | 344 | $data = $this->query(); |
345 | 345 | |
@@ -347,10 +347,10 @@ discard block |
||
347 | 347 | |
348 | 348 | $this->items = $data; |
349 | 349 | |
350 | - $this->set_pagination_args( array( |
|
350 | + $this->set_pagination_args(array( |
|
351 | 351 | 'total_items' => $total_items, |
352 | 352 | 'per_page' => $this->per_page, |
353 | - 'total_pages' => ceil( $total_items / $this->per_page ), |
|
353 | + 'total_pages' => ceil($total_items / $this->per_page), |
|
354 | 354 | ) |
355 | 355 | ); |
356 | 356 | } |
@@ -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 | |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | public function csv_cols() { |
42 | 42 | |
43 | 43 | $cols = array( |
44 | - 'ID' => __( 'ID', 'give' ), |
|
45 | - 'post_name' => __( 'Slug', 'give' ), |
|
46 | - 'post_title' => __( 'Name', 'give' ), |
|
47 | - 'post_date' => __( 'Date Created', 'give' ), |
|
48 | - 'post_author' => __( 'Author', 'give' ), |
|
49 | - 'post_content' => __( 'Description', 'give' ), |
|
50 | - 'post_excerpt' => __( 'Excerpt', 'give' ), |
|
51 | - 'post_status' => __( 'Status', 'give' ), |
|
52 | - 'categories' => __( 'Categories', 'give' ), |
|
53 | - 'tags' => __( 'Tags', 'give' ), |
|
54 | - 'give_price' => __( 'Price', 'give' ), |
|
55 | - '_thumbnail_id' => __( 'Featured Image', 'give' ), |
|
56 | - '_give_form_sales' => __( 'Donations', 'give' ), |
|
57 | - '_give_download_earnings' => __( 'Income', 'give' ), |
|
44 | + 'ID' => __('ID', 'give'), |
|
45 | + 'post_name' => __('Slug', 'give'), |
|
46 | + 'post_title' => __('Name', 'give'), |
|
47 | + 'post_date' => __('Date Created', 'give'), |
|
48 | + 'post_author' => __('Author', 'give'), |
|
49 | + 'post_content' => __('Description', 'give'), |
|
50 | + 'post_excerpt' => __('Excerpt', 'give'), |
|
51 | + 'post_status' => __('Status', 'give'), |
|
52 | + 'categories' => __('Categories', 'give'), |
|
53 | + 'tags' => __('Tags', 'give'), |
|
54 | + 'give_price' => __('Price', 'give'), |
|
55 | + '_thumbnail_id' => __('Featured Image', 'give'), |
|
56 | + '_give_form_sales' => __('Donations', 'give'), |
|
57 | + '_give_download_earnings' => __('Income', 'give'), |
|
58 | 58 | ); |
59 | 59 | |
60 | 60 | return $cols; |
@@ -84,43 +84,43 @@ discard block |
||
84 | 84 | 'paged' => $this->step |
85 | 85 | ); |
86 | 86 | |
87 | - $forms = new WP_Query( $args ); |
|
87 | + $forms = new WP_Query($args); |
|
88 | 88 | |
89 | - if ( $forms->posts ) { |
|
90 | - foreach ( $forms->posts as $form ) { |
|
89 | + if ($forms->posts) { |
|
90 | + foreach ($forms->posts as $form) { |
|
91 | 91 | |
92 | 92 | $row = []; |
93 | 93 | |
94 | - foreach ( $this->csv_cols() as $key => $value ) { |
|
94 | + foreach ($this->csv_cols() as $key => $value) { |
|
95 | 95 | |
96 | 96 | // Setup default value/ |
97 | - $row[ $key ] = ''; |
|
97 | + $row[$key] = ''; |
|
98 | 98 | |
99 | - if ( in_array( $key, $meta ) ) { |
|
99 | + if (in_array($key, $meta)) { |
|
100 | 100 | |
101 | - switch ( $key ) { |
|
101 | + switch ($key) { |
|
102 | 102 | |
103 | 103 | case '_thumbnail_id' : |
104 | 104 | |
105 | - $image_id = get_post_thumbnail_id( $form->ID ); |
|
106 | - $row[ $key ] = wp_get_attachment_url( $image_id ); |
|
105 | + $image_id = get_post_thumbnail_id($form->ID); |
|
106 | + $row[$key] = wp_get_attachment_url($image_id); |
|
107 | 107 | |
108 | 108 | break; |
109 | 109 | |
110 | 110 | case 'give_price' : |
111 | 111 | |
112 | - if ( give_has_variable_prices( $form->ID ) ) { |
|
112 | + if (give_has_variable_prices($form->ID)) { |
|
113 | 113 | |
114 | 114 | $prices = []; |
115 | - foreach ( give_get_variable_prices( $form->ID ) as $price ) { |
|
116 | - $prices[] = $price['name'] . ': ' . $price['amount']; |
|
115 | + foreach (give_get_variable_prices($form->ID) as $price) { |
|
116 | + $prices[] = $price['name'].': '.$price['amount']; |
|
117 | 117 | } |
118 | 118 | |
119 | - $row[ $key ] = implode( ' | ', $prices ); |
|
119 | + $row[$key] = implode(' | ', $prices); |
|
120 | 120 | |
121 | 121 | } else { |
122 | 122 | |
123 | - $row[ $key ] = give_get_form_price( $form->ID ); |
|
123 | + $row[$key] = give_get_form_price($form->ID); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
@@ -128,44 +128,44 @@ discard block |
||
128 | 128 | |
129 | 129 | default : |
130 | 130 | |
131 | - $row[ $key ] = give_get_meta( $form->ID, $key, TRUE ); |
|
131 | + $row[$key] = give_get_meta($form->ID, $key, TRUE); |
|
132 | 132 | |
133 | 133 | break; |
134 | 134 | |
135 | 135 | } |
136 | 136 | |
137 | - } elseif ( isset( $form->$key ) ) { |
|
137 | + } elseif (isset($form->$key)) { |
|
138 | 138 | |
139 | - switch ( $key ) { |
|
139 | + switch ($key) { |
|
140 | 140 | |
141 | 141 | case 'post_author' : |
142 | 142 | |
143 | - $row[ $key ] = get_the_author_meta( 'user_login', $form->post_author ); |
|
143 | + $row[$key] = get_the_author_meta('user_login', $form->post_author); |
|
144 | 144 | |
145 | 145 | break; |
146 | 146 | |
147 | 147 | default : |
148 | 148 | |
149 | - $row[ $key ] = $form->$key; |
|
149 | + $row[$key] = $form->$key; |
|
150 | 150 | |
151 | 151 | break; |
152 | 152 | } |
153 | 153 | |
154 | - } elseif ( 'tags' == $key ) { |
|
154 | + } elseif ('tags' == $key) { |
|
155 | 155 | |
156 | - $terms = get_the_terms( $form->ID, 'form_tag' ); |
|
157 | - if ( $terms ) { |
|
158 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
159 | - $row[ $key ] = implode( ' | ', $terms ); |
|
156 | + $terms = get_the_terms($form->ID, 'form_tag'); |
|
157 | + if ($terms) { |
|
158 | + $terms = wp_list_pluck($terms, 'name'); |
|
159 | + $row[$key] = implode(' | ', $terms); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | |
163 | - } elseif ( 'categories' == $key ) { |
|
163 | + } elseif ('categories' == $key) { |
|
164 | 164 | |
165 | - $terms = get_the_terms( $form->ID, 'form_category' ); |
|
166 | - if ( $terms ) { |
|
167 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
168 | - $row[ $key ] = implode( ' | ', $terms ); |
|
165 | + $terms = get_the_terms($form->ID, 'form_category'); |
|
166 | + if ($terms) { |
|
167 | + $terms = wp_list_pluck($terms, 'name'); |
|
168 | + $row[$key] = implode(' | ', $terms); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | } |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | |
177 | 177 | } |
178 | 178 | |
179 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
180 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
179 | + $data = apply_filters('give_export_get_data', $data); |
|
180 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
181 | 181 | |
182 | 182 | return $data; |
183 | 183 | |
@@ -197,20 +197,20 @@ discard block |
||
197 | 197 | |
198 | 198 | $args = array( |
199 | 199 | 'post_type' => 'give_forms', |
200 | - 'posts_per_page' => - 1, |
|
200 | + 'posts_per_page' => -1, |
|
201 | 201 | 'post_status' => 'any', |
202 | 202 | 'fields' => 'ids', |
203 | 203 | ); |
204 | 204 | |
205 | - $forms = new WP_Query( $args ); |
|
205 | + $forms = new WP_Query($args); |
|
206 | 206 | $total = (int) $forms->post_count; |
207 | 207 | $percentage = 100; |
208 | 208 | |
209 | - if ( $total > 0 ) { |
|
210 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
209 | + if ($total > 0) { |
|
210 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
211 | 211 | } |
212 | 212 | |
213 | - if ( $percentage > 100 ) { |
|
213 | + if ($percentage > 100) { |
|
214 | 214 | $percentage = 100; |
215 | 215 | } |
216 | 216 |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @access public |
218 | 218 | * @since 1.1 |
219 | - * @return array |
|
219 | + * @return string |
|
220 | 220 | */ |
221 | 221 | public function get_versions() { |
222 | 222 | return $this->versions; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @uses Give_API::invalid_key() |
303 | 303 | * @uses Give_API::invalid_auth() |
304 | 304 | * @since 1.1 |
305 | - * @return bool |
|
305 | + * @return false|null |
|
306 | 306 | */ |
307 | 307 | private function validate_request() { |
308 | 308 | global $wp_query; |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | * |
695 | 695 | * @param array $args Arguments to override defaults |
696 | 696 | * |
697 | - * @return array $dates |
|
697 | + * @return integer|null $dates |
|
698 | 698 | */ |
699 | 699 | public function get_dates( $args = array() ) { |
700 | 700 | $dates = array(); |
@@ -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 | |
@@ -141,27 +141,27 @@ discard block |
||
141 | 141 | 'v1' => 'GIVE_API_V1', |
142 | 142 | ); |
143 | 143 | |
144 | - foreach ( $this->get_versions() as $version => $class ) { |
|
145 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
144 | + foreach ($this->get_versions() as $version => $class) { |
|
145 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
146 | 146 | } |
147 | 147 | |
148 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
149 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
150 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
151 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
153 | - add_action( 'personal_options_update', array( $this, 'generate_api_key' ) ); |
|
154 | - add_action( 'edit_user_profile_update', array( $this, 'generate_api_key' ) ); |
|
155 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
148 | + add_action('init', array($this, 'add_endpoint')); |
|
149 | + add_action('wp', array($this, 'process_query'), - 1); |
|
150 | + add_filter('query_vars', array($this, 'query_vars')); |
|
151 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
153 | + add_action('personal_options_update', array($this, 'generate_api_key')); |
|
154 | + add_action('edit_user_profile_update', array($this, 'generate_api_key')); |
|
155 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
156 | 156 | |
157 | 157 | // Setup a backwards compatibility check for user API Keys |
158 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
158 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
159 | 159 | |
160 | 160 | // Determine if JSON_PRETTY_PRINT is available |
161 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
161 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
162 | 162 | |
163 | 163 | // Allow API request logging to be turned off |
164 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
164 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
165 | 165 | |
166 | 166 | // Setup Give_Payment_Stats instance |
167 | 167 | $this->stats = new Give_Payment_Stats(); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @since 1.1 |
177 | 177 | */ |
178 | 178 | public function add_endpoint() { |
179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
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 | |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | $this->override = false; |
309 | 309 | |
310 | 310 | // Make sure we have both user and api key |
311 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] !== 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
311 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] !== 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
312 | 312 | |
313 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
313 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
314 | 314 | $this->missing_auth(); |
315 | 315 | |
316 | 316 | return false; |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Retrieve the user by public API key and ensure they exist |
320 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
320 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
321 | 321 | |
322 | 322 | $this->invalid_key(); |
323 | 323 | |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | |
326 | 326 | } else { |
327 | 327 | |
328 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
329 | - $secret = $this->get_user_secret_key( $user ); |
|
330 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
328 | + $token = urldecode($wp_query->query_vars['token']); |
|
329 | + $secret = $this->get_user_secret_key($user); |
|
330 | + $public = urldecode($wp_query->query_vars['key']); |
|
331 | 331 | |
332 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
332 | + if (hash_equals(md5($secret.$public), $token)) { |
|
333 | 333 | $this->is_valid_request = true; |
334 | 334 | } else { |
335 | 335 | $this->invalid_auth(); |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | } |
341 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] === 'forms' ) { |
|
341 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] === 'forms') { |
|
342 | 342 | $this->is_valid_request = true; |
343 | - $wp_query->set( 'key', 'public' ); |
|
343 | + $wp_query->set('key', 'public'); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -356,25 +356,25 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @return bool if user ID is found, false otherwise |
358 | 358 | */ |
359 | - public function get_user( $key = '' ) { |
|
359 | + public function get_user($key = '') { |
|
360 | 360 | global $wpdb, $wp_query; |
361 | 361 | |
362 | - if ( empty( $key ) ) { |
|
363 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
362 | + if (empty($key)) { |
|
363 | + $key = urldecode($wp_query->query_vars['key']); |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( empty( $key ) ) { |
|
366 | + if (empty($key)) { |
|
367 | 367 | return false; |
368 | 368 | } |
369 | 369 | |
370 | - $user = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
|
370 | + $user = Give_Cache::get(md5('give_api_user_'.$key), true); |
|
371 | 371 | |
372 | - if ( false === $user ) { |
|
373 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
374 | - Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
|
372 | + if (false === $user) { |
|
373 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
374 | + Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true); |
|
375 | 375 | } |
376 | 376 | |
377 | - if ( $user != null ) { |
|
377 | + if ($user != null) { |
|
378 | 378 | $this->user_id = $user; |
379 | 379 | |
380 | 380 | return $user; |
@@ -390,19 +390,19 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return mixed|null|string |
392 | 392 | */ |
393 | - public function get_user_public_key( $user_id = 0 ) { |
|
393 | + public function get_user_public_key($user_id = 0) { |
|
394 | 394 | global $wpdb; |
395 | 395 | |
396 | - if ( empty( $user_id ) ) { |
|
396 | + if (empty($user_id)) { |
|
397 | 397 | return ''; |
398 | 398 | } |
399 | 399 | |
400 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
401 | - $user_public_key = Give_Cache::get( $cache_key, true ); |
|
400 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
401 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
402 | 402 | |
403 | - if ( empty( $user_public_key ) ) { |
|
404 | - $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 ) ); |
|
405 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
403 | + if (empty($user_public_key)) { |
|
404 | + $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)); |
|
405 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return $user_public_key; |
@@ -415,19 +415,19 @@ discard block |
||
415 | 415 | * |
416 | 416 | * @return mixed|null|string |
417 | 417 | */ |
418 | - public function get_user_secret_key( $user_id = 0 ) { |
|
418 | + public function get_user_secret_key($user_id = 0) { |
|
419 | 419 | global $wpdb; |
420 | 420 | |
421 | - if ( empty( $user_id ) ) { |
|
421 | + if (empty($user_id)) { |
|
422 | 422 | return ''; |
423 | 423 | } |
424 | 424 | |
425 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
426 | - $user_secret_key = Give_Cache::get( $cache_key, true ); |
|
425 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
426 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
427 | 427 | |
428 | - if ( empty( $user_secret_key ) ) { |
|
429 | - $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 ) ); |
|
430 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
428 | + if (empty($user_secret_key)) { |
|
429 | + $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)); |
|
430 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | return $user_secret_key; |
@@ -443,10 +443,10 @@ discard block |
||
443 | 443 | */ |
444 | 444 | private function missing_auth() { |
445 | 445 | $error = array(); |
446 | - $error['error'] = __( 'You must specify both a token and API key.', 'give' ); |
|
446 | + $error['error'] = __('You must specify both a token and API key.', 'give'); |
|
447 | 447 | |
448 | 448 | $this->data = $error; |
449 | - $this->output( 401 ); |
|
449 | + $this->output(401); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -460,10 +460,10 @@ discard block |
||
460 | 460 | */ |
461 | 461 | private function invalid_auth() { |
462 | 462 | $error = array(); |
463 | - $error['error'] = __( 'Your request could not be authenticated.', 'give' ); |
|
463 | + $error['error'] = __('Your request could not be authenticated.', 'give'); |
|
464 | 464 | |
465 | 465 | $this->data = $error; |
466 | - $this->output( 403 ); |
|
466 | + $this->output(403); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
477 | 477 | */ |
478 | 478 | private function invalid_key() { |
479 | 479 | $error = array(); |
480 | - $error['error'] = __( 'Invalid API key.', 'give' ); |
|
480 | + $error['error'] = __('Invalid API key.', 'give'); |
|
481 | 481 | |
482 | 482 | $this->data = $error; |
483 | - $this->output( 403 ); |
|
483 | + $this->output(403); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -493,10 +493,10 @@ discard block |
||
493 | 493 | */ |
494 | 494 | private function invalid_version() { |
495 | 495 | $error = array(); |
496 | - $error['error'] = __( 'Invalid API version.', 'give' ); |
|
496 | + $error['error'] = __('Invalid API version.', 'give'); |
|
497 | 497 | |
498 | 498 | $this->data = $error; |
499 | - $this->output( 404 ); |
|
499 | + $this->output(404); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -512,10 +512,10 @@ discard block |
||
512 | 512 | global $wp_query; |
513 | 513 | |
514 | 514 | // Start logging how long the request takes for logging |
515 | - $before = microtime( true ); |
|
515 | + $before = microtime(true); |
|
516 | 516 | |
517 | 517 | // Check for give-api var. Get out if not present |
518 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
518 | + if (empty($wp_query->query_vars['give-api'])) { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
@@ -529,45 +529,45 @@ discard block |
||
529 | 529 | $this->validate_request(); |
530 | 530 | |
531 | 531 | // Only proceed if no errors have been noted |
532 | - if ( ! $this->is_valid_request ) { |
|
532 | + if ( ! $this->is_valid_request) { |
|
533 | 533 | return; |
534 | 534 | } |
535 | 535 | |
536 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
537 | - define( 'GIVE_DOING_API', true ); |
|
536 | + if ( ! defined('GIVE_DOING_API')) { |
|
537 | + define('GIVE_DOING_API', true); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | $data = array(); |
541 | 541 | $this->routes = new $this->versions[$this->get_queried_version()]; |
542 | 542 | $this->routes->validate_request(); |
543 | 543 | |
544 | - switch ( $this->endpoint ) : |
|
544 | + switch ($this->endpoint) : |
|
545 | 545 | |
546 | 546 | case 'stats' : |
547 | 547 | |
548 | - $data = $this->routes->get_stats( array( |
|
549 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
550 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
551 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
552 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
553 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
554 | - ) ); |
|
548 | + $data = $this->routes->get_stats(array( |
|
549 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
550 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
551 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
552 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
553 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
554 | + )); |
|
555 | 555 | |
556 | 556 | break; |
557 | 557 | |
558 | 558 | case 'forms' : |
559 | 559 | |
560 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
560 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
561 | 561 | |
562 | - $data = $this->routes->get_forms( $form ); |
|
562 | + $data = $this->routes->get_forms($form); |
|
563 | 563 | |
564 | 564 | break; |
565 | 565 | |
566 | 566 | case 'donors' : |
567 | 567 | |
568 | - $donor = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
568 | + $donor = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
569 | 569 | |
570 | - $data = $this->routes->get_donors( $donor ); |
|
570 | + $data = $this->routes->get_donors($donor); |
|
571 | 571 | |
572 | 572 | break; |
573 | 573 | |
@@ -580,26 +580,26 @@ discard block |
||
580 | 580 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
581 | 581 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
582 | 582 | */ |
583 | - $data = $this->routes->get_recent_donations( array( |
|
584 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
585 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
586 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
587 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
588 | - ) ); |
|
583 | + $data = $this->routes->get_recent_donations(array( |
|
584 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
585 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
586 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
587 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
588 | + )); |
|
589 | 589 | |
590 | 590 | break; |
591 | 591 | |
592 | 592 | endswitch; |
593 | 593 | |
594 | 594 | // Allow extensions to setup their own return data |
595 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
595 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
596 | 596 | |
597 | - $after = microtime( true ); |
|
598 | - $request_time = ( $after - $before ); |
|
597 | + $after = microtime(true); |
|
598 | + $request_time = ($after - $before); |
|
599 | 599 | $this->data['request_speed'] = $request_time; |
600 | 600 | |
601 | 601 | // Log this API request, if enabled. We log it here because we have access to errors. |
602 | - $this->log_request( $this->data ); |
|
602 | + $this->log_request($this->data); |
|
603 | 603 | |
604 | 604 | // Send out data to the output function |
605 | 605 | $this->output(); |
@@ -629,25 +629,25 @@ discard block |
||
629 | 629 | global $wp_query; |
630 | 630 | |
631 | 631 | // Whitelist our query options |
632 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
632 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
633 | 633 | 'stats', |
634 | 634 | 'forms', |
635 | 635 | 'donors', |
636 | 636 | 'donations', |
637 | - ) ); |
|
637 | + )); |
|
638 | 638 | |
639 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
640 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
639 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
640 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
641 | 641 | |
642 | 642 | $error = array(); |
643 | 643 | |
644 | 644 | // Make sure our query is valid |
645 | - if ( ! in_array( $query, $accepted ) ) { |
|
646 | - $error['error'] = __( 'Invalid query.', 'give' ); |
|
645 | + if ( ! in_array($query, $accepted)) { |
|
646 | + $error['error'] = __('Invalid query.', 'give'); |
|
647 | 647 | |
648 | 648 | $this->data = $error; |
649 | 649 | // 400 is Bad Request |
650 | - $this->output( 400 ); |
|
650 | + $this->output(400); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | $this->endpoint = $query; |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | public function get_paged() { |
665 | 665 | global $wp_query; |
666 | 666 | |
667 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
667 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | |
@@ -679,13 +679,13 @@ discard block |
||
679 | 679 | public function per_page() { |
680 | 680 | global $wp_query; |
681 | 681 | |
682 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
682 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
683 | 683 | |
684 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
684 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
685 | 685 | $per_page = 99999999; |
686 | 686 | } // End if(). |
687 | 687 | |
688 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
688 | + return apply_filters('give_api_results_per_page', $per_page); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | * |
699 | 699 | * @return array $dates |
700 | 700 | */ |
701 | - public function get_dates( $args = array() ) { |
|
701 | + public function get_dates($args = array()) { |
|
702 | 702 | $dates = array(); |
703 | 703 | |
704 | 704 | $defaults = array( |
@@ -709,60 +709,60 @@ discard block |
||
709 | 709 | 'enddate' => null, |
710 | 710 | ); |
711 | 711 | |
712 | - $args = wp_parse_args( $args, $defaults ); |
|
712 | + $args = wp_parse_args($args, $defaults); |
|
713 | 713 | |
714 | - $current_time = current_time( 'timestamp' ); |
|
714 | + $current_time = current_time('timestamp'); |
|
715 | 715 | |
716 | - if ( 'range' === $args['date'] ) { |
|
717 | - $startdate = strtotime( $args['startdate'] ); |
|
718 | - $enddate = strtotime( $args['enddate'] ); |
|
719 | - $dates['day_start'] = date( 'd', $startdate ); |
|
720 | - $dates['day_end'] = date( 'd', $enddate ); |
|
721 | - $dates['m_start'] = date( 'n', $startdate ); |
|
722 | - $dates['m_end'] = date( 'n', $enddate ); |
|
723 | - $dates['year'] = date( 'Y', $startdate ); |
|
724 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
716 | + if ('range' === $args['date']) { |
|
717 | + $startdate = strtotime($args['startdate']); |
|
718 | + $enddate = strtotime($args['enddate']); |
|
719 | + $dates['day_start'] = date('d', $startdate); |
|
720 | + $dates['day_end'] = date('d', $enddate); |
|
721 | + $dates['m_start'] = date('n', $startdate); |
|
722 | + $dates['m_end'] = date('n', $enddate); |
|
723 | + $dates['year'] = date('Y', $startdate); |
|
724 | + $dates['year_end'] = date('Y', $enddate); |
|
725 | 725 | } else { |
726 | 726 | // Modify dates based on predefined ranges |
727 | - switch ( $args['date'] ) : |
|
727 | + switch ($args['date']) : |
|
728 | 728 | |
729 | 729 | case 'this_month' : |
730 | 730 | $dates['day'] = null; |
731 | - $dates['m_start'] = date( 'n', $current_time ); |
|
732 | - $dates['m_end'] = date( 'n', $current_time ); |
|
733 | - $dates['year'] = date( 'Y', $current_time ); |
|
731 | + $dates['m_start'] = date('n', $current_time); |
|
732 | + $dates['m_end'] = date('n', $current_time); |
|
733 | + $dates['year'] = date('Y', $current_time); |
|
734 | 734 | break; |
735 | 735 | |
736 | 736 | case 'last_month' : |
737 | 737 | $dates['day'] = null; |
738 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
738 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
739 | 739 | $dates['m_end'] = $dates['m_start']; |
740 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
740 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
741 | 741 | break; |
742 | 742 | |
743 | 743 | case 'today' : |
744 | - $dates['day'] = date( 'd', $current_time ); |
|
745 | - $dates['m_start'] = date( 'n', $current_time ); |
|
746 | - $dates['m_end'] = date( 'n', $current_time ); |
|
747 | - $dates['year'] = date( 'Y', $current_time ); |
|
744 | + $dates['day'] = date('d', $current_time); |
|
745 | + $dates['m_start'] = date('n', $current_time); |
|
746 | + $dates['m_end'] = date('n', $current_time); |
|
747 | + $dates['year'] = date('Y', $current_time); |
|
748 | 748 | break; |
749 | 749 | |
750 | 750 | case 'yesterday' : |
751 | 751 | |
752 | - $year = date( 'Y', $current_time ); |
|
753 | - $month = date( 'n', $current_time ); |
|
754 | - $day = date( 'd', $current_time ); |
|
752 | + $year = date('Y', $current_time); |
|
753 | + $month = date('n', $current_time); |
|
754 | + $day = date('d', $current_time); |
|
755 | 755 | |
756 | - if ( $month == 1 && $day == 1 ) { |
|
756 | + if ($month == 1 && $day == 1) { |
|
757 | 757 | |
758 | - $year -= 1; |
|
758 | + $year -= 1; |
|
759 | 759 | $month = 12; |
760 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
760 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
761 | 761 | |
762 | - } elseif ( $month > 1 && $day == 1 ) { |
|
762 | + } elseif ($month > 1 && $day == 1) { |
|
763 | 763 | |
764 | 764 | $month -= 1; |
765 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
765 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
766 | 766 | |
767 | 767 | } else { |
768 | 768 | |
@@ -778,65 +778,65 @@ discard block |
||
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'this_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'] = 1; |
788 | 788 | $dates['m_end'] = 3; |
789 | - $dates['year'] = date( 'Y', $current_time ); |
|
789 | + $dates['year'] = date('Y', $current_time); |
|
790 | 790 | |
791 | - } elseif ( $month_now <= 6 ) { |
|
791 | + } elseif ($month_now <= 6) { |
|
792 | 792 | |
793 | 793 | $dates['m_start'] = 4; |
794 | 794 | $dates['m_end'] = 6; |
795 | - $dates['year'] = date( 'Y', $current_time ); |
|
795 | + $dates['year'] = date('Y', $current_time); |
|
796 | 796 | |
797 | - } elseif ( $month_now <= 9 ) { |
|
797 | + } elseif ($month_now <= 9) { |
|
798 | 798 | |
799 | 799 | $dates['m_start'] = 7; |
800 | 800 | $dates['m_end'] = 9; |
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'] = 10; |
806 | 806 | $dates['m_end'] = 12; |
807 | - $dates['year'] = date( 'Y', $current_time ); |
|
807 | + $dates['year'] = date('Y', $current_time); |
|
808 | 808 | |
809 | 809 | } |
810 | 810 | break; |
811 | 811 | |
812 | 812 | case 'last_quarter' : |
813 | - $month_now = date( 'n', $current_time ); |
|
813 | + $month_now = date('n', $current_time); |
|
814 | 814 | |
815 | 815 | $dates['day'] = null; |
816 | 816 | |
817 | - if ( $month_now <= 3 ) { |
|
817 | + if ($month_now <= 3) { |
|
818 | 818 | |
819 | 819 | $dates['m_start'] = 10; |
820 | 820 | $dates['m_end'] = 12; |
821 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
821 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
822 | 822 | |
823 | - } elseif ( $month_now <= 6 ) { |
|
823 | + } elseif ($month_now <= 6) { |
|
824 | 824 | |
825 | 825 | $dates['m_start'] = 1; |
826 | 826 | $dates['m_end'] = 3; |
827 | - $dates['year'] = date( 'Y', $current_time ); |
|
827 | + $dates['year'] = date('Y', $current_time); |
|
828 | 828 | |
829 | - } elseif ( $month_now <= 9 ) { |
|
829 | + } elseif ($month_now <= 9) { |
|
830 | 830 | |
831 | 831 | $dates['m_start'] = 4; |
832 | 832 | $dates['m_end'] = 6; |
833 | - $dates['year'] = date( 'Y', $current_time ); |
|
833 | + $dates['year'] = date('Y', $current_time); |
|
834 | 834 | |
835 | 835 | } else { |
836 | 836 | |
837 | 837 | $dates['m_start'] = 7; |
838 | 838 | $dates['m_end'] = 9; |
839 | - $dates['year'] = date( 'Y', $current_time ); |
|
839 | + $dates['year'] = date('Y', $current_time); |
|
840 | 840 | |
841 | 841 | } |
842 | 842 | break; |
@@ -845,14 +845,14 @@ discard block |
||
845 | 845 | $dates['day'] = null; |
846 | 846 | $dates['m_start'] = null; |
847 | 847 | $dates['m_end'] = null; |
848 | - $dates['year'] = date( 'Y', $current_time ); |
|
848 | + $dates['year'] = date('Y', $current_time); |
|
849 | 849 | break; |
850 | 850 | |
851 | 851 | case 'last_year' : |
852 | 852 | $dates['day'] = null; |
853 | 853 | $dates['m_start'] = null; |
854 | 854 | $dates['m_end'] = null; |
855 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
855 | + $dates['year'] = date('Y', $current_time) - 1; |
|
856 | 856 | break; |
857 | 857 | |
858 | 858 | endswitch; |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * |
866 | 866 | * @param array $dates The dates used for retrieving earnings. |
867 | 867 | */ |
868 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
868 | + return apply_filters('give_api_stat_dates', $dates); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -879,78 +879,78 @@ discard block |
||
879 | 879 | * |
880 | 880 | * @return array $donors Multidimensional array of the donors. |
881 | 881 | */ |
882 | - public function get_donors( $donor = null ) { |
|
882 | + public function get_donors($donor = null) { |
|
883 | 883 | |
884 | 884 | $donors = array(); |
885 | 885 | $error = array(); |
886 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
886 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
887 | 887 | return $donors; |
888 | 888 | } |
889 | 889 | |
890 | 890 | $paged = $this->get_paged(); |
891 | 891 | $per_page = $this->per_page(); |
892 | - $offset = $per_page * ( $paged - 1 ); |
|
892 | + $offset = $per_page * ($paged - 1); |
|
893 | 893 | |
894 | - if ( is_numeric( $donor ) ) { |
|
894 | + if (is_numeric($donor)) { |
|
895 | 895 | $field = 'id'; |
896 | 896 | } else { |
897 | 897 | $field = 'email'; |
898 | 898 | } |
899 | 899 | |
900 | - $donor_query = Give()->donors->get_donors( array( |
|
900 | + $donor_query = Give()->donors->get_donors(array( |
|
901 | 901 | 'number' => $per_page, |
902 | 902 | 'offset' => $offset, |
903 | 903 | $field => $donor, |
904 | - ) ); |
|
904 | + )); |
|
905 | 905 | $donor_count = 0; |
906 | 906 | |
907 | - if ( $donor_query ) { |
|
907 | + if ($donor_query) { |
|
908 | 908 | |
909 | - foreach ( $donor_query as $donor_obj ) { |
|
909 | + foreach ($donor_query as $donor_obj) { |
|
910 | 910 | |
911 | - $names = explode( ' ', $donor_obj->name ); |
|
912 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
911 | + $names = explode(' ', $donor_obj->name); |
|
912 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
913 | 913 | $last_name = ''; |
914 | - if ( ! empty( $names[1] ) ) { |
|
915 | - unset( $names[0] ); |
|
916 | - $last_name = implode( ' ', $names ); |
|
914 | + if ( ! empty($names[1])) { |
|
915 | + unset($names[0]); |
|
916 | + $last_name = implode(' ', $names); |
|
917 | 917 | } |
918 | 918 | |
919 | - $donors['donors'][ $donor_count ]['info']['user_id'] = ''; |
|
920 | - $donors['donors'][ $donor_count ]['info']['username'] = ''; |
|
921 | - $donors['donors'][ $donor_count ]['info']['display_name'] = ''; |
|
922 | - $donors['donors'][ $donor_count ]['info']['donor_id'] = $donor_obj->id; |
|
923 | - $donors['donors'][ $donor_count ]['info']['first_name'] = $first_name; |
|
924 | - $donors['donors'][ $donor_count ]['info']['last_name'] = $last_name; |
|
925 | - $donors['donors'][ $donor_count ]['info']['email'] = $donor_obj->email; |
|
919 | + $donors['donors'][$donor_count]['info']['user_id'] = ''; |
|
920 | + $donors['donors'][$donor_count]['info']['username'] = ''; |
|
921 | + $donors['donors'][$donor_count]['info']['display_name'] = ''; |
|
922 | + $donors['donors'][$donor_count]['info']['donor_id'] = $donor_obj->id; |
|
923 | + $donors['donors'][$donor_count]['info']['first_name'] = $first_name; |
|
924 | + $donors['donors'][$donor_count]['info']['last_name'] = $last_name; |
|
925 | + $donors['donors'][$donor_count]['info']['email'] = $donor_obj->email; |
|
926 | 926 | |
927 | - if ( ! empty( $donor_obj->user_id ) ) { |
|
927 | + if ( ! empty($donor_obj->user_id)) { |
|
928 | 928 | |
929 | - $user_data = get_userdata( $donor_obj->user_id ); |
|
929 | + $user_data = get_userdata($donor_obj->user_id); |
|
930 | 930 | |
931 | 931 | // Donor with registered account. |
932 | - $donors['donors'][ $donor_count ]['info']['user_id'] = $donor_obj->user_id; |
|
933 | - $donors['donors'][ $donor_count ]['info']['username'] = $user_data->user_login; |
|
934 | - $donors['donors'][ $donor_count ]['info']['display_name'] = $user_data->display_name; |
|
932 | + $donors['donors'][$donor_count]['info']['user_id'] = $donor_obj->user_id; |
|
933 | + $donors['donors'][$donor_count]['info']['username'] = $user_data->user_login; |
|
934 | + $donors['donors'][$donor_count]['info']['display_name'] = $user_data->display_name; |
|
935 | 935 | |
936 | 936 | } |
937 | 937 | |
938 | - $donors['donors'][ $donor_count ]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
939 | - $donors['donors'][ $donor_count ]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
938 | + $donors['donors'][$donor_count]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
939 | + $donors['donors'][$donor_count]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
940 | 940 | |
941 | - $donor_count ++; |
|
941 | + $donor_count++; |
|
942 | 942 | |
943 | 943 | } |
944 | - } elseif ( $donor ) { |
|
944 | + } elseif ($donor) { |
|
945 | 945 | |
946 | 946 | $error['error'] = sprintf( /* translators: %s: donor */ |
947 | - __( 'Donor %s not found.', 'give' ), $donor ); |
|
947 | + __('Donor %s not found.', 'give'), $donor ); |
|
948 | 948 | |
949 | 949 | return $error; |
950 | 950 | |
951 | 951 | } else { |
952 | 952 | |
953 | - $error['error'] = __( 'No donors found.', 'give' ); |
|
953 | + $error['error'] = __('No donors found.', 'give'); |
|
954 | 954 | |
955 | 955 | return $error; |
956 | 956 | |
@@ -969,37 +969,37 @@ discard block |
||
969 | 969 | * |
970 | 970 | * @return array $donors Multidimensional array of the forms. |
971 | 971 | */ |
972 | - public function get_forms( $form = null ) { |
|
972 | + public function get_forms($form = null) { |
|
973 | 973 | |
974 | 974 | $forms = array(); |
975 | 975 | $error = array(); |
976 | 976 | |
977 | - if ( $form == null ) { |
|
977 | + if ($form == null) { |
|
978 | 978 | $forms['forms'] = array(); |
979 | 979 | |
980 | - $form_list = get_posts( array( |
|
980 | + $form_list = get_posts(array( |
|
981 | 981 | 'post_type' => 'give_forms', |
982 | 982 | 'posts_per_page' => $this->per_page(), |
983 | 983 | 'suppress_filters' => true, |
984 | 984 | 'paged' => $this->get_paged(), |
985 | - ) ); |
|
985 | + )); |
|
986 | 986 | |
987 | - if ( $form_list ) { |
|
987 | + if ($form_list) { |
|
988 | 988 | $i = 0; |
989 | - foreach ( $form_list as $form_info ) { |
|
990 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
991 | - $i ++; |
|
989 | + foreach ($form_list as $form_info) { |
|
990 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
991 | + $i++; |
|
992 | 992 | } |
993 | 993 | } |
994 | 994 | } else { |
995 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
996 | - $form_info = get_post( $form ); |
|
995 | + if (get_post_type($form) == 'give_forms') { |
|
996 | + $form_info = get_post($form); |
|
997 | 997 | |
998 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
998 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
999 | 999 | |
1000 | 1000 | } else { |
1001 | 1001 | $error['error'] = sprintf( /* translators: %s: form */ |
1002 | - __( 'Form %s not found.', 'give' ), $form ); |
|
1002 | + __('Form %s not found.', 'give'), $form ); |
|
1003 | 1003 | |
1004 | 1004 | return $error; |
1005 | 1005 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | * |
1018 | 1018 | * @return array Array of post data to return back in the API. |
1019 | 1019 | */ |
1020 | - private function get_form_data( $form_info ) { |
|
1020 | + private function get_form_data($form_info) { |
|
1021 | 1021 | |
1022 | 1022 | $form = array(); |
1023 | 1023 | |
@@ -1027,60 +1027,60 @@ discard block |
||
1027 | 1027 | $form['info']['create_date'] = $form_info->post_date; |
1028 | 1028 | $form['info']['modified_date'] = $form_info->post_modified; |
1029 | 1029 | $form['info']['status'] = $form_info->post_status; |
1030 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1031 | - $form['info']['content'] = give_get_meta( $form_info->ID, '_give_form_content', true ); |
|
1032 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1030 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1031 | + $form['info']['content'] = give_get_meta($form_info->ID, '_give_form_content', true); |
|
1032 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1033 | 1033 | |
1034 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
1035 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1036 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1034 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
1035 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1036 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1037 | 1037 | } |
1038 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
1039 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1038 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
1039 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | // Check whether any goal is to be achieved for the donation form. |
1043 | - $goal_option = give_get_meta( $form_info->ID, '_give_goal_option', true ); |
|
1044 | - $goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true ); |
|
1045 | - if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) { |
|
1046 | - $total_income = give_get_form_earnings_stats( $form_info->ID ); |
|
1047 | - $goal_percentage_completed = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100; |
|
1048 | - $form['goal']['amount'] = isset( $goal_amount ) ? $goal_amount : ''; |
|
1049 | - $form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : ''; |
|
1043 | + $goal_option = give_get_meta($form_info->ID, '_give_goal_option', true); |
|
1044 | + $goal_amount = give_get_meta($form_info->ID, '_give_set_goal', true); |
|
1045 | + if (give_is_setting_enabled($goal_option) && $goal_amount) { |
|
1046 | + $total_income = give_get_form_earnings_stats($form_info->ID); |
|
1047 | + $goal_percentage_completed = ($total_income < $goal_amount) ? round(($total_income / $goal_amount) * 100, 2) : 100; |
|
1048 | + $form['goal']['amount'] = isset($goal_amount) ? $goal_amount : ''; |
|
1049 | + $form['goal']['percentage_completed'] = isset($goal_percentage_completed) ? $goal_percentage_completed : ''; |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1053 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1054 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1055 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1056 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1052 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1053 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1054 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1055 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1056 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | $counter = 0; |
1060 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1061 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1062 | - $counter ++; |
|
1060 | + if (give_has_variable_prices($form_info->ID)) { |
|
1061 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1062 | + $counter++; |
|
1063 | 1063 | // multi-level item |
1064 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1065 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1064 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1065 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1066 | 1066 | |
1067 | 1067 | } |
1068 | 1068 | } else { |
1069 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1069 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1070 | 1070 | } |
1071 | 1071 | |
1072 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1072 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1073 | 1073 | |
1074 | 1074 | /** |
1075 | 1075 | * Fires when generating API sensitive data. |
1076 | 1076 | * |
1077 | 1077 | * @since 1.1 |
1078 | 1078 | */ |
1079 | - do_action( 'give_api_sensitive_data' ); |
|
1079 | + do_action('give_api_sensitive_data'); |
|
1080 | 1080 | |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1083 | + return apply_filters('give_api_forms_form', $form); |
|
1084 | 1084 | |
1085 | 1085 | } |
1086 | 1086 | |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | * |
1096 | 1096 | * @return array |
1097 | 1097 | */ |
1098 | - public function get_stats( $args = array() ) { |
|
1098 | + public function get_stats($args = array()) { |
|
1099 | 1099 | $defaults = array( |
1100 | 1100 | 'type' => null, |
1101 | 1101 | 'form' => null, |
@@ -1104,9 +1104,9 @@ discard block |
||
1104 | 1104 | 'enddate' => null, |
1105 | 1105 | ); |
1106 | 1106 | |
1107 | - $args = wp_parse_args( $args, $defaults ); |
|
1107 | + $args = wp_parse_args($args, $defaults); |
|
1108 | 1108 | |
1109 | - $dates = $this->get_dates( $args ); |
|
1109 | + $dates = $this->get_dates($args); |
|
1110 | 1110 | |
1111 | 1111 | $stats = array(); |
1112 | 1112 | $earnings = array( |
@@ -1117,40 +1117,40 @@ discard block |
||
1117 | 1117 | ); |
1118 | 1118 | $error = array(); |
1119 | 1119 | |
1120 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1120 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1121 | 1121 | return $stats; |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - if ( $args['type'] == 'donations' ) { |
|
1124 | + if ($args['type'] == 'donations') { |
|
1125 | 1125 | |
1126 | - if ( $args['form'] == null ) { |
|
1127 | - if ( $args['date'] == null ) { |
|
1126 | + if ($args['form'] == null) { |
|
1127 | + if ($args['date'] == null) { |
|
1128 | 1128 | $donations = $this->get_default_sales_stats(); |
1129 | - } elseif ( $args['date'] === 'range' ) { |
|
1129 | + } elseif ($args['date'] === 'range') { |
|
1130 | 1130 | // Return donations for a date range. |
1131 | 1131 | // Ensure the end date is later than the start date. |
1132 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1133 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
1132 | + if ($args['enddate'] < $args['startdate']) { |
|
1133 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | // Ensure both the start and end date are specified |
1137 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1138 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
1137 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1138 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | $total = 0; |
1142 | 1142 | |
1143 | 1143 | // Loop through the years |
1144 | 1144 | $y = $dates['year']; |
1145 | - while ( $y <= $dates['year_end'] ) : |
|
1145 | + while ($y <= $dates['year_end']) : |
|
1146 | 1146 | |
1147 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1147 | + if ($dates['year'] == $dates['year_end']) { |
|
1148 | 1148 | $month_start = $dates['m_start']; |
1149 | 1149 | $month_end = $dates['m_end']; |
1150 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1150 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1151 | 1151 | $month_start = $dates['m_start']; |
1152 | 1152 | $month_end = 12; |
1153 | - } elseif ( $y == $dates['year_end'] ) { |
|
1153 | + } elseif ($y == $dates['year_end']) { |
|
1154 | 1154 | $month_start = 1; |
1155 | 1155 | $month_end = $dates['m_end']; |
1156 | 1156 | } else { |
@@ -1159,116 +1159,116 @@ discard block |
||
1159 | 1159 | } |
1160 | 1160 | |
1161 | 1161 | $i = $month_start; |
1162 | - while ( $i <= $month_end ) : |
|
1162 | + while ($i <= $month_end) : |
|
1163 | 1163 | |
1164 | - if ( $i == $dates['m_start'] ) { |
|
1164 | + if ($i == $dates['m_start']) { |
|
1165 | 1165 | $d = $dates['day_start']; |
1166 | 1166 | } else { |
1167 | 1167 | $d = 1; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - if ( $i == $dates['m_end'] ) { |
|
1170 | + if ($i == $dates['m_end']) { |
|
1171 | 1171 | $num_of_days = $dates['day_end']; |
1172 | 1172 | } else { |
1173 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1173 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | - while ( $d <= $num_of_days ) : |
|
1177 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1178 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1179 | - if ( ! isset( $donations['sales'][ $date_key ] ) ) { |
|
1180 | - $donations['sales'][ $date_key ] = 0; |
|
1176 | + while ($d <= $num_of_days) : |
|
1177 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1178 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1179 | + if ( ! isset($donations['sales'][$date_key])) { |
|
1180 | + $donations['sales'][$date_key] = 0; |
|
1181 | 1181 | } |
1182 | - $donations['sales'][ $date_key ] += $sale_count; |
|
1182 | + $donations['sales'][$date_key] += $sale_count; |
|
1183 | 1183 | $total += $sale_count; |
1184 | - $d ++; |
|
1184 | + $d++; |
|
1185 | 1185 | endwhile; |
1186 | - $i ++; |
|
1186 | + $i++; |
|
1187 | 1187 | endwhile; |
1188 | 1188 | |
1189 | - $y ++; |
|
1189 | + $y++; |
|
1190 | 1190 | endwhile; |
1191 | 1191 | |
1192 | 1192 | $donations['totals'] = $total; |
1193 | 1193 | } else { |
1194 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1194 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1195 | 1195 | $donations_count = 0; |
1196 | 1196 | |
1197 | 1197 | // Loop through the months |
1198 | 1198 | $month = $dates['m_start']; |
1199 | 1199 | |
1200 | - while ( $month <= $dates['m_end'] ) : |
|
1201 | - $donations_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1202 | - $month ++; |
|
1200 | + while ($month <= $dates['m_end']) : |
|
1201 | + $donations_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1202 | + $month++; |
|
1203 | 1203 | endwhile; |
1204 | 1204 | |
1205 | - $donations['donations'][ $args['date'] ] = $donations_count; |
|
1205 | + $donations['donations'][$args['date']] = $donations_count; |
|
1206 | 1206 | } else { |
1207 | - $donations['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1207 | + $donations['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1208 | 1208 | } |
1209 | 1209 | }// End if(). |
1210 | - } elseif ( $args['form'] == 'all' ) { |
|
1211 | - $forms = get_posts( array( |
|
1210 | + } elseif ($args['form'] == 'all') { |
|
1211 | + $forms = get_posts(array( |
|
1212 | 1212 | 'post_type' => 'give_forms', |
1213 | 1213 | 'nopaging' => true, |
1214 | - ) ); |
|
1215 | - $i = 0; |
|
1216 | - foreach ( $forms as $form_info ) { |
|
1217 | - $donations['donations'][ $i ] = array( |
|
1218 | - $form_info->post_name => give_get_form_sales_stats( $form_info->ID ), |
|
1214 | + )); |
|
1215 | + $i = 0; |
|
1216 | + foreach ($forms as $form_info) { |
|
1217 | + $donations['donations'][$i] = array( |
|
1218 | + $form_info->post_name => give_get_form_sales_stats($form_info->ID), |
|
1219 | 1219 | ); |
1220 | - $i ++; |
|
1220 | + $i++; |
|
1221 | 1221 | } |
1222 | 1222 | } else { |
1223 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1224 | - $form_info = get_post( $args['form'] ); |
|
1223 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1224 | + $form_info = get_post($args['form']); |
|
1225 | 1225 | $donations['donations'][0] = array( |
1226 | - $form_info->post_name => give_get_form_sales_stats( $args['form'] ), |
|
1226 | + $form_info->post_name => give_get_form_sales_stats($args['form']), |
|
1227 | 1227 | ); |
1228 | 1228 | } else { |
1229 | 1229 | $error['error'] = sprintf( /* translators: %s: form */ |
1230 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
1230 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
1231 | 1231 | } |
1232 | 1232 | }// End if(). |
1233 | 1233 | |
1234 | - if ( ! empty( $error ) ) { |
|
1234 | + if ( ! empty($error)) { |
|
1235 | 1235 | return $error; |
1236 | 1236 | } |
1237 | 1237 | |
1238 | 1238 | return $donations; |
1239 | 1239 | |
1240 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1241 | - if ( $args['form'] == null ) { |
|
1242 | - if ( $args['date'] == null ) { |
|
1240 | + } elseif ($args['type'] == 'earnings') { |
|
1241 | + if ($args['form'] == null) { |
|
1242 | + if ($args['date'] == null) { |
|
1243 | 1243 | $earnings = $this->get_default_earnings_stats(); |
1244 | - } elseif ( $args['date'] === 'range' ) { |
|
1244 | + } elseif ($args['date'] === 'range') { |
|
1245 | 1245 | // Return sales for a date range |
1246 | 1246 | // Ensure the end date is later than the start date |
1247 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1248 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
1247 | + if ($args['enddate'] < $args['startdate']) { |
|
1248 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | // Ensure both the start and end date are specified |
1252 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1253 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
1252 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1253 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | $total = (float) 0.00; |
1257 | 1257 | |
1258 | 1258 | // Loop through the years |
1259 | 1259 | $y = $dates['year']; |
1260 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1260 | + if ( ! isset($earnings['earnings'])) { |
|
1261 | 1261 | $earnings['earnings'] = array(); |
1262 | 1262 | } |
1263 | - while ( $y <= $dates['year_end'] ) : |
|
1263 | + while ($y <= $dates['year_end']) : |
|
1264 | 1264 | |
1265 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1265 | + if ($dates['year'] == $dates['year_end']) { |
|
1266 | 1266 | $month_start = $dates['m_start']; |
1267 | 1267 | $month_end = $dates['m_end']; |
1268 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1268 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1269 | 1269 | $month_start = $dates['m_start']; |
1270 | 1270 | $month_end = 12; |
1271 | - } elseif ( $y == $dates['year_end'] ) { |
|
1271 | + } elseif ($y == $dates['year_end']) { |
|
1272 | 1272 | $month_start = 1; |
1273 | 1273 | $month_end = $dates['m_end']; |
1274 | 1274 | } else { |
@@ -1277,94 +1277,94 @@ discard block |
||
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | $i = $month_start; |
1280 | - while ( $i <= $month_end ) : |
|
1280 | + while ($i <= $month_end) : |
|
1281 | 1281 | |
1282 | - if ( $i == $dates['m_start'] ) { |
|
1282 | + if ($i == $dates['m_start']) { |
|
1283 | 1283 | $d = $dates['day_start']; |
1284 | 1284 | } else { |
1285 | 1285 | $d = 1; |
1286 | 1286 | } |
1287 | 1287 | |
1288 | - if ( $i == $dates['m_end'] ) { |
|
1288 | + if ($i == $dates['m_end']) { |
|
1289 | 1289 | $num_of_days = $dates['day_end']; |
1290 | 1290 | } else { |
1291 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1291 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | - while ( $d <= $num_of_days ) : |
|
1295 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1296 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1297 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1298 | - $earnings['earnings'][ $date_key ] = 0; |
|
1294 | + while ($d <= $num_of_days) : |
|
1295 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1296 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1297 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1298 | + $earnings['earnings'][$date_key] = 0; |
|
1299 | 1299 | } |
1300 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1300 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1301 | 1301 | $total += $earnings_stat; |
1302 | - $d ++; |
|
1302 | + $d++; |
|
1303 | 1303 | endwhile; |
1304 | 1304 | |
1305 | - $i ++; |
|
1305 | + $i++; |
|
1306 | 1306 | endwhile; |
1307 | 1307 | |
1308 | - $y ++; |
|
1308 | + $y++; |
|
1309 | 1309 | endwhile; |
1310 | 1310 | |
1311 | 1311 | $earnings['totals'] = $total; |
1312 | 1312 | } else { |
1313 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1313 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1314 | 1314 | $earnings_count = (float) 0.00; |
1315 | 1315 | |
1316 | 1316 | // Loop through the months |
1317 | 1317 | $month = $dates['m_start']; |
1318 | 1318 | |
1319 | - while ( $month <= $dates['m_end'] ) : |
|
1320 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1321 | - $month ++; |
|
1319 | + while ($month <= $dates['m_end']) : |
|
1320 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1321 | + $month++; |
|
1322 | 1322 | endwhile; |
1323 | 1323 | |
1324 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1324 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1325 | 1325 | } else { |
1326 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1326 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1327 | 1327 | } |
1328 | 1328 | }// End if(). |
1329 | - } elseif ( $args['form'] == 'all' ) { |
|
1330 | - $forms = get_posts( array( |
|
1329 | + } elseif ($args['form'] == 'all') { |
|
1330 | + $forms = get_posts(array( |
|
1331 | 1331 | 'post_type' => 'give_forms', |
1332 | 1332 | 'nopaging' => true, |
1333 | - ) ); |
|
1333 | + )); |
|
1334 | 1334 | |
1335 | 1335 | $i = 0; |
1336 | - foreach ( $forms as $form_info ) { |
|
1337 | - $earnings['earnings'][ $i ] = array( |
|
1338 | - $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ), |
|
1336 | + foreach ($forms as $form_info) { |
|
1337 | + $earnings['earnings'][$i] = array( |
|
1338 | + $form_info->post_name => give_get_form_earnings_stats($form_info->ID), |
|
1339 | 1339 | ); |
1340 | - $i ++; |
|
1340 | + $i++; |
|
1341 | 1341 | } |
1342 | 1342 | } else { |
1343 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1344 | - $form_info = get_post( $args['form'] ); |
|
1343 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1344 | + $form_info = get_post($args['form']); |
|
1345 | 1345 | $earnings['earnings'][0] = array( |
1346 | - $form_info->post_name => give_get_form_earnings_stats( $args['form'] ), |
|
1346 | + $form_info->post_name => give_get_form_earnings_stats($args['form']), |
|
1347 | 1347 | ); |
1348 | 1348 | } else { |
1349 | 1349 | $error['error'] = sprintf( /* translators: %s: form */ |
1350 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
1350 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
1351 | 1351 | } |
1352 | 1352 | }// End if(). |
1353 | 1353 | |
1354 | - if ( ! empty( $error ) ) { |
|
1354 | + if ( ! empty($error)) { |
|
1355 | 1355 | return $error; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | 1358 | return $earnings; |
1359 | - } elseif ( $args['type'] == 'donors' ) { |
|
1359 | + } elseif ($args['type'] == 'donors') { |
|
1360 | 1360 | $donors = new Give_DB_Donors(); |
1361 | 1361 | $stats['donations']['total_donors'] = $donors->count(); |
1362 | 1362 | |
1363 | 1363 | return $stats; |
1364 | 1364 | |
1365 | - } elseif ( empty( $args['type'] ) ) { |
|
1366 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1367 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1365 | + } elseif (empty($args['type'])) { |
|
1366 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1367 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1368 | 1368 | |
1369 | 1369 | return array( |
1370 | 1370 | 'stats' => $stats, |
@@ -1382,7 +1382,7 @@ discard block |
||
1382 | 1382 | * |
1383 | 1383 | * @return array |
1384 | 1384 | */ |
1385 | - public function get_recent_donations( $args = array() ) { |
|
1385 | + public function get_recent_donations($args = array()) { |
|
1386 | 1386 | global $wp_query; |
1387 | 1387 | |
1388 | 1388 | $defaults = array( |
@@ -1392,33 +1392,33 @@ discard block |
||
1392 | 1392 | 'enddate' => null, |
1393 | 1393 | ); |
1394 | 1394 | |
1395 | - $args = wp_parse_args( $args, $defaults ); |
|
1395 | + $args = wp_parse_args($args, $defaults); |
|
1396 | 1396 | |
1397 | 1397 | $donations = array(); |
1398 | 1398 | |
1399 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1399 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1400 | 1400 | return $donations; |
1401 | 1401 | } |
1402 | 1402 | |
1403 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1403 | + if (isset($wp_query->query_vars['id'])) { |
|
1404 | 1404 | $query = array(); |
1405 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1406 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1405 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1406 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1407 | 1407 | $query = array(); |
1408 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1409 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1410 | - $args = array( |
|
1408 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1409 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1410 | + $args = array( |
|
1411 | 1411 | 'fields' => 'ids', |
1412 | 1412 | 'meta_key' => '_give_payment_user_email', |
1413 | 1413 | 'meta_value' => $wp_query->query_vars['email'], |
1414 | 1414 | 'number' => $this->per_page(), |
1415 | 1415 | 'page' => $this->get_paged(), |
1416 | 1416 | ); |
1417 | - $query = give_get_payments( $args ); |
|
1418 | - } elseif ( isset( $wp_query->query_vars['date'] ) ) { |
|
1417 | + $query = give_get_payments($args); |
|
1418 | + } elseif (isset($wp_query->query_vars['date'])) { |
|
1419 | 1419 | |
1420 | - $current_time = current_time( 'timestamp' ); |
|
1421 | - $dates = $this->get_dates( $args ); |
|
1420 | + $current_time = current_time('timestamp'); |
|
1421 | + $dates = $this->get_dates($args); |
|
1422 | 1422 | $start_date = ''; |
1423 | 1423 | $end_date = ''; |
1424 | 1424 | |
@@ -1431,27 +1431,27 @@ discard block |
||
1431 | 1431 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
1432 | 1432 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
1433 | 1433 | */ |
1434 | - switch ( $wp_query->query_vars['date'] ) { |
|
1434 | + switch ($wp_query->query_vars['date']) { |
|
1435 | 1435 | |
1436 | 1436 | case 'today': |
1437 | 1437 | |
1438 | 1438 | // Set and Format Start and End Date to be date of today. |
1439 | - $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
1439 | + $start_date = $end_date = date('Y/m/d', $current_time); |
|
1440 | 1440 | |
1441 | 1441 | break; |
1442 | 1442 | |
1443 | 1443 | case 'yesterday': |
1444 | 1444 | |
1445 | 1445 | // Set and Format Start and End Date to be date of yesterday. |
1446 | - $start_date = $end_date = date( 'Y/m', $current_time ) . '/' . ( date( 'd', $current_time ) - 1 ); |
|
1446 | + $start_date = $end_date = date('Y/m', $current_time).'/'.(date('d', $current_time) - 1); |
|
1447 | 1447 | |
1448 | 1448 | break; |
1449 | 1449 | |
1450 | 1450 | case 'range': |
1451 | 1451 | |
1452 | 1452 | // Format Start Date and End Date for filtering payment based on date range. |
1453 | - $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
1454 | - $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
1453 | + $start_date = $dates['year'].'/'.$dates['m_start'].'/'.$dates['day_start']; |
|
1454 | + $end_date = $dates['year_end'].'/'.$dates['m_end'].'/'.$dates['day_end']; |
|
1455 | 1455 | |
1456 | 1456 | break; |
1457 | 1457 | |
@@ -1465,22 +1465,22 @@ discard block |
||
1465 | 1465 | 'page' => $this->get_paged(), |
1466 | 1466 | ); |
1467 | 1467 | |
1468 | - $query = give_get_payments( $args ); |
|
1468 | + $query = give_get_payments($args); |
|
1469 | 1469 | } else { |
1470 | 1470 | $args = array( |
1471 | 1471 | 'fields' => 'ids', |
1472 | 1472 | 'number' => $this->per_page(), |
1473 | 1473 | 'page' => $this->get_paged(), |
1474 | 1474 | ); |
1475 | - $query = give_get_payments( $args ); |
|
1475 | + $query = give_get_payments($args); |
|
1476 | 1476 | }// End if(). |
1477 | 1477 | |
1478 | - if ( $query ) { |
|
1478 | + if ($query) { |
|
1479 | 1479 | $i = 0; |
1480 | - foreach ( $query as $payment ) { |
|
1480 | + foreach ($query as $payment) { |
|
1481 | 1481 | |
1482 | - if ( is_numeric( $payment ) ) { |
|
1483 | - $payment = new Give_Payment( $payment ); |
|
1482 | + if (is_numeric($payment)) { |
|
1483 | + $payment = new Give_Payment($payment); |
|
1484 | 1484 | $payment_meta = $payment->get_meta(); |
1485 | 1485 | $user_info = $payment->user_info; |
1486 | 1486 | } |
@@ -1488,41 +1488,41 @@ discard block |
||
1488 | 1488 | $payment_meta = $payment->get_meta(); |
1489 | 1489 | $user_info = $payment->user_info; |
1490 | 1490 | |
1491 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1492 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1493 | - |
|
1494 | - $donations['donations'][ $i ]['ID'] = $payment->number; |
|
1495 | - $donations['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1496 | - $donations['donations'][ $i ]['key'] = $payment->key; |
|
1497 | - $donations['donations'][ $i ]['total'] = $payment->total; |
|
1498 | - $donations['donations'][ $i ]['status'] = give_get_payment_status( $payment, true ); |
|
1499 | - $donations['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1500 | - $donations['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1501 | - $donations['donations'][ $i ]['fname'] = $first_name; |
|
1502 | - $donations['donations'][ $i ]['lname'] = $last_name; |
|
1503 | - $donations['donations'][ $i ]['email'] = $payment->email; |
|
1504 | - $donations['donations'][ $i ]['date'] = $payment->date; |
|
1505 | - |
|
1506 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1507 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1508 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1509 | - |
|
1510 | - $donations['donations'][ $i ]['form']['id'] = $form_id; |
|
1511 | - $donations['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1512 | - $donations['donations'][ $i ]['form']['price'] = $price; |
|
1513 | - |
|
1514 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1515 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1516 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1517 | - $donations['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1518 | - $donations['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1519 | - $donations['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1491 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1492 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1493 | + |
|
1494 | + $donations['donations'][$i]['ID'] = $payment->number; |
|
1495 | + $donations['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1496 | + $donations['donations'][$i]['key'] = $payment->key; |
|
1497 | + $donations['donations'][$i]['total'] = $payment->total; |
|
1498 | + $donations['donations'][$i]['status'] = give_get_payment_status($payment, true); |
|
1499 | + $donations['donations'][$i]['gateway'] = $payment->gateway; |
|
1500 | + $donations['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1501 | + $donations['donations'][$i]['fname'] = $first_name; |
|
1502 | + $donations['donations'][$i]['lname'] = $last_name; |
|
1503 | + $donations['donations'][$i]['email'] = $payment->email; |
|
1504 | + $donations['donations'][$i]['date'] = $payment->date; |
|
1505 | + |
|
1506 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1507 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1508 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1509 | + |
|
1510 | + $donations['donations'][$i]['form']['id'] = $form_id; |
|
1511 | + $donations['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1512 | + $donations['donations'][$i]['form']['price'] = $price; |
|
1513 | + |
|
1514 | + if (give_has_variable_prices($form_id)) { |
|
1515 | + if (isset($payment_meta['price_id'])) { |
|
1516 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1517 | + $donations['donations'][$i]['form']['price_name'] = $price_name; |
|
1518 | + $donations['donations'][$i]['form']['price_id'] = $price_id; |
|
1519 | + $donations['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1520 | 1520 | |
1521 | 1521 | } |
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | // Add custom meta to API |
1525 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1525 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1526 | 1526 | |
1527 | 1527 | $exceptions = array( |
1528 | 1528 | 'form_title', |
@@ -1535,19 +1535,19 @@ discard block |
||
1535 | 1535 | ); |
1536 | 1536 | |
1537 | 1537 | // Don't clutter up results with dupes |
1538 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1538 | + if (in_array($meta_key, $exceptions)) { |
|
1539 | 1539 | continue; |
1540 | 1540 | } |
1541 | 1541 | |
1542 | - $donations['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1542 | + $donations['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1543 | 1543 | |
1544 | 1544 | } |
1545 | 1545 | |
1546 | - $i ++; |
|
1546 | + $i++; |
|
1547 | 1547 | }// End foreach(). |
1548 | 1548 | }// End if(). |
1549 | 1549 | |
1550 | - return apply_filters( 'give_api_donations_endpoint', $donations ); |
|
1550 | + return apply_filters('give_api_donations_endpoint', $donations); |
|
1551 | 1551 | } |
1552 | 1552 | |
1553 | 1553 | /** |
@@ -1563,9 +1563,9 @@ discard block |
||
1563 | 1563 | public function get_output_format() { |
1564 | 1564 | global $wp_query; |
1565 | 1565 | |
1566 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1566 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1567 | 1567 | |
1568 | - return apply_filters( 'give_api_output_format', $format ); |
|
1568 | + return apply_filters('give_api_output_format', $format); |
|
1569 | 1569 | } |
1570 | 1570 | |
1571 | 1571 | |
@@ -1582,8 +1582,8 @@ discard block |
||
1582 | 1582 | * |
1583 | 1583 | * @return void |
1584 | 1584 | */ |
1585 | - private function log_request( $data = array() ) { |
|
1586 | - if ( ! $this->log_requests ) { |
|
1585 | + private function log_request($data = array()) { |
|
1586 | + if ( ! $this->log_requests) { |
|
1587 | 1587 | return; |
1588 | 1588 | } |
1589 | 1589 | |
@@ -1599,36 +1599,36 @@ discard block |
||
1599 | 1599 | |
1600 | 1600 | $query = array( |
1601 | 1601 | 'give-api' => $wp_query->query_vars['give-api'], |
1602 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1603 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1604 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1605 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1606 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1607 | - 'donor' => isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null, |
|
1608 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1609 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1610 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1611 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1612 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1613 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1602 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1603 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1604 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1605 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1606 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1607 | + 'donor' => isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null, |
|
1608 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1609 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1610 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1611 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1612 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1613 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1614 | 1614 | ); |
1615 | 1615 | |
1616 | 1616 | $log_data = array( |
1617 | 1617 | 'log_type' => 'api_request', |
1618 | - 'post_excerpt' => http_build_query( $query ), |
|
1619 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1618 | + 'post_excerpt' => http_build_query($query), |
|
1619 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1620 | 1620 | ); |
1621 | 1621 | |
1622 | 1622 | $log_meta = array( |
1623 | 1623 | 'request_ip' => give_get_ip(), |
1624 | 1624 | 'user' => $this->user_id, |
1625 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1626 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1625 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1626 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1627 | 1627 | 'time' => $data['request_speed'], |
1628 | 1628 | 'version' => $this->get_queried_version(), |
1629 | 1629 | ); |
1630 | 1630 | |
1631 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1631 | + $give_logs->insert_log($log_data, $log_meta); |
|
1632 | 1632 | } |
1633 | 1633 | |
1634 | 1634 | |
@@ -1652,11 +1652,11 @@ discard block |
||
1652 | 1652 | * |
1653 | 1653 | * @param int $status_code |
1654 | 1654 | */ |
1655 | - public function output( $status_code = 200 ) { |
|
1655 | + public function output($status_code = 200) { |
|
1656 | 1656 | |
1657 | 1657 | $format = $this->get_output_format(); |
1658 | 1658 | |
1659 | - status_header( $status_code ); |
|
1659 | + status_header($status_code); |
|
1660 | 1660 | |
1661 | 1661 | /** |
1662 | 1662 | * Fires before outputting the API. |
@@ -1667,25 +1667,25 @@ discard block |
||
1667 | 1667 | * @param Give_API $this The Give_API object. |
1668 | 1668 | * @param string $format Output format, XML or JSON. Default is JSON. |
1669 | 1669 | */ |
1670 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1670 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1671 | 1671 | |
1672 | - switch ( $format ) : |
|
1672 | + switch ($format) : |
|
1673 | 1673 | |
1674 | 1674 | case 'xml' : |
1675 | 1675 | |
1676 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1677 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1676 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1677 | + $xml = Array2XML::createXML('give', $this->data); |
|
1678 | 1678 | echo $xml->saveXML(); |
1679 | 1679 | |
1680 | 1680 | break; |
1681 | 1681 | |
1682 | 1682 | case 'json' : |
1683 | 1683 | |
1684 | - header( 'Content-Type: application/json' ); |
|
1685 | - if ( ! empty( $this->pretty_print ) ) { |
|
1686 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1684 | + header('Content-Type: application/json'); |
|
1685 | + if ( ! empty($this->pretty_print)) { |
|
1686 | + echo json_encode($this->data, $this->pretty_print); |
|
1687 | 1687 | } else { |
1688 | - echo json_encode( $this->data ); |
|
1688 | + echo json_encode($this->data); |
|
1689 | 1689 | } |
1690 | 1690 | |
1691 | 1691 | break; |
@@ -1700,7 +1700,7 @@ discard block |
||
1700 | 1700 | * @param array $data Response data to return. |
1701 | 1701 | * @param Give_API $this The Give_API object. |
1702 | 1702 | */ |
1703 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
1703 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
1704 | 1704 | |
1705 | 1705 | break; |
1706 | 1706 | |
@@ -1715,7 +1715,7 @@ discard block |
||
1715 | 1715 | * @param Give_API $this The Give_API object. |
1716 | 1716 | * @param string $format Output format, XML or JSON. Default is JSON. |
1717 | 1717 | */ |
1718 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1718 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1719 | 1719 | |
1720 | 1720 | give_die(); |
1721 | 1721 | } |
@@ -1732,41 +1732,41 @@ discard block |
||
1732 | 1732 | * |
1733 | 1733 | * @return void |
1734 | 1734 | */ |
1735 | - function user_key_field( $user ) { |
|
1735 | + function user_key_field($user) { |
|
1736 | 1736 | |
1737 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1737 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1738 | 1738 | |
1739 | - $user = get_userdata( $user->ID ); |
|
1739 | + $user = get_userdata($user->ID); |
|
1740 | 1740 | ?> |
1741 | 1741 | <table class="form-table"> |
1742 | 1742 | <tbody> |
1743 | 1743 | <tr> |
1744 | 1744 | <th> |
1745 | - <?php _e( 'Give API Keys', 'give' ); ?> |
|
1745 | + <?php _e('Give API Keys', 'give'); ?> |
|
1746 | 1746 | </th> |
1747 | 1747 | <td> |
1748 | 1748 | <?php |
1749 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1750 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1749 | + $public_key = $this->get_user_public_key($user->ID); |
|
1750 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1751 | 1751 | ?> |
1752 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1752 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1753 | 1753 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" /> |
1754 | - <span class="description"><?php _e( 'Generate API Key', 'give' ); ?></span> |
|
1754 | + <span class="description"><?php _e('Generate API Key', 'give'); ?></span> |
|
1755 | 1755 | <?php } else { ?> |
1756 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> |
|
1756 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> |
|
1757 | 1757 | </strong> |
1758 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" /> |
|
1758 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>" /> |
|
1759 | 1759 | <br /> |
1760 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Secret key:', 'give' ); ?> |
|
1760 | + <strong style="display:inline-block; width: 125px;"><?php _e('Secret key:', 'give'); ?> |
|
1761 | 1761 | </strong> |
1762 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>" /> |
|
1762 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>" /> |
|
1763 | 1763 | <br /> |
1764 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Token:', 'give' ); ?> |
|
1764 | + <strong style="display:inline-block; width: 125px;"><?php _e('Token:', 'give'); ?> |
|
1765 | 1765 | </strong> |
1766 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>" /> |
|
1766 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>" /> |
|
1767 | 1767 | <br /> |
1768 | 1768 | <input name="give_revoke_api_key" type="checkbox" id="give_revoke_api_key" /> |
1769 | - <span class="description"><label for="give_revoke_api_key"><?php _e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1769 | + <span class="description"><label for="give_revoke_api_key"><?php _e('Revoke API Keys', 'give'); ?></label></span> |
|
1770 | 1770 | <?php } ?> |
1771 | 1771 | </td> |
1772 | 1772 | </tr> |
@@ -1785,61 +1785,61 @@ discard block |
||
1785 | 1785 | * |
1786 | 1786 | * @return void |
1787 | 1787 | */ |
1788 | - public function process_api_key( $args ) { |
|
1788 | + public function process_api_key($args) { |
|
1789 | 1789 | |
1790 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1791 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( |
|
1790 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1791 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array( |
|
1792 | 1792 | 'response' => 403, |
1793 | - ) ); |
|
1793 | + )); |
|
1794 | 1794 | } |
1795 | 1795 | |
1796 | - if ( empty( $args['user_id'] ) ) { |
|
1797 | - wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array( |
|
1796 | + if (empty($args['user_id'])) { |
|
1797 | + wp_die(__('User ID Required.', 'give'), __('Error', 'give'), array( |
|
1798 | 1798 | 'response' => 401, |
1799 | - ) ); |
|
1799 | + )); |
|
1800 | 1800 | } |
1801 | 1801 | |
1802 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1803 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1802 | + if (is_numeric($args['user_id'])) { |
|
1803 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1804 | 1804 | } else { |
1805 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1805 | + $userdata = get_user_by('login', $args['user_id']); |
|
1806 | 1806 | $user_id = $userdata->ID; |
1807 | 1807 | } |
1808 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1808 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1809 | 1809 | |
1810 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1811 | - wp_die( sprintf( /* translators: %s: process */ |
|
1812 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
1810 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1811 | + wp_die(sprintf( /* translators: %s: process */ |
|
1812 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
1813 | 1813 | 'response' => 403, |
1814 | - ) ); |
|
1815 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1816 | - wp_die( sprintf( /* translators: %s: process */ |
|
1817 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
1814 | + )); |
|
1815 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1816 | + wp_die(sprintf( /* translators: %s: process */ |
|
1817 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
1818 | 1818 | 'response' => 403, |
1819 | - ) ); |
|
1819 | + )); |
|
1820 | 1820 | } |
1821 | 1821 | |
1822 | - switch ( $process ) { |
|
1822 | + switch ($process) { |
|
1823 | 1823 | case 'generate': |
1824 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1825 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1826 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1824 | + if ($this->generate_api_key($user_id)) { |
|
1825 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1826 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1827 | 1827 | exit(); |
1828 | 1828 | } else { |
1829 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1829 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1830 | 1830 | exit(); |
1831 | 1831 | } |
1832 | 1832 | break; |
1833 | 1833 | case 'regenerate': |
1834 | - $this->generate_api_key( $user_id, true ); |
|
1835 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1836 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1834 | + $this->generate_api_key($user_id, true); |
|
1835 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1836 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1837 | 1837 | exit(); |
1838 | 1838 | break; |
1839 | 1839 | case 'revoke': |
1840 | - $this->revoke_api_key( $user_id ); |
|
1841 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1842 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1840 | + $this->revoke_api_key($user_id); |
|
1841 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1842 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1843 | 1843 | exit(); |
1844 | 1844 | break; |
1845 | 1845 | default; |
@@ -1858,59 +1858,59 @@ discard block |
||
1858 | 1858 | * |
1859 | 1859 | * @return boolean True if (re)generated successfully, false otherwise. |
1860 | 1860 | */ |
1861 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1861 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1862 | 1862 | |
1863 | 1863 | // Bail out, if user doesn't exists. |
1864 | - if ( empty( $user_id ) ) { |
|
1864 | + if (empty($user_id)) { |
|
1865 | 1865 | return false; |
1866 | 1866 | } |
1867 | 1867 | |
1868 | - $user = get_userdata( $user_id ); |
|
1868 | + $user = get_userdata($user_id); |
|
1869 | 1869 | |
1870 | 1870 | // Bail Out, if user object doesn't exists. |
1871 | - if ( ! $user ) { |
|
1871 | + if ( ! $user) { |
|
1872 | 1872 | return false; |
1873 | 1873 | } |
1874 | 1874 | |
1875 | 1875 | $new_public_key = ''; |
1876 | 1876 | $new_secret_key = ''; |
1877 | 1877 | |
1878 | - if( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) { |
|
1878 | + if ( ! empty($_POST['from']) && 'profile' === $_POST['from']) { |
|
1879 | 1879 | // For User Profile Page. |
1880 | - if( ! empty( $_POST['give_set_api_key'] ) ) { |
|
1880 | + if ( ! empty($_POST['give_set_api_key'])) { |
|
1881 | 1881 | // Generate API Key from User Profile page. |
1882 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1883 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1884 | - } elseif ( ! empty( $_POST['give_revoke_api_key'] ) ) { |
|
1882 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1883 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1884 | + } elseif ( ! empty($_POST['give_revoke_api_key'])) { |
|
1885 | 1885 | // Revoke API Key from User Profile page. |
1886 | - $this->revoke_api_key( $user->ID ); |
|
1886 | + $this->revoke_api_key($user->ID); |
|
1887 | 1887 | } else { |
1888 | 1888 | return false; |
1889 | 1889 | } |
1890 | 1890 | } else { |
1891 | 1891 | // For Tools > API page. |
1892 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1892 | + $public_key = $this->get_user_public_key($user_id); |
|
1893 | 1893 | |
1894 | - if ( empty( $public_key ) && ! $regenerate ) { |
|
1894 | + if (empty($public_key) && ! $regenerate) { |
|
1895 | 1895 | // Generating API for first time. |
1896 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1897 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1898 | - } elseif ( $public_key && $regenerate ) { |
|
1896 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1897 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1898 | + } elseif ($public_key && $regenerate) { |
|
1899 | 1899 | // API Key already exists and Regenerating API Key. |
1900 | - $this->revoke_api_key( $user->ID ); |
|
1901 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1902 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1903 | - } elseif ( ! empty( $public_key ) && ! $regenerate ) { |
|
1900 | + $this->revoke_api_key($user->ID); |
|
1901 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1902 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1903 | + } elseif ( ! empty($public_key) && ! $regenerate) { |
|
1904 | 1904 | // Doing nothing, when API Key exists but still try to generate again instead of regenerating. |
1905 | 1905 | return false; |
1906 | 1906 | } else { |
1907 | 1907 | // Revoke API Key. |
1908 | - $this->revoke_api_key( $user->ID ); |
|
1908 | + $this->revoke_api_key($user->ID); |
|
1909 | 1909 | } |
1910 | 1910 | } |
1911 | 1911 | |
1912 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1913 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1912 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1913 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1914 | 1914 | |
1915 | 1915 | return true; |
1916 | 1916 | } |
@@ -1925,26 +1925,26 @@ discard block |
||
1925 | 1925 | * |
1926 | 1926 | * @return bool |
1927 | 1927 | */ |
1928 | - public function revoke_api_key( $user_id = 0 ) { |
|
1928 | + public function revoke_api_key($user_id = 0) { |
|
1929 | 1929 | |
1930 | - if ( empty( $user_id ) ) { |
|
1930 | + if (empty($user_id)) { |
|
1931 | 1931 | return false; |
1932 | 1932 | } |
1933 | 1933 | |
1934 | - $user = get_userdata( $user_id ); |
|
1934 | + $user = get_userdata($user_id); |
|
1935 | 1935 | |
1936 | - if ( ! $user ) { |
|
1936 | + if ( ! $user) { |
|
1937 | 1937 | return false; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1941 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1942 | - if ( ! empty( $public_key ) ) { |
|
1943 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
1944 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
1945 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
1946 | - delete_user_meta( $user_id, $public_key ); |
|
1947 | - delete_user_meta( $user_id, $secret_key ); |
|
1940 | + $public_key = $this->get_user_public_key($user_id); |
|
1941 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1942 | + if ( ! empty($public_key)) { |
|
1943 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
1944 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
1945 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
1946 | + delete_user_meta($user_id, $public_key); |
|
1947 | + delete_user_meta($user_id, $secret_key); |
|
1948 | 1948 | } else { |
1949 | 1949 | return false; |
1950 | 1950 | } |
@@ -1966,9 +1966,9 @@ discard block |
||
1966 | 1966 | * |
1967 | 1967 | * @return string |
1968 | 1968 | */ |
1969 | - private function generate_public_key( $user_email = '' ) { |
|
1970 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1971 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1969 | + private function generate_public_key($user_email = '') { |
|
1970 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1971 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1972 | 1972 | |
1973 | 1973 | return $public; |
1974 | 1974 | } |
@@ -1983,9 +1983,9 @@ discard block |
||
1983 | 1983 | * |
1984 | 1984 | * @return string |
1985 | 1985 | */ |
1986 | - private function generate_private_key( $user_id = 0 ) { |
|
1987 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1988 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1986 | + private function generate_private_key($user_id = 0) { |
|
1987 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1988 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1989 | 1989 | |
1990 | 1990 | return $secret; |
1991 | 1991 | } |
@@ -2000,8 +2000,8 @@ discard block |
||
2000 | 2000 | * |
2001 | 2001 | * @return string |
2002 | 2002 | */ |
2003 | - public function get_token( $user_id = 0 ) { |
|
2004 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
2003 | + public function get_token($user_id = 0) { |
|
2004 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | 2007 | /** |
@@ -2015,9 +2015,9 @@ discard block |
||
2015 | 2015 | |
2016 | 2016 | // Default sales return |
2017 | 2017 | $donations = array(); |
2018 | - $donations['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
2019 | - $donations['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
2020 | - $donations['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
2018 | + $donations['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
2019 | + $donations['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
2020 | + $donations['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
2021 | 2021 | $donations['donations']['totals'] = give_get_total_donations(); |
2022 | 2022 | |
2023 | 2023 | return $donations; |
@@ -2034,9 +2034,9 @@ discard block |
||
2034 | 2034 | |
2035 | 2035 | // Default earnings return |
2036 | 2036 | $earnings = array(); |
2037 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
2038 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
2039 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
2037 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
2038 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
2039 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
2040 | 2040 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
2041 | 2041 | |
2042 | 2042 | return $earnings; |
@@ -2056,25 +2056,25 @@ discard block |
||
2056 | 2056 | * |
2057 | 2057 | * @return string The API key/secret for the user supplied |
2058 | 2058 | */ |
2059 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
2059 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
2060 | 2060 | |
2061 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
2061 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
2062 | 2062 | return $check; |
2063 | 2063 | } |
2064 | 2064 | |
2065 | 2065 | $return = $check; |
2066 | 2066 | |
2067 | - switch ( $meta_key ) { |
|
2067 | + switch ($meta_key) { |
|
2068 | 2068 | case 'give_user_public_key': |
2069 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
2069 | + $return = Give()->api->get_user_public_key($object_id); |
|
2070 | 2070 | break; |
2071 | 2071 | case 'give_user_secret_key': |
2072 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
2072 | + $return = Give()->api->get_user_secret_key($object_id); |
|
2073 | 2073 | break; |
2074 | 2074 | } |
2075 | 2075 | |
2076 | - if ( ! $single ) { |
|
2077 | - $return = array( $return ); |
|
2076 | + if ( ! $single) { |
|
2077 | + $return = array($return); |
|
2078 | 2078 | } |
2079 | 2079 | |
2080 | 2080 | return $return; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @since 1.0 |
162 | 162 | * @access public |
163 | 163 | * |
164 | - * @param bool|string|int $_id_or_email |
|
164 | + * @param integer $_id_or_email |
|
165 | 165 | * |
166 | 166 | * @return bool|int |
167 | 167 | */ |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param int $user_id User ID. |
317 | 317 | * @param WP_User|bool $old_user_data User data. |
318 | 318 | * |
319 | - * @return bool |
|
319 | + * @return false|null |
|
320 | 320 | */ |
321 | 321 | public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) { |
322 | 322 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @access public |
374 | 374 | * |
375 | 375 | * @param string $field ID or email. Default is 'id'. |
376 | - * @param mixed $value The Customer ID or email to search. Default is 0. |
|
376 | + * @param integer $value The Customer ID or email to search. Default is 0. |
|
377 | 377 | * |
378 | 378 | * @return mixed Upon success, an object of the donor. Upon failure, NULL |
379 | 379 | */ |
@@ -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 | |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | /* @var WPDB $wpdb */ |
36 | 36 | global $wpdb; |
37 | 37 | |
38 | - $this->table_name = $wpdb->prefix . 'give_customers'; |
|
38 | + $this->table_name = $wpdb->prefix.'give_customers'; |
|
39 | 39 | $this->primary_key = 'id'; |
40 | 40 | $this->version = '1.0'; |
41 | 41 | |
42 | 42 | // Set hooks and register table only if instance loading first time. |
43 | - if ( ! ( Give()->donors instanceof Give_DB_Donors ) ) { |
|
43 | + if ( ! (Give()->donors instanceof Give_DB_Donors)) { |
|
44 | 44 | // Setup hook. |
45 | - add_action( 'profile_update', array( $this, 'update_donor_email_on_user_update' ), 10, 2 ); |
|
45 | + add_action('profile_update', array($this, 'update_donor_email_on_user_update'), 10, 2); |
|
46 | 46 | |
47 | 47 | // Install table. |
48 | 48 | $this->register_table(); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | 'purchase_value' => 0.00, |
90 | 90 | 'purchase_count' => 0, |
91 | 91 | 'notes' => '', |
92 | - 'date_created' => date( 'Y-m-d H:i:s' ), |
|
92 | + 'date_created' => date('Y-m-d H:i:s'), |
|
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
@@ -103,40 +103,40 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return int|bool |
105 | 105 | */ |
106 | - public function add( $data = array() ) { |
|
106 | + public function add($data = array()) { |
|
107 | 107 | |
108 | 108 | $defaults = array( |
109 | 109 | 'payment_ids' => '', |
110 | 110 | ); |
111 | 111 | |
112 | - $args = wp_parse_args( $data, $defaults ); |
|
112 | + $args = wp_parse_args($data, $defaults); |
|
113 | 113 | |
114 | - if ( empty( $args['email'] ) ) { |
|
114 | + if (empty($args['email'])) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) { |
|
119 | - $args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) ); |
|
118 | + if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) { |
|
119 | + $args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids']))); |
|
120 | 120 | } |
121 | 121 | |
122 | - $donor = $this->get_donor_by( 'email', $args['email'] ); |
|
122 | + $donor = $this->get_donor_by('email', $args['email']); |
|
123 | 123 | |
124 | 124 | // update an existing donor. |
125 | - if ( $donor ) { |
|
125 | + if ($donor) { |
|
126 | 126 | |
127 | 127 | // Update the payment IDs attached to the donor |
128 | - if ( ! empty( $args['payment_ids'] ) ) { |
|
128 | + if ( ! empty($args['payment_ids'])) { |
|
129 | 129 | |
130 | - if ( empty( $donor->payment_ids ) ) { |
|
130 | + if (empty($donor->payment_ids)) { |
|
131 | 131 | |
132 | 132 | $donor->payment_ids = $args['payment_ids']; |
133 | 133 | |
134 | 134 | } else { |
135 | 135 | |
136 | - $existing_ids = array_map( 'absint', explode( ',', $donor->payment_ids ) ); |
|
137 | - $payment_ids = array_map( 'absint', explode( ',', $args['payment_ids'] ) ); |
|
138 | - $payment_ids = array_merge( $payment_ids, $existing_ids ); |
|
139 | - $donor->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
136 | + $existing_ids = array_map('absint', explode(',', $donor->payment_ids)); |
|
137 | + $payment_ids = array_map('absint', explode(',', $args['payment_ids'])); |
|
138 | + $payment_ids = array_merge($payment_ids, $existing_ids); |
|
139 | + $donor->payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | |
145 | 145 | } |
146 | 146 | |
147 | - $this->update( $donor->id, $args ); |
|
147 | + $this->update($donor->id, $args); |
|
148 | 148 | |
149 | 149 | return $donor->id; |
150 | 150 | |
151 | 151 | } else { |
152 | 152 | |
153 | - return $this->insert( $args, 'donor' ); |
|
153 | + return $this->insert($args, 'donor'); |
|
154 | 154 | |
155 | 155 | } |
156 | 156 | |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @return bool|int |
171 | 171 | */ |
172 | - public function delete( $_id_or_email = false ) { |
|
172 | + public function delete($_id_or_email = false) { |
|
173 | 173 | |
174 | - if ( empty( $_id_or_email ) ) { |
|
174 | + if (empty($_id_or_email)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
178 | - $column = is_email( $_id_or_email ) ? 'email' : 'id'; |
|
179 | - $donor = $this->get_donor_by( $column, $_id_or_email ); |
|
178 | + $column = is_email($_id_or_email) ? 'email' : 'id'; |
|
179 | + $donor = $this->get_donor_by($column, $_id_or_email); |
|
180 | 180 | |
181 | - if ( $donor->id > 0 ) { |
|
181 | + if ($donor->id > 0) { |
|
182 | 182 | |
183 | 183 | global $wpdb; |
184 | 184 | |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @since 1.8.14 |
189 | 189 | */ |
190 | - Give()->donor_meta->delete_all_meta( $donor->id ); |
|
190 | + Give()->donor_meta->delete_all_meta($donor->id); |
|
191 | 191 | |
192 | - return $wpdb->delete( $this->table_name, array( 'id' => $donor->id ), array( '%d' ) ); |
|
192 | + return $wpdb->delete($this->table_name, array('id' => $donor->id), array('%d')); |
|
193 | 193 | |
194 | 194 | } else { |
195 | 195 | return false; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return bool|int |
212 | 212 | */ |
213 | - public function delete_by_user_id( $user_id = false ) { |
|
213 | + public function delete_by_user_id($user_id = false) { |
|
214 | 214 | |
215 | - if ( empty( $user_id ) ) { |
|
215 | + if (empty($user_id)) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @since 1.8.14 |
223 | 223 | */ |
224 | - $donor = new Give_Donor( $user_id, true ); |
|
225 | - if ( ! empty( $donor->id ) ) { |
|
226 | - Give()->donor_meta->delete_all_meta( $donor->id ); |
|
224 | + $donor = new Give_Donor($user_id, true); |
|
225 | + if ( ! empty($donor->id)) { |
|
226 | + Give()->donor_meta->delete_all_meta($donor->id); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | global $wpdb; |
230 | 230 | |
231 | - return $wpdb->delete( $this->table_name, array( 'user_id' => $user_id ), array( '%d' ) ); |
|
231 | + return $wpdb->delete($this->table_name, array('user_id' => $user_id), array('%d')); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -242,14 +242,14 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @return bool True is exists, false otherwise. |
244 | 244 | */ |
245 | - public function exists( $value = '', $field = 'email' ) { |
|
245 | + public function exists($value = '', $field = 'email') { |
|
246 | 246 | |
247 | 247 | $columns = $this->get_columns(); |
248 | - if ( ! array_key_exists( $field, $columns ) ) { |
|
248 | + if ( ! array_key_exists($field, $columns)) { |
|
249 | 249 | return false; |
250 | 250 | } |
251 | 251 | |
252 | - return (bool) $this->get_column_by( 'id', $field, $value ); |
|
252 | + return (bool) $this->get_column_by('id', $field, $value); |
|
253 | 253 | |
254 | 254 | } |
255 | 255 | |
@@ -264,16 +264,16 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @return bool |
266 | 266 | */ |
267 | - public function attach_payment( $donor_id = 0, $payment_id = 0 ) { |
|
267 | + public function attach_payment($donor_id = 0, $payment_id = 0) { |
|
268 | 268 | |
269 | - $donor = new Give_Donor( $donor_id ); |
|
269 | + $donor = new Give_Donor($donor_id); |
|
270 | 270 | |
271 | - if ( empty( $donor->id ) ) { |
|
271 | + if (empty($donor->id)) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | 275 | // Attach the payment, but don't increment stats, as this function previously did not |
276 | - return $donor->attach_payment( $payment_id, false ); |
|
276 | + return $donor->attach_payment($payment_id, false); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return bool |
290 | 290 | */ |
291 | - public function remove_payment( $donor_id = 0, $payment_id = 0 ) { |
|
291 | + public function remove_payment($donor_id = 0, $payment_id = 0) { |
|
292 | 292 | |
293 | - $donor = new Give_Donor( $donor_id ); |
|
293 | + $donor = new Give_Donor($donor_id); |
|
294 | 294 | |
295 | - if ( ! $donor ) { |
|
295 | + if ( ! $donor) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | |
299 | 299 | // Remove the payment, but don't decrease stats, as this function previously did not |
300 | - return $donor->remove_payment( $payment_id, false ); |
|
300 | + return $donor->remove_payment($payment_id, false); |
|
301 | 301 | |
302 | 302 | } |
303 | 303 | |
@@ -311,18 +311,18 @@ discard block |
||
311 | 311 | * |
312 | 312 | * @return bool |
313 | 313 | */ |
314 | - public function increment_stats( $donor_id = 0, $amount = 0.00 ) { |
|
314 | + public function increment_stats($donor_id = 0, $amount = 0.00) { |
|
315 | 315 | |
316 | - $donor = new Give_Donor( $donor_id ); |
|
316 | + $donor = new Give_Donor($donor_id); |
|
317 | 317 | |
318 | - if ( empty( $donor->id ) ) { |
|
318 | + if (empty($donor->id)) { |
|
319 | 319 | return false; |
320 | 320 | } |
321 | 321 | |
322 | 322 | $increased_count = $donor->increase_purchase_count(); |
323 | - $increased_value = $donor->increase_value( $amount ); |
|
323 | + $increased_value = $donor->increase_value($amount); |
|
324 | 324 | |
325 | - return ( $increased_count && $increased_value ) ? true : false; |
|
325 | + return ($increased_count && $increased_value) ? true : false; |
|
326 | 326 | |
327 | 327 | } |
328 | 328 | |
@@ -337,18 +337,18 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @return bool |
339 | 339 | */ |
340 | - public function decrement_stats( $donor_id = 0, $amount = 0.00 ) { |
|
340 | + public function decrement_stats($donor_id = 0, $amount = 0.00) { |
|
341 | 341 | |
342 | - $donor = new Give_Donor( $donor_id ); |
|
342 | + $donor = new Give_Donor($donor_id); |
|
343 | 343 | |
344 | - if ( ! $donor ) { |
|
344 | + if ( ! $donor) { |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | |
348 | 348 | $decreased_count = $donor->decrease_donation_count(); |
349 | - $decreased_value = $donor->decrease_value( $amount ); |
|
349 | + $decreased_value = $donor->decrease_value($amount); |
|
350 | 350 | |
351 | - return ( $decreased_count && $decreased_value ) ? true : false; |
|
351 | + return ($decreased_count && $decreased_value) ? true : false; |
|
352 | 352 | |
353 | 353 | } |
354 | 354 | |
@@ -363,31 +363,31 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return bool |
365 | 365 | */ |
366 | - public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) { |
|
366 | + public function update_donor_email_on_user_update($user_id = 0, $old_user_data = false) { |
|
367 | 367 | |
368 | - $donor = new Give_Donor( $user_id, true ); |
|
368 | + $donor = new Give_Donor($user_id, true); |
|
369 | 369 | |
370 | - if ( ! $donor ) { |
|
370 | + if ( ! $donor) { |
|
371 | 371 | return false; |
372 | 372 | } |
373 | 373 | |
374 | - $user = get_userdata( $user_id ); |
|
374 | + $user = get_userdata($user_id); |
|
375 | 375 | |
376 | - if ( ! empty( $user ) && $user->user_email !== $donor->email ) { |
|
376 | + if ( ! empty($user) && $user->user_email !== $donor->email) { |
|
377 | 377 | |
378 | - if ( ! $this->get_donor_by( 'email', $user->user_email ) ) { |
|
378 | + if ( ! $this->get_donor_by('email', $user->user_email)) { |
|
379 | 379 | |
380 | - $success = $this->update( $donor->id, array( 'email' => $user->user_email ) ); |
|
380 | + $success = $this->update($donor->id, array('email' => $user->user_email)); |
|
381 | 381 | |
382 | - if ( $success ) { |
|
382 | + if ($success) { |
|
383 | 383 | // Update some payment meta if we need to |
384 | - $payments_array = explode( ',', $donor->payment_ids ); |
|
384 | + $payments_array = explode(',', $donor->payment_ids); |
|
385 | 385 | |
386 | - if ( ! empty( $payments_array ) ) { |
|
386 | + if ( ! empty($payments_array)) { |
|
387 | 387 | |
388 | - foreach ( $payments_array as $payment_id ) { |
|
388 | + foreach ($payments_array as $payment_id) { |
|
389 | 389 | |
390 | - give_update_payment_meta( $payment_id, 'email', $user->user_email ); |
|
390 | + give_update_payment_meta($payment_id, 'email', $user->user_email); |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @param WP_User $user WordPress User object. |
402 | 402 | * @param Give_Donor $donor Give donor object. |
403 | 403 | */ |
404 | - do_action( 'give_update_donor_email_on_user_update', $user, $donor ); |
|
404 | + do_action('give_update_donor_email_on_user_update', $user, $donor); |
|
405 | 405 | |
406 | 406 | } |
407 | 407 | |
@@ -422,44 +422,44 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @return mixed Upon success, an object of the donor. Upon failure, NULL |
424 | 424 | */ |
425 | - public function get_donor_by( $field = 'id', $value = 0 ) { |
|
426 | - $value = sanitize_text_field( $value ); |
|
425 | + public function get_donor_by($field = 'id', $value = 0) { |
|
426 | + $value = sanitize_text_field($value); |
|
427 | 427 | |
428 | 428 | // Bailout. |
429 | - if ( empty( $field ) || empty( $value ) ) { |
|
429 | + if (empty($field) || empty($value)) { |
|
430 | 430 | return null; |
431 | 431 | } |
432 | 432 | |
433 | 433 | // Verify values. |
434 | - if ( 'id' === $field || 'user_id' === $field ) { |
|
434 | + if ('id' === $field || 'user_id' === $field) { |
|
435 | 435 | // Make sure the value is numeric to avoid casting objects, for example, |
436 | 436 | // to int 1. |
437 | - if ( ! is_numeric( $value ) ) { |
|
437 | + if ( ! is_numeric($value)) { |
|
438 | 438 | return false; |
439 | 439 | } |
440 | 440 | |
441 | - $value = absint( $value ); |
|
441 | + $value = absint($value); |
|
442 | 442 | |
443 | - if ( $value < 1 ) { |
|
443 | + if ($value < 1) { |
|
444 | 444 | return false; |
445 | 445 | } |
446 | 446 | |
447 | - } elseif ( 'email' === $field ) { |
|
447 | + } elseif ('email' === $field) { |
|
448 | 448 | |
449 | - if ( ! is_email( $value ) ) { |
|
449 | + if ( ! is_email($value)) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | |
453 | - $value = trim( $value ); |
|
453 | + $value = trim($value); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | // Bailout |
457 | - if ( ! $value ) { |
|
457 | + if ( ! $value) { |
|
458 | 458 | return false; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Set query params. |
462 | - switch ( $field ) { |
|
462 | + switch ($field) { |
|
463 | 463 | case 'id': |
464 | 464 | $args['donor'] = $value; |
465 | 465 | break; |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | } |
475 | 475 | |
476 | 476 | // Get donors. |
477 | - $donor = new Give_Donors_Query( $args ); |
|
477 | + $donor = new Give_Donors_Query($args); |
|
478 | 478 | |
479 | - if ( ! $donor = $donor->get_donors() ) { |
|
479 | + if ( ! $donor = $donor->get_donors()) { |
|
480 | 480 | // Look for donor from an additional email. |
481 | 481 | $args = array( |
482 | 482 | 'meta_query' => array( |
@@ -487,15 +487,15 @@ discard block |
||
487 | 487 | ), |
488 | 488 | ); |
489 | 489 | |
490 | - $donor = new Give_Donors_Query( $args ); |
|
490 | + $donor = new Give_Donors_Query($args); |
|
491 | 491 | $donor = $donor->get_donors(); |
492 | 492 | |
493 | - if ( empty( $donor ) ) { |
|
493 | + if (empty($donor)) { |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
498 | - return current( $donor ); |
|
498 | + return current($donor); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -508,18 +508,18 @@ discard block |
||
508 | 508 | * |
509 | 509 | * @return array|object|null Donors array or object. Null if not found. |
510 | 510 | */ |
511 | - public function get_donors( $args = array() ) { |
|
512 | - $this->bc_1814_params( $args ); |
|
511 | + public function get_donors($args = array()) { |
|
512 | + $this->bc_1814_params($args); |
|
513 | 513 | |
514 | - $cache_key = md5( 'give_donors_' . serialize( $args ) ); |
|
514 | + $cache_key = md5('give_donors_'.serialize($args)); |
|
515 | 515 | |
516 | - $donors = wp_cache_get( $cache_key, 'donors' ); |
|
516 | + $donors = wp_cache_get($cache_key, 'donors'); |
|
517 | 517 | |
518 | - if ( $donors === false ) { |
|
519 | - $donors = new Give_Donors_Query( $args ); |
|
518 | + if ($donors === false) { |
|
519 | + $donors = new Give_Donors_Query($args); |
|
520 | 520 | $donors = $donors->get_donors(); |
521 | 521 | |
522 | - wp_cache_set( $cache_key, $donors, 'donors', 3600 ); |
|
522 | + wp_cache_set($cache_key, $donors, 'donors', 3600); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | return $donors; |
@@ -537,21 +537,21 @@ discard block |
||
537 | 537 | * |
538 | 538 | * @return int Total number of donors. |
539 | 539 | */ |
540 | - public function count( $args = array() ) { |
|
541 | - $this->bc_1814_params( $args ); |
|
540 | + public function count($args = array()) { |
|
541 | + $this->bc_1814_params($args); |
|
542 | 542 | $args['count'] = true; |
543 | 543 | |
544 | - $cache_key = md5( 'give_donors_count' . serialize( $args ) ); |
|
545 | - $count = wp_cache_get( $cache_key, 'donors' ); |
|
544 | + $cache_key = md5('give_donors_count'.serialize($args)); |
|
545 | + $count = wp_cache_get($cache_key, 'donors'); |
|
546 | 546 | |
547 | - if ( $count === false ) { |
|
548 | - $donors = new Give_Donors_Query( $args ); |
|
547 | + if ($count === false) { |
|
548 | + $donors = new Give_Donors_Query($args); |
|
549 | 549 | $count = $donors->get_donors(); |
550 | 550 | |
551 | - wp_cache_set( $cache_key, $count, 'donors', 3600 ); |
|
551 | + wp_cache_set($cache_key, $count, 'donors', 3600); |
|
552 | 552 | } |
553 | 553 | |
554 | - return absint( $count ); |
|
554 | + return absint($count); |
|
555 | 555 | |
556 | 556 | } |
557 | 557 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | */ |
566 | 566 | public function create_table() { |
567 | 567 | |
568 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
568 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
569 | 569 | |
570 | - $sql = "CREATE TABLE " . $this->table_name . " ( |
|
570 | + $sql = "CREATE TABLE ".$this->table_name." ( |
|
571 | 571 | id bigint(20) NOT NULL AUTO_INCREMENT, |
572 | 572 | user_id bigint(20) NOT NULL, |
573 | 573 | email varchar(50) NOT NULL, |
@@ -582,9 +582,9 @@ discard block |
||
582 | 582 | KEY user (user_id) |
583 | 583 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
584 | 584 | |
585 | - dbDelta( $sql ); |
|
585 | + dbDelta($sql); |
|
586 | 586 | |
587 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
587 | + update_option($this->table_name.'_db_version', $this->version); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @return bool Returns if the donors table was installed and upgrade routine run. |
597 | 597 | */ |
598 | 598 | public function installed() { |
599 | - return $this->table_exists( $this->table_name ); |
|
599 | + return $this->table_exists($this->table_name); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -607,41 +607,41 @@ discard block |
||
607 | 607 | * |
608 | 608 | * @param $args |
609 | 609 | */ |
610 | - private function bc_1814_params( &$args ) { |
|
610 | + private function bc_1814_params(&$args) { |
|
611 | 611 | // Backward compatibility: user_id |
612 | - if ( ! empty( $args['user_id'] ) ) { |
|
612 | + if ( ! empty($args['user_id'])) { |
|
613 | 613 | $args['user'] = $args['user_id']; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Backward compatibility: id |
617 | - if ( ! empty( $args['id'] ) ) { |
|
617 | + if ( ! empty($args['id'])) { |
|
618 | 618 | $args['donor'] = $args['id']; |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Backward compatibility: name |
622 | - if ( ! empty( $args['name'] ) ) { |
|
622 | + if ( ! empty($args['name'])) { |
|
623 | 623 | $args['s'] = "name:{$args['name']}"; |
624 | 624 | } |
625 | 625 | |
626 | 626 | // Backward compatibility: date |
627 | 627 | // Donors created for a specific date or in a date range. |
628 | - if ( ! empty( $args['date'] ) ) { |
|
628 | + if ( ! empty($args['date'])) { |
|
629 | 629 | |
630 | - if ( is_array( $args['date'] ) ) { |
|
630 | + if (is_array($args['date'])) { |
|
631 | 631 | |
632 | - if ( ! empty( $args['date']['start'] ) ) { |
|
633 | - $args['date_query']['after'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
632 | + if ( ! empty($args['date']['start'])) { |
|
633 | + $args['date_query']['after'] = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
634 | 634 | } |
635 | 635 | |
636 | - if ( ! empty( $args['date']['end'] ) ) { |
|
637 | - $args['date_query']['before'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
636 | + if ( ! empty($args['date']['end'])) { |
|
637 | + $args['date_query']['before'] = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | } else { |
641 | 641 | |
642 | - $args['date_query']['year'] = date( 'Y', strtotime( $args['date'] ) ); |
|
643 | - $args['date_query']['month'] = date( 'm', strtotime( $args['date'] ) ); |
|
644 | - $args['date_query']['day'] = date( 'd', strtotime( $args['date'] ) ); |
|
642 | + $args['date_query']['year'] = date('Y', strtotime($args['date'])); |
|
643 | + $args['date_query']['month'] = date('m', strtotime($args['date'])); |
|
644 | + $args['date_query']['day'] = date('d', strtotime($args['date'])); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | } |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | * @access private |
704 | 704 | * @since 1.7 |
705 | 705 | * |
706 | - * @return bool |
|
706 | + * @return false|null |
|
707 | 707 | */ |
708 | 708 | private function __remove_license_key_from_subscriptions() { |
709 | 709 | $subscriptions = get_option( 'give_subscriptions', array() ); |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | * @param $plugin_data |
737 | 737 | * @param $status |
738 | 738 | * |
739 | - * @return bool |
|
739 | + * @return false|null |
|
740 | 740 | */ |
741 | 741 | public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
742 | 742 | // Bailout. |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | * |
759 | 759 | * @since 1.8.7 |
760 | 760 | * @access public |
761 | - * @return array |
|
761 | + * @return string |
|
762 | 762 | */ |
763 | 763 | public function license_state_message() { |
764 | 764 | $message_data = array(); |
@@ -10,11 +10,11 @@ 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 | |
17 | -if ( ! class_exists( 'Give_License' ) ) : |
|
17 | +if ( ! class_exists('Give_License')) : |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Give_License Class |
@@ -143,27 +143,27 @@ discard block |
||
143 | 143 | * @param string $_checkout_url |
144 | 144 | * @param string $_account_url |
145 | 145 | */ |
146 | - public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null ) { |
|
146 | + public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null) { |
|
147 | 147 | |
148 | 148 | $give_options = give_get_settings(); |
149 | 149 | |
150 | 150 | $this->file = $_file; |
151 | 151 | $this->item_name = $_item_name; |
152 | - $this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); |
|
152 | + $this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); |
|
153 | 153 | $this->version = $_version; |
154 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
155 | - $this->license_data = get_option( $this->item_shortname . '_license_active' ); |
|
154 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
155 | + $this->license_data = get_option($this->item_shortname.'_license_active'); |
|
156 | 156 | $this->author = $_author; |
157 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
158 | - $this->checkout_url = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url; |
|
159 | - $this->account_url = is_null( $_account_url ) ? $this->account_url : $_account_url; |
|
157 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
158 | + $this->checkout_url = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url; |
|
159 | + $this->account_url = is_null($_account_url) ? $this->account_url : $_account_url; |
|
160 | 160 | $this->auto_updater_obj = null; |
161 | 161 | |
162 | 162 | // Add Setting for Give Add-on activation status. |
163 | - $is_addon_activated = get_option( 'give_is_addon_activated' ); |
|
164 | - if ( ! $is_addon_activated && is_object( $this ) && sizeof( $this ) > 0 ) { |
|
165 | - update_option( 'give_is_addon_activated', true ); |
|
166 | - Give_Cache::set( 'give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS ); |
|
163 | + $is_addon_activated = get_option('give_is_addon_activated'); |
|
164 | + if ( ! $is_addon_activated && is_object($this) && sizeof($this) > 0) { |
|
165 | + update_option('give_is_addon_activated', true); |
|
166 | + Give_Cache::set('give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Setup hooks |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | private function includes() { |
186 | 186 | |
187 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
187 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
188 | 188 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
189 | 189 | } |
190 | 190 | } |
@@ -202,30 +202,30 @@ discard block |
||
202 | 202 | private function hooks() { |
203 | 203 | |
204 | 204 | // Register settings. |
205 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
205 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
206 | 206 | |
207 | 207 | // Activate license key on settings save. |
208 | - add_action( 'admin_init', array( $this, 'activate_license' ), 10 ); |
|
208 | + add_action('admin_init', array($this, 'activate_license'), 10); |
|
209 | 209 | |
210 | 210 | // Deactivate license key. |
211 | - add_action( 'admin_init', array( $this, 'deactivate_license' ), 11 ); |
|
211 | + add_action('admin_init', array($this, 'deactivate_license'), 11); |
|
212 | 212 | |
213 | 213 | // Updater. |
214 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
215 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
214 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
215 | + add_action('admin_notices', array($this, 'notices')); |
|
216 | 216 | |
217 | 217 | // Check license weekly. |
218 | - Give_Cron::add_weekly_event( array( $this, 'weekly_license_check' ) ); |
|
219 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_license_check' ) ); |
|
218 | + Give_Cron::add_weekly_event(array($this, 'weekly_license_check')); |
|
219 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_license_check')); |
|
220 | 220 | |
221 | 221 | // Check subscription weekly. |
222 | - Give_Cron::add_weekly_event( array( $this, 'weekly_subscription_check' ) ); |
|
223 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_subscription_check' ) ); |
|
222 | + Give_Cron::add_weekly_event(array($this, 'weekly_subscription_check')); |
|
223 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_subscription_check')); |
|
224 | 224 | |
225 | 225 | // Show addon notice on plugin page. |
226 | - $plugin_name = explode( 'plugins/', $this->file ); |
|
227 | - $plugin_name = end( $plugin_name ); |
|
228 | - add_action( "after_plugin_row_{$plugin_name}", array( $this, 'plugin_page_notices' ), 10, 3 ); |
|
226 | + $plugin_name = explode('plugins/', $this->file); |
|
227 | + $plugin_name = end($plugin_name); |
|
228 | + add_action("after_plugin_row_{$plugin_name}", array($this, 'plugin_page_notices'), 10, 3); |
|
229 | 229 | |
230 | 230 | } |
231 | 231 | |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return array License settings. |
267 | 267 | */ |
268 | - public function settings( $settings ) { |
|
268 | + public function settings($settings) { |
|
269 | 269 | |
270 | 270 | $give_license_settings = array( |
271 | 271 | array( |
272 | 272 | 'name' => $this->item_name, |
273 | - 'id' => $this->item_shortname . '_license_key', |
|
273 | + 'id' => $this->item_shortname.'_license_key', |
|
274 | 274 | 'desc' => '', |
275 | 275 | 'type' => 'license_key', |
276 | 276 | 'options' => array( |
277 | - 'license' => get_option( $this->item_shortname . '_license_active' ), |
|
277 | + 'license' => get_option($this->item_shortname.'_license_active'), |
|
278 | 278 | 'shortname' => $this->item_shortname, |
279 | 279 | 'item_name' => $this->item_name, |
280 | 280 | 'api_url' => $this->api_url, |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | ), |
286 | 286 | ); |
287 | 287 | |
288 | - return array_merge( $settings, $give_license_settings ); |
|
288 | + return array_merge($settings, $give_license_settings); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -300,18 +300,18 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return array License settings content. |
302 | 302 | */ |
303 | - public function license_settings_content( $settings ) { |
|
303 | + public function license_settings_content($settings) { |
|
304 | 304 | |
305 | 305 | $give_license_settings = array( |
306 | 306 | array( |
307 | - 'name' => __( 'Add-on Licenses', 'give' ), |
|
307 | + 'name' => __('Add-on Licenses', 'give'), |
|
308 | 308 | 'desc' => '<hr>', |
309 | 309 | 'type' => 'give_title', |
310 | 310 | 'id' => 'give_title', |
311 | 311 | ), |
312 | 312 | ); |
313 | 313 | |
314 | - return array_merge( $settings, $give_license_settings ); |
|
314 | + return array_merge($settings, $give_license_settings); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -326,62 +326,62 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function activate_license() { |
328 | 328 | // Bailout. |
329 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
329 | + if ( ! $this->__is_user_can_edit_license()) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
333 | 333 | // Allow third party addon developers to handle license activation. |
334 | - if ( $this->__is_third_party_addon() ) { |
|
335 | - do_action( 'give_activate_license', $this ); |
|
334 | + if ($this->__is_third_party_addon()) { |
|
335 | + do_action('give_activate_license', $this); |
|
336 | 336 | |
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // Delete previous license setting if a empty license key submitted. |
341 | - if ( empty( $_POST["{$this->item_shortname}_license_key"] ) ) { |
|
341 | + if (empty($_POST["{$this->item_shortname}_license_key"])) { |
|
342 | 342 | $this->unset_license(); |
343 | 343 | |
344 | 344 | return; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Do not simultaneously activate add-ons if the user want to deactivate a specific add-on. |
348 | - if( $this->is_deactivating_license() ) { |
|
348 | + if ($this->is_deactivating_license()) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Check if plugin previously installed. |
353 | - if ( $this->is_valid_license() ) { |
|
353 | + if ($this->is_valid_license()) { |
|
354 | 354 | return; |
355 | 355 | } |
356 | 356 | |
357 | 357 | // Get license key. |
358 | - $this->license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
358 | + $this->license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
359 | 359 | |
360 | 360 | // Delete previous license key from subscription if previously added. |
361 | 361 | $this->__remove_license_key_from_subscriptions(); |
362 | 362 | |
363 | 363 | // Make sure there are no api errors. |
364 | - if ( ! ( $license_data = $this->get_license_info( 'activate_license' ) ) ) { |
|
364 | + if ( ! ($license_data = $this->get_license_info('activate_license'))) { |
|
365 | 365 | return; |
366 | 366 | } |
367 | 367 | |
368 | 368 | // Make sure license is valid. |
369 | 369 | // return because admin will want to activate license again. |
370 | - if ( ! $this->is_license( $license_data ) ) { |
|
370 | + if ( ! $this->is_license($license_data)) { |
|
371 | 371 | // Add license key. |
372 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
372 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
373 | 373 | |
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Tell WordPress to look for updates. |
378 | - set_site_transient( 'update_plugins', null ); |
|
378 | + set_site_transient('update_plugins', null); |
|
379 | 379 | |
380 | 380 | // Add license data. |
381 | - update_option( "{$this->item_shortname}_license_active", $license_data ); |
|
381 | + update_option("{$this->item_shortname}_license_active", $license_data); |
|
382 | 382 | |
383 | 383 | // Add license key. |
384 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
384 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
385 | 385 | |
386 | 386 | // Check subscription for license key and store this to db (if any). |
387 | 387 | $this->__single_subscription_check(); |
@@ -399,19 +399,19 @@ discard block |
||
399 | 399 | */ |
400 | 400 | public function deactivate_license() { |
401 | 401 | // Bailout. |
402 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
402 | + if ( ! $this->__is_user_can_edit_license()) { |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | |
406 | 406 | // Allow third party add-on developers to handle license deactivation. |
407 | - if ( $this->__is_third_party_addon() ) { |
|
408 | - do_action( 'give_deactivate_license', $this ); |
|
407 | + if ($this->__is_third_party_addon()) { |
|
408 | + do_action('give_deactivate_license', $this); |
|
409 | 409 | |
410 | 410 | return; |
411 | 411 | } |
412 | 412 | |
413 | 413 | // Run on deactivate button press. |
414 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
414 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
415 | 415 | $this->unset_license(); |
416 | 416 | } |
417 | 417 | } |
@@ -427,30 +427,30 @@ discard block |
||
427 | 427 | public function weekly_license_check() { |
428 | 428 | |
429 | 429 | if ( |
430 | - ! empty( $_POST['give_settings'] ) || |
|
431 | - empty( $this->license ) |
|
430 | + ! empty($_POST['give_settings']) || |
|
431 | + empty($this->license) |
|
432 | 432 | ) { |
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Allow third party add-on developers to handle their license check. |
437 | - if ( $this->__is_third_party_addon() ) { |
|
438 | - do_action( 'give_weekly_license_check', $this ); |
|
437 | + if ($this->__is_third_party_addon()) { |
|
438 | + do_action('give_weekly_license_check', $this); |
|
439 | 439 | |
440 | 440 | return; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Make sure there are no api errors. |
444 | - if ( ! ( $license_data = $this->get_license_info( 'check_license' ) ) ) { |
|
444 | + if ( ! ($license_data = $this->get_license_info('check_license'))) { |
|
445 | 445 | return; |
446 | 446 | } |
447 | 447 | |
448 | 448 | // Bailout. |
449 | - if ( ! $this->is_license( $license_data ) ) { |
|
449 | + if ( ! $this->is_license($license_data)) { |
|
450 | 450 | return; |
451 | 451 | } |
452 | 452 | |
453 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
453 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
454 | 454 | |
455 | 455 | return; |
456 | 456 | } |
@@ -466,21 +466,21 @@ discard block |
||
466 | 466 | public function weekly_subscription_check() { |
467 | 467 | // Bailout. |
468 | 468 | if ( |
469 | - ! empty( $_POST['give_settings'] ) || |
|
470 | - empty( $this->license ) |
|
469 | + ! empty($_POST['give_settings']) || |
|
470 | + empty($this->license) |
|
471 | 471 | ) { |
472 | 472 | return; |
473 | 473 | } |
474 | 474 | |
475 | 475 | // Remove old subscription data. |
476 | - if ( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp', 1 ) ) { |
|
477 | - delete_option( 'give_subscriptions' ); |
|
478 | - update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp', 1 ) ) ); |
|
476 | + if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) { |
|
477 | + delete_option('give_subscriptions'); |
|
478 | + update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1))); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | // Allow third party add-on developers to handle their subscription check. |
482 | - if ( $this->__is_third_party_addon() ) { |
|
483 | - do_action( 'give_weekly_subscription_check', $this ); |
|
482 | + if ($this->__is_third_party_addon()) { |
|
483 | + do_action('give_weekly_subscription_check', $this); |
|
484 | 484 | |
485 | 485 | return; |
486 | 486 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @return void |
498 | 498 | */ |
499 | 499 | private function __single_subscription_check() { |
500 | - if ( empty( $this->license ) ) { |
|
500 | + if (empty($this->license)) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
@@ -508,26 +508,26 @@ discard block |
||
508 | 508 | * By default edd software licensing api does not have api to check subscription. |
509 | 509 | * This is a custom feature to check subscriptions. |
510 | 510 | */ |
511 | - $subscription_data = $this->get_license_info( 'check_subscription', true ); |
|
511 | + $subscription_data = $this->get_license_info('check_subscription', true); |
|
512 | 512 | |
513 | - if ( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
513 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
514 | 514 | |
515 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
515 | + $subscriptions = get_option('give_subscriptions', array()); |
|
516 | 516 | |
517 | 517 | // Update subscription data only if subscription does not exist already. |
518 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
518 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
519 | 519 | |
520 | 520 | // Initiate default set of license for subscription. |
521 | - if ( ! isset( $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
522 | - $subscriptions[ $subscription_data['id'] ]['licenses'] = array(); |
|
521 | + if ( ! isset($subscriptions[$subscription_data['id']]['licenses'])) { |
|
522 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | // Store licenses for subscription. |
526 | - if ( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
527 | - $subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license; |
|
526 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
527 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
528 | 528 | } |
529 | 529 | |
530 | - update_option( 'give_subscriptions', $subscriptions ); |
|
530 | + update_option('give_subscriptions', $subscriptions); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -541,12 +541,12 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public function notices() { |
543 | 543 | |
544 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
544 | + if ( ! current_user_can('manage_give_settings')) { |
|
545 | 545 | return; |
546 | 546 | } |
547 | 547 | |
548 | 548 | // Do not show licenses notices on license tab. |
549 | - if ( 'licenses' === give_get_current_setting_tab() ) { |
|
549 | + if ('licenses' === give_get_current_setting_tab()) { |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | |
@@ -555,118 +555,118 @@ discard block |
||
555 | 555 | static $addon_license_key_in_subscriptions; |
556 | 556 | |
557 | 557 | // Set default value. |
558 | - $addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array(); |
|
558 | + $addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array(); |
|
559 | 559 | $messages = array(); |
560 | 560 | |
561 | 561 | // Check whether admin has Give Add-on activated since 24 hours? |
562 | - $is_license_notice_hidden = Give_Cache::get( 'give_cache_hide_license_notice_after_activation' ); |
|
562 | + $is_license_notice_hidden = Give_Cache::get('give_cache_hide_license_notice_after_activation'); |
|
563 | 563 | |
564 | 564 | // Display Invalid License notice, if its more than 24 hours since first Give Add-on activation. |
565 | 565 | if ( |
566 | - empty( $this->license ) |
|
567 | - && empty( $showed_invalid_message ) |
|
568 | - && ( false === $is_license_notice_hidden ) |
|
566 | + empty($this->license) |
|
567 | + && empty($showed_invalid_message) |
|
568 | + && (false === $is_license_notice_hidden) |
|
569 | 569 | ) { |
570 | 570 | |
571 | - Give()->notices->register_notice( array( |
|
571 | + Give()->notices->register_notice(array( |
|
572 | 572 | 'id' => 'give-invalid-license', |
573 | 573 | 'type' => 'error', |
574 | 574 | 'description' => sprintf( |
575 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
576 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
575 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
576 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
577 | 577 | ), |
578 | 578 | 'dismissible_type' => 'user', |
579 | 579 | 'dismiss_interval' => 'shortly', |
580 | - ) ); |
|
580 | + )); |
|
581 | 581 | |
582 | 582 | $showed_invalid_message = true; |
583 | 583 | |
584 | 584 | } |
585 | 585 | |
586 | 586 | // Get subscriptions. |
587 | - $subscriptions = get_option( 'give_subscriptions' ); |
|
587 | + $subscriptions = get_option('give_subscriptions'); |
|
588 | 588 | |
589 | 589 | // Show subscription messages. |
590 | - if ( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) { |
|
590 | + if ( ! empty($subscriptions) && ! $showed_subscriptions_message) { |
|
591 | 591 | |
592 | - foreach ( $subscriptions as $subscription ) { |
|
592 | + foreach ($subscriptions as $subscription) { |
|
593 | 593 | // Subscription expires timestamp. |
594 | - $subscription_expires = strtotime( $subscription['expires'] ); |
|
594 | + $subscription_expires = strtotime($subscription['expires']); |
|
595 | 595 | |
596 | 596 | // Start showing subscriptions message before one week of renewal date. |
597 | - if ( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) { |
|
597 | + if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) { |
|
598 | 598 | continue; |
599 | 599 | } |
600 | 600 | |
601 | 601 | // Check if subscription message already exist in messages. |
602 | - if ( array_key_exists( $subscription['id'], $messages ) ) { |
|
602 | + if (array_key_exists($subscription['id'], $messages)) { |
|
603 | 603 | continue; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // Check if license already expired. |
607 | - if ( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) { |
|
608 | - Give()->notices->register_notice( array( |
|
607 | + if (strtotime($subscription['expires']) < current_time('timestamp', 1)) { |
|
608 | + Give()->notices->register_notice(array( |
|
609 | 609 | 'id' => "give-expired-subscription-{$subscription['id']}", |
610 | 610 | 'type' => 'error', |
611 | 611 | 'description' => sprintf( |
612 | - __( 'Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give' ), |
|
613 | - urldecode( $subscription['invoice_url'] ), |
|
612 | + __('Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give'), |
|
613 | + urldecode($subscription['invoice_url']), |
|
614 | 614 | $subscription['payment_id'], |
615 | 615 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
616 | - Give()->notices->get_dismiss_link( array( |
|
617 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
616 | + Give()->notices->get_dismiss_link(array( |
|
617 | + 'title' => __('Click here if already renewed', 'give'), |
|
618 | 618 | 'dismissible_type' => 'user', |
619 | 619 | 'dismiss_interval' => 'permanent', |
620 | - ) ) |
|
620 | + )) |
|
621 | 621 | ), |
622 | 622 | 'dismissible_type' => 'user', |
623 | 623 | 'dismiss_interval' => 'shortly', |
624 | - ) ); |
|
624 | + )); |
|
625 | 625 | } else { |
626 | - Give()->notices->register_notice( array( |
|
626 | + Give()->notices->register_notice(array( |
|
627 | 627 | 'id' => "give-expires-subscription-{$subscription['id']}", |
628 | 628 | 'type' => 'error', |
629 | 629 | 'description' => sprintf( |
630 | - __( 'Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give' ), |
|
631 | - human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |
|
632 | - urldecode( $subscription['invoice_url'] ), |
|
630 | + __('Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give'), |
|
631 | + human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])), |
|
632 | + urldecode($subscription['invoice_url']), |
|
633 | 633 | $subscription['payment_id'], |
634 | 634 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
635 | - Give()->notices->get_dismiss_link( array( |
|
636 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
635 | + Give()->notices->get_dismiss_link(array( |
|
636 | + 'title' => __('Click here if already renewed', 'give'), |
|
637 | 637 | 'dismissible_type' => 'user', |
638 | 638 | 'dismiss_interval' => 'permanent', |
639 | - ) ) |
|
639 | + )) |
|
640 | 640 | ), |
641 | 641 | 'dismissible_type' => 'user', |
642 | 642 | 'dismiss_interval' => 'shortly', |
643 | - ) ); |
|
643 | + )); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | // Stop validation for these license keys. |
647 | - $addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] ); |
|
647 | + $addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']); |
|
648 | 648 | }// End foreach(). |
649 | 649 | $showed_subscriptions_message = true; |
650 | 650 | }// End if(). |
651 | 651 | |
652 | 652 | // Show Non Subscription Give Add-on messages. |
653 | 653 | if ( |
654 | - ! in_array( $this->license, $addon_license_key_in_subscriptions ) |
|
655 | - && ! empty( $this->license ) |
|
656 | - && empty( $showed_invalid_message ) |
|
654 | + ! in_array($this->license, $addon_license_key_in_subscriptions) |
|
655 | + && ! empty($this->license) |
|
656 | + && empty($showed_invalid_message) |
|
657 | 657 | && ! $this->is_valid_license() |
658 | 658 | ) { |
659 | 659 | |
660 | - Give()->notices->register_notice( array( |
|
660 | + Give()->notices->register_notice(array( |
|
661 | 661 | 'id' => 'give-invalid-license', |
662 | 662 | 'type' => 'error', |
663 | 663 | 'description' => sprintf( |
664 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
665 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
664 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
665 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
666 | 666 | ), |
667 | 667 | 'dismissible_type' => 'user', |
668 | 668 | 'dismiss_interval' => 'shortly', |
669 | - ) ); |
|
669 | + )); |
|
670 | 670 | |
671 | 671 | $showed_invalid_message = true; |
672 | 672 | |
@@ -683,10 +683,10 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return bool |
685 | 685 | */ |
686 | - public function is_valid_license( $licence_data = null ) { |
|
687 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
686 | + public function is_valid_license($licence_data = null) { |
|
687 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
688 | 688 | |
689 | - if ( apply_filters( 'give_is_valid_license', ( $this->is_license( $license_data ) && 'valid' === $license_data->license ) ) ) { |
|
689 | + if (apply_filters('give_is_valid_license', ($this->is_license($license_data) && 'valid' === $license_data->license))) { |
|
690 | 690 | return true; |
691 | 691 | } |
692 | 692 | |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | * |
705 | 705 | * @return bool |
706 | 706 | */ |
707 | - public function is_license( $licence_data = null ) { |
|
708 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
707 | + public function is_license($licence_data = null) { |
|
708 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
709 | 709 | |
710 | - if ( apply_filters( 'give_is_license', ( is_object( $license_data ) && ! empty( $license_data ) && property_exists( $license_data, 'license' ) ) ) ) { |
|
710 | + if (apply_filters('give_is_license', (is_object($license_data) && ! empty($license_data) && property_exists($license_data, 'license')))) { |
|
711 | 711 | return true; |
712 | 712 | } |
713 | 713 | |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | * @return bool |
724 | 724 | */ |
725 | 725 | private function __is_third_party_addon() { |
726 | - return ( false === strpos( $this->api_url, 'givewp.com/' ) ); |
|
726 | + return (false === strpos($this->api_url, 'givewp.com/')); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -738,25 +738,25 @@ discard block |
||
738 | 738 | * @return bool |
739 | 739 | */ |
740 | 740 | private function __remove_license_key_from_subscriptions() { |
741 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
741 | + $subscriptions = get_option('give_subscriptions', array()); |
|
742 | 742 | |
743 | 743 | // Bailout. |
744 | - if ( empty( $this->license ) ) { |
|
744 | + if (empty($this->license)) { |
|
745 | 745 | return false; |
746 | 746 | } |
747 | 747 | |
748 | - if ( ! empty( $subscriptions ) ) { |
|
749 | - foreach ( $subscriptions as $subscription_id => $subscription ) { |
|
750 | - $license_index = array_search( $this->license, $subscription['licenses'] ); |
|
751 | - if ( false !== $license_index ) { |
|
748 | + if ( ! empty($subscriptions)) { |
|
749 | + foreach ($subscriptions as $subscription_id => $subscription) { |
|
750 | + $license_index = array_search($this->license, $subscription['licenses']); |
|
751 | + if (false !== $license_index) { |
|
752 | 752 | // Remove license key. |
753 | - unset( $subscriptions[ $subscription_id ]['licenses'][ $license_index ] ); |
|
753 | + unset($subscriptions[$subscription_id]['licenses'][$license_index]); |
|
754 | 754 | |
755 | 755 | // Rearrange license keys. |
756 | - $subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] ); |
|
756 | + $subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']); |
|
757 | 757 | |
758 | 758 | // Update subscription information. |
759 | - update_option( 'give_subscriptions', $subscriptions ); |
|
759 | + update_option('give_subscriptions', $subscriptions); |
|
760 | 760 | break; |
761 | 761 | } |
762 | 762 | } |
@@ -770,17 +770,17 @@ discard block |
||
770 | 770 | * |
771 | 771 | * @return bool |
772 | 772 | */ |
773 | - public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
|
773 | + public function plugin_page_notices($plugin_file, $plugin_data, $status) { |
|
774 | 774 | // Bailout. |
775 | - if ( $this->is_valid_license() ) { |
|
775 | + if ($this->is_valid_license()) { |
|
776 | 776 | return false; |
777 | 777 | } |
778 | 778 | |
779 | 779 | $update_notice_wrap = '<tr class="give-addon-notice-tr active"><td colspan="3" class="colspanchange"><div class="notice inline notice-warning notice-alt give-invalid-license"><p><span class="dashicons dashicons-info"></span> %s</p></div></td></tr>'; |
780 | 780 | $message = $this->license_state_message(); |
781 | 781 | |
782 | - if ( ! empty( $message['message'] ) ) { |
|
783 | - echo sprintf( $update_notice_wrap, $message['message'] ); |
|
782 | + if ( ! empty($message['message'])) { |
|
783 | + echo sprintf($update_notice_wrap, $message['message']); |
|
784 | 784 | } |
785 | 785 | } |
786 | 786 | |
@@ -795,11 +795,11 @@ discard block |
||
795 | 795 | public function license_state_message() { |
796 | 796 | $message_data = array(); |
797 | 797 | |
798 | - if ( ! $this->is_valid_license() ) { |
|
798 | + if ( ! $this->is_valid_license()) { |
|
799 | 799 | |
800 | 800 | $message_data['message'] = sprintf( |
801 | 801 | 'Please <a href="%1$s">activate your license</a> to receive updates and support for the %2$s add-on.', |
802 | - esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) ), |
|
802 | + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')), |
|
803 | 803 | $this->item_name |
804 | 804 | ); |
805 | 805 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | // Bailout. |
819 | 819 | if ( |
820 | 820 | ! Give_Admin_Settings::verify_nonce() || |
821 | - ! current_user_can( 'manage_give_settings' ) || |
|
821 | + ! current_user_can('manage_give_settings') || |
|
822 | 822 | 'licenses' !== give_get_current_setting_tab() |
823 | 823 | ) { |
824 | 824 | return false; |
@@ -826,10 +826,10 @@ discard block |
||
826 | 826 | |
827 | 827 | // Security check. |
828 | 828 | if ( |
829 | - isset( $_POST[ $this->item_shortname . '_license_key-nonce' ] ) && |
|
830 | - ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) |
|
829 | + isset($_POST[$this->item_shortname.'_license_key-nonce']) && |
|
830 | + ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce') |
|
831 | 831 | ) { |
832 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
832 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | return true; |
@@ -847,9 +847,9 @@ discard block |
||
847 | 847 | * |
848 | 848 | * @return mixed |
849 | 849 | */ |
850 | - public function get_license_info( $edd_action = '', $response_in_array = false ) { |
|
850 | + public function get_license_info($edd_action = '', $response_in_array = false) { |
|
851 | 851 | |
852 | - if ( empty( $edd_action ) ) { |
|
852 | + if (empty($edd_action)) { |
|
853 | 853 | return false; |
854 | 854 | } |
855 | 855 | |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | $api_params = array( |
858 | 858 | 'edd_action' => $edd_action, // never change from "edd_" to "give_"! |
859 | 859 | 'license' => $this->license, |
860 | - 'item_name' => urlencode( $this->item_name ), |
|
860 | + 'item_name' => urlencode($this->item_name), |
|
861 | 861 | 'url' => home_url(), |
862 | 862 | ); |
863 | 863 | |
@@ -872,11 +872,11 @@ discard block |
||
872 | 872 | ); |
873 | 873 | |
874 | 874 | // Make sure there are no errors. |
875 | - if ( is_wp_error( $response ) ) { |
|
875 | + if (is_wp_error($response)) { |
|
876 | 876 | return false; |
877 | 877 | } |
878 | 878 | |
879 | - return json_decode( wp_remote_retrieve_body( $response ), $response_in_array ); |
|
879 | + return json_decode(wp_remote_retrieve_body($response), $response_in_array); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | $this->__remove_license_key_from_subscriptions(); |
893 | 893 | |
894 | 894 | // Remove license from database. |
895 | - delete_option( "{$this->item_shortname}_license_active" ); |
|
896 | - give_delete_option( "{$this->item_shortname}_license_key" ); |
|
897 | - unset( $_POST["{$this->item_shortname}_license_key"] ); |
|
895 | + delete_option("{$this->item_shortname}_license_active"); |
|
896 | + give_delete_option("{$this->item_shortname}_license_key"); |
|
897 | + unset($_POST["{$this->item_shortname}_license_key"]); |
|
898 | 898 | |
899 | 899 | // Unset license param. |
900 | 900 | $this->license = ''; |
@@ -912,8 +912,8 @@ discard block |
||
912 | 912 | private function is_deactivating_license() { |
913 | 913 | $status = false; |
914 | 914 | |
915 | - foreach ( $_POST as $key => $value ) { |
|
916 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
915 | + foreach ($_POST as $key => $value) { |
|
916 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
917 | 917 | $status = true; |
918 | 918 | break; |
919 | 919 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param $end_date string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` |
37 | 37 | * @param $status string|array The sale status(es) to count. Only valid when retrieving global stats |
38 | 38 | * |
39 | - * @return float|int Total amount of donations based on the passed arguments. |
|
39 | + * @return string Total amount of donations based on the passed arguments. |
|
40 | 40 | */ |
41 | 41 | public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
42 | 42 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param $end_date string|bool The end date for which we'd like to filter the donations stats. If false, method will use the default end date of `this_month`. |
84 | 84 | * @param $gateway_id string|bool The gateway to get earnings for such as 'paypal' or 'stripe'. |
85 | 85 | * |
86 | - * @return float|int Total amount of donations based on the passed arguments. |
|
86 | + * @return string Total amount of donations based on the passed arguments. |
|
87 | 87 | */ |
88 | 88 | public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
89 | 89 | $this->setup_dates( $start_date, $end_date ); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param $end_date string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` |
169 | 169 | * @param $gateway_id string|bool The gateway to get earnings for such as 'paypal' or 'stripe' |
170 | 170 | * |
171 | - * @return float|int Total amount of donations based on the passed arguments. |
|
171 | + * @return string Total amount of donations based on the passed arguments. |
|
172 | 172 | */ |
173 | 173 | public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
174 | 174 |
@@ -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 | |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return float|int Total amount of donations based on the passed arguments. |
40 | 40 | */ |
41 | - public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
|
41 | + public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { |
|
42 | 42 | |
43 | - $this->setup_dates( $start_date, $end_date ); |
|
43 | + $this->setup_dates($start_date, $end_date); |
|
44 | 44 | |
45 | 45 | // Make sure start date is valid |
46 | - if ( is_wp_error( $this->start_date ) ) { |
|
46 | + if (is_wp_error($this->start_date)) { |
|
47 | 47 | return $this->start_date; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Make sure end date is valid |
51 | - if ( is_wp_error( $this->end_date ) ) { |
|
51 | + if (is_wp_error($this->end_date)) { |
|
52 | 52 | return $this->end_date; |
53 | 53 | } |
54 | 54 | |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | 'start_date' => $this->start_date, |
58 | 58 | 'end_date' => $this->end_date, |
59 | 59 | 'fields' => 'ids', |
60 | - 'number' => - 1, |
|
60 | + 'number' => -1, |
|
61 | 61 | ); |
62 | 62 | |
63 | - if ( ! empty( $form_id ) ) { |
|
63 | + if ( ! empty($form_id)) { |
|
64 | 64 | $args['give_forms'] = $form_id; |
65 | 65 | } |
66 | 66 | |
67 | 67 | /* @var Give_Payments_Query $payments */ |
68 | - $payments = new Give_Payments_Query( $args ); |
|
68 | + $payments = new Give_Payments_Query($args); |
|
69 | 69 | $payments = $payments->get_payments(); |
70 | 70 | |
71 | - return count( $payments ); |
|
71 | + return count($payments); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return float|int Total amount of donations based on the passed arguments. |
87 | 87 | */ |
88 | - public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
89 | - $this->setup_dates( $start_date, $end_date ); |
|
88 | + public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
89 | + $this->setup_dates($start_date, $end_date); |
|
90 | 90 | |
91 | 91 | // Make sure start date is valid |
92 | - if ( is_wp_error( $this->start_date ) ) { |
|
92 | + if (is_wp_error($this->start_date)) { |
|
93 | 93 | return $this->start_date; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Make sure end date is valid |
97 | - if ( is_wp_error( $this->end_date ) ) { |
|
97 | + if (is_wp_error($this->end_date)) { |
|
98 | 98 | return $this->end_date; |
99 | 99 | } |
100 | 100 | |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | 'start_date' => $this->start_date, |
105 | 105 | 'end_date' => $this->end_date, |
106 | 106 | 'fields' => 'ids', |
107 | - 'number' => - 1, |
|
107 | + 'number' => -1, |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | |
111 | 111 | // Filter by Gateway ID meta_key |
112 | - if ( $gateway_id ) { |
|
112 | + if ($gateway_id) { |
|
113 | 113 | $args['meta_query'][] = array( |
114 | 114 | 'key' => '_give_payment_gateway', |
115 | 115 | 'value' => $gateway_id, |
@@ -117,39 +117,39 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // Filter by Gateway ID meta_key |
120 | - if ( $form_id ) { |
|
120 | + if ($form_id) { |
|
121 | 121 | $args['meta_query'][] = array( |
122 | 122 | 'key' => '_give_payment_form_id', |
123 | 123 | 'value' => $form_id, |
124 | 124 | ); |
125 | 125 | } |
126 | 126 | |
127 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
127 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
128 | 128 | $args['meta_query']['relation'] = 'AND'; |
129 | 129 | } |
130 | 130 | |
131 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
132 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
131 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
132 | + $key = Give_Cache::get_key('give_stats', $args); |
|
133 | 133 | |
134 | 134 | // Set transient for faster stats. |
135 | - $earnings = Give_Cache::get( $key ); |
|
135 | + $earnings = Give_Cache::get($key); |
|
136 | 136 | |
137 | - if ( false === $earnings ) { |
|
137 | + if (false === $earnings) { |
|
138 | 138 | |
139 | 139 | $this->timestamp = false; |
140 | - $payments = new Give_Payments_Query( $args ); |
|
140 | + $payments = new Give_Payments_Query($args); |
|
141 | 141 | $payments = $payments->get_payments(); |
142 | 142 | $earnings = 0; |
143 | 143 | |
144 | - if ( ! empty( $payments ) ) { |
|
145 | - foreach ( $payments as $payment ) { |
|
146 | - $earnings += (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) ); |
|
144 | + if ( ! empty($payments)) { |
|
145 | + foreach ($payments as $payment) { |
|
146 | + $earnings += (float) give_donation_amount($payment->ID, array('type' => 'stats')); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Cache the results for one hour. |
152 | - Give_Cache::set( $key, give_sanitize_amount_for_db( $earnings ), 60 * 60 ); |
|
152 | + Give_Cache::set($key, give_sanitize_amount_for_db($earnings), 60 * 60); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | * @param string|bool $end_date Earning end date. |
164 | 164 | * @param string|bool $gateway_id Payment gateway id. |
165 | 165 | */ |
166 | - $earnings = apply_filters( 'give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id ); |
|
166 | + $earnings = apply_filters('give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id); |
|
167 | 167 | |
168 | 168 | //return earnings |
169 | - return round( $earnings, give_get_price_decimals( $form_id ) ); |
|
169 | + return round($earnings, give_get_price_decimals($form_id)); |
|
170 | 170 | |
171 | 171 | } |
172 | 172 | |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return float|int Total amount of donations based on the passed arguments. |
185 | 185 | */ |
186 | - public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
186 | + public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
187 | 187 | |
188 | - $this->setup_dates( $start_date, $end_date ); |
|
188 | + $this->setup_dates($start_date, $end_date); |
|
189 | 189 | |
190 | 190 | // Make sure start date is valid |
191 | - if ( is_wp_error( $this->start_date ) ) { |
|
191 | + if (is_wp_error($this->start_date)) { |
|
192 | 192 | return $this->start_date; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Make sure end date is valid |
196 | - if ( is_wp_error( $this->end_date ) ) { |
|
196 | + if (is_wp_error($this->end_date)) { |
|
197 | 197 | return $this->end_date; |
198 | 198 | } |
199 | 199 | |
@@ -203,12 +203,12 @@ discard block |
||
203 | 203 | 'start_date' => $this->start_date, |
204 | 204 | 'end_date' => $this->end_date, |
205 | 205 | 'fields' => 'ids', |
206 | - 'number' => - 1, |
|
206 | + 'number' => -1, |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | |
210 | 210 | // Filter by Gateway ID meta_key |
211 | - if ( $gateway_id ) { |
|
211 | + if ($gateway_id) { |
|
212 | 212 | $args['meta_query'][] = array( |
213 | 213 | 'key' => '_give_payment_gateway', |
214 | 214 | 'value' => $gateway_id, |
@@ -216,19 +216,19 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | // Filter by Gateway ID meta_key |
219 | - if ( $form_id ) { |
|
219 | + if ($form_id) { |
|
220 | 220 | $args['meta_query'][] = array( |
221 | 221 | 'key' => '_give_payment_form_id', |
222 | 222 | 'value' => $form_id, |
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
226 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
227 | 227 | $args['meta_query']['relation'] = 'AND'; |
228 | 228 | } |
229 | 229 | |
230 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
231 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
230 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
231 | + $key = Give_Cache::get_key('give_stats', $args); |
|
232 | 232 | |
233 | 233 | //return earnings |
234 | 234 | return $key; |
@@ -245,16 +245,16 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @return array Best selling forms |
247 | 247 | */ |
248 | - public function get_best_selling( $number = 10 ) { |
|
248 | + public function get_best_selling($number = 10) { |
|
249 | 249 | |
250 | 250 | global $wpdb; |
251 | 251 | |
252 | - $give_forms = $wpdb->get_results( $wpdb->prepare( |
|
252 | + $give_forms = $wpdb->get_results($wpdb->prepare( |
|
253 | 253 | "SELECT post_id as form_id, max(meta_value) as sales |
254 | 254 | FROM $wpdb->postmeta WHERE meta_key='_give_form_sales' AND meta_value > 0 |
255 | 255 | GROUP BY meta_value+0 |
256 | 256 | DESC LIMIT %d;", $number |
257 | - ) ); |
|
257 | + )); |
|
258 | 258 | |
259 | 259 | return $give_forms; |
260 | 260 | } |
@@ -249,10 +249,10 @@ |
||
249 | 249 | $admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n"; |
250 | 250 | |
251 | 251 | $admin_message .= sprintf( |
252 | - '<a href="%1$s">%2$s</a>', |
|
253 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ), |
|
254 | - __( 'View Donation Details »', 'give' ) |
|
255 | - ) . "\n\n"; |
|
252 | + '<a href="%1$s">%2$s</a>', |
|
253 | + admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ), |
|
254 | + __( 'View Donation Details »', 'give' ) |
|
255 | + ) . "\n\n"; |
|
256 | 256 | |
257 | 257 | $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id ); |
258 | 258 | $admin_message = give_do_email_tags( $admin_message, $payment_id ); |
@@ -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,9 +40,9 @@ 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 | // Get offline payment instruction. |
45 | - $offline_instructions = give_get_offline_payment_instruction( $form_id, true ); |
|
45 | + $offline_instructions = give_get_offline_payment_instruction($form_id, true); |
|
46 | 46 | |
47 | 47 | ob_start(); |
48 | 48 | |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @param int $form_id Give form id. |
55 | 55 | */ |
56 | - do_action( 'give_before_offline_info_fields', $form_id ); |
|
56 | + do_action('give_before_offline_info_fields', $form_id); |
|
57 | 57 | ?> |
58 | 58 | <fieldset id="give_offline_payment_info"> |
59 | - <?php echo stripslashes( $offline_instructions ); ?> |
|
59 | + <?php echo stripslashes($offline_instructions); ?> |
|
60 | 60 | </fieldset> |
61 | 61 | <?php |
62 | 62 | /** |
@@ -66,35 +66,35 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param int $form_id Give form id. |
68 | 68 | */ |
69 | - do_action( 'give_after_offline_info_fields', $form_id ); |
|
69 | + do_action('give_after_offline_info_fields', $form_id); |
|
70 | 70 | |
71 | 71 | echo ob_get_clean(); |
72 | 72 | } |
73 | 73 | |
74 | -add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' ); |
|
74 | +add_action('give_offline_cc_form', 'give_offline_payment_cc_form'); |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Give Offline Billing Field |
78 | 78 | * |
79 | 79 | * @param $form_id |
80 | 80 | */ |
81 | -function give_offline_billing_fields( $form_id ) { |
|
81 | +function give_offline_billing_fields($form_id) { |
|
82 | 82 | //Enable Default CC fields (billing info) |
83 | - $post_offline_cc_fields = give_get_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true ); |
|
84 | - $post_offline_customize_option = give_get_meta( $form_id, '_give_customize_offline_donations', true ); |
|
83 | + $post_offline_cc_fields = give_get_meta($form_id, '_give_offline_donation_enable_billing_fields_single', true); |
|
84 | + $post_offline_customize_option = give_get_meta($form_id, '_give_customize_offline_donations', true); |
|
85 | 85 | |
86 | - $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' ); |
|
86 | + $global_offline_cc_fields = give_get_option('give_offline_donation_enable_billing_fields'); |
|
87 | 87 | |
88 | 88 | //Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options |
89 | 89 | if ( |
90 | - ( give_is_setting_enabled( $post_offline_customize_option, 'global' ) && give_is_setting_enabled( $global_offline_cc_fields ) ) |
|
91 | - || ( give_is_setting_enabled( $post_offline_customize_option, 'enabled' ) && give_is_setting_enabled( $post_offline_cc_fields ) ) |
|
90 | + (give_is_setting_enabled($post_offline_customize_option, 'global') && give_is_setting_enabled($global_offline_cc_fields)) |
|
91 | + || (give_is_setting_enabled($post_offline_customize_option, 'enabled') && give_is_setting_enabled($post_offline_cc_fields)) |
|
92 | 92 | ) { |
93 | - give_default_cc_address_fields( $form_id ); |
|
93 | + give_default_cc_address_fields($form_id); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | -add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 ); |
|
97 | +add_action('give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Process the payment |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return void |
107 | 107 | */ |
108 | -function give_offline_process_payment( $purchase_data ) { |
|
108 | +function give_offline_process_payment($purchase_data) { |
|
109 | 109 | |
110 | 110 | // Setup the payment details. |
111 | 111 | $payment_data = array( |
112 | 112 | 'price' => $purchase_data['price'], |
113 | 113 | 'give_form_title' => $purchase_data['post_data']['give-form-title'], |
114 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
|
115 | - 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '', |
|
114 | + 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), |
|
115 | + 'give_price_id' => isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '', |
|
116 | 116 | 'date' => $purchase_data['date'], |
117 | 117 | 'user_email' => $purchase_data['user_email'], |
118 | 118 | 'purchase_key' => $purchase_data['purchase_key'], |
119 | - 'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ), |
|
119 | + 'currency' => give_get_currency($purchase_data['post_data']['give-form-id'], $purchase_data), |
|
120 | 120 | 'user_info' => $purchase_data['user_info'], |
121 | 121 | 'status' => 'pending', |
122 | 122 | 'gateway' => 'offline' |
@@ -124,20 +124,20 @@ discard block |
||
124 | 124 | |
125 | 125 | |
126 | 126 | // record the pending payment |
127 | - $payment = give_insert_payment( $payment_data ); |
|
127 | + $payment = give_insert_payment($payment_data); |
|
128 | 128 | |
129 | - if ( $payment ) { |
|
130 | - give_offline_send_admin_notice( $payment ); |
|
131 | - give_offline_send_donor_instructions( $payment ); |
|
129 | + if ($payment) { |
|
130 | + give_offline_send_admin_notice($payment); |
|
131 | + give_offline_send_donor_instructions($payment); |
|
132 | 132 | give_send_to_success_page(); |
133 | 133 | } else { |
134 | 134 | // if errors are present, send the user back to the donation form so they can be corrected |
135 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
135 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | } |
139 | 139 | |
140 | -add_action( 'give_gateway_offline', 'give_offline_process_payment' ); |
|
140 | +add_action('give_gateway_offline', 'give_offline_process_payment'); |
|
141 | 141 | |
142 | 142 | |
143 | 143 | /** |
@@ -150,59 +150,59 @@ discard block |
||
150 | 150 | * @since 1.0 |
151 | 151 | * @return void |
152 | 152 | */ |
153 | -function give_offline_send_donor_instructions( $payment_id = 0 ) { |
|
153 | +function give_offline_send_donor_instructions($payment_id = 0) { |
|
154 | 154 | |
155 | - $payment_data = give_get_payment_meta( $payment_id ); |
|
156 | - $post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true ); |
|
155 | + $payment_data = give_get_payment_meta($payment_id); |
|
156 | + $post_offline_customization_option = give_get_meta($payment_data['form_id'], '_give_customize_offline_donations', true); |
|
157 | 157 | |
158 | 158 | //Customize email content depending on whether the single form has been customized |
159 | - $email_content = give_get_option( 'global_offline_donation_email' ); |
|
159 | + $email_content = give_get_option('global_offline_donation_email'); |
|
160 | 160 | |
161 | - if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { |
|
162 | - $email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true ); |
|
161 | + if (give_is_setting_enabled($post_offline_customization_option, 'enabled')) { |
|
162 | + $email_content = give_get_meta($payment_data['form_id'], '_give_offline_donation_email', true); |
|
163 | 163 | } |
164 | 164 | |
165 | - $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
165 | + $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
166 | 166 | |
167 | 167 | /** |
168 | 168 | * Filters the from name. |
169 | 169 | * |
170 | 170 | * @since 1.7 |
171 | 171 | */ |
172 | - $from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data ); |
|
172 | + $from_name = apply_filters('give_donation_from_name', $from_name, $payment_id, $payment_data); |
|
173 | 173 | |
174 | - $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
|
174 | + $from_email = give_get_option('from_email', get_bloginfo('admin_email')); |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * Filters the from email. |
178 | 178 | * |
179 | 179 | * @since 1.7 |
180 | 180 | */ |
181 | - $from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data ); |
|
181 | + $from_email = apply_filters('give_donation_from_address', $from_email, $payment_id, $payment_data); |
|
182 | 182 | |
183 | - $to_email = give_get_payment_user_email( $payment_id ); |
|
183 | + $to_email = give_get_payment_user_email($payment_id); |
|
184 | 184 | |
185 | - $subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) ); |
|
186 | - if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { |
|
187 | - $subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true ); |
|
185 | + $subject = give_get_option('offline_donation_subject', __('Offline Donation Instructions', 'give')); |
|
186 | + if (give_is_setting_enabled($post_offline_customization_option, 'enabled')) { |
|
187 | + $subject = give_get_meta($payment_data['form_id'], '_give_offline_donation_subject', true); |
|
188 | 188 | } |
189 | 189 | |
190 | - $subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id ); |
|
191 | - $subject = give_do_email_tags( $subject, $payment_id ); |
|
190 | + $subject = apply_filters('give_offline_donation_subject', wp_strip_all_tags($subject), $payment_id); |
|
191 | + $subject = give_do_email_tags($subject, $payment_id); |
|
192 | 192 | |
193 | - $attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data ); |
|
194 | - $message = give_do_email_tags( $email_content, $payment_id ); |
|
193 | + $attachments = apply_filters('give_offline_donation_attachments', array(), $payment_id, $payment_data); |
|
194 | + $message = give_do_email_tags($email_content, $payment_id); |
|
195 | 195 | |
196 | 196 | $emails = Give()->emails; |
197 | 197 | |
198 | - $emails->__set( 'from_name', $from_name ); |
|
199 | - $emails->__set( 'from_email', $from_email ); |
|
200 | - $emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) ); |
|
198 | + $emails->__set('from_name', $from_name); |
|
199 | + $emails->__set('from_email', $from_email); |
|
200 | + $emails->__set('heading', __('Offline Donation Instructions', 'give')); |
|
201 | 201 | |
202 | - $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data ); |
|
203 | - $emails->__set( 'headers', $headers ); |
|
202 | + $headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); |
|
203 | + $emails->__set('headers', $headers); |
|
204 | 204 | |
205 | - $emails->send( $to_email, $subject, $message, $attachments ); |
|
205 | + $emails->send($to_email, $subject, $message, $attachments); |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | |
@@ -219,54 +219,54 @@ discard block |
||
219 | 219 | * @return void |
220 | 220 | * |
221 | 221 | */ |
222 | -function give_offline_send_admin_notice( $payment_id = 0 ) { |
|
222 | +function give_offline_send_admin_notice($payment_id = 0) { |
|
223 | 223 | |
224 | 224 | /* Send an email notification to the admin */ |
225 | 225 | $admin_email = give_get_admin_notice_emails(); |
226 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
226 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
227 | 227 | |
228 | - if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { |
|
229 | - $user_data = get_userdata( $user_info['id'] ); |
|
228 | + if (isset($user_info['id']) && $user_info['id'] > 0) { |
|
229 | + $user_data = get_userdata($user_info['id']); |
|
230 | 230 | $name = $user_data->display_name; |
231 | - } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { |
|
232 | - $name = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
231 | + } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) { |
|
232 | + $name = $user_info['first_name'].' '.$user_info['last_name']; |
|
233 | 233 | } else { |
234 | 234 | $name = $user_info['email']; |
235 | 235 | } |
236 | 236 | |
237 | - $amount = give_donation_amount( $payment_id ); |
|
237 | + $amount = give_donation_amount($payment_id); |
|
238 | 238 | |
239 | - $admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id ); |
|
239 | + $admin_subject = apply_filters('give_offline_admin_donation_notification_subject', __('New Pending Donation', 'give'), $payment_id); |
|
240 | 240 | |
241 | - $admin_message = __( 'Dear Admin,', 'give' ) . "\n\n"; |
|
242 | - $admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n"; |
|
243 | - $admin_message .= __( '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"; |
|
241 | + $admin_message = __('Dear Admin,', 'give')."\n\n"; |
|
242 | + $admin_message .= sprintf(__('A new offline donation has been made on your website for %s.', 'give'), $amount)."\n\n"; |
|
243 | + $admin_message .= __('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"; |
|
244 | 244 | |
245 | 245 | |
246 | - $admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n"; |
|
247 | - $admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n"; |
|
246 | + $admin_message .= '<strong>'.__('Donor:', 'give').'</strong> {fullname}'."\n"; |
|
247 | + $admin_message .= '<strong>'.__('Amount:', 'give').'</strong> {amount}'."\n\n"; |
|
248 | 248 | |
249 | 249 | $admin_message .= sprintf( |
250 | 250 | '<a href="%1$s">%2$s</a>', |
251 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ), |
|
252 | - __( 'View Donation Details »', 'give' ) |
|
253 | - ) . "\n\n"; |
|
251 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id='.$payment_id), |
|
252 | + __('View Donation Details »', 'give') |
|
253 | + )."\n\n"; |
|
254 | 254 | |
255 | - $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id ); |
|
256 | - $admin_message = give_do_email_tags( $admin_message, $payment_id ); |
|
255 | + $admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id); |
|
256 | + $admin_message = give_do_email_tags($admin_message, $payment_id); |
|
257 | 257 | |
258 | - $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id ); |
|
259 | - $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id ); |
|
258 | + $attachments = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id); |
|
259 | + $admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id); |
|
260 | 260 | |
261 | 261 | //Send Email |
262 | 262 | $emails = Give()->emails; |
263 | - $emails->__set( 'heading', __( 'New Offline Donation', 'give' ) ); |
|
263 | + $emails->__set('heading', __('New Offline Donation', 'give')); |
|
264 | 264 | |
265 | - if ( ! empty( $admin_headers ) ) { |
|
266 | - $emails->__set( 'headers', $admin_headers ); |
|
265 | + if ( ! empty($admin_headers)) { |
|
266 | + $emails->__set('headers', $admin_headers); |
|
267 | 267 | } |
268 | 268 | |
269 | - $emails->send( $admin_email, $admin_subject, $admin_message, $attachments ); |
|
269 | + $emails->send($admin_email, $admin_subject, $admin_message, $attachments); |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | |
@@ -278,20 +278,20 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @return array |
280 | 280 | */ |
281 | -function give_offline_add_settings( $settings ) { |
|
281 | +function give_offline_add_settings($settings) { |
|
282 | 282 | |
283 | 283 | // Bailout: Do not show offline gateways setting in to metabox if its disabled globally. |
284 | - if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) { |
|
284 | + if (in_array('offline', (array) give_get_option('gateways'))) { |
|
285 | 285 | return $settings; |
286 | 286 | } |
287 | 287 | |
288 | 288 | //Vars |
289 | 289 | $prefix = '_give_'; |
290 | 290 | |
291 | - $is_gateway_active = give_is_gateway_active( 'offline' ); |
|
291 | + $is_gateway_active = give_is_gateway_active('offline'); |
|
292 | 292 | |
293 | 293 | //this gateway isn't active |
294 | - if ( ! $is_gateway_active ) { |
|
294 | + if ( ! $is_gateway_active) { |
|
295 | 295 | //return settings and bounce |
296 | 296 | return $settings; |
297 | 297 | } |
@@ -300,34 +300,34 @@ discard block |
||
300 | 300 | $check_settings = array( |
301 | 301 | |
302 | 302 | array( |
303 | - 'name' => __( 'Offline Donations', 'give' ), |
|
304 | - 'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ), |
|
305 | - 'id' => $prefix . 'customize_offline_donations', |
|
303 | + 'name' => __('Offline Donations', 'give'), |
|
304 | + 'desc' => __('Do you want to customize the donation instructions for this form?', 'give'), |
|
305 | + 'id' => $prefix.'customize_offline_donations', |
|
306 | 306 | 'type' => 'radio_inline', |
307 | 307 | 'default' => 'global', |
308 | - 'options' => apply_filters( 'give_forms_content_options_select', array( |
|
309 | - 'global' => __( 'Global Option', 'give' ), |
|
310 | - 'enabled' => __( 'Customize', 'give' ), |
|
311 | - 'disabled' => __( 'Disable', 'give' ), |
|
308 | + 'options' => apply_filters('give_forms_content_options_select', array( |
|
309 | + 'global' => __('Global Option', 'give'), |
|
310 | + 'enabled' => __('Customize', 'give'), |
|
311 | + 'disabled' => __('Disable', 'give'), |
|
312 | 312 | ) |
313 | 313 | ), |
314 | 314 | ), |
315 | 315 | array( |
316 | - 'name' => __( 'Billing Fields', 'give' ), |
|
317 | - 'desc' => __( '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' ), |
|
318 | - 'id' => $prefix . 'offline_donation_enable_billing_fields_single', |
|
316 | + 'name' => __('Billing Fields', 'give'), |
|
317 | + 'desc' => __('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'), |
|
318 | + 'id' => $prefix.'offline_donation_enable_billing_fields_single', |
|
319 | 319 | 'row_classes' => 'give-subfield give-hidden', |
320 | 320 | 'type' => 'radio_inline', |
321 | 321 | 'default' => 'disabled', |
322 | 322 | 'options' => array( |
323 | - 'enabled' => __( 'Enabled', 'give' ), |
|
324 | - 'disabled' => __( 'Disabled', 'give' ), |
|
323 | + 'enabled' => __('Enabled', 'give'), |
|
324 | + 'disabled' => __('Disabled', 'give'), |
|
325 | 325 | ), |
326 | 326 | ), |
327 | 327 | array( |
328 | - 'id' => $prefix . 'offline_checkout_notes', |
|
329 | - 'name' => __( 'Donation Instructions', 'give' ), |
|
330 | - 'desc' => __( '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' ), |
|
328 | + 'id' => $prefix.'offline_checkout_notes', |
|
329 | + 'name' => __('Donation Instructions', 'give'), |
|
330 | + 'desc' => __('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'), |
|
331 | 331 | 'default' => give_get_default_offline_donation_content(), |
332 | 332 | 'type' => 'wysiwyg', |
333 | 333 | 'row_classes' => 'give-subfield give-hidden', |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | ), |
337 | 337 | ), |
338 | 338 | array( |
339 | - 'id' => $prefix . 'offline_donation_subject', |
|
340 | - 'name' => __( 'Email Subject', 'give' ), |
|
341 | - 'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ), |
|
342 | - 'default' => __( '{form_title} - Offline Donation Instructions', 'give' ), |
|
339 | + 'id' => $prefix.'offline_donation_subject', |
|
340 | + 'name' => __('Email Subject', 'give'), |
|
341 | + 'desc' => __('Enter the subject line for the donation receipt email.', 'give'), |
|
342 | + 'default' => __('{form_title} - Offline Donation Instructions', 'give'), |
|
343 | 343 | 'row_classes' => 'give-subfield give-hidden', |
344 | 344 | 'type' => 'text', |
345 | 345 | ), |
346 | 346 | array( |
347 | - 'id' => $prefix . 'offline_donation_email', |
|
348 | - 'name' => __( 'Email Instructions', 'give' ), |
|
349 | - 'desc' => __( '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' ) . ' ' . __( 'Available template tags:', 'give' ) . give_get_emails_tags_list(), |
|
347 | + 'id' => $prefix.'offline_donation_email', |
|
348 | + 'name' => __('Email Instructions', 'give'), |
|
349 | + 'desc' => __('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').' '.__('Available template tags:', 'give').give_get_emails_tags_list(), |
|
350 | 350 | 'default' => give_get_default_offline_donation_email_content(), |
351 | 351 | 'type' => 'wysiwyg', |
352 | 352 | 'row_classes' => 'give-subfield give-hidden', |
@@ -358,14 +358,14 @@ discard block |
||
358 | 358 | 'name' => 'offline_docs', |
359 | 359 | 'type' => 'docs_link', |
360 | 360 | 'url' => 'http://docs.givewp.com/settings-gateway-offline-donations', |
361 | - 'title' => __( 'Offline Donations', 'give' ), |
|
361 | + 'title' => __('Offline Donations', 'give'), |
|
362 | 362 | ), |
363 | 363 | ); |
364 | 364 | |
365 | - return array_merge( $settings, $check_settings ); |
|
365 | + return array_merge($settings, $check_settings); |
|
366 | 366 | } |
367 | 367 | |
368 | -add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' ); |
|
368 | +add_filter('give_forms_offline_donations_metabox_fields', 'give_offline_add_settings'); |
|
369 | 369 | |
370 | 370 | |
371 | 371 | /** |
@@ -377,32 +377,32 @@ discard block |
||
377 | 377 | */ |
378 | 378 | function give_get_default_offline_donation_content() { |
379 | 379 | |
380 | - $sitename = get_bloginfo( 'sitename' ); |
|
380 | + $sitename = get_bloginfo('sitename'); |
|
381 | 381 | |
382 | - $default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>'; |
|
382 | + $default_text = '<p>'.__('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>111 Not A Real St.</em><br>'; |
402 | 402 | $default_text .= ' <em>Anytown, CA 12345 </em><br>'; |
403 | - $default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>'; |
|
403 | + $default_text .= '<p>'.__('All contributions will be gratefully acknowledged and are tax deductible.', 'give').'</p>'; |
|
404 | 404 | |
405 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
405 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | |
@@ -415,34 +415,34 @@ discard block |
||
415 | 415 | */ |
416 | 416 | function give_get_default_offline_donation_email_content() { |
417 | 417 | |
418 | - $sitename = get_bloginfo( 'sitename' ); |
|
419 | - $default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>'; |
|
420 | - $default_text .= '<p>' . __( '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>'; |
|
418 | + $sitename = get_bloginfo('sitename'); |
|
419 | + $default_text = '<p>'.__('Dear {name},', 'give').'</p>'; |
|
420 | + $default_text .= '<p>'.__('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>'; |
|
421 | 421 | $default_text .= '<ol>'; |
422 | 422 | $default_text .= '<li>'; |
423 | 423 | $default_text .= sprintf( |
424 | 424 | /* translators: %s: site name */ |
425 | - __( 'Make a check payable to "%s"', 'give' ), |
|
425 | + __('Make a check payable to "%s"', 'give'), |
|
426 | 426 | $sitename |
427 | 427 | ); |
428 | 428 | $default_text .= '</li>'; |
429 | 429 | $default_text .= '<li>'; |
430 | 430 | $default_text .= sprintf( |
431 | 431 | /* translators: %s: site name */ |
432 | - __( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ), |
|
432 | + __('On the memo line of the check, please indicate that the donation is for "%s"', 'give'), |
|
433 | 433 | $sitename |
434 | 434 | ); |
435 | 435 | $default_text .= '</li>'; |
436 | - $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>'; |
|
436 | + $default_text .= '<li>'.__('Please mail your check to:', 'give').'</li>'; |
|
437 | 437 | $default_text .= '</ol>'; |
438 | - $default_text .= ' <em>' . $sitename . '</em><br>'; |
|
438 | + $default_text .= ' <em>'.$sitename.'</em><br>'; |
|
439 | 439 | $default_text .= ' <em>111 Not A Real St.</em><br>'; |
440 | 440 | $default_text .= ' <em>Anytown, CA 12345 </em><br>'; |
441 | - $default_text .= '<p>' . __( '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>'; |
|
442 | - $default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>'; |
|
443 | - $default_text .= '<p>' . $sitename . '</p>'; |
|
441 | + $default_text .= '<p>'.__('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>'; |
|
442 | + $default_text .= '<p>'.__('Sincerely,', 'give').'</p>'; |
|
443 | + $default_text .= '<p>'.$sitename.'</p>'; |
|
444 | 444 | |
445 | - return apply_filters( 'give_default_offline_donation_content', $default_text ); |
|
445 | + return apply_filters('give_default_offline_donation_content', $default_text); |
|
446 | 446 | |
447 | 447 | } |
448 | 448 | |
@@ -456,17 +456,17 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return string |
458 | 458 | */ |
459 | -function give_offline_donation_receipt_status_notice( $notice, $id ) { |
|
460 | - $payment = new Give_Payment( $id ); |
|
459 | +function give_offline_donation_receipt_status_notice($notice, $id) { |
|
460 | + $payment = new Give_Payment($id); |
|
461 | 461 | |
462 | - if ( 'offline' !== $payment->gateway || $payment->is_completed() ) { |
|
462 | + if ('offline' !== $payment->gateway || $payment->is_completed()) { |
|
463 | 463 | return $notice; |
464 | 464 | } |
465 | 465 | |
466 | - return Give()->notices->print_frontend_notice( __( 'Payment Pending: Please follow the instructions below to complete your donation.', 'give' ), false, 'warning' ); |
|
466 | + return Give()->notices->print_frontend_notice(__('Payment Pending: Please follow the instructions below to complete your donation.', 'give'), false, 'warning'); |
|
467 | 467 | } |
468 | 468 | |
469 | -add_filter( 'give_receipt_status_notice', 'give_offline_donation_receipt_status_notice', 10, 2 ); |
|
469 | +add_filter('give_receipt_status_notice', 'give_offline_donation_receipt_status_notice', 10, 2); |
|
470 | 470 | |
471 | 471 | /** |
472 | 472 | * Get offline payment instructions. |
@@ -478,27 +478,27 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @return string |
480 | 480 | */ |
481 | -function give_get_offline_payment_instruction( $form_id, $wpautop = false ) { |
|
481 | +function give_get_offline_payment_instruction($form_id, $wpautop = false) { |
|
482 | 482 | // Bailout. |
483 | - if ( ! $form_id ) { |
|
483 | + if ( ! $form_id) { |
|
484 | 484 | return ''; |
485 | 485 | } |
486 | 486 | |
487 | - $post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true ); |
|
488 | - $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true ); |
|
489 | - $global_offline_instruction = give_get_option( 'global_offline_donation_content' ); |
|
487 | + $post_offline_customization_option = give_get_meta($form_id, '_give_customize_offline_donations', true); |
|
488 | + $post_offline_instructions = give_get_meta($form_id, '_give_offline_checkout_notes', true); |
|
489 | + $global_offline_instruction = give_get_option('global_offline_donation_content'); |
|
490 | 490 | $offline_instructions = $global_offline_instruction; |
491 | 491 | |
492 | - if ( give_is_setting_enabled( $post_offline_customization_option ) ) { |
|
492 | + if (give_is_setting_enabled($post_offline_customization_option)) { |
|
493 | 493 | $offline_instructions = $post_offline_instructions; |
494 | 494 | } |
495 | 495 | |
496 | - $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' ); |
|
496 | + $settings_url = admin_url('post.php?post='.$form_id.'&action=edit&message=1'); |
|
497 | 497 | |
498 | 498 | /* translators: %s: form settings url */ |
499 | - $offline_instructions = ! empty( $offline_instructions ) ? $offline_instructions : sprintf( __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), $settings_url ); |
|
499 | + $offline_instructions = ! empty($offline_instructions) ? $offline_instructions : sprintf(__('Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give'), $settings_url); |
|
500 | 500 | |
501 | - return ( $wpautop ? wpautop( $offline_instructions ) : $offline_instructions ); |
|
501 | + return ($wpautop ? wpautop($offline_instructions) : $offline_instructions); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | |
@@ -512,24 +512,24 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @return array |
514 | 514 | */ |
515 | -function give_filter_offline_gateway( $gateway_list, $form_id ) { |
|
515 | +function give_filter_offline_gateway($gateway_list, $form_id) { |
|
516 | 516 | if ( |
517 | 517 | // Show offline payment gateway if enable for new donation form. |
518 | - ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) ) |
|
518 | + (false === strpos($_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms')) |
|
519 | 519 | && $form_id |
520 | - && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true ), array( |
|
520 | + && ! give_is_setting_enabled(give_get_meta($form_id, '_give_customize_offline_donations', true), array( |
|
521 | 521 | 'enabled', |
522 | 522 | 'global', |
523 | - ) ) |
|
523 | + )) |
|
524 | 524 | ) { |
525 | - unset( $gateway_list['offline'] ); |
|
525 | + unset($gateway_list['offline']); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | // Output. |
529 | 529 | return $gateway_list; |
530 | 530 | } |
531 | 531 | |
532 | -add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 ); |
|
532 | +add_filter('give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2); |
|
533 | 533 | |
534 | 534 | /** |
535 | 535 | * Set default gateway to global default payment gateway |
@@ -543,10 +543,10 @@ discard block |
||
543 | 543 | * |
544 | 544 | * @return void |
545 | 545 | */ |
546 | -function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) { |
|
547 | - if ( ! give_is_setting_enabled( $meta_value, array( 'global', 'enabled' ) ) && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) ) ) { |
|
548 | - give_update_meta( $postid, '_give_default_gateway', 'global' ); |
|
546 | +function _give_customize_offline_donations_on_save_callback($meta_key, $meta_value, $postid) { |
|
547 | + if ( ! give_is_setting_enabled($meta_value, array('global', 'enabled')) && ('offline' === give_get_meta($postid, '_give_default_gateway', true))) { |
|
548 | + give_update_meta($postid, '_give_default_gateway', 'global'); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | -add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 ); |
|
552 | +add_filter('give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_do_ajax_export() { |
27 | 27 | |
28 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export.php'; |
|
28 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/export/class-batch-export.php'; |
|
29 | 29 | |
30 | - parse_str( $_POST['form'], $form ); |
|
30 | + parse_str($_POST['form'], $form); |
|
31 | 31 | |
32 | 32 | $_REQUEST = $form = (array) $form; |
33 | 33 | |
34 | - if ( ! wp_verify_nonce( $_REQUEST['give_ajax_export'], 'give_ajax_export' ) ) { |
|
35 | - die( '-2' ); |
|
34 | + if ( ! wp_verify_nonce($_REQUEST['give_ajax_export'], 'give_ajax_export')) { |
|
35 | + die('-2'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,28 +42,28 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @param string $class Export class. |
44 | 44 | */ |
45 | - do_action( 'give_batch_export_class_include', $form['give-export-class'] ); |
|
45 | + do_action('give_batch_export_class_include', $form['give-export-class']); |
|
46 | 46 | |
47 | - $step = absint( $_POST['step'] ); |
|
48 | - $class = sanitize_text_field( $form['give-export-class'] ); |
|
47 | + $step = absint($_POST['step']); |
|
48 | + $class = sanitize_text_field($form['give-export-class']); |
|
49 | 49 | |
50 | 50 | /* @var Give_Batch_Export $export */ |
51 | - $export = new $class( $step ); |
|
51 | + $export = new $class($step); |
|
52 | 52 | |
53 | - if ( ! $export->can_export() ) { |
|
54 | - die( '-1' ); |
|
53 | + if ( ! $export->can_export()) { |
|
54 | + die('-1'); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! $export->is_writable ) { |
|
57 | + if ( ! $export->is_writable) { |
|
58 | 58 | $json_args = array( |
59 | 59 | 'error' => true, |
60 | - 'message' => esc_html__( 'Export location or file not writable.', 'give' ) |
|
60 | + 'message' => esc_html__('Export location or file not writable.', 'give') |
|
61 | 61 | ); |
62 | 62 | echo json_encode($json_args); |
63 | 63 | exit; |
64 | 64 | } |
65 | 65 | |
66 | - $export->set_properties( give_clean( $_REQUEST ) ); |
|
66 | + $export->set_properties(give_clean($_REQUEST)); |
|
67 | 67 | |
68 | 68 | $export->pre_fetch(); |
69 | 69 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | $percentage = $export->get_percentage_complete(); |
73 | 73 | |
74 | - if ( $ret ) { |
|
74 | + if ($ret) { |
|
75 | 75 | |
76 | 76 | $step += 1; |
77 | 77 | $json_data = array( |
@@ -79,18 +79,17 @@ discard block |
||
79 | 79 | 'percentage' => $percentage |
80 | 80 | ); |
81 | 81 | |
82 | - } elseif ( true === $export->is_empty ) { |
|
82 | + } elseif (true === $export->is_empty) { |
|
83 | 83 | |
84 | 84 | $json_data = array( |
85 | 85 | 'error' => true, |
86 | - 'message' => esc_html__( 'No data found for export parameters.', 'give' ) |
|
86 | + 'message' => esc_html__('No data found for export parameters.', 'give') |
|
87 | 87 | ); |
88 | 88 | |
89 | - } elseif ( true === $export->done && true === $export->is_void ) { |
|
89 | + } elseif (true === $export->done && true === $export->is_void) { |
|
90 | 90 | |
91 | - $message = ! empty( $export->message ) ? |
|
92 | - $export->message : |
|
93 | - esc_html__( 'Batch Processing Complete', 'give' ); |
|
91 | + $message = ! empty($export->message) ? |
|
92 | + $export->message : esc_html__('Batch Processing Complete', 'give'); |
|
94 | 93 | |
95 | 94 | $json_data = array( |
96 | 95 | 'success' => true, |
@@ -99,23 +98,23 @@ discard block |
||
99 | 98 | |
100 | 99 | } else { |
101 | 100 | |
102 | - $args = array_merge( $_REQUEST, array( |
|
101 | + $args = array_merge($_REQUEST, array( |
|
103 | 102 | 'step' => $step, |
104 | 103 | 'class' => $class, |
105 | - 'nonce' => wp_create_nonce( 'give-batch-export' ), |
|
104 | + 'nonce' => wp_create_nonce('give-batch-export'), |
|
106 | 105 | 'give_action' => 'form_batch_export', |
107 | - ) ); |
|
106 | + )); |
|
108 | 107 | |
109 | 108 | $json_data = array( |
110 | 109 | 'step' => 'done', |
111 | - 'url' => add_query_arg( $args, admin_url() ) |
|
110 | + 'url' => add_query_arg($args, admin_url()) |
|
112 | 111 | ); |
113 | 112 | |
114 | 113 | } |
115 | 114 | |
116 | - $export->unset_properties( give_clean( $_REQUEST ), $export ); |
|
117 | - echo json_encode( $json_data ); |
|
115 | + $export->unset_properties(give_clean($_REQUEST), $export); |
|
116 | + echo json_encode($json_data); |
|
118 | 117 | exit; |
119 | 118 | } |
120 | 119 | |
121 | -add_action( 'wp_ajax_give_do_ajax_export', 'give_do_ajax_export' ); |
|
120 | +add_action('wp_ajax_give_do_ajax_export', 'give_do_ajax_export'); |
@@ -245,7 +245,7 @@ |
||
245 | 245 | |
246 | 246 | // Continue if donor already included. |
247 | 247 | if ( empty( $payment->customer_id ) || |
248 | - in_array( $payment->customer_id, $cached_donor_ids ) |
|
248 | + in_array( $payment->customer_id, $cached_donor_ids ) |
|
249 | 249 | ) { |
250 | 250 | continue; |
251 | 251 | } |
@@ -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 | |
@@ -70,23 +70,23 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param array $request The Form Data passed into the batch processing |
72 | 72 | */ |
73 | - public function set_properties( $request ) { |
|
73 | + public function set_properties($request) { |
|
74 | 74 | |
75 | 75 | // Set data from form submission |
76 | - if ( isset( $_POST['form'] ) ) { |
|
77 | - parse_str( $_POST['form'], $this->data ); |
|
76 | + if (isset($_POST['form'])) { |
|
77 | + parse_str($_POST['form'], $this->data); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $this->form = $this->data['forms']; |
81 | 81 | |
82 | 82 | // Setup donor ids cache. |
83 | - if ( ! empty( $this->form ) ) { |
|
83 | + if ( ! empty($this->form)) { |
|
84 | 84 | // Cache donor ids to output unique list of donor. |
85 | - $this->query_id = give_clean( $_REQUEST['give_export_option']['query_id'] ); |
|
85 | + $this->query_id = give_clean($_REQUEST['give_export_option']['query_id']); |
|
86 | 86 | $this->cache_donor_ids(); |
87 | 87 | } |
88 | 88 | |
89 | - $this->price_id = ! empty( $request['give_price_option'] ) && 'all' !== $request['give_price_option'] ? absint( $request['give_price_option'] ) : null; |
|
89 | + $this->price_id = ! empty($request['give_price_option']) && 'all' !== $request['give_price_option'] ? absint($request['give_price_option']) : null; |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | // Fetch already cached donor ids. |
102 | 102 | $donor_ids = $this->donor_ids; |
103 | 103 | |
104 | - if ( $cached_donor_ids = Give_Cache::get( $this->query_id, true ) ) { |
|
105 | - $donor_ids = array_unique( array_merge( $cached_donor_ids, $this->donor_ids ) ); |
|
104 | + if ($cached_donor_ids = Give_Cache::get($this->query_id, true)) { |
|
105 | + $donor_ids = array_unique(array_merge($cached_donor_ids, $this->donor_ids)); |
|
106 | 106 | } |
107 | 107 | |
108 | - $donor_ids = array_values( $donor_ids ); |
|
109 | - Give_Cache::set( $this->query_id, $donor_ids, HOUR_IN_SECONDS, true ); |
|
108 | + $donor_ids = array_values($donor_ids); |
|
109 | + Give_Cache::set($this->query_id, $donor_ids, HOUR_IN_SECONDS, true); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function csv_cols() { |
120 | 120 | |
121 | - $columns = isset( $this->data['give_export_option'] ) ? $this->data['give_export_option'] : array(); |
|
121 | + $columns = isset($this->data['give_export_option']) ? $this->data['give_export_option'] : array(); |
|
122 | 122 | |
123 | 123 | // We need columns. |
124 | - if ( empty( $columns ) ) { |
|
124 | + if (empty($columns)) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | - $cols = $this->get_cols( $columns ); |
|
128 | + $cols = $this->get_cols($columns); |
|
129 | 129 | |
130 | 130 | return $cols; |
131 | 131 | } |
@@ -137,41 +137,41 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return array |
139 | 139 | */ |
140 | - private function get_cols( $columns ) { |
|
140 | + private function get_cols($columns) { |
|
141 | 141 | |
142 | 142 | $cols = array(); |
143 | 143 | |
144 | - foreach ( $columns as $key => $value ) { |
|
144 | + foreach ($columns as $key => $value) { |
|
145 | 145 | |
146 | - switch ( $key ) { |
|
146 | + switch ($key) { |
|
147 | 147 | case 'full_name' : |
148 | - $cols['full_name'] = esc_html__( 'Full Name', 'give' ); |
|
148 | + $cols['full_name'] = esc_html__('Full Name', 'give'); |
|
149 | 149 | break; |
150 | 150 | case 'email' : |
151 | - $cols['email'] = esc_html__( 'Email Address', 'give' ); |
|
151 | + $cols['email'] = esc_html__('Email Address', 'give'); |
|
152 | 152 | break; |
153 | 153 | case 'address' : |
154 | - $cols['address_line1'] = esc_html__( 'Address', 'give' ); |
|
155 | - $cols['address_line2'] = esc_html__( 'Address 2', 'give' ); |
|
156 | - $cols['address_city'] = esc_html__( 'City', 'give' ); |
|
157 | - $cols['address_state'] = esc_html__( 'State', 'give' ); |
|
158 | - $cols['address_zip'] = esc_html__( 'Zip', 'give' ); |
|
159 | - $cols['address_country'] = esc_html__( 'Country', 'give' ); |
|
154 | + $cols['address_line1'] = esc_html__('Address', 'give'); |
|
155 | + $cols['address_line2'] = esc_html__('Address 2', 'give'); |
|
156 | + $cols['address_city'] = esc_html__('City', 'give'); |
|
157 | + $cols['address_state'] = esc_html__('State', 'give'); |
|
158 | + $cols['address_zip'] = esc_html__('Zip', 'give'); |
|
159 | + $cols['address_country'] = esc_html__('Country', 'give'); |
|
160 | 160 | break; |
161 | 161 | case 'userid' : |
162 | - $cols['userid'] = esc_html__( 'User ID', 'give' ); |
|
162 | + $cols['userid'] = esc_html__('User ID', 'give'); |
|
163 | 163 | break; |
164 | 164 | case 'donation_form' : |
165 | - $cols['donation_form'] = esc_html__( 'Donation Form', 'give' ); |
|
165 | + $cols['donation_form'] = esc_html__('Donation Form', 'give'); |
|
166 | 166 | break; |
167 | 167 | case 'date_first_donated' : |
168 | - $cols['date_first_donated'] = esc_html__( 'First Donation Date', 'give' ); |
|
168 | + $cols['date_first_donated'] = esc_html__('First Donation Date', 'give'); |
|
169 | 169 | break; |
170 | 170 | case 'donations' : |
171 | - $cols['donations'] = esc_html__( 'Number of Donations', 'give' ); |
|
171 | + $cols['donations'] = esc_html__('Number of Donations', 'give'); |
|
172 | 172 | break; |
173 | 173 | case 'donation_sum' : |
174 | - $cols['donation_sum'] = esc_html__( 'Sum of Donations', 'give' ); |
|
174 | + $cols['donation_sum'] = esc_html__('Sum of Donations', 'give'); |
|
175 | 175 | break; |
176 | 176 | } |
177 | 177 | } |
@@ -192,29 +192,29 @@ discard block |
||
192 | 192 | $i = 0; |
193 | 193 | |
194 | 194 | $data = array(); |
195 | - $cached_donor_ids = Give_Cache::get( $this->query_id, true ); |
|
195 | + $cached_donor_ids = Give_Cache::get($this->query_id, true); |
|
196 | 196 | |
197 | - if ( ! empty( $this->form ) ) { |
|
197 | + if ( ! empty($this->form)) { |
|
198 | 198 | |
199 | 199 | // Export donors for a specific donation form and also within specified timeframe |
200 | 200 | $args = array( |
201 | 201 | 'output' => 'payments', // Use 'posts' to get standard post objects |
202 | - 'post_type' => array( 'give_payment' ), |
|
202 | + 'post_type' => array('give_payment'), |
|
203 | 203 | 'number' => 30, |
204 | 204 | 'paged' => $this->step, |
205 | 205 | 'status' => 'publish', |
206 | 206 | 'meta_key' => '_give_payment_form_id', |
207 | - 'meta_value' => absint( $this->form ), |
|
207 | + 'meta_value' => absint($this->form), |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | // Check for date option filter |
211 | - if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) { |
|
212 | - $args['start_date'] = ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' ); |
|
213 | - $args['end_date'] = ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) ); |
|
211 | + if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) { |
|
212 | + $args['start_date'] = ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00'); |
|
213 | + $args['end_date'] = ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | // Check for price option. |
217 | - if ( null !== $this->price_id ) { |
|
217 | + if (null !== $this->price_id) { |
|
218 | 218 | $args['meta_query'] = array( |
219 | 219 | array( |
220 | 220 | 'key' => '_give_payment_price_id', |
@@ -223,45 +223,43 @@ discard block |
||
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - $payments_query = new Give_Payments_Query( $args ); |
|
226 | + $payments_query = new Give_Payments_Query($args); |
|
227 | 227 | $payments = $payments_query->get_payments(); |
228 | 228 | |
229 | - if ( $payments ) { |
|
229 | + if ($payments) { |
|
230 | 230 | /* @var Give_Payment $payment */ |
231 | - foreach ( $payments as $payment ) { |
|
231 | + foreach ($payments as $payment) { |
|
232 | 232 | // Set donation sum. |
233 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] = isset( $this->payment_stats[ $payment->customer_id ]['donation_sum'] ) ? |
|
234 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] : |
|
235 | - 0; |
|
236 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] += $payment->total; |
|
233 | + $this->payment_stats[$payment->customer_id]['donation_sum'] = isset($this->payment_stats[$payment->customer_id]['donation_sum']) ? |
|
234 | + $this->payment_stats[$payment->customer_id]['donation_sum'] : 0; |
|
235 | + $this->payment_stats[$payment->customer_id]['donation_sum'] += $payment->total; |
|
237 | 236 | |
238 | 237 | // Set donation count. |
239 | - $this->payment_stats[ $payment->customer_id ]['donations'] = isset( $this->payment_stats[ $payment->customer_id ]['donations'] ) ? |
|
240 | - ++ $this->payment_stats[ $payment->customer_id ]['donations'] : |
|
241 | - 1; |
|
238 | + $this->payment_stats[$payment->customer_id]['donations'] = isset($this->payment_stats[$payment->customer_id]['donations']) ? |
|
239 | + ++$this->payment_stats[$payment->customer_id]['donations'] : 1; |
|
242 | 240 | |
243 | 241 | // Set donation form name. |
244 | - $this->payment_stats[ $payment->customer_id ]['form_title'] = $payment->form_title; |
|
242 | + $this->payment_stats[$payment->customer_id]['form_title'] = $payment->form_title; |
|
245 | 243 | |
246 | 244 | // Continue if donor already included. |
247 | - if ( empty( $payment->customer_id ) || |
|
248 | - in_array( $payment->customer_id, $cached_donor_ids ) |
|
245 | + if (empty($payment->customer_id) || |
|
246 | + in_array($payment->customer_id, $cached_donor_ids) |
|
249 | 247 | ) { |
250 | 248 | continue; |
251 | 249 | } |
252 | 250 | |
253 | 251 | $this->donor_ids[] = $cached_donor_ids[] = $payment->customer_id; |
254 | 252 | |
255 | - $i ++; |
|
253 | + $i++; |
|
256 | 254 | } |
257 | 255 | |
258 | - if ( ! empty( $this->donor_ids ) ) { |
|
259 | - foreach ( $this->donor_ids as $donor_id ) { |
|
260 | - $donor = Give()->donors->get_donor_by( 'id', $donor_id ); |
|
261 | - $donor->donation_form_title = $this->payment_stats[ $donor_id ]['form_title']; |
|
262 | - $donor->purchase_count = $this->payment_stats[ $donor_id ]['donations']; |
|
263 | - $donor->purchase_value = $this->payment_stats[ $donor_id ]['donation_sum']; |
|
264 | - $data[] = $this->set_donor_data( $i, $data, $donor ); |
|
256 | + if ( ! empty($this->donor_ids)) { |
|
257 | + foreach ($this->donor_ids as $donor_id) { |
|
258 | + $donor = Give()->donors->get_donor_by('id', $donor_id); |
|
259 | + $donor->donation_form_title = $this->payment_stats[$donor_id]['form_title']; |
|
260 | + $donor->purchase_count = $this->payment_stats[$donor_id]['donations']; |
|
261 | + $donor->purchase_value = $this->payment_stats[$donor_id]['donation_sum']; |
|
262 | + $data[] = $this->set_donor_data($i, $data, $donor); |
|
265 | 263 | } |
266 | 264 | |
267 | 265 | // Cache donor ids only if admin export donor for specific form. |
@@ -271,7 +269,7 @@ discard block |
||
271 | 269 | } else { |
272 | 270 | |
273 | 271 | // Export all donors. |
274 | - $offset = 30 * ( $this->step - 1 ); |
|
272 | + $offset = 30 * ($this->step - 1); |
|
275 | 273 | |
276 | 274 | $args = array( |
277 | 275 | 'number' => 30, |
@@ -279,31 +277,31 @@ discard block |
||
279 | 277 | ); |
280 | 278 | |
281 | 279 | // Check for date option filter |
282 | - if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) { |
|
280 | + if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) { |
|
283 | 281 | $args['date'] = array( |
284 | - 'start' => ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' ), |
|
285 | - 'end' => ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) ), |
|
282 | + 'start' => ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00'), |
|
283 | + 'end' => ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp')), |
|
286 | 284 | ); |
287 | 285 | } |
288 | 286 | |
289 | - $donors = Give()->donors->get_donors( $args ); |
|
287 | + $donors = Give()->donors->get_donors($args); |
|
290 | 288 | |
291 | - foreach ( $donors as $donor ) { |
|
289 | + foreach ($donors as $donor) { |
|
292 | 290 | |
293 | 291 | // Continue if donor already included. |
294 | - if ( empty( $donor->id ) || empty( $donor->payment_ids ) ) { |
|
292 | + if (empty($donor->id) || empty($donor->payment_ids)) { |
|
295 | 293 | continue; |
296 | 294 | } |
297 | 295 | |
298 | - $payment = new Give_Payment( $donor->payment_ids ); |
|
296 | + $payment = new Give_Payment($donor->payment_ids); |
|
299 | 297 | $donor->donation_form_title = $payment->form_title; |
300 | - $data[] = $this->set_donor_data( $i, $data, $donor ); |
|
301 | - $i ++; |
|
298 | + $data[] = $this->set_donor_data($i, $data, $donor); |
|
299 | + $i++; |
|
302 | 300 | } |
303 | 301 | }// End if(). |
304 | 302 | |
305 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
306 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
303 | + $data = apply_filters('give_export_get_data', $data); |
|
304 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
307 | 305 | |
308 | 306 | return $data; |
309 | 307 | } |
@@ -319,18 +317,18 @@ discard block |
||
319 | 317 | $percentage = 0; |
320 | 318 | |
321 | 319 | // We can't count the number when getting them for a specific form. |
322 | - if ( empty( $this->form ) ) { |
|
320 | + if (empty($this->form)) { |
|
323 | 321 | |
324 | 322 | $total = Give()->donors->count(); |
325 | 323 | |
326 | - if ( $total > 0 ) { |
|
324 | + if ($total > 0) { |
|
327 | 325 | |
328 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
326 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
329 | 327 | |
330 | 328 | } |
331 | 329 | } |
332 | 330 | |
333 | - if ( $percentage > 100 ) { |
|
331 | + if ($percentage > 100) { |
|
334 | 332 | $percentage = 100; |
335 | 333 | } |
336 | 334 | |
@@ -346,51 +344,51 @@ discard block |
||
346 | 344 | * |
347 | 345 | * @return mixed |
348 | 346 | */ |
349 | - private function set_donor_data( $i, $data, $donor ) { |
|
347 | + private function set_donor_data($i, $data, $donor) { |
|
350 | 348 | |
351 | 349 | $columns = $this->csv_cols(); |
352 | 350 | |
353 | 351 | // Set address variable |
354 | 352 | $address = ''; |
355 | - if ( isset( $donor->user_id ) && $donor->user_id > 0 ) { |
|
356 | - $address = give_get_donor_address( $donor->user_id ); |
|
353 | + if (isset($donor->user_id) && $donor->user_id > 0) { |
|
354 | + $address = give_get_donor_address($donor->user_id); |
|
357 | 355 | } |
358 | 356 | |
359 | 357 | // Set columns |
360 | - if ( ! empty( $columns['full_name'] ) ) { |
|
361 | - $data[ $i ]['full_name'] = $donor->name; |
|
358 | + if ( ! empty($columns['full_name'])) { |
|
359 | + $data[$i]['full_name'] = $donor->name; |
|
362 | 360 | } |
363 | - if ( ! empty( $columns['email'] ) ) { |
|
364 | - $data[ $i ]['email'] = $donor->email; |
|
361 | + if ( ! empty($columns['email'])) { |
|
362 | + $data[$i]['email'] = $donor->email; |
|
365 | 363 | } |
366 | - if ( ! empty( $columns['address_line1'] ) ) { |
|
367 | - |
|
368 | - $data[ $i ]['address_line1'] = isset( $address['line1'] ) ? $address['line1'] : ''; |
|
369 | - $data[ $i ]['address_line2'] = isset( $address['line2'] ) ? $address['line2'] : ''; |
|
370 | - $data[ $i ]['address_city'] = isset( $address['city'] ) ? $address['city'] : ''; |
|
371 | - $data[ $i ]['address_state'] = isset( $address['state'] ) ? $address['state'] : ''; |
|
372 | - $data[ $i ]['address_zip'] = isset( $address['zip'] ) ? $address['zip'] : ''; |
|
373 | - $data[ $i ]['address_country'] = isset( $address['country'] ) ? $address['country'] : ''; |
|
364 | + if ( ! empty($columns['address_line1'])) { |
|
365 | + |
|
366 | + $data[$i]['address_line1'] = isset($address['line1']) ? $address['line1'] : ''; |
|
367 | + $data[$i]['address_line2'] = isset($address['line2']) ? $address['line2'] : ''; |
|
368 | + $data[$i]['address_city'] = isset($address['city']) ? $address['city'] : ''; |
|
369 | + $data[$i]['address_state'] = isset($address['state']) ? $address['state'] : ''; |
|
370 | + $data[$i]['address_zip'] = isset($address['zip']) ? $address['zip'] : ''; |
|
371 | + $data[$i]['address_country'] = isset($address['country']) ? $address['country'] : ''; |
|
374 | 372 | } |
375 | - if ( ! empty( $columns['userid'] ) ) { |
|
376 | - $data[ $i ]['userid'] = ! empty( $donor->user_id ) ? $donor->user_id : ''; |
|
373 | + if ( ! empty($columns['userid'])) { |
|
374 | + $data[$i]['userid'] = ! empty($donor->user_id) ? $donor->user_id : ''; |
|
377 | 375 | } |
378 | - if ( ! empty( $columns['donation_form'] ) ) { |
|
379 | - $data[ $i ]['donation_form'] = ! empty( $donor->donation_form_title ) ? $donor->donation_form_title : ''; |
|
376 | + if ( ! empty($columns['donation_form'])) { |
|
377 | + $data[$i]['donation_form'] = ! empty($donor->donation_form_title) ? $donor->donation_form_title : ''; |
|
380 | 378 | } |
381 | - if ( ! empty( $columns['date_first_donated'] ) ) { |
|
382 | - $data[ $i ]['date_first_donated'] = date_i18n( give_date_format(), strtotime( $donor->date_created ) ); |
|
379 | + if ( ! empty($columns['date_first_donated'])) { |
|
380 | + $data[$i]['date_first_donated'] = date_i18n(give_date_format(), strtotime($donor->date_created)); |
|
383 | 381 | } |
384 | - if ( ! empty( $columns['donations'] ) ) { |
|
385 | - $data[ $i ]['donations'] = $donor->purchase_count; |
|
382 | + if ( ! empty($columns['donations'])) { |
|
383 | + $data[$i]['donations'] = $donor->purchase_count; |
|
386 | 384 | } |
387 | - if ( ! empty( $columns['donation_sum'] ) ) { |
|
388 | - $data[ $i ]['donation_sum'] = give_format_amount( $donor->purchase_value, array( 'sanitize' => false ) ); |
|
385 | + if ( ! empty($columns['donation_sum'])) { |
|
386 | + $data[$i]['donation_sum'] = give_format_amount($donor->purchase_value, array('sanitize' => false)); |
|
389 | 387 | } |
390 | 388 | |
391 | - $data[ $i ] = apply_filters( 'give_export_set_donor_data', $data[ $i ], $donor ); |
|
389 | + $data[$i] = apply_filters('give_export_set_donor_data', $data[$i], $donor); |
|
392 | 390 | |
393 | - return $data[ $i ]; |
|
391 | + return $data[$i]; |
|
394 | 392 | |
395 | 393 | } |
396 | 394 | |
@@ -400,9 +398,9 @@ discard block |
||
400 | 398 | * @param array $request |
401 | 399 | * @param Give_Batch_Export $export |
402 | 400 | */ |
403 | - public function unset_properties( $request, $export ) { |
|
404 | - if ( $export->done ) { |
|
405 | - Give_Cache::delete( "give_cache_{$this->query_id}" ); |
|
401 | + public function unset_properties($request, $export) { |
|
402 | + if ($export->done) { |
|
403 | + Give_Cache::delete("give_cache_{$this->query_id}"); |
|
406 | 404 | } |
407 | 405 | } |
408 | 406 | } |
409 | 407 | \ No newline at end of file |