@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly. |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | 'v1' => 'GIVE_API_V1', |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $this->get_versions() as $version => $class ) { |
|
144 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
143 | + foreach ($this->get_versions() as $version => $class) { |
|
144 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
145 | 145 | } |
146 | 146 | |
147 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
148 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
149 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
150 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
154 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
147 | + add_action('init', array($this, 'add_endpoint')); |
|
148 | + add_action('wp', array($this, 'process_query'), - 1); |
|
149 | + add_filter('query_vars', array($this, 'query_vars')); |
|
150 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('personal_options_update', array($this, 'update_key')); |
|
153 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
154 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
155 | 155 | |
156 | 156 | // Setup a backwards compatibility check for user API Keys |
157 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
157 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
158 | 158 | |
159 | 159 | // Determine if JSON_PRETTY_PRINT is available |
160 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
160 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
161 | 161 | |
162 | 162 | // Allow API request logging to be turned off |
163 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
163 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
164 | 164 | |
165 | 165 | // Setup Give_Payment_Stats instance |
166 | 166 | $this->stats = new Give_Payment_Stats; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @since 1.1 |
178 | 178 | */ |
179 | - public function add_endpoint( $rewrite_rules ) { |
|
180 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
179 | + public function add_endpoint($rewrite_rules) { |
|
180 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] $vars New query vars |
192 | 192 | */ |
193 | - public function query_vars( $vars ) { |
|
193 | + public function query_vars($vars) { |
|
194 | 194 | |
195 | 195 | $vars[] = 'token'; |
196 | 196 | $vars[] = 'key'; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function get_default_version() { |
243 | 243 | |
244 | - $version = get_option( 'give_default_api_version' ); |
|
244 | + $version = get_option('give_default_api_version'); |
|
245 | 245 | |
246 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
246 | + if (defined('GIVE_API_VERSION')) { |
|
247 | 247 | $version = GIVE_API_VERSION; |
248 | - } elseif ( ! $version ) { |
|
248 | + } elseif ( ! $version) { |
|
249 | 249 | $version = 'v1'; |
250 | 250 | } |
251 | 251 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | $version = $wp_query->query_vars['give-api']; |
268 | 268 | |
269 | - if ( strpos( $version, '/' ) ) { |
|
269 | + if (strpos($version, '/')) { |
|
270 | 270 | |
271 | - $version = explode( '/', $version ); |
|
272 | - $version = strtolower( $version[0] ); |
|
271 | + $version = explode('/', $version); |
|
272 | + $version = strtolower($version[0]); |
|
273 | 273 | |
274 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
274 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
275 | 275 | |
276 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
276 | + if (array_key_exists($version, $this->versions)) { |
|
277 | 277 | |
278 | 278 | $this->queried_version = $version; |
279 | 279 | |
@@ -309,32 +309,32 @@ discard block |
||
309 | 309 | $this->override = false; |
310 | 310 | |
311 | 311 | // Make sure we have both user and api key |
312 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
312 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
313 | 313 | |
314 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
314 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
315 | 315 | $this->missing_auth(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Retrieve the user by public API key and ensure they exist |
319 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
319 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
320 | 320 | |
321 | 321 | $this->invalid_key(); |
322 | 322 | |
323 | 323 | } else { |
324 | 324 | |
325 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
326 | - $secret = $this->get_user_secret_key( $user ); |
|
327 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
325 | + $token = urldecode($wp_query->query_vars['token']); |
|
326 | + $secret = $this->get_user_secret_key($user); |
|
327 | + $public = urldecode($wp_query->query_vars['key']); |
|
328 | 328 | |
329 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
329 | + if (hash_equals(md5($secret.$public), $token)) { |
|
330 | 330 | $this->is_valid_request = true; |
331 | 331 | } else { |
332 | 332 | $this->invalid_auth(); |
333 | 333 | } |
334 | 334 | } |
335 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
335 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
336 | 336 | $this->is_valid_request = true; |
337 | - $wp_query->set( 'key', 'public' ); |
|
337 | + $wp_query->set('key', 'public'); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
@@ -350,25 +350,25 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return bool if user ID is found, false otherwise |
352 | 352 | */ |
353 | - public function get_user( $key = '' ) { |
|
353 | + public function get_user($key = '') { |
|
354 | 354 | global $wpdb, $wp_query; |
355 | 355 | |
356 | - if ( empty( $key ) ) { |
|
357 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
356 | + if (empty($key)) { |
|
357 | + $key = urldecode($wp_query->query_vars['key']); |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( empty( $key ) ) { |
|
360 | + if (empty($key)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
364 | - $user = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
|
364 | + $user = Give_Cache::get(md5('give_api_user_'.$key), true); |
|
365 | 365 | |
366 | - if ( false === $user ) { |
|
367 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
368 | - Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
|
366 | + if (false === $user) { |
|
367 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
368 | + Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $user != null ) { |
|
371 | + if ($user != null) { |
|
372 | 372 | $this->user_id = $user; |
373 | 373 | |
374 | 374 | return $user; |
@@ -377,37 +377,37 @@ discard block |
||
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | |
380 | - public function get_user_public_key( $user_id = 0 ) { |
|
380 | + public function get_user_public_key($user_id = 0) { |
|
381 | 381 | global $wpdb; |
382 | 382 | |
383 | - if ( empty( $user_id ) ) { |
|
383 | + if (empty($user_id)) { |
|
384 | 384 | return ''; |
385 | 385 | } |
386 | 386 | |
387 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
388 | - $user_public_key = Give_Cache::get( $cache_key, true ); |
|
387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
388 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
389 | 389 | |
390 | - if ( empty( $user_public_key ) ) { |
|
391 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
392 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
390 | + if (empty($user_public_key)) { |
|
391 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
392 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | return $user_public_key; |
396 | 396 | } |
397 | 397 | |
398 | - public function get_user_secret_key( $user_id = 0 ) { |
|
398 | + public function get_user_secret_key($user_id = 0) { |
|
399 | 399 | global $wpdb; |
400 | 400 | |
401 | - if ( empty( $user_id ) ) { |
|
401 | + if (empty($user_id)) { |
|
402 | 402 | return ''; |
403 | 403 | } |
404 | 404 | |
405 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
406 | - $user_secret_key = Give_Cache::get( $cache_key, true ); |
|
405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
406 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
407 | 407 | |
408 | - if ( empty( $user_secret_key ) ) { |
|
409 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
410 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
408 | + if (empty($user_secret_key)) { |
|
409 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
410 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | */ |
424 | 424 | private function missing_auth() { |
425 | 425 | $error = array(); |
426 | - $error['error'] = esc_html__( 'You must specify both a token and API key.', 'give' ); |
|
426 | + $error['error'] = esc_html__('You must specify both a token and API key.', 'give'); |
|
427 | 427 | |
428 | 428 | $this->data = $error; |
429 | - $this->output( 401 ); |
|
429 | + $this->output(401); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | */ |
441 | 441 | private function invalid_auth() { |
442 | 442 | $error = array(); |
443 | - $error['error'] = esc_html__( 'Your request could not be authenticated.', 'give' ); |
|
443 | + $error['error'] = esc_html__('Your request could not be authenticated.', 'give'); |
|
444 | 444 | |
445 | 445 | $this->data = $error; |
446 | - $this->output( 403 ); |
|
446 | + $this->output(403); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function invalid_key() { |
459 | 459 | $error = array(); |
460 | - $error['error'] = esc_html__( 'Invalid API key.', 'give' ); |
|
460 | + $error['error'] = esc_html__('Invalid API key.', 'give'); |
|
461 | 461 | |
462 | 462 | $this->data = $error; |
463 | - $this->output( 403 ); |
|
463 | + $this->output(403); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | */ |
474 | 474 | private function invalid_version() { |
475 | 475 | $error = array(); |
476 | - $error['error'] = esc_html__( 'Invalid API version.', 'give' ); |
|
476 | + $error['error'] = esc_html__('Invalid API version.', 'give'); |
|
477 | 477 | |
478 | 478 | $this->data = $error; |
479 | - $this->output( 404 ); |
|
479 | + $this->output(404); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | global $wp_query; |
493 | 493 | |
494 | 494 | // Start logging how long the request takes for logging |
495 | - $before = microtime( true ); |
|
495 | + $before = microtime(true); |
|
496 | 496 | |
497 | 497 | // Check for give-api var. Get out if not present |
498 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
498 | + if (empty($wp_query->query_vars['give-api'])) { |
|
499 | 499 | return; |
500 | 500 | } |
501 | 501 | |
@@ -509,45 +509,45 @@ discard block |
||
509 | 509 | $this->validate_request(); |
510 | 510 | |
511 | 511 | // Only proceed if no errors have been noted |
512 | - if ( ! $this->is_valid_request ) { |
|
512 | + if ( ! $this->is_valid_request) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
517 | - define( 'GIVE_DOING_API', true ); |
|
516 | + if ( ! defined('GIVE_DOING_API')) { |
|
517 | + define('GIVE_DOING_API', true); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | $data = array(); |
521 | 521 | $this->routes = new $this->versions[$this->get_queried_version()]; |
522 | 522 | $this->routes->validate_request(); |
523 | 523 | |
524 | - switch ( $this->endpoint ) : |
|
524 | + switch ($this->endpoint) : |
|
525 | 525 | |
526 | 526 | case 'stats' : |
527 | 527 | |
528 | - $data = $this->routes->get_stats( array( |
|
529 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
530 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
531 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
532 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
533 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
534 | - ) ); |
|
528 | + $data = $this->routes->get_stats(array( |
|
529 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
530 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
531 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
532 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
533 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
534 | + )); |
|
535 | 535 | |
536 | 536 | break; |
537 | 537 | |
538 | 538 | case 'forms' : |
539 | 539 | |
540 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
540 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
541 | 541 | |
542 | - $data = $this->routes->get_forms( $form ); |
|
542 | + $data = $this->routes->get_forms($form); |
|
543 | 543 | |
544 | 544 | break; |
545 | 545 | |
546 | 546 | case 'donors' : |
547 | 547 | |
548 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
548 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
549 | 549 | |
550 | - $data = $this->routes->get_customers( $customer ); |
|
550 | + $data = $this->routes->get_customers($customer); |
|
551 | 551 | |
552 | 552 | break; |
553 | 553 | |
@@ -560,14 +560,14 @@ discard block |
||
560 | 560 | endswitch; |
561 | 561 | |
562 | 562 | // Allow extensions to setup their own return data |
563 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
563 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
564 | 564 | |
565 | - $after = microtime( true ); |
|
566 | - $request_time = ( $after - $before ); |
|
565 | + $after = microtime(true); |
|
566 | + $request_time = ($after - $before); |
|
567 | 567 | $this->data['request_speed'] = $request_time; |
568 | 568 | |
569 | 569 | // Log this API request, if enabled. We log it here because we have access to errors. |
570 | - $this->log_request( $this->data ); |
|
570 | + $this->log_request($this->data); |
|
571 | 571 | |
572 | 572 | // Send out data to the output function |
573 | 573 | $this->output(); |
@@ -597,25 +597,25 @@ discard block |
||
597 | 597 | global $wp_query; |
598 | 598 | |
599 | 599 | // Whitelist our query options |
600 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
600 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
601 | 601 | 'stats', |
602 | 602 | 'forms', |
603 | 603 | 'donors', |
604 | 604 | 'donations', |
605 | - ) ); |
|
605 | + )); |
|
606 | 606 | |
607 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
608 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
607 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
608 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
609 | 609 | |
610 | 610 | $error = array(); |
611 | 611 | |
612 | 612 | // Make sure our query is valid |
613 | - if ( ! in_array( $query, $accepted ) ) { |
|
614 | - $error['error'] = esc_html__( 'Invalid query.', 'give' ); |
|
613 | + if ( ! in_array($query, $accepted)) { |
|
614 | + $error['error'] = esc_html__('Invalid query.', 'give'); |
|
615 | 615 | |
616 | 616 | $this->data = $error; |
617 | 617 | // 400 is Bad Request |
618 | - $this->output( 400 ); |
|
618 | + $this->output(400); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $this->endpoint = $query; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | public function get_paged() { |
633 | 633 | global $wp_query; |
634 | 634 | |
635 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
635 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -647,13 +647,13 @@ discard block |
||
647 | 647 | public function per_page() { |
648 | 648 | global $wp_query; |
649 | 649 | |
650 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
650 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
651 | 651 | |
652 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
652 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
653 | 653 | $per_page = 99999999; |
654 | 654 | } // Customers query doesn't support -1 |
655 | 655 | |
656 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
656 | + return apply_filters('give_api_results_per_page', $per_page); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * |
667 | 667 | * @return array $dates |
668 | 668 | */ |
669 | - public function get_dates( $args = array() ) { |
|
669 | + public function get_dates($args = array()) { |
|
670 | 670 | $dates = array(); |
671 | 671 | |
672 | 672 | $defaults = array( |
@@ -677,60 +677,60 @@ discard block |
||
677 | 677 | 'enddate' => null, |
678 | 678 | ); |
679 | 679 | |
680 | - $args = wp_parse_args( $args, $defaults ); |
|
680 | + $args = wp_parse_args($args, $defaults); |
|
681 | 681 | |
682 | - $current_time = current_time( 'timestamp' ); |
|
682 | + $current_time = current_time('timestamp'); |
|
683 | 683 | |
684 | - if ( 'range' === $args['date'] ) { |
|
685 | - $startdate = strtotime( $args['startdate'] ); |
|
686 | - $enddate = strtotime( $args['enddate'] ); |
|
687 | - $dates['day_start'] = date( 'd', $startdate ); |
|
688 | - $dates['day_end'] = date( 'd', $enddate ); |
|
689 | - $dates['m_start'] = date( 'n', $startdate ); |
|
690 | - $dates['m_end'] = date( 'n', $enddate ); |
|
691 | - $dates['year'] = date( 'Y', $startdate ); |
|
692 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
684 | + if ('range' === $args['date']) { |
|
685 | + $startdate = strtotime($args['startdate']); |
|
686 | + $enddate = strtotime($args['enddate']); |
|
687 | + $dates['day_start'] = date('d', $startdate); |
|
688 | + $dates['day_end'] = date('d', $enddate); |
|
689 | + $dates['m_start'] = date('n', $startdate); |
|
690 | + $dates['m_end'] = date('n', $enddate); |
|
691 | + $dates['year'] = date('Y', $startdate); |
|
692 | + $dates['year_end'] = date('Y', $enddate); |
|
693 | 693 | } else { |
694 | 694 | // Modify dates based on predefined ranges |
695 | - switch ( $args['date'] ) : |
|
695 | + switch ($args['date']) : |
|
696 | 696 | |
697 | 697 | case 'this_month' : |
698 | 698 | $dates['day'] = null; |
699 | - $dates['m_start'] = date( 'n', $current_time ); |
|
700 | - $dates['m_end'] = date( 'n', $current_time ); |
|
701 | - $dates['year'] = date( 'Y', $current_time ); |
|
699 | + $dates['m_start'] = date('n', $current_time); |
|
700 | + $dates['m_end'] = date('n', $current_time); |
|
701 | + $dates['year'] = date('Y', $current_time); |
|
702 | 702 | break; |
703 | 703 | |
704 | 704 | case 'last_month' : |
705 | 705 | $dates['day'] = null; |
706 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
706 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
707 | 707 | $dates['m_end'] = $dates['m_start']; |
708 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
708 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
709 | 709 | break; |
710 | 710 | |
711 | 711 | case 'today' : |
712 | - $dates['day'] = date( 'd', $current_time ); |
|
713 | - $dates['m_start'] = date( 'n', $current_time ); |
|
714 | - $dates['m_end'] = date( 'n', $current_time ); |
|
715 | - $dates['year'] = date( 'Y', $current_time ); |
|
712 | + $dates['day'] = date('d', $current_time); |
|
713 | + $dates['m_start'] = date('n', $current_time); |
|
714 | + $dates['m_end'] = date('n', $current_time); |
|
715 | + $dates['year'] = date('Y', $current_time); |
|
716 | 716 | break; |
717 | 717 | |
718 | 718 | case 'yesterday' : |
719 | 719 | |
720 | - $year = date( 'Y', $current_time ); |
|
721 | - $month = date( 'n', $current_time ); |
|
722 | - $day = date( 'd', $current_time ); |
|
720 | + $year = date('Y', $current_time); |
|
721 | + $month = date('n', $current_time); |
|
722 | + $day = date('d', $current_time); |
|
723 | 723 | |
724 | - if ( $month == 1 && $day == 1 ) { |
|
724 | + if ($month == 1 && $day == 1) { |
|
725 | 725 | |
726 | 726 | $year -= 1; |
727 | 727 | $month = 12; |
728 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
728 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
729 | 729 | |
730 | - } elseif ( $month > 1 && $day == 1 ) { |
|
730 | + } elseif ($month > 1 && $day == 1) { |
|
731 | 731 | |
732 | 732 | $month -= 1; |
733 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
733 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
734 | 734 | |
735 | 735 | } else { |
736 | 736 | |
@@ -746,65 +746,65 @@ discard block |
||
746 | 746 | break; |
747 | 747 | |
748 | 748 | case 'this_quarter' : |
749 | - $month_now = date( 'n', $current_time ); |
|
749 | + $month_now = date('n', $current_time); |
|
750 | 750 | |
751 | 751 | $dates['day'] = null; |
752 | 752 | |
753 | - if ( $month_now <= 3 ) { |
|
753 | + if ($month_now <= 3) { |
|
754 | 754 | |
755 | 755 | $dates['m_start'] = 1; |
756 | 756 | $dates['m_end'] = 3; |
757 | - $dates['year'] = date( 'Y', $current_time ); |
|
757 | + $dates['year'] = date('Y', $current_time); |
|
758 | 758 | |
759 | - } elseif ( $month_now <= 6 ) { |
|
759 | + } elseif ($month_now <= 6) { |
|
760 | 760 | |
761 | 761 | $dates['m_start'] = 4; |
762 | 762 | $dates['m_end'] = 6; |
763 | - $dates['year'] = date( 'Y', $current_time ); |
|
763 | + $dates['year'] = date('Y', $current_time); |
|
764 | 764 | |
765 | - } elseif ( $month_now <= 9 ) { |
|
765 | + } elseif ($month_now <= 9) { |
|
766 | 766 | |
767 | 767 | $dates['m_start'] = 7; |
768 | 768 | $dates['m_end'] = 9; |
769 | - $dates['year'] = date( 'Y', $current_time ); |
|
769 | + $dates['year'] = date('Y', $current_time); |
|
770 | 770 | |
771 | 771 | } else { |
772 | 772 | |
773 | 773 | $dates['m_start'] = 10; |
774 | 774 | $dates['m_end'] = 12; |
775 | - $dates['year'] = date( 'Y', $current_time ); |
|
775 | + $dates['year'] = date('Y', $current_time); |
|
776 | 776 | |
777 | 777 | } |
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'last_quarter' : |
781 | - $month_now = date( 'n', $current_time ); |
|
781 | + $month_now = date('n', $current_time); |
|
782 | 782 | |
783 | 783 | $dates['day'] = null; |
784 | 784 | |
785 | - if ( $month_now <= 3 ) { |
|
785 | + if ($month_now <= 3) { |
|
786 | 786 | |
787 | 787 | $dates['m_start'] = 10; |
788 | 788 | $dates['m_end'] = 12; |
789 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
789 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
790 | 790 | |
791 | - } elseif ( $month_now <= 6 ) { |
|
791 | + } elseif ($month_now <= 6) { |
|
792 | 792 | |
793 | 793 | $dates['m_start'] = 1; |
794 | 794 | $dates['m_end'] = 3; |
795 | - $dates['year'] = date( 'Y', $current_time ); |
|
795 | + $dates['year'] = date('Y', $current_time); |
|
796 | 796 | |
797 | - } elseif ( $month_now <= 9 ) { |
|
797 | + } elseif ($month_now <= 9) { |
|
798 | 798 | |
799 | 799 | $dates['m_start'] = 4; |
800 | 800 | $dates['m_end'] = 6; |
801 | - $dates['year'] = date( 'Y', $current_time ); |
|
801 | + $dates['year'] = date('Y', $current_time); |
|
802 | 802 | |
803 | 803 | } else { |
804 | 804 | |
805 | 805 | $dates['m_start'] = 7; |
806 | 806 | $dates['m_end'] = 9; |
807 | - $dates['year'] = date( 'Y', $current_time ); |
|
807 | + $dates['year'] = date('Y', $current_time); |
|
808 | 808 | |
809 | 809 | } |
810 | 810 | break; |
@@ -813,14 +813,14 @@ discard block |
||
813 | 813 | $dates['day'] = null; |
814 | 814 | $dates['m_start'] = null; |
815 | 815 | $dates['m_end'] = null; |
816 | - $dates['year'] = date( 'Y', $current_time ); |
|
816 | + $dates['year'] = date('Y', $current_time); |
|
817 | 817 | break; |
818 | 818 | |
819 | 819 | case 'last_year' : |
820 | 820 | $dates['day'] = null; |
821 | 821 | $dates['m_start'] = null; |
822 | 822 | $dates['m_end'] = null; |
823 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
823 | + $dates['year'] = date('Y', $current_time) - 1; |
|
824 | 824 | break; |
825 | 825 | |
826 | 826 | endswitch; |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | * |
834 | 834 | * @param array $dates The dates used for retrieving earnings/donations |
835 | 835 | */ |
836 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
836 | + return apply_filters('give_api_stat_dates', $dates); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -848,11 +848,11 @@ discard block |
||
848 | 848 | * |
849 | 849 | * @return array $customers Multidimensional array of the customers |
850 | 850 | */ |
851 | - public function get_customers( $customer = null ) { |
|
851 | + public function get_customers($customer = null) { |
|
852 | 852 | |
853 | 853 | $customers = array(); |
854 | 854 | $error = array(); |
855 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
855 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
856 | 856 | return $customers; |
857 | 857 | } |
858 | 858 | |
@@ -860,63 +860,63 @@ discard block |
||
860 | 860 | |
861 | 861 | $paged = $this->get_paged(); |
862 | 862 | $per_page = $this->per_page(); |
863 | - $offset = $per_page * ( $paged - 1 ); |
|
863 | + $offset = $per_page * ($paged - 1); |
|
864 | 864 | |
865 | - if ( is_numeric( $customer ) ) { |
|
865 | + if (is_numeric($customer)) { |
|
866 | 866 | $field = 'id'; |
867 | 867 | } else { |
868 | 868 | $field = 'email'; |
869 | 869 | } |
870 | 870 | |
871 | - $customer_query = Give()->customers->get_customers( array( |
|
871 | + $customer_query = Give()->customers->get_customers(array( |
|
872 | 872 | 'number' => $per_page, |
873 | 873 | 'offset' => $offset, |
874 | 874 | $field => $customer, |
875 | - ) ); |
|
875 | + )); |
|
876 | 876 | $customer_count = 0; |
877 | 877 | |
878 | - if ( $customer_query ) { |
|
878 | + if ($customer_query) { |
|
879 | 879 | |
880 | - foreach ( $customer_query as $customer_obj ) { |
|
880 | + foreach ($customer_query as $customer_obj) { |
|
881 | 881 | |
882 | - $names = explode( ' ', $customer_obj->name ); |
|
883 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
882 | + $names = explode(' ', $customer_obj->name); |
|
883 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
884 | 884 | $last_name = ''; |
885 | - if ( ! empty( $names[1] ) ) { |
|
886 | - unset( $names[0] ); |
|
887 | - $last_name = implode( ' ', $names ); |
|
885 | + if ( ! empty($names[1])) { |
|
886 | + unset($names[0]); |
|
887 | + $last_name = implode(' ', $names); |
|
888 | 888 | } |
889 | 889 | |
890 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
891 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
892 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
894 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
895 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
896 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
890 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
891 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
892 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
894 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
895 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
896 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
897 | 897 | |
898 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
898 | + if ( ! empty($customer_obj->user_id)) { |
|
899 | 899 | |
900 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
900 | + $user_data = get_userdata($customer_obj->user_id); |
|
901 | 901 | |
902 | 902 | // Customer with registered account. |
903 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
904 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
905 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
903 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
904 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
905 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
906 | 906 | |
907 | 907 | } |
908 | 908 | |
909 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
910 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
909 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
910 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
911 | 911 | |
912 | - $customer_count ++; |
|
912 | + $customer_count++; |
|
913 | 913 | |
914 | 914 | } |
915 | - } elseif ( $customer ) { |
|
915 | + } elseif ($customer) { |
|
916 | 916 | |
917 | 917 | $error['error'] = sprintf( |
918 | 918 | /* translators: %s: customer */ |
919 | - esc_html__( 'Donor %s not found.', 'give' ), |
|
919 | + esc_html__('Donor %s not found.', 'give'), |
|
920 | 920 | $customer |
921 | 921 | ); |
922 | 922 | |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | |
925 | 925 | } else { |
926 | 926 | |
927 | - $error['error'] = esc_html__( 'No donors found.', 'give' ); |
|
927 | + $error['error'] = esc_html__('No donors found.', 'give'); |
|
928 | 928 | |
929 | 929 | return $error; |
930 | 930 | |
@@ -943,38 +943,38 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @return array $customers Multidimensional array of the forms |
945 | 945 | */ |
946 | - public function get_forms( $form = null ) { |
|
946 | + public function get_forms($form = null) { |
|
947 | 947 | |
948 | 948 | $forms = array(); |
949 | 949 | $error = array(); |
950 | 950 | |
951 | - if ( $form == null ) { |
|
951 | + if ($form == null) { |
|
952 | 952 | $forms['forms'] = array(); |
953 | 953 | |
954 | - $form_list = get_posts( array( |
|
954 | + $form_list = get_posts(array( |
|
955 | 955 | 'post_type' => 'give_forms', |
956 | 956 | 'posts_per_page' => $this->per_page(), |
957 | 957 | 'suppress_filters' => true, |
958 | 958 | 'paged' => $this->get_paged(), |
959 | - ) ); |
|
959 | + )); |
|
960 | 960 | |
961 | - if ( $form_list ) { |
|
961 | + if ($form_list) { |
|
962 | 962 | $i = 0; |
963 | - foreach ( $form_list as $form_info ) { |
|
964 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
965 | - $i ++; |
|
963 | + foreach ($form_list as $form_info) { |
|
964 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
965 | + $i++; |
|
966 | 966 | } |
967 | 967 | } |
968 | 968 | } else { |
969 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
970 | - $form_info = get_post( $form ); |
|
969 | + if (get_post_type($form) == 'give_forms') { |
|
970 | + $form_info = get_post($form); |
|
971 | 971 | |
972 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
972 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
973 | 973 | |
974 | 974 | } else { |
975 | 975 | $error['error'] = sprintf( |
976 | 976 | /* translators: %s: form */ |
977 | - esc_html__( 'Form %s not found.', 'give' ), |
|
977 | + esc_html__('Form %s not found.', 'give'), |
|
978 | 978 | $form |
979 | 979 | ); |
980 | 980 | |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @return array Array of post data to return back in the API |
996 | 996 | */ |
997 | - private function get_form_data( $form_info ) { |
|
997 | + private function get_form_data($form_info) { |
|
998 | 998 | |
999 | 999 | $form = array(); |
1000 | 1000 | |
@@ -1004,50 +1004,50 @@ discard block |
||
1004 | 1004 | $form['info']['create_date'] = $form_info->post_date; |
1005 | 1005 | $form['info']['modified_date'] = $form_info->post_modified; |
1006 | 1006 | $form['info']['status'] = $form_info->post_status; |
1007 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1008 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1009 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1007 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1008 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1009 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1010 | 1010 | |
1011 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
1012 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1013 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1011 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
1012 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1013 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1014 | 1014 | } |
1015 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
1016 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1015 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
1016 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1020 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1021 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1022 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1023 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1019 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1020 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1021 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1022 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1023 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | $counter = 0; |
1027 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1028 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1029 | - $counter ++; |
|
1027 | + if (give_has_variable_prices($form_info->ID)) { |
|
1028 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1029 | + $counter++; |
|
1030 | 1030 | // muli-level item |
1031 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1032 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1031 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1032 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1033 | 1033 | |
1034 | 1034 | } |
1035 | 1035 | } else { |
1036 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1036 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1039 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1040 | 1040 | |
1041 | 1041 | /** |
1042 | 1042 | * Fires when generating API sensitive data. |
1043 | 1043 | * |
1044 | 1044 | * @since 1.1 |
1045 | 1045 | */ |
1046 | - do_action( 'give_api_sensitive_data' ); |
|
1046 | + do_action('give_api_sensitive_data'); |
|
1047 | 1047 | |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1050 | + return apply_filters('give_api_forms_form', $form); |
|
1051 | 1051 | |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | * |
1063 | 1063 | * @return array |
1064 | 1064 | */ |
1065 | - public function get_stats( $args = array() ) { |
|
1065 | + public function get_stats($args = array()) { |
|
1066 | 1066 | $defaults = array( |
1067 | 1067 | 'type' => null, |
1068 | 1068 | 'form' => null, |
@@ -1071,9 +1071,9 @@ discard block |
||
1071 | 1071 | 'enddate' => null, |
1072 | 1072 | ); |
1073 | 1073 | |
1074 | - $args = wp_parse_args( $args, $defaults ); |
|
1074 | + $args = wp_parse_args($args, $defaults); |
|
1075 | 1075 | |
1076 | - $dates = $this->get_dates( $args ); |
|
1076 | + $dates = $this->get_dates($args); |
|
1077 | 1077 | |
1078 | 1078 | $stats = array(); |
1079 | 1079 | $earnings = array( |
@@ -1084,40 +1084,40 @@ discard block |
||
1084 | 1084 | ); |
1085 | 1085 | $error = array(); |
1086 | 1086 | |
1087 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1087 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1088 | 1088 | return $stats; |
1089 | 1089 | } |
1090 | 1090 | |
1091 | - if ( $args['type'] == 'donations' ) { |
|
1091 | + if ($args['type'] == 'donations') { |
|
1092 | 1092 | |
1093 | - if ( $args['form'] == null ) { |
|
1094 | - if ( $args['date'] == null ) { |
|
1093 | + if ($args['form'] == null) { |
|
1094 | + if ($args['date'] == null) { |
|
1095 | 1095 | $sales = $this->get_default_sales_stats(); |
1096 | - } elseif ( $args['date'] === 'range' ) { |
|
1096 | + } elseif ($args['date'] === 'range') { |
|
1097 | 1097 | // Return sales for a date range |
1098 | 1098 | // Ensure the end date is later than the start date |
1099 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1100 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1099 | + if ($args['enddate'] < $args['startdate']) { |
|
1100 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Ensure both the start and end date are specified |
1104 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1105 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1104 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1105 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $total = 0; |
1109 | 1109 | |
1110 | 1110 | // Loop through the years |
1111 | 1111 | $y = $dates['year']; |
1112 | - while ( $y <= $dates['year_end'] ) : |
|
1112 | + while ($y <= $dates['year_end']) : |
|
1113 | 1113 | |
1114 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1114 | + if ($dates['year'] == $dates['year_end']) { |
|
1115 | 1115 | $month_start = $dates['m_start']; |
1116 | 1116 | $month_end = $dates['m_end']; |
1117 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1117 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1118 | 1118 | $month_start = $dates['m_start']; |
1119 | 1119 | $month_end = 12; |
1120 | - } elseif ( $y == $dates['year_end'] ) { |
|
1120 | + } elseif ($y == $dates['year_end']) { |
|
1121 | 1121 | $month_start = 1; |
1122 | 1122 | $month_end = $dates['m_end']; |
1123 | 1123 | } else { |
@@ -1126,112 +1126,112 @@ discard block |
||
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | $i = $month_start; |
1129 | - while ( $i <= $month_end ) : |
|
1129 | + while ($i <= $month_end) : |
|
1130 | 1130 | |
1131 | - if ( $i == $dates['m_start'] ) { |
|
1131 | + if ($i == $dates['m_start']) { |
|
1132 | 1132 | $d = $dates['day_start']; |
1133 | 1133 | } else { |
1134 | 1134 | $d = 1; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if ( $i == $dates['m_end'] ) { |
|
1137 | + if ($i == $dates['m_end']) { |
|
1138 | 1138 | $num_of_days = $dates['day_end']; |
1139 | 1139 | } else { |
1140 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1140 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - while ( $d <= $num_of_days ) : |
|
1144 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1145 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1146 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1147 | - $sales['sales'][ $date_key ] = 0; |
|
1143 | + while ($d <= $num_of_days) : |
|
1144 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1145 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1146 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1147 | + $sales['sales'][$date_key] = 0; |
|
1148 | 1148 | } |
1149 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1149 | + $sales['sales'][$date_key] += $sale_count; |
|
1150 | 1150 | $total += $sale_count; |
1151 | - $d ++; |
|
1151 | + $d++; |
|
1152 | 1152 | endwhile; |
1153 | - $i ++; |
|
1153 | + $i++; |
|
1154 | 1154 | endwhile; |
1155 | 1155 | |
1156 | - $y ++; |
|
1156 | + $y++; |
|
1157 | 1157 | endwhile; |
1158 | 1158 | |
1159 | 1159 | $sales['totals'] = $total; |
1160 | 1160 | } else { |
1161 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1161 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1162 | 1162 | $sales_count = 0; |
1163 | 1163 | |
1164 | 1164 | // Loop through the months |
1165 | 1165 | $month = $dates['m_start']; |
1166 | 1166 | |
1167 | - while ( $month <= $dates['m_end'] ) : |
|
1168 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1169 | - $month ++; |
|
1167 | + while ($month <= $dates['m_end']) : |
|
1168 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1169 | + $month++; |
|
1170 | 1170 | endwhile; |
1171 | 1171 | |
1172 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1172 | + $sales['donations'][$args['date']] = $sales_count; |
|
1173 | 1173 | } else { |
1174 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1174 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1175 | 1175 | } |
1176 | 1176 | } |
1177 | - } elseif ( $args['form'] == 'all' ) { |
|
1178 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1177 | + } elseif ($args['form'] == 'all') { |
|
1178 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1179 | 1179 | $i = 0; |
1180 | - foreach ( $forms as $form_info ) { |
|
1181 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1182 | - $i ++; |
|
1180 | + foreach ($forms as $form_info) { |
|
1181 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1182 | + $i++; |
|
1183 | 1183 | } |
1184 | 1184 | } else { |
1185 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1186 | - $form_info = get_post( $args['form'] ); |
|
1187 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1185 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1186 | + $form_info = get_post($args['form']); |
|
1187 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1188 | 1188 | } else { |
1189 | 1189 | $error['error'] = sprintf( |
1190 | 1190 | /* translators: %s: form */ |
1191 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1191 | + esc_html__('Form %s not found.', 'give'), |
|
1192 | 1192 | $args['form'] |
1193 | 1193 | ); |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( ! empty( $error ) ) { |
|
1197 | + if ( ! empty($error)) { |
|
1198 | 1198 | return $error; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | return $sales; |
1202 | 1202 | |
1203 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1204 | - if ( $args['form'] == null ) { |
|
1205 | - if ( $args['date'] == null ) { |
|
1203 | + } elseif ($args['type'] == 'earnings') { |
|
1204 | + if ($args['form'] == null) { |
|
1205 | + if ($args['date'] == null) { |
|
1206 | 1206 | $earnings = $this->get_default_earnings_stats(); |
1207 | - } elseif ( $args['date'] === 'range' ) { |
|
1207 | + } elseif ($args['date'] === 'range') { |
|
1208 | 1208 | // Return sales for a date range |
1209 | 1209 | // Ensure the end date is later than the start date |
1210 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1211 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1210 | + if ($args['enddate'] < $args['startdate']) { |
|
1211 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Ensure both the start and end date are specified |
1215 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1216 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1215 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1216 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | $total = (float) 0.00; |
1220 | 1220 | |
1221 | 1221 | // Loop through the years |
1222 | 1222 | $y = $dates['year']; |
1223 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1223 | + if ( ! isset($earnings['earnings'])) { |
|
1224 | 1224 | $earnings['earnings'] = array(); |
1225 | 1225 | } |
1226 | - while ( $y <= $dates['year_end'] ) : |
|
1226 | + while ($y <= $dates['year_end']) : |
|
1227 | 1227 | |
1228 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1228 | + if ($dates['year'] == $dates['year_end']) { |
|
1229 | 1229 | $month_start = $dates['m_start']; |
1230 | 1230 | $month_end = $dates['m_end']; |
1231 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1231 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1232 | 1232 | $month_start = $dates['m_start']; |
1233 | 1233 | $month_end = 12; |
1234 | - } elseif ( $y == $dates['year_end'] ) { |
|
1234 | + } elseif ($y == $dates['year_end']) { |
|
1235 | 1235 | $month_start = 1; |
1236 | 1236 | $month_end = $dates['m_end']; |
1237 | 1237 | } else { |
@@ -1240,92 +1240,92 @@ discard block |
||
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | $i = $month_start; |
1243 | - while ( $i <= $month_end ) : |
|
1243 | + while ($i <= $month_end) : |
|
1244 | 1244 | |
1245 | - if ( $i == $dates['m_start'] ) { |
|
1245 | + if ($i == $dates['m_start']) { |
|
1246 | 1246 | $d = $dates['day_start']; |
1247 | 1247 | } else { |
1248 | 1248 | $d = 1; |
1249 | 1249 | } |
1250 | 1250 | |
1251 | - if ( $i == $dates['m_end'] ) { |
|
1251 | + if ($i == $dates['m_end']) { |
|
1252 | 1252 | $num_of_days = $dates['day_end']; |
1253 | 1253 | } else { |
1254 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1254 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | - while ( $d <= $num_of_days ) : |
|
1258 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1259 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1260 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1261 | - $earnings['earnings'][ $date_key ] = 0; |
|
1257 | + while ($d <= $num_of_days) : |
|
1258 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1259 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1260 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1261 | + $earnings['earnings'][$date_key] = 0; |
|
1262 | 1262 | } |
1263 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1263 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1264 | 1264 | $total += $earnings_stat; |
1265 | - $d ++; |
|
1265 | + $d++; |
|
1266 | 1266 | endwhile; |
1267 | 1267 | |
1268 | - $i ++; |
|
1268 | + $i++; |
|
1269 | 1269 | endwhile; |
1270 | 1270 | |
1271 | - $y ++; |
|
1271 | + $y++; |
|
1272 | 1272 | endwhile; |
1273 | 1273 | |
1274 | 1274 | $earnings['totals'] = $total; |
1275 | 1275 | } else { |
1276 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1276 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1277 | 1277 | $earnings_count = (float) 0.00; |
1278 | 1278 | |
1279 | 1279 | // Loop through the months |
1280 | 1280 | $month = $dates['m_start']; |
1281 | 1281 | |
1282 | - while ( $month <= $dates['m_end'] ) : |
|
1283 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1284 | - $month ++; |
|
1282 | + while ($month <= $dates['m_end']) : |
|
1283 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1284 | + $month++; |
|
1285 | 1285 | endwhile; |
1286 | 1286 | |
1287 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1287 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1288 | 1288 | } else { |
1289 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1289 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | - } elseif ( $args['form'] == 'all' ) { |
|
1293 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1292 | + } elseif ($args['form'] == 'all') { |
|
1293 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1294 | 1294 | |
1295 | 1295 | $i = 0; |
1296 | - foreach ( $forms as $form_info ) { |
|
1297 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1298 | - $i ++; |
|
1296 | + foreach ($forms as $form_info) { |
|
1297 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1298 | + $i++; |
|
1299 | 1299 | } |
1300 | 1300 | } else { |
1301 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1302 | - $form_info = get_post( $args['form'] ); |
|
1303 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1301 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1302 | + $form_info = get_post($args['form']); |
|
1303 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1304 | 1304 | } else { |
1305 | 1305 | $error['error'] = sprintf( |
1306 | 1306 | /* translators: %s: form */ |
1307 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1307 | + esc_html__('Form %s not found.', 'give'), |
|
1308 | 1308 | $args['form'] |
1309 | 1309 | ); |
1310 | 1310 | } |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( ! empty( $error ) ) { |
|
1313 | + if ( ! empty($error)) { |
|
1314 | 1314 | return $error; |
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $earnings; |
1318 | - } elseif ( $args['type'] == 'donors' ) { |
|
1318 | + } elseif ($args['type'] == 'donors') { |
|
1319 | 1319 | $customers = new Give_DB_Customers(); |
1320 | 1320 | $stats['donations']['total_donors'] = $customers->count(); |
1321 | 1321 | |
1322 | 1322 | return $stats; |
1323 | 1323 | |
1324 | - } elseif ( empty( $args['type'] ) ) { |
|
1325 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1326 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1324 | + } elseif (empty($args['type'])) { |
|
1325 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1326 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1327 | 1327 | |
1328 | - return array( 'stats' => $stats ); |
|
1328 | + return array('stats' => $stats); |
|
1329 | 1329 | } |
1330 | 1330 | } |
1331 | 1331 | |
@@ -1341,18 +1341,18 @@ discard block |
||
1341 | 1341 | |
1342 | 1342 | $sales = array(); |
1343 | 1343 | |
1344 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1344 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1345 | 1345 | return $sales; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1348 | + if (isset($wp_query->query_vars['id'])) { |
|
1349 | 1349 | $query = array(); |
1350 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1351 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1350 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1351 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1352 | 1352 | $query = array(); |
1353 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1354 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1355 | - $args = array( |
|
1353 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1354 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1355 | + $args = array( |
|
1356 | 1356 | 'fields' => 'ids', |
1357 | 1357 | 'meta_key' => '_give_payment_user_email', |
1358 | 1358 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1360,7 +1360,7 @@ discard block |
||
1360 | 1360 | 'page' => $this->get_paged(), |
1361 | 1361 | 'status' => 'publish', |
1362 | 1362 | ); |
1363 | - $query = give_get_payments( $args ); |
|
1363 | + $query = give_get_payments($args); |
|
1364 | 1364 | } else { |
1365 | 1365 | $args = array( |
1366 | 1366 | 'fields' => 'ids', |
@@ -1368,14 +1368,14 @@ discard block |
||
1368 | 1368 | 'page' => $this->get_paged(), |
1369 | 1369 | 'status' => 'publish', |
1370 | 1370 | ); |
1371 | - $query = give_get_payments( $args ); |
|
1371 | + $query = give_get_payments($args); |
|
1372 | 1372 | } |
1373 | - if ( $query ) { |
|
1373 | + if ($query) { |
|
1374 | 1374 | $i = 0; |
1375 | - foreach ( $query as $payment ) { |
|
1375 | + foreach ($query as $payment) { |
|
1376 | 1376 | |
1377 | - if ( is_numeric( $payment ) ) { |
|
1378 | - $payment = new Give_Payment( $payment ); |
|
1377 | + if (is_numeric($payment)) { |
|
1378 | + $payment = new Give_Payment($payment); |
|
1379 | 1379 | $payment_meta = $payment->get_meta(); |
1380 | 1380 | $user_info = $payment->user_info; |
1381 | 1381 | } else { |
@@ -1385,40 +1385,40 @@ discard block |
||
1385 | 1385 | $payment_meta = $payment->get_meta(); |
1386 | 1386 | $user_info = $payment->user_info; |
1387 | 1387 | |
1388 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1389 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1390 | - |
|
1391 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1392 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1393 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1394 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1395 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1396 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1397 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1398 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1399 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1400 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1401 | - |
|
1402 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1404 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1405 | - |
|
1406 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1407 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1408 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1409 | - |
|
1410 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1411 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1412 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1413 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1414 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1415 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1388 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1389 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1390 | + |
|
1391 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1392 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1393 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1394 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1395 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1396 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1397 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1398 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1399 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1400 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1401 | + |
|
1402 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1403 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1404 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1405 | + |
|
1406 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1407 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1408 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1409 | + |
|
1410 | + if (give_has_variable_prices($form_id)) { |
|
1411 | + if (isset($payment_meta['price_id'])) { |
|
1412 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1413 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1414 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1415 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1416 | 1416 | |
1417 | 1417 | } |
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | // Add custom meta to API |
1421 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1421 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1422 | 1422 | |
1423 | 1423 | $exceptions = array( |
1424 | 1424 | 'form_title', |
@@ -1431,19 +1431,19 @@ discard block |
||
1431 | 1431 | ); |
1432 | 1432 | |
1433 | 1433 | // Don't clutter up results with dupes |
1434 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1434 | + if (in_array($meta_key, $exceptions)) { |
|
1435 | 1435 | continue; |
1436 | 1436 | } |
1437 | 1437 | |
1438 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1438 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1439 | 1439 | |
1440 | 1440 | } |
1441 | 1441 | |
1442 | - $i ++; |
|
1442 | + $i++; |
|
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1446 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | /** |
@@ -1459,9 +1459,9 @@ discard block |
||
1459 | 1459 | public function get_output_format() { |
1460 | 1460 | global $wp_query; |
1461 | 1461 | |
1462 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1462 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1463 | 1463 | |
1464 | - return apply_filters( 'give_api_output_format', $format ); |
|
1464 | + return apply_filters('give_api_output_format', $format); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | 1467 | |
@@ -1478,8 +1478,8 @@ discard block |
||
1478 | 1478 | * |
1479 | 1479 | * @return void |
1480 | 1480 | */ |
1481 | - private function log_request( $data = array() ) { |
|
1482 | - if ( ! $this->log_requests ) { |
|
1481 | + private function log_request($data = array()) { |
|
1482 | + if ( ! $this->log_requests) { |
|
1483 | 1483 | return; |
1484 | 1484 | } |
1485 | 1485 | |
@@ -1495,36 +1495,36 @@ discard block |
||
1495 | 1495 | |
1496 | 1496 | $query = array( |
1497 | 1497 | 'give-api' => $wp_query->query_vars['give-api'], |
1498 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1499 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1500 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1501 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1502 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1503 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1504 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1505 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1506 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1507 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1508 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1509 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1498 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1499 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1500 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1501 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1502 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1503 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1504 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1505 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1506 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1507 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1508 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1509 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1510 | 1510 | ); |
1511 | 1511 | |
1512 | 1512 | $log_data = array( |
1513 | 1513 | 'log_type' => 'api_request', |
1514 | - 'post_excerpt' => http_build_query( $query ), |
|
1515 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1514 | + 'post_excerpt' => http_build_query($query), |
|
1515 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1516 | 1516 | ); |
1517 | 1517 | |
1518 | 1518 | $log_meta = array( |
1519 | 1519 | 'request_ip' => give_get_ip(), |
1520 | 1520 | 'user' => $this->user_id, |
1521 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1522 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1521 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1522 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1523 | 1523 | 'time' => $data['request_speed'], |
1524 | 1524 | 'version' => $this->get_queried_version(), |
1525 | 1525 | ); |
1526 | 1526 | |
1527 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1527 | + $give_logs->insert_log($log_data, $log_meta); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | * |
1549 | 1549 | * @param int $status_code |
1550 | 1550 | */ |
1551 | - public function output( $status_code = 200 ) { |
|
1551 | + public function output($status_code = 200) { |
|
1552 | 1552 | /** |
1553 | 1553 | * @var WP_Query $wp_query |
1554 | 1554 | */ |
@@ -1556,7 +1556,7 @@ discard block |
||
1556 | 1556 | |
1557 | 1557 | $format = $this->get_output_format(); |
1558 | 1558 | |
1559 | - status_header( $status_code ); |
|
1559 | + status_header($status_code); |
|
1560 | 1560 | |
1561 | 1561 | /** |
1562 | 1562 | * Fires before outputing the API. |
@@ -1567,25 +1567,25 @@ discard block |
||
1567 | 1567 | * @param Give_API $this The Give_API object. |
1568 | 1568 | * @param string $format Output format, XML or JSON. Default is JSON. |
1569 | 1569 | */ |
1570 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1570 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1571 | 1571 | |
1572 | - switch ( $format ) : |
|
1572 | + switch ($format) : |
|
1573 | 1573 | |
1574 | 1574 | case 'xml' : |
1575 | 1575 | |
1576 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1577 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1576 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1577 | + $xml = Array2XML::createXML('give', $this->data); |
|
1578 | 1578 | echo $xml->saveXML(); |
1579 | 1579 | |
1580 | 1580 | break; |
1581 | 1581 | |
1582 | 1582 | case 'json' : |
1583 | 1583 | |
1584 | - header( 'Content-Type: application/json' ); |
|
1585 | - if ( ! empty( $this->pretty_print ) ) { |
|
1586 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1584 | + header('Content-Type: application/json'); |
|
1585 | + if ( ! empty($this->pretty_print)) { |
|
1586 | + echo json_encode($this->data, $this->pretty_print); |
|
1587 | 1587 | } else { |
1588 | - echo json_encode( $this->data ); |
|
1588 | + echo json_encode($this->data); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | break; |
@@ -1600,7 +1600,7 @@ discard block |
||
1600 | 1600 | * @param array $data Response data to return. |
1601 | 1601 | * @param Give_API $this The Give_API object. |
1602 | 1602 | */ |
1603 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
1603 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
1604 | 1604 | |
1605 | 1605 | break; |
1606 | 1606 | |
@@ -1615,7 +1615,7 @@ discard block |
||
1615 | 1615 | * @param Give_API $this The Give_API object. |
1616 | 1616 | * @param string $format Output format, XML or JSON. Default is JSON. |
1617 | 1617 | */ |
1618 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1618 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1619 | 1619 | |
1620 | 1620 | give_die(); |
1621 | 1621 | } |
@@ -1632,40 +1632,40 @@ discard block |
||
1632 | 1632 | * |
1633 | 1633 | * @return void |
1634 | 1634 | */ |
1635 | - function user_key_field( $user ) { |
|
1635 | + function user_key_field($user) { |
|
1636 | 1636 | |
1637 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1638 | - $user = get_userdata( $user->ID ); |
|
1637 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1638 | + $user = get_userdata($user->ID); |
|
1639 | 1639 | ?> |
1640 | 1640 | <table class="form-table"> |
1641 | 1641 | <tbody> |
1642 | 1642 | <tr> |
1643 | 1643 | <th> |
1644 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1644 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1645 | 1645 | </th> |
1646 | 1646 | <td> |
1647 | 1647 | <?php |
1648 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1649 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1648 | + $public_key = $this->get_user_public_key($user->ID); |
|
1649 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1650 | 1650 | ?> |
1651 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1651 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1652 | 1652 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1653 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1653 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1654 | 1654 | <?php } else { ?> |
1655 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> |
|
1655 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> |
|
1656 | 1656 | </strong> |
1657 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1657 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1658 | 1658 | <br/> |
1659 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> |
|
1659 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> |
|
1660 | 1660 | </strong> |
1661 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1661 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1662 | 1662 | <br/> |
1663 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> |
|
1663 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> |
|
1664 | 1664 | </strong> |
1665 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1665 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1666 | 1666 | <br/> |
1667 | 1667 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1668 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1668 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1669 | 1669 | <?php } ?> |
1670 | 1670 | </td> |
1671 | 1671 | </tr> |
@@ -1684,69 +1684,69 @@ discard block |
||
1684 | 1684 | * |
1685 | 1685 | * @return void |
1686 | 1686 | */ |
1687 | - public function process_api_key( $args ) { |
|
1687 | + public function process_api_key($args) { |
|
1688 | 1688 | |
1689 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1689 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1690 | 1690 | |
1691 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1691 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
1692 | 1692 | |
1693 | 1693 | } |
1694 | 1694 | |
1695 | - if ( empty( $args['user_id'] ) ) { |
|
1696 | - wp_die( esc_html__( 'User ID Required.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1695 | + if (empty($args['user_id'])) { |
|
1696 | + wp_die(esc_html__('User ID Required.', 'give'), esc_html__('Error', 'give'), array('response' => 401)); |
|
1697 | 1697 | } |
1698 | 1698 | |
1699 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1700 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1699 | + if (is_numeric($args['user_id'])) { |
|
1700 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1701 | 1701 | } else { |
1702 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1702 | + $userdata = get_user_by('login', $args['user_id']); |
|
1703 | 1703 | $user_id = $userdata->ID; |
1704 | 1704 | } |
1705 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1705 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1706 | 1706 | |
1707 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1707 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1708 | 1708 | wp_die( |
1709 | 1709 | sprintf( |
1710 | 1710 | /* translators: %s: process */ |
1711 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1711 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1712 | 1712 | $process |
1713 | 1713 | ), |
1714 | - esc_html__( 'Error', 'give' ), |
|
1715 | - array( 'response' => 403 ) |
|
1714 | + esc_html__('Error', 'give'), |
|
1715 | + array('response' => 403) |
|
1716 | 1716 | ); |
1717 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1717 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1718 | 1718 | wp_die( |
1719 | 1719 | sprintf( |
1720 | 1720 | /* translators: %s: process */ |
1721 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1721 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1722 | 1722 | $process |
1723 | 1723 | ), |
1724 | - esc_html__( 'Error', 'give' ), |
|
1725 | - array( 'response' => 403 ) |
|
1724 | + esc_html__('Error', 'give'), |
|
1725 | + array('response' => 403) |
|
1726 | 1726 | ); |
1727 | 1727 | } |
1728 | 1728 | |
1729 | - switch ( $process ) { |
|
1729 | + switch ($process) { |
|
1730 | 1730 | case 'generate': |
1731 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1732 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1733 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1731 | + if ($this->generate_api_key($user_id)) { |
|
1732 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1733 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1734 | 1734 | exit(); |
1735 | 1735 | } else { |
1736 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1736 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1737 | 1737 | exit(); |
1738 | 1738 | } |
1739 | 1739 | break; |
1740 | 1740 | case 'regenerate': |
1741 | - $this->generate_api_key( $user_id, true ); |
|
1742 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1743 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1741 | + $this->generate_api_key($user_id, true); |
|
1742 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1743 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1744 | 1744 | exit(); |
1745 | 1745 | break; |
1746 | 1746 | case 'revoke': |
1747 | - $this->revoke_api_key( $user_id ); |
|
1748 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
1749 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
1747 | + $this->revoke_api_key($user_id); |
|
1748 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
1749 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
1750 | 1750 | exit(); |
1751 | 1751 | break; |
1752 | 1752 | default; |
@@ -1765,34 +1765,34 @@ discard block |
||
1765 | 1765 | * |
1766 | 1766 | * @return boolean True if (re)generated succesfully, false otherwise. |
1767 | 1767 | */ |
1768 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1768 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1769 | 1769 | |
1770 | - if ( empty( $user_id ) ) { |
|
1770 | + if (empty($user_id)) { |
|
1771 | 1771 | return false; |
1772 | 1772 | } |
1773 | 1773 | |
1774 | - $user = get_userdata( $user_id ); |
|
1774 | + $user = get_userdata($user_id); |
|
1775 | 1775 | |
1776 | - if ( ! $user ) { |
|
1776 | + if ( ! $user) { |
|
1777 | 1777 | return false; |
1778 | 1778 | } |
1779 | 1779 | |
1780 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1781 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1780 | + $public_key = $this->get_user_public_key($user_id); |
|
1781 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1782 | 1782 | |
1783 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1784 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1785 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1783 | + if (empty($public_key) || $regenerate == true) { |
|
1784 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1785 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1786 | 1786 | } else { |
1787 | 1787 | return false; |
1788 | 1788 | } |
1789 | 1789 | |
1790 | - if ( $regenerate == true ) { |
|
1791 | - $this->revoke_api_key( $user->ID ); |
|
1790 | + if ($regenerate == true) { |
|
1791 | + $this->revoke_api_key($user->ID); |
|
1792 | 1792 | } |
1793 | 1793 | |
1794 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1795 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1794 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1795 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1796 | 1796 | |
1797 | 1797 | return true; |
1798 | 1798 | } |
@@ -1807,26 +1807,26 @@ discard block |
||
1807 | 1807 | * |
1808 | 1808 | * @return bool |
1809 | 1809 | */ |
1810 | - public function revoke_api_key( $user_id = 0 ) { |
|
1810 | + public function revoke_api_key($user_id = 0) { |
|
1811 | 1811 | |
1812 | - if ( empty( $user_id ) ) { |
|
1812 | + if (empty($user_id)) { |
|
1813 | 1813 | return false; |
1814 | 1814 | } |
1815 | 1815 | |
1816 | - $user = get_userdata( $user_id ); |
|
1816 | + $user = get_userdata($user_id); |
|
1817 | 1817 | |
1818 | - if ( ! $user ) { |
|
1818 | + if ( ! $user) { |
|
1819 | 1819 | return false; |
1820 | 1820 | } |
1821 | 1821 | |
1822 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1823 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1824 | - if ( ! empty( $public_key ) ) { |
|
1825 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
1826 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
1827 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
1828 | - delete_user_meta( $user_id, $public_key ); |
|
1829 | - delete_user_meta( $user_id, $secret_key ); |
|
1822 | + $public_key = $this->get_user_public_key($user_id); |
|
1823 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1824 | + if ( ! empty($public_key)) { |
|
1825 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
1826 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
1827 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
1828 | + delete_user_meta($user_id, $public_key); |
|
1829 | + delete_user_meta($user_id, $secret_key); |
|
1830 | 1830 | } else { |
1831 | 1831 | return false; |
1832 | 1832 | } |
@@ -1851,22 +1851,22 @@ discard block |
||
1851 | 1851 | * |
1852 | 1852 | * @return void |
1853 | 1853 | */ |
1854 | - public function update_key( $user_id ) { |
|
1855 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1854 | + public function update_key($user_id) { |
|
1855 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1856 | 1856 | |
1857 | - $user = get_userdata( $user_id ); |
|
1857 | + $user = get_userdata($user_id); |
|
1858 | 1858 | |
1859 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1860 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1859 | + $public_key = $this->get_user_public_key($user_id); |
|
1860 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1861 | 1861 | |
1862 | - if ( empty( $public_key ) ) { |
|
1863 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1864 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1862 | + if (empty($public_key)) { |
|
1863 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1864 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1865 | 1865 | |
1866 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1867 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1866 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1867 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1868 | 1868 | } else { |
1869 | - $this->revoke_api_key( $user_id ); |
|
1869 | + $this->revoke_api_key($user_id); |
|
1870 | 1870 | } |
1871 | 1871 | } |
1872 | 1872 | } |
@@ -1881,9 +1881,9 @@ discard block |
||
1881 | 1881 | * |
1882 | 1882 | * @return string |
1883 | 1883 | */ |
1884 | - private function generate_public_key( $user_email = '' ) { |
|
1885 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1886 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1884 | + private function generate_public_key($user_email = '') { |
|
1885 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1886 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1887 | 1887 | |
1888 | 1888 | return $public; |
1889 | 1889 | } |
@@ -1898,9 +1898,9 @@ discard block |
||
1898 | 1898 | * |
1899 | 1899 | * @return string |
1900 | 1900 | */ |
1901 | - private function generate_private_key( $user_id = 0 ) { |
|
1902 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1903 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1901 | + private function generate_private_key($user_id = 0) { |
|
1902 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1903 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1904 | 1904 | |
1905 | 1905 | return $secret; |
1906 | 1906 | } |
@@ -1915,8 +1915,8 @@ discard block |
||
1915 | 1915 | * |
1916 | 1916 | * @return string |
1917 | 1917 | */ |
1918 | - public function get_token( $user_id = 0 ) { |
|
1919 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1918 | + public function get_token($user_id = 0) { |
|
1919 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1920 | 1920 | } |
1921 | 1921 | |
1922 | 1922 | /** |
@@ -1930,9 +1930,9 @@ discard block |
||
1930 | 1930 | |
1931 | 1931 | // Default sales return |
1932 | 1932 | $sales = array(); |
1933 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1934 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1935 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1933 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1934 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1935 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1936 | 1936 | $sales['donations']['totals'] = give_get_total_sales(); |
1937 | 1937 | |
1938 | 1938 | return $sales; |
@@ -1949,9 +1949,9 @@ discard block |
||
1949 | 1949 | |
1950 | 1950 | // Default earnings return |
1951 | 1951 | $earnings = array(); |
1952 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1953 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1954 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1952 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1953 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1954 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1955 | 1955 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1956 | 1956 | |
1957 | 1957 | return $earnings; |
@@ -1971,25 +1971,25 @@ discard block |
||
1971 | 1971 | * |
1972 | 1972 | * @return string The API key/secret for the user supplied |
1973 | 1973 | */ |
1974 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1974 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1975 | 1975 | |
1976 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1976 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1977 | 1977 | return $check; |
1978 | 1978 | } |
1979 | 1979 | |
1980 | 1980 | $return = $check; |
1981 | 1981 | |
1982 | - switch ( $meta_key ) { |
|
1982 | + switch ($meta_key) { |
|
1983 | 1983 | case 'give_user_public_key': |
1984 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1984 | + $return = Give()->api->get_user_public_key($object_id); |
|
1985 | 1985 | break; |
1986 | 1986 | case 'give_user_secret_key': |
1987 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1987 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1988 | 1988 | break; |
1989 | 1989 | } |
1990 | 1990 | |
1991 | - if ( ! $single ) { |
|
1992 | - $return = array( $return ); |
|
1991 | + if ( ! $single) { |
|
1992 | + $return = array($return); |
|
1993 | 1993 | } |
1994 | 1994 | |
1995 | 1995 | return $return; |