@@ -6,16 +6,16 @@ discard block |
||
| 6 | 6 | * @version 1.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } // Exit if accessed directly. |
| 12 | 12 | |
| 13 | 13 | // For gmail compatibility, including CSS styles in head/body are stripped out therefore styles need to be inline. These variables contain rules which are added to the template inline. !important; is a gmail hack to prevent styles being stripped if it doesn't like something. |
| 14 | -$body = " |
|
| 14 | +$body = " |
|
| 15 | 15 | background-color: #f6f6f6; |
| 16 | 16 | font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; |
| 17 | 17 | "; |
| 18 | -$wrapper = " |
|
| 18 | +$wrapper = " |
|
| 19 | 19 | width:100%; |
| 20 | 20 | -webkit-text-size-adjust:none !important; |
| 21 | 21 | margin:0; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | border-radius:3px !important; |
| 30 | 30 | padding: 20px; |
| 31 | 31 | "; |
| 32 | -$template_header = " |
|
| 32 | +$template_header = " |
|
| 33 | 33 | color: #00000; |
| 34 | 34 | border-top-left-radius:3px !important; |
| 35 | 35 | border-top-right-radius:3px !important; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | text-align: center; |
| 40 | 40 | vertical-align:middle; |
| 41 | 41 | "; |
| 42 | -$body_content = " |
|
| 42 | +$body_content = " |
|
| 43 | 43 | border-radius:3px !important; |
| 44 | 44 | font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; |
| 45 | 45 | "; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | line-height:150%; |
| 51 | 51 | text-align:left; |
| 52 | 52 | "; |
| 53 | -$header_content_h1 = " |
|
| 53 | +$header_content_h1 = " |
|
| 54 | 54 | color: #000000; |
| 55 | 55 | margin:0; |
| 56 | 56 | padding: 28px 24px; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | <html> |
| 66 | 66 | <head> |
| 67 | 67 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 68 | - <title><?php echo get_bloginfo( 'name' ); ?></title> |
|
| 68 | + <title><?php echo get_bloginfo('name'); ?></title> |
|
| 69 | 69 | </head> |
| 70 | 70 | <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="<?php echo $body; ?>"> |
| 71 | 71 | <div style="<?php echo $wrapper; ?>"> |
@@ -4,17 +4,17 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | |
| 7 | -if ( ! is_user_logged_in() ) { |
|
| 7 | +if ( ! is_user_logged_in()) { |
|
| 8 | 8 | |
| 9 | - if ( ! empty( $_GET['payment_key'] ) ) { |
|
| 10 | - $give_login_redirect = add_query_arg( 'payment_key', give_clean( $_GET['payment_key'] ) , give_get_history_page_uri() ); |
|
| 9 | + if ( ! empty($_GET['payment_key'])) { |
|
| 10 | + $give_login_redirect = add_query_arg('payment_key', give_clean($_GET['payment_key']), give_get_history_page_uri()); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // Show any error messages after form submission |
| 14 | - Give()->notices->render_frontend_notices( 0 ); ?> |
|
| 14 | + Give()->notices->render_frontend_notices(0); ?> |
|
| 15 | 15 | <form id="give-login-form" class="give-form" action="" method="post"> |
| 16 | 16 | <fieldset> |
| 17 | - <legend><?php _e( 'Log into Your Account', 'give' ); ?></legend> |
|
| 17 | + <legend><?php _e('Log into Your Account', 'give'); ?></legend> |
|
| 18 | 18 | <?php |
| 19 | 19 | /** |
| 20 | 20 | * Fires in the login shortcode, before the login fields. |
@@ -23,27 +23,27 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @since 1.0 |
| 25 | 25 | */ |
| 26 | - do_action( 'give_login_fields_before' ); |
|
| 26 | + do_action('give_login_fields_before'); |
|
| 27 | 27 | ?> |
| 28 | 28 | <div class="give-login-username give-login"> |
| 29 | - <label for="give_user_login"><?php _e( 'Username', 'give' ); ?></label> |
|
| 29 | + <label for="give_user_login"><?php _e('Username', 'give'); ?></label> |
|
| 30 | 30 | <input name="give_user_login" id="give_user_login" class="give-required give-input" type="text" required aria-required="true" /> |
| 31 | 31 | </div> |
| 32 | 32 | |
| 33 | 33 | <div class="give-login-password give-login"> |
| 34 | - <label for="give_user_pass"><?php _e( 'Password', 'give' ); ?></label> |
|
| 34 | + <label for="give_user_pass"><?php _e('Password', 'give'); ?></label> |
|
| 35 | 35 | <input name="give_user_pass" id="give_user_pass" class="give-password give-required give-input" type="password" required aria-required="true" /> |
| 36 | 36 | </div> |
| 37 | 37 | |
| 38 | 38 | <div class="give-login-submit give-login"> |
| 39 | - <input type="hidden" name="give_login_redirect" value="<?php echo esc_url( $give_login_redirect ); ?>" /> |
|
| 40 | - <input type="hidden" name="give_login_nonce" value="<?php echo wp_create_nonce( 'give-login-nonce' ); ?>" /> |
|
| 39 | + <input type="hidden" name="give_login_redirect" value="<?php echo esc_url($give_login_redirect); ?>" /> |
|
| 40 | + <input type="hidden" name="give_login_nonce" value="<?php echo wp_create_nonce('give-login-nonce'); ?>" /> |
|
| 41 | 41 | <input type="hidden" name="give_action" value="user_login" /> |
| 42 | - <input id="give_login_submit" type="submit" class="give_submit" value="<?php _e( 'Log In', 'give' ); ?>" /> |
|
| 42 | + <input id="give_login_submit" type="submit" class="give_submit" value="<?php _e('Log In', 'give'); ?>" /> |
|
| 43 | 43 | </div> |
| 44 | 44 | |
| 45 | 45 | <div class="give-lost-password give-login"> |
| 46 | - <a href="<?php echo wp_lostpassword_url(); ?>"><?php _e( 'Reset Password', 'give' ); ?></a> |
|
| 46 | + <a href="<?php echo wp_lostpassword_url(); ?>"><?php _e('Reset Password', 'give'); ?></a> |
|
| 47 | 47 | </div> |
| 48 | 48 | <?php |
| 49 | 49 | /** |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @since 1.0 |
| 55 | 55 | */ |
| 56 | - do_action( 'give_login_fields_after' ); |
|
| 56 | + do_action('give_login_fields_after'); |
|
| 57 | 57 | ?> |
| 58 | 58 | </fieldset> |
| 59 | 59 | </form> |
| 60 | -<?php } elseif( isset( $_GET['give-login-success'] ) && true === (bool) $_GET['give-login-success'] ) { ?> |
|
| 61 | - <?php Give()->notices->print_frontend_notice( apply_filters('give_successful_login_message', __( 'Login successful. Welcome!', 'give' )), true, 'success' ); ?> |
|
| 60 | +<?php } elseif (isset($_GET['give-login-success']) && true === (bool) $_GET['give-login-success']) { ?> |
|
| 61 | + <?php Give()->notices->print_frontend_notice(apply_filters('give_successful_login_message', __('Login successful. Welcome!', 'give')), true, 'success'); ?> |
|
| 62 | 62 | <?php } else { ?> |
| 63 | - <?php Give()->notices->print_frontend_notice( apply_filters('give_already_logged_in_message', sprintf( __( 'You are already logged in to the site. <a href="%s">Click here</a> to logout.', 'give' ), esc_url( $give_logout_redirect ) ) ), true, 'warning' ); ?> |
|
| 63 | + <?php Give()->notices->print_frontend_notice(apply_filters('give_already_logged_in_message', sprintf(__('You are already logged in to the site. <a href="%s">Click here</a> to logout.', 'give'), esc_url($give_logout_redirect))), true, 'warning'); ?> |
|
| 64 | 64 | <?php } ?> |
| 65 | 65 | \ No newline at end of file |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @uses Give_API::invalid_key() |
| 327 | 327 | * @uses Give_API::invalid_auth() |
| 328 | 328 | * @since 1.1 |
| 329 | - * @return bool |
|
| 329 | + * @return false|null |
|
| 330 | 330 | */ |
| 331 | 331 | private function validate_request() { |
| 332 | 332 | global $wp_query; |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | * |
| 723 | 723 | * @param array $args Arguments to override defaults |
| 724 | 724 | * |
| 725 | - * @return array $dates |
|
| 725 | + * @return integer|null $dates |
|
| 726 | 726 | */ |
| 727 | 727 | public function get_dates( $args = array() ) { |
| 728 | 728 | $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(); |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return mixed |
| 181 | 181 | */ |
| 182 | - public function __call( $name, $arguments ) { |
|
| 182 | + public function __call($name, $arguments) { |
|
| 183 | 183 | $deprecated_function_arr = array( |
| 184 | 184 | 'get_customers', |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | - if ( in_array( $name, $deprecated_function_arr, true ) ) { |
|
| 188 | - switch ( $name ) { |
|
| 187 | + if (in_array($name, $deprecated_function_arr, true)) { |
|
| 188 | + switch ($name) { |
|
| 189 | 189 | case 'get_customers': |
| 190 | - $args = ! empty( $arguments[0] ) ? $arguments[0] : array(); |
|
| 190 | + $args = ! empty($arguments[0]) ? $arguments[0] : array(); |
|
| 191 | 191 | |
| 192 | - return $this->get_donors( $args ); |
|
| 192 | + return $this->get_donors($args); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @since 1.1 |
| 203 | 203 | */ |
| 204 | 204 | public function add_endpoint() { |
| 205 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
| 205 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return string[] $vars New query vars |
| 217 | 217 | */ |
| 218 | - public function query_vars( $vars ) { |
|
| 218 | + public function query_vars($vars) { |
|
| 219 | 219 | |
| 220 | 220 | $vars[] = 'token'; |
| 221 | 221 | $vars[] = 'key'; |
@@ -266,11 +266,11 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function get_default_version() { |
| 268 | 268 | |
| 269 | - $version = get_option( 'give_default_api_version' ); |
|
| 269 | + $version = get_option('give_default_api_version'); |
|
| 270 | 270 | |
| 271 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
| 271 | + if (defined('GIVE_API_VERSION')) { |
|
| 272 | 272 | $version = GIVE_API_VERSION; |
| 273 | - } elseif ( ! $version ) { |
|
| 273 | + } elseif ( ! $version) { |
|
| 274 | 274 | $version = 'v1'; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -291,14 +291,14 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | $version = $wp_query->query_vars['give-api']; |
| 293 | 293 | |
| 294 | - if ( strpos( $version, '/' ) ) { |
|
| 294 | + if (strpos($version, '/')) { |
|
| 295 | 295 | |
| 296 | - $version = explode( '/', $version ); |
|
| 297 | - $version = strtolower( $version[0] ); |
|
| 296 | + $version = explode('/', $version); |
|
| 297 | + $version = strtolower($version[0]); |
|
| 298 | 298 | |
| 299 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
| 299 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
| 300 | 300 | |
| 301 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
| 301 | + if (array_key_exists($version, $this->versions)) { |
|
| 302 | 302 | |
| 303 | 303 | $this->queried_version = $version; |
| 304 | 304 | |
@@ -334,16 +334,16 @@ discard block |
||
| 334 | 334 | $this->override = false; |
| 335 | 335 | |
| 336 | 336 | // Make sure we have both user and api key |
| 337 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] !== 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
| 337 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] !== 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
| 338 | 338 | |
| 339 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
| 339 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
| 340 | 340 | $this->missing_auth(); |
| 341 | 341 | |
| 342 | 342 | return false; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | // Retrieve the user by public API key and ensure they exist |
| 346 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
| 346 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
| 347 | 347 | |
| 348 | 348 | $this->invalid_key(); |
| 349 | 349 | |
@@ -351,11 +351,11 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | } else { |
| 353 | 353 | |
| 354 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
| 355 | - $secret = $this->get_user_secret_key( $user ); |
|
| 356 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
| 354 | + $token = urldecode($wp_query->query_vars['token']); |
|
| 355 | + $secret = $this->get_user_secret_key($user); |
|
| 356 | + $public = urldecode($wp_query->query_vars['key']); |
|
| 357 | 357 | |
| 358 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
| 358 | + if (hash_equals(md5($secret.$public), $token)) { |
|
| 359 | 359 | $this->is_valid_request = true; |
| 360 | 360 | } else { |
| 361 | 361 | $this->invalid_auth(); |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | } |
| 367 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] === 'forms' ) { |
|
| 367 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] === 'forms') { |
|
| 368 | 368 | $this->is_valid_request = true; |
| 369 | - $wp_query->set( 'key', 'public' ); |
|
| 369 | + $wp_query->set('key', 'public'); |
|
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
@@ -382,25 +382,25 @@ discard block |
||
| 382 | 382 | * |
| 383 | 383 | * @return bool if user ID is found, false otherwise |
| 384 | 384 | */ |
| 385 | - public function get_user( $key = '' ) { |
|
| 385 | + public function get_user($key = '') { |
|
| 386 | 386 | global $wpdb, $wp_query; |
| 387 | 387 | |
| 388 | - if ( empty( $key ) ) { |
|
| 389 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
| 388 | + if (empty($key)) { |
|
| 389 | + $key = urldecode($wp_query->query_vars['key']); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ( empty( $key ) ) { |
|
| 392 | + if (empty($key)) { |
|
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - $user = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
|
| 396 | + $user = Give_Cache::get(md5('give_api_user_'.$key), true); |
|
| 397 | 397 | |
| 398 | - if ( false === $user ) { |
|
| 399 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
| 400 | - Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
|
| 398 | + if (false === $user) { |
|
| 399 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
| 400 | + Give_Cache::set(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS, true); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( $user != null ) { |
|
| 403 | + if ($user != null) { |
|
| 404 | 404 | $this->user_id = $user; |
| 405 | 405 | |
| 406 | 406 | return $user; |
@@ -416,19 +416,19 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @return mixed|null|string |
| 418 | 418 | */ |
| 419 | - public function get_user_public_key( $user_id = 0 ) { |
|
| 419 | + public function get_user_public_key($user_id = 0) { |
|
| 420 | 420 | global $wpdb; |
| 421 | 421 | |
| 422 | - if ( empty( $user_id ) ) { |
|
| 422 | + if (empty($user_id)) { |
|
| 423 | 423 | return ''; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
| 427 | - $user_public_key = Give_Cache::get( $cache_key, true ); |
|
| 426 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
| 427 | + $user_public_key = Give_Cache::get($cache_key, true); |
|
| 428 | 428 | |
| 429 | - if ( empty( $user_public_key ) ) { |
|
| 430 | - $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 ) ); |
|
| 431 | - Give_Cache::set( $cache_key, $user_public_key, HOUR_IN_SECONDS, true ); |
|
| 429 | + if (empty($user_public_key)) { |
|
| 430 | + $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)); |
|
| 431 | + Give_Cache::set($cache_key, $user_public_key, HOUR_IN_SECONDS, true); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | return $user_public_key; |
@@ -441,19 +441,19 @@ discard block |
||
| 441 | 441 | * |
| 442 | 442 | * @return mixed|null|string |
| 443 | 443 | */ |
| 444 | - public function get_user_secret_key( $user_id = 0 ) { |
|
| 444 | + public function get_user_secret_key($user_id = 0) { |
|
| 445 | 445 | global $wpdb; |
| 446 | 446 | |
| 447 | - if ( empty( $user_id ) ) { |
|
| 447 | + if (empty($user_id)) { |
|
| 448 | 448 | return ''; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
| 452 | - $user_secret_key = Give_Cache::get( $cache_key, true ); |
|
| 451 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
| 452 | + $user_secret_key = Give_Cache::get($cache_key, true); |
|
| 453 | 453 | |
| 454 | - if ( empty( $user_secret_key ) ) { |
|
| 455 | - $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 ) ); |
|
| 456 | - Give_Cache::set( $cache_key, $user_secret_key, HOUR_IN_SECONDS, true ); |
|
| 454 | + if (empty($user_secret_key)) { |
|
| 455 | + $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)); |
|
| 456 | + Give_Cache::set($cache_key, $user_secret_key, HOUR_IN_SECONDS, true); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | return $user_secret_key; |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | */ |
| 470 | 470 | private function missing_auth() { |
| 471 | 471 | $error = array(); |
| 472 | - $error['error'] = __( 'You must specify both a token and API key.', 'give' ); |
|
| 472 | + $error['error'] = __('You must specify both a token and API key.', 'give'); |
|
| 473 | 473 | |
| 474 | 474 | $this->data = $error; |
| 475 | - $this->output( 401 ); |
|
| 475 | + $this->output(401); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -486,10 +486,10 @@ discard block |
||
| 486 | 486 | */ |
| 487 | 487 | private function invalid_auth() { |
| 488 | 488 | $error = array(); |
| 489 | - $error['error'] = __( 'Your request could not be authenticated.', 'give' ); |
|
| 489 | + $error['error'] = __('Your request could not be authenticated.', 'give'); |
|
| 490 | 490 | |
| 491 | 491 | $this->data = $error; |
| 492 | - $this->output( 403 ); |
|
| 492 | + $this->output(403); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -503,10 +503,10 @@ discard block |
||
| 503 | 503 | */ |
| 504 | 504 | private function invalid_key() { |
| 505 | 505 | $error = array(); |
| 506 | - $error['error'] = __( 'Invalid API key.', 'give' ); |
|
| 506 | + $error['error'] = __('Invalid API key.', 'give'); |
|
| 507 | 507 | |
| 508 | 508 | $this->data = $error; |
| 509 | - $this->output( 403 ); |
|
| 509 | + $this->output(403); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
| 519 | 519 | */ |
| 520 | 520 | private function invalid_version() { |
| 521 | 521 | $error = array(); |
| 522 | - $error['error'] = __( 'Invalid API version.', 'give' ); |
|
| 522 | + $error['error'] = __('Invalid API version.', 'give'); |
|
| 523 | 523 | |
| 524 | 524 | $this->data = $error; |
| 525 | - $this->output( 404 ); |
|
| 525 | + $this->output(404); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -538,10 +538,10 @@ discard block |
||
| 538 | 538 | global $wp_query; |
| 539 | 539 | |
| 540 | 540 | // Start logging how long the request takes for logging |
| 541 | - $before = microtime( true ); |
|
| 541 | + $before = microtime(true); |
|
| 542 | 542 | |
| 543 | 543 | // Check for give-api var. Get out if not present |
| 544 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
| 544 | + if (empty($wp_query->query_vars['give-api'])) { |
|
| 545 | 545 | return; |
| 546 | 546 | } |
| 547 | 547 | |
@@ -555,45 +555,45 @@ discard block |
||
| 555 | 555 | $this->validate_request(); |
| 556 | 556 | |
| 557 | 557 | // Only proceed if no errors have been noted |
| 558 | - if ( ! $this->is_valid_request ) { |
|
| 558 | + if ( ! $this->is_valid_request) { |
|
| 559 | 559 | return; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
| 563 | - define( 'GIVE_DOING_API', true ); |
|
| 562 | + if ( ! defined('GIVE_DOING_API')) { |
|
| 563 | + define('GIVE_DOING_API', true); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | $data = array(); |
| 567 | 567 | $this->routes = new $this->versions[$this->get_queried_version()]; |
| 568 | 568 | $this->routes->validate_request(); |
| 569 | 569 | |
| 570 | - switch ( $this->endpoint ) : |
|
| 570 | + switch ($this->endpoint) : |
|
| 571 | 571 | |
| 572 | 572 | case 'stats' : |
| 573 | 573 | |
| 574 | - $data = $this->routes->get_stats( array( |
|
| 575 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 576 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 577 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 578 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 579 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 580 | - ) ); |
|
| 574 | + $data = $this->routes->get_stats(array( |
|
| 575 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 576 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 577 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 578 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 579 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 580 | + )); |
|
| 581 | 581 | |
| 582 | 582 | break; |
| 583 | 583 | |
| 584 | 584 | case 'forms' : |
| 585 | 585 | |
| 586 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
| 586 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
| 587 | 587 | |
| 588 | - $data = $this->routes->get_forms( $form ); |
|
| 588 | + $data = $this->routes->get_forms($form); |
|
| 589 | 589 | |
| 590 | 590 | break; |
| 591 | 591 | |
| 592 | 592 | case 'donors' : |
| 593 | 593 | |
| 594 | - $donor = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
| 594 | + $donor = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
| 595 | 595 | |
| 596 | - $data = $this->routes->get_donors( $donor ); |
|
| 596 | + $data = $this->routes->get_donors($donor); |
|
| 597 | 597 | |
| 598 | 598 | break; |
| 599 | 599 | |
@@ -606,26 +606,26 @@ discard block |
||
| 606 | 606 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 607 | 607 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 608 | 608 | */ |
| 609 | - $data = $this->routes->get_recent_donations( array( |
|
| 610 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 611 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 612 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 613 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 614 | - ) ); |
|
| 609 | + $data = $this->routes->get_recent_donations(array( |
|
| 610 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 611 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 612 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 613 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 614 | + )); |
|
| 615 | 615 | |
| 616 | 616 | break; |
| 617 | 617 | |
| 618 | 618 | endswitch; |
| 619 | 619 | |
| 620 | 620 | // Allow extensions to setup their own return data |
| 621 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
| 621 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
| 622 | 622 | |
| 623 | - $after = microtime( true ); |
|
| 624 | - $request_time = ( $after - $before ); |
|
| 623 | + $after = microtime(true); |
|
| 624 | + $request_time = ($after - $before); |
|
| 625 | 625 | $this->data['request_speed'] = $request_time; |
| 626 | 626 | |
| 627 | 627 | // Log this API request, if enabled. We log it here because we have access to errors. |
| 628 | - $this->log_request( $this->data ); |
|
| 628 | + $this->log_request($this->data); |
|
| 629 | 629 | |
| 630 | 630 | // Send out data to the output function |
| 631 | 631 | $this->output(); |
@@ -655,25 +655,25 @@ discard block |
||
| 655 | 655 | global $wp_query; |
| 656 | 656 | |
| 657 | 657 | // Whitelist our query options |
| 658 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
| 658 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
| 659 | 659 | 'stats', |
| 660 | 660 | 'forms', |
| 661 | 661 | 'donors', |
| 662 | 662 | 'donations', |
| 663 | - ) ); |
|
| 663 | + )); |
|
| 664 | 664 | |
| 665 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
| 666 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
| 665 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
| 666 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
| 667 | 667 | |
| 668 | 668 | $error = array(); |
| 669 | 669 | |
| 670 | 670 | // Make sure our query is valid |
| 671 | - if ( ! in_array( $query, $accepted ) ) { |
|
| 672 | - $error['error'] = __( 'Invalid query.', 'give' ); |
|
| 671 | + if ( ! in_array($query, $accepted)) { |
|
| 672 | + $error['error'] = __('Invalid query.', 'give'); |
|
| 673 | 673 | |
| 674 | 674 | $this->data = $error; |
| 675 | 675 | // 400 is Bad Request |
| 676 | - $this->output( 400 ); |
|
| 676 | + $this->output(400); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | $this->endpoint = $query; |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | public function get_paged() { |
| 691 | 691 | global $wp_query; |
| 692 | 692 | |
| 693 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
| 693 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | |
@@ -705,13 +705,13 @@ discard block |
||
| 705 | 705 | public function per_page() { |
| 706 | 706 | global $wp_query; |
| 707 | 707 | |
| 708 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
| 708 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
| 709 | 709 | |
| 710 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
| 710 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
| 711 | 711 | $per_page = 99999999; |
| 712 | 712 | } // End if(). |
| 713 | 713 | |
| 714 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
| 714 | + return apply_filters('give_api_results_per_page', $per_page); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * |
| 725 | 725 | * @return array $dates |
| 726 | 726 | */ |
| 727 | - public function get_dates( $args = array() ) { |
|
| 727 | + public function get_dates($args = array()) { |
|
| 728 | 728 | $dates = array(); |
| 729 | 729 | |
| 730 | 730 | $defaults = array( |
@@ -735,60 +735,60 @@ discard block |
||
| 735 | 735 | 'enddate' => null, |
| 736 | 736 | ); |
| 737 | 737 | |
| 738 | - $args = wp_parse_args( $args, $defaults ); |
|
| 738 | + $args = wp_parse_args($args, $defaults); |
|
| 739 | 739 | |
| 740 | - $current_time = current_time( 'timestamp' ); |
|
| 740 | + $current_time = current_time('timestamp'); |
|
| 741 | 741 | |
| 742 | - if ( 'range' === $args['date'] ) { |
|
| 743 | - $startdate = strtotime( $args['startdate'] ); |
|
| 744 | - $enddate = strtotime( $args['enddate'] ); |
|
| 745 | - $dates['day_start'] = date( 'd', $startdate ); |
|
| 746 | - $dates['day_end'] = date( 'd', $enddate ); |
|
| 747 | - $dates['m_start'] = date( 'n', $startdate ); |
|
| 748 | - $dates['m_end'] = date( 'n', $enddate ); |
|
| 749 | - $dates['year'] = date( 'Y', $startdate ); |
|
| 750 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
| 742 | + if ('range' === $args['date']) { |
|
| 743 | + $startdate = strtotime($args['startdate']); |
|
| 744 | + $enddate = strtotime($args['enddate']); |
|
| 745 | + $dates['day_start'] = date('d', $startdate); |
|
| 746 | + $dates['day_end'] = date('d', $enddate); |
|
| 747 | + $dates['m_start'] = date('n', $startdate); |
|
| 748 | + $dates['m_end'] = date('n', $enddate); |
|
| 749 | + $dates['year'] = date('Y', $startdate); |
|
| 750 | + $dates['year_end'] = date('Y', $enddate); |
|
| 751 | 751 | } else { |
| 752 | 752 | // Modify dates based on predefined ranges |
| 753 | - switch ( $args['date'] ) : |
|
| 753 | + switch ($args['date']) : |
|
| 754 | 754 | |
| 755 | 755 | case 'this_month' : |
| 756 | 756 | $dates['day'] = null; |
| 757 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 758 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 759 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 757 | + $dates['m_start'] = date('n', $current_time); |
|
| 758 | + $dates['m_end'] = date('n', $current_time); |
|
| 759 | + $dates['year'] = date('Y', $current_time); |
|
| 760 | 760 | break; |
| 761 | 761 | |
| 762 | 762 | case 'last_month' : |
| 763 | 763 | $dates['day'] = null; |
| 764 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
| 764 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
| 765 | 765 | $dates['m_end'] = $dates['m_start']; |
| 766 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
| 766 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
| 767 | 767 | break; |
| 768 | 768 | |
| 769 | 769 | case 'today' : |
| 770 | - $dates['day'] = date( 'd', $current_time ); |
|
| 771 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 772 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 773 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 770 | + $dates['day'] = date('d', $current_time); |
|
| 771 | + $dates['m_start'] = date('n', $current_time); |
|
| 772 | + $dates['m_end'] = date('n', $current_time); |
|
| 773 | + $dates['year'] = date('Y', $current_time); |
|
| 774 | 774 | break; |
| 775 | 775 | |
| 776 | 776 | case 'yesterday' : |
| 777 | 777 | |
| 778 | - $year = date( 'Y', $current_time ); |
|
| 779 | - $month = date( 'n', $current_time ); |
|
| 780 | - $day = date( 'd', $current_time ); |
|
| 778 | + $year = date('Y', $current_time); |
|
| 779 | + $month = date('n', $current_time); |
|
| 780 | + $day = date('d', $current_time); |
|
| 781 | 781 | |
| 782 | - if ( $month == 1 && $day == 1 ) { |
|
| 782 | + if ($month == 1 && $day == 1) { |
|
| 783 | 783 | |
| 784 | - $year -= 1; |
|
| 784 | + $year -= 1; |
|
| 785 | 785 | $month = 12; |
| 786 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 786 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 787 | 787 | |
| 788 | - } elseif ( $month > 1 && $day == 1 ) { |
|
| 788 | + } elseif ($month > 1 && $day == 1) { |
|
| 789 | 789 | |
| 790 | 790 | $month -= 1; |
| 791 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 791 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 792 | 792 | |
| 793 | 793 | } else { |
| 794 | 794 | |
@@ -804,65 +804,65 @@ discard block |
||
| 804 | 804 | break; |
| 805 | 805 | |
| 806 | 806 | case 'this_quarter' : |
| 807 | - $month_now = date( 'n', $current_time ); |
|
| 807 | + $month_now = date('n', $current_time); |
|
| 808 | 808 | |
| 809 | 809 | $dates['day'] = null; |
| 810 | 810 | |
| 811 | - if ( $month_now <= 3 ) { |
|
| 811 | + if ($month_now <= 3) { |
|
| 812 | 812 | |
| 813 | 813 | $dates['m_start'] = 1; |
| 814 | 814 | $dates['m_end'] = 3; |
| 815 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 815 | + $dates['year'] = date('Y', $current_time); |
|
| 816 | 816 | |
| 817 | - } elseif ( $month_now <= 6 ) { |
|
| 817 | + } elseif ($month_now <= 6) { |
|
| 818 | 818 | |
| 819 | 819 | $dates['m_start'] = 4; |
| 820 | 820 | $dates['m_end'] = 6; |
| 821 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 821 | + $dates['year'] = date('Y', $current_time); |
|
| 822 | 822 | |
| 823 | - } elseif ( $month_now <= 9 ) { |
|
| 823 | + } elseif ($month_now <= 9) { |
|
| 824 | 824 | |
| 825 | 825 | $dates['m_start'] = 7; |
| 826 | 826 | $dates['m_end'] = 9; |
| 827 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 827 | + $dates['year'] = date('Y', $current_time); |
|
| 828 | 828 | |
| 829 | 829 | } else { |
| 830 | 830 | |
| 831 | 831 | $dates['m_start'] = 10; |
| 832 | 832 | $dates['m_end'] = 12; |
| 833 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 833 | + $dates['year'] = date('Y', $current_time); |
|
| 834 | 834 | |
| 835 | 835 | } |
| 836 | 836 | break; |
| 837 | 837 | |
| 838 | 838 | case 'last_quarter' : |
| 839 | - $month_now = date( 'n', $current_time ); |
|
| 839 | + $month_now = date('n', $current_time); |
|
| 840 | 840 | |
| 841 | 841 | $dates['day'] = null; |
| 842 | 842 | |
| 843 | - if ( $month_now <= 3 ) { |
|
| 843 | + if ($month_now <= 3) { |
|
| 844 | 844 | |
| 845 | 845 | $dates['m_start'] = 10; |
| 846 | 846 | $dates['m_end'] = 12; |
| 847 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 847 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
| 848 | 848 | |
| 849 | - } elseif ( $month_now <= 6 ) { |
|
| 849 | + } elseif ($month_now <= 6) { |
|
| 850 | 850 | |
| 851 | 851 | $dates['m_start'] = 1; |
| 852 | 852 | $dates['m_end'] = 3; |
| 853 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 853 | + $dates['year'] = date('Y', $current_time); |
|
| 854 | 854 | |
| 855 | - } elseif ( $month_now <= 9 ) { |
|
| 855 | + } elseif ($month_now <= 9) { |
|
| 856 | 856 | |
| 857 | 857 | $dates['m_start'] = 4; |
| 858 | 858 | $dates['m_end'] = 6; |
| 859 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 859 | + $dates['year'] = date('Y', $current_time); |
|
| 860 | 860 | |
| 861 | 861 | } else { |
| 862 | 862 | |
| 863 | 863 | $dates['m_start'] = 7; |
| 864 | 864 | $dates['m_end'] = 9; |
| 865 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 865 | + $dates['year'] = date('Y', $current_time); |
|
| 866 | 866 | |
| 867 | 867 | } |
| 868 | 868 | break; |
@@ -871,14 +871,14 @@ discard block |
||
| 871 | 871 | $dates['day'] = null; |
| 872 | 872 | $dates['m_start'] = null; |
| 873 | 873 | $dates['m_end'] = null; |
| 874 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 874 | + $dates['year'] = date('Y', $current_time); |
|
| 875 | 875 | break; |
| 876 | 876 | |
| 877 | 877 | case 'last_year' : |
| 878 | 878 | $dates['day'] = null; |
| 879 | 879 | $dates['m_start'] = null; |
| 880 | 880 | $dates['m_end'] = null; |
| 881 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 881 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 882 | 882 | break; |
| 883 | 883 | |
| 884 | 884 | endswitch; |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | * |
| 892 | 892 | * @param array $dates The dates used for retrieving earnings. |
| 893 | 893 | */ |
| 894 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
| 894 | + return apply_filters('give_api_stat_dates', $dates); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -905,86 +905,86 @@ discard block |
||
| 905 | 905 | * |
| 906 | 906 | * @return array $donors Multidimensional array of the donors. |
| 907 | 907 | */ |
| 908 | - public function get_donors( $donor = null ) { |
|
| 908 | + public function get_donors($donor = null) { |
|
| 909 | 909 | |
| 910 | 910 | $donors = array(); |
| 911 | 911 | $error = array(); |
| 912 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
| 912 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
| 913 | 913 | return $donors; |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | $paged = $this->get_paged(); |
| 917 | 917 | $per_page = $this->per_page(); |
| 918 | - $offset = $per_page * ( $paged - 1 ); |
|
| 918 | + $offset = $per_page * ($paged - 1); |
|
| 919 | 919 | |
| 920 | - if ( is_numeric( $donor ) ) { |
|
| 920 | + if (is_numeric($donor)) { |
|
| 921 | 921 | $field = 'id'; |
| 922 | 922 | } else { |
| 923 | 923 | $field = 'email'; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | - $donor_query = Give()->donors->get_donors( array( |
|
| 926 | + $donor_query = Give()->donors->get_donors(array( |
|
| 927 | 927 | 'number' => $per_page, |
| 928 | 928 | 'offset' => $offset, |
| 929 | 929 | $field => $donor, |
| 930 | - ) ); |
|
| 930 | + )); |
|
| 931 | 931 | $donor_count = 0; |
| 932 | 932 | |
| 933 | - if ( $donor_query ) { |
|
| 933 | + if ($donor_query) { |
|
| 934 | 934 | |
| 935 | - foreach ( $donor_query as $donor_obj ) { |
|
| 935 | + foreach ($donor_query as $donor_obj) { |
|
| 936 | 936 | |
| 937 | - $names = explode( ' ', $donor_obj->name ); |
|
| 938 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
| 937 | + $names = explode(' ', $donor_obj->name); |
|
| 938 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
| 939 | 939 | $last_name = ''; |
| 940 | - if ( ! empty( $names[1] ) ) { |
|
| 941 | - unset( $names[0] ); |
|
| 942 | - $last_name = implode( ' ', $names ); |
|
| 940 | + if ( ! empty($names[1])) { |
|
| 941 | + unset($names[0]); |
|
| 942 | + $last_name = implode(' ', $names); |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | - $title_prefix = Give()->donor_meta->get_meta( $donor_obj->id, '_give_donor_title_prefix', true ); |
|
| 945 | + $title_prefix = Give()->donor_meta->get_meta($donor_obj->id, '_give_donor_title_prefix', true); |
|
| 946 | 946 | |
| 947 | 947 | // Set title prefix empty, if not available in db. |
| 948 | - if ( empty( $title_prefix ) ) { |
|
| 948 | + if (empty($title_prefix)) { |
|
| 949 | 949 | $title_prefix = ''; |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - $donors['donors'][ $donor_count ]['info']['user_id'] = ''; |
|
| 953 | - $donors['donors'][ $donor_count ]['info']['username'] = ''; |
|
| 954 | - $donors['donors'][ $donor_count ]['info']['display_name'] = ''; |
|
| 955 | - $donors['donors'][ $donor_count ]['info']['donor_id'] = $donor_obj->id; |
|
| 956 | - $donors['donors'][ $donor_count ]['info']['title_prefix'] = $title_prefix; |
|
| 957 | - $donors['donors'][ $donor_count ]['info']['first_name'] = $first_name; |
|
| 958 | - $donors['donors'][ $donor_count ]['info']['last_name'] = $last_name; |
|
| 959 | - $donors['donors'][ $donor_count ]['info']['email'] = $donor_obj->email; |
|
| 952 | + $donors['donors'][$donor_count]['info']['user_id'] = ''; |
|
| 953 | + $donors['donors'][$donor_count]['info']['username'] = ''; |
|
| 954 | + $donors['donors'][$donor_count]['info']['display_name'] = ''; |
|
| 955 | + $donors['donors'][$donor_count]['info']['donor_id'] = $donor_obj->id; |
|
| 956 | + $donors['donors'][$donor_count]['info']['title_prefix'] = $title_prefix; |
|
| 957 | + $donors['donors'][$donor_count]['info']['first_name'] = $first_name; |
|
| 958 | + $donors['donors'][$donor_count]['info']['last_name'] = $last_name; |
|
| 959 | + $donors['donors'][$donor_count]['info']['email'] = $donor_obj->email; |
|
| 960 | 960 | |
| 961 | - if ( ! empty( $donor_obj->user_id ) ) { |
|
| 961 | + if ( ! empty($donor_obj->user_id)) { |
|
| 962 | 962 | |
| 963 | - $user_data = get_userdata( $donor_obj->user_id ); |
|
| 963 | + $user_data = get_userdata($donor_obj->user_id); |
|
| 964 | 964 | |
| 965 | 965 | // Donor with registered account. |
| 966 | - $donors['donors'][ $donor_count ]['info']['user_id'] = $donor_obj->user_id; |
|
| 967 | - $donors['donors'][ $donor_count ]['info']['username'] = $user_data->user_login; |
|
| 968 | - $donors['donors'][ $donor_count ]['info']['display_name'] = $user_data->display_name; |
|
| 966 | + $donors['donors'][$donor_count]['info']['user_id'] = $donor_obj->user_id; |
|
| 967 | + $donors['donors'][$donor_count]['info']['username'] = $user_data->user_login; |
|
| 968 | + $donors['donors'][$donor_count]['info']['display_name'] = $user_data->display_name; |
|
| 969 | 969 | |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - $donors['donors'][ $donor_count ]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
| 973 | - $donors['donors'][ $donor_count ]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
| 972 | + $donors['donors'][$donor_count]['stats']['total_donations'] = $donor_obj->purchase_count; |
|
| 973 | + $donors['donors'][$donor_count]['stats']['total_spent'] = $donor_obj->purchase_value; |
|
| 974 | 974 | |
| 975 | - $donor = new Give_Donor( $donor_obj->id ); |
|
| 975 | + $donor = new Give_Donor($donor_obj->id); |
|
| 976 | 976 | |
| 977 | 977 | // Get donor's addresses. |
| 978 | - $donors['donors'][ $donor_count ]['address'] = $donor->address; |
|
| 978 | + $donors['donors'][$donor_count]['address'] = $donor->address; |
|
| 979 | 979 | |
| 980 | - $donor_count ++; |
|
| 980 | + $donor_count++; |
|
| 981 | 981 | |
| 982 | 982 | } // End foreach(). |
| 983 | - } elseif ( $donor ) { |
|
| 983 | + } elseif ($donor) { |
|
| 984 | 984 | |
| 985 | 985 | $error['error'] = sprintf( |
| 986 | 986 | /* translators: %s: donor */ |
| 987 | - __( 'Donor %s not found.', 'give' ), |
|
| 987 | + __('Donor %s not found.', 'give'), |
|
| 988 | 988 | $donor |
| 989 | 989 | ); |
| 990 | 990 | |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | |
| 993 | 993 | } else { |
| 994 | 994 | |
| 995 | - $error['error'] = __( 'No donors found.', 'give' ); |
|
| 995 | + $error['error'] = __('No donors found.', 'give'); |
|
| 996 | 996 | |
| 997 | 997 | return $error; |
| 998 | 998 | |
@@ -1011,37 +1011,37 @@ discard block |
||
| 1011 | 1011 | * |
| 1012 | 1012 | * @return array $donors Multidimensional array of the forms. |
| 1013 | 1013 | */ |
| 1014 | - public function get_forms( $form = null ) { |
|
| 1014 | + public function get_forms($form = null) { |
|
| 1015 | 1015 | |
| 1016 | 1016 | $forms = array(); |
| 1017 | 1017 | $error = array(); |
| 1018 | 1018 | |
| 1019 | - if ( $form == null ) { |
|
| 1019 | + if ($form == null) { |
|
| 1020 | 1020 | $forms['forms'] = array(); |
| 1021 | 1021 | |
| 1022 | - $form_list = get_posts( array( |
|
| 1022 | + $form_list = get_posts(array( |
|
| 1023 | 1023 | 'post_type' => 'give_forms', |
| 1024 | 1024 | 'posts_per_page' => $this->per_page(), |
| 1025 | 1025 | 'suppress_filters' => true, |
| 1026 | 1026 | 'paged' => $this->get_paged(), |
| 1027 | - ) ); |
|
| 1027 | + )); |
|
| 1028 | 1028 | |
| 1029 | - if ( $form_list ) { |
|
| 1029 | + if ($form_list) { |
|
| 1030 | 1030 | $i = 0; |
| 1031 | - foreach ( $form_list as $form_info ) { |
|
| 1032 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
| 1033 | - $i ++; |
|
| 1031 | + foreach ($form_list as $form_info) { |
|
| 1032 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
| 1033 | + $i++; |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } else { |
| 1037 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
| 1038 | - $form_info = get_post( $form ); |
|
| 1037 | + if (get_post_type($form) == 'give_forms') { |
|
| 1038 | + $form_info = get_post($form); |
|
| 1039 | 1039 | |
| 1040 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
| 1040 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
| 1041 | 1041 | |
| 1042 | 1042 | } else { |
| 1043 | 1043 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1044 | - __( 'Form %s not found.', 'give' ), $form ); |
|
| 1044 | + __('Form %s not found.', 'give'), $form ); |
|
| 1045 | 1045 | |
| 1046 | 1046 | return $error; |
| 1047 | 1047 | } |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | * |
| 1060 | 1060 | * @return array Array of post data to return back in the API. |
| 1061 | 1061 | */ |
| 1062 | - private function get_form_data( $form_info ) { |
|
| 1062 | + private function get_form_data($form_info) { |
|
| 1063 | 1063 | |
| 1064 | 1064 | $form = array(); |
| 1065 | 1065 | |
@@ -1069,60 +1069,60 @@ discard block |
||
| 1069 | 1069 | $form['info']['create_date'] = $form_info->post_date; |
| 1070 | 1070 | $form['info']['modified_date'] = $form_info->post_modified; |
| 1071 | 1071 | $form['info']['status'] = $form_info->post_status; |
| 1072 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
| 1073 | - $form['info']['content'] = give_get_meta( $form_info->ID, '_give_form_content', true ); |
|
| 1074 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
| 1072 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
| 1073 | + $form['info']['content'] = give_get_meta($form_info->ID, '_give_form_content', true); |
|
| 1074 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
| 1075 | 1075 | |
| 1076 | - if ( give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) { |
|
| 1077 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
| 1078 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1076 | + if (give_is_setting_enabled(give_get_option('categories', 'disabled'))) { |
|
| 1077 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
| 1078 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1079 | 1079 | } |
| 1080 | - if ( give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) { |
|
| 1081 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1080 | + if (give_is_setting_enabled(give_get_option('tags', 'disabled'))) { |
|
| 1081 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | // Check whether any goal is to be achieved for the donation form. |
| 1085 | - $goal_option = give_get_meta( $form_info->ID, '_give_goal_option', true ); |
|
| 1086 | - $goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true ); |
|
| 1087 | - if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) { |
|
| 1088 | - $total_income = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1089 | - $goal_percentage_completed = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100; |
|
| 1090 | - $form['goal']['amount'] = isset( $goal_amount ) ? $goal_amount : ''; |
|
| 1091 | - $form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : ''; |
|
| 1085 | + $goal_option = give_get_meta($form_info->ID, '_give_goal_option', true); |
|
| 1086 | + $goal_amount = give_get_meta($form_info->ID, '_give_set_goal', true); |
|
| 1087 | + if (give_is_setting_enabled($goal_option) && $goal_amount) { |
|
| 1088 | + $total_income = give_get_form_earnings_stats($form_info->ID); |
|
| 1089 | + $goal_percentage_completed = ($total_income < $goal_amount) ? round(($total_income / $goal_amount) * 100, 2) : 100; |
|
| 1090 | + $form['goal']['amount'] = isset($goal_amount) ? $goal_amount : ''; |
|
| 1091 | + $form['goal']['percentage_completed'] = isset($goal_percentage_completed) ? $goal_percentage_completed : ''; |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
| 1095 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
| 1096 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1097 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
| 1098 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
| 1094 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
| 1095 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
| 1096 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
| 1097 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
| 1098 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | $counter = 0; |
| 1102 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
| 1103 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
| 1104 | - $counter ++; |
|
| 1102 | + if (give_has_variable_prices($form_info->ID)) { |
|
| 1103 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
| 1104 | + $counter++; |
|
| 1105 | 1105 | // multi-level item |
| 1106 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
| 1107 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
| 1106 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
| 1107 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
| 1108 | 1108 | |
| 1109 | 1109 | } |
| 1110 | 1110 | } else { |
| 1111 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
| 1111 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
| 1114 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
| 1115 | 1115 | |
| 1116 | 1116 | /** |
| 1117 | 1117 | * Fires when generating API sensitive data. |
| 1118 | 1118 | * |
| 1119 | 1119 | * @since 1.1 |
| 1120 | 1120 | */ |
| 1121 | - do_action( 'give_api_sensitive_data' ); |
|
| 1121 | + do_action('give_api_sensitive_data'); |
|
| 1122 | 1122 | |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | - return apply_filters( 'give_api_forms_form', $form ); |
|
| 1125 | + return apply_filters('give_api_forms_form', $form); |
|
| 1126 | 1126 | |
| 1127 | 1127 | } |
| 1128 | 1128 | |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | * |
| 1138 | 1138 | * @return array |
| 1139 | 1139 | */ |
| 1140 | - public function get_stats( $args = array() ) { |
|
| 1140 | + public function get_stats($args = array()) { |
|
| 1141 | 1141 | $defaults = array( |
| 1142 | 1142 | 'type' => null, |
| 1143 | 1143 | 'form' => null, |
@@ -1146,9 +1146,9 @@ discard block |
||
| 1146 | 1146 | 'enddate' => null, |
| 1147 | 1147 | ); |
| 1148 | 1148 | |
| 1149 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1149 | + $args = wp_parse_args($args, $defaults); |
|
| 1150 | 1150 | |
| 1151 | - $dates = $this->get_dates( $args ); |
|
| 1151 | + $dates = $this->get_dates($args); |
|
| 1152 | 1152 | |
| 1153 | 1153 | $stats = array(); |
| 1154 | 1154 | $earnings = array( |
@@ -1159,40 +1159,40 @@ discard block |
||
| 1159 | 1159 | ); |
| 1160 | 1160 | $error = array(); |
| 1161 | 1161 | |
| 1162 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1162 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1163 | 1163 | return $stats; |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - if ( $args['type'] == 'donations' ) { |
|
| 1166 | + if ($args['type'] == 'donations') { |
|
| 1167 | 1167 | |
| 1168 | - if ( $args['form'] == null ) { |
|
| 1169 | - if ( $args['date'] == null ) { |
|
| 1168 | + if ($args['form'] == null) { |
|
| 1169 | + if ($args['date'] == null) { |
|
| 1170 | 1170 | $donations = $this->get_default_sales_stats(); |
| 1171 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1171 | + } elseif ($args['date'] === 'range') { |
|
| 1172 | 1172 | // Return donations for a date range. |
| 1173 | 1173 | // Ensure the end date is later than the start date. |
| 1174 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1175 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
| 1174 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1175 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | // Ensure both the start and end date are specified |
| 1179 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1180 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
| 1179 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1180 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | 1183 | $total = 0; |
| 1184 | 1184 | |
| 1185 | 1185 | // Loop through the years |
| 1186 | 1186 | $y = $dates['year']; |
| 1187 | - while ( $y <= $dates['year_end'] ) : |
|
| 1187 | + while ($y <= $dates['year_end']) : |
|
| 1188 | 1188 | |
| 1189 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1189 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1190 | 1190 | $month_start = $dates['m_start']; |
| 1191 | 1191 | $month_end = $dates['m_end']; |
| 1192 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1192 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1193 | 1193 | $month_start = $dates['m_start']; |
| 1194 | 1194 | $month_end = 12; |
| 1195 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1195 | + } elseif ($y == $dates['year_end']) { |
|
| 1196 | 1196 | $month_start = 1; |
| 1197 | 1197 | $month_end = $dates['m_end']; |
| 1198 | 1198 | } else { |
@@ -1201,132 +1201,132 @@ discard block |
||
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | $i = $month_start; |
| 1204 | - while ( $i <= $month_end ) : |
|
| 1204 | + while ($i <= $month_end) : |
|
| 1205 | 1205 | |
| 1206 | - if ( $i == $dates['m_start'] ) { |
|
| 1206 | + if ($i == $dates['m_start']) { |
|
| 1207 | 1207 | $d = $dates['day_start']; |
| 1208 | 1208 | } else { |
| 1209 | 1209 | $d = 1; |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | - if ( $i == $dates['m_end'] ) { |
|
| 1212 | + if ($i == $dates['m_end']) { |
|
| 1213 | 1213 | $num_of_days = $dates['day_end']; |
| 1214 | 1214 | } else { |
| 1215 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1215 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | - while ( $d <= $num_of_days ) : |
|
| 1219 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
| 1220 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1221 | - if ( ! isset( $donations['sales'][ $date_key ] ) ) { |
|
| 1222 | - $donations['sales'][ $date_key ] = 0; |
|
| 1218 | + while ($d <= $num_of_days) : |
|
| 1219 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
| 1220 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1221 | + if ( ! isset($donations['sales'][$date_key])) { |
|
| 1222 | + $donations['sales'][$date_key] = 0; |
|
| 1223 | 1223 | } |
| 1224 | - $donations['sales'][ $date_key ] += $sale_count; |
|
| 1224 | + $donations['sales'][$date_key] += $sale_count; |
|
| 1225 | 1225 | $total += $sale_count; |
| 1226 | - $d ++; |
|
| 1226 | + $d++; |
|
| 1227 | 1227 | endwhile; |
| 1228 | - $i ++; |
|
| 1228 | + $i++; |
|
| 1229 | 1229 | endwhile; |
| 1230 | 1230 | |
| 1231 | - $y ++; |
|
| 1231 | + $y++; |
|
| 1232 | 1232 | endwhile; |
| 1233 | 1233 | |
| 1234 | 1234 | $donations['totals'] = $total; |
| 1235 | 1235 | } else { |
| 1236 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1236 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1237 | 1237 | $donations_count = 0; |
| 1238 | 1238 | |
| 1239 | 1239 | // Loop through the months |
| 1240 | 1240 | $month = $dates['m_start']; |
| 1241 | 1241 | |
| 1242 | - while ( $month <= $dates['m_end'] ) : |
|
| 1243 | - $donations_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
| 1244 | - $month ++; |
|
| 1242 | + while ($month <= $dates['m_end']) : |
|
| 1243 | + $donations_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
| 1244 | + $month++; |
|
| 1245 | 1245 | endwhile; |
| 1246 | 1246 | |
| 1247 | - $donations['donations'][ $args['date'] ] = $donations_count; |
|
| 1247 | + $donations['donations'][$args['date']] = $donations_count; |
|
| 1248 | 1248 | } else { |
| 1249 | - $donations['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1249 | + $donations['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1250 | 1250 | } |
| 1251 | 1251 | }// End if(). |
| 1252 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1253 | - $forms = get_posts( array( |
|
| 1252 | + } elseif ($args['form'] == 'all') { |
|
| 1253 | + $forms = get_posts(array( |
|
| 1254 | 1254 | 'post_type' => 'give_forms', |
| 1255 | 1255 | 'nopaging' => true, |
| 1256 | - ) ); |
|
| 1257 | - $i = 0; |
|
| 1258 | - foreach ( $forms as $form_info ) { |
|
| 1259 | - $donations['donations'][ $i ] = array( |
|
| 1256 | + )); |
|
| 1257 | + $i = 0; |
|
| 1258 | + foreach ($forms as $form_info) { |
|
| 1259 | + $donations['donations'][$i] = array( |
|
| 1260 | 1260 | $form_info->post_name => $this->stats->get_sales( |
| 1261 | 1261 | $form_info->ID, |
| 1262 | - is_numeric( $args['startdate'] ) |
|
| 1263 | - ? strtotime( $args['startdate'] ) |
|
| 1262 | + is_numeric($args['startdate']) |
|
| 1263 | + ? strtotime($args['startdate']) |
|
| 1264 | 1264 | : $args['startdate'], |
| 1265 | - is_numeric( $args['enddate'] ) |
|
| 1266 | - ? strtotime( $args['enddate'] ) |
|
| 1265 | + is_numeric($args['enddate']) |
|
| 1266 | + ? strtotime($args['enddate']) |
|
| 1267 | 1267 | : $args['enddate'] |
| 1268 | 1268 | ), |
| 1269 | 1269 | ); |
| 1270 | - $i ++; |
|
| 1270 | + $i++; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | } else { |
| 1273 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1274 | - $form_info = get_post( $args['form'] ); |
|
| 1273 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1274 | + $form_info = get_post($args['form']); |
|
| 1275 | 1275 | $donations['donations'][0] = array( |
| 1276 | 1276 | $form_info->post_name => $this->stats->get_sales( |
| 1277 | 1277 | $args['form'], |
| 1278 | - is_numeric( $args['startdate'] ) |
|
| 1279 | - ? strtotime( $args['startdate'] ) |
|
| 1278 | + is_numeric($args['startdate']) |
|
| 1279 | + ? strtotime($args['startdate']) |
|
| 1280 | 1280 | : $args['startdate'], |
| 1281 | - is_numeric( $args['enddate'] ) |
|
| 1282 | - ? strtotime( $args['enddate'] ) |
|
| 1281 | + is_numeric($args['enddate']) |
|
| 1282 | + ? strtotime($args['enddate']) |
|
| 1283 | 1283 | : $args['enddate'] |
| 1284 | 1284 | ), |
| 1285 | 1285 | ); |
| 1286 | 1286 | } else { |
| 1287 | 1287 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1288 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
| 1288 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
| 1289 | 1289 | } |
| 1290 | 1290 | }// End if(). |
| 1291 | 1291 | |
| 1292 | - if ( ! empty( $error ) ) { |
|
| 1292 | + if ( ! empty($error)) { |
|
| 1293 | 1293 | return $error; |
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | return $donations; |
| 1297 | 1297 | |
| 1298 | - } elseif ( $args['type'] == 'earnings' ) { |
|
| 1299 | - if ( $args['form'] == null ) { |
|
| 1300 | - if ( $args['date'] == null ) { |
|
| 1298 | + } elseif ($args['type'] == 'earnings') { |
|
| 1299 | + if ($args['form'] == null) { |
|
| 1300 | + if ($args['date'] == null) { |
|
| 1301 | 1301 | $earnings = $this->get_default_earnings_stats(); |
| 1302 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1302 | + } elseif ($args['date'] === 'range') { |
|
| 1303 | 1303 | // Return sales for a date range |
| 1304 | 1304 | // Ensure the end date is later than the start date |
| 1305 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1306 | - $error['error'] = __( 'The end date must be later than the start date.', 'give' ); |
|
| 1305 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1306 | + $error['error'] = __('The end date must be later than the start date.', 'give'); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | // Ensure both the start and end date are specified |
| 1310 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1311 | - $error['error'] = __( 'Invalid or no date range specified.', 'give' ); |
|
| 1310 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1311 | + $error['error'] = __('Invalid or no date range specified.', 'give'); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | $total = (float) 0.00; |
| 1315 | 1315 | |
| 1316 | 1316 | // Loop through the years |
| 1317 | 1317 | $y = $dates['year']; |
| 1318 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
| 1318 | + if ( ! isset($earnings['earnings'])) { |
|
| 1319 | 1319 | $earnings['earnings'] = array(); |
| 1320 | 1320 | } |
| 1321 | - while ( $y <= $dates['year_end'] ) : |
|
| 1321 | + while ($y <= $dates['year_end']) : |
|
| 1322 | 1322 | |
| 1323 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1323 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1324 | 1324 | $month_start = $dates['m_start']; |
| 1325 | 1325 | $month_end = $dates['m_end']; |
| 1326 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1326 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1327 | 1327 | $month_start = $dates['m_start']; |
| 1328 | 1328 | $month_end = 12; |
| 1329 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1329 | + } elseif ($y == $dates['year_end']) { |
|
| 1330 | 1330 | $month_start = 1; |
| 1331 | 1331 | $month_end = $dates['m_end']; |
| 1332 | 1332 | } else { |
@@ -1335,102 +1335,102 @@ discard block |
||
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | $i = $month_start; |
| 1338 | - while ( $i <= $month_end ) : |
|
| 1338 | + while ($i <= $month_end) : |
|
| 1339 | 1339 | |
| 1340 | - if ( $i == $dates['m_start'] ) { |
|
| 1340 | + if ($i == $dates['m_start']) { |
|
| 1341 | 1341 | $d = $dates['day_start']; |
| 1342 | 1342 | } else { |
| 1343 | 1343 | $d = 1; |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | - if ( $i == $dates['m_end'] ) { |
|
| 1346 | + if ($i == $dates['m_end']) { |
|
| 1347 | 1347 | $num_of_days = $dates['day_end']; |
| 1348 | 1348 | } else { |
| 1349 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1349 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | - while ( $d <= $num_of_days ) : |
|
| 1353 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
| 1354 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1355 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
| 1356 | - $earnings['earnings'][ $date_key ] = 0; |
|
| 1352 | + while ($d <= $num_of_days) : |
|
| 1353 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
| 1354 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1355 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
| 1356 | + $earnings['earnings'][$date_key] = 0; |
|
| 1357 | 1357 | } |
| 1358 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
| 1358 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
| 1359 | 1359 | $total += $earnings_stat; |
| 1360 | - $d ++; |
|
| 1360 | + $d++; |
|
| 1361 | 1361 | endwhile; |
| 1362 | 1362 | |
| 1363 | - $i ++; |
|
| 1363 | + $i++; |
|
| 1364 | 1364 | endwhile; |
| 1365 | 1365 | |
| 1366 | - $y ++; |
|
| 1366 | + $y++; |
|
| 1367 | 1367 | endwhile; |
| 1368 | 1368 | |
| 1369 | 1369 | $earnings['totals'] = $total; |
| 1370 | 1370 | } else { |
| 1371 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1371 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1372 | 1372 | $earnings_count = (float) 0.00; |
| 1373 | 1373 | |
| 1374 | 1374 | // Loop through the months |
| 1375 | 1375 | $month = $dates['m_start']; |
| 1376 | 1376 | |
| 1377 | - while ( $month <= $dates['m_end'] ) : |
|
| 1378 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
| 1379 | - $month ++; |
|
| 1377 | + while ($month <= $dates['m_end']) : |
|
| 1378 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
| 1379 | + $month++; |
|
| 1380 | 1380 | endwhile; |
| 1381 | 1381 | |
| 1382 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
| 1382 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
| 1383 | 1383 | } else { |
| 1384 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1384 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1385 | 1385 | } |
| 1386 | 1386 | }// End if(). |
| 1387 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1388 | - $forms = get_posts( array( |
|
| 1387 | + } elseif ($args['form'] == 'all') { |
|
| 1388 | + $forms = get_posts(array( |
|
| 1389 | 1389 | 'post_type' => 'give_forms', |
| 1390 | 1390 | 'nopaging' => true, |
| 1391 | - ) ); |
|
| 1391 | + )); |
|
| 1392 | 1392 | |
| 1393 | 1393 | $i = 0; |
| 1394 | - foreach ( $forms as $form_info ) { |
|
| 1395 | - $earnings['earnings'][ $i ] = array( |
|
| 1396 | - $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ), |
|
| 1394 | + foreach ($forms as $form_info) { |
|
| 1395 | + $earnings['earnings'][$i] = array( |
|
| 1396 | + $form_info->post_name => give_get_form_earnings_stats($form_info->ID), |
|
| 1397 | 1397 | ); |
| 1398 | - $i ++; |
|
| 1398 | + $i++; |
|
| 1399 | 1399 | } |
| 1400 | 1400 | } else { |
| 1401 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1402 | - $form_info = get_post( $args['form'] ); |
|
| 1401 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1402 | + $form_info = get_post($args['form']); |
|
| 1403 | 1403 | $earnings['earnings'][0] = array( |
| 1404 | 1404 | $form_info->post_name => $this->stats->get_earnings( |
| 1405 | 1405 | $args['form'], |
| 1406 | - is_numeric( $args['startdate'] ) |
|
| 1407 | - ? strtotime( $args['startdate'] ) |
|
| 1406 | + is_numeric($args['startdate']) |
|
| 1407 | + ? strtotime($args['startdate']) |
|
| 1408 | 1408 | : $args['startdate'], |
| 1409 | - is_numeric( $args['enddate'] ) |
|
| 1410 | - ? strtotime( $args['enddate'] ) |
|
| 1409 | + is_numeric($args['enddate']) |
|
| 1410 | + ? strtotime($args['enddate']) |
|
| 1411 | 1411 | : $args['enddate'] |
| 1412 | 1412 | ), |
| 1413 | 1413 | ); |
| 1414 | 1414 | } else { |
| 1415 | 1415 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1416 | - __( 'Form %s not found.', 'give' ), $args['form'] ); |
|
| 1416 | + __('Form %s not found.', 'give'), $args['form'] ); |
|
| 1417 | 1417 | } |
| 1418 | 1418 | }// End if(). |
| 1419 | 1419 | |
| 1420 | - if ( ! empty( $error ) ) { |
|
| 1420 | + if ( ! empty($error)) { |
|
| 1421 | 1421 | return $error; |
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | return $earnings; |
| 1425 | - } elseif ( $args['type'] == 'donors' ) { |
|
| 1425 | + } elseif ($args['type'] == 'donors') { |
|
| 1426 | 1426 | $donors = new Give_DB_Donors(); |
| 1427 | 1427 | $stats['donations']['total_donors'] = $donors->count(); |
| 1428 | 1428 | |
| 1429 | 1429 | return $stats; |
| 1430 | 1430 | |
| 1431 | - } elseif ( empty( $args['type'] ) ) { |
|
| 1432 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
| 1433 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
| 1431 | + } elseif (empty($args['type'])) { |
|
| 1432 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
| 1433 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
| 1434 | 1434 | |
| 1435 | 1435 | return array( |
| 1436 | 1436 | 'stats' => $stats, |
@@ -1448,7 +1448,7 @@ discard block |
||
| 1448 | 1448 | * |
| 1449 | 1449 | * @return array |
| 1450 | 1450 | */ |
| 1451 | - public function get_recent_donations( $args = array() ) { |
|
| 1451 | + public function get_recent_donations($args = array()) { |
|
| 1452 | 1452 | global $wp_query; |
| 1453 | 1453 | |
| 1454 | 1454 | $defaults = array( |
@@ -1458,33 +1458,33 @@ discard block |
||
| 1458 | 1458 | 'enddate' => null, |
| 1459 | 1459 | ); |
| 1460 | 1460 | |
| 1461 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1461 | + $args = wp_parse_args($args, $defaults); |
|
| 1462 | 1462 | |
| 1463 | 1463 | $donations = array(); |
| 1464 | 1464 | |
| 1465 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1465 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1466 | 1466 | return $donations; |
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
| 1469 | + if (isset($wp_query->query_vars['id'])) { |
|
| 1470 | 1470 | $query = array(); |
| 1471 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
| 1472 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
| 1471 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
| 1472 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
| 1473 | 1473 | $query = array(); |
| 1474 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
| 1475 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
| 1476 | - $args = array( |
|
| 1474 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
| 1475 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
| 1476 | + $args = array( |
|
| 1477 | 1477 | 'fields' => 'ids', |
| 1478 | 1478 | 'meta_key' => '_give_payment_donor_email', |
| 1479 | 1479 | 'meta_value' => $wp_query->query_vars['email'], |
| 1480 | 1480 | 'number' => $this->per_page(), |
| 1481 | 1481 | 'page' => $this->get_paged(), |
| 1482 | 1482 | ); |
| 1483 | - $query = give_get_payments( $args ); |
|
| 1484 | - } elseif ( isset( $wp_query->query_vars['date'] ) ) { |
|
| 1483 | + $query = give_get_payments($args); |
|
| 1484 | + } elseif (isset($wp_query->query_vars['date'])) { |
|
| 1485 | 1485 | |
| 1486 | - $current_time = current_time( 'timestamp' ); |
|
| 1487 | - $dates = $this->get_dates( $args ); |
|
| 1486 | + $current_time = current_time('timestamp'); |
|
| 1487 | + $dates = $this->get_dates($args); |
|
| 1488 | 1488 | $start_date = ''; |
| 1489 | 1489 | $end_date = ''; |
| 1490 | 1490 | |
@@ -1497,27 +1497,27 @@ discard block |
||
| 1497 | 1497 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 1498 | 1498 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 1499 | 1499 | */ |
| 1500 | - switch ( $wp_query->query_vars['date'] ) { |
|
| 1500 | + switch ($wp_query->query_vars['date']) { |
|
| 1501 | 1501 | |
| 1502 | 1502 | case 'today': |
| 1503 | 1503 | |
| 1504 | 1504 | // Set and Format Start and End Date to be date of today. |
| 1505 | - $start_date = $end_date = date( 'Y/m/d', $current_time ); |
|
| 1505 | + $start_date = $end_date = date('Y/m/d', $current_time); |
|
| 1506 | 1506 | |
| 1507 | 1507 | break; |
| 1508 | 1508 | |
| 1509 | 1509 | case 'yesterday': |
| 1510 | 1510 | |
| 1511 | 1511 | // Set and Format Start and End Date to be date of yesterday. |
| 1512 | - $start_date = $end_date = date( 'Y/m', $current_time ) . '/' . ( date( 'd', $current_time ) - 1 ); |
|
| 1512 | + $start_date = $end_date = date('Y/m', $current_time).'/'.(date('d', $current_time) - 1); |
|
| 1513 | 1513 | |
| 1514 | 1514 | break; |
| 1515 | 1515 | |
| 1516 | 1516 | case 'range': |
| 1517 | 1517 | |
| 1518 | 1518 | // Format Start Date and End Date for filtering payment based on date range. |
| 1519 | - $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
|
| 1520 | - $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
|
| 1519 | + $start_date = $dates['year'].'/'.$dates['m_start'].'/'.$dates['day_start']; |
|
| 1520 | + $end_date = $dates['year_end'].'/'.$dates['m_end'].'/'.$dates['day_end']; |
|
| 1521 | 1521 | |
| 1522 | 1522 | break; |
| 1523 | 1523 | |
@@ -1531,22 +1531,22 @@ discard block |
||
| 1531 | 1531 | 'page' => $this->get_paged(), |
| 1532 | 1532 | ); |
| 1533 | 1533 | |
| 1534 | - $query = give_get_payments( $args ); |
|
| 1534 | + $query = give_get_payments($args); |
|
| 1535 | 1535 | } else { |
| 1536 | 1536 | $args = array( |
| 1537 | 1537 | 'fields' => 'ids', |
| 1538 | 1538 | 'number' => $this->per_page(), |
| 1539 | 1539 | 'page' => $this->get_paged(), |
| 1540 | 1540 | ); |
| 1541 | - $query = give_get_payments( $args ); |
|
| 1541 | + $query = give_get_payments($args); |
|
| 1542 | 1542 | }// End if(). |
| 1543 | 1543 | |
| 1544 | - if ( $query ) { |
|
| 1544 | + if ($query) { |
|
| 1545 | 1545 | $i = 0; |
| 1546 | - foreach ( $query as $payment ) { |
|
| 1546 | + foreach ($query as $payment) { |
|
| 1547 | 1547 | |
| 1548 | - if ( is_numeric( $payment ) ) { |
|
| 1549 | - $payment = new Give_Payment( $payment ); |
|
| 1548 | + if (is_numeric($payment)) { |
|
| 1549 | + $payment = new Give_Payment($payment); |
|
| 1550 | 1550 | $payment_meta = $payment->get_meta(); |
| 1551 | 1551 | $user_info = $payment->user_info; |
| 1552 | 1552 | } |
@@ -1554,44 +1554,44 @@ discard block |
||
| 1554 | 1554 | $payment_meta = $payment->get_meta(); |
| 1555 | 1555 | $user_info = $payment->user_info; |
| 1556 | 1556 | |
| 1557 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
| 1558 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
| 1559 | - |
|
| 1560 | - $donations['donations'][ $i ]['ID'] = $payment->ID; |
|
| 1561 | - $donations['donations'][ $i ]['number'] = $payment->number; |
|
| 1562 | - $donations['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
| 1563 | - $donations['donations'][ $i ]['key'] = $payment->key; |
|
| 1564 | - $donations['donations'][ $i ]['total'] = $payment->total; |
|
| 1565 | - $donations['donations'][ $i ]['status'] = give_get_payment_status( $payment, true ); |
|
| 1566 | - $donations['donations'][ $i ]['gateway'] = $payment->gateway; |
|
| 1567 | - $donations['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
| 1568 | - $donations['donations'][ $i ]['fname'] = $first_name; |
|
| 1569 | - $donations['donations'][ $i ]['lname'] = $last_name; |
|
| 1570 | - $donations['donations'][ $i ]['email'] = $payment->email; |
|
| 1571 | - $donations['donations'][ $i ]['date'] = $payment->date; |
|
| 1572 | - $donations['donations'][ $i ]['payment_meta'] = array(); |
|
| 1573 | - |
|
| 1574 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1575 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
| 1576 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
| 1577 | - |
|
| 1578 | - $donations['donations'][ $i ]['form']['id'] = $form_id; |
|
| 1579 | - $donations['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
| 1580 | - $donations['donations'][ $i ]['form']['price'] = $price; |
|
| 1581 | - |
|
| 1582 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1583 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
| 1584 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
| 1585 | - $donations['donations'][ $i ]['form']['price_name'] = $price_name; |
|
| 1586 | - $donations['donations'][ $i ]['form']['price_id'] = $price_id; |
|
| 1587 | - $donations['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
| 1557 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
| 1558 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
| 1559 | + |
|
| 1560 | + $donations['donations'][$i]['ID'] = $payment->ID; |
|
| 1561 | + $donations['donations'][$i]['number'] = $payment->number; |
|
| 1562 | + $donations['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
| 1563 | + $donations['donations'][$i]['key'] = $payment->key; |
|
| 1564 | + $donations['donations'][$i]['total'] = $payment->total; |
|
| 1565 | + $donations['donations'][$i]['status'] = give_get_payment_status($payment, true); |
|
| 1566 | + $donations['donations'][$i]['gateway'] = $payment->gateway; |
|
| 1567 | + $donations['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
| 1568 | + $donations['donations'][$i]['fname'] = $first_name; |
|
| 1569 | + $donations['donations'][$i]['lname'] = $last_name; |
|
| 1570 | + $donations['donations'][$i]['email'] = $payment->email; |
|
| 1571 | + $donations['donations'][$i]['date'] = $payment->date; |
|
| 1572 | + $donations['donations'][$i]['payment_meta'] = array(); |
|
| 1573 | + |
|
| 1574 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1575 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
| 1576 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
| 1577 | + |
|
| 1578 | + $donations['donations'][$i]['form']['id'] = $form_id; |
|
| 1579 | + $donations['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
| 1580 | + $donations['donations'][$i]['form']['price'] = $price; |
|
| 1581 | + |
|
| 1582 | + if (give_has_variable_prices($form_id)) { |
|
| 1583 | + if (isset($payment_meta['price_id'])) { |
|
| 1584 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
| 1585 | + $donations['donations'][$i]['form']['price_name'] = $price_name; |
|
| 1586 | + $donations['donations'][$i]['form']['price_id'] = $price_id; |
|
| 1587 | + $donations['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
| 1588 | 1588 | |
| 1589 | 1589 | } |
| 1590 | 1590 | } |
| 1591 | 1591 | |
| 1592 | - if( ! empty( $payment_meta ) ) { |
|
| 1592 | + if ( ! empty($payment_meta)) { |
|
| 1593 | 1593 | // Add custom meta to API |
| 1594 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
| 1594 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
| 1595 | 1595 | |
| 1596 | 1596 | $exceptions = array( |
| 1597 | 1597 | 'form_title', |
@@ -1604,20 +1604,20 @@ discard block |
||
| 1604 | 1604 | ); |
| 1605 | 1605 | |
| 1606 | 1606 | // Don't clutter up results with dupes |
| 1607 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
| 1607 | + if (in_array($meta_key, $exceptions)) { |
|
| 1608 | 1608 | continue; |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - $donations['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
| 1611 | + $donations['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
| 1612 | 1612 | |
| 1613 | 1613 | } |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | - $i ++; |
|
| 1616 | + $i++; |
|
| 1617 | 1617 | }// End foreach(). |
| 1618 | 1618 | }// End if(). |
| 1619 | 1619 | |
| 1620 | - return apply_filters( 'give_api_donations_endpoint', $donations ); |
|
| 1620 | + return apply_filters('give_api_donations_endpoint', $donations); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | /** |
@@ -1633,9 +1633,9 @@ discard block |
||
| 1633 | 1633 | public function get_output_format() { |
| 1634 | 1634 | global $wp_query; |
| 1635 | 1635 | |
| 1636 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1636 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1637 | 1637 | |
| 1638 | - return apply_filters( 'give_api_output_format', $format ); |
|
| 1638 | + return apply_filters('give_api_output_format', $format); |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | |
@@ -1651,8 +1651,8 @@ discard block |
||
| 1651 | 1651 | * |
| 1652 | 1652 | * @return void |
| 1653 | 1653 | */ |
| 1654 | - private function log_request( $data = array() ) { |
|
| 1655 | - if ( ! $this->log_requests ) { |
|
| 1654 | + private function log_request($data = array()) { |
|
| 1655 | + if ( ! $this->log_requests) { |
|
| 1656 | 1656 | return; |
| 1657 | 1657 | } |
| 1658 | 1658 | |
@@ -1663,37 +1663,37 @@ discard block |
||
| 1663 | 1663 | |
| 1664 | 1664 | $query = array( |
| 1665 | 1665 | 'give-api' => $wp_query->query_vars['give-api'], |
| 1666 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1667 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1668 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
| 1669 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 1670 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 1671 | - 'donor' => isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null, |
|
| 1672 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 1673 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 1674 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 1675 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 1676 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1677 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
| 1666 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1667 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1668 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
| 1669 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 1670 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 1671 | + 'donor' => isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null, |
|
| 1672 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 1673 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 1674 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 1675 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 1676 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1677 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
| 1678 | 1678 | ); |
| 1679 | 1679 | |
| 1680 | 1680 | $log_data = array( |
| 1681 | 1681 | 'log_type' => 'api_request', |
| 1682 | - 'post_excerpt' => http_build_query( $query ), |
|
| 1683 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
| 1682 | + 'post_excerpt' => http_build_query($query), |
|
| 1683 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
| 1684 | 1684 | ); |
| 1685 | 1685 | |
| 1686 | 1686 | $log_meta = array( |
| 1687 | - 'api_query' => http_build_query( $query ), |
|
| 1687 | + 'api_query' => http_build_query($query), |
|
| 1688 | 1688 | 'request_ip' => give_get_ip(), |
| 1689 | 1689 | 'user' => $this->user_id, |
| 1690 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1691 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1690 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1691 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1692 | 1692 | 'time' => $data['request_speed'], |
| 1693 | 1693 | 'version' => $this->get_queried_version(), |
| 1694 | 1694 | ); |
| 1695 | 1695 | |
| 1696 | - Give()->logs->insert_log( $log_data, $log_meta ); |
|
| 1696 | + Give()->logs->insert_log($log_data, $log_meta); |
|
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | 1699 | |
@@ -1717,11 +1717,11 @@ discard block |
||
| 1717 | 1717 | * |
| 1718 | 1718 | * @param int $status_code |
| 1719 | 1719 | */ |
| 1720 | - public function output( $status_code = 200 ) { |
|
| 1720 | + public function output($status_code = 200) { |
|
| 1721 | 1721 | |
| 1722 | 1722 | $format = $this->get_output_format(); |
| 1723 | 1723 | |
| 1724 | - status_header( $status_code ); |
|
| 1724 | + status_header($status_code); |
|
| 1725 | 1725 | |
| 1726 | 1726 | /** |
| 1727 | 1727 | * Fires before outputting the API. |
@@ -1732,25 +1732,25 @@ discard block |
||
| 1732 | 1732 | * @param Give_API $this The Give_API object. |
| 1733 | 1733 | * @param string $format Output format, XML or JSON. Default is JSON. |
| 1734 | 1734 | */ |
| 1735 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
| 1735 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
| 1736 | 1736 | |
| 1737 | - switch ( $format ) : |
|
| 1737 | + switch ($format) : |
|
| 1738 | 1738 | |
| 1739 | 1739 | case 'xml' : |
| 1740 | 1740 | |
| 1741 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
| 1742 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
| 1741 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
| 1742 | + $xml = Array2XML::createXML('give', $this->data); |
|
| 1743 | 1743 | echo $xml->saveXML(); |
| 1744 | 1744 | |
| 1745 | 1745 | break; |
| 1746 | 1746 | |
| 1747 | 1747 | case 'json' : |
| 1748 | 1748 | |
| 1749 | - header( 'Content-Type: application/json' ); |
|
| 1750 | - if ( ! empty( $this->pretty_print ) ) { |
|
| 1751 | - echo json_encode( $this->data, $this->pretty_print ); |
|
| 1749 | + header('Content-Type: application/json'); |
|
| 1750 | + if ( ! empty($this->pretty_print)) { |
|
| 1751 | + echo json_encode($this->data, $this->pretty_print); |
|
| 1752 | 1752 | } else { |
| 1753 | - echo json_encode( $this->data ); |
|
| 1753 | + echo json_encode($this->data); |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | 1756 | break; |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | * @param array $data Response data to return. |
| 1766 | 1766 | * @param Give_API $this The Give_API object. |
| 1767 | 1767 | */ |
| 1768 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
| 1768 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
| 1769 | 1769 | |
| 1770 | 1770 | break; |
| 1771 | 1771 | |
@@ -1780,7 +1780,7 @@ discard block |
||
| 1780 | 1780 | * @param Give_API $this The Give_API object. |
| 1781 | 1781 | * @param string $format Output format, XML or JSON. Default is JSON. |
| 1782 | 1782 | */ |
| 1783 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
| 1783 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
| 1784 | 1784 | |
| 1785 | 1785 | give_die(); |
| 1786 | 1786 | } |
@@ -1797,41 +1797,41 @@ discard block |
||
| 1797 | 1797 | * |
| 1798 | 1798 | * @return void |
| 1799 | 1799 | */ |
| 1800 | - function user_key_field( $user ) { |
|
| 1800 | + function user_key_field($user) { |
|
| 1801 | 1801 | |
| 1802 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
| 1802 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
| 1803 | 1803 | |
| 1804 | - $user = get_userdata( $user->ID ); |
|
| 1804 | + $user = get_userdata($user->ID); |
|
| 1805 | 1805 | ?> |
| 1806 | 1806 | <table class="form-table"> |
| 1807 | 1807 | <tbody> |
| 1808 | 1808 | <tr> |
| 1809 | 1809 | <th> |
| 1810 | - <?php _e( 'Give API Keys', 'give' ); ?> |
|
| 1810 | + <?php _e('Give API Keys', 'give'); ?> |
|
| 1811 | 1811 | </th> |
| 1812 | 1812 | <td> |
| 1813 | 1813 | <?php |
| 1814 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
| 1815 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
| 1814 | + $public_key = $this->get_user_public_key($user->ID); |
|
| 1815 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
| 1816 | 1816 | ?> |
| 1817 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
| 1817 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
| 1818 | 1818 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" /> |
| 1819 | - <span class="description"><?php _e( 'Generate API Key', 'give' ); ?></span> |
|
| 1819 | + <span class="description"><?php _e('Generate API Key', 'give'); ?></span> |
|
| 1820 | 1820 | <?php } else { ?> |
| 1821 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> |
|
| 1821 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> |
|
| 1822 | 1822 | </strong> |
| 1823 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" /> |
|
| 1823 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>" /> |
|
| 1824 | 1824 | <br /> |
| 1825 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Secret key:', 'give' ); ?> |
|
| 1825 | + <strong style="display:inline-block; width: 125px;"><?php _e('Secret key:', 'give'); ?> |
|
| 1826 | 1826 | </strong> |
| 1827 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>" /> |
|
| 1827 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>" /> |
|
| 1828 | 1828 | <br /> |
| 1829 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Token:', 'give' ); ?> |
|
| 1829 | + <strong style="display:inline-block; width: 125px;"><?php _e('Token:', 'give'); ?> |
|
| 1830 | 1830 | </strong> |
| 1831 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>" /> |
|
| 1831 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>" /> |
|
| 1832 | 1832 | <br /> |
| 1833 | 1833 | <input name="give_revoke_api_key" type="checkbox" id="give_revoke_api_key" /> |
| 1834 | - <span class="description"><label for="give_revoke_api_key"><?php _e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
| 1834 | + <span class="description"><label for="give_revoke_api_key"><?php _e('Revoke API Keys', 'give'); ?></label></span> |
|
| 1835 | 1835 | <?php } ?> |
| 1836 | 1836 | </td> |
| 1837 | 1837 | </tr> |
@@ -1850,61 +1850,61 @@ discard block |
||
| 1850 | 1850 | * |
| 1851 | 1851 | * @return void |
| 1852 | 1852 | */ |
| 1853 | - public function process_api_key( $args ) { |
|
| 1853 | + public function process_api_key($args) { |
|
| 1854 | 1854 | |
| 1855 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
| 1856 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( |
|
| 1855 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
| 1856 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array( |
|
| 1857 | 1857 | 'response' => 403, |
| 1858 | - ) ); |
|
| 1858 | + )); |
|
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | - if ( empty( $args['user_id'] ) ) { |
|
| 1862 | - wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array( |
|
| 1861 | + if (empty($args['user_id'])) { |
|
| 1862 | + wp_die(__('User ID Required.', 'give'), __('Error', 'give'), array( |
|
| 1863 | 1863 | 'response' => 401, |
| 1864 | - ) ); |
|
| 1864 | + )); |
|
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | - if ( is_numeric( $args['user_id'] ) ) { |
|
| 1868 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
| 1867 | + if (is_numeric($args['user_id'])) { |
|
| 1868 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
| 1869 | 1869 | } else { |
| 1870 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
| 1870 | + $userdata = get_user_by('login', $args['user_id']); |
|
| 1871 | 1871 | $user_id = $userdata->ID; |
| 1872 | 1872 | } |
| 1873 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
| 1873 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
| 1874 | 1874 | |
| 1875 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1876 | - wp_die( sprintf( /* translators: %s: process */ |
|
| 1877 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
| 1875 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
| 1876 | + wp_die(sprintf( /* translators: %s: process */ |
|
| 1877 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
| 1878 | 1878 | 'response' => 403, |
| 1879 | - ) ); |
|
| 1880 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1881 | - wp_die( sprintf( /* translators: %s: process */ |
|
| 1882 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( |
|
| 1879 | + )); |
|
| 1880 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
| 1881 | + wp_die(sprintf( /* translators: %s: process */ |
|
| 1882 | + __('You do not have permission to %s API keys for this user.', 'give'), $process ), __('Error', 'give'), array( |
|
| 1883 | 1883 | 'response' => 403, |
| 1884 | - ) ); |
|
| 1884 | + )); |
|
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | - switch ( $process ) { |
|
| 1887 | + switch ($process) { |
|
| 1888 | 1888 | case 'generate': |
| 1889 | - if ( $this->generate_api_key( $user_id ) ) { |
|
| 1890 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1891 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1889 | + if ($this->generate_api_key($user_id)) { |
|
| 1890 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1891 | + wp_redirect(add_query_arg('give-messages[]', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1892 | 1892 | exit(); |
| 1893 | 1893 | } else { |
| 1894 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1894 | + wp_redirect(add_query_arg('give-messages[]', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1895 | 1895 | exit(); |
| 1896 | 1896 | } |
| 1897 | 1897 | break; |
| 1898 | 1898 | case 'regenerate': |
| 1899 | - $this->generate_api_key( $user_id, true ); |
|
| 1900 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1901 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1899 | + $this->generate_api_key($user_id, true); |
|
| 1900 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1901 | + wp_redirect(add_query_arg('give-messages[]', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1902 | 1902 | exit(); |
| 1903 | 1903 | break; |
| 1904 | 1904 | case 'revoke': |
| 1905 | - $this->revoke_api_key( $user_id ); |
|
| 1906 | - Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
|
| 1907 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); |
|
| 1905 | + $this->revoke_api_key($user_id); |
|
| 1906 | + Give_Cache::delete(Give_Cache::get_key('give_total_api_keys')); |
|
| 1907 | + wp_redirect(add_query_arg('give-messages[]', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api')); |
|
| 1908 | 1908 | exit(); |
| 1909 | 1909 | break; |
| 1910 | 1910 | default; |
@@ -1923,59 +1923,59 @@ discard block |
||
| 1923 | 1923 | * |
| 1924 | 1924 | * @return boolean True if (re)generated successfully, false otherwise. |
| 1925 | 1925 | */ |
| 1926 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
| 1926 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
| 1927 | 1927 | |
| 1928 | 1928 | // Bail out, if user doesn't exists. |
| 1929 | - if ( empty( $user_id ) ) { |
|
| 1929 | + if (empty($user_id)) { |
|
| 1930 | 1930 | return false; |
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | - $user = get_userdata( $user_id ); |
|
| 1933 | + $user = get_userdata($user_id); |
|
| 1934 | 1934 | |
| 1935 | 1935 | // Bail Out, if user object doesn't exists. |
| 1936 | - if ( ! $user ) { |
|
| 1936 | + if ( ! $user) { |
|
| 1937 | 1937 | return false; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | $new_public_key = ''; |
| 1941 | 1941 | $new_secret_key = ''; |
| 1942 | 1942 | |
| 1943 | - if( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) { |
|
| 1943 | + if ( ! empty($_POST['from']) && 'profile' === $_POST['from']) { |
|
| 1944 | 1944 | // For User Profile Page. |
| 1945 | - if( ! empty( $_POST['give_set_api_key'] ) ) { |
|
| 1945 | + if ( ! empty($_POST['give_set_api_key'])) { |
|
| 1946 | 1946 | // Generate API Key from User Profile page. |
| 1947 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1948 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1949 | - } elseif ( ! empty( $_POST['give_revoke_api_key'] ) ) { |
|
| 1947 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1948 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1949 | + } elseif ( ! empty($_POST['give_revoke_api_key'])) { |
|
| 1950 | 1950 | // Revoke API Key from User Profile page. |
| 1951 | - $this->revoke_api_key( $user->ID ); |
|
| 1951 | + $this->revoke_api_key($user->ID); |
|
| 1952 | 1952 | } else { |
| 1953 | 1953 | return false; |
| 1954 | 1954 | } |
| 1955 | 1955 | } else { |
| 1956 | 1956 | // For Tools > API page. |
| 1957 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1957 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1958 | 1958 | |
| 1959 | - if ( empty( $public_key ) && ! $regenerate ) { |
|
| 1959 | + if (empty($public_key) && ! $regenerate) { |
|
| 1960 | 1960 | // Generating API for first time. |
| 1961 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1962 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1963 | - } elseif ( $public_key && $regenerate ) { |
|
| 1961 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1962 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1963 | + } elseif ($public_key && $regenerate) { |
|
| 1964 | 1964 | // API Key already exists and Regenerating API Key. |
| 1965 | - $this->revoke_api_key( $user->ID ); |
|
| 1966 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1967 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1968 | - } elseif ( ! empty( $public_key ) && ! $regenerate ) { |
|
| 1965 | + $this->revoke_api_key($user->ID); |
|
| 1966 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1967 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1968 | + } elseif ( ! empty($public_key) && ! $regenerate) { |
|
| 1969 | 1969 | // Doing nothing, when API Key exists but still try to generate again instead of regenerating. |
| 1970 | 1970 | return false; |
| 1971 | 1971 | } else { |
| 1972 | 1972 | // Revoke API Key. |
| 1973 | - $this->revoke_api_key( $user->ID ); |
|
| 1973 | + $this->revoke_api_key($user->ID); |
|
| 1974 | 1974 | } |
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1978 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1977 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1978 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1979 | 1979 | |
| 1980 | 1980 | return true; |
| 1981 | 1981 | } |
@@ -1990,26 +1990,26 @@ discard block |
||
| 1990 | 1990 | * |
| 1991 | 1991 | * @return bool |
| 1992 | 1992 | */ |
| 1993 | - public function revoke_api_key( $user_id = 0 ) { |
|
| 1993 | + public function revoke_api_key($user_id = 0) { |
|
| 1994 | 1994 | |
| 1995 | - if ( empty( $user_id ) ) { |
|
| 1995 | + if (empty($user_id)) { |
|
| 1996 | 1996 | return false; |
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | - $user = get_userdata( $user_id ); |
|
| 1999 | + $user = get_userdata($user_id); |
|
| 2000 | 2000 | |
| 2001 | - if ( ! $user ) { |
|
| 2001 | + if ( ! $user) { |
|
| 2002 | 2002 | return false; |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 2006 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 2007 | - if ( ! empty( $public_key ) ) { |
|
| 2008 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_' . $public_key ) ) ); |
|
| 2009 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_public_key' . $user_id ) ) ); |
|
| 2010 | - Give_Cache::delete( Give_Cache::get_key( md5( 'give_api_user_secret_key' . $user_id ) ) ); |
|
| 2011 | - delete_user_meta( $user_id, $public_key ); |
|
| 2012 | - delete_user_meta( $user_id, $secret_key ); |
|
| 2005 | + $public_key = $this->get_user_public_key($user_id); |
|
| 2006 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 2007 | + if ( ! empty($public_key)) { |
|
| 2008 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_'.$public_key))); |
|
| 2009 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_public_key'.$user_id))); |
|
| 2010 | + Give_Cache::delete(Give_Cache::get_key(md5('give_api_user_secret_key'.$user_id))); |
|
| 2011 | + delete_user_meta($user_id, $public_key); |
|
| 2012 | + delete_user_meta($user_id, $secret_key); |
|
| 2013 | 2013 | } else { |
| 2014 | 2014 | return false; |
| 2015 | 2015 | } |
@@ -2031,9 +2031,9 @@ discard block |
||
| 2031 | 2031 | * |
| 2032 | 2032 | * @return string |
| 2033 | 2033 | */ |
| 2034 | - private function generate_public_key( $user_email = '' ) { |
|
| 2035 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2036 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
| 2034 | + private function generate_public_key($user_email = '') { |
|
| 2035 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2036 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
| 2037 | 2037 | |
| 2038 | 2038 | return $public; |
| 2039 | 2039 | } |
@@ -2048,9 +2048,9 @@ discard block |
||
| 2048 | 2048 | * |
| 2049 | 2049 | * @return string |
| 2050 | 2050 | */ |
| 2051 | - private function generate_private_key( $user_id = 0 ) { |
|
| 2052 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2053 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
| 2051 | + private function generate_private_key($user_id = 0) { |
|
| 2052 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2053 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
| 2054 | 2054 | |
| 2055 | 2055 | return $secret; |
| 2056 | 2056 | } |
@@ -2065,8 +2065,8 @@ discard block |
||
| 2065 | 2065 | * |
| 2066 | 2066 | * @return string |
| 2067 | 2067 | */ |
| 2068 | - public function get_token( $user_id = 0 ) { |
|
| 2069 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
| 2068 | + public function get_token($user_id = 0) { |
|
| 2069 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | /** |
@@ -2080,9 +2080,9 @@ discard block |
||
| 2080 | 2080 | |
| 2081 | 2081 | // Default sales return |
| 2082 | 2082 | $donations = array(); |
| 2083 | - $donations['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
| 2084 | - $donations['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
| 2085 | - $donations['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
| 2083 | + $donations['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
| 2084 | + $donations['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
| 2085 | + $donations['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
| 2086 | 2086 | $donations['donations']['totals'] = give_get_total_donations(); |
| 2087 | 2087 | |
| 2088 | 2088 | return $donations; |
@@ -2099,9 +2099,9 @@ discard block |
||
| 2099 | 2099 | |
| 2100 | 2100 | // Default earnings return |
| 2101 | 2101 | $earnings = array(); |
| 2102 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
| 2103 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
| 2104 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
| 2102 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
| 2103 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
| 2104 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
| 2105 | 2105 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
| 2106 | 2106 | |
| 2107 | 2107 | return $earnings; |
@@ -2121,25 +2121,25 @@ discard block |
||
| 2121 | 2121 | * |
| 2122 | 2122 | * @return string The API key/secret for the user supplied |
| 2123 | 2123 | */ |
| 2124 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
| 2124 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
| 2125 | 2125 | |
| 2126 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
| 2126 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
| 2127 | 2127 | return $check; |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | 2130 | $return = $check; |
| 2131 | 2131 | |
| 2132 | - switch ( $meta_key ) { |
|
| 2132 | + switch ($meta_key) { |
|
| 2133 | 2133 | case 'give_user_public_key': |
| 2134 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
| 2134 | + $return = Give()->api->get_user_public_key($object_id); |
|
| 2135 | 2135 | break; |
| 2136 | 2136 | case 'give_user_secret_key': |
| 2137 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
| 2137 | + $return = Give()->api->get_user_secret_key($object_id); |
|
| 2138 | 2138 | break; |
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | - if ( ! $single ) { |
|
| 2142 | - $return = array( $return ); |
|
| 2141 | + if ( ! $single) { |
|
| 2142 | + $return = array($return); |
|
| 2143 | 2143 | } |
| 2144 | 2144 | |
| 2145 | 2145 | return $return; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | /* @var WPDB $wpdb */ |
| 51 | 51 | global $wpdb; |
| 52 | 52 | |
| 53 | - $wpdb->formmeta = $this->table_name = $wpdb->prefix . 'give_formmeta'; |
|
| 53 | + $wpdb->formmeta = $this->table_name = $wpdb->prefix.'give_formmeta'; |
|
| 54 | 54 | $this->primary_key = 'meta_id'; |
| 55 | 55 | $this->version = '1.0'; |
| 56 | 56 | |
@@ -84,6 +84,6 @@ discard block |
||
| 84 | 84 | * @return bool |
| 85 | 85 | */ |
| 86 | 86 | protected function is_custom_meta_table_active() { |
| 87 | - return give_has_upgrade_completed( 'v20_move_metadata_into_new_table' ); |
|
| 87 | + return give_has_upgrade_completed('v20_move_metadata_into_new_table'); |
|
| 88 | 88 | } |
| 89 | 89 | } |
@@ -9,11 +9,11 @@ discard block |
||
| 9 | 9 | * @since 1.8 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | +if ( ! defined('ABSPATH')) { |
|
| 13 | 13 | exit; // Exit if accessed directly |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | -if ( ! class_exists( 'Give_Settings_Logs' ) ) : |
|
| 16 | +if ( ! class_exists('Give_Settings_Logs')) : |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Give_Settings_Logs. |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct() { |
| 36 | 36 | $this->id = 'logs'; |
| 37 | - $this->label = __( 'Logs', 'give' ); |
|
| 37 | + $this->label = __('Logs', 'give'); |
|
| 38 | 38 | |
| 39 | 39 | $this->default_tab = 'sales'; |
| 40 | 40 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function get_settings() { |
| 52 | 52 | // Get settings. |
| 53 | - $settings = apply_filters( 'give_settings_logs', array( |
|
| 53 | + $settings = apply_filters('give_settings_logs', array( |
|
| 54 | 54 | array( |
| 55 | 55 | 'id' => 'give_tools_logs', |
| 56 | 56 | 'type' => 'title', |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ), |
| 59 | 59 | array( |
| 60 | 60 | 'id' => 'logs', |
| 61 | - 'name' => __( 'Log', 'give' ), |
|
| 61 | + 'name' => __('Log', 'give'), |
|
| 62 | 62 | 'type' => 'logs', |
| 63 | 63 | |
| 64 | 64 | ), |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | 'type' => 'sectionend', |
| 68 | 68 | 'table_html' => false, |
| 69 | 69 | ), |
| 70 | - ) ); |
|
| 70 | + )); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Filter the settings. |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @param array $settings |
| 78 | 78 | */ |
| 79 | - $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
|
| 79 | + $settings = apply_filters('give_get_settings_'.$this->id, $settings); |
|
| 80 | 80 | |
| 81 | 81 | // Output. |
| 82 | 82 | return $settings; |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function get_sections() { |
| 92 | 92 | $sections = array( |
| 93 | - 'sales' => __( 'Donations', 'give' ), |
|
| 94 | - 'gateway_errors' => __( 'Payment Errors', 'give' ), |
|
| 95 | - 'api_requests' => __( 'API Requests', 'give' ), |
|
| 96 | - 'updates' => __( 'Updates', 'give' ), |
|
| 93 | + 'sales' => __('Donations', 'give'), |
|
| 94 | + 'gateway_errors' => __('Payment Errors', 'give'), |
|
| 95 | + 'api_requests' => __('API Requests', 'give'), |
|
| 96 | + 'updates' => __('Updates', 'give'), |
|
| 97 | 97 | ); |
| 98 | 98 | |
| 99 | - $sections = apply_filters( 'give_log_views', $sections ); |
|
| 99 | + $sections = apply_filters('give_log_views', $sections); |
|
| 100 | 100 | |
| 101 | - return apply_filters( 'give_get_sections_' . $this->id, $sections ); |
|
| 101 | + return apply_filters('give_get_sections_'.$this->id, $sections); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -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 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function give_get_logs_tab() { |
| 24 | 24 | |
| 25 | - require( GIVE_PLUGIN_DIR . 'includes/admin/tools/logs/logs.php' ); |
|
| 25 | + require(GIVE_PLUGIN_DIR.'includes/admin/tools/logs/logs.php'); |
|
| 26 | 26 | |
| 27 | 27 | // Get current section. |
| 28 | 28 | $current_section = $_GET['section'] = give_get_current_setting_section(); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @since 1.0 |
| 34 | 34 | */ |
| 35 | - do_action( "give_logs_view_{$current_section}" ); |
|
| 35 | + do_action("give_logs_view_{$current_section}"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function give_logs_view_sales() { |
| 48 | 48 | |
| 49 | - include GIVE_PLUGIN_DIR . 'includes/admin/tools/logs/class-sales-logs-list-table.php'; |
|
| 49 | + include GIVE_PLUGIN_DIR.'includes/admin/tools/logs/class-sales-logs-list-table.php'; |
|
| 50 | 50 | |
| 51 | 51 | $logs_table = new Give_Sales_Log_Table(); |
| 52 | 52 | $logs_table->prepare_items(); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @since 1.8.12 |
| 61 | 61 | */ |
| 62 | - do_action( 'give_logs_donations_top' ); |
|
| 62 | + do_action('give_logs_donations_top'); |
|
| 63 | 63 | |
| 64 | 64 | $logs_table->display(); ?> |
| 65 | 65 | <input type="hidden" name="post_type" value="give_forms"/> |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @since 1.8.12 |
| 75 | 75 | */ |
| 76 | - do_action( 'give_logs_donations_bottom' ); |
|
| 76 | + do_action('give_logs_donations_bottom'); |
|
| 77 | 77 | ?> |
| 78 | 78 | |
| 79 | 79 | </div> |
| 80 | 80 | <?php |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | -add_action( 'give_logs_view_sales', 'give_logs_view_sales' ); |
|
| 83 | +add_action('give_logs_view_sales', 'give_logs_view_sales'); |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Update Logs |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | 92 | function give_logs_view_updates() { |
| 93 | - include( GIVE_PLUGIN_DIR . 'includes/admin/tools/logs/class-update-logs-list-table.php' ); |
|
| 93 | + include(GIVE_PLUGIN_DIR.'includes/admin/tools/logs/class-update-logs-list-table.php'); |
|
| 94 | 94 | |
| 95 | 95 | $logs_table = new Give_Update_Log_Table(); |
| 96 | 96 | $logs_table->prepare_items(); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @since 2.0.1 |
| 105 | 105 | */ |
| 106 | - do_action( 'give_logs_update_top' ); |
|
| 106 | + do_action('give_logs_update_top'); |
|
| 107 | 107 | |
| 108 | 108 | $logs_table->display(); ?> |
| 109 | 109 | <input type="hidden" name="post_type" value="give_forms"/> |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @since 2.0.1 |
| 119 | 119 | */ |
| 120 | - do_action( 'give_logs_update_bottom' ); |
|
| 120 | + do_action('give_logs_update_bottom'); |
|
| 121 | 121 | ?> |
| 122 | 122 | |
| 123 | 123 | </div> |
| 124 | 124 | <?php |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | -add_action( 'give_logs_view_updates', 'give_logs_view_updates' ); |
|
| 127 | +add_action('give_logs_view_updates', 'give_logs_view_updates'); |
|
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * Gateway Error Logs |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | 137 | function give_logs_view_gateway_errors() { |
| 138 | - include( GIVE_PLUGIN_DIR . 'includes/admin/tools/logs/class-gateway-error-logs-list-table.php' ); |
|
| 138 | + include(GIVE_PLUGIN_DIR.'includes/admin/tools/logs/class-gateway-error-logs-list-table.php'); |
|
| 139 | 139 | |
| 140 | 140 | $logs_table = new Give_Gateway_Error_Log_Table(); |
| 141 | 141 | $logs_table->prepare_items(); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @since 1.8.12 |
| 150 | 150 | */ |
| 151 | - do_action( 'give_logs_payment_error_top' ); |
|
| 151 | + do_action('give_logs_payment_error_top'); |
|
| 152 | 152 | |
| 153 | 153 | $logs_table->display(); ?> |
| 154 | 154 | <input type="hidden" name="post_type" value="give_forms"/> |
@@ -162,14 +162,14 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @since 1.8.12 |
| 164 | 164 | */ |
| 165 | - do_action( 'give_logs_payment_error_bottom' ); |
|
| 165 | + do_action('give_logs_payment_error_bottom'); |
|
| 166 | 166 | ?> |
| 167 | 167 | |
| 168 | 168 | </div> |
| 169 | 169 | <?php |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | -add_action( 'give_logs_view_gateway_errors', 'give_logs_view_gateway_errors' ); |
|
| 172 | +add_action('give_logs_view_gateway_errors', 'give_logs_view_gateway_errors'); |
|
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * API Request Logs |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | */ |
| 182 | 182 | function give_logs_view_api_requests() { |
| 183 | - include( GIVE_PLUGIN_DIR . 'includes/admin/tools/logs/class-api-requests-logs-list-table.php' ); |
|
| 183 | + include(GIVE_PLUGIN_DIR.'includes/admin/tools/logs/class-api-requests-logs-list-table.php'); |
|
| 184 | 184 | |
| 185 | 185 | $logs_table = new Give_API_Request_Log_Table(); |
| 186 | 186 | $logs_table->prepare_items(); |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @since 1.0 |
| 192 | 192 | */ |
| 193 | - do_action( 'give_logs_api_requests_top' ); |
|
| 193 | + do_action('give_logs_api_requests_top'); |
|
| 194 | 194 | |
| 195 | - $logs_table->search_box( esc_html__( 'Search', 'give' ), 'give-api-requests' ); |
|
| 195 | + $logs_table->search_box(esc_html__('Search', 'give'), 'give-api-requests'); |
|
| 196 | 196 | $logs_table->display(); |
| 197 | 197 | ?> |
| 198 | 198 | <input type="hidden" name="post_type" value="give_forms"/> |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @since 1.0 |
| 208 | 208 | */ |
| 209 | - do_action( 'give_logs_api_requests_bottom' ); |
|
| 209 | + do_action('give_logs_api_requests_bottom'); |
|
| 210 | 210 | } |
| 211 | -add_action( 'give_logs_view_api_requests', 'give_logs_view_api_requests' ); |
|
| 211 | +add_action('give_logs_view_api_requests', 'give_logs_view_api_requests'); |
|
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Renders the log views drop down. |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | $current_section = give_get_current_setting_section(); |
| 221 | 221 | |
| 222 | 222 | // If there are not any event attach to action then do not show form. |
| 223 | - if ( ! has_action( 'give_log_view_actions' ) ) { |
|
| 223 | + if ( ! has_action('give_log_view_actions')) { |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | ?> |
| 227 | - <form id="give-logs-filter" method="get" action="<?php echo 'edit.php?post_type=give_forms&page=give-tools&tab=logs§ion=' . $current_section; ?>"> |
|
| 227 | + <form id="give-logs-filter" method="get" action="<?php echo 'edit.php?post_type=give_forms&page=give-tools&tab=logs§ion='.$current_section; ?>"> |
|
| 228 | 228 | <?php |
| 229 | 229 | /** |
| 230 | 230 | * Fires after displaying the reports page views drop down. |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @since 1.0 |
| 235 | 235 | */ |
| 236 | - do_action( 'give_log_view_actions' ); |
|
| 236 | + do_action('give_log_view_actions'); |
|
| 237 | 237 | ?> |
| 238 | 238 | |
| 239 | 239 | <input type="hidden" name="post_type" value="give_forms"/> |
| 240 | 240 | <input type="hidden" name="page" value="give-tools"/> |
| 241 | 241 | <input type="hidden" name="tab" value="logs"/> |
| 242 | 242 | |
| 243 | - <?php submit_button( esc_html__( 'Apply', 'give' ), 'secondary', 'submit', false ); ?> |
|
| 243 | + <?php submit_button(esc_html__('Apply', 'give'), 'secondary', 'submit', false); ?> |
|
| 244 | 244 | </form> |
| 245 | 245 | <?php |
| 246 | 246 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * |
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | -function give_tools_set_form_method( $method ) { |
|
| 255 | +function give_tools_set_form_method($method) { |
|
| 256 | 256 | return 'get'; |
| 257 | 257 | } |
| 258 | -add_filter( 'give-tools_form_method_tab_logs', 'give_tools_set_form_method', 10 ); |
|
| 258 | +add_filter('give-tools_form_method_tab_logs', 'give_tools_set_form_method', 10); |
|
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | /* @var WPDB $wpdb */ |
| 51 | 51 | global $wpdb; |
| 52 | 52 | |
| 53 | - $wpdb->logmeta = $this->table_name = $wpdb->prefix . 'give_logmeta'; |
|
| 53 | + $wpdb->logmeta = $this->table_name = $wpdb->prefix.'give_logmeta'; |
|
| 54 | 54 | $this->primary_key = 'meta_id'; |
| 55 | 55 | $this->version = '1.0'; |
| 56 | 56 | |
@@ -86,18 +86,18 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | - public function delete_row( $log_id = 0 ) { |
|
| 89 | + public function delete_row($log_id = 0) { |
|
| 90 | 90 | /* @var WPDB $wpdb */ |
| 91 | 91 | global $wpdb; |
| 92 | 92 | |
| 93 | 93 | // Row ID must be positive integer |
| 94 | - $log_id = absint( $log_id ); |
|
| 94 | + $log_id = absint($log_id); |
|
| 95 | 95 | |
| 96 | - if ( empty( $log_id ) ) { |
|
| 96 | + if (empty($log_id)) { |
|
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE log_id = %d", $log_id ) ) ) { |
|
| 100 | + if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE log_id = %d", $log_id))) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return bool |
| 116 | 116 | */ |
| 117 | - protected function is_valid_post_type( $ID ) { |
|
| 117 | + protected function is_valid_post_type($ID) { |
|
| 118 | 118 | return $ID && true; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -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 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * Constructor. |
| 50 | 50 | */ |
| 51 | - public function __construct( $_step = 1 ) { |
|
| 52 | - parent::__construct( $_step ); |
|
| 51 | + public function __construct($_step = 1) { |
|
| 52 | + parent::__construct($_step); |
|
| 53 | 53 | |
| 54 | 54 | $this->is_writable = true; |
| 55 | 55 | } |
@@ -66,32 +66,32 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | $args = array( |
| 68 | 68 | 'number' => $this->per_step, |
| 69 | - 'offset' => $this->per_step * ( $this->step - 1 ), |
|
| 69 | + 'offset' => $this->per_step * ($this->step - 1), |
|
| 70 | 70 | 'orderby' => 'id', |
| 71 | 71 | 'order' => 'DESC', |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - $donors = Give()->donors->get_donors( $args ); |
|
| 74 | + $donors = Give()->donors->get_donors($args); |
|
| 75 | 75 | |
| 76 | - if ( $donors ) { |
|
| 76 | + if ($donors) { |
|
| 77 | 77 | |
| 78 | - $allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() ); |
|
| 78 | + $allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys()); |
|
| 79 | 79 | |
| 80 | - foreach ( $donors as $donor ) { |
|
| 80 | + foreach ($donors as $donor) { |
|
| 81 | 81 | |
| 82 | - $attached_payment_ids = explode( ',', $donor->payment_ids ); |
|
| 82 | + $attached_payment_ids = explode(',', $donor->payment_ids); |
|
| 83 | 83 | |
| 84 | 84 | $attached_args = array( |
| 85 | 85 | 'post__in' => $attached_payment_ids, |
| 86 | - 'number' => - 1, |
|
| 86 | + 'number' => -1, |
|
| 87 | 87 | 'status' => $allowed_payment_status, |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - $attached_payments = (array) give_get_payments( $attached_args ); |
|
| 90 | + $attached_payments = (array) give_get_payments($attached_args); |
|
| 91 | 91 | |
| 92 | 92 | $unattached_args = array( |
| 93 | 93 | 'post__not_in' => $attached_payment_ids, |
| 94 | - 'number' => - 1, |
|
| 94 | + 'number' => -1, |
|
| 95 | 95 | 'status' => $allowed_payment_status, |
| 96 | 96 | 'meta_query' => array( |
| 97 | 97 | array( |
@@ -102,29 +102,29 @@ discard block |
||
| 102 | 102 | ), |
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | - $unattached_payments = give_get_payments( $unattached_args ); |
|
| 105 | + $unattached_payments = give_get_payments($unattached_args); |
|
| 106 | 106 | |
| 107 | - $payments = array_merge( $attached_payments, $unattached_payments ); |
|
| 107 | + $payments = array_merge($attached_payments, $unattached_payments); |
|
| 108 | 108 | |
| 109 | 109 | $purchase_value = 0.00; |
| 110 | 110 | $purchase_count = 0; |
| 111 | 111 | $payment_ids = array(); |
| 112 | 112 | |
| 113 | - if ( $payments ) { |
|
| 113 | + if ($payments) { |
|
| 114 | 114 | |
| 115 | - foreach ( $payments as $payment ) { |
|
| 115 | + foreach ($payments as $payment) { |
|
| 116 | 116 | |
| 117 | 117 | $should_process_payment = 'publish' == $payment->post_status ? true : false; |
| 118 | - $should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment ); |
|
| 118 | + $should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment); |
|
| 119 | 119 | |
| 120 | - if ( true === $should_process_payment ) { |
|
| 120 | + if (true === $should_process_payment) { |
|
| 121 | 121 | |
| 122 | - if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) { |
|
| 123 | - $purchase_value += (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) ); |
|
| 122 | + if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) { |
|
| 123 | + $purchase_value += (float) give_donation_amount($payment->ID, array('type' => 'stats')); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) { |
|
| 127 | - $purchase_count ++; |
|
| 126 | + if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) { |
|
| 127 | + $purchase_count++; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - $payment_ids = implode( ',', $payment_ids ); |
|
| 135 | + $payment_ids = implode(',', $payment_ids); |
|
| 136 | 136 | |
| 137 | 137 | $donor_update_data = array( |
| 138 | 138 | 'purchase_count' => $purchase_count, |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | 'payment_ids' => $payment_ids, |
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | - $donor_instance = new Give_Donor( $donor->id ); |
|
| 144 | - $donor_instance->update( $donor_update_data ); |
|
| 143 | + $donor_instance = new Give_Donor($donor->id); |
|
| 144 | + $donor_instance->update($donor_update_data); |
|
| 145 | 145 | |
| 146 | 146 | }// End foreach(). |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | public function get_percentage_complete() { |
| 162 | 162 | |
| 163 | 163 | $args = array( |
| 164 | - 'number' => - 1, |
|
| 164 | + 'number' => -1, |
|
| 165 | 165 | 'orderby' => 'id', |
| 166 | 166 | 'order' => 'DESC', |
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | - $donors = Give()->donors->get_donors( $args ); |
|
| 170 | - $total = count( $donors ); |
|
| 169 | + $donors = Give()->donors->get_donors($args); |
|
| 170 | + $total = count($donors); |
|
| 171 | 171 | |
| 172 | 172 | $percentage = 100; |
| 173 | 173 | |
| 174 | - if ( $total > 0 ) { |
|
| 175 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
| 174 | + if ($total > 0) { |
|
| 175 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( $percentage > 100 ) { |
|
| 178 | + if ($percentage > 100) { |
|
| 179 | 179 | $percentage = 100; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @param array $request The Form Data passed into the batch processing |
| 191 | 191 | */ |
| 192 | - public function set_properties( $request ) { |
|
| 192 | + public function set_properties($request) { |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,21 +200,21 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function process_step() { |
| 202 | 202 | |
| 203 | - if ( ! $this->can_export() ) { |
|
| 204 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
| 203 | + if ( ! $this->can_export()) { |
|
| 204 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array( |
|
| 205 | 205 | 'response' => 403, |
| 206 | - ) ); |
|
| 206 | + )); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | $had_data = $this->get_data(); |
| 210 | 210 | |
| 211 | - if ( $had_data ) { |
|
| 211 | + if ($had_data) { |
|
| 212 | 212 | $this->done = false; |
| 213 | 213 | |
| 214 | 214 | return true; |
| 215 | 215 | } else { |
| 216 | 216 | $this->done = true; |
| 217 | - $this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' ); |
|
| 217 | + $this->message = esc_html__('Donor stats have been successfully recounted.', 'give'); |
|
| 218 | 218 | |
| 219 | 219 | return false; |
| 220 | 220 | } |
@@ -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 | |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * Constructor. |
| 48 | 48 | */ |
| 49 | - public function __construct( $_step = 1 ) { |
|
| 50 | - parent::__construct( $_step ); |
|
| 49 | + public function __construct($_step = 1) { |
|
| 50 | + parent::__construct($_step); |
|
| 51 | 51 | |
| 52 | 52 | $this->is_writable = true; |
| 53 | 53 | } |
@@ -62,40 +62,40 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function get_data() { |
| 64 | 64 | |
| 65 | - $donor = new Give_Donor( $this->customer_id ); |
|
| 66 | - $payments = $this->get_stored_data( 'give_recount_donor_payments_' . $donor->id ); |
|
| 65 | + $donor = new Give_Donor($this->customer_id); |
|
| 66 | + $payments = $this->get_stored_data('give_recount_donor_payments_'.$donor->id); |
|
| 67 | 67 | |
| 68 | - $offset = ( $this->step - 1 ) * $this->per_step; |
|
| 69 | - $step_items = array_slice( $payments, $offset, $this->per_step ); |
|
| 68 | + $offset = ($this->step - 1) * $this->per_step; |
|
| 69 | + $step_items = array_slice($payments, $offset, $this->per_step); |
|
| 70 | 70 | |
| 71 | - if ( count( $step_items ) > 0 ) { |
|
| 72 | - $pending_total = (float) $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
| 71 | + if (count($step_items) > 0) { |
|
| 72 | + $pending_total = (float) $this->get_stored_data('give_stats_donor_pending_total'.$donor->id); |
|
| 73 | 73 | $step_total = 0; |
| 74 | 74 | |
| 75 | - $found_payment_ids = $this->get_stored_data( 'give_stats_found_payments_' . $donor->id ); |
|
| 75 | + $found_payment_ids = $this->get_stored_data('give_stats_found_payments_'.$donor->id); |
|
| 76 | 76 | |
| 77 | - foreach ( $step_items as $payment ) { |
|
| 78 | - $payment = get_post( $payment->ID ); |
|
| 77 | + foreach ($step_items as $payment) { |
|
| 78 | + $payment = get_post($payment->ID); |
|
| 79 | 79 | |
| 80 | - if ( is_null( $payment ) || is_wp_error( $payment ) || 'give_payment' !== $payment->post_type ) { |
|
| 80 | + if (is_null($payment) || is_wp_error($payment) || 'give_payment' !== $payment->post_type) { |
|
| 81 | 81 | |
| 82 | - $missing_payments = $this->get_stored_data( 'give_stats_missing_payments' . $donor->id ); |
|
| 82 | + $missing_payments = $this->get_stored_data('give_stats_missing_payments'.$donor->id); |
|
| 83 | 83 | $missing_payments[] = $payment->ID; |
| 84 | - $this->store_data( 'give_stats_missing_payments' . $donor->id, $missing_payments ); |
|
| 84 | + $this->store_data('give_stats_missing_payments'.$donor->id, $missing_payments); |
|
| 85 | 85 | |
| 86 | 86 | continue; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | $should_process_payment = 'publish' == $payment->post_status ? true : false; |
| 90 | - $should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment ); |
|
| 90 | + $should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment); |
|
| 91 | 91 | |
| 92 | - if ( true === $should_process_payment ) { |
|
| 92 | + if (true === $should_process_payment) { |
|
| 93 | 93 | |
| 94 | 94 | $found_payment_ids[] = $payment->ID; |
| 95 | 95 | |
| 96 | - if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) { |
|
| 97 | - $payment_amount = (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) ); |
|
| 98 | - $step_total += $payment_amount; |
|
| 96 | + if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) { |
|
| 97 | + $payment_amount = (float) give_donation_amount($payment->ID, array('type' => 'stats')); |
|
| 98 | + $step_total += $payment_amount; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | } |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $updated_total = $pending_total + $step_total; |
| 106 | - $this->store_data( 'give_stats_donor_pending_total' . $donor->id, $updated_total ); |
|
| 107 | - $this->store_data( 'give_stats_found_payments_' . $donor->id, $found_payment_ids ); |
|
| 106 | + $this->store_data('give_stats_donor_pending_total'.$donor->id, $updated_total); |
|
| 107 | + $this->store_data('give_stats_found_payments_'.$donor->id, $found_payment_ids); |
|
| 108 | 108 | |
| 109 | 109 | return true; |
| 110 | 110 | } |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function get_percentage_complete() { |
| 123 | 123 | |
| 124 | - $payments = $this->get_stored_data( 'give_recount_donor_payments_' . $this->customer_id ); |
|
| 125 | - $total = count( $payments ); |
|
| 124 | + $payments = $this->get_stored_data('give_recount_donor_payments_'.$this->customer_id); |
|
| 125 | + $total = count($payments); |
|
| 126 | 126 | |
| 127 | 127 | $percentage = 100; |
| 128 | 128 | |
| 129 | - if ( $total > 0 ) { |
|
| 130 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
| 129 | + if ($total > 0) { |
|
| 130 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if ( $percentage > 100 ) { |
|
| 133 | + if ($percentage > 100) { |
|
| 134 | 134 | $percentage = 100; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param array $request The Form Data passed into the batch processing |
| 146 | 146 | */ |
| 147 | - public function set_properties( $request ) { |
|
| 148 | - $this->customer_id = isset( $request['customer_id'] ) ? sanitize_text_field( $request['customer_id'] ) : false; |
|
| 147 | + public function set_properties($request) { |
|
| 148 | + $this->customer_id = isset($request['customer_id']) ? sanitize_text_field($request['customer_id']) : false; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -156,53 +156,53 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function process_step() { |
| 158 | 158 | |
| 159 | - if ( ! $this->can_export() ) { |
|
| 160 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 159 | + if ( ! $this->can_export()) { |
|
| 160 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $had_data = $this->get_data(); |
| 164 | 164 | |
| 165 | - if ( $had_data ) { |
|
| 165 | + if ($had_data) { |
|
| 166 | 166 | $this->done = false; |
| 167 | 167 | |
| 168 | 168 | return true; |
| 169 | 169 | } else { |
| 170 | - $donor = new Give_Donor( $this->customer_id ); |
|
| 171 | - $payment_ids = get_option( 'give_stats_found_payments_' . $donor->id, array() ); |
|
| 172 | - $this->delete_data( 'give_stats_found_payments_' . $donor->id ); |
|
| 170 | + $donor = new Give_Donor($this->customer_id); |
|
| 171 | + $payment_ids = get_option('give_stats_found_payments_'.$donor->id, array()); |
|
| 172 | + $this->delete_data('give_stats_found_payments_'.$donor->id); |
|
| 173 | 173 | |
| 174 | - $removed_payments = array_unique( get_option( 'give_stats_missing_payments' . $donor->id, array() ) ); |
|
| 174 | + $removed_payments = array_unique(get_option('give_stats_missing_payments'.$donor->id, array())); |
|
| 175 | 175 | |
| 176 | 176 | // Find non-existing payments (deleted) and total up the donation count |
| 177 | 177 | $purchase_count = 0; |
| 178 | - foreach ( $payment_ids as $key => $payment_id ) { |
|
| 179 | - if ( in_array( $payment_id, $removed_payments ) ) { |
|
| 180 | - unset( $payment_ids[ $key ] ); |
|
| 178 | + foreach ($payment_ids as $key => $payment_id) { |
|
| 179 | + if (in_array($payment_id, $removed_payments)) { |
|
| 180 | + unset($payment_ids[$key]); |
|
| 181 | 181 | continue; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $payment = get_post( $payment_id ); |
|
| 185 | - if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) { |
|
| 186 | - $purchase_count ++; |
|
| 184 | + $payment = get_post($payment_id); |
|
| 185 | + if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) { |
|
| 186 | + $purchase_count++; |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $this->delete_data( 'give_stats_missing_payments' . $donor->id ); |
|
| 190 | + $this->delete_data('give_stats_missing_payments'.$donor->id); |
|
| 191 | 191 | |
| 192 | - $pending_total = $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
| 193 | - $this->delete_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
| 194 | - $this->delete_data( 'give_recount_donor_stats_' . $donor->id ); |
|
| 195 | - $this->delete_data( 'give_recount_donor_payments_' . $this->customer_id ); |
|
| 192 | + $pending_total = $this->get_stored_data('give_stats_donor_pending_total'.$donor->id); |
|
| 193 | + $this->delete_data('give_stats_donor_pending_total'.$donor->id); |
|
| 194 | + $this->delete_data('give_recount_donor_stats_'.$donor->id); |
|
| 195 | + $this->delete_data('give_recount_donor_payments_'.$this->customer_id); |
|
| 196 | 196 | |
| 197 | - $payment_ids = implode( ',', $payment_ids ); |
|
| 198 | - $donor->update( array( |
|
| 197 | + $payment_ids = implode(',', $payment_ids); |
|
| 198 | + $donor->update(array( |
|
| 199 | 199 | 'payment_ids' => $payment_ids, |
| 200 | 200 | 'purchase_count' => $purchase_count, |
| 201 | 201 | 'purchase_value' => $pending_total, |
| 202 | - ) ); |
|
| 202 | + )); |
|
| 203 | 203 | |
| 204 | 204 | $this->done = true; |
| 205 | - $this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' ); |
|
| 205 | + $this->message = esc_html__('Donor stats have been successfully recounted.', 'give'); |
|
| 206 | 206 | |
| 207 | 207 | return false; |
| 208 | 208 | } |
@@ -235,26 +235,26 @@ discard block |
||
| 235 | 235 | * @return void |
| 236 | 236 | */ |
| 237 | 237 | public function pre_fetch() { |
| 238 | - if ( $this->step === 1 ) { |
|
| 239 | - $allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() ); |
|
| 238 | + if ($this->step === 1) { |
|
| 239 | + $allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys()); |
|
| 240 | 240 | |
| 241 | 241 | // Before we start, let's zero out the customer's data |
| 242 | - $donor = new Give_Donor( $this->customer_id ); |
|
| 243 | - $donor->update( array( 'purchase_value' => give_format_amount( 0, array( 'sanitize' => false ) ), 'purchase_count' => 0 ) ); |
|
| 242 | + $donor = new Give_Donor($this->customer_id); |
|
| 243 | + $donor->update(array('purchase_value' => give_format_amount(0, array('sanitize' => false)), 'purchase_count' => 0)); |
|
| 244 | 244 | |
| 245 | - $attached_payment_ids = explode( ',', $donor->payment_ids ); |
|
| 245 | + $attached_payment_ids = explode(',', $donor->payment_ids); |
|
| 246 | 246 | |
| 247 | 247 | $attached_args = array( |
| 248 | 248 | 'post__in' => $attached_payment_ids, |
| 249 | - 'number' => - 1, |
|
| 249 | + 'number' => -1, |
|
| 250 | 250 | 'status' => $allowed_payment_status, |
| 251 | 251 | ); |
| 252 | 252 | |
| 253 | - $attached_payments = give_get_payments( $attached_args ); |
|
| 253 | + $attached_payments = give_get_payments($attached_args); |
|
| 254 | 254 | |
| 255 | 255 | $unattached_args = array( |
| 256 | 256 | 'post__not_in' => $attached_payment_ids, |
| 257 | - 'number' => - 1, |
|
| 257 | + 'number' => -1, |
|
| 258 | 258 | 'status' => $allowed_payment_status, |
| 259 | 259 | 'meta_query' => array( |
| 260 | 260 | array( |
@@ -264,11 +264,11 @@ discard block |
||
| 264 | 264 | ), |
| 265 | 265 | ); |
| 266 | 266 | |
| 267 | - $unattached_payments = give_get_payments( $unattached_args ); |
|
| 267 | + $unattached_payments = give_get_payments($unattached_args); |
|
| 268 | 268 | |
| 269 | - $payments = array_merge( $attached_payments, $unattached_payments ); |
|
| 269 | + $payments = array_merge($attached_payments, $unattached_payments); |
|
| 270 | 270 | |
| 271 | - $this->store_data( 'give_recount_donor_payments_' . $donor->id, $payments ); |
|
| 271 | + $this->store_data('give_recount_donor_payments_'.$donor->id, $payments); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -281,17 +281,17 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @return mixed Returns the data from the database |
| 283 | 283 | */ |
| 284 | - private function get_stored_data( $key ) { |
|
| 284 | + private function get_stored_data($key) { |
|
| 285 | 285 | global $wpdb; |
| 286 | - $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) ); |
|
| 286 | + $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key)); |
|
| 287 | 287 | |
| 288 | - if ( empty( $value ) ) { |
|
| 288 | + if (empty($value)) { |
|
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $maybe_json = json_decode( $value ); |
|
| 293 | - if ( ! is_null( $maybe_json ) ) { |
|
| 294 | - $value = json_decode( $value, true ); |
|
| 292 | + $maybe_json = json_decode($value); |
|
| 293 | + if ( ! is_null($maybe_json)) { |
|
| 294 | + $value = json_decode($value, true); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | return $value; |
@@ -307,10 +307,10 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @return void |
| 309 | 309 | */ |
| 310 | - private function store_data( $key, $value ) { |
|
| 310 | + private function store_data($key, $value) { |
|
| 311 | 311 | global $wpdb; |
| 312 | 312 | |
| 313 | - $value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value ); |
|
| 313 | + $value = is_array($value) ? wp_json_encode($value) : esc_attr($value); |
|
| 314 | 314 | |
| 315 | 315 | $data = array( |
| 316 | 316 | 'option_name' => $key, |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | '%s', |
| 325 | 325 | ); |
| 326 | 326 | |
| 327 | - $wpdb->replace( $wpdb->options, $data, $formats ); |
|
| 327 | + $wpdb->replace($wpdb->options, $data, $formats); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @return void |
| 338 | 338 | */ |
| 339 | - private function delete_data( $key ) { |
|
| 339 | + private function delete_data($key) { |
|
| 340 | 340 | global $wpdb; |
| 341 | - $wpdb->delete( $wpdb->options, array( 'option_name' => $key ) ); |
|
| 341 | + $wpdb->delete($wpdb->options, array('option_name' => $key)); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | } |