@@ -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 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @return Give_Session |
| 136 | 136 | */ |
| 137 | 137 | public static function get_instance() { |
| 138 | - if ( null === static::$instance ) { |
|
| 138 | + if (null === static::$instance) { |
|
| 139 | 139 | self::$instance = new static(); |
| 140 | 140 | self::$instance->__setup(); |
| 141 | 141 | } |
@@ -150,25 +150,25 @@ discard block |
||
| 150 | 150 | * @access public |
| 151 | 151 | */ |
| 152 | 152 | private function __setup() { // @codingStandardsIgnoreLine |
| 153 | - $this->exp_option = give_get_option( 'session_lifetime' ); |
|
| 154 | - $this->exp_option = ! empty( $this->exp_option ) |
|
| 153 | + $this->exp_option = give_get_option('session_lifetime'); |
|
| 154 | + $this->exp_option = ! empty($this->exp_option) |
|
| 155 | 155 | ? $this->exp_option |
| 156 | 156 | : 30 * 60 * 24; // Default expiration time is 12 hours |
| 157 | 157 | |
| 158 | 158 | $this->set_cookie_name(); |
| 159 | - $this->cookie_name = $this->get_cookie_name( 'session' ); |
|
| 159 | + $this->cookie_name = $this->get_cookie_name('session'); |
|
| 160 | 160 | $cookie = $this->get_session_cookie(); |
| 161 | 161 | |
| 162 | - if ( ! empty( $cookie ) ) { |
|
| 162 | + if ( ! empty($cookie)) { |
|
| 163 | 163 | $this->donor_id = $cookie[0]; |
| 164 | 164 | $this->session_expiration = $cookie[1]; |
| 165 | 165 | $this->session_expiring = $cookie[2]; |
| 166 | 166 | $this->has_cookie = true; |
| 167 | 167 | |
| 168 | 168 | // Update session if its close to expiring. |
| 169 | - if ( time() > $this->session_expiring ) { |
|
| 169 | + if (time() > $this->session_expiring) { |
|
| 170 | 170 | $this->set_expiration_time(); |
| 171 | - Give()->session_db->update_session_timestamp( $this->donor_id, $this->session_expiration ); |
|
| 171 | + Give()->session_db->update_session_timestamp($this->donor_id, $this->session_expiration); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Load session. |
@@ -178,17 +178,17 @@ discard block |
||
| 178 | 178 | $this->generate_donor_id(); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - add_action( 'give_process_donation_after_validation', array( $this, 'maybe_start_session' ) ); |
|
| 181 | + add_action('give_process_donation_after_validation', array($this, 'maybe_start_session')); |
|
| 182 | 182 | |
| 183 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 184 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 183 | + add_action('shutdown', array($this, 'save_data'), 20); |
|
| 184 | + add_action('wp_logout', array($this, 'destroy_session')); |
|
| 185 | 185 | |
| 186 | - if ( ! is_user_logged_in() ) { |
|
| 187 | - add_filter( 'nonce_user_logged_out', array( $this, '__nonce_user_logged_out' ) ); |
|
| 186 | + if ( ! is_user_logged_in()) { |
|
| 187 | + add_filter('nonce_user_logged_out', array($this, '__nonce_user_logged_out')); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Remove old sessions. |
| 191 | - Give_Cron::add_daily_event( array( $this, '__cleanup_sessions' ) ); |
|
| 191 | + Give_Cron::add_daily_event(array($this, '__cleanup_sessions')); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return array |
| 201 | 201 | */ |
| 202 | 202 | public function get_session_data() { |
| 203 | - return $this->has_session() ? (array) Give()->session_db->get_session( $this->donor_id, array() ) : array(); |
|
| 203 | + return $this->has_session() ? (array) Give()->session_db->get_session($this->donor_id, array()) : array(); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | |
@@ -214,27 +214,27 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function get_session_cookie() { |
| 216 | 216 | $session = array(); |
| 217 | - $cookie_value = isset( $_COOKIE[ $this->cookie_name ] ) ? give_clean( $_COOKIE[ $this->cookie_name ] ) : false; // @codingStandardsIgnoreLine. |
|
| 217 | + $cookie_value = isset($_COOKIE[$this->cookie_name]) ? give_clean($_COOKIE[$this->cookie_name]) : false; // @codingStandardsIgnoreLine. |
|
| 218 | 218 | |
| 219 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 219 | + if (empty($cookie_value) || ! is_string($cookie_value)) { |
|
| 220 | 220 | return $session; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - list( $donor_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 223 | + list($donor_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value); |
|
| 224 | 224 | |
| 225 | - if ( empty( $donor_id ) ) { |
|
| 225 | + if (empty($donor_id)) { |
|
| 226 | 226 | return $session; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Validate hash. |
| 230 | - $to_hash = $donor_id . '|' . $session_expiration; |
|
| 231 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 230 | + $to_hash = $donor_id.'|'.$session_expiration; |
|
| 231 | + $hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
| 232 | 232 | |
| 233 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 233 | + if (empty($cookie_hash) || ! hash_equals($hash, $cookie_hash)) { |
|
| 234 | 234 | return $session; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return array( $donor_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 237 | + return array($donor_id, $session_expiration, $session_expiring, $cookie_hash); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @return string Cookie name. |
| 260 | 260 | */ |
| 261 | 261 | private function set_cookie_name() { |
| 262 | - $this->cookie_name = apply_filters( 'give_session_cookie', 'wp_give_session_' . COOKIEHASH ); |
|
| 263 | - $this->nonce_cookie_name = 'wp_give_session_reset_nonce_' . COOKIEHASH; |
|
| 262 | + $this->cookie_name = apply_filters('give_session_cookie', 'wp_give_session_'.COOKIEHASH); |
|
| 263 | + $this->nonce_cookie_name = 'wp_give_session_reset_nonce_'.COOKIEHASH; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,10 +276,10 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return string|array Session variable. |
| 278 | 278 | */ |
| 279 | - public function get( $key, $default = false ) { |
|
| 280 | - $key = sanitize_key( $key ); |
|
| 279 | + public function get($key, $default = false) { |
|
| 280 | + $key = sanitize_key($key); |
|
| 281 | 281 | |
| 282 | - return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : $default; |
|
| 282 | + return isset($this->session[$key]) ? maybe_unserialize($this->session[$key]) : $default; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @return string Session variable. |
| 295 | 295 | */ |
| 296 | - public function set( $key, $value ) { |
|
| 297 | - if ( $value !== $this->get( $key ) ) { |
|
| 298 | - $this->session[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
| 296 | + public function set($key, $value) { |
|
| 297 | + if ($value !== $this->get($key)) { |
|
| 298 | + $this->session[sanitize_key($key)] = maybe_serialize($value); |
|
| 299 | 299 | $this->session_data_changed = true; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - return $this->session[ $key ]; |
|
| 302 | + return $this->session[$key]; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -313,17 +313,17 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @param bool $set Flag to check if set cookie or not. |
| 315 | 315 | */ |
| 316 | - public function set_session_cookies( $set ) { |
|
| 317 | - if ( $set ) { |
|
| 316 | + public function set_session_cookies($set) { |
|
| 317 | + if ($set) { |
|
| 318 | 318 | $this->set_expiration_time(); |
| 319 | 319 | |
| 320 | - $to_hash = $this->donor_id . '|' . $this->session_expiration; |
|
| 321 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 322 | - $cookie_value = $this->donor_id . '||' . $this->session_expiration . '||' . $this->session_expiring . '||' . $cookie_hash; |
|
| 320 | + $to_hash = $this->donor_id.'|'.$this->session_expiration; |
|
| 321 | + $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
| 322 | + $cookie_value = $this->donor_id.'||'.$this->session_expiration.'||'.$this->session_expiring.'||'.$cookie_hash; |
|
| 323 | 323 | $this->has_cookie = true; |
| 324 | 324 | |
| 325 | - give_setcookie( $this->cookie_name, $cookie_value, $this->session_expiration, apply_filters( 'give_session_use_secure_cookie', false ) ); |
|
| 326 | - give_setcookie( $this->nonce_cookie_name, '1', $this->session_expiration, apply_filters( 'give_session_use_secure_cookie', false ) ); |
|
| 325 | + give_setcookie($this->cookie_name, $cookie_value, $this->session_expiration, apply_filters('give_session_use_secure_cookie', false)); |
|
| 326 | + give_setcookie($this->nonce_cookie_name, '1', $this->session_expiration, apply_filters('give_session_use_secure_cookie', false)); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | * @return int |
| 339 | 339 | */ |
| 340 | 340 | public function set_expiration_time() { |
| 341 | - $this->session_expiring = time() + intval( apply_filters( 'give_session_expiring', ( $this->exp_option - 3600 ) ) ); // Default 11 Hours. |
|
| 342 | - $this->session_expiration = time() + intval( apply_filters( 'give_session_expiration', $this->exp_option ) ); // Default 12 Hours. |
|
| 341 | + $this->session_expiring = time() + intval(apply_filters('give_session_expiring', ($this->exp_option - 3600))); // Default 11 Hours. |
|
| 342 | + $this->session_expiration = time() + intval(apply_filters('give_session_expiration', $this->exp_option)); // Default 12 Hours. |
|
| 343 | 343 | |
| 344 | 344 | return $this->session_expiration; |
| 345 | 345 | } |
@@ -371,10 +371,10 @@ discard block |
||
| 371 | 371 | public function maybe_start_session() { |
| 372 | 372 | if ( |
| 373 | 373 | ! headers_sent() |
| 374 | - && empty( $this->session ) |
|
| 374 | + && empty($this->session) |
|
| 375 | 375 | && ! $this->has_cookie |
| 376 | 376 | ) { |
| 377 | - $this->set_session_cookies( true ); |
|
| 377 | + $this->set_session_cookies(true); |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | * @access public |
| 388 | 388 | */ |
| 389 | 389 | public function generate_donor_id() { |
| 390 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 390 | + require_once ABSPATH.'wp-includes/class-phpass.php'; |
|
| 391 | 391 | |
| 392 | - $hasher = new PasswordHash( 8, false ); |
|
| 393 | - $this->donor_id = md5( $hasher->get_random_bytes( 32 ) ); |
|
| 392 | + $hasher = new PasswordHash(8, false); |
|
| 393 | + $this->donor_id = md5($hasher->get_random_bytes(32)); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -401,14 +401,14 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | public function save_data() { |
| 403 | 403 | // Dirty if something changed - prevents saving nothing new. |
| 404 | - if ( $this->session_data_changed && $this->has_session() ) { |
|
| 404 | + if ($this->session_data_changed && $this->has_session()) { |
|
| 405 | 405 | global $wpdb; |
| 406 | 406 | |
| 407 | 407 | Give()->session_db->__replace( |
| 408 | 408 | Give()->session_db->table_name, |
| 409 | 409 | array( |
| 410 | 410 | 'session_key' => $this->donor_id, |
| 411 | - 'session_value' => maybe_serialize( $this->session ), |
|
| 411 | + 'session_value' => maybe_serialize($this->session), |
|
| 412 | 412 | 'session_expiry' => $this->session_expiration, |
| 413 | 413 | ), |
| 414 | 414 | array( |
@@ -429,10 +429,10 @@ discard block |
||
| 429 | 429 | * @access public |
| 430 | 430 | */ |
| 431 | 431 | public function destroy_session() { |
| 432 | - give_setcookie( $this->cookie_name, '', time() - YEAR_IN_SECONDS, apply_filters( 'give_session_use_secure_cookie', false ) ); |
|
| 433 | - give_setcookie( $this->nonce_cookie_name, '', time() - YEAR_IN_SECONDS, apply_filters( 'give_session_use_secure_cookie', false ) ); |
|
| 432 | + give_setcookie($this->cookie_name, '', time() - YEAR_IN_SECONDS, apply_filters('give_session_use_secure_cookie', false)); |
|
| 433 | + give_setcookie($this->nonce_cookie_name, '', time() - YEAR_IN_SECONDS, apply_filters('give_session_use_secure_cookie', false)); |
|
| 434 | 434 | |
| 435 | - Give()->session_db->delete_session( $this->donor_id ); |
|
| 435 | + Give()->session_db->delete_session($this->donor_id); |
|
| 436 | 436 | |
| 437 | 437 | $this->session = array(); |
| 438 | 438 | $this->session_data_changed = false; |
@@ -448,10 +448,10 @@ discard block |
||
| 448 | 448 | * |
| 449 | 449 | * @return bool |
| 450 | 450 | */ |
| 451 | - public function is_delete_nonce_cookie(){ |
|
| 451 | + public function is_delete_nonce_cookie() { |
|
| 452 | 452 | $value = false; |
| 453 | 453 | |
| 454 | - if ( Give()->session->has_session() ) { |
|
| 454 | + if (Give()->session->has_session()) { |
|
| 455 | 455 | $value = true; |
| 456 | 456 | } |
| 457 | 457 | |
@@ -468,10 +468,10 @@ discard block |
||
| 468 | 468 | * |
| 469 | 469 | * @return string Cookie name |
| 470 | 470 | */ |
| 471 | - public function get_cookie_name( $type = '' ) { |
|
| 471 | + public function get_cookie_name($type = '') { |
|
| 472 | 472 | $name = ''; |
| 473 | 473 | |
| 474 | - switch ( $type ) { |
|
| 474 | + switch ($type) { |
|
| 475 | 475 | case 'nonce': |
| 476 | 476 | $name = $this->nonce_cookie_name; |
| 477 | 477 | break; |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * |
| 496 | 496 | * @return string |
| 497 | 497 | */ |
| 498 | - public function __nonce_user_logged_out( $uid ) { |
|
| 498 | + public function __nonce_user_logged_out($uid) { |
|
| 499 | 499 | return $this->has_session() && $this->donor_id ? $this->donor_id : $uid; |
| 500 | 500 | } |
| 501 | 501 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | */ |
| 542 | 542 | public function set_expiration_variant_time() { |
| 543 | 543 | |
| 544 | - return ( ! empty( $this->exp_option ) ? ( intval( $this->exp_option ) - 3600 ) : 30 * 60 * 23 ); |
|
| 544 | + return ( ! empty($this->exp_option) ? (intval($this->exp_option) - 3600) : 30 * 60 * 23); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -558,9 +558,9 @@ discard block |
||
| 558 | 558 | public function use_php_sessions() { |
| 559 | 559 | $ret = false; |
| 560 | 560 | |
| 561 | - give_doing_it_wrong( __FUNCTION__, __( 'We are using database session logic instead of PHP session', 'give' ), '2.2.0' ); |
|
| 561 | + give_doing_it_wrong(__FUNCTION__, __('We are using database session logic instead of PHP session', 'give'), '2.2.0'); |
|
| 562 | 562 | |
| 563 | - return (bool) apply_filters( 'give_use_php_sessions', $ret ); |
|
| 563 | + return (bool) apply_filters('give_use_php_sessions', $ret); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -578,10 +578,10 @@ discard block |
||
| 578 | 578 | |
| 579 | 579 | $start_session = true; |
| 580 | 580 | |
| 581 | - give_doing_it_wrong( __FUNCTION__, __( 'We are using database session logic instead of PHP session', 'give' ), '2.2.0' ); |
|
| 581 | + give_doing_it_wrong(__FUNCTION__, __('We are using database session logic instead of PHP session', 'give'), '2.2.0'); |
|
| 582 | 582 | |
| 583 | 583 | |
| 584 | - if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { // @codingStandardsIgnoreLine |
|
| 584 | + if ( ! empty($_SERVER['REQUEST_URI'])) { // @codingStandardsIgnoreLine |
|
| 585 | 585 | |
| 586 | 586 | $blacklist = apply_filters( |
| 587 | 587 | 'give_session_start_uri_blacklist', array( |
@@ -594,19 +594,19 @@ discard block |
||
| 594 | 594 | 'comments/feed/', |
| 595 | 595 | ) |
| 596 | 596 | ); |
| 597 | - $uri = ltrim( $_SERVER['REQUEST_URI'], '/' ); // // @codingStandardsIgnoreLine |
|
| 598 | - $uri = untrailingslashit( $uri ); |
|
| 599 | - if ( in_array( $uri, $blacklist, true ) ) { |
|
| 597 | + $uri = ltrim($_SERVER['REQUEST_URI'], '/'); // // @codingStandardsIgnoreLine |
|
| 598 | + $uri = untrailingslashit($uri); |
|
| 599 | + if (in_array($uri, $blacklist, true)) { |
|
| 600 | 600 | $start_session = false; |
| 601 | 601 | } |
| 602 | - if ( false !== strpos( $uri, 'feed=' ) ) { |
|
| 602 | + if (false !== strpos($uri, 'feed=')) { |
|
| 603 | 603 | $start_session = false; |
| 604 | 604 | } |
| 605 | - if ( is_admin() ) { |
|
| 605 | + if (is_admin()) { |
|
| 606 | 606 | $start_session = false; |
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - return apply_filters( 'give_start_session', $start_session ); |
|
| 610 | + return apply_filters('give_start_session', $start_session); |
|
| 611 | 611 | } |
| 612 | 612 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /* @var WPDB $wpdb */ |
| 36 | 36 | global $wpdb; |
| 37 | 37 | |
| 38 | - $this->table_name = $wpdb->prefix . 'give_logs'; |
|
| 38 | + $this->table_name = $wpdb->prefix.'give_logs'; |
|
| 39 | 39 | $this->primary_key = 'ID'; |
| 40 | 40 | $this->version = '1.0'; |
| 41 | 41 | |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @return array Default column values. |
| 75 | 75 | */ |
| 76 | 76 | public function get_column_defaults() { |
| 77 | - $log_create_date = current_time( 'mysql', 0 ); |
|
| 78 | - $log_create_date_gmt = get_gmt_from_date( $log_create_date ); |
|
| 77 | + $log_create_date = current_time('mysql', 0); |
|
| 78 | + $log_create_date_gmt = get_gmt_from_date($log_create_date); |
|
| 79 | 79 | |
| 80 | 80 | return array( |
| 81 | 81 | 'ID' => 0, |
@@ -98,39 +98,39 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return bool|int |
| 100 | 100 | */ |
| 101 | - public function add( $data = array() ) { |
|
| 101 | + public function add($data = array()) { |
|
| 102 | 102 | // Valid table columns. |
| 103 | - $table_columns = array_keys( $this->get_columns() ); |
|
| 103 | + $table_columns = array_keys($this->get_columns()); |
|
| 104 | 104 | |
| 105 | 105 | // Filter data. |
| 106 | - foreach ( $data as $table_column => $column_data ) { |
|
| 107 | - if ( ! in_array( $table_column, $table_columns ) ) { |
|
| 108 | - unset( $data[ $table_column ] ); |
|
| 106 | + foreach ($data as $table_column => $column_data) { |
|
| 107 | + if ( ! in_array($table_column, $table_columns)) { |
|
| 108 | + unset($data[$table_column]); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Set default values. |
| 113 | - $current_log_data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
| 113 | + $current_log_data = wp_parse_args($data, $this->get_column_defaults()); |
|
| 114 | 114 | |
| 115 | 115 | // Log parent should be an int. |
| 116 | - $current_log_data['log_parent'] = absint( $current_log_data['log_parent'] ); |
|
| 116 | + $current_log_data['log_parent'] = absint($current_log_data['log_parent']); |
|
| 117 | 117 | |
| 118 | 118 | // Get log. |
| 119 | - $existing_log = $this->get_log_by( $current_log_data['ID'] ); |
|
| 119 | + $existing_log = $this->get_log_by($current_log_data['ID']); |
|
| 120 | 120 | |
| 121 | 121 | // Update an existing log. |
| 122 | - if ( $existing_log ) { |
|
| 122 | + if ($existing_log) { |
|
| 123 | 123 | |
| 124 | 124 | // Create new log data from existing and new log data. |
| 125 | - $current_log_data = array_merge( $current_log_data, $existing_log ); |
|
| 125 | + $current_log_data = array_merge($current_log_data, $existing_log); |
|
| 126 | 126 | |
| 127 | 127 | // Update log data. |
| 128 | - $this->update( $current_log_data['ID'], $current_log_data ); |
|
| 128 | + $this->update($current_log_data['ID'], $current_log_data); |
|
| 129 | 129 | |
| 130 | 130 | $log_id = $current_log_data['ID']; |
| 131 | 131 | |
| 132 | 132 | } else { |
| 133 | - $log_id = $this->insert( $current_log_data, 'log' ); |
|
| 133 | + $log_id = $this->insert($current_log_data, 'log'); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return $log_id; |
@@ -148,20 +148,20 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return bool|null|array |
| 150 | 150 | */ |
| 151 | - public function get_log_by( $log_id = 0, $by = 'id' ) { |
|
| 151 | + public function get_log_by($log_id = 0, $by = 'id') { |
|
| 152 | 152 | /* @var WPDB $wpdb */ |
| 153 | 153 | global $wpdb; |
| 154 | 154 | $log = null; |
| 155 | 155 | |
| 156 | 156 | // Make sure $log_id is int. |
| 157 | - $log_id = absint( $log_id ); |
|
| 157 | + $log_id = absint($log_id); |
|
| 158 | 158 | |
| 159 | 159 | // Bailout. |
| 160 | - if ( empty( $log_id ) ) { |
|
| 160 | + if (empty($log_id)) { |
|
| 161 | 161 | return null; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - switch ( $by ) { |
|
| 164 | + switch ($by) { |
|
| 165 | 165 | case 'id': |
| 166 | 166 | $log = $wpdb->get_row( |
| 167 | 167 | $wpdb->prepare( |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | break; |
| 174 | 174 | |
| 175 | 175 | default: |
| 176 | - $log = apply_filters( "give_get_log_by_{$by}", $log, $log_id ); |
|
| 176 | + $log = apply_filters("give_get_log_by_{$by}", $log, $log_id); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | return $log; |
@@ -189,14 +189,14 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @return mixed |
| 191 | 191 | */ |
| 192 | - public function get_logs( $args = array() ) { |
|
| 192 | + public function get_logs($args = array()) { |
|
| 193 | 193 | global $wpdb; |
| 194 | - $sql_query = $this->get_sql( $args ); |
|
| 194 | + $sql_query = $this->get_sql($args); |
|
| 195 | 195 | |
| 196 | 196 | // Get log. |
| 197 | - if ( ! ( $logs = Give_Cache::get( 'give_logs', true, $sql_query ) ) ) { |
|
| 198 | - $logs = $wpdb->get_results( $sql_query ); |
|
| 199 | - Give_Cache::set( 'give_logs', $logs, 3600, true, $sql_query ); |
|
| 197 | + if ( ! ($logs = Give_Cache::get('give_logs', true, $sql_query))) { |
|
| 198 | + $logs = $wpdb->get_results($sql_query); |
|
| 199 | + Give_Cache::set('give_logs', $logs, 3600, true, $sql_query); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return $logs; |
@@ -213,21 +213,21 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return int |
| 215 | 215 | */ |
| 216 | - public function count( $args = array() ) { |
|
| 216 | + public function count($args = array()) { |
|
| 217 | 217 | /* @var WPDB $wpdb */ |
| 218 | 218 | global $wpdb; |
| 219 | 219 | $args['number'] = - 1; |
| 220 | 220 | $args['fields'] = 'ID'; |
| 221 | 221 | $args['count'] = true; |
| 222 | 222 | |
| 223 | - $sql_query = $this->get_sql( $args ); |
|
| 223 | + $sql_query = $this->get_sql($args); |
|
| 224 | 224 | |
| 225 | - if ( ! ( $count = Give_Cache::get( 'give_logs_count', true, $sql_query ) ) ) { |
|
| 226 | - $count = $wpdb->get_var( $sql_query ); |
|
| 227 | - Give_Cache::set( 'give_logs_count', $count, 3600, true, $args ); |
|
| 225 | + if ( ! ($count = Give_Cache::get('give_logs_count', true, $sql_query))) { |
|
| 226 | + $count = $wpdb->get_var($sql_query); |
|
| 227 | + Give_Cache::set('give_logs_count', $count, 3600, true, $args); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - return absint( $count ); |
|
| 230 | + return absint($count); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -253,10 +253,10 @@ discard block |
||
| 253 | 253 | PRIMARY KEY (ID) |
| 254 | 254 | ) {$charset_collate};"; |
| 255 | 255 | |
| 256 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 257 | - dbDelta( $sql ); |
|
| 256 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 257 | + dbDelta($sql); |
|
| 258 | 258 | |
| 259 | - update_option( $this->table_name . '_db_version', $this->version, false ); |
|
| 259 | + update_option($this->table_name.'_db_version', $this->version, false); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - public function get_sql( $args = array() ) { |
|
| 273 | + public function get_sql($args = array()) { |
|
| 274 | 274 | /* @var WPDB $wpdb */ |
| 275 | 275 | global $wpdb; |
| 276 | 276 | |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | 'count' => false, |
| 285 | 285 | ); |
| 286 | 286 | |
| 287 | - $args = wp_parse_args( $args, $defaults ); |
|
| 287 | + $args = wp_parse_args($args, $defaults); |
|
| 288 | 288 | |
| 289 | 289 | // validate params. |
| 290 | - $this->validate_params( $args ); |
|
| 290 | + $this->validate_params($args); |
|
| 291 | 291 | |
| 292 | - if ( $args['number'] < 1 ) { |
|
| 292 | + if ($args['number'] < 1) { |
|
| 293 | 293 | $args['number'] = 99999999999; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -297,78 +297,78 @@ discard block |
||
| 297 | 297 | $where = ''; |
| 298 | 298 | |
| 299 | 299 | // Get sql query for meta. |
| 300 | - if ( ! empty( $args['meta_query'] ) ) { |
|
| 301 | - $meta_query_object = new WP_Meta_Query( $args['meta_query'] ); |
|
| 302 | - $meta_query = $meta_query_object->get_sql( 'log', $this->table_name, 'id' ); |
|
| 303 | - $where = implode( '', $meta_query ); |
|
| 300 | + if ( ! empty($args['meta_query'])) { |
|
| 301 | + $meta_query_object = new WP_Meta_Query($args['meta_query']); |
|
| 302 | + $meta_query = $meta_query_object->get_sql('log', $this->table_name, 'id'); |
|
| 303 | + $where = implode('', $meta_query); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $where .= ' WHERE 1=1 '; |
| 307 | 307 | |
| 308 | 308 | // Set offset. |
| 309 | - if ( empty( $args['offset'] ) && ( 0 < $args['paged'] ) ) { |
|
| 310 | - $args['offset'] = $args['number'] * ( $args['paged'] - 1 ); |
|
| 309 | + if (empty($args['offset']) && (0 < $args['paged'])) { |
|
| 310 | + $args['offset'] = $args['number'] * ($args['paged'] - 1); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // Set fields. |
| 314 | 314 | $fields = "{$this->table_name}.*"; |
| 315 | - if ( is_string( $args['fields'] ) && ( 'all' !== $args['fields'] ) ) { |
|
| 315 | + if (is_string($args['fields']) && ('all' !== $args['fields'])) { |
|
| 316 | 316 | $fields = "{$this->table_name}.{$args['fields']}"; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Set count. |
| 320 | - if ( $args['count'] ) { |
|
| 320 | + if ($args['count']) { |
|
| 321 | 321 | $fields = "COUNT({$fields})"; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // Specific logs. |
| 325 | - if ( ! empty( $args['ID'] ) ) { |
|
| 325 | + if ( ! empty($args['ID'])) { |
|
| 326 | 326 | |
| 327 | - if ( ! is_array( $args['ID'] ) ) { |
|
| 328 | - $args['ID'] = explode( ',', $args['ID'] ); |
|
| 327 | + if ( ! is_array($args['ID'])) { |
|
| 328 | + $args['ID'] = explode(',', $args['ID']); |
|
| 329 | 329 | } |
| 330 | - $log_ids = implode( ',', array_map( 'intval', $args['ID'] ) ); |
|
| 330 | + $log_ids = implode(',', array_map('intval', $args['ID'])); |
|
| 331 | 331 | |
| 332 | 332 | $where .= " AND {$this->table_name}.ID IN( {$log_ids} ) "; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Logs created for a specific date or in a date range |
| 336 | - if ( ! empty( $args['date_query'] ) ) { |
|
| 337 | - $date_query_object = new WP_Date_Query( $args['date_query'], "{$this->table_name}.log_date" ); |
|
| 338 | - $where .= $date_query_object->get_sql(); |
|
| 336 | + if ( ! empty($args['date_query'])) { |
|
| 337 | + $date_query_object = new WP_Date_Query($args['date_query'], "{$this->table_name}.log_date"); |
|
| 338 | + $where .= $date_query_object->get_sql(); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | // Logs create for specific parent. |
| 342 | - if ( ! empty( $args['log_parent'] ) ) { |
|
| 343 | - if ( ! is_array( $args['log_parent'] ) ) { |
|
| 344 | - $args['log_parent'] = explode( ',', $args['log_parent'] ); |
|
| 342 | + if ( ! empty($args['log_parent'])) { |
|
| 343 | + if ( ! is_array($args['log_parent'])) { |
|
| 344 | + $args['log_parent'] = explode(',', $args['log_parent']); |
|
| 345 | 345 | } |
| 346 | - $parent_ids = implode( ',', array_map( 'intval', $args['log_parent'] ) ); |
|
| 346 | + $parent_ids = implode(',', array_map('intval', $args['log_parent'])); |
|
| 347 | 347 | |
| 348 | 348 | $where .= " AND {$this->table_name}.log_parent IN( {$parent_ids} ) "; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // Logs create for specific type. |
| 352 | 352 | // is_array check is for backward compatibility. |
| 353 | - if ( ! empty( $args['log_type'] ) && ! is_array( $args['log_type'] ) ) { |
|
| 354 | - if ( ! is_array( $args['log_type'] ) ) { |
|
| 355 | - $args['log_type'] = explode( ',', $args['log_type'] ); |
|
| 353 | + if ( ! empty($args['log_type']) && ! is_array($args['log_type'])) { |
|
| 354 | + if ( ! is_array($args['log_type'])) { |
|
| 355 | + $args['log_type'] = explode(',', $args['log_type']); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $log_types = implode( '\',\'', array_map( 'trim', $args['log_type'] ) ); |
|
| 358 | + $log_types = implode('\',\'', array_map('trim', $args['log_type'])); |
|
| 359 | 359 | |
| 360 | 360 | $where .= " AND {$this->table_name}.log_type IN( '{$log_types}' ) "; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'log_date' : $args['orderby']; |
|
| 363 | + $args['orderby'] = ! array_key_exists($args['orderby'], $this->get_columns()) ? 'log_date' : $args['orderby']; |
|
| 364 | 364 | |
| 365 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
| 366 | - $args['order'] = esc_sql( $args['order'] ); |
|
| 365 | + $args['orderby'] = esc_sql($args['orderby']); |
|
| 366 | + $args['order'] = esc_sql($args['order']); |
|
| 367 | 367 | |
| 368 | 368 | return $wpdb->prepare( |
| 369 | 369 | "SELECT {$fields} FROM {$this->table_name} {$where} ORDER BY {$this->table_name}.{$args['orderby']} {$args['order']} LIMIT %d,%d;", |
| 370 | - absint( $args['offset'] ), |
|
| 371 | - absint( $args['number'] ) |
|
| 370 | + absint($args['offset']), |
|
| 371 | + absint($args['number']) |
|
| 372 | 372 | ); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -383,13 +383,11 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @return mixed |
| 385 | 385 | */ |
| 386 | - private function validate_params( &$args ) { |
|
| 386 | + private function validate_params(&$args) { |
|
| 387 | 387 | // fields params |
| 388 | 388 | $args['fields'] = 'ids' === $args['fields'] ? |
| 389 | - 'ID' : |
|
| 390 | - $args['fields']; |
|
| 391 | - $args['fields'] = array_key_exists( $args['fields'], $this->get_columns() ) ? |
|
| 392 | - $args['fields'] : |
|
| 393 | - 'all'; |
|
| 389 | + 'ID' : $args['fields']; |
|
| 390 | + $args['fields'] = array_key_exists($args['fields'], $this->get_columns()) ? |
|
| 391 | + $args['fields'] : 'all'; |
|
| 394 | 392 | } |
| 395 | 393 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly. |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -30,54 +30,54 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return bool|array List of all user donations. |
| 32 | 32 | */ |
| 33 | -function give_get_users_donations( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
| 33 | +function give_get_users_donations($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
| 34 | 34 | |
| 35 | - if ( empty( $user ) ) { |
|
| 35 | + if (empty($user)) { |
|
| 36 | 36 | $user = get_current_user_id(); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ( 0 === $user && ! Give()->email_access->token_exists ) { |
|
| 39 | + if (0 === $user && ! Give()->email_access->token_exists) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $status = ( 'complete' === $status ) ? 'publish' : $status; |
|
| 43 | + $status = ('complete' === $status) ? 'publish' : $status; |
|
| 44 | 44 | $paged = 1; |
| 45 | 45 | |
| 46 | - if ( $pagination ) { |
|
| 47 | - if ( get_query_var( 'paged' ) ) { |
|
| 48 | - $paged = get_query_var( 'paged' ); |
|
| 49 | - } elseif ( get_query_var( 'page' ) ) { |
|
| 50 | - $paged = get_query_var( 'page' ); |
|
| 46 | + if ($pagination) { |
|
| 47 | + if (get_query_var('paged')) { |
|
| 48 | + $paged = get_query_var('paged'); |
|
| 49 | + } elseif (get_query_var('page')) { |
|
| 50 | + $paged = get_query_var('page'); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $args = apply_filters( 'give_get_users_donations_args', array( |
|
| 54 | + $args = apply_filters('give_get_users_donations_args', array( |
|
| 55 | 55 | 'user' => $user, |
| 56 | 56 | 'number' => $number, |
| 57 | 57 | 'status' => $status, |
| 58 | 58 | 'orderby' => 'date', |
| 59 | - ) ); |
|
| 59 | + )); |
|
| 60 | 60 | |
| 61 | - if ( $pagination ) { |
|
| 61 | + if ($pagination) { |
|
| 62 | 62 | $args['page'] = $paged; |
| 63 | 63 | } else { |
| 64 | 64 | $args['nopaging'] = true; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
| 68 | - $donor = new Give_Donor( $user, $by_user_id ); |
|
| 67 | + $by_user_id = is_numeric($user) ? true : false; |
|
| 68 | + $donor = new Give_Donor($user, $by_user_id); |
|
| 69 | 69 | |
| 70 | - if ( ! empty( $donor->payment_ids ) ) { |
|
| 70 | + if ( ! empty($donor->payment_ids)) { |
|
| 71 | 71 | |
| 72 | - unset( $args['user'] ); |
|
| 73 | - $args['post__in'] = array_map( 'absint', explode( ',', $donor->payment_ids ) ); |
|
| 72 | + unset($args['user']); |
|
| 73 | + $args['post__in'] = array_map('absint', explode(',', $donor->payment_ids)); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $donations = give_get_payments( apply_filters( 'give_get_users_donations_args', $args ) ); |
|
| 77 | + $donations = give_get_payments(apply_filters('give_get_users_donations_args', $args)); |
|
| 78 | 78 | |
| 79 | 79 | // No donations. |
| 80 | - if ( ! $donations ) { |
|
| 80 | + if ( ! $donations) { |
|
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -96,65 +96,65 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return bool|object List of unique forms donated by user |
| 98 | 98 | */ |
| 99 | -function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
|
| 100 | - if ( empty( $user ) ) { |
|
| 99 | +function give_get_users_completed_donations($user = 0, $status = 'complete') { |
|
| 100 | + if (empty($user)) { |
|
| 101 | 101 | $user = get_current_user_id(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ( empty( $user ) ) { |
|
| 104 | + if (empty($user)) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
| 108 | + $by_user_id = is_numeric($user) ? true : false; |
|
| 109 | 109 | |
| 110 | - $donor = new Give_Donor( $user, $by_user_id ); |
|
| 110 | + $donor = new Give_Donor($user, $by_user_id); |
|
| 111 | 111 | |
| 112 | - if ( empty( $donor->payment_ids ) ) { |
|
| 112 | + if (empty($donor->payment_ids)) { |
|
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Get all the items donated. |
| 117 | - $payment_ids = array_reverse( explode( ',', $donor->payment_ids ) ); |
|
| 118 | - $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
|
| 119 | - if ( ! empty( $limit_payments ) ) { |
|
| 120 | - $payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
|
| 117 | + $payment_ids = array_reverse(explode(',', $donor->payment_ids)); |
|
| 118 | + $limit_payments = apply_filters('give_users_completed_donations_payments', 50); |
|
| 119 | + if ( ! empty($limit_payments)) { |
|
| 120 | + $payment_ids = array_slice($payment_ids, 0, $limit_payments); |
|
| 121 | 121 | } |
| 122 | 122 | $donation_data = array(); |
| 123 | - foreach ( $payment_ids as $payment_id ) { |
|
| 124 | - $donation_data[] = give_get_payment_meta( $payment_id ); |
|
| 123 | + foreach ($payment_ids as $payment_id) { |
|
| 124 | + $donation_data[] = give_get_payment_meta($payment_id); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ( empty( $donation_data ) ) { |
|
| 127 | + if (empty($donation_data)) { |
|
| 128 | 128 | return false; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Grab only the post ids "form_id" of the forms donated on this order. |
| 132 | 132 | $completed_donations_ids = array(); |
| 133 | - foreach ( $donation_data as $donation_meta ) { |
|
| 134 | - $completed_donations_ids[] = isset( $donation_meta['form_id'] ) ? $donation_meta['form_id'] : ''; |
|
| 133 | + foreach ($donation_data as $donation_meta) { |
|
| 134 | + $completed_donations_ids[] = isset($donation_meta['form_id']) ? $donation_meta['form_id'] : ''; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( empty( $completed_donations_ids ) ) { |
|
| 137 | + if (empty($completed_donations_ids)) { |
|
| 138 | 138 | return false; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Only include each donation once. |
| 142 | - $form_ids = array_unique( $completed_donations_ids ); |
|
| 142 | + $form_ids = array_unique($completed_donations_ids); |
|
| 143 | 143 | |
| 144 | 144 | // Make sure we still have some products and a first item. |
| 145 | - if ( empty( $form_ids ) || ! isset( $form_ids[0] ) ) { |
|
| 145 | + if (empty($form_ids) || ! isset($form_ids[0])) { |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $post_type = get_post_type( $form_ids[0] ); |
|
| 149 | + $post_type = get_post_type($form_ids[0]); |
|
| 150 | 150 | |
| 151 | - $args = apply_filters( 'give_get_users_completed_donations_args', array( |
|
| 151 | + $args = apply_filters('give_get_users_completed_donations_args', array( |
|
| 152 | 152 | 'include' => $form_ids, |
| 153 | 153 | 'post_type' => $post_type, |
| 154 | - 'posts_per_page' => - 1, |
|
| 155 | - ) ); |
|
| 154 | + 'posts_per_page' => -1, |
|
| 155 | + )); |
|
| 156 | 156 | |
| 157 | - return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
|
| 157 | + return apply_filters('give_users_completed_donations_list', get_posts($args)); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return bool True if has donated, false other wise. |
| 172 | 172 | */ |
| 173 | -function give_has_donations( $user_id = null ) { |
|
| 174 | - if ( empty( $user_id ) ) { |
|
| 173 | +function give_has_donations($user_id = null) { |
|
| 174 | + if (empty($user_id)) { |
|
| 175 | 175 | $user_id = get_current_user_id(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( give_get_users_donations( $user_id, 1 ) ) { |
|
| 178 | + if (give_get_users_donations($user_id, 1)) { |
|
| 179 | 179 | return true; // User has at least one donation. |
| 180 | 180 | } |
| 181 | 181 | |
@@ -196,23 +196,23 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return array |
| 198 | 198 | */ |
| 199 | -function give_get_donation_stats_by_user( $user = '' ) { |
|
| 199 | +function give_get_donation_stats_by_user($user = '') { |
|
| 200 | 200 | |
| 201 | 201 | $field = ''; |
| 202 | 202 | |
| 203 | - if ( is_email( $user ) ) { |
|
| 203 | + if (is_email($user)) { |
|
| 204 | 204 | $field = 'email'; |
| 205 | - } elseif ( is_numeric( $user ) ) { |
|
| 205 | + } elseif (is_numeric($user)) { |
|
| 206 | 206 | $field = 'user_id'; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $stats = array(); |
|
| 210 | - $donor = Give()->donors->get_donor_by( $field, $user ); |
|
| 209 | + $stats = array(); |
|
| 210 | + $donor = Give()->donors->get_donor_by($field, $user); |
|
| 211 | 211 | |
| 212 | - if ( $donor ) { |
|
| 213 | - $donor = new Give_Donor( $donor->id ); |
|
| 214 | - $stats['purchases'] = absint( $donor->purchase_count ); |
|
| 215 | - $stats['total_spent'] = give_maybe_sanitize_amount( $donor->get_total_donation_amount() ); |
|
| 212 | + if ($donor) { |
|
| 213 | + $donor = new Give_Donor($donor->id); |
|
| 214 | + $stats['purchases'] = absint($donor->purchase_count); |
|
| 215 | + $stats['total_spent'] = give_maybe_sanitize_amount($donor->get_total_donation_amount()); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @since 1.7 |
| 222 | 222 | */ |
| 223 | - $stats = (array) apply_filters( 'give_donation_stats_by_user', $stats, $user ); |
|
| 223 | + $stats = (array) apply_filters('give_donation_stats_by_user', $stats, $user); |
|
| 224 | 224 | |
| 225 | 225 | return $stats; |
| 226 | 226 | } |
@@ -238,21 +238,21 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @return int The total number of donations. |
| 240 | 240 | */ |
| 241 | -function give_count_donations_of_donor( $user = null ) { |
|
| 241 | +function give_count_donations_of_donor($user = null) { |
|
| 242 | 242 | |
| 243 | 243 | // Logged in? |
| 244 | - if ( empty( $user ) ) { |
|
| 244 | + if (empty($user)) { |
|
| 245 | 245 | $user = get_current_user_id(); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Email access? |
| 249 | - if ( empty( $user ) && Give()->email_access->token_email ) { |
|
| 249 | + if (empty($user) && Give()->email_access->token_email) { |
|
| 250 | 250 | $user = Give()->email_access->token_email; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $stats = ! empty( $user ) ? give_get_donation_stats_by_user( $user ) : false; |
|
| 253 | + $stats = ! empty($user) ? give_get_donation_stats_by_user($user) : false; |
|
| 254 | 254 | |
| 255 | - return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
|
| 255 | + return isset($stats['purchases']) ? $stats['purchases'] : 0; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return float The total amount the user has spent |
| 267 | 267 | */ |
| 268 | -function give_donation_total_of_user( $user = null ) { |
|
| 268 | +function give_donation_total_of_user($user = null) { |
|
| 269 | 269 | |
| 270 | - $stats = give_get_donation_stats_by_user( $user ); |
|
| 270 | + $stats = give_get_donation_stats_by_user($user); |
|
| 271 | 271 | |
| 272 | 272 | return $stats['total_spent']; |
| 273 | 273 | } |
@@ -283,40 +283,40 @@ discard block |
||
| 283 | 283 | * |
| 284 | 284 | * @return bool |
| 285 | 285 | */ |
| 286 | -function give_validate_username( $username, $form_id = 0 ) { |
|
| 286 | +function give_validate_username($username, $form_id = 0) { |
|
| 287 | 287 | $valid = true; |
| 288 | 288 | |
| 289 | 289 | // Validate username. |
| 290 | - if ( ! empty( $username ) ) { |
|
| 290 | + if ( ! empty($username)) { |
|
| 291 | 291 | |
| 292 | 292 | // Sanitize username. |
| 293 | - $sanitized_user_name = sanitize_user( $username, false ); |
|
| 293 | + $sanitized_user_name = sanitize_user($username, false); |
|
| 294 | 294 | |
| 295 | 295 | // We have an user name, check if it already exists. |
| 296 | - if ( username_exists( $username ) ) { |
|
| 296 | + if (username_exists($username)) { |
|
| 297 | 297 | // Username already registered. |
| 298 | - give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) ); |
|
| 298 | + give_set_error('username_unavailable', __('Username already taken.', 'give')); |
|
| 299 | 299 | $valid = false; |
| 300 | 300 | |
| 301 | 301 | // Check if it's valid. |
| 302 | - } elseif ( $sanitized_user_name !== $username ) { |
|
| 302 | + } elseif ($sanitized_user_name !== $username) { |
|
| 303 | 303 | // Invalid username. |
| 304 | - if ( is_multisite() ) { |
|
| 305 | - give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) ); |
|
| 304 | + if (is_multisite()) { |
|
| 305 | + give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give')); |
|
| 306 | 306 | $valid = false; |
| 307 | 307 | } else { |
| 308 | - give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) ); |
|
| 308 | + give_set_error('username_invalid', __('Invalid username.', 'give')); |
|
| 309 | 309 | $valid = false; |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | } else { |
| 313 | 313 | // Username is empty. |
| 314 | - give_set_error( 'username_empty', __( 'Enter a username.', 'give' ) ); |
|
| 314 | + give_set_error('username_empty', __('Enter a username.', 'give')); |
|
| 315 | 315 | $valid = false; |
| 316 | 316 | |
| 317 | 317 | // Check if guest checkout is disable for form. |
| 318 | - if ( $form_id && give_logged_in_only( $form_id ) ) { |
|
| 319 | - give_set_error( 'registration_required', __( 'You must register or login to complete your donation.', 'give' ) ); |
|
| 318 | + if ($form_id && give_logged_in_only($form_id)) { |
|
| 319 | + give_set_error('registration_required', __('You must register or login to complete your donation.', 'give')); |
|
| 320 | 320 | $valid = false; |
| 321 | 321 | } |
| 322 | 322 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * |
| 331 | 331 | * @since 1.8 |
| 332 | 332 | */ |
| 333 | - $valid = (bool) apply_filters( 'give_validate_username', $valid, $username, $form_id ); |
|
| 333 | + $valid = (bool) apply_filters('give_validate_username', $valid, $username, $form_id); |
|
| 334 | 334 | |
| 335 | 335 | return $valid; |
| 336 | 336 | } |
@@ -346,30 +346,30 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @return bool |
| 348 | 348 | */ |
| 349 | -function give_validate_user_email( $email, $registering_new_user = false ) { |
|
| 349 | +function give_validate_user_email($email, $registering_new_user = false) { |
|
| 350 | 350 | $valid = true; |
| 351 | 351 | |
| 352 | - if ( empty( $email ) ) { |
|
| 352 | + if (empty($email)) { |
|
| 353 | 353 | // No email. |
| 354 | - give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
|
| 354 | + give_set_error('email_empty', __('Enter an email.', 'give')); |
|
| 355 | 355 | $valid = false; |
| 356 | 356 | |
| 357 | - } elseif ( email_exists( $email ) ) { |
|
| 357 | + } elseif (email_exists($email)) { |
|
| 358 | 358 | // Email already exists. |
| 359 | - give_set_error( 'email_exists', __( 'Email already exists.', 'give' ) ); |
|
| 359 | + give_set_error('email_exists', __('Email already exists.', 'give')); |
|
| 360 | 360 | $valid = false; |
| 361 | 361 | |
| 362 | - } elseif ( ! is_email( $email ) ) { |
|
| 362 | + } elseif ( ! is_email($email)) { |
|
| 363 | 363 | // Validate email. |
| 364 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
| 364 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
| 365 | 365 | $valid = false; |
| 366 | 366 | |
| 367 | - } elseif ( $registering_new_user ) { |
|
| 367 | + } elseif ($registering_new_user) { |
|
| 368 | 368 | |
| 369 | 369 | // If donor email is not primary. |
| 370 | - if ( ! email_exists( $email ) && give_donor_email_exists( $email ) && give_is_additional_email( $email ) ) { |
|
| 370 | + if ( ! email_exists($email) && give_donor_email_exists($email) && give_is_additional_email($email)) { |
|
| 371 | 371 | // Check if email exists. |
| 372 | - give_set_error( 'email_used', __( 'The email address provided is already active for another user.', 'give' ) ); |
|
| 372 | + give_set_error('email_used', __('The email address provided is already active for another user.', 'give')); |
|
| 373 | 373 | $valid = false; |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @since 1.8 |
| 385 | 385 | */ |
| 386 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $email, $registering_new_user ); |
|
| 386 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $email, $registering_new_user); |
|
| 387 | 387 | |
| 388 | 388 | return $valid; |
| 389 | 389 | } |
@@ -399,34 +399,34 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @return bool |
| 401 | 401 | */ |
| 402 | -function give_validate_user_password( $password = '', $confirm_password = '', $registering_new_user = false ) { |
|
| 402 | +function give_validate_user_password($password = '', $confirm_password = '', $registering_new_user = false) { |
|
| 403 | 403 | $valid = true; |
| 404 | 404 | |
| 405 | 405 | // Passwords Validation For New Donors Only. |
| 406 | - if ( $registering_new_user ) { |
|
| 406 | + if ($registering_new_user) { |
|
| 407 | 407 | // Password or confirmation missing. |
| 408 | - if ( ! $password ) { |
|
| 408 | + if ( ! $password) { |
|
| 409 | 409 | // The password is invalid. |
| 410 | - give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
|
| 410 | + give_set_error('password_empty', __('Enter a password.', 'give')); |
|
| 411 | 411 | $valid = false; |
| 412 | - } elseif ( ! $confirm_password ) { |
|
| 412 | + } elseif ( ! $confirm_password) { |
|
| 413 | 413 | // Confirmation password is invalid. |
| 414 | - give_set_error( 'confirmation_empty', __( 'Enter the password confirmation.', 'give' ) ); |
|
| 414 | + give_set_error('confirmation_empty', __('Enter the password confirmation.', 'give')); |
|
| 415 | 415 | $valid = false; |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | // Passwords Validation For New Donors as well as Existing Donors. |
| 419 | - if ( $password || $confirm_password ) { |
|
| 420 | - if ( strlen( $password ) < 6 || strlen( $confirm_password ) < 6 ) { |
|
| 419 | + if ($password || $confirm_password) { |
|
| 420 | + if (strlen($password) < 6 || strlen($confirm_password) < 6) { |
|
| 421 | 421 | // Seems Weak Password. |
| 422 | - give_set_error( 'password_weak', __( 'Passwords should have at least 6 characters.', 'give' ) ); |
|
| 422 | + give_set_error('password_weak', __('Passwords should have at least 6 characters.', 'give')); |
|
| 423 | 423 | $valid = false; |
| 424 | 424 | } |
| 425 | - if ( $password && $confirm_password ) { |
|
| 425 | + if ($password && $confirm_password) { |
|
| 426 | 426 | // Verify confirmation matches. |
| 427 | - if ( $password !== $confirm_password ) { |
|
| 427 | + if ($password !== $confirm_password) { |
|
| 428 | 428 | // Passwords do not match. |
| 429 | - give_set_error( 'password_mismatch', __( 'Passwords you entered do not match. Please try again.', 'give' ) ); |
|
| 429 | + give_set_error('password_mismatch', __('Passwords you entered do not match. Please try again.', 'give')); |
|
| 430 | 430 | $valid = false; |
| 431 | 431 | } |
| 432 | 432 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | * |
| 443 | 443 | * @since 1.8 |
| 444 | 444 | */ |
| 445 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user ); |
|
| 445 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user); |
|
| 446 | 446 | |
| 447 | 447 | return $valid; |
| 448 | 448 | } |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | * |
| 471 | 471 | * @return array The donor's address, if any |
| 472 | 472 | */ |
| 473 | -function give_get_donor_address( $donor_id = null, $args = array() ) { |
|
| 474 | - if ( empty( $donor_id ) ) { |
|
| 473 | +function give_get_donor_address($donor_id = null, $args = array()) { |
|
| 474 | + if (empty($donor_id)) { |
|
| 475 | 475 | $donor_id = get_current_user_id(); |
| 476 | 476 | } |
| 477 | 477 | |
@@ -493,33 +493,33 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | |
| 495 | 495 | // Backward compatibility for user id param. |
| 496 | - $by_user_id = get_user_by( 'id', $donor_id ) ? true : false; |
|
| 496 | + $by_user_id = get_user_by('id', $donor_id) ? true : false; |
|
| 497 | 497 | |
| 498 | 498 | // Backward compatibility. |
| 499 | - if ( ! give_has_upgrade_completed( 'v20_upgrades_user_address' ) && $by_user_id ) { |
|
| 499 | + if ( ! give_has_upgrade_completed('v20_upgrades_user_address') && $by_user_id) { |
|
| 500 | 500 | return wp_parse_args( |
| 501 | - (array) get_user_meta( $donor_id, '_give_user_address', true ), |
|
| 501 | + (array) get_user_meta($donor_id, '_give_user_address', true), |
|
| 502 | 502 | $default_address |
| 503 | 503 | ); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $donor = new Give_Donor( $donor_id, $by_user_id ); |
|
| 506 | + $donor = new Give_Donor($donor_id, $by_user_id); |
|
| 507 | 507 | |
| 508 | 508 | if ( |
| 509 | 509 | ! $donor->id || |
| 510 | - empty( $donor->address ) || |
|
| 511 | - ! array_key_exists( $args['address_type'], $donor->address ) |
|
| 510 | + empty($donor->address) || |
|
| 511 | + ! array_key_exists($args['address_type'], $donor->address) |
|
| 512 | 512 | ) { |
| 513 | 513 | return $default_address; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - switch ( true ) { |
|
| 517 | - case is_string( end( $donor->address[ $args['address_type'] ] ) ): |
|
| 518 | - $address = wp_parse_args( $donor->address[ $args['address_type'] ], $default_address ); |
|
| 516 | + switch (true) { |
|
| 517 | + case is_string(end($donor->address[$args['address_type']])): |
|
| 518 | + $address = wp_parse_args($donor->address[$args['address_type']], $default_address); |
|
| 519 | 519 | break; |
| 520 | 520 | |
| 521 | - case is_array( end( $donor->address[ $args['address_type'] ] ) ): |
|
| 522 | - $address = wp_parse_args( array_shift( $donor->address[ $args['address_type'] ] ), $default_address ); |
|
| 521 | + case is_array(end($donor->address[$args['address_type']])): |
|
| 522 | + $address = wp_parse_args(array_shift($donor->address[$args['address_type']]), $default_address); |
|
| 523 | 523 | break; |
| 524 | 524 | } |
| 525 | 525 | |
@@ -539,19 +539,19 @@ discard block |
||
| 539 | 539 | * |
| 540 | 540 | * @return void |
| 541 | 541 | */ |
| 542 | -function give_new_user_notification( $donation_id = 0, $donation_data = array() ) { |
|
| 542 | +function give_new_user_notification($donation_id = 0, $donation_data = array()) { |
|
| 543 | 543 | // Bailout. |
| 544 | 544 | if ( |
| 545 | - empty( $donation_id ) |
|
| 546 | - || empty( $donation_data ) |
|
| 547 | - || ! isset( $_POST['give_create_account'] ) |
|
| 548 | - || 'on' !== give_clean( $_POST['give_create_account'] ) |
|
| 545 | + empty($donation_id) |
|
| 546 | + || empty($donation_data) |
|
| 547 | + || ! isset($_POST['give_create_account']) |
|
| 548 | + || 'on' !== give_clean($_POST['give_create_account']) |
|
| 549 | 549 | ) { |
| 550 | 550 | return; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | // For backward compatibility |
| 554 | - $user = get_user_by( 'ID', $donation_data['user_info']['id'] ); |
|
| 554 | + $user = get_user_by('ID', $donation_data['user_info']['id']); |
|
| 555 | 555 | |
| 556 | 556 | $donation_data['user_info'] = array_merge( |
| 557 | 557 | $donation_data['user_info'], |
@@ -564,11 +564,11 @@ discard block |
||
| 564 | 564 | ) |
| 565 | 565 | ); |
| 566 | 566 | |
| 567 | - do_action( 'give_new-donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id ); |
|
| 568 | - do_action( 'give_donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id ); |
|
| 567 | + do_action('give_new-donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id); |
|
| 568 | + do_action('give_donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | -add_action( 'give_insert_payment', 'give_new_user_notification', 10, 2 ); |
|
| 571 | +add_action('give_insert_payment', 'give_new_user_notification', 10, 2); |
|
| 572 | 572 | |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -584,37 +584,37 @@ discard block |
||
| 584 | 584 | * |
| 585 | 585 | * @return string |
| 586 | 586 | */ |
| 587 | -function give_get_donor_name_by( $id = 0, $from = 'donation' ) { |
|
| 587 | +function give_get_donor_name_by($id = 0, $from = 'donation') { |
|
| 588 | 588 | |
| 589 | 589 | // ID shouldn't be empty. |
| 590 | - if ( empty( $id ) ) { |
|
| 590 | + if (empty($id)) { |
|
| 591 | 591 | return ''; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | $name = ''; |
| 595 | 595 | $title_prefix = ''; |
| 596 | 596 | |
| 597 | - switch ( $from ) { |
|
| 597 | + switch ($from) { |
|
| 598 | 598 | |
| 599 | 599 | case 'donation': |
| 600 | - $title_prefix = give_get_meta( $id, '_give_payment_donor_title_prefix', true ); |
|
| 601 | - $first_name = give_get_meta( $id, '_give_donor_billing_first_name', true ); |
|
| 602 | - $last_name = give_get_meta( $id, '_give_donor_billing_last_name', true ); |
|
| 600 | + $title_prefix = give_get_meta($id, '_give_payment_donor_title_prefix', true); |
|
| 601 | + $first_name = give_get_meta($id, '_give_donor_billing_first_name', true); |
|
| 602 | + $last_name = give_get_meta($id, '_give_donor_billing_last_name', true); |
|
| 603 | 603 | |
| 604 | 604 | $name = "{$first_name} {$last_name}"; |
| 605 | 605 | |
| 606 | 606 | break; |
| 607 | 607 | |
| 608 | 608 | case 'donor': |
| 609 | - $name = Give()->donors->get_column( 'name', $id ); |
|
| 610 | - $title_prefix = Give()->donor_meta->get_meta( $id, '_give_donor_title_prefix', true ); |
|
| 609 | + $name = Give()->donors->get_column('name', $id); |
|
| 610 | + $title_prefix = Give()->donor_meta->get_meta($id, '_give_donor_title_prefix', true); |
|
| 611 | 611 | |
| 612 | 612 | break; |
| 613 | 613 | |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // If title prefix is set then prepend it to name. |
| 617 | - $name = give_get_donor_name_with_title_prefixes( $title_prefix, $name ); |
|
| 617 | + $name = give_get_donor_name_with_title_prefixes($title_prefix, $name); |
|
| 618 | 618 | |
| 619 | 619 | return $name; |
| 620 | 620 | |
@@ -629,8 +629,8 @@ discard block |
||
| 629 | 629 | * |
| 630 | 630 | * @return boolean The user's ID on success, and false on failure. |
| 631 | 631 | */ |
| 632 | -function give_donor_email_exists( $email ) { |
|
| 633 | - if ( Give()->donors->get_donor_by( 'email', $email ) ) { |
|
| 632 | +function give_donor_email_exists($email) { |
|
| 633 | + if (Give()->donors->get_donor_by('email', $email)) { |
|
| 634 | 634 | return true; |
| 635 | 635 | } |
| 636 | 636 | return false; |
@@ -645,14 +645,14 @@ discard block |
||
| 645 | 645 | * |
| 646 | 646 | * @return bool |
| 647 | 647 | */ |
| 648 | -function give_is_additional_email( $email ) { |
|
| 648 | +function give_is_additional_email($email) { |
|
| 649 | 649 | global $wpdb; |
| 650 | 650 | |
| 651 | 651 | $meta_table = Give()->donor_meta->table_name; |
| 652 | 652 | $meta_type = Give()->donor_meta->meta_type; |
| 653 | - $donor_id = $wpdb->get_var( $wpdb->prepare( "SELECT {$meta_type}_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $email ) ); |
|
| 653 | + $donor_id = $wpdb->get_var($wpdb->prepare("SELECT {$meta_type}_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $email)); |
|
| 654 | 654 | |
| 655 | - if ( empty( $donor_id ) ) { |
|
| 655 | + if (empty($donor_id)) { |
|
| 656 | 656 | return false; |
| 657 | 657 | } |
| 658 | 658 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -23,13 +23,13 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @return bool true if has variable prices, false otherwise |
| 25 | 25 | */ |
| 26 | -function give_has_variable_prices( $form_id = 0 ) { |
|
| 26 | +function give_has_variable_prices($form_id = 0) { |
|
| 27 | 27 | |
| 28 | - if ( empty( $form_id ) ) { |
|
| 28 | + if (empty($form_id)) { |
|
| 29 | 29 | return false; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $form = new Give_Donate_Form( $form_id ); |
|
| 32 | + $form = new Give_Donate_Form($form_id); |
|
| 33 | 33 | |
| 34 | 34 | return $form->has_variable_prices(); |
| 35 | 35 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return array|bool Variable prices |
| 46 | 46 | */ |
| 47 | -function give_get_variable_prices( $form_id = 0 ) { |
|
| 47 | +function give_get_variable_prices($form_id = 0) { |
|
| 48 | 48 | |
| 49 | - if ( empty( $form_id ) ) { |
|
| 49 | + if (empty($form_id)) { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $form = new Give_Donate_Form( $form_id ); |
|
| 53 | + $form = new Give_Donate_Form($form_id); |
|
| 54 | 54 | |
| 55 | 55 | return $form->prices; |
| 56 | 56 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return array Variable prices |
| 67 | 67 | */ |
| 68 | -function give_get_variable_price_ids( $form_id = 0 ) { |
|
| 69 | - if( ! ( $prices = give_get_variable_prices( $form_id ) ) ) { |
|
| 68 | +function give_get_variable_price_ids($form_id = 0) { |
|
| 69 | + if ( ! ($prices = give_get_variable_prices($form_id))) { |
|
| 70 | 70 | return array(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $price_ids = array(); |
| 74 | - foreach ( $prices as $price ){ |
|
| 74 | + foreach ($prices as $price) { |
|
| 75 | 75 | $price_ids[] = $price['_give_id']['level_id']; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string $default_price |
| 91 | 91 | */ |
| 92 | -function give_get_default_multilevel_amount( $form_id ) { |
|
| 92 | +function give_get_default_multilevel_amount($form_id) { |
|
| 93 | 93 | $default_price = '1.00'; |
| 94 | 94 | |
| 95 | 95 | // Get default level price data. |
| 96 | - $default_level = give_form_get_default_level( $form_id ); |
|
| 97 | - $default_price = isset( $default_level['_give_amount'] ) ? $default_level['_give_amount'] : $default_price; |
|
| 96 | + $default_level = give_form_get_default_level($form_id); |
|
| 97 | + $default_price = isset($default_level['_give_amount']) ? $default_level['_give_amount'] : $default_price; |
|
| 98 | 98 | |
| 99 | 99 | return $default_price; |
| 100 | 100 | } |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @return string $default_price |
| 111 | 111 | * @since 1.0 |
| 112 | 112 | */ |
| 113 | -function give_get_default_form_amount( $form_id ) { |
|
| 113 | +function give_get_default_form_amount($form_id) { |
|
| 114 | 114 | |
| 115 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 115 | + if (give_has_variable_prices($form_id)) { |
|
| 116 | 116 | |
| 117 | - $default_amount = give_get_default_multilevel_amount( $form_id ); |
|
| 117 | + $default_amount = give_get_default_multilevel_amount($form_id); |
|
| 118 | 118 | |
| 119 | 119 | } else { |
| 120 | 120 | |
| 121 | - $default_amount = give_get_meta( $form_id, '_give_set_price', true ); |
|
| 121 | + $default_amount = give_get_meta($form_id, '_give_set_price', true); |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return apply_filters( 'give_default_form_amount', $default_amount, $form_id ); |
|
| 125 | + return apply_filters('give_default_form_amount', $default_amount, $form_id); |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return bool |
| 142 | 142 | */ |
| 143 | -function give_is_custom_price_mode( $form_id = 0 ) { |
|
| 143 | +function give_is_custom_price_mode($form_id = 0) { |
|
| 144 | 144 | |
| 145 | - if ( empty( $form_id ) ) { |
|
| 145 | + if (empty($form_id)) { |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $form = new Give_Donate_Form( $form_id ); |
|
| 149 | + $form = new Give_Donate_Form($form_id); |
|
| 150 | 150 | |
| 151 | 151 | return $form->is_custom_price_mode(); |
| 152 | 152 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return float|int Total amount of donations based on the passed arguments. |
| 40 | 40 | */ |
| 41 | - public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
|
| 41 | + public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { |
|
| 42 | 42 | |
| 43 | - $this->setup_dates( $start_date, $end_date ); |
|
| 43 | + $this->setup_dates($start_date, $end_date); |
|
| 44 | 44 | |
| 45 | 45 | // Make sure start date is valid |
| 46 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 46 | + if (is_wp_error($this->start_date)) { |
|
| 47 | 47 | return $this->start_date; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Make sure end date is valid |
| 51 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 51 | + if (is_wp_error($this->end_date)) { |
|
| 52 | 52 | return $this->end_date; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | 'start_date' => $this->start_date, |
| 58 | 58 | 'end_date' => $this->end_date, |
| 59 | 59 | 'fields' => 'ids', |
| 60 | - 'number' => - 1, |
|
| 60 | + 'number' => -1, |
|
| 61 | 61 | 'output' => '' |
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | - if ( ! empty( $form_id ) ) { |
|
| 64 | + if ( ! empty($form_id)) { |
|
| 65 | 65 | $args['give_forms'] = $form_id; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /* @var Give_Payments_Query $payments */ |
| 69 | - $payments = new Give_Payments_Query( $args ); |
|
| 69 | + $payments = new Give_Payments_Query($args); |
|
| 70 | 70 | $payments = $payments->get_payments(); |
| 71 | 71 | |
| 72 | - return count( $payments ); |
|
| 72 | + return count($payments); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,17 +86,17 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return float|int Total amount of donations based on the passed arguments. |
| 88 | 88 | */ |
| 89 | - public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
| 89 | + public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
| 90 | 90 | global $wpdb; |
| 91 | - $this->setup_dates( $start_date, $end_date ); |
|
| 91 | + $this->setup_dates($start_date, $end_date); |
|
| 92 | 92 | |
| 93 | 93 | // Make sure start date is valid |
| 94 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 94 | + if (is_wp_error($this->start_date)) { |
|
| 95 | 95 | return $this->start_date; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Make sure end date is valid |
| 99 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 99 | + if (is_wp_error($this->end_date)) { |
|
| 100 | 100 | return $this->end_date; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | 'start_date' => $this->start_date, |
| 107 | 107 | 'end_date' => $this->end_date, |
| 108 | 108 | 'fields' => 'ids', |
| 109 | - 'number' => - 1, |
|
| 109 | + 'number' => -1, |
|
| 110 | 110 | 'output' => '', |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | // Filter by Gateway ID meta_key |
| 115 | - if ( $gateway_id ) { |
|
| 115 | + if ($gateway_id) { |
|
| 116 | 116 | $args['meta_query'][] = array( |
| 117 | 117 | 'key' => '_give_payment_gateway', |
| 118 | 118 | 'value' => $gateway_id, |
@@ -120,41 +120,41 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Filter by Gateway ID meta_key |
| 123 | - if ( $form_id ) { |
|
| 123 | + if ($form_id) { |
|
| 124 | 124 | $args['meta_query'][] = array( |
| 125 | 125 | 'key' => '_give_payment_form_id', |
| 126 | 126 | 'value' => $form_id, |
| 127 | 127 | ); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
| 130 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
| 131 | 131 | $args['meta_query']['relation'] = 'AND'; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 135 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
| 134 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 135 | + $key = Give_Cache::get_key('give_stats', $args); |
|
| 136 | 136 | |
| 137 | 137 | // Set transient for faster stats. |
| 138 | - $earnings = Give_Cache::get( $key ); |
|
| 138 | + $earnings = Give_Cache::get($key); |
|
| 139 | 139 | |
| 140 | - if ( false === $earnings ) { |
|
| 140 | + if (false === $earnings) { |
|
| 141 | 141 | |
| 142 | 142 | $this->timestamp = false; |
| 143 | - $payments = new Give_Payments_Query( $args ); |
|
| 143 | + $payments = new Give_Payments_Query($args); |
|
| 144 | 144 | $payments = $payments->get_payments(); |
| 145 | 145 | $earnings = 0; |
| 146 | 146 | |
| 147 | - if ( ! empty( $payments ) ) { |
|
| 148 | - $donation_id_col = Give()->payment_meta->get_meta_type() . '_id'; |
|
| 147 | + if ( ! empty($payments)) { |
|
| 148 | + $donation_id_col = Give()->payment_meta->get_meta_type().'_id'; |
|
| 149 | 149 | $query = "SELECT {$donation_id_col} as id, meta_value as total |
| 150 | 150 | FROM {$wpdb->donationmeta} |
| 151 | 151 | WHERE meta_key='_give_payment_total' |
| 152 | - AND {$donation_id_col} IN ('". implode( '\',\'', $payments ) ."')"; |
|
| 152 | + AND {$donation_id_col} IN ('".implode('\',\'', $payments)."')"; |
|
| 153 | 153 | |
| 154 | 154 | $payments = $wpdb->get_results($query, ARRAY_A); |
| 155 | 155 | |
| 156 | - if( ! empty( $payments ) ) { |
|
| 157 | - foreach ( $payments as $payment ) { |
|
| 156 | + if ( ! empty($payments)) { |
|
| 157 | + foreach ($payments as $payment) { |
|
| 158 | 158 | /** |
| 159 | 159 | * Filter the donation amount |
| 160 | 160 | * Note: this filter documented in payments/functions.php:give_donation_amount() |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | $formatted_amount = apply_filters( |
| 165 | 165 | 'give_donation_amount', |
| 166 | - give_format_amount( $payment['total'], array( 'donation_id' => $payment['id'] ) ), |
|
| 166 | + give_format_amount($payment['total'], array('donation_id' => $payment['id'])), |
|
| 167 | 167 | $payment['total'], |
| 168 | 168 | $payment['id'], |
| 169 | - array( 'type' => 'stats', 'currency'=> false, 'amount' => false ) |
|
| 169 | + array('type' => 'stats', 'currency'=> false, 'amount' => false) |
|
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | - $earnings += (float) give_maybe_sanitize_amount( $formatted_amount ); |
|
| 172 | + $earnings += (float) give_maybe_sanitize_amount($formatted_amount); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Cache the results for one hour. |
| 179 | - Give_Cache::set( $key, give_sanitize_amount_for_db( $earnings ), 60 * 60 ); |
|
| 179 | + Give_Cache::set($key, give_sanitize_amount_for_db($earnings), 60 * 60); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | * @param string|bool $end_date Earning end date. |
| 191 | 191 | * @param string|bool $gateway_id Payment gateway id. |
| 192 | 192 | */ |
| 193 | - $earnings = apply_filters( 'give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id ); |
|
| 193 | + $earnings = apply_filters('give_get_earnings', $earnings, $form_id, $start_date, $end_date, $gateway_id); |
|
| 194 | 194 | |
| 195 | 195 | //return earnings |
| 196 | - return round( $earnings, give_get_price_decimals( $form_id ) ); |
|
| 196 | + return round($earnings, give_get_price_decimals($form_id)); |
|
| 197 | 197 | |
| 198 | 198 | } |
| 199 | 199 | |
@@ -210,17 +210,17 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return float|int Total amount of donations based on the passed arguments. |
| 212 | 212 | */ |
| 213 | - public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
| 213 | + public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
| 214 | 214 | |
| 215 | - $this->setup_dates( $start_date, $end_date ); |
|
| 215 | + $this->setup_dates($start_date, $end_date); |
|
| 216 | 216 | |
| 217 | 217 | // Make sure start date is valid |
| 218 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 218 | + if (is_wp_error($this->start_date)) { |
|
| 219 | 219 | return $this->start_date; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Make sure end date is valid |
| 223 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 223 | + if (is_wp_error($this->end_date)) { |
|
| 224 | 224 | return $this->end_date; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | 'start_date' => $this->start_date, |
| 231 | 231 | 'end_date' => $this->end_date, |
| 232 | 232 | 'fields' => 'ids', |
| 233 | - 'number' => - 1, |
|
| 233 | + 'number' => -1, |
|
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // Filter by Gateway ID meta_key |
| 238 | - if ( $gateway_id ) { |
|
| 238 | + if ($gateway_id) { |
|
| 239 | 239 | $args['meta_query'][] = array( |
| 240 | 240 | 'key' => '_give_payment_gateway', |
| 241 | 241 | 'value' => $gateway_id, |
@@ -243,19 +243,19 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Filter by Gateway ID meta_key |
| 246 | - if ( $form_id ) { |
|
| 246 | + if ($form_id) { |
|
| 247 | 247 | $args['meta_query'][] = array( |
| 248 | 248 | 'key' => '_give_payment_form_id', |
| 249 | 249 | 'value' => $form_id, |
| 250 | 250 | ); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
| 253 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
| 254 | 254 | $args['meta_query']['relation'] = 'AND'; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 258 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
| 257 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 258 | + $key = Give_Cache::get_key('give_stats', $args); |
|
| 259 | 259 | |
| 260 | 260 | //return earnings |
| 261 | 261 | return $key; |
@@ -273,17 +273,17 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return array Best selling forms |
| 275 | 275 | */ |
| 276 | - public function get_best_selling( $number = 10 ) { |
|
| 276 | + public function get_best_selling($number = 10) { |
|
| 277 | 277 | global $wpdb; |
| 278 | 278 | |
| 279 | - $meta_table = __give_v20_bc_table_details( 'form' ); |
|
| 279 | + $meta_table = __give_v20_bc_table_details('form'); |
|
| 280 | 280 | |
| 281 | - $give_forms = $wpdb->get_results( $wpdb->prepare( |
|
| 281 | + $give_forms = $wpdb->get_results($wpdb->prepare( |
|
| 282 | 282 | "SELECT {$meta_table['column']['id']} as form_id, max(meta_value) as sales |
| 283 | 283 | FROM {$meta_table['name']} WHERE meta_key='_give_form_sales' AND meta_value > 0 |
| 284 | 284 | GROUP BY meta_value+0 |
| 285 | 285 | DESC LIMIT %d;", $number |
| 286 | - ) ); |
|
| 286 | + )); |
|
| 287 | 287 | |
| 288 | 288 | return $give_forms; |
| 289 | 289 | } |
@@ -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 | |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return array $payments Payments retrieved from the database |
| 46 | 46 | */ |
| 47 | -function give_get_payments( $args = array() ) { |
|
| 47 | +function give_get_payments($args = array()) { |
|
| 48 | 48 | |
| 49 | 49 | // Fallback to post objects to ensure backwards compatibility. |
| 50 | - if ( ! isset( $args['output'] ) ) { |
|
| 50 | + if ( ! isset($args['output'])) { |
|
| 51 | 51 | $args['output'] = 'posts'; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $args = apply_filters( 'give_get_payments_args', $args ); |
|
| 55 | - $payments = new Give_Payments_Query( $args ); |
|
| 54 | + $args = apply_filters('give_get_payments_args', $args); |
|
| 55 | + $payments = new Give_Payments_Query($args); |
|
| 56 | 56 | |
| 57 | 57 | return $payments->get_payments(); |
| 58 | 58 | } |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @return mixed |
| 69 | 69 | */ |
| 70 | -function give_get_payment_by( $field = '', $value = '' ) { |
|
| 70 | +function give_get_payment_by($field = '', $value = '') { |
|
| 71 | 71 | |
| 72 | - if ( empty( $field ) || empty( $value ) ) { |
|
| 72 | + if (empty($field) || empty($value)) { |
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - switch ( strtolower( $field ) ) { |
|
| 76 | + switch (strtolower($field)) { |
|
| 77 | 77 | |
| 78 | 78 | case 'id': |
| 79 | - $payment = new Give_Payment( $value ); |
|
| 79 | + $payment = new Give_Payment($value); |
|
| 80 | 80 | $id = $payment->ID; |
| 81 | 81 | |
| 82 | - if ( empty( $id ) ) { |
|
| 82 | + if (empty($id)) { |
|
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | ) |
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | - if ( $payment ) { |
|
| 99 | - $payment = new Give_Payment( $payment[0] ); |
|
| 98 | + if ($payment) { |
|
| 99 | + $payment = new Give_Payment($payment[0]); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | break; |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | ) |
| 112 | 112 | ); |
| 113 | 113 | |
| 114 | - if ( $payment ) { |
|
| 115 | - $payment = new Give_Payment( $payment[0] ); |
|
| 114 | + if ($payment) { |
|
| 115 | + $payment = new Give_Payment($payment[0]); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | break; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | return false; |
| 122 | 122 | }// End switch(). |
| 123 | 123 | |
| 124 | - if ( $payment ) { |
|
| 124 | + if ($payment) { |
|
| 125 | 125 | return $payment; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return int|bool Payment ID if payment is inserted, false otherwise. |
| 139 | 139 | */ |
| 140 | -function give_insert_payment( $payment_data = array() ) { |
|
| 140 | +function give_insert_payment($payment_data = array()) { |
|
| 141 | 141 | |
| 142 | - if ( empty( $payment_data ) ) { |
|
| 142 | + if (empty($payment_data)) { |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -150,35 +150,35 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @param array $payment_data Arguments passed. |
| 152 | 152 | */ |
| 153 | - $payment_data = apply_filters( 'give_pre_insert_payment', $payment_data ); |
|
| 153 | + $payment_data = apply_filters('give_pre_insert_payment', $payment_data); |
|
| 154 | 154 | |
| 155 | 155 | $payment = new Give_Payment(); |
| 156 | - $gateway = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : ''; |
|
| 157 | - $gateway = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? give_clean( $_POST['give-gateway'] ) : $gateway; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 158 | - $form_id = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0; |
|
| 159 | - $price_id = give_get_payment_meta_price_id( $payment_data ); |
|
| 160 | - $form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id ); |
|
| 156 | + $gateway = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : ''; |
|
| 157 | + $gateway = empty($gateway) && isset($_POST['give-gateway']) ? give_clean($_POST['give-gateway']) : $gateway; // WPCS: input var ok, sanitization ok, CSRF ok. |
|
| 158 | + $form_id = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0; |
|
| 159 | + $price_id = give_get_payment_meta_price_id($payment_data); |
|
| 160 | + $form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id); |
|
| 161 | 161 | |
| 162 | 162 | // Set properties. |
| 163 | 163 | $payment->total = $payment_data['price']; |
| 164 | - $payment->status = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending'; |
|
| 165 | - $payment->currency = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency( $payment_data['give_form_id'], $payment_data ); |
|
| 164 | + $payment->status = ! empty($payment_data['status']) ? $payment_data['status'] : 'pending'; |
|
| 165 | + $payment->currency = ! empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency($payment_data['give_form_id'], $payment_data); |
|
| 166 | 166 | $payment->user_info = $payment_data['user_info']; |
| 167 | 167 | $payment->gateway = $gateway; |
| 168 | 168 | $payment->form_title = $form_title; |
| 169 | 169 | $payment->form_id = $form_id; |
| 170 | 170 | $payment->price_id = $price_id; |
| 171 | - $payment->donor_id = ( ! empty( $payment_data['donor_id'] ) ? $payment_data['donor_id'] : '' ); |
|
| 171 | + $payment->donor_id = ( ! empty($payment_data['donor_id']) ? $payment_data['donor_id'] : ''); |
|
| 172 | 172 | $payment->user_id = $payment_data['user_info']['id']; |
| 173 | 173 | $payment->email = $payment_data['user_email']; |
| 174 | 174 | $payment->first_name = $payment_data['user_info']['first_name']; |
| 175 | 175 | $payment->last_name = $payment_data['user_info']['last_name']; |
| 176 | - $payment->title_prefix = ! empty( $payment_data['user_info']['title'] ) ? $payment_data['user_info']['title'] : ''; |
|
| 176 | + $payment->title_prefix = ! empty($payment_data['user_info']['title']) ? $payment_data['user_info']['title'] : ''; |
|
| 177 | 177 | $payment->email = $payment_data['user_info']['email']; |
| 178 | 178 | $payment->ip = give_get_ip(); |
| 179 | 179 | $payment->key = $payment_data['purchase_key']; |
| 180 | - $payment->mode = ( ! empty( $payment_data['mode'] ) ? (string) $payment_data['mode'] : ( give_is_test_mode() ? 'test' : 'live' ) ); |
|
| 181 | - $payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : ''; |
|
| 180 | + $payment->mode = ( ! empty($payment_data['mode']) ? (string) $payment_data['mode'] : (give_is_test_mode() ? 'test' : 'live')); |
|
| 181 | + $payment->parent_payment = ! empty($payment_data['parent']) ? absint($payment_data['parent']) : ''; |
|
| 182 | 182 | |
| 183 | 183 | // Add the donation. |
| 184 | 184 | $args = array( |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | 'price_id' => $payment->price_id, |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - $payment->add_donation( $payment->form_id, $args ); |
|
| 189 | + $payment->add_donation($payment->form_id, $args); |
|
| 190 | 190 | |
| 191 | 191 | // Set date if present. |
| 192 | - if ( isset( $payment_data['post_date'] ) ) { |
|
| 192 | + if (isset($payment_data['post_date'])) { |
|
| 193 | 193 | $payment->date = $payment_data['post_date']; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | * @param int $payment_id The payment ID. |
| 208 | 208 | * @param array $payment_data Arguments passed. |
| 209 | 209 | */ |
| 210 | - do_action( 'give_insert_payment', $payment->ID, $payment_data ); |
|
| 210 | + do_action('give_insert_payment', $payment->ID, $payment_data); |
|
| 211 | 211 | |
| 212 | 212 | // Return payment ID upon success. |
| 213 | - if ( ! empty( $payment->ID ) ) { |
|
| 213 | + if ( ! empty($payment->ID)) { |
|
| 214 | 214 | return $payment->ID; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return bool|int |
| 228 | 228 | */ |
| 229 | -function give_create_payment( $payment_data ) { |
|
| 229 | +function give_create_payment($payment_data) { |
|
| 230 | 230 | |
| 231 | - $form_id = intval( $payment_data['post_data']['give-form-id'] ); |
|
| 232 | - $price_id = isset( $payment_data['post_data']['give-price-id'] ) ? $payment_data['post_data']['give-price-id'] : ''; |
|
| 231 | + $form_id = intval($payment_data['post_data']['give-form-id']); |
|
| 232 | + $price_id = isset($payment_data['post_data']['give-price-id']) ? $payment_data['post_data']['give-price-id'] : ''; |
|
| 233 | 233 | |
| 234 | 234 | // Collect payment data. |
| 235 | 235 | $insert_payment_data = array( |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | 'date' => $payment_data['date'], |
| 241 | 241 | 'user_email' => $payment_data['user_email'], |
| 242 | 242 | 'purchase_key' => $payment_data['purchase_key'], |
| 243 | - 'currency' => give_get_currency( $form_id, $payment_data ), |
|
| 243 | + 'currency' => give_get_currency($form_id, $payment_data), |
|
| 244 | 244 | 'user_info' => $payment_data['user_info'], |
| 245 | 245 | 'status' => 'pending', |
| 246 | 246 | 'gateway' => 'paypal', |
@@ -253,10 +253,10 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @param array $insert_payment_data |
| 255 | 255 | */ |
| 256 | - $insert_payment_data = apply_filters( 'give_create_payment', $insert_payment_data ); |
|
| 256 | + $insert_payment_data = apply_filters('give_create_payment', $insert_payment_data); |
|
| 257 | 257 | |
| 258 | 258 | // Record the pending payment. |
| 259 | - return give_insert_payment( $insert_payment_data ); |
|
| 259 | + return give_insert_payment($insert_payment_data); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -269,12 +269,12 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return bool |
| 271 | 271 | */ |
| 272 | -function give_update_payment_status( $payment_id, $new_status = 'publish' ) { |
|
| 272 | +function give_update_payment_status($payment_id, $new_status = 'publish') { |
|
| 273 | 273 | |
| 274 | 274 | $updated = false; |
| 275 | - $payment = new Give_Payment( $payment_id ); |
|
| 275 | + $payment = new Give_Payment($payment_id); |
|
| 276 | 276 | |
| 277 | - if ( $payment && $payment->ID > 0 ) { |
|
| 277 | + if ($payment && $payment->ID > 0) { |
|
| 278 | 278 | |
| 279 | 279 | $payment->status = $new_status; |
| 280 | 280 | $updated = $payment->save(); |
@@ -295,17 +295,17 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return void |
| 297 | 297 | */ |
| 298 | -function give_delete_donation( $payment_id = 0, $update_donor = true ) { |
|
| 299 | - $payment = new Give_Payment( $payment_id ); |
|
| 298 | +function give_delete_donation($payment_id = 0, $update_donor = true) { |
|
| 299 | + $payment = new Give_Payment($payment_id); |
|
| 300 | 300 | |
| 301 | 301 | // Bailout. |
| 302 | - if ( ! $payment->ID ) { |
|
| 302 | + if ( ! $payment->ID) { |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - $amount = give_donation_amount( $payment_id ); |
|
| 306 | + $amount = give_donation_amount($payment_id); |
|
| 307 | 307 | $status = $payment->post_status; |
| 308 | - $donor = new Give_Donor( $payment->donor_id ); |
|
| 308 | + $donor = new Give_Donor($payment->donor_id); |
|
| 309 | 309 | |
| 310 | 310 | // Only undo donations that aren't these statuses. |
| 311 | 311 | $dont_undo_statuses = apply_filters( |
@@ -315,26 +315,26 @@ discard block |
||
| 315 | 315 | ) |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - if ( ! in_array( $status, $dont_undo_statuses ) ) { |
|
| 319 | - give_undo_donation( $payment_id ); |
|
| 318 | + if ( ! in_array($status, $dont_undo_statuses)) { |
|
| 319 | + give_undo_donation($payment_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Only undo donations that aren't these statuses. |
| 323 | - $status_to_decrease_stats = apply_filters( 'give_decrease_donor_statuses', array( 'publish' ) ); |
|
| 323 | + $status_to_decrease_stats = apply_filters('give_decrease_donor_statuses', array('publish')); |
|
| 324 | 324 | |
| 325 | - if ( in_array( $status, $status_to_decrease_stats ) ) { |
|
| 325 | + if (in_array($status, $status_to_decrease_stats)) { |
|
| 326 | 326 | |
| 327 | 327 | // Only decrease earnings if they haven't already been decreased (or were never increased for this payment). |
| 328 | - give_decrease_total_earnings( $amount ); |
|
| 328 | + give_decrease_total_earnings($amount); |
|
| 329 | 329 | |
| 330 | 330 | // @todo: Refresh only range related stat cache |
| 331 | 331 | give_delete_donation_stats(); |
| 332 | 332 | |
| 333 | - if ( $donor->id && $update_donor ) { |
|
| 333 | + if ($donor->id && $update_donor) { |
|
| 334 | 334 | |
| 335 | 335 | // Decrement the stats for the donor. |
| 336 | 336 | $donor->decrease_donation_count(); |
| 337 | - $donor->decrease_value( $amount ); |
|
| 337 | + $donor->decrease_value($amount); |
|
| 338 | 338 | |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -346,20 +346,20 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @since 1.0 |
| 348 | 348 | */ |
| 349 | - do_action( 'give_payment_delete', $payment_id ); |
|
| 349 | + do_action('give_payment_delete', $payment_id); |
|
| 350 | 350 | |
| 351 | - if ( $donor->id && $update_donor ) { |
|
| 351 | + if ($donor->id && $update_donor) { |
|
| 352 | 352 | // Remove the payment ID from the donor. |
| 353 | - $donor->remove_payment( $payment_id ); |
|
| 353 | + $donor->remove_payment($payment_id); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Remove the payment. |
| 357 | - wp_delete_post( $payment_id, true ); |
|
| 357 | + wp_delete_post($payment_id, true); |
|
| 358 | 358 | |
| 359 | - Give()->payment_meta->delete_all_meta( $payment_id ); |
|
| 359 | + Give()->payment_meta->delete_all_meta($payment_id); |
|
| 360 | 360 | |
| 361 | 361 | // Remove related sale log entries. |
| 362 | - Give()->logs->delete_logs( $payment_id ); |
|
| 362 | + Give()->logs->delete_logs($payment_id); |
|
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | 365 | * Fires after payment deleted. |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * |
| 369 | 369 | * @since 1.0 |
| 370 | 370 | */ |
| 371 | - do_action( 'give_payment_deleted', $payment_id ); |
|
| 371 | + do_action('give_payment_deleted', $payment_id); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -383,20 +383,20 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @return void |
| 385 | 385 | */ |
| 386 | -function give_undo_donation( $payment_id ) { |
|
| 386 | +function give_undo_donation($payment_id) { |
|
| 387 | 387 | |
| 388 | - $payment = new Give_Payment( $payment_id ); |
|
| 388 | + $payment = new Give_Payment($payment_id); |
|
| 389 | 389 | |
| 390 | - $maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id ); |
|
| 391 | - if ( true === $maybe_decrease_earnings ) { |
|
| 390 | + $maybe_decrease_earnings = apply_filters('give_decrease_earnings_on_undo', true, $payment, $payment->form_id); |
|
| 391 | + if (true === $maybe_decrease_earnings) { |
|
| 392 | 392 | // Decrease earnings. |
| 393 | - give_decrease_form_earnings( $payment->form_id, $payment->total, $payment_id ); |
|
| 393 | + give_decrease_form_earnings($payment->form_id, $payment->total, $payment_id); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - $maybe_decrease_donations = apply_filters( 'give_decrease_donations_on_undo', true, $payment, $payment->form_id ); |
|
| 397 | - if ( true === $maybe_decrease_donations ) { |
|
| 396 | + $maybe_decrease_donations = apply_filters('give_decrease_donations_on_undo', true, $payment, $payment->form_id); |
|
| 397 | + if (true === $maybe_decrease_donations) { |
|
| 398 | 398 | // Decrease donation count. |
| 399 | - give_decrease_donation_count( $payment->form_id ); |
|
| 399 | + give_decrease_donation_count($payment->form_id); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | } |
@@ -413,21 +413,21 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @return object $stats Contains the number of payments per payment status. |
| 415 | 415 | */ |
| 416 | -function give_count_payments( $args = array() ) { |
|
| 416 | +function give_count_payments($args = array()) { |
|
| 417 | 417 | // Backward compatibility. |
| 418 | - if ( ! empty( $args['start-date'] ) ) { |
|
| 418 | + if ( ! empty($args['start-date'])) { |
|
| 419 | 419 | $args['start_date'] = $args['start-date']; |
| 420 | - unset( $args['start-date'] ); |
|
| 420 | + unset($args['start-date']); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if ( ! empty( $args['end-date'] ) ) { |
|
| 423 | + if ( ! empty($args['end-date'])) { |
|
| 424 | 424 | $args['end_date'] = $args['end-date']; |
| 425 | - unset( $args['end-date'] ); |
|
| 425 | + unset($args['end-date']); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if ( ! empty( $args['form_id'] ) ) { |
|
| 428 | + if ( ! empty($args['form_id'])) { |
|
| 429 | 429 | $args['give_forms'] = $args['form_id']; |
| 430 | - unset( $args['form_id'] ); |
|
| 430 | + unset($args['form_id']); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | // Extract all donations |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | $args['group_by'] = 'post_status'; |
| 436 | 436 | $args['count'] = 'true'; |
| 437 | 437 | |
| 438 | - $donations_obj = new Give_Payments_Query( $args ); |
|
| 438 | + $donations_obj = new Give_Payments_Query($args); |
|
| 439 | 439 | $donations_count = $donations_obj->get_payment_by_group(); |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | * |
| 444 | 444 | * @since 1.0 |
| 445 | 445 | */ |
| 446 | - return (object) apply_filters( 'give_count_payments', $donations_count, $args, $donations_obj ); |
|
| 446 | + return (object) apply_filters('give_count_payments', $donations_count, $args, $donations_obj); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * |
| 457 | 457 | * @return bool $exists True if payment exists, false otherwise. |
| 458 | 458 | */ |
| 459 | -function give_check_for_existing_payment( $payment_id ) { |
|
| 459 | +function give_check_for_existing_payment($payment_id) { |
|
| 460 | 460 | global $wpdb; |
| 461 | 461 | |
| 462 | 462 | return (bool) $wpdb->get_var( |
@@ -484,9 +484,9 @@ discard block |
||
| 484 | 484 | * |
| 485 | 485 | * @return bool|mixed True if payment status exists, false otherwise. |
| 486 | 486 | */ |
| 487 | -function give_get_payment_status( $payment_id, $return_label = false ) { |
|
| 487 | +function give_get_payment_status($payment_id, $return_label = false) { |
|
| 488 | 488 | |
| 489 | - if ( ! is_numeric( $payment_id ) ) { |
|
| 489 | + if ( ! is_numeric($payment_id)) { |
|
| 490 | 490 | if ( |
| 491 | 491 | $payment_id instanceof Give_Payment |
| 492 | 492 | || $payment_id instanceof WP_Post |
@@ -495,28 +495,28 @@ discard block |
||
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if ( ! $payment_id > 0 ) { |
|
| 498 | + if ( ! $payment_id > 0) { |
|
| 499 | 499 | return false; |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - $payment_status = get_post_status( $payment_id ); |
|
| 502 | + $payment_status = get_post_status($payment_id); |
|
| 503 | 503 | |
| 504 | 504 | $statuses = give_get_payment_statuses(); |
| 505 | 505 | |
| 506 | - if ( empty( $payment_status ) || ! is_array( $statuses ) || empty( $statuses ) ) { |
|
| 506 | + if (empty($payment_status) || ! is_array($statuses) || empty($statuses)) { |
|
| 507 | 507 | return false; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - if ( array_key_exists( $payment_status, $statuses ) ) { |
|
| 511 | - if ( true === $return_label ) { |
|
| 510 | + if (array_key_exists($payment_status, $statuses)) { |
|
| 511 | + if (true === $return_label) { |
|
| 512 | 512 | // Return translated status label. |
| 513 | - return $statuses[ $payment_status ]; |
|
| 513 | + return $statuses[$payment_status]; |
|
| 514 | 514 | } else { |
| 515 | 515 | // Account that our 'publish' status is labeled 'Complete' |
| 516 | 516 | $post_status = 'publish' === $payment_status ? 'Complete' : $payment_status; |
| 517 | 517 | |
| 518 | 518 | // Make sure we're matching cases, since they matter |
| 519 | - return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) ); |
|
| 519 | + return array_search(strtolower($post_status), array_map('strtolower', $statuses)); |
|
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
@@ -532,18 +532,18 @@ discard block |
||
| 532 | 532 | */ |
| 533 | 533 | function give_get_payment_statuses() { |
| 534 | 534 | $payment_statuses = array( |
| 535 | - 'pending' => __( 'Pending', 'give' ), |
|
| 536 | - 'publish' => __( 'Complete', 'give' ), |
|
| 537 | - 'refunded' => __( 'Refunded', 'give' ), |
|
| 538 | - 'failed' => __( 'Failed', 'give' ), |
|
| 539 | - 'cancelled' => __( 'Cancelled', 'give' ), |
|
| 540 | - 'abandoned' => __( 'Abandoned', 'give' ), |
|
| 541 | - 'preapproval' => __( 'Pre-Approved', 'give' ), |
|
| 542 | - 'processing' => __( 'Processing', 'give' ), |
|
| 543 | - 'revoked' => __( 'Revoked', 'give' ), |
|
| 535 | + 'pending' => __('Pending', 'give'), |
|
| 536 | + 'publish' => __('Complete', 'give'), |
|
| 537 | + 'refunded' => __('Refunded', 'give'), |
|
| 538 | + 'failed' => __('Failed', 'give'), |
|
| 539 | + 'cancelled' => __('Cancelled', 'give'), |
|
| 540 | + 'abandoned' => __('Abandoned', 'give'), |
|
| 541 | + 'preapproval' => __('Pre-Approved', 'give'), |
|
| 542 | + 'processing' => __('Processing', 'give'), |
|
| 543 | + 'revoked' => __('Revoked', 'give'), |
|
| 544 | 544 | ); |
| 545 | 545 | |
| 546 | - return apply_filters( 'give_payment_statuses', $payment_statuses ); |
|
| 546 | + return apply_filters('give_payment_statuses', $payment_statuses); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -556,10 +556,10 @@ discard block |
||
| 556 | 556 | * @return array $payment_status All the available payment statuses. |
| 557 | 557 | */ |
| 558 | 558 | function give_get_payment_status_keys() { |
| 559 | - $statuses = array_keys( give_get_payment_statuses() ); |
|
| 560 | - asort( $statuses ); |
|
| 559 | + $statuses = array_keys(give_get_payment_statuses()); |
|
| 560 | + asort($statuses); |
|
| 561 | 561 | |
| 562 | - return array_values( $statuses ); |
|
| 562 | + return array_values($statuses); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -574,43 +574,43 @@ discard block |
||
| 574 | 574 | * |
| 575 | 575 | * @return int $earnings Earnings |
| 576 | 576 | */ |
| 577 | -function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) { |
|
| 577 | +function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) { |
|
| 578 | 578 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead. |
| 579 | 579 | global $wpdb; |
| 580 | - $meta_table = __give_v20_bc_table_details( 'payment' ); |
|
| 580 | + $meta_table = __give_v20_bc_table_details('payment'); |
|
| 581 | 581 | |
| 582 | 582 | $args = array( |
| 583 | 583 | 'post_type' => 'give_payment', |
| 584 | 584 | 'nopaging' => true, |
| 585 | 585 | 'year' => $year, |
| 586 | 586 | 'monthnum' => $month_num, |
| 587 | - 'post_status' => array( 'publish' ), |
|
| 587 | + 'post_status' => array('publish'), |
|
| 588 | 588 | 'fields' => 'ids', |
| 589 | 589 | 'update_post_term_cache' => false, |
| 590 | 590 | ); |
| 591 | - if ( ! empty( $day ) ) { |
|
| 591 | + if ( ! empty($day)) { |
|
| 592 | 592 | $args['day'] = $day; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - if ( isset( $hour ) ) { |
|
| 595 | + if (isset($hour)) { |
|
| 596 | 596 | $args['hour'] = $hour; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - $args = apply_filters( 'give_get_earnings_by_date_args', $args ); |
|
| 600 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
| 599 | + $args = apply_filters('give_get_earnings_by_date_args', $args); |
|
| 600 | + $key = Give_Cache::get_key('give_stats', $args); |
|
| 601 | 601 | |
| 602 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
| 602 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
| 603 | 603 | $earnings = false; |
| 604 | 604 | } else { |
| 605 | - $earnings = Give_Cache::get( $key ); |
|
| 605 | + $earnings = Give_Cache::get($key); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - if ( false === $earnings ) { |
|
| 609 | - $donations = get_posts( $args ); |
|
| 608 | + if (false === $earnings) { |
|
| 609 | + $donations = get_posts($args); |
|
| 610 | 610 | $earnings = 0; |
| 611 | - if ( $donations ) { |
|
| 612 | - $donations = implode( ',', $donations ); |
|
| 613 | - $earning_totals = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})" ); |
|
| 611 | + if ($donations) { |
|
| 612 | + $donations = implode(',', $donations); |
|
| 613 | + $earning_totals = $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})"); |
|
| 614 | 614 | |
| 615 | 615 | /** |
| 616 | 616 | * Filter The earnings by dates. |
@@ -621,13 +621,13 @@ discard block |
||
| 621 | 621 | * @param array $donations Donations lists. |
| 622 | 622 | * @param array $args Donation query args. |
| 623 | 623 | */ |
| 624 | - $earnings = apply_filters( 'give_get_earnings_by_date', $earning_totals, $donations, $args ); |
|
| 624 | + $earnings = apply_filters('give_get_earnings_by_date', $earning_totals, $donations, $args); |
|
| 625 | 625 | } |
| 626 | 626 | // Cache the results for one hour. |
| 627 | - Give_Cache::set( $key, $earnings, HOUR_IN_SECONDS ); |
|
| 627 | + Give_Cache::set($key, $earnings, HOUR_IN_SECONDS); |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | - return round( $earnings, 2 ); |
|
| 630 | + return round($earnings, 2); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | * |
| 643 | 643 | * @return int $count Sales |
| 644 | 644 | */ |
| 645 | -function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) { |
|
| 645 | +function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) { |
|
| 646 | 646 | |
| 647 | 647 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead. |
| 648 | 648 | $args = array( |
@@ -650,14 +650,14 @@ discard block |
||
| 650 | 650 | 'nopaging' => true, |
| 651 | 651 | 'year' => $year, |
| 652 | 652 | 'fields' => 'ids', |
| 653 | - 'post_status' => array( 'publish' ), |
|
| 653 | + 'post_status' => array('publish'), |
|
| 654 | 654 | 'update_post_meta_cache' => false, |
| 655 | 655 | 'update_post_term_cache' => false, |
| 656 | 656 | ); |
| 657 | 657 | |
| 658 | - $show_free = apply_filters( 'give_sales_by_date_show_free', true, $args ); |
|
| 658 | + $show_free = apply_filters('give_sales_by_date_show_free', true, $args); |
|
| 659 | 659 | |
| 660 | - if ( false === $show_free ) { |
|
| 660 | + if (false === $show_free) { |
|
| 661 | 661 | $args['meta_query'] = array( |
| 662 | 662 | array( |
| 663 | 663 | 'key' => '_give_payment_total', |
@@ -668,33 +668,33 @@ discard block |
||
| 668 | 668 | ); |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - if ( ! empty( $month_num ) ) { |
|
| 671 | + if ( ! empty($month_num)) { |
|
| 672 | 672 | $args['monthnum'] = $month_num; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if ( ! empty( $day ) ) { |
|
| 675 | + if ( ! empty($day)) { |
|
| 676 | 676 | $args['day'] = $day; |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - if ( isset( $hour ) ) { |
|
| 679 | + if (isset($hour)) { |
|
| 680 | 680 | $args['hour'] = $hour; |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - $args = apply_filters( 'give_get_sales_by_date_args', $args ); |
|
| 683 | + $args = apply_filters('give_get_sales_by_date_args', $args); |
|
| 684 | 684 | |
| 685 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
| 685 | + $key = Give_Cache::get_key('give_stats', $args); |
|
| 686 | 686 | |
| 687 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
| 687 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
| 688 | 688 | $count = false; |
| 689 | 689 | } else { |
| 690 | - $count = Give_Cache::get( $key ); |
|
| 690 | + $count = Give_Cache::get($key); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( false === $count ) { |
|
| 694 | - $donations = new WP_Query( $args ); |
|
| 693 | + if (false === $count) { |
|
| 694 | + $donations = new WP_Query($args); |
|
| 695 | 695 | $count = (int) $donations->post_count; |
| 696 | 696 | // Cache the results for one hour. |
| 697 | - Give_Cache::set( $key, $count, HOUR_IN_SECONDS ); |
|
| 697 | + Give_Cache::set($key, $count, HOUR_IN_SECONDS); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | return $count; |
@@ -709,14 +709,14 @@ discard block |
||
| 709 | 709 | * |
| 710 | 710 | * @return bool $ret True if complete, false otherwise. |
| 711 | 711 | */ |
| 712 | -function give_is_payment_complete( $payment_id ) { |
|
| 712 | +function give_is_payment_complete($payment_id) { |
|
| 713 | 713 | $ret = false; |
| 714 | 714 | $payment_status = ''; |
| 715 | 715 | |
| 716 | - if ( $payment_id > 0 && 'give_payment' === get_post_type( $payment_id ) ) { |
|
| 717 | - $payment_status = get_post_status( $payment_id ); |
|
| 716 | + if ($payment_id > 0 && 'give_payment' === get_post_type($payment_id)) { |
|
| 717 | + $payment_status = get_post_status($payment_id); |
|
| 718 | 718 | |
| 719 | - if ( 'publish' === $payment_status ) { |
|
| 719 | + if ('publish' === $payment_status) { |
|
| 720 | 720 | $ret = true; |
| 721 | 721 | } |
| 722 | 722 | } |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | * |
| 727 | 727 | * @since 1.0 |
| 728 | 728 | */ |
| 729 | - return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment_status ); |
|
| 729 | + return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment_status); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -752,13 +752,13 @@ discard block |
||
| 752 | 752 | * |
| 753 | 753 | * @return float $total Total earnings. |
| 754 | 754 | */ |
| 755 | -function give_get_total_earnings( $recalculate = false ) { |
|
| 755 | +function give_get_total_earnings($recalculate = false) { |
|
| 756 | 756 | |
| 757 | - $total = get_option( 'give_earnings_total', 0 ); |
|
| 758 | - $meta_table = __give_v20_bc_table_details( 'payment' ); |
|
| 757 | + $total = get_option('give_earnings_total', 0); |
|
| 758 | + $meta_table = __give_v20_bc_table_details('payment'); |
|
| 759 | 759 | |
| 760 | 760 | // Calculate total earnings. |
| 761 | - if ( ! $total || $recalculate ) { |
|
| 761 | + if ( ! $total || $recalculate) { |
|
| 762 | 762 | global $wpdb; |
| 763 | 763 | |
| 764 | 764 | $total = (float) 0; |
@@ -766,38 +766,38 @@ discard block |
||
| 766 | 766 | $args = apply_filters( |
| 767 | 767 | 'give_get_total_earnings_args', array( |
| 768 | 768 | 'offset' => 0, |
| 769 | - 'number' => - 1, |
|
| 770 | - 'status' => array( 'publish' ), |
|
| 769 | + 'number' => -1, |
|
| 770 | + 'status' => array('publish'), |
|
| 771 | 771 | 'fields' => 'ids', |
| 772 | 772 | ) |
| 773 | 773 | ); |
| 774 | 774 | |
| 775 | - $payments = give_get_payments( $args ); |
|
| 776 | - if ( $payments ) { |
|
| 775 | + $payments = give_get_payments($args); |
|
| 776 | + if ($payments) { |
|
| 777 | 777 | |
| 778 | 778 | /** |
| 779 | 779 | * If performing a donation, we need to skip the very last payment in the database, |
| 780 | 780 | * since it calls give_increase_total_earnings() on completion, |
| 781 | 781 | * which results in duplicated earnings for the very first donation. |
| 782 | 782 | */ |
| 783 | - if ( did_action( 'give_update_payment_status' ) ) { |
|
| 784 | - array_pop( $payments ); |
|
| 783 | + if (did_action('give_update_payment_status')) { |
|
| 784 | + array_pop($payments); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - if ( ! empty( $payments ) ) { |
|
| 788 | - $payments = implode( ',', $payments ); |
|
| 789 | - $total += $wpdb->get_var( "SELECT SUM(meta_value) FROM {$meta_table['name']} WHERE meta_key = '_give_payment_total' AND {$meta_table['column']['id']} IN({$payments})" ); |
|
| 787 | + if ( ! empty($payments)) { |
|
| 788 | + $payments = implode(',', $payments); |
|
| 789 | + $total += $wpdb->get_var("SELECT SUM(meta_value) FROM {$meta_table['name']} WHERE meta_key = '_give_payment_total' AND {$meta_table['column']['id']} IN({$payments})"); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - update_option( 'give_earnings_total', $total, false ); |
|
| 793 | + update_option('give_earnings_total', $total, false); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - if ( $total < 0 ) { |
|
| 796 | + if ($total < 0) { |
|
| 797 | 797 | $total = 0; // Don't ever show negative earnings. |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - return apply_filters( 'give_total_earnings', round( $total, give_get_price_decimals() ), $total ); |
|
| 800 | + return apply_filters('give_total_earnings', round($total, give_get_price_decimals()), $total); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -809,10 +809,10 @@ discard block |
||
| 809 | 809 | * |
| 810 | 810 | * @return float $total Total earnings. |
| 811 | 811 | */ |
| 812 | -function give_increase_total_earnings( $amount = 0 ) { |
|
| 812 | +function give_increase_total_earnings($amount = 0) { |
|
| 813 | 813 | $total = give_get_total_earnings(); |
| 814 | 814 | $total += $amount; |
| 815 | - update_option( 'give_earnings_total', $total, false ); |
|
| 815 | + update_option('give_earnings_total', $total, false); |
|
| 816 | 816 | |
| 817 | 817 | return $total; |
| 818 | 818 | } |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | * |
| 827 | 827 | * @return float $total Total earnings. |
| 828 | 828 | */ |
| 829 | -function give_decrease_total_earnings( $amount = 0 ) { |
|
| 829 | +function give_decrease_total_earnings($amount = 0) { |
|
| 830 | 830 | $total = give_get_total_earnings(); |
| 831 | 831 | $total -= $amount; |
| 832 | - if ( $total < 0 ) { |
|
| 832 | + if ($total < 0) { |
|
| 833 | 833 | $total = 0; |
| 834 | 834 | } |
| 835 | - update_option( 'give_earnings_total', $total, false ); |
|
| 835 | + update_option('give_earnings_total', $total, false); |
|
| 836 | 836 | |
| 837 | 837 | return $total; |
| 838 | 838 | } |
@@ -848,8 +848,8 @@ discard block |
||
| 848 | 848 | * |
| 849 | 849 | * @return mixed $meta Payment Meta. |
| 850 | 850 | */ |
| 851 | -function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) { |
|
| 852 | - return give_get_meta( $payment_id, $meta_key, $single ); |
|
| 851 | +function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) { |
|
| 852 | + return give_get_meta($payment_id, $meta_key, $single); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
@@ -862,8 +862,8 @@ discard block |
||
| 862 | 862 | * |
| 863 | 863 | * @return mixed Meta ID if successful, false if unsuccessful. |
| 864 | 864 | */ |
| 865 | -function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 866 | - return give_update_meta( $payment_id, $meta_key, $meta_value ); |
|
| 865 | +function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 866 | + return give_update_meta($payment_id, $meta_key, $meta_value); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /** |
@@ -875,34 +875,34 @@ discard block |
||
| 875 | 875 | * |
| 876 | 876 | * @return array $user_info User Info Meta Values. |
| 877 | 877 | */ |
| 878 | -function give_get_payment_meta_user_info( $payment_id ) { |
|
| 878 | +function give_get_payment_meta_user_info($payment_id) { |
|
| 879 | 879 | $donor_id = 0; |
| 880 | 880 | $donor_info = array( |
| 881 | - 'first_name' => give_get_meta( $payment_id, '_give_donor_billing_first_name', true ), |
|
| 882 | - 'last_name' => give_get_meta( $payment_id, '_give_donor_billing_last_name', true ), |
|
| 883 | - 'email' => give_get_meta( $payment_id, '_give_donor_billing_donor_email', true ), |
|
| 881 | + 'first_name' => give_get_meta($payment_id, '_give_donor_billing_first_name', true), |
|
| 882 | + 'last_name' => give_get_meta($payment_id, '_give_donor_billing_last_name', true), |
|
| 883 | + 'email' => give_get_meta($payment_id, '_give_donor_billing_donor_email', true), |
|
| 884 | 884 | ); |
| 885 | 885 | |
| 886 | - if ( empty( $donor_info['first_name'] ) ) { |
|
| 887 | - $donor_id = give_get_payment_donor_id( $payment_id ); |
|
| 888 | - $donor_info['first_name'] = Give()->donor_meta->get_meta( $donor_id, '_give_donor_first_name', true ); |
|
| 886 | + if (empty($donor_info['first_name'])) { |
|
| 887 | + $donor_id = give_get_payment_donor_id($payment_id); |
|
| 888 | + $donor_info['first_name'] = Give()->donor_meta->get_meta($donor_id, '_give_donor_first_name', true); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - if ( empty( $donor_info['last_name'] ) ) { |
|
| 892 | - $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id( $payment_id ); |
|
| 893 | - $donor_info['last_name'] = Give()->donor_meta->get_meta( $donor_id, '_give_donor_last_name', true ); |
|
| 891 | + if (empty($donor_info['last_name'])) { |
|
| 892 | + $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id($payment_id); |
|
| 893 | + $donor_info['last_name'] = Give()->donor_meta->get_meta($donor_id, '_give_donor_last_name', true); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | - if ( empty( $donor_info['email'] ) ) { |
|
| 897 | - $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id( $payment_id ); |
|
| 898 | - $donor_info['email'] = Give()->donors->get_column_by( 'email', 'id', $donor_id ); |
|
| 896 | + if (empty($donor_info['email'])) { |
|
| 897 | + $donor_id = $donor_id ? $donor_id : give_get_payment_donor_id($payment_id); |
|
| 898 | + $donor_info['email'] = Give()->donors->get_column_by('email', 'id', $donor_id); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - $donor_info['title'] = Give()->donor_meta->get_meta( $donor_id, '_give_donor_title_prefix', true ); |
|
| 901 | + $donor_info['title'] = Give()->donor_meta->get_meta($donor_id, '_give_donor_title_prefix', true); |
|
| 902 | 902 | |
| 903 | - $donor_info['address'] = give_get_donation_address( $payment_id ); |
|
| 904 | - $donor_info['id'] = give_get_payment_user_id( $payment_id ); |
|
| 905 | - $donor_info['donor_id'] = give_get_payment_donor_id( $payment_id ); |
|
| 903 | + $donor_info['address'] = give_get_donation_address($payment_id); |
|
| 904 | + $donor_info['id'] = give_get_payment_user_id($payment_id); |
|
| 905 | + $donor_info['donor_id'] = give_get_payment_donor_id($payment_id); |
|
| 906 | 906 | |
| 907 | 907 | return $donor_info; |
| 908 | 908 | } |
@@ -918,8 +918,8 @@ discard block |
||
| 918 | 918 | * |
| 919 | 919 | * @return int $form_id Form ID. |
| 920 | 920 | */ |
| 921 | -function give_get_payment_form_id( $payment_id ) { |
|
| 922 | - return (int) give_get_meta( $payment_id, '_give_payment_form_id', true ); |
|
| 921 | +function give_get_payment_form_id($payment_id) { |
|
| 922 | + return (int) give_get_meta($payment_id, '_give_payment_form_id', true); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -931,11 +931,11 @@ discard block |
||
| 931 | 931 | * |
| 932 | 932 | * @return string $email User email. |
| 933 | 933 | */ |
| 934 | -function give_get_payment_user_email( $payment_id ) { |
|
| 935 | - $email = give_get_meta( $payment_id, '_give_payment_donor_email', true ); |
|
| 934 | +function give_get_payment_user_email($payment_id) { |
|
| 935 | + $email = give_get_meta($payment_id, '_give_payment_donor_email', true); |
|
| 936 | 936 | |
| 937 | - if ( empty( $email ) && ( $donor_id = give_get_payment_donor_id( $payment_id ) ) ) { |
|
| 938 | - $email = Give()->donors->get_column( 'email', $donor_id ); |
|
| 937 | + if (empty($email) && ($donor_id = give_get_payment_donor_id($payment_id))) { |
|
| 938 | + $email = Give()->donors->get_column('email', $donor_id); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | return $email; |
@@ -950,11 +950,11 @@ discard block |
||
| 950 | 950 | * |
| 951 | 951 | * @return bool $is_guest_payment If the payment is associated with a user (false) or not (true) |
| 952 | 952 | */ |
| 953 | -function give_is_guest_payment( $payment_id ) { |
|
| 954 | - $payment_user_id = give_get_payment_user_id( $payment_id ); |
|
| 955 | - $is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true; |
|
| 953 | +function give_is_guest_payment($payment_id) { |
|
| 954 | + $payment_user_id = give_get_payment_user_id($payment_id); |
|
| 955 | + $is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true; |
|
| 956 | 956 | |
| 957 | - return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id ); |
|
| 957 | + return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -966,10 +966,10 @@ discard block |
||
| 966 | 966 | * |
| 967 | 967 | * @return int $user_id User ID. |
| 968 | 968 | */ |
| 969 | -function give_get_payment_user_id( $payment_id ) { |
|
| 969 | +function give_get_payment_user_id($payment_id) { |
|
| 970 | 970 | global $wpdb; |
| 971 | 971 | $paymentmeta_table = Give()->payment_meta->table_name; |
| 972 | - $donationmeta_primary_key = Give()->payment_meta->get_meta_type() . '_id'; |
|
| 972 | + $donationmeta_primary_key = Give()->payment_meta->get_meta_type().'_id'; |
|
| 973 | 973 | |
| 974 | 974 | return (int) $wpdb->get_var( |
| 975 | 975 | $wpdb->prepare( |
@@ -998,8 +998,8 @@ discard block |
||
| 998 | 998 | * |
| 999 | 999 | * @return int $payment->customer_id Donor ID. |
| 1000 | 1000 | */ |
| 1001 | -function give_get_payment_donor_id( $payment_id ) { |
|
| 1002 | - return give_get_meta( $payment_id, '_give_payment_donor_id', true ); |
|
| 1001 | +function give_get_payment_donor_id($payment_id) { |
|
| 1002 | + return give_get_meta($payment_id, '_give_payment_donor_id', true); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1011,8 +1011,8 @@ discard block |
||
| 1011 | 1011 | * |
| 1012 | 1012 | * @return string |
| 1013 | 1013 | */ |
| 1014 | -function give_get_donation_donor_email( $payment_id ) { |
|
| 1015 | - return give_get_meta( $payment_id, '_give_payment_donor_email', true ); |
|
| 1014 | +function give_get_donation_donor_email($payment_id) { |
|
| 1015 | + return give_get_meta($payment_id, '_give_payment_donor_email', true); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | /** |
@@ -1024,8 +1024,8 @@ discard block |
||
| 1024 | 1024 | * |
| 1025 | 1025 | * @return string $ip User IP. |
| 1026 | 1026 | */ |
| 1027 | -function give_get_payment_user_ip( $payment_id ) { |
|
| 1028 | - return give_get_meta( $payment_id, '_give_payment_donor_ip', true ); |
|
| 1027 | +function give_get_payment_user_ip($payment_id) { |
|
| 1028 | + return give_get_meta($payment_id, '_give_payment_donor_ip', true); |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
@@ -1037,8 +1037,8 @@ discard block |
||
| 1037 | 1037 | * |
| 1038 | 1038 | * @return string $date The date the payment was completed. |
| 1039 | 1039 | */ |
| 1040 | -function give_get_payment_completed_date( $payment_id = 0 ) { |
|
| 1041 | - return give_get_meta( $payment_id, '_give_completed_date', true ); |
|
| 1040 | +function give_get_payment_completed_date($payment_id = 0) { |
|
| 1041 | + return give_get_meta($payment_id, '_give_completed_date', true); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1050,8 +1050,8 @@ discard block |
||
| 1050 | 1050 | * |
| 1051 | 1051 | * @return string $gateway Gateway. |
| 1052 | 1052 | */ |
| 1053 | -function give_get_payment_gateway( $payment_id ) { |
|
| 1054 | - return give_get_meta( $payment_id, '_give_payment_gateway', true ); |
|
| 1053 | +function give_get_payment_gateway($payment_id) { |
|
| 1054 | + return give_get_meta($payment_id, '_give_payment_gateway', true); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1064,10 +1064,9 @@ discard block |
||
| 1064 | 1064 | * |
| 1065 | 1065 | * @return bool |
| 1066 | 1066 | */ |
| 1067 | -function give_has_payment_gateway( $donation_id, $gateway_id ) { |
|
| 1067 | +function give_has_payment_gateway($donation_id, $gateway_id) { |
|
| 1068 | 1068 | $donation_gateway = $donation_id instanceof Give_Payment ? |
| 1069 | - $donation_id->gateway : |
|
| 1070 | - give_get_payment_gateway( $donation_id ); |
|
| 1069 | + $donation_id->gateway : give_get_payment_gateway($donation_id); |
|
| 1071 | 1070 | |
| 1072 | 1071 | return $gateway_id === $donation_gateway; |
| 1073 | 1072 | } |
@@ -1081,8 +1080,8 @@ discard block |
||
| 1081 | 1080 | * |
| 1082 | 1081 | * @return string $currency The currency code. |
| 1083 | 1082 | */ |
| 1084 | -function give_get_payment_currency_code( $payment_id = 0 ) { |
|
| 1085 | - return give_get_meta( $payment_id, '_give_payment_currency', true ); |
|
| 1083 | +function give_get_payment_currency_code($payment_id = 0) { |
|
| 1084 | + return give_get_meta($payment_id, '_give_payment_currency', true); |
|
| 1086 | 1085 | } |
| 1087 | 1086 | |
| 1088 | 1087 | /** |
@@ -1094,10 +1093,10 @@ discard block |
||
| 1094 | 1093 | * |
| 1095 | 1094 | * @return string $currency The currency name. |
| 1096 | 1095 | */ |
| 1097 | -function give_get_payment_currency( $payment_id = 0 ) { |
|
| 1098 | - $currency = give_get_payment_currency_code( $payment_id ); |
|
| 1096 | +function give_get_payment_currency($payment_id = 0) { |
|
| 1097 | + $currency = give_get_payment_currency_code($payment_id); |
|
| 1099 | 1098 | |
| 1100 | - return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id ); |
|
| 1099 | + return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id); |
|
| 1101 | 1100 | } |
| 1102 | 1101 | |
| 1103 | 1102 | /** |
@@ -1109,8 +1108,8 @@ discard block |
||
| 1109 | 1108 | * |
| 1110 | 1109 | * @return string $key Donation key. |
| 1111 | 1110 | */ |
| 1112 | -function give_get_payment_key( $payment_id = 0 ) { |
|
| 1113 | - return give_get_meta( $payment_id, '_give_payment_purchase_key', true ); |
|
| 1111 | +function give_get_payment_key($payment_id = 0) { |
|
| 1112 | + return give_get_meta($payment_id, '_give_payment_purchase_key', true); |
|
| 1114 | 1113 | } |
| 1115 | 1114 | |
| 1116 | 1115 | /** |
@@ -1124,8 +1123,8 @@ discard block |
||
| 1124 | 1123 | * |
| 1125 | 1124 | * @return string $number Payment order number. |
| 1126 | 1125 | */ |
| 1127 | -function give_get_payment_number( $payment_id = 0 ) { |
|
| 1128 | - return Give()->seq_donation_number->get_serial_code( $payment_id ); |
|
| 1126 | +function give_get_payment_number($payment_id = 0) { |
|
| 1127 | + return Give()->seq_donation_number->get_serial_code($payment_id); |
|
| 1129 | 1128 | } |
| 1130 | 1129 | |
| 1131 | 1130 | |
@@ -1143,17 +1142,17 @@ discard block |
||
| 1143 | 1142 | * |
| 1144 | 1143 | * @return string $amount Fully formatted donation amount. |
| 1145 | 1144 | */ |
| 1146 | -function give_donation_amount( $donation_id, $format_args = array() ) { |
|
| 1147 | - if ( ! $donation_id ) { |
|
| 1145 | +function give_donation_amount($donation_id, $format_args = array()) { |
|
| 1146 | + if ( ! $donation_id) { |
|
| 1148 | 1147 | return ''; |
| 1149 | - } elseif ( ! is_numeric( $donation_id ) && ( $donation_id instanceof Give_Payment ) ) { |
|
| 1148 | + } elseif ( ! is_numeric($donation_id) && ($donation_id instanceof Give_Payment)) { |
|
| 1150 | 1149 | $donation_id = $donation_id->ID; |
| 1151 | 1150 | } |
| 1152 | 1151 | |
| 1153 | - $amount = $formatted_amount = give_get_payment_total( $donation_id ); |
|
| 1154 | - $currency_code = give_get_payment_currency_code( $donation_id ); |
|
| 1152 | + $amount = $formatted_amount = give_get_payment_total($donation_id); |
|
| 1153 | + $currency_code = give_get_payment_currency_code($donation_id); |
|
| 1155 | 1154 | |
| 1156 | - if ( is_bool( $format_args ) ) { |
|
| 1155 | + if (is_bool($format_args)) { |
|
| 1157 | 1156 | $format_args = array( |
| 1158 | 1157 | 'currency' => (bool) $format_args, |
| 1159 | 1158 | 'amount' => (bool) $format_args, |
@@ -1176,27 +1175,25 @@ discard block |
||
| 1176 | 1175 | ) |
| 1177 | 1176 | ); |
| 1178 | 1177 | |
| 1179 | - if ( $format_args['amount'] || $format_args['currency'] ) { |
|
| 1178 | + if ($format_args['amount'] || $format_args['currency']) { |
|
| 1180 | 1179 | |
| 1181 | - if ( $format_args['amount'] ) { |
|
| 1180 | + if ($format_args['amount']) { |
|
| 1182 | 1181 | |
| 1183 | 1182 | $formatted_amount = give_format_amount( |
| 1184 | 1183 | $amount, |
| 1185 | - ! is_array( $format_args['amount'] ) ? |
|
| 1184 | + ! is_array($format_args['amount']) ? |
|
| 1186 | 1185 | array( |
| 1187 | 1186 | 'sanitize' => false, |
| 1188 | 1187 | 'currency' => $currency_code, |
| 1189 | - ) : |
|
| 1190 | - $format_args['amount'] |
|
| 1188 | + ) : $format_args['amount'] |
|
| 1191 | 1189 | ); |
| 1192 | 1190 | } |
| 1193 | 1191 | |
| 1194 | - if ( $format_args['currency'] ) { |
|
| 1192 | + if ($format_args['currency']) { |
|
| 1195 | 1193 | $formatted_amount = give_currency_filter( |
| 1196 | 1194 | $formatted_amount, |
| 1197 | - ! is_array( $format_args['currency'] ) ? |
|
| 1198 | - array( 'currency_code' => $currency_code ) : |
|
| 1199 | - $format_args['currency'] |
|
| 1195 | + ! is_array($format_args['currency']) ? |
|
| 1196 | + array('currency_code' => $currency_code) : $format_args['currency'] |
|
| 1200 | 1197 | ); |
| 1201 | 1198 | } |
| 1202 | 1199 | } |
@@ -1211,7 +1208,7 @@ discard block |
||
| 1211 | 1208 | * @param int $donation_id Donation ID. |
| 1212 | 1209 | * @param string $type Donation amount type. |
| 1213 | 1210 | */ |
| 1214 | - return apply_filters( 'give_donation_amount', (string) $formatted_amount, $amount, $donation_id, $format_args ); |
|
| 1211 | + return apply_filters('give_donation_amount', (string) $formatted_amount, $amount, $donation_id, $format_args); |
|
| 1215 | 1212 | } |
| 1216 | 1213 | |
| 1217 | 1214 | /** |
@@ -1228,10 +1225,10 @@ discard block |
||
| 1228 | 1225 | * |
| 1229 | 1226 | * @return array Fully formatted payment subtotal. |
| 1230 | 1227 | */ |
| 1231 | -function give_payment_subtotal( $payment_id = 0 ) { |
|
| 1232 | - $subtotal = give_get_payment_subtotal( $payment_id ); |
|
| 1228 | +function give_payment_subtotal($payment_id = 0) { |
|
| 1229 | + $subtotal = give_get_payment_subtotal($payment_id); |
|
| 1233 | 1230 | |
| 1234 | - return give_currency_filter( give_format_amount( $subtotal, array( 'sanitize' => false ) ), array( 'currency_code' => give_get_payment_currency_code( $payment_id ) ) ); |
|
| 1231 | + return give_currency_filter(give_format_amount($subtotal, array('sanitize' => false)), array('currency_code' => give_get_payment_currency_code($payment_id))); |
|
| 1235 | 1232 | } |
| 1236 | 1233 | |
| 1237 | 1234 | /** |
@@ -1245,8 +1242,8 @@ discard block |
||
| 1245 | 1242 | * |
| 1246 | 1243 | * @return float $subtotal Subtotal for payment (non formatted). |
| 1247 | 1244 | */ |
| 1248 | -function give_get_payment_subtotal( $payment_id = 0 ) { |
|
| 1249 | - $payment = new Give_Payment( $payment_id ); |
|
| 1245 | +function give_get_payment_subtotal($payment_id = 0) { |
|
| 1246 | + $payment = new Give_Payment($payment_id); |
|
| 1250 | 1247 | |
| 1251 | 1248 | return $payment->subtotal; |
| 1252 | 1249 | } |
@@ -1260,12 +1257,12 @@ discard block |
||
| 1260 | 1257 | * |
| 1261 | 1258 | * @return string The donation ID. |
| 1262 | 1259 | */ |
| 1263 | -function give_get_payment_transaction_id( $payment_id = 0 ) { |
|
| 1264 | - $transaction_id = give_get_meta( $payment_id, '_give_payment_transaction_id', true ); |
|
| 1260 | +function give_get_payment_transaction_id($payment_id = 0) { |
|
| 1261 | + $transaction_id = give_get_meta($payment_id, '_give_payment_transaction_id', true); |
|
| 1265 | 1262 | |
| 1266 | - if ( empty( $transaction_id ) ) { |
|
| 1267 | - $gateway = give_get_payment_gateway( $payment_id ); |
|
| 1268 | - $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $payment_id ); |
|
| 1263 | + if (empty($transaction_id)) { |
|
| 1264 | + $gateway = give_get_payment_gateway($payment_id); |
|
| 1265 | + $transaction_id = apply_filters("give_get_payment_transaction_id-{$gateway}", $payment_id); |
|
| 1269 | 1266 | } |
| 1270 | 1267 | |
| 1271 | 1268 | return $transaction_id; |
@@ -1281,15 +1278,15 @@ discard block |
||
| 1281 | 1278 | * |
| 1282 | 1279 | * @return bool|mixed |
| 1283 | 1280 | */ |
| 1284 | -function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) { |
|
| 1281 | +function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') { |
|
| 1285 | 1282 | |
| 1286 | - if ( empty( $payment_id ) || empty( $transaction_id ) ) { |
|
| 1283 | + if (empty($payment_id) || empty($transaction_id)) { |
|
| 1287 | 1284 | return false; |
| 1288 | 1285 | } |
| 1289 | 1286 | |
| 1290 | - $transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
| 1287 | + $transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id); |
|
| 1291 | 1288 | |
| 1292 | - return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id ); |
|
| 1289 | + return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id); |
|
| 1293 | 1290 | } |
| 1294 | 1291 | |
| 1295 | 1292 | /** |
@@ -1302,10 +1299,10 @@ discard block |
||
| 1302 | 1299 | * |
| 1303 | 1300 | * @return int $purchase Donation ID. |
| 1304 | 1301 | */ |
| 1305 | -function give_get_donation_id_by_key( $key ) { |
|
| 1302 | +function give_get_donation_id_by_key($key) { |
|
| 1306 | 1303 | global $wpdb; |
| 1307 | 1304 | |
| 1308 | - $meta_table = __give_v20_bc_table_details( 'payment' ); |
|
| 1305 | + $meta_table = __give_v20_bc_table_details('payment'); |
|
| 1309 | 1306 | |
| 1310 | 1307 | $purchase = $wpdb->get_var( |
| 1311 | 1308 | $wpdb->prepare( |
@@ -1321,7 +1318,7 @@ discard block |
||
| 1321 | 1318 | ) |
| 1322 | 1319 | ); |
| 1323 | 1320 | |
| 1324 | - if ( $purchase != null ) { |
|
| 1321 | + if ($purchase != null) { |
|
| 1325 | 1322 | return $purchase; |
| 1326 | 1323 | } |
| 1327 | 1324 | |
@@ -1339,13 +1336,13 @@ discard block |
||
| 1339 | 1336 | * |
| 1340 | 1337 | * @return int $purchase Donation ID. |
| 1341 | 1338 | */ |
| 1342 | -function give_get_purchase_id_by_transaction_id( $key ) { |
|
| 1339 | +function give_get_purchase_id_by_transaction_id($key) { |
|
| 1343 | 1340 | global $wpdb; |
| 1344 | - $meta_table = __give_v20_bc_table_details( 'payment' ); |
|
| 1341 | + $meta_table = __give_v20_bc_table_details('payment'); |
|
| 1345 | 1342 | |
| 1346 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT {$meta_table['column']['id']} FROM {$meta_table['name']} WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1343 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT {$meta_table['column']['id']} FROM {$meta_table['name']} WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 1347 | 1344 | |
| 1348 | - if ( $purchase != null ) { |
|
| 1345 | + if ($purchase != null) { |
|
| 1349 | 1346 | return $purchase; |
| 1350 | 1347 | } |
| 1351 | 1348 | |
@@ -1362,8 +1359,8 @@ discard block |
||
| 1362 | 1359 | * |
| 1363 | 1360 | * @return array $notes Donation Notes |
| 1364 | 1361 | */ |
| 1365 | -function give_get_payment_notes( $payment_id = 0, $search = '' ) { |
|
| 1366 | - return Give_Comment::get( $payment_id,'payment', array(), $search ); |
|
| 1362 | +function give_get_payment_notes($payment_id = 0, $search = '') { |
|
| 1363 | + return Give_Comment::get($payment_id, 'payment', array(), $search); |
|
| 1367 | 1364 | } |
| 1368 | 1365 | |
| 1369 | 1366 | |
@@ -1377,8 +1374,8 @@ discard block |
||
| 1377 | 1374 | * |
| 1378 | 1375 | * @return int The new note ID |
| 1379 | 1376 | */ |
| 1380 | -function give_insert_payment_note( $payment_id = 0, $note = '' ) { |
|
| 1381 | - return Give_Comment::add( $payment_id, $note, 'payment' ); |
|
| 1377 | +function give_insert_payment_note($payment_id = 0, $note = '') { |
|
| 1378 | + return Give_Comment::add($payment_id, $note, 'payment'); |
|
| 1382 | 1379 | } |
| 1383 | 1380 | |
| 1384 | 1381 | /** |
@@ -1391,8 +1388,8 @@ discard block |
||
| 1391 | 1388 | * |
| 1392 | 1389 | * @return bool True on success, false otherwise. |
| 1393 | 1390 | */ |
| 1394 | -function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) { |
|
| 1395 | - return Give_Comment::delete( $comment_id, $payment_id, 'payment' ); |
|
| 1391 | +function give_delete_payment_note($comment_id = 0, $payment_id = 0) { |
|
| 1392 | + return Give_Comment::delete($comment_id, $payment_id, 'payment'); |
|
| 1396 | 1393 | } |
| 1397 | 1394 | |
| 1398 | 1395 | /** |
@@ -1405,20 +1402,20 @@ discard block |
||
| 1405 | 1402 | * |
| 1406 | 1403 | * @return string |
| 1407 | 1404 | */ |
| 1408 | -function give_get_payment_note_html( $note, $payment_id = 0 ) { |
|
| 1405 | +function give_get_payment_note_html($note, $payment_id = 0) { |
|
| 1409 | 1406 | |
| 1410 | - if ( is_numeric( $note ) ) { |
|
| 1411 | - $note = get_comment( $note ); |
|
| 1407 | + if (is_numeric($note)) { |
|
| 1408 | + $note = get_comment($note); |
|
| 1412 | 1409 | } |
| 1413 | 1410 | |
| 1414 | - if ( ! empty( $note->user_id ) ) { |
|
| 1415 | - $user = get_userdata( $note->user_id ); |
|
| 1411 | + if ( ! empty($note->user_id)) { |
|
| 1412 | + $user = get_userdata($note->user_id); |
|
| 1416 | 1413 | $user = $user->display_name; |
| 1417 | 1414 | } else { |
| 1418 | - $user = __( 'System', 'give' ); |
|
| 1415 | + $user = __('System', 'give'); |
|
| 1419 | 1416 | } |
| 1420 | 1417 | |
| 1421 | - $date_format = give_date_format() . ', ' . get_option( 'time_format' ); |
|
| 1418 | + $date_format = give_date_format().', '.get_option('time_format'); |
|
| 1422 | 1419 | |
| 1423 | 1420 | $delete_note_url = wp_nonce_url( |
| 1424 | 1421 | add_query_arg( |
@@ -1427,14 +1424,14 @@ discard block |
||
| 1427 | 1424 | 'note_id' => $note->comment_ID, |
| 1428 | 1425 | 'payment_id' => $payment_id, |
| 1429 | 1426 | ) |
| 1430 | - ), 'give_delete_payment_note_' . $note->comment_ID |
|
| 1427 | + ), 'give_delete_payment_note_'.$note->comment_ID |
|
| 1431 | 1428 | ); |
| 1432 | 1429 | |
| 1433 | - $note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">'; |
|
| 1430 | + $note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">'; |
|
| 1434 | 1431 | $note_html .= '<p>'; |
| 1435 | - $note_html .= '<strong>' . $user . '</strong> – <span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>'; |
|
| 1432 | + $note_html .= '<strong>'.$user.'</strong> – <span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>'; |
|
| 1436 | 1433 | $note_html .= $note->comment_content; |
| 1437 | - $note_html .= ' – <a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" aria-label="' . __( 'Delete this donation note.', 'give' ) . '">' . __( 'Delete', 'give' ) . '</a>'; |
|
| 1434 | + $note_html .= ' – <a href="'.esc_url($delete_note_url).'" class="give-delete-payment-note" data-note-id="'.absint($note->comment_ID).'" data-payment-id="'.absint($payment_id).'" aria-label="'.__('Delete this donation note.', 'give').'">'.__('Delete', 'give').'</a>'; |
|
| 1438 | 1435 | $note_html .= '</p>'; |
| 1439 | 1436 | $note_html .= '</div>'; |
| 1440 | 1437 | |
@@ -1453,9 +1450,9 @@ discard block |
||
| 1453 | 1450 | * |
| 1454 | 1451 | * @return string $where Modified where clause. |
| 1455 | 1452 | */ |
| 1456 | -function give_filter_where_older_than_week( $where = '' ) { |
|
| 1453 | +function give_filter_where_older_than_week($where = '') { |
|
| 1457 | 1454 | // Payments older than one week. |
| 1458 | - $start = date( 'Y-m-d', strtotime( '-7 days' ) ); |
|
| 1455 | + $start = date('Y-m-d', strtotime('-7 days')); |
|
| 1459 | 1456 | $where .= " AND post_date <= '{$start}'"; |
| 1460 | 1457 | |
| 1461 | 1458 | return $where; |
@@ -1476,13 +1473,13 @@ discard block |
||
| 1476 | 1473 | * |
| 1477 | 1474 | * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title. |
| 1478 | 1475 | */ |
| 1479 | -function give_get_donation_form_title( $donation_id, $args = array() ) { |
|
| 1476 | +function give_get_donation_form_title($donation_id, $args = array()) { |
|
| 1480 | 1477 | // Backward compatibility. |
| 1481 | - if ( ! is_numeric( $donation_id ) && $donation_id instanceof Give_Payment ) { |
|
| 1478 | + if ( ! is_numeric($donation_id) && $donation_id instanceof Give_Payment) { |
|
| 1482 | 1479 | $donation_id = $donation_id->ID; |
| 1483 | 1480 | } |
| 1484 | 1481 | |
| 1485 | - if ( ! $donation_id ) { |
|
| 1482 | + if ( ! $donation_id) { |
|
| 1486 | 1483 | return ''; |
| 1487 | 1484 | } |
| 1488 | 1485 | |
@@ -1491,11 +1488,11 @@ discard block |
||
| 1491 | 1488 | 'separator' => '', |
| 1492 | 1489 | ); |
| 1493 | 1490 | |
| 1494 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1491 | + $args = wp_parse_args($args, $defaults); |
|
| 1495 | 1492 | |
| 1496 | - $form_id = give_get_payment_form_id( $donation_id ); |
|
| 1497 | - $price_id = give_get_meta( $donation_id, '_give_payment_price_id', true ); |
|
| 1498 | - $form_title = give_get_meta( $donation_id, '_give_payment_form_title', true ); |
|
| 1493 | + $form_id = give_get_payment_form_id($donation_id); |
|
| 1494 | + $price_id = give_get_meta($donation_id, '_give_payment_price_id', true); |
|
| 1495 | + $form_title = give_get_meta($donation_id, '_give_payment_form_title', true); |
|
| 1499 | 1496 | $only_level = $args['only_level']; |
| 1500 | 1497 | $separator = $args['separator']; |
| 1501 | 1498 | $level_label = ''; |
@@ -1511,38 +1508,38 @@ discard block |
||
| 1511 | 1508 | ), false |
| 1512 | 1509 | ); |
| 1513 | 1510 | |
| 1514 | - $form_title_html = Give_Cache::get_db_query( $cache_key ); |
|
| 1511 | + $form_title_html = Give_Cache::get_db_query($cache_key); |
|
| 1515 | 1512 | |
| 1516 | - if ( is_null( $form_title_html ) ) { |
|
| 1517 | - if ( true === $only_level ) { |
|
| 1513 | + if (is_null($form_title_html)) { |
|
| 1514 | + if (true === $only_level) { |
|
| 1518 | 1515 | $form_title = ''; |
| 1519 | 1516 | } |
| 1520 | 1517 | |
| 1521 | 1518 | $form_title_html = $form_title; |
| 1522 | 1519 | |
| 1523 | - if ( 'custom' === $price_id ) { |
|
| 1520 | + if ('custom' === $price_id) { |
|
| 1524 | 1521 | |
| 1525 | - $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
|
| 1526 | - $level_label = ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ); |
|
| 1522 | + $custom_amount_text = give_get_meta($form_id, '_give_custom_amount_text', true); |
|
| 1523 | + $level_label = ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'); |
|
| 1527 | 1524 | |
| 1528 | 1525 | // Show custom amount level only in backend otherwise hide it. |
| 1529 | - if ( 'set' === give_get_meta( $form_id, '_give_price_option', true ) && ! is_admin() ) { |
|
| 1526 | + if ('set' === give_get_meta($form_id, '_give_price_option', true) && ! is_admin()) { |
|
| 1530 | 1527 | $level_label = ''; |
| 1531 | 1528 | } |
| 1532 | - } elseif ( give_has_variable_prices( $form_id ) ) { |
|
| 1533 | - $level_label = give_get_price_option_name( $form_id, $price_id, $donation_id, false ); |
|
| 1529 | + } elseif (give_has_variable_prices($form_id)) { |
|
| 1530 | + $level_label = give_get_price_option_name($form_id, $price_id, $donation_id, false); |
|
| 1534 | 1531 | } |
| 1535 | 1532 | |
| 1536 | 1533 | // Only add separator if there is a form title. |
| 1537 | 1534 | if ( |
| 1538 | - ! empty( $form_title_html ) && |
|
| 1539 | - ! empty( $level_label ) |
|
| 1535 | + ! empty($form_title_html) && |
|
| 1536 | + ! empty($level_label) |
|
| 1540 | 1537 | ) { |
| 1541 | 1538 | $form_title_html .= " {$separator} "; |
| 1542 | 1539 | } |
| 1543 | 1540 | |
| 1544 | 1541 | $form_title_html .= "<span class=\"donation-level-text-wrap\">{$level_label}</span>"; |
| 1545 | - Give_Cache::set_db_query( $cache_key, $form_title_html ); |
|
| 1542 | + Give_Cache::set_db_query($cache_key, $form_title_html); |
|
| 1546 | 1543 | } |
| 1547 | 1544 | |
| 1548 | 1545 | /** |
@@ -1551,7 +1548,7 @@ discard block |
||
| 1551 | 1548 | * @since 1.0 |
| 1552 | 1549 | * @todo: remove third param after 2.1.0 |
| 1553 | 1550 | */ |
| 1554 | - return apply_filters( 'give_get_donation_form_title', $form_title_html, $donation_id, '' ); |
|
| 1551 | + return apply_filters('give_get_donation_form_title', $form_title_html, $donation_id, ''); |
|
| 1555 | 1552 | } |
| 1556 | 1553 | |
| 1557 | 1554 | /** |
@@ -1564,19 +1561,19 @@ discard block |
||
| 1564 | 1561 | * |
| 1565 | 1562 | * @return string $price_id |
| 1566 | 1563 | */ |
| 1567 | -function give_get_price_id( $form_id, $price ) { |
|
| 1564 | +function give_get_price_id($form_id, $price) { |
|
| 1568 | 1565 | $price_id = null; |
| 1569 | 1566 | |
| 1570 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1567 | + if (give_has_variable_prices($form_id)) { |
|
| 1571 | 1568 | |
| 1572 | - $levels = give_get_meta( $form_id, '_give_donation_levels', true ); |
|
| 1569 | + $levels = give_get_meta($form_id, '_give_donation_levels', true); |
|
| 1573 | 1570 | |
| 1574 | - foreach ( $levels as $level ) { |
|
| 1571 | + foreach ($levels as $level) { |
|
| 1575 | 1572 | |
| 1576 | - $level_amount = give_maybe_sanitize_amount( $level['_give_amount'] ); |
|
| 1573 | + $level_amount = give_maybe_sanitize_amount($level['_give_amount']); |
|
| 1577 | 1574 | |
| 1578 | 1575 | // Check that this indeed the recurring price. |
| 1579 | - if ( $level_amount == $price ) { |
|
| 1576 | + if ($level_amount == $price) { |
|
| 1580 | 1577 | |
| 1581 | 1578 | $price_id = $level['_give_id']['level_id']; |
| 1582 | 1579 | break; |
@@ -1584,13 +1581,13 @@ discard block |
||
| 1584 | 1581 | } |
| 1585 | 1582 | } |
| 1586 | 1583 | |
| 1587 | - if ( is_null( $price_id ) && give_is_custom_price_mode( $form_id ) ) { |
|
| 1584 | + if (is_null($price_id) && give_is_custom_price_mode($form_id)) { |
|
| 1588 | 1585 | $price_id = 'custom'; |
| 1589 | 1586 | } |
| 1590 | 1587 | } |
| 1591 | 1588 | |
| 1592 | 1589 | // Price ID must be numeric or string. |
| 1593 | - $price_id = ! is_numeric( $price_id ) && ! is_string( $price_id ) ? 0 : $price_id; |
|
| 1590 | + $price_id = ! is_numeric($price_id) && ! is_string($price_id) ? 0 : $price_id; |
|
| 1594 | 1591 | |
| 1595 | 1592 | /** |
| 1596 | 1593 | * Filter the price id |
@@ -1600,7 +1597,7 @@ discard block |
||
| 1600 | 1597 | * @param string $price_id |
| 1601 | 1598 | * @param int $form_id |
| 1602 | 1599 | */ |
| 1603 | - return apply_filters( 'give_get_price_id', $price_id, $form_id ); |
|
| 1600 | + return apply_filters('give_get_price_id', $price_id, $form_id); |
|
| 1604 | 1601 | } |
| 1605 | 1602 | |
| 1606 | 1603 | /** |
@@ -1616,10 +1613,10 @@ discard block |
||
| 1616 | 1613 | * |
| 1617 | 1614 | * @return string |
| 1618 | 1615 | */ |
| 1619 | -function give_get_form_dropdown( $args = array(), $echo = false ) { |
|
| 1620 | - $form_dropdown_html = Give()->html->forms_dropdown( $args ); |
|
| 1616 | +function give_get_form_dropdown($args = array(), $echo = false) { |
|
| 1617 | + $form_dropdown_html = Give()->html->forms_dropdown($args); |
|
| 1621 | 1618 | |
| 1622 | - if ( ! $echo ) { |
|
| 1619 | + if ( ! $echo) { |
|
| 1623 | 1620 | return $form_dropdown_html; |
| 1624 | 1621 | } |
| 1625 | 1622 | |
@@ -1636,17 +1633,17 @@ discard block |
||
| 1636 | 1633 | * |
| 1637 | 1634 | * @return string|bool |
| 1638 | 1635 | */ |
| 1639 | -function give_get_form_variable_price_dropdown( $args = array(), $echo = false ) { |
|
| 1636 | +function give_get_form_variable_price_dropdown($args = array(), $echo = false) { |
|
| 1640 | 1637 | |
| 1641 | 1638 | // Check for give form id. |
| 1642 | - if ( empty( $args['id'] ) ) { |
|
| 1639 | + if (empty($args['id'])) { |
|
| 1643 | 1640 | return false; |
| 1644 | 1641 | } |
| 1645 | 1642 | |
| 1646 | - $form = new Give_Donate_Form( $args['id'] ); |
|
| 1643 | + $form = new Give_Donate_Form($args['id']); |
|
| 1647 | 1644 | |
| 1648 | 1645 | // Check if form has variable prices or not. |
| 1649 | - if ( ! $form->ID || ! $form->has_variable_prices() ) { |
|
| 1646 | + if ( ! $form->ID || ! $form->has_variable_prices()) { |
|
| 1650 | 1647 | return false; |
| 1651 | 1648 | } |
| 1652 | 1649 | |
@@ -1654,13 +1651,13 @@ discard block |
||
| 1654 | 1651 | $variable_price_options = array(); |
| 1655 | 1652 | |
| 1656 | 1653 | // Check if multi donation form support custom donation or not. |
| 1657 | - if ( $form->is_custom_price_mode() ) { |
|
| 1658 | - $variable_price_options['custom'] = _x( 'Custom', 'custom donation dropdown item', 'give' ); |
|
| 1654 | + if ($form->is_custom_price_mode()) { |
|
| 1655 | + $variable_price_options['custom'] = _x('Custom', 'custom donation dropdown item', 'give'); |
|
| 1659 | 1656 | } |
| 1660 | 1657 | |
| 1661 | 1658 | // Get variable price and ID from variable price array. |
| 1662 | - foreach ( $variable_prices as $variable_price ) { |
|
| 1663 | - $variable_price_options[ $variable_price['_give_id']['level_id'] ] = ! empty( $variable_price['_give_text'] ) ? $variable_price['_give_text'] : give_currency_filter( give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) ) ); |
|
| 1659 | + foreach ($variable_prices as $variable_price) { |
|
| 1660 | + $variable_price_options[$variable_price['_give_id']['level_id']] = ! empty($variable_price['_give_text']) ? $variable_price['_give_text'] : give_currency_filter(give_format_amount($variable_price['_give_amount'], array('sanitize' => false))); |
|
| 1664 | 1661 | } |
| 1665 | 1662 | |
| 1666 | 1663 | // Update options. |
@@ -1671,9 +1668,9 @@ discard block |
||
| 1671 | 1668 | ); |
| 1672 | 1669 | |
| 1673 | 1670 | // Generate select html. |
| 1674 | - $form_dropdown_html = Give()->html->select( $args ); |
|
| 1671 | + $form_dropdown_html = Give()->html->select($args); |
|
| 1675 | 1672 | |
| 1676 | - if ( ! $echo ) { |
|
| 1673 | + if ( ! $echo) { |
|
| 1677 | 1674 | return $form_dropdown_html; |
| 1678 | 1675 | } |
| 1679 | 1676 | |
@@ -1692,14 +1689,14 @@ discard block |
||
| 1692 | 1689 | * |
| 1693 | 1690 | * @return string |
| 1694 | 1691 | */ |
| 1695 | -function give_get_payment_meta_price_id( $payment_meta ) { |
|
| 1692 | +function give_get_payment_meta_price_id($payment_meta) { |
|
| 1696 | 1693 | |
| 1697 | - if ( isset( $payment_meta['give_price_id'] ) ) { |
|
| 1694 | + if (isset($payment_meta['give_price_id'])) { |
|
| 1698 | 1695 | $price_id = $payment_meta['give_price_id']; |
| 1699 | - } elseif ( isset( $payment_meta['price_id'] ) ) { |
|
| 1696 | + } elseif (isset($payment_meta['price_id'])) { |
|
| 1700 | 1697 | $price_id = $payment_meta['price_id']; |
| 1701 | 1698 | } else { |
| 1702 | - $price_id = give_get_price_id( $payment_meta['give_form_id'], $payment_meta['price'] ); |
|
| 1699 | + $price_id = give_get_price_id($payment_meta['give_form_id'], $payment_meta['price']); |
|
| 1703 | 1700 | } |
| 1704 | 1701 | |
| 1705 | 1702 | /** |
@@ -1710,7 +1707,7 @@ discard block |
||
| 1710 | 1707 | * @param string $price_id |
| 1711 | 1708 | * @param array $payment_meta |
| 1712 | 1709 | */ |
| 1713 | - return apply_filters( 'give_get_payment_meta_price_id', $price_id, $payment_meta ); |
|
| 1710 | + return apply_filters('give_get_payment_meta_price_id', $price_id, $payment_meta); |
|
| 1714 | 1711 | |
| 1715 | 1712 | } |
| 1716 | 1713 | |
@@ -1724,10 +1721,10 @@ discard block |
||
| 1724 | 1721 | * |
| 1725 | 1722 | * @return float |
| 1726 | 1723 | */ |
| 1727 | -function give_get_payment_total( $payment_id = 0 ) { |
|
| 1724 | +function give_get_payment_total($payment_id = 0) { |
|
| 1728 | 1725 | return round( |
| 1729 | - floatval( give_get_meta( $payment_id, '_give_payment_total', true ) ), |
|
| 1730 | - give_get_price_decimals( $payment_id ) |
|
| 1726 | + floatval(give_get_meta($payment_id, '_give_payment_total', true)), |
|
| 1727 | + give_get_price_decimals($payment_id) |
|
| 1731 | 1728 | ); |
| 1732 | 1729 | } |
| 1733 | 1730 | |
@@ -1740,13 +1737,13 @@ discard block |
||
| 1740 | 1737 | * |
| 1741 | 1738 | * @return array |
| 1742 | 1739 | */ |
| 1743 | -function give_get_donation_address( $donation_id ) { |
|
| 1744 | - $address['line1'] = give_get_meta( $donation_id, '_give_donor_billing_address1', true, '' ); |
|
| 1745 | - $address['line2'] = give_get_meta( $donation_id, '_give_donor_billing_address2', true, '' ); |
|
| 1746 | - $address['city'] = give_get_meta( $donation_id, '_give_donor_billing_city', true, '' ); |
|
| 1747 | - $address['state'] = give_get_meta( $donation_id, '_give_donor_billing_state', true, '' ); |
|
| 1748 | - $address['zip'] = give_get_meta( $donation_id, '_give_donor_billing_zip', true, '' ); |
|
| 1749 | - $address['country'] = give_get_meta( $donation_id, '_give_donor_billing_country', true, '' ); |
|
| 1740 | +function give_get_donation_address($donation_id) { |
|
| 1741 | + $address['line1'] = give_get_meta($donation_id, '_give_donor_billing_address1', true, ''); |
|
| 1742 | + $address['line2'] = give_get_meta($donation_id, '_give_donor_billing_address2', true, ''); |
|
| 1743 | + $address['city'] = give_get_meta($donation_id, '_give_donor_billing_city', true, ''); |
|
| 1744 | + $address['state'] = give_get_meta($donation_id, '_give_donor_billing_state', true, ''); |
|
| 1745 | + $address['zip'] = give_get_meta($donation_id, '_give_donor_billing_zip', true, ''); |
|
| 1746 | + $address['country'] = give_get_meta($donation_id, '_give_donor_billing_country', true, ''); |
|
| 1750 | 1747 | |
| 1751 | 1748 | return $address; |
| 1752 | 1749 | } |
@@ -1761,7 +1758,7 @@ discard block |
||
| 1761 | 1758 | * |
| 1762 | 1759 | * @return bool |
| 1763 | 1760 | */ |
| 1764 | -function give_is_donation_completed( $donation_id ) { |
|
| 1761 | +function give_is_donation_completed($donation_id) { |
|
| 1765 | 1762 | global $wpdb; |
| 1766 | 1763 | |
| 1767 | 1764 | /** |
@@ -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 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return static |
| 54 | 54 | */ |
| 55 | 55 | public static function get_instance() { |
| 56 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give_Cache ) ) { |
|
| 56 | + if ( ! isset(self::$instance) && ! (self::$instance instanceof Give_Cache)) { |
|
| 57 | 57 | self::$instance = new Give_Cache(); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -68,20 +68,20 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function setup() { |
| 70 | 70 | // Currently enable cache only for backend. |
| 71 | - self::$instance->is_cache = ( defined( 'GIVE_CACHE' ) ? GIVE_CACHE : give_is_setting_enabled( give_get_option( 'cache', 'enabled' ) ) ) && is_admin(); |
|
| 71 | + self::$instance->is_cache = (defined('GIVE_CACHE') ? GIVE_CACHE : give_is_setting_enabled(give_get_option('cache', 'enabled'))) && is_admin(); |
|
| 72 | 72 | |
| 73 | 73 | // weekly delete all expired cache. |
| 74 | - Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) ); |
|
| 74 | + Give_Cron::add_weekly_event(array($this, 'delete_all_expired')); |
|
| 75 | 75 | |
| 76 | - add_action( 'save_post_give_forms', array( $this, 'delete_form_related_cache' ) ); |
|
| 77 | - add_action( 'save_post_give_payment', array( $this, 'delete_payment_related_cache' ) ); |
|
| 78 | - add_action( 'give_deleted_give-donors_cache', array( $this, 'delete_donor_related_cache' ), 10, 3 ); |
|
| 79 | - add_action( 'give_deleted_give-donations_cache', array( $this, 'delete_donations_related_cache' ), 10, 3 ); |
|
| 76 | + add_action('save_post_give_forms', array($this, 'delete_form_related_cache')); |
|
| 77 | + add_action('save_post_give_payment', array($this, 'delete_payment_related_cache')); |
|
| 78 | + add_action('give_deleted_give-donors_cache', array($this, 'delete_donor_related_cache'), 10, 3); |
|
| 79 | + add_action('give_deleted_give-donations_cache', array($this, 'delete_donations_related_cache'), 10, 3); |
|
| 80 | 80 | |
| 81 | - add_action( 'give_save_settings_give_settings', array( __CLASS__, 'flush_cache' ) ); |
|
| 81 | + add_action('give_save_settings_give_settings', array(__CLASS__, 'flush_cache')); |
|
| 82 | 82 | |
| 83 | - add_action( 'wp', array( __CLASS__, 'prevent_caching' ) ); |
|
| 84 | - add_action( 'admin_notices', array( $this, '__notices' ) ); |
|
| 83 | + add_action('wp', array(__CLASS__, 'prevent_caching')); |
|
| 84 | + add_action('admin_notices', array($this, '__notices')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -92,19 +92,19 @@ discard block |
||
| 92 | 92 | * @credit WooCommerce |
| 93 | 93 | */ |
| 94 | 94 | public static function prevent_caching() { |
| 95 | - if ( ! is_blog_installed() ) { |
|
| 95 | + if ( ! is_blog_installed()) { |
|
| 96 | 96 | return; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $page_ids = array_filter( array( |
|
| 100 | - give_get_option( 'success_page' ), |
|
| 101 | - give_get_option( 'failure_page' ), |
|
| 102 | - give_get_option( 'history_page' ), |
|
| 103 | - ) ); |
|
| 99 | + $page_ids = array_filter(array( |
|
| 100 | + give_get_option('success_page'), |
|
| 101 | + give_get_option('failure_page'), |
|
| 102 | + give_get_option('history_page'), |
|
| 103 | + )); |
|
| 104 | 104 | |
| 105 | 105 | if ( |
| 106 | - is_page( $page_ids ) |
|
| 107 | - || is_singular( 'give_forms' ) |
|
| 106 | + is_page($page_ids) |
|
| 107 | + || is_singular('give_forms') |
|
| 108 | 108 | ) { |
| 109 | 109 | self::set_nocache_constants(); |
| 110 | 110 | nocache_headers(); |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return mixed |
| 124 | 124 | */ |
| 125 | - public static function set_nocache_constants( $return = true ) { |
|
| 126 | - give_maybe_define_constant( 'DONOTCACHEPAGE', true ); |
|
| 127 | - give_maybe_define_constant( 'DONOTCACHEOBJECT', true ); |
|
| 128 | - give_maybe_define_constant( 'DONOTCACHEDB', true ); |
|
| 125 | + public static function set_nocache_constants($return = true) { |
|
| 126 | + give_maybe_define_constant('DONOTCACHEPAGE', true); |
|
| 127 | + give_maybe_define_constant('DONOTCACHEOBJECT', true); |
|
| 128 | + give_maybe_define_constant('DONOTCACHEDB', true); |
|
| 129 | 129 | |
| 130 | 130 | return $return; |
| 131 | 131 | } |
@@ -138,18 +138,18 @@ discard block |
||
| 138 | 138 | * @credit WooCommerce |
| 139 | 139 | */ |
| 140 | 140 | public function __notices() { |
| 141 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
| 141 | + if ( ! function_exists('w3tc_pgcache_flush') || ! function_exists('w3_instance')) { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $config = w3_instance( 'W3_Config' ); |
|
| 146 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
| 147 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
| 145 | + $config = w3_instance('W3_Config'); |
|
| 146 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
| 147 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
| 148 | 148 | |
| 149 | - if ( $enabled && ! in_array( 'give', $settings, true ) ) { |
|
| 149 | + if ($enabled && ! in_array('give', $settings, true)) { |
|
| 150 | 150 | ?> |
| 151 | 151 | <div class="error"> |
| 152 | - <p><?php echo wp_kses_post( sprintf( __( 'In order for <strong>database caching</strong> to work with Give you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'give' ), '<code>give</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ) ); ?></p> |
|
| 152 | + <p><?php echo wp_kses_post(sprintf(__('In order for <strong>database caching</strong> to work with Give you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'give'), '<code>give</code>', esc_url(admin_url('admin.php?page=w3tc_dbcache')))); ?></p> |
|
| 153 | 153 | </div> |
| 154 | 154 | <?php |
| 155 | 155 | } |
@@ -166,18 +166,18 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | - public static function get_key( $action, $query_args = null, $is_prefix = true ) { |
|
| 169 | + public static function get_key($action, $query_args = null, $is_prefix = true) { |
|
| 170 | 170 | // Bailout. |
| 171 | - if ( empty( $action ) ) { |
|
| 172 | - return new WP_Error( 'give_invalid_cache_key_action', __( 'Do not pass empty action to generate cache key.', 'give' ) ); |
|
| 171 | + if (empty($action)) { |
|
| 172 | + return new WP_Error('give_invalid_cache_key_action', __('Do not pass empty action to generate cache key.', 'give')); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // Set cache key. |
| 176 | 176 | $cache_key = $is_prefix ? "give_cache_{$action}" : $action; |
| 177 | 177 | |
| 178 | 178 | // Bailout. |
| 179 | - if ( ! empty( $query_args ) ) { |
|
| 180 | - $cache_key = "{$cache_key}_" . substr( md5( serialize( $query_args ) ), 0, 15 ); |
|
| 179 | + if ( ! empty($query_args)) { |
|
| 180 | + $cache_key = "{$cache_key}_".substr(md5(serialize($query_args)), 0, 15); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @since 2.0 |
| 187 | 187 | */ |
| 188 | - return apply_filters( 'give_get_cache_key', $cache_key, $action, $query_args ); |
|
| 188 | + return apply_filters('give_get_cache_key', $cache_key, $action, $query_args); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -199,28 +199,28 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return mixed |
| 201 | 201 | */ |
| 202 | - public static function get( $cache_key, $custom_key = false, $query_args = array() ) { |
|
| 203 | - if ( ! self::is_valid_cache_key( $cache_key ) ) { |
|
| 204 | - if( empty( $cache_key ) ) { |
|
| 205 | - return new WP_Error( 'give_empty_cache_key', __( 'Do not pass invalid empty cache key', 'give' ) ); |
|
| 206 | - }elseif ( ! $custom_key ) { |
|
| 207 | - return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) ); |
|
| 202 | + public static function get($cache_key, $custom_key = false, $query_args = array()) { |
|
| 203 | + if ( ! self::is_valid_cache_key($cache_key)) { |
|
| 204 | + if (empty($cache_key)) { |
|
| 205 | + return new WP_Error('give_empty_cache_key', __('Do not pass invalid empty cache key', 'give')); |
|
| 206 | + }elseif ( ! $custom_key) { |
|
| 207 | + return new WP_Error('give_invalid_cache_key', __('Cache key format should be give_cache_*', 'give')); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - $cache_key = self::get_key( $cache_key, $query_args ); |
|
| 210 | + $cache_key = self::get_key($cache_key, $query_args); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $option = get_option( $cache_key ); |
|
| 213 | + $option = get_option($cache_key); |
|
| 214 | 214 | |
| 215 | 215 | // Backward compatibility (<1.8.7). |
| 216 | - if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) { |
|
| 216 | + if ( ! is_array($option) || empty($option) || ! array_key_exists('expiration', $option)) { |
|
| 217 | 217 | return $option; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // Get current time. |
| 221 | - $current_time = current_time( 'timestamp', 1 ); |
|
| 221 | + $current_time = current_time('timestamp', 1); |
|
| 222 | 222 | |
| 223 | - if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) { |
|
| 223 | + if (empty($option['expiration']) || ($current_time < $option['expiration'])) { |
|
| 224 | 224 | $option = $option['data']; |
| 225 | 225 | } else { |
| 226 | 226 | $option = false; |
@@ -242,23 +242,23 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @return mixed |
| 244 | 244 | */ |
| 245 | - public static function set( $cache_key, $data, $expiration = null, $custom_key = false, $query_args = array() ) { |
|
| 246 | - if ( ! self::is_valid_cache_key( $cache_key ) ) { |
|
| 247 | - if ( ! $custom_key ) { |
|
| 248 | - return new WP_Error( 'give_invalid_cache_key', __( 'Cache key format should be give_cache_*', 'give' ) ); |
|
| 245 | + public static function set($cache_key, $data, $expiration = null, $custom_key = false, $query_args = array()) { |
|
| 246 | + if ( ! self::is_valid_cache_key($cache_key)) { |
|
| 247 | + if ( ! $custom_key) { |
|
| 248 | + return new WP_Error('give_invalid_cache_key', __('Cache key format should be give_cache_*', 'give')); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $cache_key = self::get_key( $cache_key, $query_args ); |
|
| 251 | + $cache_key = self::get_key($cache_key, $query_args); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | $option_value = array( |
| 255 | 255 | 'data' => $data, |
| 256 | - 'expiration' => ! is_null( $expiration ) |
|
| 257 | - ? ( $expiration + current_time( 'timestamp', 1 ) ) |
|
| 256 | + 'expiration' => ! is_null($expiration) |
|
| 257 | + ? ($expiration + current_time('timestamp', 1)) |
|
| 258 | 258 | : null, |
| 259 | 259 | ); |
| 260 | 260 | |
| 261 | - $result = update_option( $cache_key, $option_value, false ); |
|
| 261 | + $result = update_option($cache_key, $option_value, false); |
|
| 262 | 262 | |
| 263 | 263 | return $result; |
| 264 | 264 | } |
@@ -274,27 +274,27 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return bool|WP_Error |
| 276 | 276 | */ |
| 277 | - public static function delete( $cache_keys ) { |
|
| 277 | + public static function delete($cache_keys) { |
|
| 278 | 278 | $result = true; |
| 279 | 279 | $invalid_keys = array(); |
| 280 | 280 | |
| 281 | - if ( ! empty( $cache_keys ) ) { |
|
| 282 | - $cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys ); |
|
| 281 | + if ( ! empty($cache_keys)) { |
|
| 282 | + $cache_keys = is_array($cache_keys) ? $cache_keys : array($cache_keys); |
|
| 283 | 283 | |
| 284 | - foreach ( $cache_keys as $cache_key ) { |
|
| 285 | - if ( ! self::is_valid_cache_key( $cache_key ) ) { |
|
| 284 | + foreach ($cache_keys as $cache_key) { |
|
| 285 | + if ( ! self::is_valid_cache_key($cache_key)) { |
|
| 286 | 286 | $invalid_keys[] = $cache_key; |
| 287 | 287 | $result = false; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - delete_option( $cache_key ); |
|
| 290 | + delete_option($cache_key); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( ! $result ) { |
|
| 294 | + if ( ! $result) { |
|
| 295 | 295 | $result = new WP_Error( |
| 296 | 296 | 'give_invalid_cache_key', |
| 297 | - __( 'Cache key format should be give_cache_*', 'give' ), |
|
| 297 | + __('Cache key format should be give_cache_*', 'give'), |
|
| 298 | 298 | $invalid_keys |
| 299 | 299 | ); |
| 300 | 300 | } |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * |
| 316 | 316 | * @return bool |
| 317 | 317 | */ |
| 318 | - public static function delete_all_expired( $force = false ) { |
|
| 318 | + public static function delete_all_expired($force = false) { |
|
| 319 | 319 | global $wpdb; |
| 320 | 320 | $options = $wpdb->get_results( |
| 321 | 321 | $wpdb->prepare( |
@@ -329,30 +329,30 @@ discard block |
||
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | 331 | // Bailout. |
| 332 | - if ( empty( $options ) ) { |
|
| 332 | + if (empty($options)) { |
|
| 333 | 333 | return false; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $current_time = current_time( 'timestamp', 1 ); |
|
| 336 | + $current_time = current_time('timestamp', 1); |
|
| 337 | 337 | |
| 338 | 338 | // Delete log cache. |
| 339 | - foreach ( $options as $option ) { |
|
| 340 | - $option['option_value'] = maybe_unserialize( $option['option_value'] ); |
|
| 339 | + foreach ($options as $option) { |
|
| 340 | + $option['option_value'] = maybe_unserialize($option['option_value']); |
|
| 341 | 341 | |
| 342 | 342 | if ( |
| 343 | 343 | ( |
| 344 | - ! self::is_valid_cache_key( $option['option_name'] ) |
|
| 345 | - || ! is_array( $option['option_value'] ) // Backward compatibility (<1.8.7). |
|
| 346 | - || ! array_key_exists( 'expiration', $option['option_value'] ) // Backward compatibility (<1.8.7). |
|
| 347 | - || empty( $option['option_value']['expiration'] ) |
|
| 348 | - || ( $current_time < $option['option_value']['expiration'] ) |
|
| 344 | + ! self::is_valid_cache_key($option['option_name']) |
|
| 345 | + || ! is_array($option['option_value']) // Backward compatibility (<1.8.7). |
|
| 346 | + || ! array_key_exists('expiration', $option['option_value']) // Backward compatibility (<1.8.7). |
|
| 347 | + || empty($option['option_value']['expiration']) |
|
| 348 | + || ($current_time < $option['option_value']['expiration']) |
|
| 349 | 349 | ) |
| 350 | 350 | && ! $force |
| 351 | 351 | ) { |
| 352 | 352 | continue; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - self::delete( $option['option_name'] ); |
|
| 355 | + self::delete($option['option_name']); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
@@ -370,12 +370,12 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | * @return array |
| 372 | 372 | */ |
| 373 | - public static function get_options_like( $option_name, $fields = false ) { |
|
| 373 | + public static function get_options_like($option_name, $fields = false) { |
|
| 374 | 374 | global $wpdb; |
| 375 | 375 | |
| 376 | 376 | $field_names = $fields ? 'option_name, option_value' : 'option_name'; |
| 377 | 377 | |
| 378 | - if ( $fields ) { |
|
| 378 | + if ($fields) { |
|
| 379 | 379 | $options = $wpdb->get_results( |
| 380 | 380 | $wpdb->prepare( |
| 381 | 381 | "SELECT {$field_names } |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | ); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if ( ! empty( $options ) && $fields ) { |
|
| 403 | - foreach ( $options as $index => $option ) { |
|
| 404 | - $option['option_value'] = maybe_unserialize( $option['option_value'] ); |
|
| 405 | - $options[ $index ] = $option; |
|
| 402 | + if ( ! empty($options) && $fields) { |
|
| 403 | + foreach ($options as $index => $option) { |
|
| 404 | + $option['option_value'] = maybe_unserialize($option['option_value']); |
|
| 405 | + $options[$index] = $option; |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | * |
| 420 | 420 | * @return bool |
| 421 | 421 | */ |
| 422 | - public static function is_valid_cache_key( $cache_key ) { |
|
| 423 | - $is_valid = ( false !== strpos( $cache_key, 'give_cache_' ) ); |
|
| 422 | + public static function is_valid_cache_key($cache_key) { |
|
| 423 | + $is_valid = (false !== strpos($cache_key, 'give_cache_')); |
|
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * |
| 429 | 429 | * @since 2.0 |
| 430 | 430 | */ |
| 431 | - return apply_filters( 'give_is_valid_cache_key', $is_valid, $cache_key ); |
|
| 431 | + return apply_filters('give_is_valid_cache_key', $is_valid, $cache_key); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -443,14 +443,14 @@ discard block |
||
| 443 | 443 | * |
| 444 | 444 | * @return mixed |
| 445 | 445 | */ |
| 446 | - public static function get_group( $id, $group = '' ) { |
|
| 446 | + public static function get_group($id, $group = '') { |
|
| 447 | 447 | $cached_data = null; |
| 448 | 448 | |
| 449 | 449 | // Bailout. |
| 450 | - if ( self::$instance->is_cache && ! empty( $id ) ) { |
|
| 451 | - $group = self::$instance->filter_group_name( $group ); |
|
| 450 | + if (self::$instance->is_cache && ! empty($id)) { |
|
| 451 | + $group = self::$instance->filter_group_name($group); |
|
| 452 | 452 | |
| 453 | - $cached_data = wp_cache_get( $id, $group ); |
|
| 453 | + $cached_data = wp_cache_get($id, $group); |
|
| 454 | 454 | $cached_data = false !== $cached_data ? $cached_data : null; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -470,17 +470,17 @@ discard block |
||
| 470 | 470 | * |
| 471 | 471 | * @return bool |
| 472 | 472 | */ |
| 473 | - public static function set_group( $id, $data, $group = '', $expire = 0 ) { |
|
| 473 | + public static function set_group($id, $data, $group = '', $expire = 0) { |
|
| 474 | 474 | $status = false; |
| 475 | 475 | |
| 476 | 476 | // Bailout. |
| 477 | - if ( ! self::$instance->is_cache || empty( $id ) ) { |
|
| 477 | + if ( ! self::$instance->is_cache || empty($id)) { |
|
| 478 | 478 | return $status; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $group = self::$instance->filter_group_name( $group ); |
|
| 481 | + $group = self::$instance->filter_group_name($group); |
|
| 482 | 482 | |
| 483 | - $status = wp_cache_set( $id, $data, $group, $expire ); |
|
| 483 | + $status = wp_cache_set($id, $data, $group, $expire); |
|
| 484 | 484 | |
| 485 | 485 | return $status; |
| 486 | 486 | } |
@@ -496,15 +496,15 @@ discard block |
||
| 496 | 496 | * |
| 497 | 497 | * @return bool |
| 498 | 498 | */ |
| 499 | - public static function set_db_query( $id, $data ) { |
|
| 499 | + public static function set_db_query($id, $data) { |
|
| 500 | 500 | $status = false; |
| 501 | 501 | |
| 502 | 502 | // Bailout. |
| 503 | - if ( ! self::$instance->is_cache || empty( $id ) ) { |
|
| 503 | + if ( ! self::$instance->is_cache || empty($id)) { |
|
| 504 | 504 | return $status; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - return self::set_group( $id, $data, 'give-db-queries', 0 ); |
|
| 507 | + return self::set_group($id, $data, 'give-db-queries', 0); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | * |
| 518 | 518 | * @return mixed |
| 519 | 519 | */ |
| 520 | - public static function get_db_query( $id ) { |
|
| 521 | - return self::get_group( $id, 'give-db-queries' ); |
|
| 520 | + public static function get_db_query($id) { |
|
| 521 | + return self::get_group($id, 'give-db-queries'); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -533,21 +533,21 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @return bool |
| 535 | 535 | */ |
| 536 | - public static function delete_group( $ids, $group = '', $expire = 0 ) { |
|
| 536 | + public static function delete_group($ids, $group = '', $expire = 0) { |
|
| 537 | 537 | $status = false; |
| 538 | 538 | |
| 539 | 539 | // Bailout. |
| 540 | - if ( ! self::$instance->is_cache || empty( $ids ) ) { |
|
| 540 | + if ( ! self::$instance->is_cache || empty($ids)) { |
|
| 541 | 541 | return $status; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | $group_prefix = $group; |
| 545 | - $group = self::$instance->filter_group_name( $group ); |
|
| 545 | + $group = self::$instance->filter_group_name($group); |
|
| 546 | 546 | |
| 547 | 547 | // Delete single or multiple cache items from cache. |
| 548 | - if ( ! is_array( $ids ) ) { |
|
| 549 | - $status = wp_cache_delete( $ids, $group ); |
|
| 550 | - self::$instance->get_incrementer( true ); |
|
| 548 | + if ( ! is_array($ids)) { |
|
| 549 | + $status = wp_cache_delete($ids, $group); |
|
| 550 | + self::$instance->get_incrementer(true); |
|
| 551 | 551 | |
| 552 | 552 | /** |
| 553 | 553 | * Fire action when cache deleted for specific id. |
@@ -558,12 +558,12 @@ discard block |
||
| 558 | 558 | * @param string $group |
| 559 | 559 | * @param int $expire |
| 560 | 560 | */ |
| 561 | - do_action( "give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status ); |
|
| 561 | + do_action("give_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status); |
|
| 562 | 562 | |
| 563 | 563 | } else { |
| 564 | - foreach ( $ids as $id ) { |
|
| 565 | - $status = wp_cache_delete( $id, $group ); |
|
| 566 | - self::$instance->get_incrementer( true ); |
|
| 564 | + foreach ($ids as $id) { |
|
| 565 | + $status = wp_cache_delete($id, $group); |
|
| 566 | + self::$instance->get_incrementer(true); |
|
| 567 | 567 | |
| 568 | 568 | /** |
| 569 | 569 | * Fire action when cache deleted for specific id . |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @param string $group |
| 575 | 575 | * @param int $expire |
| 576 | 576 | */ |
| 577 | - do_action( "give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status ); |
|
| 577 | + do_action("give_deleted_{$group_prefix}_cache", $id, $group, $expire, $status); |
|
| 578 | 578 | } |
| 579 | 579 | } |
| 580 | 580 | |
@@ -591,15 +591,15 @@ discard block |
||
| 591 | 591 | * |
| 592 | 592 | * @param int $form_id |
| 593 | 593 | */ |
| 594 | - public function delete_form_related_cache( $form_id ) { |
|
| 594 | + public function delete_form_related_cache($form_id) { |
|
| 595 | 595 | // If this is just a revision, don't send the email. |
| 596 | - if ( wp_is_post_revision( $form_id ) ) { |
|
| 596 | + if (wp_is_post_revision($form_id)) { |
|
| 597 | 597 | return; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | $donation_query = new Give_Payments_Query( |
| 601 | 601 | array( |
| 602 | - 'number' => - 1, |
|
| 602 | + 'number' => -1, |
|
| 603 | 603 | 'give_forms' => $form_id, |
| 604 | 604 | 'output' => '', |
| 605 | 605 | 'fields' => 'ids', |
@@ -608,15 +608,15 @@ discard block |
||
| 608 | 608 | |
| 609 | 609 | $donations = $donation_query->get_payments(); |
| 610 | 610 | |
| 611 | - if ( ! empty( $donations ) ) { |
|
| 611 | + if ( ! empty($donations)) { |
|
| 612 | 612 | /* @var Give_Payment $donation */ |
| 613 | - foreach ( $donations as $donation_id ) { |
|
| 614 | - wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) ); |
|
| 615 | - wp_cache_delete( give_get_payment_donor_id( $donation_id ), $this->filter_group_name( 'give-donors' ) ); |
|
| 613 | + foreach ($donations as $donation_id) { |
|
| 614 | + wp_cache_delete($donation_id, $this->filter_group_name('give-donations')); |
|
| 615 | + wp_cache_delete(give_get_payment_donor_id($donation_id), $this->filter_group_name('give-donors')); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - self::$instance->get_incrementer( true ); |
|
| 619 | + self::$instance->get_incrementer(true); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -628,19 +628,19 @@ discard block |
||
| 628 | 628 | * |
| 629 | 629 | * @param int $donation_id |
| 630 | 630 | */ |
| 631 | - public function delete_payment_related_cache( $donation_id ) { |
|
| 631 | + public function delete_payment_related_cache($donation_id) { |
|
| 632 | 632 | // If this is just a revision, don't send the email. |
| 633 | - if ( wp_is_post_revision( $donation_id ) ) { |
|
| 633 | + if (wp_is_post_revision($donation_id)) { |
|
| 634 | 634 | return; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - if ( $donation_id && ( $donor_id = give_get_payment_donor_id( $donation_id ) ) ) { |
|
| 638 | - wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) ); |
|
| 637 | + if ($donation_id && ($donor_id = give_get_payment_donor_id($donation_id))) { |
|
| 638 | + wp_cache_delete($donor_id, $this->filter_group_name('give-donors')); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - wp_cache_delete( $donation_id, $this->filter_group_name( 'give-donations' ) ); |
|
| 641 | + wp_cache_delete($donation_id, $this->filter_group_name('give-donations')); |
|
| 642 | 642 | |
| 643 | - self::$instance->get_incrementer( true ); |
|
| 643 | + self::$instance->get_incrementer(true); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -654,18 +654,18 @@ discard block |
||
| 654 | 654 | * @param string $group |
| 655 | 655 | * @param int $expire |
| 656 | 656 | */ |
| 657 | - public function delete_donor_related_cache( $id, $group, $expire ) { |
|
| 658 | - $donation_ids = Give()->donors->get_column( 'payment_ids', $id ); |
|
| 657 | + public function delete_donor_related_cache($id, $group, $expire) { |
|
| 658 | + $donation_ids = Give()->donors->get_column('payment_ids', $id); |
|
| 659 | 659 | |
| 660 | - if ( ! empty( $donation_ids ) ) { |
|
| 661 | - $donation_ids = array_map( 'trim', (array) explode( ',', trim( $donation_ids ) ) ); |
|
| 660 | + if ( ! empty($donation_ids)) { |
|
| 661 | + $donation_ids = array_map('trim', (array) explode(',', trim($donation_ids))); |
|
| 662 | 662 | |
| 663 | - foreach ( $donation_ids as $donation ) { |
|
| 664 | - wp_cache_delete( $donation, $this->filter_group_name( 'give-donations' ) ); |
|
| 663 | + foreach ($donation_ids as $donation) { |
|
| 664 | + wp_cache_delete($donation, $this->filter_group_name('give-donations')); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - self::$instance->get_incrementer( true ); |
|
| 668 | + self::$instance->get_incrementer(true); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -679,12 +679,12 @@ discard block |
||
| 679 | 679 | * @param string $group |
| 680 | 680 | * @param int $expire |
| 681 | 681 | */ |
| 682 | - public function delete_donations_related_cache( $id, $group, $expire ) { |
|
| 683 | - if ( $id && ( $donor_id = give_get_payment_donor_id( $id ) ) ) { |
|
| 684 | - wp_cache_delete( $donor_id, $this->filter_group_name( 'give-donors' ) ); |
|
| 682 | + public function delete_donations_related_cache($id, $group, $expire) { |
|
| 683 | + if ($id && ($donor_id = give_get_payment_donor_id($id))) { |
|
| 684 | + wp_cache_delete($donor_id, $this->filter_group_name('give-donors')); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - self::$instance->get_incrementer( true ); |
|
| 687 | + self::$instance->get_incrementer(true); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -702,12 +702,12 @@ discard block |
||
| 702 | 702 | * |
| 703 | 703 | * @return string |
| 704 | 704 | */ |
| 705 | - public function get_incrementer( $refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries' ) { |
|
| 706 | - $incrementer_value = wp_cache_get( $incrementer_key ); |
|
| 705 | + public function get_incrementer($refresh = false, $incrementer_key = 'give-cache-incrementer-db-queries') { |
|
| 706 | + $incrementer_value = wp_cache_get($incrementer_key); |
|
| 707 | 707 | |
| 708 | - if ( false === $incrementer_value || true === $refresh ) { |
|
| 709 | - $incrementer_value = microtime( true ); |
|
| 710 | - wp_cache_set( $incrementer_key, $incrementer_value ); |
|
| 708 | + if (false === $incrementer_value || true === $refresh) { |
|
| 709 | + $incrementer_value = microtime(true); |
|
| 710 | + wp_cache_set($incrementer_key, $incrementer_value); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | return $incrementer_value; |
@@ -725,21 +725,21 @@ discard block |
||
| 725 | 725 | * |
| 726 | 726 | * @return bool |
| 727 | 727 | */ |
| 728 | - public static function flush_cache( $force = false ) { |
|
| 728 | + public static function flush_cache($force = false) { |
|
| 729 | 729 | if ( |
| 730 | 730 | $force |
| 731 | - || ( Give_Admin_Settings::is_saving_settings() && isset( $_POST['cache'] ) && give_is_setting_enabled( give_clean( $_POST['cache'] ) ) ) |
|
| 732 | - || ( wp_doing_ajax() && isset( $_GET['action'] ) && 'give_cache_flush' === give_clean( $_GET['action'] ) ) |
|
| 731 | + || (Give_Admin_Settings::is_saving_settings() && isset($_POST['cache']) && give_is_setting_enabled(give_clean($_POST['cache']))) |
|
| 732 | + || (wp_doing_ajax() && isset($_GET['action']) && 'give_cache_flush' === give_clean($_GET['action'])) |
|
| 733 | 733 | ) { |
| 734 | - self::$instance->get_incrementer( true ); |
|
| 735 | - self::$instance->get_incrementer( true, 'give-cache-incrementer' ); |
|
| 734 | + self::$instance->get_incrementer(true); |
|
| 735 | + self::$instance->get_incrementer(true, 'give-cache-incrementer'); |
|
| 736 | 736 | |
| 737 | 737 | /** |
| 738 | 738 | * Fire the action when all cache deleted. |
| 739 | 739 | * |
| 740 | 740 | * @since 2.1.0 |
| 741 | 741 | */ |
| 742 | - do_action( 'give_fluched_cache' ); |
|
| 742 | + do_action('give_fluched_cache'); |
|
| 743 | 743 | |
| 744 | 744 | return true; |
| 745 | 745 | } |
@@ -758,23 +758,23 @@ discard block |
||
| 758 | 758 | * |
| 759 | 759 | * @return mixed |
| 760 | 760 | */ |
| 761 | - private function filter_group_name( $group ) { |
|
| 761 | + private function filter_group_name($group) { |
|
| 762 | 762 | /** |
| 763 | 763 | * Filter the group name |
| 764 | 764 | * |
| 765 | 765 | * @since 2.1.0 |
| 766 | 766 | */ |
| 767 | - $filtered_group = apply_filters( 'give_cache_filter_group_name', '', $group ); |
|
| 767 | + $filtered_group = apply_filters('give_cache_filter_group_name', '', $group); |
|
| 768 | 768 | |
| 769 | - if ( empty( $filtered_group ) ) { |
|
| 769 | + if (empty($filtered_group)) { |
|
| 770 | 770 | |
| 771 | - switch ( $group ) { |
|
| 771 | + switch ($group) { |
|
| 772 | 772 | case 'give-db-queries': |
| 773 | 773 | $incrementer = self::$instance->get_incrementer(); |
| 774 | 774 | break; |
| 775 | 775 | |
| 776 | 776 | default: |
| 777 | - $incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' ); |
|
| 777 | + $incrementer = self::$instance->get_incrementer(false, 'give-cache-incrementer'); |
|
| 778 | 778 | |
| 779 | 779 | } |
| 780 | 780 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /* @var WPDB $wpdb */ |
| 36 | 36 | global $wpdb; |
| 37 | 37 | |
| 38 | - $this->table_name = $wpdb->prefix . 'give_sequential_ordering'; |
|
| 38 | + $this->table_name = $wpdb->prefix.'give_sequential_ordering'; |
|
| 39 | 39 | $this->primary_key = 'id'; |
| 40 | 40 | $this->version = '1.0'; |
| 41 | 41 | |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | PRIMARY KEY (id) |
| 109 | 109 | ) {$charset_collate};"; |
| 110 | 110 | |
| 111 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 112 | - dbDelta( $sql ); |
|
| 111 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 112 | + dbDelta($sql); |
|
| 113 | 113 | |
| 114 | - if ( ! empty( $payment_ID ) ) { |
|
| 114 | + if ( ! empty($payment_ID)) { |
|
| 115 | 115 | $auto_increment = $payment_ID + 1; |
| 116 | - $wpdb->query( "ALTER TABLE {$this->table_name} AUTO_INCREMENT={$auto_increment};" ); |
|
| 117 | - give_update_option( 'sequential-ordering_number', $auto_increment ); |
|
| 116 | + $wpdb->query("ALTER TABLE {$this->table_name} AUTO_INCREMENT={$auto_increment};"); |
|
| 117 | + give_update_option('sequential-ordering_number', $auto_increment); |
|
| 118 | 118 | } else { |
| 119 | - give_update_option( 'sequential-ordering_number', 1 ); |
|
| 119 | + give_update_option('sequential-ordering_number', 1); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - update_option( $this->table_name . '_db_version', $this->version, false ); |
|
| 122 | + update_option($this->table_name.'_db_version', $this->version, false); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if access directly. |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 14 | +if ( ! defined('ABSPATH')) { |
|
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | -if ( ! class_exists( 'Give_Email_Access_Email' ) ) : |
|
| 18 | +if ( ! class_exists('Give_Email_Access_Email')) : |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Give_Email_Access_Email |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | * @since 2.0 |
| 32 | 32 | */ |
| 33 | 33 | public function init() { |
| 34 | - $this->load( array( |
|
| 34 | + $this->load(array( |
|
| 35 | 35 | 'id' => 'email-access', |
| 36 | - 'label' => __( 'Email access', 'give' ), |
|
| 37 | - 'description' => __( 'Sent when donors request access to their donation history using only their email as verification. (See Settings > General > Access Control)', 'give' ), |
|
| 38 | - 'notification_status' => give_get_option( 'email_access', 'disabled' ), |
|
| 36 | + 'label' => __('Email access', 'give'), |
|
| 37 | + 'description' => __('Sent when donors request access to their donation history using only their email as verification. (See Settings > General > Access Control)', 'give'), |
|
| 38 | + 'notification_status' => give_get_option('email_access', 'disabled'), |
|
| 39 | 39 | 'form_metabox_setting' => false, |
| 40 | 40 | 'notification_status_editable' => false, |
| 41 | 41 | 'email_tag_context' => 'donor', |
| 42 | - 'recipient_group_name' => __( 'Donor', 'give' ), |
|
| 43 | - 'default_email_subject' => sprintf( __( 'Please confirm your email for %s', 'give' ), get_bloginfo( 'url' ) ), |
|
| 42 | + 'recipient_group_name' => __('Donor', 'give'), |
|
| 43 | + 'default_email_subject' => sprintf(__('Please confirm your email for %s', 'give'), get_bloginfo('url')), |
|
| 44 | 44 | 'default_email_message' => $this->get_default_email_message(), |
| 45 | - 'default_email_header' => __( 'Confirm Email', 'give' ), |
|
| 45 | + 'default_email_header' => __('Confirm Email', 'give'), |
|
| 46 | 46 | 'notices' => array( |
| 47 | 47 | 'non-notification-status-editable' => sprintf( |
| 48 | 48 | '%1$s <a href="%2$s">%3$s »</a>', |
| 49 | - __( 'This notification is automatically toggled based on whether the email access is enabled or not.', 'give' ), |
|
| 50 | - esc_url( admin_url('edit.php?post_type=give_forms&page=give-settings&tab=general§ion=access-control') ), |
|
| 51 | - __( 'Edit Setting', 'give' ) |
|
| 49 | + __('This notification is automatically toggled based on whether the email access is enabled or not.', 'give'), |
|
| 50 | + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=general§ion=access-control')), |
|
| 51 | + __('Edit Setting', 'give') |
|
| 52 | 52 | ) |
| 53 | 53 | ), |
| 54 | - ) ); |
|
| 54 | + )); |
|
| 55 | 55 | |
| 56 | - add_filter( "give_{$this->config['id']}_email_notification", array( $this, 'setup_email_notification' ), 10, 2 ); |
|
| 57 | - add_action( 'give_save_settings_give_settings', array( $this, 'set_notification_status' ), 10, 2 ); |
|
| 58 | - add_filter( 'give_email_preview_header', array( $this, 'email_preview_header' ), 10, 2 ); |
|
| 56 | + add_filter("give_{$this->config['id']}_email_notification", array($this, 'setup_email_notification'), 10, 2); |
|
| 57 | + add_action('give_save_settings_give_settings', array($this, 'set_notification_status'), 10, 2); |
|
| 58 | + add_filter('give_email_preview_header', array($this, 'email_preview_header'), 10, 2); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - public function get_email_subject( $form_id = null ) { |
|
| 71 | + public function get_email_subject($form_id = null) { |
|
| 72 | 72 | $subject = wp_strip_all_tags( |
| 73 | 73 | Give_Email_Notification_Util::get_value( |
| 74 | 74 | $this, |
| 75 | - Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_subject', |
|
| 75 | + Give_Email_Setting_Field::get_prefix($this, $form_id).'email_subject', |
|
| 76 | 76 | $form_id, |
| 77 | 77 | $this->config['default_email_subject'] |
| 78 | 78 | ) |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @since 1.0 |
| 86 | 86 | */ |
| 87 | - $subject = apply_filters( 'give_email_access_token_subject', $subject ); |
|
| 87 | + $subject = apply_filters('give_email_access_token_subject', $subject); |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Filters the donation notification subject. |
| 91 | 91 | * |
| 92 | 92 | * @since 2.0 |
| 93 | 93 | */ |
| 94 | - $subject = apply_filters( "give_{$this->config['id']}_get_email_subject", $subject, $this, $form_id ); |
|
| 94 | + $subject = apply_filters("give_{$this->config['id']}_get_email_subject", $subject, $this, $form_id); |
|
| 95 | 95 | |
| 96 | 96 | return $subject; |
| 97 | 97 | } |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public function get_email_message( $form_id = null ) { |
|
| 110 | + public function get_email_message($form_id = null) { |
|
| 111 | 111 | $message = Give_Email_Notification_Util::get_value( |
| 112 | 112 | $this, |
| 113 | - Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_message', |
|
| 113 | + Give_Email_Setting_Field::get_prefix($this, $form_id).'email_message', |
|
| 114 | 114 | $form_id, |
| 115 | 115 | $this->config['default_email_message'] |
| 116 | 116 | ); |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @since 1.0 |
| 123 | 123 | */ |
| 124 | - $message = apply_filters( 'give_email_access_token_message', $message ); |
|
| 124 | + $message = apply_filters('give_email_access_token_message', $message); |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Filter the email message |
| 128 | 128 | * |
| 129 | 129 | * @since 2.0 |
| 130 | 130 | */ |
| 131 | - $message = apply_filters( "give_{$this->config['id']}_get_default_email_message", $message, $this, $form_id ); |
|
| 131 | + $message = apply_filters("give_{$this->config['id']}_get_default_email_message", $message, $this, $form_id); |
|
| 132 | 132 | |
| 133 | 133 | return $message; |
| 134 | 134 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param int $form_id |
| 144 | 144 | * @return array |
| 145 | 145 | */ |
| 146 | - public function get_email_attachments( $form_id = null ) { |
|
| 146 | + public function get_email_attachments($form_id = null) { |
|
| 147 | 147 | /** |
| 148 | 148 | * Filters the donation notification email attachments. |
| 149 | 149 | * By default, there is no attachment but plugins can hook in to provide one more multiple. |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @since 1.0 |
| 153 | 153 | */ |
| 154 | - $attachments = apply_filters( 'give_admin_donation_notification_attachments', array() ); |
|
| 154 | + $attachments = apply_filters('give_admin_donation_notification_attachments', array()); |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Filters the donation notification email attachments. |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @since 2.0 |
| 161 | 161 | */ |
| 162 | - $attachments = apply_filters( "give_{$this->config['id']}_get_email_attachments", $attachments, $this, $form_id ); |
|
| 162 | + $attachments = apply_filters("give_{$this->config['id']}_get_email_attachments", $attachments, $this, $form_id); |
|
| 163 | 163 | |
| 164 | 164 | return $attachments; |
| 165 | 165 | } |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | 176 | public function get_default_email_message() { |
| 177 | - $message = __( 'Please click the link to access your donation history on {site_url}. If you did not request this email, please contact {admin_email}.', 'give' ) . "\n\n"; |
|
| 178 | - $message .= '{email_access_link}' . "\n\n"; |
|
| 177 | + $message = __('Please click the link to access your donation history on {site_url}. If you did not request this email, please contact {admin_email}.', 'give')."\n\n"; |
|
| 178 | + $message .= '{email_access_link}'."\n\n"; |
|
| 179 | 179 | $message .= "\n\n"; |
| 180 | - $message .= __( 'Sincerely,', 'give' ) . "\n"; |
|
| 181 | - $message .= get_bloginfo( 'name' ) . "\n"; |
|
| 180 | + $message .= __('Sincerely,', 'give')."\n"; |
|
| 181 | + $message .= get_bloginfo('name')."\n"; |
|
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * Filter the new donation email message |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @param string $message |
| 189 | 189 | */ |
| 190 | - return apply_filters( "give_{$this->config['id']}_get_default_email_message", $message, $this ); |
|
| 190 | + return apply_filters("give_{$this->config['id']}_get_default_email_message", $message, $this); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @since 1.0 |
| 205 | 205 | */ |
| 206 | - $from_name = apply_filters( 'give_donation_from_name', Give()->emails->get_from_name() ); |
|
| 206 | + $from_name = apply_filters('give_donation_from_name', Give()->emails->get_from_name()); |
|
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * Filters the from email. |
@@ -211,19 +211,19 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @since 1.0 |
| 213 | 213 | */ |
| 214 | - $from_email = apply_filters( 'give_donation_from_address', Give()->emails->get_from_address() ); |
|
| 214 | + $from_email = apply_filters('give_donation_from_address', Give()->emails->get_from_address()); |
|
| 215 | 215 | |
| 216 | - Give()->emails->__set( 'from_name', $from_name ); |
|
| 217 | - Give()->emails->__set( 'from_email', $from_email ); |
|
| 218 | - Give()->emails->__set( 'heading', apply_filters( 'give_email_access_token_heading', $this->get_email_header() ) ); |
|
| 216 | + Give()->emails->__set('from_name', $from_name); |
|
| 217 | + Give()->emails->__set('from_email', $from_email); |
|
| 218 | + Give()->emails->__set('heading', apply_filters('give_email_access_token_heading', $this->get_email_header())); |
|
| 219 | 219 | /** |
| 220 | 220 | * Filters the donation notification email headers. |
| 221 | 221 | * |
| 222 | 222 | * @since 1.0 |
| 223 | 223 | */ |
| 224 | - $headers = apply_filters( 'give_admin_donation_notification_headers', Give()->emails->get_headers() ); |
|
| 224 | + $headers = apply_filters('give_admin_donation_notification_headers', Give()->emails->get_headers()); |
|
| 225 | 225 | |
| 226 | - Give()->emails->__set( 'headers', $headers ); |
|
| 226 | + Give()->emails->__set('headers', $headers); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - public function setup_email_notification( $donor_id, $email ) { |
|
| 241 | - $donor = Give()->donors->get_donor_by( 'email', $email ); |
|
| 240 | + public function setup_email_notification($donor_id, $email) { |
|
| 241 | + $donor = Give()->donors->get_donor_by('email', $email); |
|
| 242 | 242 | $this->recipient_email = $email; |
| 243 | 243 | |
| 244 | 244 | // Set email data. |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | * @param $update_options |
| 264 | 264 | * @param $option_name |
| 265 | 265 | */ |
| 266 | - public function set_notification_status( $update_options, $option_name ) { |
|
| 266 | + public function set_notification_status($update_options, $option_name) { |
|
| 267 | 267 | // Get updated settings. |
| 268 | 268 | $update_options = give_get_settings(); |
| 269 | 269 | |
| 270 | 270 | if ( |
| 271 | - ! empty( $update_options['email_access'] ) |
|
| 272 | - && ! empty( $update_options[ "{$this->config['id']}_notification" ] ) |
|
| 273 | - && $update_options['email_access'] !== $update_options[ "{$this->config['id']}_notification" ] |
|
| 271 | + ! empty($update_options['email_access']) |
|
| 272 | + && ! empty($update_options["{$this->config['id']}_notification"]) |
|
| 273 | + && $update_options['email_access'] !== $update_options["{$this->config['id']}_notification"] |
|
| 274 | 274 | ) { |
| 275 | - $update_options[ "{$this->config['id']}_notification" ] = $update_options['email_access']; |
|
| 276 | - update_option( $option_name, $update_options, false ); |
|
| 275 | + $update_options["{$this->config['id']}_notification"] = $update_options['email_access']; |
|
| 276 | + update_option($option_name, $update_options, false); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | * @param Give_Email_Access_Email $email |
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | - public function email_preview_header( $email_preview_header, $email ) { |
|
| 292 | - if( $this->config['id'] === $email->config['id'] ) { |
|
| 291 | + public function email_preview_header($email_preview_header, $email) { |
|
| 292 | + if ($this->config['id'] === $email->config['id']) { |
|
| 293 | 293 | $email_preview_header = ''; |
| 294 | 294 | } |
| 295 | 295 | |