@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * Define the shortcode attribute fields |
| 106 | 106 | * |
| 107 | - * @return false|array |
|
| 107 | + * @return boolean |
|
| 108 | 108 | * |
| 109 | 109 | * @since 1.0 |
| 110 | 110 | */ |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | /** |
| 117 | 117 | * Generate the shortcode dialog fields |
| 118 | 118 | * |
| 119 | - * @param array $defined_fields |
|
| 119 | + * @param boolean $defined_fields |
|
| 120 | 120 | * |
| 121 | 121 | * @return array |
| 122 | 122 | * |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @since 1.3.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -defined( 'ABSPATH' ) or exit; |
|
| 14 | +defined('ABSPATH') or exit; |
|
| 15 | 15 | |
| 16 | 16 | abstract class Give_Shortcode_Generator { |
| 17 | 17 | |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @since 1.0 |
| 59 | 59 | */ |
| 60 | - public function __construct( $shortcode ) { |
|
| 60 | + public function __construct($shortcode) { |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | $this->shortcode_tag = $shortcode; |
| 64 | 64 | |
| 65 | - add_action( 'admin_init', array( $this, 'init' ) ); |
|
| 65 | + add_action('admin_init', array($this, 'init')); |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function init() { |
| 74 | 74 | |
| 75 | - if ( $this->shortcode_tag ) { |
|
| 75 | + if ($this->shortcode_tag) { |
|
| 76 | 76 | |
| 77 | - $this->self = get_class( $this ); |
|
| 77 | + $this->self = get_class($this); |
|
| 78 | 78 | |
| 79 | 79 | $this->errors = array(); |
| 80 | 80 | $this->required = array(); |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | $fields = $this->get_fields(); |
| 84 | 84 | |
| 85 | 85 | $defaults = array( |
| 86 | - 'btn_close' => __( 'Close', 'give' ), |
|
| 87 | - 'btn_okay' => __( 'Insert Shortcode', 'give' ), |
|
| 86 | + 'btn_close' => __('Close', 'give'), |
|
| 87 | + 'btn_okay' => __('Insert Shortcode', 'give'), |
|
| 88 | 88 | 'errors' => $this->errors, |
| 89 | 89 | 'fields' => $fields, |
| 90 | - 'label' => '[' . $this->shortcode_tag . ']', |
|
| 90 | + 'label' => '['.$this->shortcode_tag.']', |
|
| 91 | 91 | 'required' => $this->required, |
| 92 | - 'title' => __( 'Insert Shortcode', 'give' ), |
|
| 92 | + 'title' => __('Insert Shortcode', 'give'), |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | - Give_Shortcode_Button::$shortcodes[ $this->shortcode_tag ] = wp_parse_args( $this->shortcode, $defaults ); |
|
| 95 | + Give_Shortcode_Button::$shortcodes[$this->shortcode_tag] = wp_parse_args($this->shortcode, $defaults); |
|
| 96 | 96 | |
| 97 | 97 | // |
| 98 | 98 | |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @since 1.0 |
| 124 | 124 | */ |
| 125 | - protected function generate_fields( $defined_fields ) { |
|
| 125 | + protected function generate_fields($defined_fields) { |
|
| 126 | 126 | |
| 127 | 127 | $fields = array(); |
| 128 | 128 | |
| 129 | - if ( is_array( $defined_fields ) ) { |
|
| 129 | + if (is_array($defined_fields)) { |
|
| 130 | 130 | |
| 131 | - foreach ( $defined_fields as $field ) { |
|
| 131 | + foreach ($defined_fields as $field) { |
|
| 132 | 132 | |
| 133 | 133 | $defaults = array( |
| 134 | 134 | 'label' => false, |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | 'type' => '', |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - $field = wp_parse_args( (array) $field, $defaults ); |
|
| 143 | - $method = 'generate_' . strtolower( $field['type'] ); |
|
| 142 | + $field = wp_parse_args((array) $field, $defaults); |
|
| 143 | + $method = 'generate_'.strtolower($field['type']); |
|
| 144 | 144 | |
| 145 | - if ( method_exists( $this, $method ) ) { |
|
| 145 | + if (method_exists($this, $method)) { |
|
| 146 | 146 | |
| 147 | - $field = call_user_func( array( $this, $method ), $field ); |
|
| 147 | + $field = call_user_func(array($this, $method), $field); |
|
| 148 | 148 | |
| 149 | - if ( $field ) { |
|
| 149 | + if ($field) { |
|
| 150 | 150 | $fields[] = $field; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -166,22 +166,22 @@ discard block |
||
| 166 | 166 | protected function get_fields() { |
| 167 | 167 | |
| 168 | 168 | $defined_fields = $this->define_fields(); |
| 169 | - $generated_fields = $this->generate_fields( $defined_fields ); |
|
| 169 | + $generated_fields = $this->generate_fields($defined_fields); |
|
| 170 | 170 | |
| 171 | 171 | $errors = array(); |
| 172 | 172 | |
| 173 | - if ( ! empty( $this->errors ) ) { |
|
| 174 | - foreach ( $this->required as $name => $alert ) { |
|
| 175 | - if ( false === array_search( $name, array_column( $generated_fields, 'name' ) ) ) { |
|
| 173 | + if ( ! empty($this->errors)) { |
|
| 174 | + foreach ($this->required as $name => $alert) { |
|
| 175 | + if (false === array_search($name, array_column($generated_fields, 'name'))) { |
|
| 176 | 176 | |
| 177 | - $errors[] = $this->errors[ $name ]; |
|
| 177 | + $errors[] = $this->errors[$name]; |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $this->errors = $errors; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ( ! empty( $errors ) ) { |
|
| 184 | + if ( ! empty($errors)) { |
|
| 185 | 185 | |
| 186 | 186 | return $errors; |
| 187 | 187 | } |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @since 1.0 |
| 200 | 200 | */ |
| 201 | - protected function generate_container( $field ) { |
|
| 201 | + protected function generate_container($field) { |
|
| 202 | 202 | |
| 203 | - if ( array_key_exists( 'html', $field ) ) { |
|
| 203 | + if (array_key_exists('html', $field)) { |
|
| 204 | 204 | |
| 205 | 205 | return array( |
| 206 | 206 | 'type' => $field['type'], |
@@ -220,36 +220,36 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @since 1.0 |
| 222 | 222 | */ |
| 223 | - protected function generate_listbox( $field ) { |
|
| 223 | + protected function generate_listbox($field) { |
|
| 224 | 224 | |
| 225 | - $listbox = shortcode_atts( array( |
|
| 225 | + $listbox = shortcode_atts(array( |
|
| 226 | 226 | 'label' => '', |
| 227 | 227 | 'minWidth' => '', |
| 228 | 228 | 'name' => false, |
| 229 | 229 | 'tooltip' => '', |
| 230 | 230 | 'type' => '', |
| 231 | 231 | 'value' => '', |
| 232 | - ), $field ); |
|
| 232 | + ), $field); |
|
| 233 | 233 | |
| 234 | - if ( $this->validate( $field ) ) { |
|
| 234 | + if ($this->validate($field)) { |
|
| 235 | 235 | |
| 236 | 236 | $new_listbox = array(); |
| 237 | 237 | |
| 238 | - foreach ( $listbox as $key => $value ) { |
|
| 238 | + foreach ($listbox as $key => $value) { |
|
| 239 | 239 | |
| 240 | - if ( $key == 'value' && empty( $value ) ) { |
|
| 241 | - $new_listbox[ $key ] = $listbox['name']; |
|
| 242 | - } else if ( $value ) { |
|
| 243 | - $new_listbox[ $key ] = $value; |
|
| 240 | + if ($key == 'value' && empty($value)) { |
|
| 241 | + $new_listbox[$key] = $listbox['name']; |
|
| 242 | + } else if ($value) { |
|
| 243 | + $new_listbox[$key] = $value; |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // do not reindex array! |
| 248 | 248 | $field['options'] = array( |
| 249 | - '' => ( $field['placeholder'] ? $field['placeholder'] : sprintf( '– %s –', __( 'Select', 'give' ) ) ), |
|
| 249 | + '' => ($field['placeholder'] ? $field['placeholder'] : sprintf('– %s –', __('Select', 'give'))), |
|
| 250 | 250 | ) + $field['options']; |
| 251 | 251 | |
| 252 | - foreach ( $field['options'] as $value => $text ) { |
|
| 252 | + foreach ($field['options'] as $value => $text) { |
|
| 253 | 253 | $new_listbox['values'][] = array( |
| 254 | 254 | 'text' => $text, |
| 255 | 255 | 'value' => $value, |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @since 1.0 |
| 273 | 273 | */ |
| 274 | - protected function generate_post( $field ) { |
|
| 274 | + protected function generate_post($field) { |
|
| 275 | 275 | |
| 276 | 276 | $args = array( |
| 277 | 277 | 'post_type' => 'post', |
@@ -280,23 +280,23 @@ discard block |
||
| 280 | 280 | 'posts_per_page' => 30, |
| 281 | 281 | ); |
| 282 | 282 | |
| 283 | - $args = wp_parse_args( (array) $field['query_args'], $args ); |
|
| 284 | - $posts = get_posts( $args ); |
|
| 283 | + $args = wp_parse_args((array) $field['query_args'], $args); |
|
| 284 | + $posts = get_posts($args); |
|
| 285 | 285 | $options = array(); |
| 286 | 286 | |
| 287 | - if ( $posts ) { |
|
| 288 | - foreach ( $posts as $post ) { |
|
| 289 | - $options[ absint( $post->ID ) ] = esc_html( $post->post_title ); |
|
| 287 | + if ($posts) { |
|
| 288 | + foreach ($posts as $post) { |
|
| 289 | + $options[absint($post->ID)] = esc_html($post->post_title); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | $field['type'] = 'listbox'; |
| 293 | 293 | $field['options'] = $options; |
| 294 | 294 | |
| 295 | - return $this->generate_listbox( $field ); |
|
| 295 | + return $this->generate_listbox($field); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | // perform validation here before returning false |
| 299 | - $this->validate( $field ); |
|
| 299 | + $this->validate($field); |
|
| 300 | 300 | |
| 301 | 301 | return false; |
| 302 | 302 | } |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @since 1.0 |
| 312 | 312 | */ |
| 313 | - protected function generate_textbox( $field ) { |
|
| 313 | + protected function generate_textbox($field) { |
|
| 314 | 314 | |
| 315 | - $textbox = shortcode_atts( array( |
|
| 315 | + $textbox = shortcode_atts(array( |
|
| 316 | 316 | 'label' => '', |
| 317 | 317 | 'maxLength' => '', |
| 318 | 318 | 'minHeight' => '', |
@@ -322,10 +322,10 @@ discard block |
||
| 322 | 322 | 'tooltip' => '', |
| 323 | 323 | 'type' => '', |
| 324 | 324 | 'value' => '', |
| 325 | - ), $field ); |
|
| 325 | + ), $field); |
|
| 326 | 326 | |
| 327 | - if ( $this->validate( $field ) ) { |
|
| 328 | - return array_filter( $textbox, array( $this, 'return_textbox_value' ) ); |
|
| 327 | + if ($this->validate($field)) { |
|
| 328 | + return array_filter($textbox, array($this, 'return_textbox_value')); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | return false; |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | * |
| 339 | 339 | * @return bool |
| 340 | 340 | */ |
| 341 | - function return_textbox_value( $value ) { |
|
| 341 | + function return_textbox_value($value) { |
|
| 342 | 342 | return $value !== ''; |
| 343 | 343 | } |
| 344 | 344 | |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * |
| 355 | 355 | * @since 1.0 |
| 356 | 356 | */ |
| 357 | - protected function validate( $field ) { |
|
| 357 | + protected function validate($field) { |
|
| 358 | 358 | |
| 359 | - extract( shortcode_atts( |
|
| 359 | + extract(shortcode_atts( |
|
| 360 | 360 | array( |
| 361 | 361 | 'name' => false, |
| 362 | 362 | 'required' => false, |
@@ -364,34 +364,34 @@ discard block |
||
| 364 | 364 | ), $field ) |
| 365 | 365 | ); |
| 366 | 366 | |
| 367 | - if ( $name ) { |
|
| 367 | + if ($name) { |
|
| 368 | 368 | |
| 369 | - if ( isset( $required['error'] ) ) { |
|
| 369 | + if (isset($required['error'])) { |
|
| 370 | 370 | |
| 371 | 371 | $error = array( |
| 372 | 372 | 'type' => 'container', |
| 373 | 373 | 'html' => $required['error'], |
| 374 | 374 | ); |
| 375 | 375 | |
| 376 | - $this->errors[ $name ] = $this->generate_container( $error ); |
|
| 376 | + $this->errors[$name] = $this->generate_container($error); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( ! ! $required || is_array( $required ) ) { |
|
| 379 | + if ( ! ! $required || is_array($required)) { |
|
| 380 | 380 | |
| 381 | - $alert = __( 'Some of the Shortcode options are required.', 'give' ); |
|
| 381 | + $alert = __('Some of the Shortcode options are required.', 'give'); |
|
| 382 | 382 | |
| 383 | - if ( isset( $required['alert'] ) ) { |
|
| 383 | + if (isset($required['alert'])) { |
|
| 384 | 384 | |
| 385 | 385 | $alert = $required['alert']; |
| 386 | 386 | |
| 387 | - } else if ( ! empty( $label ) ) { |
|
| 387 | + } else if ( ! empty($label)) { |
|
| 388 | 388 | |
| 389 | - $alert = sprintf( __( 'The "%s" option is required.', 'give' ), |
|
| 390 | - str_replace( ':', '', $label ) |
|
| 389 | + $alert = sprintf(__('The "%s" option is required.', 'give'), |
|
| 390 | + str_replace(':', '', $label) |
|
| 391 | 391 | ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - $this->required[ $name ] = $alert; |
|
| 394 | + $this->required[$name] = $alert; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | return true; |
@@ -246,8 +246,8 @@ |
||
| 246 | 246 | |
| 247 | 247 | // do not reindex array! |
| 248 | 248 | $field['options'] = array( |
| 249 | - '' => ( $field['placeholder'] ? $field['placeholder'] : sprintf( '– %s –', __( 'Select', 'give' ) ) ), |
|
| 250 | - ) + $field['options']; |
|
| 249 | + '' => ( $field['placeholder'] ? $field['placeholder'] : sprintf( '– %s –', __( 'Select', 'give' ) ) ), |
|
| 250 | + ) + $field['options']; |
|
| 251 | 251 | |
| 252 | 252 | foreach ( $field['options'] as $value => $text ) { |
| 253 | 253 | $new_listbox['values'][] = array( |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @access public |
| 213 | 213 | * @since 1.1 |
| 214 | - * @return array |
|
| 214 | + * @return string |
|
| 215 | 215 | */ |
| 216 | 216 | public function get_versions() { |
| 217 | 217 | return $this->versions; |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | * |
| 663 | 663 | * @param array $args Arguments to override defaults |
| 664 | 664 | * |
| 665 | - * @return array $dates |
|
| 665 | + * @return integer|null $dates |
|
| 666 | 666 | */ |
| 667 | 667 | public function get_dates( $args = array() ) { |
| 668 | 668 | $dates = array(); |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | * |
| 1713 | 1713 | * @param int $user_id User ID of user to revoke key for |
| 1714 | 1714 | * |
| 1715 | - * @return string |
|
| 1715 | + * @return boolean |
|
| 1716 | 1716 | */ |
| 1717 | 1717 | public function revoke_api_key( $user_id = 0 ) { |
| 1718 | 1718 | |
@@ -1,15 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Give API |
|
| 4 | - * |
|
| 5 | - * A front-facing JSON/XML API that makes it possible to query donation data. |
|
| 6 | - * |
|
| 7 | - * @package Give |
|
| 8 | - * @subpackage Classes/API |
|
| 9 | - * @copyright Copyright (c) 2015, WordImpress |
|
| 10 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
| 11 | - * @since 1.1 |
|
| 12 | - */ |
|
| 3 | + * Give API |
|
| 4 | + * |
|
| 5 | + * A front-facing JSON/XML API that makes it possible to query donation data. |
|
| 6 | + * |
|
| 7 | + * @package Give |
|
| 8 | + * @subpackage Classes/API |
|
| 9 | + * @copyright Copyright (c) 2015, WordImpress |
|
| 10 | + * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
| 11 | + * @since 1.1 |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -139,27 +139,27 @@ discard block |
||
| 139 | 139 | 'v1' => 'GIVE_API_V1', |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - foreach ( $this->get_versions() as $version => $class ) { |
|
| 143 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
| 142 | + foreach ($this->get_versions() as $version => $class) { |
|
| 143 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
| 147 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
| 148 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
| 149 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
| 150 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
| 151 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
| 152 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
| 153 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
| 146 | + add_action('init', array($this, 'add_endpoint')); |
|
| 147 | + add_action('wp', array($this, 'process_query'), - 1); |
|
| 148 | + add_filter('query_vars', array($this, 'query_vars')); |
|
| 149 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
| 150 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
| 151 | + add_action('personal_options_update', array($this, 'update_key')); |
|
| 152 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
| 153 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
| 154 | 154 | |
| 155 | 155 | // Setup a backwards compatibility check for user API Keys |
| 156 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
| 156 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
| 157 | 157 | |
| 158 | 158 | // Determine if JSON_PRETTY_PRINT is available |
| 159 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
| 159 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
| 160 | 160 | |
| 161 | 161 | // Allow API request logging to be turned off |
| 162 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
| 162 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
| 163 | 163 | |
| 164 | 164 | // Setup Give_Payment_Stats instance |
| 165 | 165 | $this->stats = new Give_Payment_Stats; |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @since 1.1 |
| 177 | 177 | */ |
| 178 | - public function add_endpoint( $rewrite_rules ) { |
|
| 179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
| 178 | + public function add_endpoint($rewrite_rules) { |
|
| 179 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @return string[] $vars New query vars |
| 191 | 191 | */ |
| 192 | - public function query_vars( $vars ) { |
|
| 192 | + public function query_vars($vars) { |
|
| 193 | 193 | |
| 194 | 194 | $vars[] = 'token'; |
| 195 | 195 | $vars[] = 'key'; |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function get_default_version() { |
| 242 | 242 | |
| 243 | - $version = get_option( 'give_default_api_version' ); |
|
| 243 | + $version = get_option('give_default_api_version'); |
|
| 244 | 244 | |
| 245 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
| 245 | + if (defined('GIVE_API_VERSION')) { |
|
| 246 | 246 | $version = GIVE_API_VERSION; |
| 247 | - } elseif ( ! $version ) { |
|
| 247 | + } elseif ( ! $version) { |
|
| 248 | 248 | $version = 'v1'; |
| 249 | 249 | } |
| 250 | 250 | |
@@ -265,14 +265,14 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | $version = $wp_query->query_vars['give-api']; |
| 267 | 267 | |
| 268 | - if ( strpos( $version, '/' ) ) { |
|
| 268 | + if (strpos($version, '/')) { |
|
| 269 | 269 | |
| 270 | - $version = explode( '/', $version ); |
|
| 271 | - $version = strtolower( $version[0] ); |
|
| 270 | + $version = explode('/', $version); |
|
| 271 | + $version = strtolower($version[0]); |
|
| 272 | 272 | |
| 273 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
| 273 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
| 274 | 274 | |
| 275 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
| 275 | + if (array_key_exists($version, $this->versions)) { |
|
| 276 | 276 | |
| 277 | 277 | $this->queried_version = $version; |
| 278 | 278 | |
@@ -309,32 +309,32 @@ discard block |
||
| 309 | 309 | $this->override = false; |
| 310 | 310 | |
| 311 | 311 | // Make sure we have both user and api key |
| 312 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
| 312 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
| 313 | 313 | |
| 314 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
| 314 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
| 315 | 315 | $this->missing_auth(); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Retrieve the user by public API key and ensure they exist |
| 319 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
| 319 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
| 320 | 320 | |
| 321 | 321 | $this->invalid_key(); |
| 322 | 322 | |
| 323 | 323 | } else { |
| 324 | 324 | |
| 325 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
| 326 | - $secret = $this->get_user_secret_key( $user ); |
|
| 327 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
| 325 | + $token = urldecode($wp_query->query_vars['token']); |
|
| 326 | + $secret = $this->get_user_secret_key($user); |
|
| 327 | + $public = urldecode($wp_query->query_vars['key']); |
|
| 328 | 328 | |
| 329 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
| 329 | + if (hash_equals(md5($secret.$public), $token)) { |
|
| 330 | 330 | $this->is_valid_request = true; |
| 331 | 331 | } else { |
| 332 | 332 | $this->invalid_auth(); |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
| 335 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
| 336 | 336 | $this->is_valid_request = true; |
| 337 | - $wp_query->set( 'key', 'public' ); |
|
| 337 | + $wp_query->set('key', 'public'); |
|
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
@@ -350,25 +350,25 @@ discard block |
||
| 350 | 350 | * |
| 351 | 351 | * @return bool if user ID is found, false otherwise |
| 352 | 352 | */ |
| 353 | - public function get_user( $key = '' ) { |
|
| 353 | + public function get_user($key = '') { |
|
| 354 | 354 | global $wpdb, $wp_query; |
| 355 | 355 | |
| 356 | - if ( empty( $key ) ) { |
|
| 357 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
| 356 | + if (empty($key)) { |
|
| 357 | + $key = urldecode($wp_query->query_vars['key']); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( empty( $key ) ) { |
|
| 360 | + if (empty($key)) { |
|
| 361 | 361 | return false; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
| 364 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
| 365 | 365 | |
| 366 | - if ( false === $user ) { |
|
| 367 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
| 368 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
| 366 | + if (false === $user) { |
|
| 367 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
| 368 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if ( $user != null ) { |
|
| 371 | + if ($user != null) { |
|
| 372 | 372 | $this->user_id = $user; |
| 373 | 373 | |
| 374 | 374 | return $user; |
@@ -377,37 +377,37 @@ discard block |
||
| 377 | 377 | return false; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - public function get_user_public_key( $user_id = 0 ) { |
|
| 380 | + public function get_user_public_key($user_id = 0) { |
|
| 381 | 381 | global $wpdb; |
| 382 | 382 | |
| 383 | - if ( empty( $user_id ) ) { |
|
| 383 | + if (empty($user_id)) { |
|
| 384 | 384 | return ''; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
| 388 | - $user_public_key = get_transient( $cache_key ); |
|
| 387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
| 388 | + $user_public_key = get_transient($cache_key); |
|
| 389 | 389 | |
| 390 | - if ( empty( $user_public_key ) ) { |
|
| 391 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
| 392 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
| 390 | + if (empty($user_public_key)) { |
|
| 391 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
| 392 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | return $user_public_key; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - public function get_user_secret_key( $user_id = 0 ) { |
|
| 398 | + public function get_user_secret_key($user_id = 0) { |
|
| 399 | 399 | global $wpdb; |
| 400 | 400 | |
| 401 | - if ( empty( $user_id ) ) { |
|
| 401 | + if (empty($user_id)) { |
|
| 402 | 402 | return ''; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
| 406 | - $user_secret_key = get_transient( $cache_key ); |
|
| 405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
| 406 | + $user_secret_key = get_transient($cache_key); |
|
| 407 | 407 | |
| 408 | - if ( empty( $user_secret_key ) ) { |
|
| 409 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
| 410 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
| 408 | + if (empty($user_secret_key)) { |
|
| 409 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
| 410 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | private function missing_auth() { |
| 425 | 425 | $error = array(); |
| 426 | - $error['error'] = esc_attr__( 'You must specify both a token and API key!', 'give' ); |
|
| 426 | + $error['error'] = esc_attr__('You must specify both a token and API key!', 'give'); |
|
| 427 | 427 | |
| 428 | 428 | $this->data = $error; |
| 429 | - $this->output( 401 ); |
|
| 429 | + $this->output(401); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -440,10 +440,10 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | private function invalid_auth() { |
| 442 | 442 | $error = array(); |
| 443 | - $error['error'] = esc_attr__( 'Your request could not be authenticated!', 'give' ); |
|
| 443 | + $error['error'] = esc_attr__('Your request could not be authenticated!', 'give'); |
|
| 444 | 444 | |
| 445 | 445 | $this->data = $error; |
| 446 | - $this->output( 403 ); |
|
| 446 | + $this->output(403); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -457,10 +457,10 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | private function invalid_key() { |
| 459 | 459 | $error = array(); |
| 460 | - $error['error'] = esc_attr__( 'Invalid API key!', 'give' ); |
|
| 460 | + $error['error'] = esc_attr__('Invalid API key!', 'give'); |
|
| 461 | 461 | |
| 462 | 462 | $this->data = $error; |
| 463 | - $this->output( 403 ); |
|
| 463 | + $this->output(403); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | private function invalid_version() { |
| 475 | 475 | $error = array(); |
| 476 | - $error['error'] = esc_attr__( 'Invalid API version!', 'give' ); |
|
| 476 | + $error['error'] = esc_attr__('Invalid API version!', 'give'); |
|
| 477 | 477 | |
| 478 | 478 | $this->data = $error; |
| 479 | - $this->output( 404 ); |
|
| 479 | + $this->output(404); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -492,10 +492,10 @@ discard block |
||
| 492 | 492 | global $wp_query; |
| 493 | 493 | |
| 494 | 494 | // Start logging how long the request takes for logging |
| 495 | - $before = microtime( true ); |
|
| 495 | + $before = microtime(true); |
|
| 496 | 496 | |
| 497 | 497 | // Check for give-api var. Get out if not present |
| 498 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
| 498 | + if (empty($wp_query->query_vars['give-api'])) { |
|
| 499 | 499 | return; |
| 500 | 500 | } |
| 501 | 501 | |
@@ -509,45 +509,45 @@ discard block |
||
| 509 | 509 | $this->validate_request(); |
| 510 | 510 | |
| 511 | 511 | // Only proceed if no errors have been noted |
| 512 | - if ( ! $this->is_valid_request ) { |
|
| 512 | + if ( ! $this->is_valid_request) { |
|
| 513 | 513 | return; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
| 517 | - define( 'GIVE_DOING_API', true ); |
|
| 516 | + if ( ! defined('GIVE_DOING_API')) { |
|
| 517 | + define('GIVE_DOING_API', true); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | $data = array(); |
| 521 | 521 | $this->routes = new $this->versions[$this->get_queried_version()]; |
| 522 | 522 | $this->routes->validate_request(); |
| 523 | 523 | |
| 524 | - switch ( $this->endpoint ) : |
|
| 524 | + switch ($this->endpoint) : |
|
| 525 | 525 | |
| 526 | 526 | case 'stats' : |
| 527 | 527 | |
| 528 | - $data = $this->routes->get_stats( array( |
|
| 529 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 530 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 531 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 532 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 533 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
| 534 | - ) ); |
|
| 528 | + $data = $this->routes->get_stats(array( |
|
| 529 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 530 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 531 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 532 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 533 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
| 534 | + )); |
|
| 535 | 535 | |
| 536 | 536 | break; |
| 537 | 537 | |
| 538 | 538 | case 'forms' : |
| 539 | 539 | |
| 540 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
| 540 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
| 541 | 541 | |
| 542 | - $data = $this->routes->get_forms( $form ); |
|
| 542 | + $data = $this->routes->get_forms($form); |
|
| 543 | 543 | |
| 544 | 544 | break; |
| 545 | 545 | |
| 546 | 546 | case 'donors' : |
| 547 | 547 | |
| 548 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
| 548 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
| 549 | 549 | |
| 550 | - $data = $this->routes->get_customers( $customer ); |
|
| 550 | + $data = $this->routes->get_customers($customer); |
|
| 551 | 551 | |
| 552 | 552 | break; |
| 553 | 553 | |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | endswitch; |
| 561 | 561 | |
| 562 | 562 | // Allow extensions to setup their own return data |
| 563 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
| 563 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
| 564 | 564 | |
| 565 | - $after = microtime( true ); |
|
| 566 | - $request_time = ( $after - $before ); |
|
| 565 | + $after = microtime(true); |
|
| 566 | + $request_time = ($after - $before); |
|
| 567 | 567 | $this->data['request_speed'] = $request_time; |
| 568 | 568 | |
| 569 | 569 | // Log this API request, if enabled. We log it here because we have access to errors. |
| 570 | - $this->log_request( $this->data ); |
|
| 570 | + $this->log_request($this->data); |
|
| 571 | 571 | |
| 572 | 572 | // Send out data to the output function |
| 573 | 573 | $this->output(); |
@@ -597,21 +597,21 @@ discard block |
||
| 597 | 597 | global $wp_query; |
| 598 | 598 | |
| 599 | 599 | // Whitelist our query options |
| 600 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
| 600 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
| 601 | 601 | 'stats', |
| 602 | 602 | 'forms', |
| 603 | 603 | 'donors', |
| 604 | 604 | 'donations' |
| 605 | - ) ); |
|
| 605 | + )); |
|
| 606 | 606 | |
| 607 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
| 608 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
| 607 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
| 608 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
| 609 | 609 | |
| 610 | 610 | $error = array(); |
| 611 | 611 | |
| 612 | 612 | // Make sure our query is valid |
| 613 | - if ( ! in_array( $query, $accepted ) ) { |
|
| 614 | - $error['error'] = __( 'Invalid query!', 'give' ); |
|
| 613 | + if ( ! in_array($query, $accepted)) { |
|
| 614 | + $error['error'] = __('Invalid query!', 'give'); |
|
| 615 | 615 | |
| 616 | 616 | $this->data = $error; |
| 617 | 617 | $this->output(); |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | public function get_paged() { |
| 632 | 632 | global $wp_query; |
| 633 | 633 | |
| 634 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
| 634 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | |
@@ -646,13 +646,13 @@ discard block |
||
| 646 | 646 | public function per_page() { |
| 647 | 647 | global $wp_query; |
| 648 | 648 | |
| 649 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
| 649 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
| 650 | 650 | |
| 651 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
| 651 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
| 652 | 652 | $per_page = 99999999; |
| 653 | 653 | } // Customers query doesn't support -1 |
| 654 | 654 | |
| 655 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
| 655 | + return apply_filters('give_api_results_per_page', $per_page); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | * |
| 666 | 666 | * @return array $dates |
| 667 | 667 | */ |
| 668 | - public function get_dates( $args = array() ) { |
|
| 668 | + public function get_dates($args = array()) { |
|
| 669 | 669 | $dates = array(); |
| 670 | 670 | |
| 671 | 671 | $defaults = array( |
@@ -676,60 +676,60 @@ discard block |
||
| 676 | 676 | 'enddate' => null |
| 677 | 677 | ); |
| 678 | 678 | |
| 679 | - $args = wp_parse_args( $args, $defaults ); |
|
| 679 | + $args = wp_parse_args($args, $defaults); |
|
| 680 | 680 | |
| 681 | - $current_time = current_time( 'timestamp' ); |
|
| 681 | + $current_time = current_time('timestamp'); |
|
| 682 | 682 | |
| 683 | - if ( 'range' === $args['date'] ) { |
|
| 684 | - $startdate = strtotime( $args['startdate'] ); |
|
| 685 | - $enddate = strtotime( $args['enddate'] ); |
|
| 686 | - $dates['day_start'] = date( 'd', $startdate ); |
|
| 687 | - $dates['day_end'] = date( 'd', $enddate ); |
|
| 688 | - $dates['m_start'] = date( 'n', $startdate ); |
|
| 689 | - $dates['m_end'] = date( 'n', $enddate ); |
|
| 690 | - $dates['year'] = date( 'Y', $startdate ); |
|
| 691 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
| 683 | + if ('range' === $args['date']) { |
|
| 684 | + $startdate = strtotime($args['startdate']); |
|
| 685 | + $enddate = strtotime($args['enddate']); |
|
| 686 | + $dates['day_start'] = date('d', $startdate); |
|
| 687 | + $dates['day_end'] = date('d', $enddate); |
|
| 688 | + $dates['m_start'] = date('n', $startdate); |
|
| 689 | + $dates['m_end'] = date('n', $enddate); |
|
| 690 | + $dates['year'] = date('Y', $startdate); |
|
| 691 | + $dates['year_end'] = date('Y', $enddate); |
|
| 692 | 692 | } else { |
| 693 | 693 | // Modify dates based on predefined ranges |
| 694 | - switch ( $args['date'] ) : |
|
| 694 | + switch ($args['date']) : |
|
| 695 | 695 | |
| 696 | 696 | case 'this_month' : |
| 697 | 697 | $dates['day'] = null; |
| 698 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 699 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 700 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 698 | + $dates['m_start'] = date('n', $current_time); |
|
| 699 | + $dates['m_end'] = date('n', $current_time); |
|
| 700 | + $dates['year'] = date('Y', $current_time); |
|
| 701 | 701 | break; |
| 702 | 702 | |
| 703 | 703 | case 'last_month' : |
| 704 | 704 | $dates['day'] = null; |
| 705 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
| 705 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
| 706 | 706 | $dates['m_end'] = $dates['m_start']; |
| 707 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
| 707 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
| 708 | 708 | break; |
| 709 | 709 | |
| 710 | 710 | case 'today' : |
| 711 | - $dates['day'] = date( 'd', $current_time ); |
|
| 712 | - $dates['m_start'] = date( 'n', $current_time ); |
|
| 713 | - $dates['m_end'] = date( 'n', $current_time ); |
|
| 714 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 711 | + $dates['day'] = date('d', $current_time); |
|
| 712 | + $dates['m_start'] = date('n', $current_time); |
|
| 713 | + $dates['m_end'] = date('n', $current_time); |
|
| 714 | + $dates['year'] = date('Y', $current_time); |
|
| 715 | 715 | break; |
| 716 | 716 | |
| 717 | 717 | case 'yesterday' : |
| 718 | 718 | |
| 719 | - $year = date( 'Y', $current_time ); |
|
| 720 | - $month = date( 'n', $current_time ); |
|
| 721 | - $day = date( 'd', $current_time ); |
|
| 719 | + $year = date('Y', $current_time); |
|
| 720 | + $month = date('n', $current_time); |
|
| 721 | + $day = date('d', $current_time); |
|
| 722 | 722 | |
| 723 | - if ( $month == 1 && $day == 1 ) { |
|
| 723 | + if ($month == 1 && $day == 1) { |
|
| 724 | 724 | |
| 725 | 725 | $year -= 1; |
| 726 | 726 | $month = 12; |
| 727 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 727 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 728 | 728 | |
| 729 | - } elseif ( $month > 1 && $day == 1 ) { |
|
| 729 | + } elseif ($month > 1 && $day == 1) { |
|
| 730 | 730 | |
| 731 | 731 | $month -= 1; |
| 732 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 732 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 733 | 733 | |
| 734 | 734 | } else { |
| 735 | 735 | |
@@ -745,65 +745,65 @@ discard block |
||
| 745 | 745 | break; |
| 746 | 746 | |
| 747 | 747 | case 'this_quarter' : |
| 748 | - $month_now = date( 'n', $current_time ); |
|
| 748 | + $month_now = date('n', $current_time); |
|
| 749 | 749 | |
| 750 | 750 | $dates['day'] = null; |
| 751 | 751 | |
| 752 | - if ( $month_now <= 3 ) { |
|
| 752 | + if ($month_now <= 3) { |
|
| 753 | 753 | |
| 754 | 754 | $dates['m_start'] = 1; |
| 755 | 755 | $dates['m_end'] = 3; |
| 756 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 756 | + $dates['year'] = date('Y', $current_time); |
|
| 757 | 757 | |
| 758 | - } else if ( $month_now <= 6 ) { |
|
| 758 | + } else if ($month_now <= 6) { |
|
| 759 | 759 | |
| 760 | 760 | $dates['m_start'] = 4; |
| 761 | 761 | $dates['m_end'] = 6; |
| 762 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 762 | + $dates['year'] = date('Y', $current_time); |
|
| 763 | 763 | |
| 764 | - } else if ( $month_now <= 9 ) { |
|
| 764 | + } else if ($month_now <= 9) { |
|
| 765 | 765 | |
| 766 | 766 | $dates['m_start'] = 7; |
| 767 | 767 | $dates['m_end'] = 9; |
| 768 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 768 | + $dates['year'] = date('Y', $current_time); |
|
| 769 | 769 | |
| 770 | 770 | } else { |
| 771 | 771 | |
| 772 | 772 | $dates['m_start'] = 10; |
| 773 | 773 | $dates['m_end'] = 12; |
| 774 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 774 | + $dates['year'] = date('Y', $current_time); |
|
| 775 | 775 | |
| 776 | 776 | } |
| 777 | 777 | break; |
| 778 | 778 | |
| 779 | 779 | case 'last_quarter' : |
| 780 | - $month_now = date( 'n', $current_time ); |
|
| 780 | + $month_now = date('n', $current_time); |
|
| 781 | 781 | |
| 782 | 782 | $dates['day'] = null; |
| 783 | 783 | |
| 784 | - if ( $month_now <= 3 ) { |
|
| 784 | + if ($month_now <= 3) { |
|
| 785 | 785 | |
| 786 | 786 | $dates['m_start'] = 10; |
| 787 | 787 | $dates['m_end'] = 12; |
| 788 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
| 788 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
| 789 | 789 | |
| 790 | - } else if ( $month_now <= 6 ) { |
|
| 790 | + } else if ($month_now <= 6) { |
|
| 791 | 791 | |
| 792 | 792 | $dates['m_start'] = 1; |
| 793 | 793 | $dates['m_end'] = 3; |
| 794 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 794 | + $dates['year'] = date('Y', $current_time); |
|
| 795 | 795 | |
| 796 | - } else if ( $month_now <= 9 ) { |
|
| 796 | + } else if ($month_now <= 9) { |
|
| 797 | 797 | |
| 798 | 798 | $dates['m_start'] = 4; |
| 799 | 799 | $dates['m_end'] = 6; |
| 800 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 800 | + $dates['year'] = date('Y', $current_time); |
|
| 801 | 801 | |
| 802 | 802 | } else { |
| 803 | 803 | |
| 804 | 804 | $dates['m_start'] = 7; |
| 805 | 805 | $dates['m_end'] = 9; |
| 806 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 806 | + $dates['year'] = date('Y', $current_time); |
|
| 807 | 807 | |
| 808 | 808 | } |
| 809 | 809 | break; |
@@ -812,14 +812,14 @@ discard block |
||
| 812 | 812 | $dates['day'] = null; |
| 813 | 813 | $dates['m_start'] = null; |
| 814 | 814 | $dates['m_end'] = null; |
| 815 | - $dates['year'] = date( 'Y', $current_time ); |
|
| 815 | + $dates['year'] = date('Y', $current_time); |
|
| 816 | 816 | break; |
| 817 | 817 | |
| 818 | 818 | case 'last_year' : |
| 819 | 819 | $dates['day'] = null; |
| 820 | 820 | $dates['m_start'] = null; |
| 821 | 821 | $dates['m_end'] = null; |
| 822 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
| 822 | + $dates['year'] = date('Y', $current_time) - 1; |
|
| 823 | 823 | break; |
| 824 | 824 | |
| 825 | 825 | endswitch; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | * @param object $dates The dates used for retreiving earnings/donations |
| 834 | 834 | */ |
| 835 | 835 | |
| 836 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
| 836 | + return apply_filters('give_api_stat_dates', $dates); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -848,11 +848,11 @@ discard block |
||
| 848 | 848 | * |
| 849 | 849 | * @return array $customers Multidimensional array of the customers |
| 850 | 850 | */ |
| 851 | - public function get_customers( $customer = null ) { |
|
| 851 | + public function get_customers($customer = null) { |
|
| 852 | 852 | |
| 853 | 853 | $customers = array(); |
| 854 | 854 | $error = array(); |
| 855 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
| 855 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
| 856 | 856 | return $customers; |
| 857 | 857 | } |
| 858 | 858 | |
@@ -860,68 +860,68 @@ discard block |
||
| 860 | 860 | |
| 861 | 861 | $paged = $this->get_paged(); |
| 862 | 862 | $per_page = $this->per_page(); |
| 863 | - $offset = $per_page * ( $paged - 1 ); |
|
| 863 | + $offset = $per_page * ($paged - 1); |
|
| 864 | 864 | |
| 865 | - if ( is_numeric( $customer ) ) { |
|
| 865 | + if (is_numeric($customer)) { |
|
| 866 | 866 | $field = 'id'; |
| 867 | 867 | } else { |
| 868 | 868 | $field = 'email'; |
| 869 | 869 | } |
| 870 | 870 | |
| 871 | - $customer_query = Give()->customers->get_customers( array( |
|
| 871 | + $customer_query = Give()->customers->get_customers(array( |
|
| 872 | 872 | 'number' => $per_page, |
| 873 | 873 | 'offset' => $offset, |
| 874 | 874 | $field => $customer |
| 875 | - ) ); |
|
| 875 | + )); |
|
| 876 | 876 | $customer_count = 0; |
| 877 | 877 | |
| 878 | - if ( $customer_query ) { |
|
| 878 | + if ($customer_query) { |
|
| 879 | 879 | |
| 880 | - foreach ( $customer_query as $customer_obj ) { |
|
| 880 | + foreach ($customer_query as $customer_obj) { |
|
| 881 | 881 | |
| 882 | - $names = explode( ' ', $customer_obj->name ); |
|
| 883 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
| 882 | + $names = explode(' ', $customer_obj->name); |
|
| 883 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
| 884 | 884 | $last_name = ''; |
| 885 | - if ( ! empty( $names[1] ) ) { |
|
| 886 | - unset( $names[0] ); |
|
| 887 | - $last_name = implode( ' ', $names ); |
|
| 885 | + if ( ! empty($names[1])) { |
|
| 886 | + unset($names[0]); |
|
| 887 | + $last_name = implode(' ', $names); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
| 891 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
| 892 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
| 893 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
| 894 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
| 895 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
| 896 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
| 890 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
| 891 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
| 892 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
| 893 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
| 894 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
| 895 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
| 896 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
| 897 | 897 | |
| 898 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
| 898 | + if ( ! empty($customer_obj->user_id)) { |
|
| 899 | 899 | |
| 900 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
| 900 | + $user_data = get_userdata($customer_obj->user_id); |
|
| 901 | 901 | |
| 902 | 902 | // Customer with registered account |
| 903 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
| 904 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
| 905 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
| 903 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
| 904 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
| 905 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
| 906 | 906 | |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
| 910 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
| 909 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
| 910 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
| 911 | 911 | |
| 912 | - $customer_count ++; |
|
| 912 | + $customer_count++; |
|
| 913 | 913 | |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | - } elseif ( $customer ) { |
|
| 916 | + } elseif ($customer) { |
|
| 917 | 917 | |
| 918 | - $error['error'] = sprintf( __( 'Donor %s not found!', 'give' ), $customer ); |
|
| 918 | + $error['error'] = sprintf(__('Donor %s not found!', 'give'), $customer); |
|
| 919 | 919 | |
| 920 | 920 | return $error; |
| 921 | 921 | |
| 922 | 922 | } else { |
| 923 | 923 | |
| 924 | - $error['error'] = __( 'No donors found!', 'give' ); |
|
| 924 | + $error['error'] = __('No donors found!', 'give'); |
|
| 925 | 925 | |
| 926 | 926 | return $error; |
| 927 | 927 | |
@@ -940,36 +940,36 @@ discard block |
||
| 940 | 940 | * |
| 941 | 941 | * @return array $customers Multidimensional array of the forms |
| 942 | 942 | */ |
| 943 | - public function get_forms( $form = null ) { |
|
| 943 | + public function get_forms($form = null) { |
|
| 944 | 944 | |
| 945 | 945 | $forms = array(); |
| 946 | 946 | $error = array(); |
| 947 | 947 | |
| 948 | - if ( $form == null ) { |
|
| 948 | + if ($form == null) { |
|
| 949 | 949 | $forms['forms'] = array(); |
| 950 | 950 | |
| 951 | - $form_list = get_posts( array( |
|
| 951 | + $form_list = get_posts(array( |
|
| 952 | 952 | 'post_type' => 'give_forms', |
| 953 | 953 | 'posts_per_page' => $this->per_page(), |
| 954 | 954 | 'suppress_filters' => true, |
| 955 | 955 | 'paged' => $this->get_paged() |
| 956 | - ) ); |
|
| 956 | + )); |
|
| 957 | 957 | |
| 958 | - if ( $form_list ) { |
|
| 958 | + if ($form_list) { |
|
| 959 | 959 | $i = 0; |
| 960 | - foreach ( $form_list as $form_info ) { |
|
| 961 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
| 962 | - $i ++; |
|
| 960 | + foreach ($form_list as $form_info) { |
|
| 961 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
| 962 | + $i++; |
|
| 963 | 963 | } |
| 964 | 964 | } |
| 965 | 965 | } else { |
| 966 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
| 967 | - $form_info = get_post( $form ); |
|
| 966 | + if (get_post_type($form) == 'give_forms') { |
|
| 967 | + $form_info = get_post($form); |
|
| 968 | 968 | |
| 969 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
| 969 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
| 970 | 970 | |
| 971 | 971 | } else { |
| 972 | - $error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $form ); |
|
| 972 | + $error['error'] = sprintf(__('Form %s not found!', 'give'), $form); |
|
| 973 | 973 | |
| 974 | 974 | return $error; |
| 975 | 975 | } |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | * |
| 988 | 988 | * @return array Array of post data to return back in the API |
| 989 | 989 | */ |
| 990 | - private function get_form_data( $form_info ) { |
|
| 990 | + private function get_form_data($form_info) { |
|
| 991 | 991 | |
| 992 | 992 | $form = array(); |
| 993 | 993 | |
@@ -997,46 +997,46 @@ discard block |
||
| 997 | 997 | $form['info']['create_date'] = $form_info->post_date; |
| 998 | 998 | $form['info']['modified_date'] = $form_info->post_modified; |
| 999 | 999 | $form['info']['status'] = $form_info->post_status; |
| 1000 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
| 1001 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
| 1002 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
| 1000 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
| 1001 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
| 1002 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
| 1003 | 1003 | |
| 1004 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
| 1005 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
| 1006 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1004 | + if (give_get_option('enable_categories') == 'on') { |
|
| 1005 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
| 1006 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1007 | 1007 | } |
| 1008 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
| 1009 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
| 1008 | + if (give_get_option('enable_tags') == 'on') { |
|
| 1009 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
| 1013 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
| 1014 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
| 1015 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
| 1016 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
| 1012 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
| 1013 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
| 1014 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
| 1015 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
| 1016 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | $counter = 0; |
| 1020 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
| 1021 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
| 1022 | - $counter ++; |
|
| 1020 | + if (give_has_variable_prices($form_info->ID)) { |
|
| 1021 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
| 1022 | + $counter++; |
|
| 1023 | 1023 | //muli-level item |
| 1024 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
| 1025 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
| 1024 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
| 1025 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
| 1026 | 1026 | |
| 1027 | 1027 | } |
| 1028 | 1028 | } else { |
| 1029 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
| 1029 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
| 1032 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
| 1033 | 1033 | |
| 1034 | 1034 | //Sensitive data here |
| 1035 | - do_action( 'give_api_sensitive_data' ); |
|
| 1035 | + do_action('give_api_sensitive_data'); |
|
| 1036 | 1036 | |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - return apply_filters( 'give_api_forms_form', $form ); |
|
| 1039 | + return apply_filters('give_api_forms_form', $form); |
|
| 1040 | 1040 | |
| 1041 | 1041 | } |
| 1042 | 1042 | |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | * |
| 1052 | 1052 | * @return array |
| 1053 | 1053 | */ |
| 1054 | - public function get_stats( $args = array() ) { |
|
| 1054 | + public function get_stats($args = array()) { |
|
| 1055 | 1055 | $defaults = array( |
| 1056 | 1056 | 'type' => null, |
| 1057 | 1057 | 'form' => null, |
@@ -1060,9 +1060,9 @@ discard block |
||
| 1060 | 1060 | 'enddate' => null |
| 1061 | 1061 | ); |
| 1062 | 1062 | |
| 1063 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1063 | + $args = wp_parse_args($args, $defaults); |
|
| 1064 | 1064 | |
| 1065 | - $dates = $this->get_dates( $args ); |
|
| 1065 | + $dates = $this->get_dates($args); |
|
| 1066 | 1066 | |
| 1067 | 1067 | $stats = array(); |
| 1068 | 1068 | $earnings = array( |
@@ -1071,43 +1071,43 @@ discard block |
||
| 1071 | 1071 | $sales = array( |
| 1072 | 1072 | 'donations' => array() |
| 1073 | 1073 | ); |
| 1074 | - $error = array(); |
|
| 1074 | + $error = array(); |
|
| 1075 | 1075 | |
| 1076 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1076 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1077 | 1077 | return $stats; |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if ( $args['type'] == 'donations' ) { |
|
| 1080 | + if ($args['type'] == 'donations') { |
|
| 1081 | 1081 | |
| 1082 | - if ( $args['form'] == null ) { |
|
| 1083 | - if ( $args['date'] == null ) { |
|
| 1082 | + if ($args['form'] == null) { |
|
| 1083 | + if ($args['date'] == null) { |
|
| 1084 | 1084 | $sales = $this->get_default_sales_stats(); |
| 1085 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1085 | + } elseif ($args['date'] === 'range') { |
|
| 1086 | 1086 | // Return sales for a date range |
| 1087 | 1087 | |
| 1088 | 1088 | // Ensure the end date is later than the start date |
| 1089 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1090 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
| 1089 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1090 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | // Ensure both the start and end date are specified |
| 1094 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1095 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
| 1094 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1095 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | $total = 0; |
| 1099 | 1099 | |
| 1100 | 1100 | // Loop through the years |
| 1101 | 1101 | $y = $dates['year']; |
| 1102 | - while ( $y <= $dates['year_end'] ) : |
|
| 1102 | + while ($y <= $dates['year_end']) : |
|
| 1103 | 1103 | |
| 1104 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1104 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1105 | 1105 | $month_start = $dates['m_start']; |
| 1106 | 1106 | $month_end = $dates['m_end']; |
| 1107 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1107 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1108 | 1108 | $month_start = $dates['m_start']; |
| 1109 | 1109 | $month_end = 12; |
| 1110 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1110 | + } elseif ($y == $dates['year_end']) { |
|
| 1111 | 1111 | $month_start = 1; |
| 1112 | 1112 | $month_end = $dates['m_end']; |
| 1113 | 1113 | } else { |
@@ -1116,109 +1116,109 @@ discard block |
||
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | $i = $month_start; |
| 1119 | - while ( $i <= $month_end ) : |
|
| 1119 | + while ($i <= $month_end) : |
|
| 1120 | 1120 | |
| 1121 | - if ( $i == $dates['m_start'] ) { |
|
| 1121 | + if ($i == $dates['m_start']) { |
|
| 1122 | 1122 | $d = $dates['day_start']; |
| 1123 | 1123 | } else { |
| 1124 | 1124 | $d = 1; |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | - if ( $i == $dates['m_end'] ) { |
|
| 1127 | + if ($i == $dates['m_end']) { |
|
| 1128 | 1128 | $num_of_days = $dates['day_end']; |
| 1129 | 1129 | } else { |
| 1130 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1130 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | - while ( $d <= $num_of_days ) : |
|
| 1134 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
| 1135 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1136 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
| 1137 | - $sales['sales'][ $date_key ] = 0; |
|
| 1133 | + while ($d <= $num_of_days) : |
|
| 1134 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
| 1135 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1136 | + if ( ! isset($sales['sales'][$date_key])) { |
|
| 1137 | + $sales['sales'][$date_key] = 0; |
|
| 1138 | 1138 | } |
| 1139 | - $sales['sales'][ $date_key ] += $sale_count; |
|
| 1139 | + $sales['sales'][$date_key] += $sale_count; |
|
| 1140 | 1140 | $total += $sale_count; |
| 1141 | - $d ++; |
|
| 1141 | + $d++; |
|
| 1142 | 1142 | endwhile; |
| 1143 | - $i ++; |
|
| 1143 | + $i++; |
|
| 1144 | 1144 | endwhile; |
| 1145 | 1145 | |
| 1146 | - $y ++; |
|
| 1146 | + $y++; |
|
| 1147 | 1147 | endwhile; |
| 1148 | 1148 | |
| 1149 | 1149 | $sales['totals'] = $total; |
| 1150 | 1150 | } else { |
| 1151 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1151 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1152 | 1152 | $sales_count = 0; |
| 1153 | 1153 | |
| 1154 | 1154 | // Loop through the months |
| 1155 | 1155 | $month = $dates['m_start']; |
| 1156 | 1156 | |
| 1157 | - while ( $month <= $dates['m_end'] ) : |
|
| 1158 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
| 1159 | - $month ++; |
|
| 1157 | + while ($month <= $dates['m_end']) : |
|
| 1158 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
| 1159 | + $month++; |
|
| 1160 | 1160 | endwhile; |
| 1161 | 1161 | |
| 1162 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
| 1162 | + $sales['donations'][$args['date']] = $sales_count; |
|
| 1163 | 1163 | } else { |
| 1164 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1164 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1165 | 1165 | } |
| 1166 | 1166 | } |
| 1167 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1168 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
| 1167 | + } elseif ($args['form'] == 'all') { |
|
| 1168 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
| 1169 | 1169 | $i = 0; |
| 1170 | - foreach ( $forms as $form_info ) { |
|
| 1171 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
| 1172 | - $i ++; |
|
| 1170 | + foreach ($forms as $form_info) { |
|
| 1171 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
| 1172 | + $i++; |
|
| 1173 | 1173 | } |
| 1174 | 1174 | } else { |
| 1175 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1176 | - $form_info = get_post( $args['form'] ); |
|
| 1177 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
| 1175 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1176 | + $form_info = get_post($args['form']); |
|
| 1177 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
| 1178 | 1178 | } else { |
| 1179 | - $error['error'] = sprintf( __( 'Product %s not found!', 'give' ), $args['form'] ); |
|
| 1179 | + $error['error'] = sprintf(__('Product %s not found!', 'give'), $args['form']); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | - if ( ! empty( $error ) ) { |
|
| 1183 | + if ( ! empty($error)) { |
|
| 1184 | 1184 | return $error; |
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | return $sales; |
| 1188 | 1188 | |
| 1189 | - } elseif ( $args['type'] == 'earnings' ) { |
|
| 1190 | - if ( $args['form'] == null ) { |
|
| 1191 | - if ( $args['date'] == null ) { |
|
| 1189 | + } elseif ($args['type'] == 'earnings') { |
|
| 1190 | + if ($args['form'] == null) { |
|
| 1191 | + if ($args['date'] == null) { |
|
| 1192 | 1192 | $earnings = $this->get_default_earnings_stats(); |
| 1193 | - } elseif ( $args['date'] === 'range' ) { |
|
| 1193 | + } elseif ($args['date'] === 'range') { |
|
| 1194 | 1194 | // Return sales for a date range |
| 1195 | 1195 | |
| 1196 | 1196 | // Ensure the end date is later than the start date |
| 1197 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
| 1198 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
| 1197 | + if ($args['enddate'] < $args['startdate']) { |
|
| 1198 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | // Ensure both the start and end date are specified |
| 1202 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
| 1203 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
| 1202 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
| 1203 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | $total = (float) 0.00; |
| 1207 | 1207 | |
| 1208 | 1208 | // Loop through the years |
| 1209 | 1209 | $y = $dates['year']; |
| 1210 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
| 1210 | + if ( ! isset($earnings['earnings'])) { |
|
| 1211 | 1211 | $earnings['earnings'] = array(); |
| 1212 | 1212 | } |
| 1213 | - while ( $y <= $dates['year_end'] ) : |
|
| 1213 | + while ($y <= $dates['year_end']) : |
|
| 1214 | 1214 | |
| 1215 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
| 1215 | + if ($dates['year'] == $dates['year_end']) { |
|
| 1216 | 1216 | $month_start = $dates['m_start']; |
| 1217 | 1217 | $month_end = $dates['m_end']; |
| 1218 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
| 1218 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
| 1219 | 1219 | $month_start = $dates['m_start']; |
| 1220 | 1220 | $month_end = 12; |
| 1221 | - } elseif ( $y == $dates['year_end'] ) { |
|
| 1221 | + } elseif ($y == $dates['year_end']) { |
|
| 1222 | 1222 | $month_start = 1; |
| 1223 | 1223 | $month_end = $dates['m_end']; |
| 1224 | 1224 | } else { |
@@ -1227,88 +1227,88 @@ discard block |
||
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | $i = $month_start; |
| 1230 | - while ( $i <= $month_end ) : |
|
| 1230 | + while ($i <= $month_end) : |
|
| 1231 | 1231 | |
| 1232 | - if ( $i == $dates['m_start'] ) { |
|
| 1232 | + if ($i == $dates['m_start']) { |
|
| 1233 | 1233 | $d = $dates['day_start']; |
| 1234 | 1234 | } else { |
| 1235 | 1235 | $d = 1; |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | - if ( $i == $dates['m_end'] ) { |
|
| 1238 | + if ($i == $dates['m_end']) { |
|
| 1239 | 1239 | $num_of_days = $dates['day_end']; |
| 1240 | 1240 | } else { |
| 1241 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
| 1241 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | - while ( $d <= $num_of_days ) : |
|
| 1245 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
| 1246 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
| 1247 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
| 1248 | - $earnings['earnings'][ $date_key ] = 0; |
|
| 1244 | + while ($d <= $num_of_days) : |
|
| 1245 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
| 1246 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
| 1247 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
| 1248 | + $earnings['earnings'][$date_key] = 0; |
|
| 1249 | 1249 | } |
| 1250 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
| 1250 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
| 1251 | 1251 | $total += $earnings_stat; |
| 1252 | - $d ++; |
|
| 1252 | + $d++; |
|
| 1253 | 1253 | endwhile; |
| 1254 | 1254 | |
| 1255 | - $i ++; |
|
| 1255 | + $i++; |
|
| 1256 | 1256 | endwhile; |
| 1257 | 1257 | |
| 1258 | - $y ++; |
|
| 1258 | + $y++; |
|
| 1259 | 1259 | endwhile; |
| 1260 | 1260 | |
| 1261 | 1261 | $earnings['totals'] = $total; |
| 1262 | 1262 | } else { |
| 1263 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
| 1263 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
| 1264 | 1264 | $earnings_count = (float) 0.00; |
| 1265 | 1265 | |
| 1266 | 1266 | // Loop through the months |
| 1267 | 1267 | $month = $dates['m_start']; |
| 1268 | 1268 | |
| 1269 | - while ( $month <= $dates['m_end'] ) : |
|
| 1270 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
| 1271 | - $month ++; |
|
| 1269 | + while ($month <= $dates['m_end']) : |
|
| 1270 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
| 1271 | + $month++; |
|
| 1272 | 1272 | endwhile; |
| 1273 | 1273 | |
| 1274 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
| 1274 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
| 1275 | 1275 | } else { |
| 1276 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
| 1276 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | } |
| 1279 | - } elseif ( $args['form'] == 'all' ) { |
|
| 1280 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
| 1279 | + } elseif ($args['form'] == 'all') { |
|
| 1280 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
| 1281 | 1281 | |
| 1282 | 1282 | $i = 0; |
| 1283 | - foreach ( $forms as $form_info ) { |
|
| 1284 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
| 1285 | - $i ++; |
|
| 1283 | + foreach ($forms as $form_info) { |
|
| 1284 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
| 1285 | + $i++; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | } else { |
| 1288 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
| 1289 | - $form_info = get_post( $args['form'] ); |
|
| 1290 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
| 1288 | + if (get_post_type($args['form']) == 'give_forms') { |
|
| 1289 | + $form_info = get_post($args['form']); |
|
| 1290 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
| 1291 | 1291 | } else { |
| 1292 | - $error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $args['form'] ); |
|
| 1292 | + $error['error'] = sprintf(__('Form %s not found!', 'give'), $args['form']); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | - if ( ! empty( $error ) ) { |
|
| 1296 | + if ( ! empty($error)) { |
|
| 1297 | 1297 | return $error; |
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | return $earnings; |
| 1301 | - } elseif ( $args['type'] == 'donors' ) { |
|
| 1301 | + } elseif ($args['type'] == 'donors') { |
|
| 1302 | 1302 | $customers = new Give_DB_Customers(); |
| 1303 | 1303 | $stats['donations']['total_donors'] = $customers->count(); |
| 1304 | 1304 | |
| 1305 | 1305 | return $stats; |
| 1306 | 1306 | |
| 1307 | - } elseif ( empty( $args['type'] ) ) { |
|
| 1308 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
| 1309 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
| 1307 | + } elseif (empty($args['type'])) { |
|
| 1308 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
| 1309 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
| 1310 | 1310 | |
| 1311 | - return array( 'stats' => $stats ); |
|
| 1311 | + return array('stats' => $stats); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | } |
| 1314 | 1314 | |
@@ -1324,71 +1324,71 @@ discard block |
||
| 1324 | 1324 | |
| 1325 | 1325 | $sales = array(); |
| 1326 | 1326 | |
| 1327 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
| 1327 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
| 1328 | 1328 | return $sales; |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
| 1331 | + if (isset($wp_query->query_vars['id'])) { |
|
| 1332 | 1332 | $query = array(); |
| 1333 | - $query[] = give_get_payment_by( 'id', $wp_query->query_vars['id'] ); |
|
| 1334 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
| 1333 | + $query[] = give_get_payment_by('id', $wp_query->query_vars['id']); |
|
| 1334 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
| 1335 | 1335 | $query = array(); |
| 1336 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
| 1337 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
| 1338 | - $query = give_get_payments( array( |
|
| 1336 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
| 1337 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
| 1338 | + $query = give_get_payments(array( |
|
| 1339 | 1339 | 'meta_key' => '_give_payment_user_email', |
| 1340 | 1340 | 'meta_value' => $wp_query->query_vars['email'], |
| 1341 | 1341 | 'number' => $this->per_page(), |
| 1342 | 1342 | 'page' => $this->get_paged(), |
| 1343 | 1343 | 'status' => 'publish' |
| 1344 | - ) ); |
|
| 1344 | + )); |
|
| 1345 | 1345 | } else { |
| 1346 | - $query = give_get_payments( array( |
|
| 1346 | + $query = give_get_payments(array( |
|
| 1347 | 1347 | 'number' => $this->per_page(), |
| 1348 | 1348 | 'page' => $this->get_paged(), |
| 1349 | 1349 | 'status' => 'publish' |
| 1350 | - ) ); |
|
| 1350 | + )); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | - if ( $query ) { |
|
| 1353 | + if ($query) { |
|
| 1354 | 1354 | $i = 0; |
| 1355 | - foreach ( $query as $payment ) { |
|
| 1356 | - $payment_meta = give_get_payment_meta( $payment->ID ); |
|
| 1357 | - $user_info = give_get_payment_meta_user_info( $payment->ID ); |
|
| 1358 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
| 1359 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
| 1360 | - |
|
| 1361 | - $sales['donations'][ $i ]['ID'] = give_get_payment_number( $payment->ID ); |
|
| 1362 | - $sales['donations'][ $i ]['transaction_id'] = give_get_payment_transaction_id( $payment->ID ); |
|
| 1363 | - $sales['donations'][ $i ]['key'] = give_get_payment_key( $payment->ID ); |
|
| 1364 | - $sales['donations'][ $i ]['total'] = give_get_payment_amount( $payment->ID ); |
|
| 1365 | - $sales['donations'][ $i ]['gateway'] = give_get_payment_gateway( $payment->ID ); |
|
| 1366 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
| 1367 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
| 1368 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
| 1369 | - $sales['donations'][ $i ]['email'] = give_get_payment_user_email( $payment->ID ); |
|
| 1370 | - $sales['donations'][ $i ]['date'] = $payment->post_date; |
|
| 1371 | - |
|
| 1372 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1373 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
| 1374 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
| 1375 | - |
|
| 1376 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
| 1377 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
| 1378 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
| 1379 | - |
|
| 1380 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1381 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
| 1382 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
| 1383 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
| 1384 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
| 1385 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
| 1355 | + foreach ($query as $payment) { |
|
| 1356 | + $payment_meta = give_get_payment_meta($payment->ID); |
|
| 1357 | + $user_info = give_get_payment_meta_user_info($payment->ID); |
|
| 1358 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
| 1359 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
| 1360 | + |
|
| 1361 | + $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID); |
|
| 1362 | + $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID); |
|
| 1363 | + $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID); |
|
| 1364 | + $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID); |
|
| 1365 | + $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID); |
|
| 1366 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
| 1367 | + $sales['donations'][$i]['fname'] = $first_name; |
|
| 1368 | + $sales['donations'][$i]['lname'] = $last_name; |
|
| 1369 | + $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID); |
|
| 1370 | + $sales['donations'][$i]['date'] = $payment->post_date; |
|
| 1371 | + |
|
| 1372 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
| 1373 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
| 1374 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
| 1375 | + |
|
| 1376 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
| 1377 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
| 1378 | + $sales['donations'][$i]['form']['price'] = $price; |
|
| 1379 | + |
|
| 1380 | + if (give_has_variable_prices($form_id)) { |
|
| 1381 | + if (isset($payment_meta['price_id'])) { |
|
| 1382 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
| 1383 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
| 1384 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
| 1385 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
| 1386 | 1386 | |
| 1387 | 1387 | } |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | //Add custom meta to API |
| 1391 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
| 1391 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
| 1392 | 1392 | |
| 1393 | 1393 | $exceptions = array( |
| 1394 | 1394 | 'form_title', |
@@ -1401,19 +1401,19 @@ discard block |
||
| 1401 | 1401 | ); |
| 1402 | 1402 | |
| 1403 | 1403 | //Don't clutter up results with dupes |
| 1404 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
| 1404 | + if (in_array($meta_key, $exceptions)) { |
|
| 1405 | 1405 | continue; |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
| 1408 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
| 1409 | 1409 | |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | - $i ++; |
|
| 1412 | + $i++; |
|
| 1413 | 1413 | } |
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
| 1416 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
@@ -1428,9 +1428,9 @@ discard block |
||
| 1428 | 1428 | public function get_output_format() { |
| 1429 | 1429 | global $wp_query; |
| 1430 | 1430 | |
| 1431 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1431 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
| 1432 | 1432 | |
| 1433 | - return apply_filters( 'give_api_output_format', $format ); |
|
| 1433 | + return apply_filters('give_api_output_format', $format); |
|
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | 1436 | |
@@ -1446,8 +1446,8 @@ discard block |
||
| 1446 | 1446 | * |
| 1447 | 1447 | * @return void |
| 1448 | 1448 | */ |
| 1449 | - private function log_request( $data = array() ) { |
|
| 1450 | - if ( ! $this->log_requests ) { |
|
| 1449 | + private function log_request($data = array()) { |
|
| 1450 | + if ( ! $this->log_requests) { |
|
| 1451 | 1451 | return; |
| 1452 | 1452 | } |
| 1453 | 1453 | |
@@ -1455,36 +1455,36 @@ discard block |
||
| 1455 | 1455 | |
| 1456 | 1456 | $query = array( |
| 1457 | 1457 | 'give-api' => $wp_query->query_vars['give-api'], |
| 1458 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1459 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1460 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
| 1461 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
| 1462 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
| 1463 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
| 1464 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
| 1465 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
| 1466 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
| 1467 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
| 1468 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1469 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
| 1458 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1459 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1460 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
| 1461 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
| 1462 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
| 1463 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
| 1464 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
| 1465 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
| 1466 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
| 1467 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
| 1468 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
| 1469 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
| 1470 | 1470 | ); |
| 1471 | 1471 | |
| 1472 | 1472 | $log_data = array( |
| 1473 | 1473 | 'log_type' => 'api_request', |
| 1474 | - 'post_excerpt' => http_build_query( $query ), |
|
| 1475 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
| 1474 | + 'post_excerpt' => http_build_query($query), |
|
| 1475 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
| 1476 | 1476 | ); |
| 1477 | 1477 | |
| 1478 | 1478 | $log_meta = array( |
| 1479 | 1479 | 'request_ip' => give_get_ip(), |
| 1480 | 1480 | 'user' => $this->user_id, |
| 1481 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
| 1482 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
| 1481 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
| 1482 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
| 1483 | 1483 | 'time' => $data['request_speed'], |
| 1484 | 1484 | 'version' => $this->get_queried_version() |
| 1485 | 1485 | ); |
| 1486 | 1486 | |
| 1487 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
| 1487 | + $give_logs->insert_log($log_data, $log_meta); |
|
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | |
@@ -1508,32 +1508,32 @@ discard block |
||
| 1508 | 1508 | * |
| 1509 | 1509 | * @param int $status_code |
| 1510 | 1510 | */ |
| 1511 | - public function output( $status_code = 200 ) { |
|
| 1511 | + public function output($status_code = 200) { |
|
| 1512 | 1512 | global $wp_query; |
| 1513 | 1513 | |
| 1514 | 1514 | $format = $this->get_output_format(); |
| 1515 | 1515 | |
| 1516 | - status_header( $status_code ); |
|
| 1516 | + status_header($status_code); |
|
| 1517 | 1517 | |
| 1518 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
| 1518 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
| 1519 | 1519 | |
| 1520 | - switch ( $format ) : |
|
| 1520 | + switch ($format) : |
|
| 1521 | 1521 | |
| 1522 | 1522 | case 'xml' : |
| 1523 | 1523 | |
| 1524 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
| 1525 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
| 1524 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
| 1525 | + $xml = Array2XML::createXML('give', $this->data); |
|
| 1526 | 1526 | echo $xml->saveXML(); |
| 1527 | 1527 | |
| 1528 | 1528 | break; |
| 1529 | 1529 | |
| 1530 | 1530 | case 'json' : |
| 1531 | 1531 | |
| 1532 | - header( 'Content-Type: application/json' ); |
|
| 1533 | - if ( ! empty( $this->pretty_print ) ) { |
|
| 1534 | - echo json_encode( $this->data, $this->pretty_print ); |
|
| 1532 | + header('Content-Type: application/json'); |
|
| 1533 | + if ( ! empty($this->pretty_print)) { |
|
| 1534 | + echo json_encode($this->data, $this->pretty_print); |
|
| 1535 | 1535 | } else { |
| 1536 | - echo json_encode( $this->data ); |
|
| 1536 | + echo json_encode($this->data); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | break; |
@@ -1542,13 +1542,13 @@ discard block |
||
| 1542 | 1542 | default : |
| 1543 | 1543 | |
| 1544 | 1544 | // Allow other formats to be added via extensions |
| 1545 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
| 1545 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
| 1546 | 1546 | |
| 1547 | 1547 | break; |
| 1548 | 1548 | |
| 1549 | 1549 | endswitch; |
| 1550 | 1550 | |
| 1551 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
| 1551 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
| 1552 | 1552 | |
| 1553 | 1553 | give_die(); |
| 1554 | 1554 | } |
@@ -1565,37 +1565,37 @@ discard block |
||
| 1565 | 1565 | * |
| 1566 | 1566 | * @return void |
| 1567 | 1567 | */ |
| 1568 | - function user_key_field( $user ) { |
|
| 1568 | + function user_key_field($user) { |
|
| 1569 | 1569 | |
| 1570 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
| 1571 | - $user = get_userdata( $user->ID ); |
|
| 1570 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
| 1571 | + $user = get_userdata($user->ID); |
|
| 1572 | 1572 | ?> |
| 1573 | 1573 | <table class="form-table"> |
| 1574 | 1574 | <tbody> |
| 1575 | 1575 | <tr> |
| 1576 | 1576 | <th> |
| 1577 | - <?php esc_attr_e( 'Give API Keys', 'give' ); ?> |
|
| 1577 | + <?php esc_attr_e('Give API Keys', 'give'); ?> |
|
| 1578 | 1578 | </th> |
| 1579 | 1579 | <td> |
| 1580 | 1580 | <?php |
| 1581 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
| 1582 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
| 1581 | + $public_key = $this->get_user_public_key($user->ID); |
|
| 1582 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
| 1583 | 1583 | ?> |
| 1584 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
| 1584 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
| 1585 | 1585 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0" /> |
| 1586 | - <span class="description"><?php esc_attr_e( 'Generate API Key', 'give' ); ?></span> |
|
| 1586 | + <span class="description"><?php esc_attr_e('Generate API Key', 'give'); ?></span> |
|
| 1587 | 1587 | <?php } else { ?> |
| 1588 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> </strong> |
|
| 1589 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" /> |
|
| 1588 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> </strong> |
|
| 1589 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>" /> |
|
| 1590 | 1590 | <br /> |
| 1591 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Secret key:', 'give' ); ?> </strong> |
|
| 1592 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>" /> |
|
| 1591 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Secret key:', 'give'); ?> </strong> |
|
| 1592 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>" /> |
|
| 1593 | 1593 | <br /> |
| 1594 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Token:', 'give' ); ?> </strong> |
|
| 1595 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>" /> |
|
| 1594 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Token:', 'give'); ?> </strong> |
|
| 1595 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>" /> |
|
| 1596 | 1596 | <br /> |
| 1597 | 1597 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0" /> |
| 1598 | - <span class="description"><label for="give_set_api_key"><?php esc_attr_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
| 1598 | + <span class="description"><label for="give_set_api_key"><?php esc_attr_e('Revoke API Keys', 'give'); ?></label></span> |
|
| 1599 | 1599 | <?php } ?> |
| 1600 | 1600 | </td> |
| 1601 | 1601 | </tr> |
@@ -1614,53 +1614,53 @@ discard block |
||
| 1614 | 1614 | * |
| 1615 | 1615 | * @return void |
| 1616 | 1616 | */ |
| 1617 | - public function process_api_key( $args ) { |
|
| 1617 | + public function process_api_key($args) { |
|
| 1618 | 1618 | |
| 1619 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
| 1619 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
| 1620 | 1620 | |
| 1621 | - wp_die( esc_attr__( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 1621 | + wp_die(esc_attr__('Nonce verification failed', 'give'), __('Error', 'give'), array('response' => 403)); |
|
| 1622 | 1622 | |
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | - if ( empty( $args['user_id'] ) ) { |
|
| 1626 | - wp_die( esc_attr__( 'User ID Required', 'give' ), esc_attr__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
| 1625 | + if (empty($args['user_id'])) { |
|
| 1626 | + wp_die(esc_attr__('User ID Required', 'give'), esc_attr__('Error', 'give'), array('response' => 401)); |
|
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | - if ( is_numeric( $args['user_id'] ) ) { |
|
| 1630 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
| 1629 | + if (is_numeric($args['user_id'])) { |
|
| 1630 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
| 1631 | 1631 | } else { |
| 1632 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
| 1632 | + $userdata = get_user_by('login', $args['user_id']); |
|
| 1633 | 1633 | $user_id = $userdata->ID; |
| 1634 | 1634 | } |
| 1635 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
| 1635 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
| 1636 | 1636 | |
| 1637 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1638 | - wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 1639 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
| 1640 | - wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 1637 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
| 1638 | + wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403)); |
|
| 1639 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
| 1640 | + wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403)); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | |
| 1643 | - switch ( $process ) { |
|
| 1643 | + switch ($process) { |
|
| 1644 | 1644 | case 'generate': |
| 1645 | - if ( $this->generate_api_key( $user_id ) ) { |
|
| 1646 | - delete_transient( 'give-total-api-keys' ); |
|
| 1647 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1645 | + if ($this->generate_api_key($user_id)) { |
|
| 1646 | + delete_transient('give-total-api-keys'); |
|
| 1647 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1648 | 1648 | exit(); |
| 1649 | 1649 | } else { |
| 1650 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1650 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1651 | 1651 | exit(); |
| 1652 | 1652 | } |
| 1653 | 1653 | break; |
| 1654 | 1654 | case 'regenerate': |
| 1655 | - $this->generate_api_key( $user_id, true ); |
|
| 1656 | - delete_transient( 'give-total-api-keys' ); |
|
| 1657 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1655 | + $this->generate_api_key($user_id, true); |
|
| 1656 | + delete_transient('give-total-api-keys'); |
|
| 1657 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1658 | 1658 | exit(); |
| 1659 | 1659 | break; |
| 1660 | 1660 | case 'revoke': |
| 1661 | - $this->revoke_api_key( $user_id ); |
|
| 1662 | - delete_transient( 'give-total-api-keys' ); |
|
| 1663 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
| 1661 | + $this->revoke_api_key($user_id); |
|
| 1662 | + delete_transient('give-total-api-keys'); |
|
| 1663 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
| 1664 | 1664 | exit(); |
| 1665 | 1665 | break; |
| 1666 | 1666 | default; |
@@ -1679,34 +1679,34 @@ discard block |
||
| 1679 | 1679 | * |
| 1680 | 1680 | * @return boolean True if (re)generated succesfully, false otherwise. |
| 1681 | 1681 | */ |
| 1682 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
| 1682 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
| 1683 | 1683 | |
| 1684 | - if ( empty( $user_id ) ) { |
|
| 1684 | + if (empty($user_id)) { |
|
| 1685 | 1685 | return false; |
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | - $user = get_userdata( $user_id ); |
|
| 1688 | + $user = get_userdata($user_id); |
|
| 1689 | 1689 | |
| 1690 | - if ( ! $user ) { |
|
| 1690 | + if ( ! $user) { |
|
| 1691 | 1691 | return false; |
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1695 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1694 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1695 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1696 | 1696 | |
| 1697 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
| 1698 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1699 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1697 | + if (empty($public_key) || $regenerate == true) { |
|
| 1698 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1699 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1700 | 1700 | } else { |
| 1701 | 1701 | return false; |
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | - if ( $regenerate == true ) { |
|
| 1705 | - $this->revoke_api_key( $user->ID ); |
|
| 1704 | + if ($regenerate == true) { |
|
| 1705 | + $this->revoke_api_key($user->ID); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1709 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1708 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1709 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1710 | 1710 | |
| 1711 | 1711 | return true; |
| 1712 | 1712 | } |
@@ -1721,26 +1721,26 @@ discard block |
||
| 1721 | 1721 | * |
| 1722 | 1722 | * @return string |
| 1723 | 1723 | */ |
| 1724 | - public function revoke_api_key( $user_id = 0 ) { |
|
| 1724 | + public function revoke_api_key($user_id = 0) { |
|
| 1725 | 1725 | |
| 1726 | - if ( empty( $user_id ) ) { |
|
| 1726 | + if (empty($user_id)) { |
|
| 1727 | 1727 | return false; |
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | - $user = get_userdata( $user_id ); |
|
| 1730 | + $user = get_userdata($user_id); |
|
| 1731 | 1731 | |
| 1732 | - if ( ! $user ) { |
|
| 1732 | + if ( ! $user) { |
|
| 1733 | 1733 | return false; |
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1737 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1738 | - if ( ! empty( $public_key ) ) { |
|
| 1739 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
| 1740 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
| 1741 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
| 1742 | - delete_user_meta( $user_id, $public_key ); |
|
| 1743 | - delete_user_meta( $user_id, $secret_key ); |
|
| 1736 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1737 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1738 | + if ( ! empty($public_key)) { |
|
| 1739 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
| 1740 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
| 1741 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
| 1742 | + delete_user_meta($user_id, $public_key); |
|
| 1743 | + delete_user_meta($user_id, $secret_key); |
|
| 1744 | 1744 | } else { |
| 1745 | 1745 | return false; |
| 1746 | 1746 | } |
@@ -1765,22 +1765,22 @@ discard block |
||
| 1765 | 1765 | * |
| 1766 | 1766 | * @return void |
| 1767 | 1767 | */ |
| 1768 | - public function update_key( $user_id ) { |
|
| 1769 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
| 1768 | + public function update_key($user_id) { |
|
| 1769 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
| 1770 | 1770 | |
| 1771 | - $user = get_userdata( $user_id ); |
|
| 1771 | + $user = get_userdata($user_id); |
|
| 1772 | 1772 | |
| 1773 | - $public_key = $this->get_user_public_key( $user_id ); |
|
| 1774 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
| 1773 | + $public_key = $this->get_user_public_key($user_id); |
|
| 1774 | + $secret_key = $this->get_user_secret_key($user_id); |
|
| 1775 | 1775 | |
| 1776 | - if ( empty( $public_key ) ) { |
|
| 1777 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
| 1778 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
| 1776 | + if (empty($public_key)) { |
|
| 1777 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
| 1778 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
| 1779 | 1779 | |
| 1780 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
| 1781 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
| 1780 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
| 1781 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
| 1782 | 1782 | } else { |
| 1783 | - $this->revoke_api_key( $user_id ); |
|
| 1783 | + $this->revoke_api_key($user_id); |
|
| 1784 | 1784 | } |
| 1785 | 1785 | } |
| 1786 | 1786 | } |
@@ -1795,9 +1795,9 @@ discard block |
||
| 1795 | 1795 | * |
| 1796 | 1796 | * @return string |
| 1797 | 1797 | */ |
| 1798 | - private function generate_public_key( $user_email = '' ) { |
|
| 1799 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1800 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
| 1798 | + private function generate_public_key($user_email = '') { |
|
| 1799 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1800 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
| 1801 | 1801 | return $public; |
| 1802 | 1802 | } |
| 1803 | 1803 | |
@@ -1811,9 +1811,9 @@ discard block |
||
| 1811 | 1811 | * |
| 1812 | 1812 | * @return string |
| 1813 | 1813 | */ |
| 1814 | - private function generate_private_key( $user_id = 0 ) { |
|
| 1815 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 1816 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
| 1814 | + private function generate_private_key($user_id = 0) { |
|
| 1815 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 1816 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
| 1817 | 1817 | |
| 1818 | 1818 | return $secret; |
| 1819 | 1819 | } |
@@ -1828,8 +1828,8 @@ discard block |
||
| 1828 | 1828 | * |
| 1829 | 1829 | * @return string |
| 1830 | 1830 | */ |
| 1831 | - public function get_token( $user_id = 0 ) { |
|
| 1832 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
| 1831 | + public function get_token($user_id = 0) { |
|
| 1832 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /** |
@@ -1843,9 +1843,9 @@ discard block |
||
| 1843 | 1843 | |
| 1844 | 1844 | // Default sales return |
| 1845 | 1845 | $sales = array(); |
| 1846 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
| 1847 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
| 1848 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
| 1846 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
| 1847 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
| 1848 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
| 1849 | 1849 | $sales['donations']['totals'] = give_get_total_sales(); |
| 1850 | 1850 | |
| 1851 | 1851 | return $sales; |
@@ -1862,9 +1862,9 @@ discard block |
||
| 1862 | 1862 | |
| 1863 | 1863 | // Default earnings return |
| 1864 | 1864 | $earnings = array(); |
| 1865 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
| 1866 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
| 1867 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
| 1865 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
| 1866 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
| 1867 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
| 1868 | 1868 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
| 1869 | 1869 | |
| 1870 | 1870 | return $earnings; |
@@ -1884,25 +1884,25 @@ discard block |
||
| 1884 | 1884 | * |
| 1885 | 1885 | * @return string The API key/secret for the user supplied |
| 1886 | 1886 | */ |
| 1887 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
| 1887 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
| 1888 | 1888 | |
| 1889 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
| 1889 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
| 1890 | 1890 | return $check; |
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | $return = $check; |
| 1894 | 1894 | |
| 1895 | - switch ( $meta_key ) { |
|
| 1895 | + switch ($meta_key) { |
|
| 1896 | 1896 | case 'give_user_public_key': |
| 1897 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
| 1897 | + $return = Give()->api->get_user_public_key($object_id); |
|
| 1898 | 1898 | break; |
| 1899 | 1899 | case 'give_user_secret_key': |
| 1900 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
| 1900 | + $return = Give()->api->get_user_secret_key($object_id); |
|
| 1901 | 1901 | break; |
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | - if ( ! $single ) { |
|
| 1905 | - $return = array( $return ); |
|
| 1904 | + if ( ! $single) { |
|
| 1905 | + $return = array($return); |
|
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | return $return; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @since 1.0 |
| 197 | 197 | * @param array $log_data Log entry data |
| 198 | 198 | * @param array $log_meta Log entry meta |
| 199 | - * @return bool True if successful, false otherwise |
|
| 199 | + * @return boolean|null True if successful, false otherwise |
|
| 200 | 200 | */ |
| 201 | 201 | public function update_log( $log_data = array(), $log_meta = array() ) { |
| 202 | 202 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | * @param string $title |
| 368 | 368 | * @param string $message |
| 369 | 369 | * @param int $parent |
| 370 | - * @param null $type |
|
| 370 | + * @param string $type |
|
| 371 | 371 | * |
| 372 | 372 | * @global $give_logs GIVE Logs Object |
| 373 | 373 | * |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @access public |
| 69 | 69 | * @since 1.0 |
| 70 | 70 | * @return void |
| 71 | - */ |
|
| 71 | + */ |
|
| 72 | 72 | public function register_taxonomy() { |
| 73 | 73 | register_taxonomy( 'give_log_type', 'give_log', array( 'public' => false ) ); |
| 74 | 74 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param string $type Log type (default: null) |
| 142 | 142 | * @param int $paged Page number (default: null) |
| 143 | 143 | * @return array Array of the connected logs |
| 144 | - */ |
|
| 144 | + */ |
|
| 145 | 145 | public function get_logs( $object_id = 0, $type = null, $paged = null ) { |
| 146 | 146 | return $this->get_connected_logs( array( 'post_parent' => $object_id, 'paged' => $paged, 'log_type' => $type ) ); |
| 147 | 147 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 13 | +if ( ! defined('ABSPATH')) exit; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Give_Logging Class |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function __construct() { |
| 30 | 30 | // Create the log post type |
| 31 | - add_action( 'init', array( $this, 'register_post_type' ), 1 ); |
|
| 31 | + add_action('init', array($this, 'register_post_type'), 1); |
|
| 32 | 32 | |
| 33 | 33 | // Create types taxonomy and default types |
| 34 | - add_action( 'init', array( $this, 'register_taxonomy' ), 1 ); |
|
| 34 | + add_action('init', array($this, 'register_taxonomy'), 1); |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function register_post_type() { |
| 46 | 46 | /* Logs post type */ |
| 47 | 47 | $log_args = array( |
| 48 | - 'labels' => array( 'name' => __( 'Logs', 'give' ) ), |
|
| 48 | + 'labels' => array('name' => __('Logs', 'give')), |
|
| 49 | 49 | 'public' => false, |
| 50 | 50 | 'exclude_from_search' => true, |
| 51 | 51 | 'publicly_queryable' => false, |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | 'query_var' => false, |
| 54 | 54 | 'rewrite' => false, |
| 55 | 55 | 'capability_type' => 'post', |
| 56 | - 'supports' => array( 'title', 'editor' ), |
|
| 56 | + 'supports' => array('title', 'editor'), |
|
| 57 | 57 | 'can_export' => true |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - register_post_type( 'give_log', $log_args ); |
|
| 60 | + register_post_type('give_log', $log_args); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @return void |
| 71 | 71 | */ |
| 72 | 72 | public function register_taxonomy() { |
| 73 | - register_taxonomy( 'give_log_type', 'give_log', array( 'public' => false ) ); |
|
| 73 | + register_taxonomy('give_log_type', 'give_log', array('public' => false)); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | 'sale', 'gateway_error', 'api_request' |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - return apply_filters( 'give_log_types', $terms ); |
|
| 90 | + return apply_filters('give_log_types', $terms); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | * @param string $type Log type |
| 102 | 102 | * @return bool Whether log type is valid |
| 103 | 103 | */ |
| 104 | - function valid_type( $type ) { |
|
| 105 | - return in_array( $type, $this->log_types() ); |
|
| 104 | + function valid_type($type) { |
|
| 105 | + return in_array($type, $this->log_types()); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $type Log type (default: null) |
| 121 | 121 | * @return int Log ID |
| 122 | 122 | */ |
| 123 | - public function add( $title = '', $message = '', $parent = 0, $type = null ) { |
|
| 123 | + public function add($title = '', $message = '', $parent = 0, $type = null) { |
|
| 124 | 124 | $log_data = array( |
| 125 | 125 | 'post_title' => $title, |
| 126 | 126 | 'post_content' => $message, |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | 'log_type' => $type |
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | - return $this->insert_log( $log_data ); |
|
| 131 | + return $this->insert_log($log_data); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | * @param int $paged Page number (default: null) |
| 143 | 143 | * @return array Array of the connected logs |
| 144 | 144 | */ |
| 145 | - public function get_logs( $object_id = 0, $type = null, $paged = null ) { |
|
| 146 | - return $this->get_connected_logs( array( 'post_parent' => $object_id, 'paged' => $paged, 'log_type' => $type ) ); |
|
| 145 | + public function get_logs($object_id = 0, $type = null, $paged = null) { |
|
| 146 | + return $this->get_connected_logs(array('post_parent' => $object_id, 'paged' => $paged, 'log_type' => $type)); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param array $log_meta Log entry meta |
| 157 | 157 | * @return int The ID of the newly created log item |
| 158 | 158 | */ |
| 159 | - function insert_log( $log_data = array(), $log_meta = array() ) { |
|
| 159 | + function insert_log($log_data = array(), $log_meta = array()) { |
|
| 160 | 160 | $defaults = array( |
| 161 | 161 | 'post_type' => 'give_log', |
| 162 | 162 | 'post_status' => 'publish', |
@@ -165,26 +165,26 @@ discard block |
||
| 165 | 165 | 'log_type' => false |
| 166 | 166 | ); |
| 167 | 167 | |
| 168 | - $args = wp_parse_args( $log_data, $defaults ); |
|
| 168 | + $args = wp_parse_args($log_data, $defaults); |
|
| 169 | 169 | |
| 170 | - do_action( 'give_pre_insert_log', $log_data, $log_meta ); |
|
| 170 | + do_action('give_pre_insert_log', $log_data, $log_meta); |
|
| 171 | 171 | |
| 172 | 172 | // Store the log entry |
| 173 | - $log_id = wp_insert_post( $args ); |
|
| 173 | + $log_id = wp_insert_post($args); |
|
| 174 | 174 | |
| 175 | 175 | // Set the log type, if any |
| 176 | - if ( $log_data['log_type'] && $this->valid_type( $log_data['log_type'] ) ) { |
|
| 177 | - wp_set_object_terms( $log_id, $log_data['log_type'], 'give_log_type', false ); |
|
| 176 | + if ($log_data['log_type'] && $this->valid_type($log_data['log_type'])) { |
|
| 177 | + wp_set_object_terms($log_id, $log_data['log_type'], 'give_log_type', false); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Set log meta, if any |
| 181 | - if ( $log_id && ! empty( $log_meta ) ) { |
|
| 182 | - foreach ( (array) $log_meta as $key => $meta ) { |
|
| 183 | - update_post_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta ); |
|
| 181 | + if ($log_id && ! empty($log_meta)) { |
|
| 182 | + foreach ((array) $log_meta as $key => $meta) { |
|
| 183 | + update_post_meta($log_id, '_give_log_'.sanitize_key($key), $meta); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - do_action( 'give_post_insert_log', $log_id, $log_data, $log_meta ); |
|
| 187 | + do_action('give_post_insert_log', $log_id, $log_data, $log_meta); |
|
| 188 | 188 | |
| 189 | 189 | return $log_id; |
| 190 | 190 | } |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | * @param array $log_meta Log entry meta |
| 199 | 199 | * @return bool True if successful, false otherwise |
| 200 | 200 | */ |
| 201 | - public function update_log( $log_data = array(), $log_meta = array() ) { |
|
| 201 | + public function update_log($log_data = array(), $log_meta = array()) { |
|
| 202 | 202 | |
| 203 | - do_action( 'give_pre_update_log', $log_data, $log_meta ); |
|
| 203 | + do_action('give_pre_update_log', $log_data, $log_meta); |
|
| 204 | 204 | |
| 205 | 205 | $defaults = array( |
| 206 | 206 | 'post_type' => 'give_log', |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | 'post_parent' => 0 |
| 209 | 209 | ); |
| 210 | 210 | |
| 211 | - $args = wp_parse_args( $log_data, $defaults ); |
|
| 211 | + $args = wp_parse_args($log_data, $defaults); |
|
| 212 | 212 | |
| 213 | 213 | // Store the log entry |
| 214 | - $log_id = wp_update_post( $args ); |
|
| 214 | + $log_id = wp_update_post($args); |
|
| 215 | 215 | |
| 216 | - if ( $log_id && ! empty( $log_meta ) ) { |
|
| 217 | - foreach ( (array) $log_meta as $key => $meta ) { |
|
| 218 | - if ( ! empty( $meta ) ) |
|
| 219 | - update_post_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta ); |
|
| 216 | + if ($log_id && ! empty($log_meta)) { |
|
| 217 | + foreach ((array) $log_meta as $key => $meta) { |
|
| 218 | + if ( ! empty($meta)) |
|
| 219 | + update_post_meta($log_id, '_give_log_'.sanitize_key($key), $meta); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - do_action( 'give_post_update_log', $log_id, $log_data, $log_meta ); |
|
| 223 | + do_action('give_post_update_log', $log_id, $log_data, $log_meta); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -233,18 +233,18 @@ discard block |
||
| 233 | 233 | * @param array $args Query arguments |
| 234 | 234 | * @return mixed array if logs were found, false otherwise |
| 235 | 235 | */ |
| 236 | - public function get_connected_logs( $args = array() ) { |
|
| 236 | + public function get_connected_logs($args = array()) { |
|
| 237 | 237 | $defaults = array( |
| 238 | 238 | 'post_type' => 'give_log', |
| 239 | 239 | 'posts_per_page' => 20, |
| 240 | 240 | 'post_status' => 'publish', |
| 241 | - 'paged' => get_query_var( 'paged' ), |
|
| 241 | + 'paged' => get_query_var('paged'), |
|
| 242 | 242 | 'log_type' => false |
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | - $query_args = wp_parse_args( $args, $defaults ); |
|
| 245 | + $query_args = wp_parse_args($args, $defaults); |
|
| 246 | 246 | |
| 247 | - if ( $query_args['log_type'] && $this->valid_type( $query_args['log_type'] ) ) { |
|
| 247 | + if ($query_args['log_type'] && $this->valid_type($query_args['log_type'])) { |
|
| 248 | 248 | $query_args['tax_query'] = array( |
| 249 | 249 | array( |
| 250 | 250 | 'taxonomy' => 'give_log_type', |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | ); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $logs = get_posts( $query_args ); |
|
| 257 | + $logs = get_posts($query_args); |
|
| 258 | 258 | |
| 259 | - if ( $logs ) |
|
| 259 | + if ($logs) |
|
| 260 | 260 | return $logs; |
| 261 | 261 | |
| 262 | 262 | // No logs found |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param array $date_query Log data query (default: null) (since 1.9) |
| 275 | 275 | * @return int Log count |
| 276 | 276 | */ |
| 277 | - public function get_log_count( $object_id = 0, $type = null, $meta_query = null, $date_query = null ) { |
|
| 277 | + public function get_log_count($object_id = 0, $type = null, $meta_query = null, $date_query = null) { |
|
| 278 | 278 | |
| 279 | 279 | global $pagenow, $typenow; |
| 280 | 280 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | 'fields' => 'ids', |
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | - if ( ! empty( $type ) && $this->valid_type( $type ) ) { |
|
| 289 | + if ( ! empty($type) && $this->valid_type($type)) { |
|
| 290 | 290 | $query_args['tax_query'] = array( |
| 291 | 291 | array( |
| 292 | 292 | 'taxonomy' => 'give_log_type', |
@@ -296,15 +296,15 @@ discard block |
||
| 296 | 296 | ); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( ! empty( $meta_query ) ) { |
|
| 299 | + if ( ! empty($meta_query)) { |
|
| 300 | 300 | $query_args['meta_query'] = $meta_query; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if ( ! empty( $date_query ) ) { |
|
| 303 | + if ( ! empty($date_query)) { |
|
| 304 | 304 | $query_args['date_query'] = $date_query; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - $logs = new WP_Query( $query_args ); |
|
| 307 | + $logs = new WP_Query($query_args); |
|
| 308 | 308 | |
| 309 | 309 | return (int) $logs->post_count; |
| 310 | 310 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @param array $meta_query Log meta query (default: null) |
| 321 | 321 | * @return void |
| 322 | 322 | */ |
| 323 | - public function delete_logs( $object_id = 0, $type = null, $meta_query = null ) { |
|
| 323 | + public function delete_logs($object_id = 0, $type = null, $meta_query = null) { |
|
| 324 | 324 | $query_args = array( |
| 325 | 325 | 'post_parent' => $object_id, |
| 326 | 326 | 'post_type' => 'give_log', |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | 'fields' => 'ids' |
| 330 | 330 | ); |
| 331 | 331 | |
| 332 | - if ( ! empty( $type ) && $this->valid_type( $type ) ) { |
|
| 332 | + if ( ! empty($type) && $this->valid_type($type)) { |
|
| 333 | 333 | $query_args['tax_query'] = array( |
| 334 | 334 | array( |
| 335 | 335 | 'taxonomy' => 'give_log_type', |
@@ -339,15 +339,15 @@ discard block |
||
| 339 | 339 | ); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( ! empty( $meta_query ) ) { |
|
| 342 | + if ( ! empty($meta_query)) { |
|
| 343 | 343 | $query_args['meta_query'] = $meta_query; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - $logs = get_posts( $query_args ); |
|
| 346 | + $logs = get_posts($query_args); |
|
| 347 | 347 | |
| 348 | - if ( $logs ) { |
|
| 349 | - foreach ( $logs as $log ) { |
|
| 350 | - wp_delete_post( $log, true ); |
|
| 348 | + if ($logs) { |
|
| 349 | + foreach ($logs as $log) { |
|
| 350 | + wp_delete_post($log, true); |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | } |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * |
| 376 | 376 | * @return mixed ID of the new log entry |
| 377 | 377 | */ |
| 378 | -function give_record_log( $title = '', $message = '', $parent = 0, $type = null ) { |
|
| 378 | +function give_record_log($title = '', $message = '', $parent = 0, $type = null) { |
|
| 379 | 379 | global $give_logs; |
| 380 | - $log = $give_logs->add( $title, $message, $parent, $type ); |
|
| 380 | + $log = $give_logs->add($title, $message, $parent, $type); |
|
| 381 | 381 | return $log; |
| 382 | 382 | } |
| 383 | 383 | \ No newline at end of file |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 13 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 14 | + exit; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * Give_Logging Class |
@@ -215,8 +217,9 @@ discard block |
||
| 215 | 217 | |
| 216 | 218 | if ( $log_id && ! empty( $log_meta ) ) { |
| 217 | 219 | foreach ( (array) $log_meta as $key => $meta ) { |
| 218 | - if ( ! empty( $meta ) ) |
|
| 219 | - update_post_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta ); |
|
| 220 | + if ( ! empty( $meta ) ) { |
|
| 221 | + update_post_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta ); |
|
| 222 | + } |
|
| 220 | 223 | } |
| 221 | 224 | } |
| 222 | 225 | |
@@ -256,8 +259,9 @@ discard block |
||
| 256 | 259 | |
| 257 | 260 | $logs = get_posts( $query_args ); |
| 258 | 261 | |
| 259 | - if ( $logs ) |
|
| 260 | - return $logs; |
|
| 262 | + if ( $logs ) { |
|
| 263 | + return $logs; |
|
| 264 | + } |
|
| 261 | 265 | |
| 262 | 266 | // No logs found |
| 263 | 267 | return false; |
@@ -121,6 +121,7 @@ |
||
| 121 | 121 | * |
| 122 | 122 | * @access public |
| 123 | 123 | * @since 1.0 |
| 124 | + * @param string|boolean $date |
|
| 124 | 125 | * @return array|WP_Error If the date is invalid, a WP_Error object will be returned |
| 125 | 126 | */ |
| 126 | 127 | public function convert_date( $date, $end_date = false ) { |
@@ -76,19 +76,19 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function get_predefined_dates() { |
| 78 | 78 | $predefined = array( |
| 79 | - 'today' => __( 'Today', 'give' ), |
|
| 80 | - 'yesterday' => __( 'Yesterday', 'give' ), |
|
| 81 | - 'this_week' => __( 'This Week', 'give' ), |
|
| 82 | - 'last_week' => __( 'Last Week', 'give' ), |
|
| 83 | - 'this_month' => __( 'This Month', 'give' ), |
|
| 84 | - 'last_month' => __( 'Last Month', 'give' ), |
|
| 85 | - 'this_quarter' => __( 'This Quarter', 'give' ), |
|
| 86 | - 'last_quarter' => __( 'Last Quarter', 'give' ), |
|
| 87 | - 'this_year' => __( 'This Year', 'give' ), |
|
| 88 | - 'last_year' => __( 'Last Year', 'give' ) |
|
| 79 | + 'today' => __('Today', 'give'), |
|
| 80 | + 'yesterday' => __('Yesterday', 'give'), |
|
| 81 | + 'this_week' => __('This Week', 'give'), |
|
| 82 | + 'last_week' => __('Last Week', 'give'), |
|
| 83 | + 'this_month' => __('This Month', 'give'), |
|
| 84 | + 'last_month' => __('Last Month', 'give'), |
|
| 85 | + 'this_quarter' => __('This Quarter', 'give'), |
|
| 86 | + 'last_quarter' => __('Last Quarter', 'give'), |
|
| 87 | + 'this_year' => __('This Year', 'give'), |
|
| 88 | + 'last_year' => __('Last Year', 'give') |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - return apply_filters( 'give_stats_predefined_dates', $predefined ); |
|
| 91 | + return apply_filters('give_stats_predefined_dates', $predefined); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -104,20 +104,20 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return void |
| 106 | 106 | */ |
| 107 | - public function setup_dates( $_start_date = 'this_month', $_end_date = false ) { |
|
| 107 | + public function setup_dates($_start_date = 'this_month', $_end_date = false) { |
|
| 108 | 108 | |
| 109 | - if ( empty( $_start_date ) ) { |
|
| 109 | + if (empty($_start_date)) { |
|
| 110 | 110 | $this->start_date = 'this_month'; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $this->start_date = $_start_date; |
| 114 | 114 | |
| 115 | - if ( empty( $_end_date ) ) { |
|
| 115 | + if (empty($_end_date)) { |
|
| 116 | 116 | $_end_date = $_start_date; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $this->start_date = $this->convert_date( $_start_date ); |
|
| 120 | - $this->end_date = $this->convert_date( $_end_date, true ); |
|
| 119 | + $this->start_date = $this->convert_date($_start_date); |
|
| 120 | + $this->end_date = $this->convert_date($_end_date, true); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,26 +127,26 @@ discard block |
||
| 127 | 127 | * @since 1.0 |
| 128 | 128 | * @return array|WP_Error If the date is invalid, a WP_Error object will be returned |
| 129 | 129 | */ |
| 130 | - public function convert_date( $date, $end_date = false ) { |
|
| 130 | + public function convert_date($date, $end_date = false) { |
|
| 131 | 131 | |
| 132 | 132 | $timestamp = false; |
| 133 | 133 | $second = 0; |
| 134 | 134 | $minute = 0; |
| 135 | 135 | $hour = 0; |
| 136 | 136 | $day = 1; |
| 137 | - $month = date( 'n', current_time( 'timestamp' ) ); |
|
| 138 | - $year = date( 'Y', current_time( 'timestamp' ) ); |
|
| 137 | + $month = date('n', current_time('timestamp')); |
|
| 138 | + $year = date('Y', current_time('timestamp')); |
|
| 139 | 139 | |
| 140 | - if ( array_key_exists( $date, $this->get_predefined_dates() ) ) { |
|
| 140 | + if (array_key_exists($date, $this->get_predefined_dates())) { |
|
| 141 | 141 | |
| 142 | 142 | // This is a predefined date rate, such as last_week |
| 143 | - switch ( $date ) { |
|
| 143 | + switch ($date) { |
|
| 144 | 144 | |
| 145 | 145 | case 'this_month' : |
| 146 | 146 | |
| 147 | - if ( $end_date ) { |
|
| 147 | + if ($end_date) { |
|
| 148 | 148 | |
| 149 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 149 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -154,28 +154,28 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | case 'last_month' : |
| 156 | 156 | |
| 157 | - if ( $month == 1 ) { |
|
| 157 | + if ($month == 1) { |
|
| 158 | 158 | |
| 159 | 159 | $month = 12; |
| 160 | - $year --; |
|
| 160 | + $year--; |
|
| 161 | 161 | |
| 162 | 162 | } else { |
| 163 | 163 | |
| 164 | - $month --; |
|
| 164 | + $month--; |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( $end_date ) { |
|
| 169 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 168 | + if ($end_date) { |
|
| 169 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case 'today' : |
| 175 | 175 | |
| 176 | - $day = date( 'd', current_time( 'timestamp' ) ); |
|
| 176 | + $day = date('d', current_time('timestamp')); |
|
| 177 | 177 | |
| 178 | - if ( $end_date ) { |
|
| 178 | + if ($end_date) { |
|
| 179 | 179 | $hour = 11; |
| 180 | 180 | $minute = 59; |
| 181 | 181 | $second = 59; |
@@ -185,23 +185,23 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | case 'yesterday' : |
| 187 | 187 | |
| 188 | - $day = date( 'd', current_time( 'timestamp' ) ) - 1; |
|
| 188 | + $day = date('d', current_time('timestamp')) - 1; |
|
| 189 | 189 | |
| 190 | 190 | // Check if Today is the first day of the month (meaning subtracting one will get us 0) |
| 191 | - if ( $day < 1 ) { |
|
| 191 | + if ($day < 1) { |
|
| 192 | 192 | |
| 193 | 193 | // If current month is 1 |
| 194 | - if ( 1 == $month ) { |
|
| 194 | + if (1 == $month) { |
|
| 195 | 195 | |
| 196 | 196 | $year -= 1; // Today is January 1, so skip back to last day of December |
| 197 | 197 | $month = 12; |
| 198 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 198 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 199 | 199 | |
| 200 | 200 | } else { |
| 201 | 201 | |
| 202 | 202 | // Go back one month and get the last day of the month |
| 203 | 203 | $month -= 1; |
| 204 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 204 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 205 | 205 | |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -210,12 +210,12 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | case 'this_week' : |
| 212 | 212 | |
| 213 | - $days_to_week_start = ( date( 'w', current_time( 'timestamp' ) ) - 1 ) * 60 * 60 * 24; |
|
| 214 | - $today = date( 'd', current_time( 'timestamp' ) ) * 60 * 60 * 24; |
|
| 213 | + $days_to_week_start = (date('w', current_time('timestamp')) - 1) * 60 * 60 * 24; |
|
| 214 | + $today = date('d', current_time('timestamp')) * 60 * 60 * 24; |
|
| 215 | 215 | |
| 216 | - if ( $today < $days_to_week_start ) { |
|
| 216 | + if ($today < $days_to_week_start) { |
|
| 217 | 217 | |
| 218 | - if ( $month > 1 ) { |
|
| 218 | + if ($month > 1) { |
|
| 219 | 219 | $month -= 1; |
| 220 | 220 | } else { |
| 221 | 221 | $month = 12; |
@@ -223,19 +223,19 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( ! $end_date ) { |
|
| 226 | + if ( ! $end_date) { |
|
| 227 | 227 | |
| 228 | 228 | // Getting the start day |
| 229 | 229 | |
| 230 | - $day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 1; |
|
| 231 | - $day += get_option( 'start_of_week' ); |
|
| 230 | + $day = date('d', current_time('timestamp') - $days_to_week_start) - 1; |
|
| 231 | + $day += get_option('start_of_week'); |
|
| 232 | 232 | |
| 233 | 233 | } else { |
| 234 | 234 | |
| 235 | 235 | // Getting the end day |
| 236 | 236 | |
| 237 | - $day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 1; |
|
| 238 | - $day += get_option( 'start_of_week' ) + 6; |
|
| 237 | + $day = date('d', current_time('timestamp') - $days_to_week_start) - 1; |
|
| 238 | + $day += get_option('start_of_week') + 6; |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
@@ -243,12 +243,12 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | case 'last_week' : |
| 245 | 245 | |
| 246 | - $days_to_week_start = ( date( 'w', current_time( 'timestamp' ) ) - 1 ) * 60 * 60 * 24; |
|
| 247 | - $today = date( 'd', current_time( 'timestamp' ) ) * 60 * 60 * 24; |
|
| 246 | + $days_to_week_start = (date('w', current_time('timestamp')) - 1) * 60 * 60 * 24; |
|
| 247 | + $today = date('d', current_time('timestamp')) * 60 * 60 * 24; |
|
| 248 | 248 | |
| 249 | - if ( $today < $days_to_week_start ) { |
|
| 249 | + if ($today < $days_to_week_start) { |
|
| 250 | 250 | |
| 251 | - if ( $month > 1 ) { |
|
| 251 | + if ($month > 1) { |
|
| 252 | 252 | $month -= 1; |
| 253 | 253 | } else { |
| 254 | 254 | $month = 12; |
@@ -256,19 +256,19 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( ! $end_date ) { |
|
| 259 | + if ( ! $end_date) { |
|
| 260 | 260 | |
| 261 | 261 | // Getting the start day |
| 262 | 262 | |
| 263 | - $day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 8; |
|
| 264 | - $day += get_option( 'start_of_week' ); |
|
| 263 | + $day = date('d', current_time('timestamp') - $days_to_week_start) - 8; |
|
| 264 | + $day += get_option('start_of_week'); |
|
| 265 | 265 | |
| 266 | 266 | } else { |
| 267 | 267 | |
| 268 | 268 | // Getting the end day |
| 269 | 269 | |
| 270 | - $day = date( 'd', current_time( 'timestamp' ) - $days_to_week_start ) - 8; |
|
| 271 | - $day += get_option( 'start_of_week' ) + 6; |
|
| 270 | + $day = date('d', current_time('timestamp') - $days_to_week_start) - 8; |
|
| 271 | + $day += get_option('start_of_week') + 6; |
|
| 272 | 272 | |
| 273 | 273 | } |
| 274 | 274 | |
@@ -276,39 +276,39 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | case 'this_quarter' : |
| 278 | 278 | |
| 279 | - $month_now = date( 'n', current_time( 'timestamp' ) ); |
|
| 279 | + $month_now = date('n', current_time('timestamp')); |
|
| 280 | 280 | |
| 281 | - if ( $month_now <= 3 ) { |
|
| 281 | + if ($month_now <= 3) { |
|
| 282 | 282 | |
| 283 | - if ( ! $end_date ) { |
|
| 283 | + if ( ! $end_date) { |
|
| 284 | 284 | $month = 1; |
| 285 | 285 | } else { |
| 286 | 286 | $month = 3; |
| 287 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 287 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 288 | 288 | $hour = 11; |
| 289 | 289 | $minute = 59; |
| 290 | 290 | $second = 59; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - } else if ( $month_now <= 6 ) { |
|
| 293 | + } else if ($month_now <= 6) { |
|
| 294 | 294 | |
| 295 | - if ( ! $end_date ) { |
|
| 295 | + if ( ! $end_date) { |
|
| 296 | 296 | $month = 4; |
| 297 | 297 | } else { |
| 298 | 298 | $month = 6; |
| 299 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 299 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 300 | 300 | $hour = 11; |
| 301 | 301 | $minute = 59; |
| 302 | 302 | $second = 59; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - } else if ( $month_now <= 9 ) { |
|
| 305 | + } else if ($month_now <= 9) { |
|
| 306 | 306 | |
| 307 | - if ( ! $end_date ) { |
|
| 307 | + if ( ! $end_date) { |
|
| 308 | 308 | $month = 7; |
| 309 | 309 | } else { |
| 310 | 310 | $month = 9; |
| 311 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 311 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 312 | 312 | $hour = 11; |
| 313 | 313 | $minute = 59; |
| 314 | 314 | $second = 59; |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | } else { |
| 318 | 318 | |
| 319 | - if ( ! $end_date ) { |
|
| 319 | + if ( ! $end_date) { |
|
| 320 | 320 | $month = 10; |
| 321 | 321 | } else { |
| 322 | 322 | $month = 12; |
| 323 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 323 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 324 | 324 | $hour = 11; |
| 325 | 325 | $minute = 59; |
| 326 | 326 | $second = 59; |
@@ -332,40 +332,40 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | case 'last_quarter' : |
| 334 | 334 | |
| 335 | - $month_now = date( 'n', current_time( 'timestamp' ) ); |
|
| 335 | + $month_now = date('n', current_time('timestamp')); |
|
| 336 | 336 | |
| 337 | - if ( $month_now <= 3 ) { |
|
| 337 | + if ($month_now <= 3) { |
|
| 338 | 338 | |
| 339 | - if ( ! $end_date ) { |
|
| 339 | + if ( ! $end_date) { |
|
| 340 | 340 | $month = 10; |
| 341 | 341 | } else { |
| 342 | 342 | $year -= 1; |
| 343 | 343 | $month = 12; |
| 344 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 344 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 345 | 345 | $hour = 11; |
| 346 | 346 | $minute = 59; |
| 347 | 347 | $second = 59; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - } else if ( $month_now <= 6 ) { |
|
| 350 | + } else if ($month_now <= 6) { |
|
| 351 | 351 | |
| 352 | - if ( ! $end_date ) { |
|
| 352 | + if ( ! $end_date) { |
|
| 353 | 353 | $month = 1; |
| 354 | 354 | } else { |
| 355 | 355 | $month = 3; |
| 356 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 356 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 357 | 357 | $hour = 11; |
| 358 | 358 | $minute = 59; |
| 359 | 359 | $second = 59; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - } else if ( $month_now <= 9 ) { |
|
| 362 | + } else if ($month_now <= 9) { |
|
| 363 | 363 | |
| 364 | - if ( ! $end_date ) { |
|
| 364 | + if ( ! $end_date) { |
|
| 365 | 365 | $month = 4; |
| 366 | 366 | } else { |
| 367 | 367 | $month = 6; |
| 368 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 368 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 369 | 369 | $hour = 11; |
| 370 | 370 | $minute = 59; |
| 371 | 371 | $second = 59; |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | } else { |
| 375 | 375 | |
| 376 | - if ( ! $end_date ) { |
|
| 376 | + if ( ! $end_date) { |
|
| 377 | 377 | $month = 7; |
| 378 | 378 | } else { |
| 379 | 379 | $month = 9; |
| 380 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 380 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 381 | 381 | $hour = 11; |
| 382 | 382 | $minute = 59; |
| 383 | 383 | $second = 59; |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | case 'this_year' : |
| 391 | 391 | |
| 392 | - if ( ! $end_date ) { |
|
| 392 | + if ( ! $end_date) { |
|
| 393 | 393 | $month = 1; |
| 394 | 394 | } else { |
| 395 | 395 | $month = 12; |
| 396 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 396 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 397 | 397 | $hour = 11; |
| 398 | 398 | $minute = 59; |
| 399 | 399 | $second = 59; |
@@ -404,11 +404,11 @@ discard block |
||
| 404 | 404 | case 'last_year' : |
| 405 | 405 | |
| 406 | 406 | $year -= 1; |
| 407 | - if ( ! $end_date ) { |
|
| 407 | + if ( ! $end_date) { |
|
| 408 | 408 | $month = 1; |
| 409 | 409 | } else { |
| 410 | 410 | $month = 12; |
| 411 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
| 411 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
| 412 | 412 | $hour = 11; |
| 413 | 413 | $minute = 59; |
| 414 | 414 | $second = 59; |
@@ -419,30 +419,30 @@ discard block |
||
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | |
| 422 | - } else if ( is_numeric( $date ) ) { |
|
| 422 | + } else if (is_numeric($date)) { |
|
| 423 | 423 | |
| 424 | 424 | // return $date unchanged since it is a timestamp |
| 425 | 425 | $this->timestamp = true; |
| 426 | 426 | |
| 427 | - } else if ( false !== strtotime( $date ) ) { |
|
| 427 | + } else if (false !== strtotime($date)) { |
|
| 428 | 428 | |
| 429 | 429 | $this->timestamp = true; |
| 430 | - $date = strtotime( $date, current_time( 'timestamp' ) ); |
|
| 430 | + $date = strtotime($date, current_time('timestamp')); |
|
| 431 | 431 | |
| 432 | 432 | } else { |
| 433 | 433 | |
| 434 | - return new WP_Error( 'invalid_date', __( 'Improper date provided.', 'give' ) ); |
|
| 434 | + return new WP_Error('invalid_date', __('Improper date provided.', 'give')); |
|
| 435 | 435 | |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if ( ! is_wp_error( $date ) && ! $this->timestamp ) { |
|
| 438 | + if ( ! is_wp_error($date) && ! $this->timestamp) { |
|
| 439 | 439 | |
| 440 | 440 | // Create an exact timestamp |
| 441 | - $date = mktime( $hour, $minute, $second, $month, $day, $year ); |
|
| 441 | + $date = mktime($hour, $minute, $second, $month, $day, $year); |
|
| 442 | 442 | |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - return apply_filters( 'give_stats_date', $date, $end_date, $this ); |
|
| 445 | + return apply_filters('give_stats_date', $date, $end_date, $this); |
|
| 446 | 446 | |
| 447 | 447 | } |
| 448 | 448 | |
@@ -453,33 +453,33 @@ discard block |
||
| 453 | 453 | * @since 1.0 |
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | - public function count_where( $where = '' ) { |
|
| 456 | + public function count_where($where = '') { |
|
| 457 | 457 | // Only get payments in our date range |
| 458 | 458 | |
| 459 | 459 | $start_where = ''; |
| 460 | 460 | $end_where = ''; |
| 461 | 461 | |
| 462 | - if ( $this->start_date ) { |
|
| 462 | + if ($this->start_date) { |
|
| 463 | 463 | |
| 464 | - if ( $this->timestamp ) { |
|
| 464 | + if ($this->timestamp) { |
|
| 465 | 465 | $format = 'Y-m-d H:i:s'; |
| 466 | 466 | } else { |
| 467 | 467 | $format = 'Y-m-d 00:00:00'; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - $start_date = date( $format, $this->start_date ); |
|
| 470 | + $start_date = date($format, $this->start_date); |
|
| 471 | 471 | $start_where = " AND p.post_date >= '{$start_date}'"; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( $this->end_date ) { |
|
| 474 | + if ($this->end_date) { |
|
| 475 | 475 | |
| 476 | - if ( $this->timestamp ) { |
|
| 476 | + if ($this->timestamp) { |
|
| 477 | 477 | $format = 'Y-m-d H:i:s'; |
| 478 | 478 | } else { |
| 479 | 479 | $format = 'Y-m-d 23:59:59'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - $end_date = date( $format, $this->end_date ); |
|
| 482 | + $end_date = date($format, $this->end_date); |
|
| 483 | 483 | |
| 484 | 484 | $end_where = " AND p.post_date <= '{$end_date}'"; |
| 485 | 485 | } |
@@ -499,34 +499,34 @@ discard block |
||
| 499 | 499 | * |
| 500 | 500 | * @return string |
| 501 | 501 | */ |
| 502 | - public function payments_where( $where = '' ) { |
|
| 502 | + public function payments_where($where = '') { |
|
| 503 | 503 | |
| 504 | 504 | global $wpdb; |
| 505 | 505 | |
| 506 | 506 | $start_where = ''; |
| 507 | 507 | $end_where = ''; |
| 508 | 508 | |
| 509 | - if ( $this->start_date ) { |
|
| 509 | + if ($this->start_date) { |
|
| 510 | 510 | |
| 511 | - if ( $this->timestamp ) { |
|
| 511 | + if ($this->timestamp) { |
|
| 512 | 512 | $format = 'Y-m-d H:i:s'; |
| 513 | 513 | } else { |
| 514 | 514 | $format = 'Y-m-d 00:00:00'; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $start_date = date( $format, $this->start_date ); |
|
| 517 | + $start_date = date($format, $this->start_date); |
|
| 518 | 518 | $start_where = " AND $wpdb->posts.post_date >= '{$start_date}'"; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if ( $this->end_date ) { |
|
| 521 | + if ($this->end_date) { |
|
| 522 | 522 | |
| 523 | - if ( $this->timestamp ) { |
|
| 523 | + if ($this->timestamp) { |
|
| 524 | 524 | $format = 'Y-m-d H:i:s'; |
| 525 | 525 | } else { |
| 526 | 526 | $format = 'Y-m-d 23:59:59'; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - $end_date = date( $format, $this->end_date ); |
|
| 529 | + $end_date = date($format, $this->end_date); |
|
| 530 | 530 | |
| 531 | 531 | $end_where = " AND $wpdb->posts.post_date <= '{$end_date}'"; |
| 532 | 532 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param array $args Arguments for display |
| 23 | 23 | * |
| 24 | - * @return string $purchase_form |
|
| 24 | + * @return false|null $purchase_form |
|
| 25 | 25 | */ |
| 26 | 26 | function give_get_donation_form( $args = array() ) { |
| 27 | 27 | |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | * @param int $form_id |
| 1151 | 1151 | * @param array $args |
| 1152 | 1152 | * |
| 1153 | - * @return mixed |
|
| 1153 | + * @return boolean |
|
| 1154 | 1154 | */ |
| 1155 | 1155 | |
| 1156 | 1156 | function give_show_goal_progress( $form_id, $args ) { |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Give Form Template |
|
| 4 | - * |
|
| 5 | - * @package Give |
|
| 6 | - * @subpackage Forms |
|
| 7 | - * @copyright Copyright (c) 2015, WordImpress |
|
| 8 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
| 9 | - * @since 1.0 |
|
| 10 | - */ |
|
| 3 | + * Give Form Template |
|
| 4 | + * |
|
| 5 | + * @package Give |
|
| 6 | + * @subpackage Forms |
|
| 7 | + * @copyright Copyright (c) 2015, WordImpress |
|
| 8 | + * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
| 9 | + * @since 1.0 |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
@@ -1170,9 +1170,9 @@ discard block |
||
| 1170 | 1170 | |
| 1171 | 1171 | //Sanity check - ensure form has goal set to output |
| 1172 | 1172 | if ( empty( $form->ID ) |
| 1173 | - || ( is_singular( 'give_forms' ) && $goal_option !== 'yes' ) |
|
| 1174 | - || $goal_option !== 'yes' |
|
| 1175 | - || $goal == 0 |
|
| 1173 | + || ( is_singular( 'give_forms' ) && $goal_option !== 'yes' ) |
|
| 1174 | + || $goal_option !== 'yes' |
|
| 1175 | + || $goal == 0 |
|
| 1176 | 1176 | ) { |
| 1177 | 1177 | //not this form, bail |
| 1178 | 1178 | return false; |
@@ -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,56 +23,56 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @return string $purchase_form |
| 25 | 25 | */ |
| 26 | -function give_get_donation_form( $args = array() ) { |
|
| 26 | +function give_get_donation_form($args = array()) { |
|
| 27 | 27 | |
| 28 | 28 | global $post; |
| 29 | 29 | |
| 30 | - $post_id = is_object( $post ) ? $post->ID : 0; |
|
| 30 | + $post_id = is_object($post) ? $post->ID : 0; |
|
| 31 | 31 | |
| 32 | - if ( isset( $args['id'] ) ) { |
|
| 32 | + if (isset($args['id'])) { |
|
| 33 | 33 | $post_id = $args['id']; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $defaults = apply_filters( 'give_form_args_defaults', array( |
|
| 36 | + $defaults = apply_filters('give_form_args_defaults', array( |
|
| 37 | 37 | 'form_id' => $post_id |
| 38 | - ) ); |
|
| 38 | + )); |
|
| 39 | 39 | |
| 40 | - $args = wp_parse_args( $args, $defaults ); |
|
| 40 | + $args = wp_parse_args($args, $defaults); |
|
| 41 | 41 | |
| 42 | - $form = new Give_Donate_Form( $args['form_id'] ); |
|
| 42 | + $form = new Give_Donate_Form($args['form_id']); |
|
| 43 | 43 | |
| 44 | 44 | //bail if no form ID |
| 45 | - if ( empty( $form->ID ) ) { |
|
| 45 | + if (empty($form->ID)) { |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $payment_mode = give_get_chosen_gateway( $form->ID ); |
|
| 49 | + $payment_mode = give_get_chosen_gateway($form->ID); |
|
| 50 | 50 | |
| 51 | - $form_action = esc_url( add_query_arg( apply_filters( 'give_form_action_args', array( |
|
| 51 | + $form_action = esc_url(add_query_arg(apply_filters('give_form_action_args', array( |
|
| 52 | 52 | 'payment-mode' => $payment_mode, |
| 53 | - ) ), |
|
| 53 | + )), |
|
| 54 | 54 | give_get_current_page_url() |
| 55 | - ) ); |
|
| 55 | + )); |
|
| 56 | 56 | |
| 57 | - if ( 'publish' !== $form->post_status && ! current_user_can( 'edit_product', $form->ID ) ) { |
|
| 57 | + if ('publish' !== $form->post_status && ! current_user_can('edit_product', $form->ID)) { |
|
| 58 | 58 | return false; // Product not published or user doesn't have permission to view drafts |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
|
| 61 | + $display_option = (isset($args['display_style']) && ! empty($args['display_style'])) |
|
| 62 | 62 | ? $args['display_style'] |
| 63 | - : get_post_meta( $form->ID, '_give_payment_display', true ); |
|
| 63 | + : get_post_meta($form->ID, '_give_payment_display', true); |
|
| 64 | 64 | |
| 65 | - $float_labels_option = give_is_float_labels_enabled( $args ) |
|
| 65 | + $float_labels_option = give_is_float_labels_enabled($args) |
|
| 66 | 66 | ? ' float-labels-enabled' |
| 67 | 67 | : ''; |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - $form_classes_array = apply_filters( 'give_form_classes', array( |
|
| 70 | + $form_classes_array = apply_filters('give_form_classes', array( |
|
| 71 | 71 | 'give-form-wrap', |
| 72 | - 'give-display-' . $display_option |
|
| 73 | - ), $form->ID, $args ); |
|
| 72 | + 'give-display-'.$display_option |
|
| 73 | + ), $form->ID, $args); |
|
| 74 | 74 | |
| 75 | - $form_classes = implode( ' ', $form_classes_array ); |
|
| 75 | + $form_classes = implode(' ', $form_classes_array); |
|
| 76 | 76 | |
| 77 | 77 | ob_start(); |
| 78 | 78 | |
@@ -84,34 +84,34 @@ discard block |
||
| 84 | 84 | * @param int $form ->ID The current form ID |
| 85 | 85 | * @param array $args An array of form args |
| 86 | 86 | */ |
| 87 | - do_action( 'give_pre_form_output', $form->ID, $args ); ?> |
|
| 87 | + do_action('give_pre_form_output', $form->ID, $args); ?> |
|
| 88 | 88 | |
| 89 | 89 | <div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_classes; ?>"> |
| 90 | 90 | |
| 91 | 91 | <?php |
| 92 | - if ( isset( $args['show_title'] ) && $args['show_title'] == true ) { |
|
| 92 | + if (isset($args['show_title']) && $args['show_title'] == true) { |
|
| 93 | 93 | |
| 94 | - echo apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $post_id ) . '</h2>' ); |
|
| 94 | + echo apply_filters('give_form_title', '<h2 class="give-form-title">'.get_the_title($post_id).'</h2>'); |
|
| 95 | 95 | |
| 96 | 96 | } ?> |
| 97 | 97 | |
| 98 | - <?php do_action( 'give_pre_form', $form->ID, $args ); ?> |
|
| 98 | + <?php do_action('give_pre_form', $form->ID, $args); ?> |
|
| 99 | 99 | |
| 100 | - <form id="give-form-<?php echo $post_id; ?>" class="give-form give-form-<?php echo absint( $form->ID ); ?><?php echo $float_labels_option; ?>" action="<?php echo $form_action; ?>" method="post"> |
|
| 100 | + <form id="give-form-<?php echo $post_id; ?>" class="give-form give-form-<?php echo absint($form->ID); ?><?php echo $float_labels_option; ?>" action="<?php echo $form_action; ?>" method="post"> |
|
| 101 | 101 | <input type="hidden" name="give-form-id" value="<?php echo $form->ID; ?>"/> |
| 102 | - <input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/> |
|
| 103 | - <input type="hidden" name="give-current-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
|
| 104 | - <input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
|
| 105 | - <input type="hidden" name="give-form-minimum" value="<?php echo give_get_form_minimum_price( $form->ID ); ?>"/> |
|
| 102 | + <input type="hidden" name="give-form-title" value="<?php echo htmlentities($form->post_title); ?>"/> |
|
| 103 | + <input type="hidden" name="give-current-url" value="<?php echo htmlspecialchars(give_get_current_page_url()); ?>"/> |
|
| 104 | + <input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars(give_get_current_page_url()); ?>"/> |
|
| 105 | + <input type="hidden" name="give-form-minimum" value="<?php echo give_get_form_minimum_price($form->ID); ?>"/> |
|
| 106 | 106 | <?php |
| 107 | 107 | //Price ID hidden field for variable (mult-level) donation forms |
| 108 | - if ( give_has_variable_prices( $post_id ) ) { |
|
| 108 | + if (give_has_variable_prices($post_id)) { |
|
| 109 | 109 | //get default selected price ID |
| 110 | - $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $post_id ), $post_id ); |
|
| 110 | + $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($post_id), $post_id); |
|
| 111 | 111 | $price_id = 0; |
| 112 | 112 | //loop through prices |
| 113 | - foreach ( $prices as $price ) { |
|
| 114 | - if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) { |
|
| 113 | + foreach ($prices as $price) { |
|
| 114 | + if (isset($price['_give_default']) && $price['_give_default'] === 'default') { |
|
| 115 | 115 | $price_id = $price['_give_id']['level_id']; |
| 116 | 116 | }; |
| 117 | 117 | } |
@@ -119,19 +119,19 @@ discard block |
||
| 119 | 119 | <input type="hidden" name="give-price-id" value="<?php echo $price_id; ?>"/> |
| 120 | 120 | <?php } |
| 121 | 121 | |
| 122 | - do_action( 'give_checkout_form_top', $form->ID, $args ); |
|
| 122 | + do_action('give_checkout_form_top', $form->ID, $args); |
|
| 123 | 123 | |
| 124 | - do_action( 'give_payment_mode_select', $form->ID, $args ); |
|
| 124 | + do_action('give_payment_mode_select', $form->ID, $args); |
|
| 125 | 125 | |
| 126 | - do_action( 'give_checkout_form_bottom', $form->ID, $args ); |
|
| 126 | + do_action('give_checkout_form_bottom', $form->ID, $args); |
|
| 127 | 127 | |
| 128 | 128 | ?> |
| 129 | 129 | |
| 130 | 130 | </form> |
| 131 | 131 | |
| 132 | - <?php do_action( 'give_post_form', $form->ID, $args ); ?> |
|
| 132 | + <?php do_action('give_post_form', $form->ID, $args); ?> |
|
| 133 | 133 | |
| 134 | - <!--end #give-form-<?php echo absint( $form->ID ); ?>--></div> |
|
| 134 | + <!--end #give-form-<?php echo absint($form->ID); ?>--></div> |
|
| 135 | 135 | <?php |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | * @param int $form ->ID The current form ID |
| 143 | 143 | * @param array $args An array of form args |
| 144 | 144 | */ |
| 145 | - do_action( 'give_post_form_output', $form->ID, $args ); |
|
| 145 | + do_action('give_post_form_output', $form->ID, $args); |
|
| 146 | 146 | |
| 147 | 147 | $final_output = ob_get_clean(); |
| 148 | 148 | |
| 149 | - echo apply_filters( 'give_donate_form', $final_output, $args ); |
|
| 149 | + echo apply_filters('give_donate_form', $final_output, $args); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -166,57 +166,57 @@ discard block |
||
| 166 | 166 | * @global $give_options Array of all the Give options |
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | -function give_show_purchase_form( $form_id ) { |
|
| 169 | +function give_show_purchase_form($form_id) { |
|
| 170 | 170 | |
| 171 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
| 171 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
| 172 | 172 | |
| 173 | - if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) { |
|
| 173 | + if ( ! isset($form_id) && isset($_POST['give_form_id'])) { |
|
| 174 | 174 | $form_id = $_POST['give_form_id']; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - do_action( 'give_purchase_form_top', $form_id ); |
|
| 177 | + do_action('give_purchase_form_top', $form_id); |
|
| 178 | 178 | |
| 179 | - if ( give_can_checkout() && isset( $form_id ) ) { |
|
| 179 | + if (give_can_checkout() && isset($form_id)) { |
|
| 180 | 180 | |
| 181 | - do_action( 'give_purchase_form_before_register_login', $form_id ); |
|
| 181 | + do_action('give_purchase_form_before_register_login', $form_id); |
|
| 182 | 182 | |
| 183 | - $show_register_form = apply_filters( 'give_show_register_form', get_post_meta( $form_id, '_give_show_register_form', true ) ); |
|
| 183 | + $show_register_form = apply_filters('give_show_register_form', get_post_meta($form_id, '_give_show_register_form', true)); |
|
| 184 | 184 | |
| 185 | - if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : ?> |
|
| 185 | + if (($show_register_form === 'registration' || ($show_register_form === 'both' && ! isset($_GET['login']))) && ! is_user_logged_in()) : ?> |
|
| 186 | 186 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 187 | - <?php do_action( 'give_purchase_form_register_fields', $form_id ); ?> |
|
| 187 | + <?php do_action('give_purchase_form_register_fields', $form_id); ?> |
|
| 188 | 188 | </div> |
| 189 | - <?php elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : ?> |
|
| 189 | + <?php elseif (($show_register_form === 'login' || ($show_register_form === 'both' && isset($_GET['login']))) && ! is_user_logged_in()) : ?> |
|
| 190 | 190 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 191 | - <?php do_action( 'give_purchase_form_login_fields', $form_id ); ?> |
|
| 191 | + <?php do_action('give_purchase_form_login_fields', $form_id); ?> |
|
| 192 | 192 | </div> |
| 193 | 193 | <?php endif; ?> |
| 194 | 194 | |
| 195 | - <?php if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) { |
|
| 196 | - do_action( 'give_purchase_form_after_user_info', $form_id ); |
|
| 195 | + <?php if (( ! isset($_GET['login']) && is_user_logged_in()) || ! isset($show_register_form) || 'none' === $show_register_form || 'login' === $show_register_form) { |
|
| 196 | + do_action('give_purchase_form_after_user_info', $form_id); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - do_action( 'give_purchase_form_before_cc_form', $form_id ); |
|
| 199 | + do_action('give_purchase_form_before_cc_form', $form_id); |
|
| 200 | 200 | |
| 201 | 201 | // Load the credit card form and allow gateways to load their own if they wish |
| 202 | - if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) { |
|
| 203 | - do_action( 'give_' . $payment_mode . '_cc_form', $form_id ); |
|
| 202 | + if (has_action('give_'.$payment_mode.'_cc_form')) { |
|
| 203 | + do_action('give_'.$payment_mode.'_cc_form', $form_id); |
|
| 204 | 204 | } else { |
| 205 | - do_action( 'give_cc_form', $form_id ); |
|
| 205 | + do_action('give_cc_form', $form_id); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - do_action( 'give_purchase_form_after_cc_form', $form_id ); |
|
| 208 | + do_action('give_purchase_form_after_cc_form', $form_id); |
|
| 209 | 209 | |
| 210 | 210 | } else { |
| 211 | 211 | // Can't checkout |
| 212 | - do_action( 'give_purchase_form_no_access', $form_id ); |
|
| 212 | + do_action('give_purchase_form_no_access', $form_id); |
|
| 213 | 213 | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - do_action( 'give_purchase_form_bottom', $form_id ); |
|
| 216 | + do_action('give_purchase_form_bottom', $form_id); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | -add_action( 'give_purchase_form', 'give_show_purchase_form' ); |
|
| 219 | +add_action('give_purchase_form', 'give_show_purchase_form'); |
|
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Donation Amount Field |
@@ -230,37 +230,37 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return void |
| 232 | 232 | */ |
| 233 | -function give_output_donation_amount_top( $form_id = 0, $args = array() ) { |
|
| 233 | +function give_output_donation_amount_top($form_id = 0, $args = array()) { |
|
| 234 | 234 | |
| 235 | 235 | global $give_options; |
| 236 | 236 | |
| 237 | - $variable_pricing = give_has_variable_prices( $form_id ); |
|
| 238 | - $allow_custom_amount = get_post_meta( $form_id, '_give_custom_amount', true ); |
|
| 239 | - $currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before'; |
|
| 240 | - $symbol = give_currency_symbol( $give_options['currency'] ); |
|
| 241 | - $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>'; |
|
| 242 | - $default_amount = give_format_amount( give_get_default_form_amount( $form_id ) ); |
|
| 243 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
| 237 | + $variable_pricing = give_has_variable_prices($form_id); |
|
| 238 | + $allow_custom_amount = get_post_meta($form_id, '_give_custom_amount', true); |
|
| 239 | + $currency_position = isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before'; |
|
| 240 | + $symbol = give_currency_symbol($give_options['currency']); |
|
| 241 | + $currency_output = '<span class="give-currency-symbol give-currency-position-'.$currency_position.'">'.$symbol.'</span>'; |
|
| 242 | + $default_amount = give_format_amount(give_get_default_form_amount($form_id)); |
|
| 243 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
| 244 | 244 | |
| 245 | - do_action( 'give_before_donation_levels', $form_id ); |
|
| 245 | + do_action('give_before_donation_levels', $form_id); |
|
| 246 | 246 | |
| 247 | 247 | //Set Price, No Custom Amount Allowed means hidden price field |
| 248 | - if ( $allow_custom_amount == 'no' ) { |
|
| 248 | + if ($allow_custom_amount == 'no') { |
|
| 249 | 249 | ?> |
| 250 | 250 | |
| 251 | - <label class="give-hidden" for="give-amount-hidden"><?php echo __( 'Donation Amount:', 'give' ); ?></label> |
|
| 251 | + <label class="give-hidden" for="give-amount-hidden"><?php echo __('Donation Amount:', 'give'); ?></label> |
|
| 252 | 252 | <input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" |
| 253 | 253 | value="<?php echo $default_amount; ?>" required> |
| 254 | 254 | <p class="set-price give-donation-amount form-row-wide"> |
| 255 | - <?php if ( $currency_position == 'before' ) { |
|
| 255 | + <?php if ($currency_position == 'before') { |
|
| 256 | 256 | echo $currency_output; |
| 257 | 257 | } ?> |
| 258 | 258 | <span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span> |
| 259 | - <?php if ( $currency_position == 'after' ) { |
|
| 259 | + <?php if ($currency_position == 'after') { |
|
| 260 | 260 | echo $currency_output; |
| 261 | 261 | } ?> |
| 262 | 262 | <span class="give-loading-text give-updating-price-loader"> |
| 263 | - <span class="give-loading-animation"></span> <?php _e( 'Updating Amount...', 'give' ); ?> |
|
| 263 | + <span class="give-loading-animation"></span> <?php _e('Updating Amount...', 'give'); ?> |
|
| 264 | 264 | </span> |
| 265 | 265 | </p> |
| 266 | 266 | <?php |
@@ -269,35 +269,35 @@ discard block |
||
| 269 | 269 | ?> |
| 270 | 270 | <div class="give-total-wrap"> |
| 271 | 271 | <div class="give-donation-amount form-row-wide"> |
| 272 | - <?php if ( $currency_position == 'before' ) { |
|
| 272 | + <?php if ($currency_position == 'before') { |
|
| 273 | 273 | echo $currency_output; |
| 274 | 274 | } ?> |
| 275 | - <label class="give-hidden" for="give-amount"><?php echo __( 'Donation Amount:', 'give' ); ?></label> |
|
| 275 | + <label class="give-hidden" for="give-amount"><?php echo __('Donation Amount:', 'give'); ?></label> |
|
| 276 | 276 | <input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" |
| 277 | 277 | placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off"> |
| 278 | - <?php if ( $currency_position == 'after' ) { |
|
| 278 | + <?php if ($currency_position == 'after') { |
|
| 279 | 279 | echo $currency_output; |
| 280 | 280 | } ?> |
| 281 | 281 | <span class="give-loading-text give-updating-price-loader"> |
| 282 | - <span class="give-loading-animation"></span> <?php _e( 'Updating Amount...', 'give' ); ?> |
|
| 282 | + <span class="give-loading-animation"></span> <?php _e('Updating Amount...', 'give'); ?> |
|
| 283 | 283 | </span> |
| 284 | 284 | </div> |
| 285 | 285 | </div> |
| 286 | 286 | <?php } |
| 287 | 287 | |
| 288 | 288 | //Custom Amount Text |
| 289 | - if ( ! $variable_pricing && $allow_custom_amount == 'yes' ) { ?> |
|
| 290 | - <p class="give-custom-amount-text"><?php echo ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Give a Custom Amount', 'give' ); ?></p> |
|
| 289 | + if ( ! $variable_pricing && $allow_custom_amount == 'yes') { ?> |
|
| 290 | + <p class="give-custom-amount-text"><?php echo ! empty($custom_amount_text) ? $custom_amount_text : __('Give a Custom Amount', 'give'); ?></p> |
|
| 291 | 291 | <?php } |
| 292 | 292 | |
| 293 | 293 | //Output Variable Pricing Levels |
| 294 | - if ( $variable_pricing ) { |
|
| 295 | - give_output_levels( $form_id ); |
|
| 294 | + if ($variable_pricing) { |
|
| 295 | + give_output_levels($form_id); |
|
| 296 | 296 | } |
| 297 | - do_action( 'give_after_donation_levels', $form_id, $args ); |
|
| 297 | + do_action('give_after_donation_levels', $form_id, $args); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | -add_action( 'give_checkout_form_top', 'give_output_donation_amount_top', 10, 2 ); |
|
| 300 | +add_action('give_checkout_form_top', 'give_output_donation_amount_top', 10, 2); |
|
| 301 | 301 | |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -309,32 +309,32 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | -function give_output_levels( $form_id ) { |
|
| 312 | +function give_output_levels($form_id) { |
|
| 313 | 313 | |
| 314 | 314 | //Get variable pricing |
| 315 | - $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
|
| 316 | - $display_style = get_post_meta( $form_id, '_give_display_style', true ); |
|
| 317 | - $custom_amount = get_post_meta( $form_id, '_give_custom_amount', true ); |
|
| 318 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
| 319 | - if ( empty( $custom_amount_text ) ) { |
|
| 320 | - $custom_amount_text = __( 'Give a Custom Amount', 'give' ); |
|
| 315 | + $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($form_id), $form_id); |
|
| 316 | + $display_style = get_post_meta($form_id, '_give_display_style', true); |
|
| 317 | + $custom_amount = get_post_meta($form_id, '_give_custom_amount', true); |
|
| 318 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
| 319 | + if (empty($custom_amount_text)) { |
|
| 320 | + $custom_amount_text = __('Give a Custom Amount', 'give'); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | $output = ''; |
| 324 | 324 | $counter = 0; |
| 325 | 325 | |
| 326 | - switch ( $display_style ) { |
|
| 326 | + switch ($display_style) { |
|
| 327 | 327 | case 'buttons': |
| 328 | 328 | |
| 329 | 329 | $output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; |
| 330 | 330 | |
| 331 | - foreach ( $prices as $price ) { |
|
| 332 | - $counter ++; |
|
| 333 | - $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
|
| 334 | - $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $counter . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price ); |
|
| 331 | + foreach ($prices as $price) { |
|
| 332 | + $counter++; |
|
| 333 | + $level_text = apply_filters('give_form_level_text', ! empty($price['_give_text']) ? $price['_give_text'] : give_currency_filter(give_format_amount($price['_give_amount'])), $form_id, $price); |
|
| 334 | + $level_classes = apply_filters('give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-'.$counter.' '.((isset($price['_give_default']) && $price['_give_default'] === 'default') ? 'give-default-level' : ''), $form_id, $price); |
|
| 335 | 335 | |
| 336 | 336 | $output .= '<li>'; |
| 337 | - $output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
|
| 337 | + $output .= '<button type="button" data-price-id="'.$price['_give_id']['level_id'].'" class=" '.$level_classes.'" value="'.give_format_amount($price['_give_amount']).'">'; |
|
| 338 | 338 | $output .= $level_text; |
| 339 | 339 | $output .= '</button>'; |
| 340 | 340 | $output .= '</li>'; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | //Custom Amount |
| 345 | - if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
|
| 345 | + if ($custom_amount === 'yes' && ! empty($custom_amount_text)) { |
|
| 346 | 346 | $output .= '<li>'; |
| 347 | 347 | $output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">'; |
| 348 | 348 | $output .= $custom_amount_text; |
@@ -358,23 +358,23 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | $output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">'; |
| 360 | 360 | |
| 361 | - foreach ( $prices as $price ) { |
|
| 362 | - $counter ++; |
|
| 363 | - $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
|
| 364 | - $level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $counter . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price ); |
|
| 361 | + foreach ($prices as $price) { |
|
| 362 | + $counter++; |
|
| 363 | + $level_text = apply_filters('give_form_level_text', ! empty($price['_give_text']) ? $price['_give_text'] : give_currency_filter(give_format_amount($price['_give_amount'])), $form_id, $price); |
|
| 364 | + $level_classes = apply_filters('give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-'.$counter.((isset($price['_give_default']) && $price['_give_default'] === 'default') ? ' give-default-level' : ''), $form_id, $price); |
|
| 365 | 365 | |
| 366 | 366 | $output .= '<li>'; |
| 367 | - $output .= '<input type="radio" data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" name="give-radio-donation-level" id="give-radio-level-' . $counter . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
|
| 368 | - $output .= '<label for="give-radio-level-' . $counter . '">' . $level_text . '</label>'; |
|
| 367 | + $output .= '<input type="radio" data-price-id="'.$price['_give_id']['level_id'].'" class="'.$level_classes.'" name="give-radio-donation-level" id="give-radio-level-'.$counter.'" '.((isset($price['_give_default']) && $price['_give_default'] === 'default') ? 'checked="checked"' : '').' value="'.give_format_amount($price['_give_amount']).'">'; |
|
| 368 | + $output .= '<label for="give-radio-level-'.$counter.'">'.$level_text.'</label>'; |
|
| 369 | 369 | $output .= '</li>'; |
| 370 | 370 | |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | //Custom Amount |
| 374 | - if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
|
| 374 | + if ($custom_amount === 'yes' && ! empty($custom_amount_text)) { |
|
| 375 | 375 | $output .= '<li>'; |
| 376 | 376 | $output .= '<input type="radio" data-price-id="custom" class="give-radio-input give-radio-input-level give-radio-level-custom" name="give-radio-donation-level" id="give-radio-level-custom" value="custom">'; |
| 377 | - $output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>'; |
|
| 377 | + $output .= '<label for="give-radio-level-custom">'.$custom_amount_text.'</label>'; |
|
| 378 | 378 | $output .= '</li>'; |
| 379 | 379 | } |
| 380 | 380 | |
@@ -384,23 +384,23 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | case 'dropdown': |
| 386 | 386 | |
| 387 | - $output .= '<label for="give-donation-level" class="give-hidden">' . __( 'Choose your Donation Amount', 'give' ) . ':</label>'; |
|
| 388 | - $output .= '<select id="give-donation-level-' . $form_id . '" class="give-select give-select-level">'; |
|
| 387 | + $output .= '<label for="give-donation-level" class="give-hidden">'.__('Choose your Donation Amount', 'give').':</label>'; |
|
| 388 | + $output .= '<select id="give-donation-level-'.$form_id.'" class="give-select give-select-level">'; |
|
| 389 | 389 | |
| 390 | 390 | //first loop through prices |
| 391 | - foreach ( $prices as $price ) { |
|
| 392 | - $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
|
| 393 | - $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $form_id, $form_id, $price ); |
|
| 391 | + foreach ($prices as $price) { |
|
| 392 | + $level_text = apply_filters('give_form_level_text', ! empty($price['_give_text']) ? $price['_give_text'] : give_currency_filter(give_format_amount($price['_give_amount'])), $form_id, $price); |
|
| 393 | + $level_classes = apply_filters('give_form_level_classes', 'give-donation-level-'.$form_id, $form_id, $price); |
|
| 394 | 394 | |
| 395 | - $output .= '<option data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
|
| 395 | + $output .= '<option data-price-id="'.$price['_give_id']['level_id'].'" class="'.$level_classes.'" '.((isset($price['_give_default']) && $price['_give_default'] === 'default') ? 'selected="selected"' : '').' value="'.give_format_amount($price['_give_amount']).'">'; |
|
| 396 | 396 | $output .= $level_text; |
| 397 | 397 | $output .= '</option>'; |
| 398 | 398 | |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | //Custom Amount |
| 402 | - if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
|
| 403 | - $output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>'; |
|
| 402 | + if ($custom_amount === 'yes' && ! empty($custom_amount_text)) { |
|
| 403 | + $output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">'.$custom_amount_text.'</option>'; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | $output .= '</select>'; |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | break; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - echo apply_filters( 'give_form_level_output', $output, $form_id ); |
|
| 411 | + echo apply_filters('give_form_level_output', $output, $form_id); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -420,26 +420,26 @@ discard block |
||
| 420 | 420 | * @param array $args |
| 421 | 421 | * |
| 422 | 422 | */ |
| 423 | -function give_display_checkout_button( $form_id, $args ) { |
|
| 423 | +function give_display_checkout_button($form_id, $args) { |
|
| 424 | 424 | |
| 425 | - $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
|
| 425 | + $display_option = (isset($args['display_style']) && ! empty($args['display_style'])) |
|
| 426 | 426 | ? $args['display_style'] |
| 427 | - : get_post_meta( $form_id, '_give_payment_display', true ); |
|
| 427 | + : get_post_meta($form_id, '_give_payment_display', true); |
|
| 428 | 428 | |
| 429 | 429 | //no btn for onpage |
| 430 | - if ( $display_option === 'onpage' ) { |
|
| 430 | + if ($display_option === 'onpage') { |
|
| 431 | 431 | return; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - $display_label_field = get_post_meta( $form_id, '_give_reveal_label', true ); |
|
| 435 | - $display_label = ( ! empty( $display_label_field ) ? $display_label_field : __( 'Donate Now', 'give' ) ); |
|
| 434 | + $display_label_field = get_post_meta($form_id, '_give_reveal_label', true); |
|
| 435 | + $display_label = ( ! empty($display_label_field) ? $display_label_field : __('Donate Now', 'give')); |
|
| 436 | 436 | |
| 437 | - $output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>'; |
|
| 437 | + $output = '<button type="button" class="give-btn give-btn-'.$display_option.'">'.$display_label.'</button>'; |
|
| 438 | 438 | |
| 439 | - echo apply_filters( 'give_display_checkout_button', $output ); |
|
| 439 | + echo apply_filters('give_display_checkout_button', $output); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | -add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 ); |
|
| 442 | +add_action('give_after_donation_levels', 'give_display_checkout_button', 10, 2); |
|
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided. |
@@ -450,71 +450,71 @@ discard block |
||
| 450 | 450 | * |
| 451 | 451 | * @return void |
| 452 | 452 | */ |
| 453 | -function give_user_info_fields( $form_id ) { |
|
| 453 | +function give_user_info_fields($form_id) { |
|
| 454 | 454 | |
| 455 | - if ( is_user_logged_in() ) : |
|
| 456 | - $user_data = get_userdata( get_current_user_id() ); |
|
| 455 | + if (is_user_logged_in()) : |
|
| 456 | + $user_data = get_userdata(get_current_user_id()); |
|
| 457 | 457 | endif; |
| 458 | 458 | |
| 459 | - do_action( 'give_purchase_form_before_personal_info', $form_id ); |
|
| 459 | + do_action('give_purchase_form_before_personal_info', $form_id); |
|
| 460 | 460 | ?> |
| 461 | 461 | <fieldset id="give_checkout_user_info"> |
| 462 | - <legend><?php echo apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ); ?></legend> |
|
| 462 | + <legend><?php echo apply_filters('give_checkout_personal_info_text', __('Personal Info', 'give')); ?></legend> |
|
| 463 | 463 | <p id="give-first-name-wrap" class="form-row form-row-first"> |
| 464 | 464 | <label class="give-label" for="give-first"> |
| 465 | - <?php _e( 'First Name', 'give' ); ?> |
|
| 466 | - <?php if ( give_field_is_required( 'give_first', $form_id ) ) { ?> |
|
| 465 | + <?php _e('First Name', 'give'); ?> |
|
| 466 | + <?php if (give_field_is_required('give_first', $form_id)) { ?> |
|
| 467 | 467 | <span class="give-required-indicator">*</span> |
| 468 | 468 | <?php } ?> |
| 469 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span> |
|
| 469 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('We will use this to personalize your account experience.', 'give'); ?>"></span> |
|
| 470 | 470 | </label> |
| 471 | - <input class="give-input required" type="text" name="give_first" placeholder="<?php _e( 'First name', 'give' ); ?>" id="give-first" value="<?php echo is_user_logged_in() ? $user_data->first_name : ''; ?>"<?php if ( give_field_is_required( 'give_first', $form_id ) ) { |
|
| 471 | + <input class="give-input required" type="text" name="give_first" placeholder="<?php _e('First name', 'give'); ?>" id="give-first" value="<?php echo is_user_logged_in() ? $user_data->first_name : ''; ?>"<?php if (give_field_is_required('give_first', $form_id)) { |
|
| 472 | 472 | echo ' required '; |
| 473 | 473 | } ?>/> |
| 474 | 474 | </p> |
| 475 | 475 | |
| 476 | 476 | <p id="give-last-name-wrap" class="form-row form-row-last"> |
| 477 | 477 | <label class="give-label" for="give-last"> |
| 478 | - <?php _e( 'Last Name', 'give' ); ?> |
|
| 479 | - <?php if ( give_field_is_required( 'give_last', $form_id ) ) { ?> |
|
| 478 | + <?php _e('Last Name', 'give'); ?> |
|
| 479 | + <?php if (give_field_is_required('give_last', $form_id)) { ?> |
|
| 480 | 480 | <span class="give-required-indicator">*</span> |
| 481 | 481 | <?php } ?> |
| 482 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span> |
|
| 482 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('We will use this as well to personalize your account experience.', 'give'); ?>"></span> |
|
| 483 | 483 | </label> |
| 484 | 484 | |
| 485 | - <input class="give-input<?php if ( give_field_is_required( 'give_last', $form_id ) ) { |
|
| 485 | + <input class="give-input<?php if (give_field_is_required('give_last', $form_id)) { |
|
| 486 | 486 | echo ' required'; |
| 487 | - } ?>" type="text" name="give_last" id="give-last" placeholder="<?php _e( 'Last name', 'give' ); ?>" value="<?php echo is_user_logged_in() ? $user_data->last_name : ''; ?>"<?php if ( give_field_is_required( 'give_last', $form_id ) ) { |
|
| 487 | + } ?>" type="text" name="give_last" id="give-last" placeholder="<?php _e('Last name', 'give'); ?>" value="<?php echo is_user_logged_in() ? $user_data->last_name : ''; ?>"<?php if (give_field_is_required('give_last', $form_id)) { |
|
| 488 | 488 | echo ' required '; |
| 489 | 489 | } ?> /> |
| 490 | 490 | </p> |
| 491 | 491 | |
| 492 | - <?php do_action( 'give_purchase_form_before_email', $form_id ); ?> |
|
| 492 | + <?php do_action('give_purchase_form_before_email', $form_id); ?> |
|
| 493 | 493 | <p id="give-email-wrap" class="form-row form-row-wide"> |
| 494 | 494 | <label class="give-label" for="give-email"> |
| 495 | - <?php _e( 'Email Address', 'give' ); ?> |
|
| 496 | - <?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?> |
|
| 495 | + <?php _e('Email Address', 'give'); ?> |
|
| 496 | + <?php if (give_field_is_required('give_email', $form_id)) { ?> |
|
| 497 | 497 | <span class="give-required-indicator">*</span> |
| 498 | 498 | <?php } ?> |
| 499 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'We will send the purchase receipt to this address.', 'give' ); ?>"></span> |
|
| 499 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('We will send the purchase receipt to this address.', 'give'); ?>"></span> |
|
| 500 | 500 | </label> |
| 501 | 501 | |
| 502 | - <input class="give-input required" type="email" name="give_email" placeholder="<?php _e( 'Email address', 'give' ); ?>" id="give-email" value="<?php echo is_user_logged_in() ? $user_data->user_email : ''; ?>"<?php if ( give_field_is_required( 'give_email', $form_id ) ) { |
|
| 502 | + <input class="give-input required" type="email" name="give_email" placeholder="<?php _e('Email address', 'give'); ?>" id="give-email" value="<?php echo is_user_logged_in() ? $user_data->user_email : ''; ?>"<?php if (give_field_is_required('give_email', $form_id)) { |
|
| 503 | 503 | echo ' required '; |
| 504 | 504 | } ?>/> |
| 505 | 505 | |
| 506 | 506 | </p> |
| 507 | - <?php do_action( 'give_purchase_form_after_email', $form_id ); ?> |
|
| 507 | + <?php do_action('give_purchase_form_after_email', $form_id); ?> |
|
| 508 | 508 | |
| 509 | - <?php do_action( 'give_purchase_form_user_info', $form_id ); ?> |
|
| 509 | + <?php do_action('give_purchase_form_user_info', $form_id); ?> |
|
| 510 | 510 | </fieldset> |
| 511 | 511 | <?php |
| 512 | - do_action( 'give_purchase_form_after_personal_info', $form_id ); |
|
| 512 | + do_action('give_purchase_form_after_personal_info', $form_id); |
|
| 513 | 513 | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | -add_action( 'give_purchase_form_after_user_info', 'give_user_info_fields' ); |
|
| 517 | -add_action( 'give_register_fields_before', 'give_user_info_fields' ); |
|
| 516 | +add_action('give_purchase_form_after_user_info', 'give_user_info_fields'); |
|
| 517 | +add_action('give_register_fields_before', 'give_user_info_fields'); |
|
| 518 | 518 | |
| 519 | 519 | /** |
| 520 | 520 | * Renders the credit card info form. |
@@ -525,73 +525,73 @@ discard block |
||
| 525 | 525 | * |
| 526 | 526 | * @return void |
| 527 | 527 | */ |
| 528 | -function give_get_cc_form( $form_id ) { |
|
| 528 | +function give_get_cc_form($form_id) { |
|
| 529 | 529 | |
| 530 | 530 | ob_start(); |
| 531 | 531 | |
| 532 | - do_action( 'give_before_cc_fields', $form_id ); ?> |
|
| 532 | + do_action('give_before_cc_fields', $form_id); ?> |
|
| 533 | 533 | |
| 534 | 534 | <fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate"> |
| 535 | - <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', __( 'Credit Card Info', 'give' ) ); ?></legend> |
|
| 536 | - <?php if ( is_ssl() ) : ?> |
|
| 535 | + <legend><?php echo apply_filters('give_credit_card_fieldset_heading', __('Credit Card Info', 'give')); ?></legend> |
|
| 536 | + <?php if (is_ssl()) : ?> |
|
| 537 | 537 | <div id="give_secure_site_wrapper-<?php echo $form_id ?>"> |
| 538 | 538 | <span class="give-icon padlock"></span> |
| 539 | - <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span> |
|
| 539 | + <span><?php _e('This is a secure SSL encrypted payment.', 'give'); ?></span> |
|
| 540 | 540 | </div> |
| 541 | 541 | <?php endif; ?> |
| 542 | 542 | <p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds"> |
| 543 | 543 | <label for="card_number-<?php echo $form_id ?>" class="give-label"> |
| 544 | - <?php _e( 'Card Number', 'give' ); ?> |
|
| 544 | + <?php _e('Card Number', 'give'); ?> |
|
| 545 | 545 | <span class="give-required-indicator">*</span> |
| 546 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span> |
|
| 546 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The (typically) 16 digits on the front of your credit card.', 'give'); ?>"></span> |
|
| 547 | 547 | <span class="card-type"></span> |
| 548 | 548 | </label> |
| 549 | 549 | |
| 550 | - <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>" class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>" required/> |
|
| 550 | + <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>" class="card-number give-input required" placeholder="<?php _e('Card number', 'give'); ?>" required/> |
|
| 551 | 551 | </p> |
| 552 | 552 | |
| 553 | 553 | <p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third"> |
| 554 | 554 | <label for="card_cvc-<?php echo $form_id ?>" class="give-label"> |
| 555 | - <?php _e( 'CVC', 'give' ); ?> |
|
| 555 | + <?php _e('CVC', 'give'); ?> |
|
| 556 | 556 | <span class="give-required-indicator">*</span> |
| 557 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span> |
|
| 557 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The 3 digit (back) or 4 digit (front) value on your card.', 'give'); ?>"></span> |
|
| 558 | 558 | </label> |
| 559 | 559 | |
| 560 | - <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>" class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>" required/> |
|
| 560 | + <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>" class="card-cvc give-input required" placeholder="<?php _e('Security code', 'give'); ?>" required/> |
|
| 561 | 561 | </p> |
| 562 | 562 | |
| 563 | 563 | <p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds"> |
| 564 | 564 | <label for="card_name-<?php echo $form_id ?>" class="give-label"> |
| 565 | - <?php _e( 'Name on the Card', 'give' ); ?> |
|
| 565 | + <?php _e('Name on the Card', 'give'); ?> |
|
| 566 | 566 | <span class="give-required-indicator">*</span> |
| 567 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span> |
|
| 567 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The name printed on the front of your credit card.', 'give'); ?>"></span> |
|
| 568 | 568 | </label> |
| 569 | 569 | |
| 570 | - <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>" class="card-name give-input required" placeholder="<?php _e( 'Card name', 'give' ); ?>" required/> |
|
| 570 | + <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>" class="card-name give-input required" placeholder="<?php _e('Card name', 'give'); ?>" required/> |
|
| 571 | 571 | </p> |
| 572 | - <?php do_action( 'give_before_cc_expiration' ); ?> |
|
| 572 | + <?php do_action('give_before_cc_expiration'); ?> |
|
| 573 | 573 | <p class="card-expiration form-row form-row-one-third"> |
| 574 | 574 | <label for="card_expiry-<?php echo $form_id ?>" class="give-label"> |
| 575 | - <?php _e( 'Expiration', 'give' ); ?> |
|
| 575 | + <?php _e('Expiration', 'give'); ?> |
|
| 576 | 576 | <span class="give-required-indicator">*</span> |
| 577 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span> |
|
| 577 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The date your credit card expires, typically on the front of the card.', 'give'); ?>"></span> |
|
| 578 | 578 | </label> |
| 579 | 579 | |
| 580 | 580 | <input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/> |
| 581 | 581 | <input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/> |
| 582 | 582 | |
| 583 | - <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php _e( 'MM / YY', 'give' ); ?>" required/> |
|
| 583 | + <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php _e('MM / YY', 'give'); ?>" required/> |
|
| 584 | 584 | </p> |
| 585 | - <?php do_action( 'give_after_cc_expiration', $form_id ); ?> |
|
| 585 | + <?php do_action('give_after_cc_expiration', $form_id); ?> |
|
| 586 | 586 | |
| 587 | 587 | </fieldset> |
| 588 | 588 | <?php |
| 589 | - do_action( 'give_after_cc_fields', $form_id ); |
|
| 589 | + do_action('give_after_cc_fields', $form_id); |
|
| 590 | 590 | |
| 591 | 591 | echo ob_get_clean(); |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | -add_action( 'give_cc_form', 'give_get_cc_form' ); |
|
| 594 | +add_action('give_cc_form', 'give_get_cc_form'); |
|
| 595 | 595 | |
| 596 | 596 | /** |
| 597 | 597 | * Outputs the default credit card address fields |
@@ -602,110 +602,110 @@ discard block |
||
| 602 | 602 | * |
| 603 | 603 | * @return void |
| 604 | 604 | */ |
| 605 | -function give_default_cc_address_fields( $form_id ) { |
|
| 605 | +function give_default_cc_address_fields($form_id) { |
|
| 606 | 606 | |
| 607 | 607 | $logged_in = is_user_logged_in(); |
| 608 | 608 | |
| 609 | - if ( $logged_in ) { |
|
| 610 | - $user_address = get_user_meta( get_current_user_id(), '_give_user_address', true ); |
|
| 609 | + if ($logged_in) { |
|
| 610 | + $user_address = get_user_meta(get_current_user_id(), '_give_user_address', true); |
|
| 611 | 611 | } |
| 612 | - $line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : ''; |
|
| 613 | - $line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : ''; |
|
| 614 | - $city = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : ''; |
|
| 615 | - $zip = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : ''; |
|
| 612 | + $line1 = $logged_in && ! empty($user_address['line1']) ? $user_address['line1'] : ''; |
|
| 613 | + $line2 = $logged_in && ! empty($user_address['line2']) ? $user_address['line2'] : ''; |
|
| 614 | + $city = $logged_in && ! empty($user_address['city']) ? $user_address['city'] : ''; |
|
| 615 | + $zip = $logged_in && ! empty($user_address['zip']) ? $user_address['zip'] : ''; |
|
| 616 | 616 | ob_start(); ?> |
| 617 | 617 | <fieldset id="give_cc_address" class="cc-address"> |
| 618 | - <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', __( 'Billing Details', 'give' ) ); ?></legend> |
|
| 619 | - <?php do_action( 'give_cc_billing_top' ); ?> |
|
| 618 | + <legend><?php echo apply_filters('give_billing_details_fieldset_heading', __('Billing Details', 'give')); ?></legend> |
|
| 619 | + <?php do_action('give_cc_billing_top'); ?> |
|
| 620 | 620 | <p id="give-card-address-wrap" class="form-row form-row-two-thirds"> |
| 621 | 621 | <label for="card_address" class="give-label"> |
| 622 | - <?php _e( 'Address', 'give' ); ?> |
|
| 622 | + <?php _e('Address', 'give'); ?> |
|
| 623 | 623 | <?php |
| 624 | - if ( give_field_is_required( 'card_address', $form_id ) ) { ?> |
|
| 624 | + if (give_field_is_required('card_address', $form_id)) { ?> |
|
| 625 | 625 | <span class="give-required-indicator">*</span> |
| 626 | 626 | <?php } ?> |
| 627 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The primary billing address for your credit card.', 'give' ); ?>"></span> |
|
| 627 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The primary billing address for your credit card.', 'give'); ?>"></span> |
|
| 628 | 628 | </label> |
| 629 | 629 | |
| 630 | - <input type="text" id="card_address" name="card_address" class="card-address give-input<?php if ( give_field_is_required( 'card_address', $form_id ) ) { |
|
| 630 | + <input type="text" id="card_address" name="card_address" class="card-address give-input<?php if (give_field_is_required('card_address', $form_id)) { |
|
| 631 | 631 | echo ' required'; |
| 632 | - } ?>" placeholder="<?php _e( 'Address line 1', 'give' ); ?>" value="<?php echo $line1; ?>"<?php if ( give_field_is_required( 'card_address', $form_id ) ) { |
|
| 632 | + } ?>" placeholder="<?php _e('Address line 1', 'give'); ?>" value="<?php echo $line1; ?>"<?php if (give_field_is_required('card_address', $form_id)) { |
|
| 633 | 633 | echo ' required '; |
| 634 | 634 | } ?>/> |
| 635 | 635 | </p> |
| 636 | 636 | |
| 637 | 637 | <p id="give-card-address-2-wrap" class="form-row form-row-one-third"> |
| 638 | 638 | <label for="card_address_2" class="give-label"> |
| 639 | - <?php _e( 'Address Line 2', 'give' ); ?> |
|
| 640 | - <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { ?> |
|
| 639 | + <?php _e('Address Line 2', 'give'); ?> |
|
| 640 | + <?php if (give_field_is_required('card_address_2', $form_id)) { ?> |
|
| 641 | 641 | <span class="give-required-indicator">*</span> |
| 642 | 642 | <?php } ?> |
| 643 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span> |
|
| 643 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give'); ?>"></span> |
|
| 644 | 644 | </label> |
| 645 | 645 | |
| 646 | - <input type="text" id="card_address_2" name="card_address_2" class="card-address-2 give-input<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { |
|
| 646 | + <input type="text" id="card_address_2" name="card_address_2" class="card-address-2 give-input<?php if (give_field_is_required('card_address_2', $form_id)) { |
|
| 647 | 647 | echo ' required'; |
| 648 | - } ?>" placeholder="<?php _e( 'Address line 2', 'give' ); ?>" value="<?php echo $line2; ?>"<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { |
|
| 648 | + } ?>" placeholder="<?php _e('Address line 2', 'give'); ?>" value="<?php echo $line2; ?>"<?php if (give_field_is_required('card_address_2', $form_id)) { |
|
| 649 | 649 | echo ' required '; |
| 650 | 650 | } ?>/> |
| 651 | 651 | </p> |
| 652 | 652 | |
| 653 | 653 | <p id="give-card-city-wrap" class="form-row form-row-two-thirds"> |
| 654 | 654 | <label for="card_city" class="give-label"> |
| 655 | - <?php _e( 'City', 'give' ); ?> |
|
| 656 | - <?php if ( give_field_is_required( 'card_city', $form_id ) ) { ?> |
|
| 655 | + <?php _e('City', 'give'); ?> |
|
| 656 | + <?php if (give_field_is_required('card_city', $form_id)) { ?> |
|
| 657 | 657 | <span class="give-required-indicator">*</span> |
| 658 | 658 | <?php } ?> |
| 659 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The city for your billing address.', 'give' ); ?>"></span> |
|
| 659 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The city for your billing address.', 'give'); ?>"></span> |
|
| 660 | 660 | </label> |
| 661 | - <input type="text" id="card_city" name="card_city" class="card-city give-input<?php if ( give_field_is_required( 'card_city', $form_id ) ) { |
|
| 661 | + <input type="text" id="card_city" name="card_city" class="card-city give-input<?php if (give_field_is_required('card_city', $form_id)) { |
|
| 662 | 662 | echo ' required'; |
| 663 | - } ?>" placeholder="<?php _e( 'City', 'give' ); ?>" value="<?php echo $city; ?>"<?php if ( give_field_is_required( 'card_city', $form_id ) ) { |
|
| 663 | + } ?>" placeholder="<?php _e('City', 'give'); ?>" value="<?php echo $city; ?>"<?php if (give_field_is_required('card_city', $form_id)) { |
|
| 664 | 664 | echo ' required '; |
| 665 | 665 | } ?>/> |
| 666 | 666 | </p> |
| 667 | 667 | |
| 668 | 668 | <p id="give-card-zip-wrap" class="form-row form-row-one-third"> |
| 669 | 669 | <label for="card_zip" class="give-label"> |
| 670 | - <?php _e( 'Zip / Postal Code', 'give' ); ?> |
|
| 671 | - <?php if ( give_field_is_required( 'card_zip', $form_id ) ) { ?> |
|
| 670 | + <?php _e('Zip / Postal Code', 'give'); ?> |
|
| 671 | + <?php if (give_field_is_required('card_zip', $form_id)) { ?> |
|
| 672 | 672 | <span class="give-required-indicator">*</span> |
| 673 | 673 | <?php } ?> |
| 674 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span> |
|
| 674 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The zip or postal code for your billing address.', 'give'); ?>"></span> |
|
| 675 | 675 | </label> |
| 676 | 676 | |
| 677 | - <input type="text" size="4" id="card_zip" name="card_zip" class="card-zip give-input<?php if ( give_field_is_required( 'card_zip', $form_id ) ) { |
|
| 677 | + <input type="text" size="4" id="card_zip" name="card_zip" class="card-zip give-input<?php if (give_field_is_required('card_zip', $form_id)) { |
|
| 678 | 678 | echo ' required'; |
| 679 | - } ?>" placeholder="<?php _e( 'Zip / Postal code', 'give' ); ?>" value="<?php echo $zip; ?>" <?php if ( give_field_is_required( 'card_zip', $form_id ) ) { |
|
| 679 | + } ?>" placeholder="<?php _e('Zip / Postal code', 'give'); ?>" value="<?php echo $zip; ?>" <?php if (give_field_is_required('card_zip', $form_id)) { |
|
| 680 | 680 | echo ' required '; |
| 681 | 681 | } ?>/> |
| 682 | 682 | </p> |
| 683 | 683 | |
| 684 | 684 | <p id="give-card-country-wrap" class="form-row form-row-first"> |
| 685 | 685 | <label for="billing_country" class="give-label"> |
| 686 | - <?php _e( 'Country', 'give' ); ?> |
|
| 687 | - <?php if ( give_field_is_required( 'billing_country', $form_id ) ) { ?> |
|
| 686 | + <?php _e('Country', 'give'); ?> |
|
| 687 | + <?php if (give_field_is_required('billing_country', $form_id)) { ?> |
|
| 688 | 688 | <span class="give-required-indicator">*</span> |
| 689 | 689 | <?php } ?> |
| 690 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The country for your billing address.', 'give' ); ?>"></span> |
|
| 690 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The country for your billing address.', 'give'); ?>"></span> |
|
| 691 | 691 | </label> |
| 692 | 692 | |
| 693 | - <select name="billing_country" id="billing_country" class="billing-country billing_country give-select<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { |
|
| 693 | + <select name="billing_country" id="billing_country" class="billing-country billing_country give-select<?php if (give_field_is_required('billing_country', $form_id)) { |
|
| 694 | 694 | echo ' required'; |
| 695 | - } ?>"<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { |
|
| 695 | + } ?>"<?php if (give_field_is_required('billing_country', $form_id)) { |
|
| 696 | 696 | echo ' required '; |
| 697 | 697 | } ?>> |
| 698 | 698 | <?php |
| 699 | 699 | |
| 700 | 700 | $selected_country = give_get_country(); |
| 701 | 701 | |
| 702 | - if ( $logged_in && ! empty( $user_address['country'] ) && '*' !== $user_address['country'] ) { |
|
| 702 | + if ($logged_in && ! empty($user_address['country']) && '*' !== $user_address['country']) { |
|
| 703 | 703 | $selected_country = $user_address['country']; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | $countries = give_get_country_list(); |
| 707 | - foreach ( $countries as $country_code => $country ) { |
|
| 708 | - echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
|
| 707 | + foreach ($countries as $country_code => $country) { |
|
| 708 | + echo '<option value="'.esc_attr($country_code).'"'.selected($country_code, $selected_country, false).'>'.$country.'</option>'; |
|
| 709 | 709 | } |
| 710 | 710 | ?> |
| 711 | 711 | </select> |
@@ -713,44 +713,44 @@ discard block |
||
| 713 | 713 | |
| 714 | 714 | <p id="give-card-state-wrap" class="form-row form-row-last"> |
| 715 | 715 | <label for="card_state" class="give-label"> |
| 716 | - <?php _e( 'State / Province', 'give' ); ?> |
|
| 717 | - <?php if ( give_field_is_required( 'card_state', $form_id ) ) { ?> |
|
| 716 | + <?php _e('State / Province', 'give'); ?> |
|
| 717 | + <?php if (give_field_is_required('card_state', $form_id)) { ?> |
|
| 718 | 718 | <span class="give-required-indicator">*</span> |
| 719 | 719 | <?php } ?> |
| 720 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The state or province for your billing address.', 'give' ); ?>"></span> |
|
| 720 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The state or province for your billing address.', 'give'); ?>"></span> |
|
| 721 | 721 | </label> |
| 722 | 722 | |
| 723 | 723 | <?php |
| 724 | 724 | $selected_state = give_get_state(); |
| 725 | - $states = give_get_states( $selected_country ); |
|
| 725 | + $states = give_get_states($selected_country); |
|
| 726 | 726 | |
| 727 | - if ( $logged_in && ! empty( $user_address['state'] ) ) { |
|
| 727 | + if ($logged_in && ! empty($user_address['state'])) { |
|
| 728 | 728 | $selected_state = $user_address['state']; |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - if ( ! empty( $states ) ) : ?> |
|
| 732 | - <select name="card_state" id="card_state" class="card_state give-select<?php if ( give_field_is_required( 'card_state', $form_id ) ) { |
|
| 731 | + if ( ! empty($states)) : ?> |
|
| 732 | + <select name="card_state" id="card_state" class="card_state give-select<?php if (give_field_is_required('card_state', $form_id)) { |
|
| 733 | 733 | echo ' required'; |
| 734 | - } ?>"<?php if ( give_field_is_required( 'card_state', $form_id ) ) { |
|
| 734 | + } ?>"<?php if (give_field_is_required('card_state', $form_id)) { |
|
| 735 | 735 | echo ' required '; |
| 736 | 736 | } ?>> |
| 737 | 737 | <?php |
| 738 | - foreach ( $states as $state_code => $state ) { |
|
| 739 | - echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
|
| 738 | + foreach ($states as $state_code => $state) { |
|
| 739 | + echo '<option value="'.$state_code.'"'.selected($state_code, $selected_state, false).'>'.$state.'</option>'; |
|
| 740 | 740 | } |
| 741 | 741 | ?> |
| 742 | 742 | </select> |
| 743 | 743 | <?php else : ?> |
| 744 | - <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php _e( 'State / Province', 'give' ); ?>"/> |
|
| 744 | + <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php _e('State / Province', 'give'); ?>"/> |
|
| 745 | 745 | <?php endif; ?> |
| 746 | 746 | </p> |
| 747 | - <?php do_action( 'give_cc_billing_bottom' ); ?> |
|
| 747 | + <?php do_action('give_cc_billing_bottom'); ?> |
|
| 748 | 748 | </fieldset> |
| 749 | 749 | <?php |
| 750 | 750 | echo ob_get_clean(); |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | -add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
|
| 753 | +add_action('give_after_cc_fields', 'give_default_cc_address_fields'); |
|
| 754 | 754 | |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -762,94 +762,94 @@ discard block |
||
| 762 | 762 | * |
| 763 | 763 | * @return string |
| 764 | 764 | */ |
| 765 | -function give_get_register_fields( $form_id ) { |
|
| 765 | +function give_get_register_fields($form_id) { |
|
| 766 | 766 | |
| 767 | 767 | global $give_options; |
| 768 | 768 | global $user_ID; |
| 769 | 769 | |
| 770 | - if ( is_user_logged_in() ) { |
|
| 771 | - $user_data = get_userdata( $user_ID ); |
|
| 770 | + if (is_user_logged_in()) { |
|
| 771 | + $user_data = get_userdata($user_ID); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - $show_register_form = apply_filters( 'give_show_register_form', get_post_meta( $form_id, '_give_show_register_form', true ) ); |
|
| 774 | + $show_register_form = apply_filters('give_show_register_form', get_post_meta($form_id, '_give_show_register_form', true)); |
|
| 775 | 775 | |
| 776 | 776 | ob_start(); ?> |
| 777 | 777 | <fieldset id="give-register-fields-<?php echo $form_id; ?>"> |
| 778 | 778 | |
| 779 | - <?php if ( $show_register_form == 'both' ) { ?> |
|
| 779 | + <?php if ($show_register_form == 'both') { ?> |
|
| 780 | 780 | <div class="give-login-account-wrap"> |
| 781 | - <p class="give-login-message"><?php _e( 'Already have an account?', 'give' ); ?> |
|
| 782 | - <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-register-login" data-action="give_checkout_login"><?php _e( 'Login', 'give' ); ?></a> |
|
| 781 | + <p class="give-login-message"><?php _e('Already have an account?', 'give'); ?> |
|
| 782 | + <a href="<?php echo esc_url(add_query_arg('login', 1)); ?>" class="give-checkout-register-login" data-action="give_checkout_login"><?php _e('Login', 'give'); ?></a> |
|
| 783 | 783 | </p> |
| 784 | 784 | <p class="give-loading-text"> |
| 785 | - <span class="give-loading-animation"></span> <?php _e( 'Loading...', 'give' ); ?></p> |
|
| 785 | + <span class="give-loading-animation"></span> <?php _e('Loading...', 'give'); ?></p> |
|
| 786 | 786 | </div> |
| 787 | 787 | <?php } ?> |
| 788 | 788 | |
| 789 | - <?php do_action( 'give_register_fields_before' ); ?> |
|
| 789 | + <?php do_action('give_register_fields_before'); ?> |
|
| 790 | 790 | |
| 791 | 791 | <fieldset id="give-register-account-fields-<?php echo $form_id; ?>"> |
| 792 | - <legend><?php echo apply_filters( 'give_create_account_fieldset_heading', __( 'Create an account', 'give' ) ); |
|
| 793 | - if ( ! give_no_guest_checkout( $form_id ) ) { |
|
| 794 | - echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>'; |
|
| 792 | + <legend><?php echo apply_filters('give_create_account_fieldset_heading', __('Create an account', 'give')); |
|
| 793 | + if ( ! give_no_guest_checkout($form_id)) { |
|
| 794 | + echo ' <span class="sub-text">'.__('(optional)', 'give').'</span>'; |
|
| 795 | 795 | } ?></legend> |
| 796 | - <?php do_action( 'give_register_account_fields_before' ); ?> |
|
| 796 | + <?php do_action('give_register_account_fields_before'); ?> |
|
| 797 | 797 | <p id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-first"> |
| 798 | 798 | <label for="give-user-login-<?php echo $form_id; ?>"> |
| 799 | - <?php _e( 'Username', 'give' ); ?> |
|
| 800 | - <?php if ( give_no_guest_checkout( $form_id ) ) { ?> |
|
| 799 | + <?php _e('Username', 'give'); ?> |
|
| 800 | + <?php if (give_no_guest_checkout($form_id)) { ?> |
|
| 801 | 801 | <span class="give-required-indicator">*</span> |
| 802 | 802 | <?php } ?> |
| 803 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The username you will use to log into your account.', 'give' ); ?>"></span> |
|
| 803 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The username you will use to log into your account.', 'give'); ?>"></span> |
|
| 804 | 804 | </label> |
| 805 | 805 | |
| 806 | - <input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="<?php if ( give_no_guest_checkout( $form_id ) ) { |
|
| 806 | + <input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="<?php if (give_no_guest_checkout($form_id)) { |
|
| 807 | 807 | echo 'required '; |
| 808 | - } ?>give-input" type="text" placeholder="<?php _e( 'Username', 'give' ); ?>" title="<?php _e( 'Username', 'give' ); ?>"/> |
|
| 808 | + } ?>give-input" type="text" placeholder="<?php _e('Username', 'give'); ?>" title="<?php _e('Username', 'give'); ?>"/> |
|
| 809 | 809 | </p> |
| 810 | 810 | |
| 811 | 811 | <p id="give-user-pass-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third"> |
| 812 | 812 | <label for="give-user-pass-<?php echo $form_id; ?>"> |
| 813 | - <?php _e( 'Password', 'give' ); ?> |
|
| 814 | - <?php if ( give_no_guest_checkout( $form_id ) ) { ?> |
|
| 813 | + <?php _e('Password', 'give'); ?> |
|
| 814 | + <?php if (give_no_guest_checkout($form_id)) { ?> |
|
| 815 | 815 | <span class="give-required-indicator">*</span> |
| 816 | 816 | <?php } ?> |
| 817 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'The password used to access your account.', 'give' ); ?>"></span> |
|
| 817 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('The password used to access your account.', 'give'); ?>"></span> |
|
| 818 | 818 | </label> |
| 819 | 819 | |
| 820 | - <input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="<?php if ( give_no_guest_checkout( $form_id ) ) { |
|
| 820 | + <input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="<?php if (give_no_guest_checkout($form_id)) { |
|
| 821 | 821 | echo 'required '; |
| 822 | - } ?>give-input" placeholder="<?php _e( 'Password', 'give' ); ?>" type="password"/> |
|
| 822 | + } ?>give-input" placeholder="<?php _e('Password', 'give'); ?>" type="password"/> |
|
| 823 | 823 | </p> |
| 824 | 824 | |
| 825 | 825 | <p id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>" class="give-register-password form-row form-row-one-third"> |
| 826 | 826 | <label for="give-user-pass-confirm-<?php echo $form_id; ?>"> |
| 827 | - <?php _e( 'Confirm Password', 'give' ); ?> |
|
| 828 | - <?php if ( give_no_guest_checkout( $form_id ) ) { ?> |
|
| 827 | + <?php _e('Confirm Password', 'give'); ?> |
|
| 828 | + <?php if (give_no_guest_checkout($form_id)) { ?> |
|
| 829 | 829 | <span class="give-required-indicator">*</span> |
| 830 | 830 | <?php } ?> |
| 831 | - <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e( 'Please retype your password to confirm.', 'give' ); ?>"></span> |
|
| 831 | + <span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php _e('Please retype your password to confirm.', 'give'); ?>"></span> |
|
| 832 | 832 | </label> |
| 833 | 833 | |
| 834 | - <input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>" class="<?php if ( give_no_guest_checkout( $form_id ) ) { |
|
| 834 | + <input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>" class="<?php if (give_no_guest_checkout($form_id)) { |
|
| 835 | 835 | echo 'required '; |
| 836 | - } ?>give-input" placeholder="<?php _e( 'Confirm password', 'give' ); ?>" type="password"/> |
|
| 836 | + } ?>give-input" placeholder="<?php _e('Confirm password', 'give'); ?>" type="password"/> |
|
| 837 | 837 | </p> |
| 838 | - <?php do_action( 'give_register_account_fields_after', $form_id ); ?> |
|
| 838 | + <?php do_action('give_register_account_fields_after', $form_id); ?> |
|
| 839 | 839 | </fieldset> |
| 840 | 840 | |
| 841 | - <?php do_action( 'give_register_fields_after', $form_id ); ?> |
|
| 841 | + <?php do_action('give_register_fields_after', $form_id); ?> |
|
| 842 | 842 | |
| 843 | 843 | <input type="hidden" name="give-purchase-var" value="needs-to-register"/> |
| 844 | 844 | |
| 845 | - <?php do_action( 'give_purchase_form_user_info', $form_id ); ?> |
|
| 845 | + <?php do_action('give_purchase_form_user_info', $form_id); ?> |
|
| 846 | 846 | |
| 847 | 847 | </fieldset> |
| 848 | 848 | <?php |
| 849 | 849 | echo ob_get_clean(); |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | -add_action( 'give_purchase_form_register_fields', 'give_get_register_fields' ); |
|
| 852 | +add_action('give_purchase_form_register_fields', 'give_get_register_fields'); |
|
| 853 | 853 | |
| 854 | 854 | /** |
| 855 | 855 | * Gets the login fields for the login form on the checkout. This function hooks |
@@ -862,76 +862,76 @@ discard block |
||
| 862 | 862 | * |
| 863 | 863 | * @return string |
| 864 | 864 | */ |
| 865 | -function give_get_login_fields( $form_id ) { |
|
| 865 | +function give_get_login_fields($form_id) { |
|
| 866 | 866 | |
| 867 | 867 | global $give_options; |
| 868 | 868 | |
| 869 | - $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id; |
|
| 870 | - $show_register_form = apply_filters( 'give_show_register_form', get_post_meta( $form_id, '_give_show_register_form', true ) ); |
|
| 869 | + $form_id = isset($_POST['form_id']) ? $_POST['form_id'] : $form_id; |
|
| 870 | + $show_register_form = apply_filters('give_show_register_form', get_post_meta($form_id, '_give_show_register_form', true)); |
|
| 871 | 871 | |
| 872 | 872 | ob_start(); |
| 873 | 873 | ?> |
| 874 | 874 | <fieldset id="give-login-fields-<?php echo $form_id; ?>"> |
| 875 | - <legend><?php echo apply_filters( 'give_account_login_fieldset_heading', __( 'Login to Your Account', 'give' ) ); |
|
| 876 | - if ( ! give_no_guest_checkout( $form_id ) ) { |
|
| 877 | - echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>'; |
|
| 875 | + <legend><?php echo apply_filters('give_account_login_fieldset_heading', __('Login to Your Account', 'give')); |
|
| 876 | + if ( ! give_no_guest_checkout($form_id)) { |
|
| 877 | + echo ' <span class="sub-text">'.__('(optional)', 'give').'</span>'; |
|
| 878 | 878 | } ?> |
| 879 | 879 | </legend> |
| 880 | - <?php if ( $show_register_form == 'both' ) { ?> |
|
| 880 | + <?php if ($show_register_form == 'both') { ?> |
|
| 881 | 881 | <p class="give-new-account-link"> |
| 882 | - <?php _e( 'Need to create an account?', 'give' ); ?> |
|
| 883 | - <a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-login" |
|
| 882 | + <?php _e('Need to create an account?', 'give'); ?> |
|
| 883 | + <a href="<?php echo remove_query_arg('login'); ?>" class="give-checkout-register-login" |
|
| 884 | 884 | data-action="give_checkout_register"> |
| 885 | - <?php _e( 'Register', 'give' ); |
|
| 886 | - if ( ! give_no_guest_checkout( $form_id ) ) { |
|
| 887 | - echo ' ' . __( 'or checkout as a guest.', 'give' ); |
|
| 885 | + <?php _e('Register', 'give'); |
|
| 886 | + if ( ! give_no_guest_checkout($form_id)) { |
|
| 887 | + echo ' '.__('or checkout as a guest.', 'give'); |
|
| 888 | 888 | } ?> |
| 889 | 889 | </a> |
| 890 | 890 | </p> |
| 891 | 891 | <p class="give-loading-text"> |
| 892 | - <span class="give-loading-animation"></span> <?php _e( 'Loading...', 'give' ); ?> </p> |
|
| 892 | + <span class="give-loading-animation"></span> <?php _e('Loading...', 'give'); ?> </p> |
|
| 893 | 893 | <?php } ?> |
| 894 | - <?php do_action( 'give_checkout_login_fields_before', $form_id ); ?> |
|
| 894 | + <?php do_action('give_checkout_login_fields_before', $form_id); ?> |
|
| 895 | 895 | <p id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first"> |
| 896 | 896 | <label class="give-label" for="give-user-login-<?php echo $form_id; ?>"> |
| 897 | - <?php _e( 'Username', 'give' ); ?> |
|
| 898 | - <?php if ( give_no_guest_checkout( $form_id ) ) { ?> |
|
| 897 | + <?php _e('Username', 'give'); ?> |
|
| 898 | + <?php if (give_no_guest_checkout($form_id)) { ?> |
|
| 899 | 899 | <span class="give-required-indicator">*</span> |
| 900 | 900 | <?php } ?> |
| 901 | 901 | </label> |
| 902 | 902 | |
| 903 | - <input class="<?php if ( give_no_guest_checkout( $form_id ) ) { |
|
| 903 | + <input class="<?php if (give_no_guest_checkout($form_id)) { |
|
| 904 | 904 | echo 'required '; |
| 905 | - } ?>give-input" type="text" name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" placeholder="<?php _e( 'Your username', 'give' ); ?>"/> |
|
| 905 | + } ?>give-input" type="text" name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" placeholder="<?php _e('Your username', 'give'); ?>"/> |
|
| 906 | 906 | </p> |
| 907 | 907 | |
| 908 | 908 | <p id="give-user-pass-wrap-<?php echo $form_id; ?>" class="give_login_password form-row form-row-last"> |
| 909 | 909 | <label class="give-label" for="give-user-pass-<?php echo $form_id; ?>"> |
| 910 | - <?php _e( 'Password', 'give' ); ?> |
|
| 911 | - <?php if ( give_no_guest_checkout( $form_id ) ) { ?> |
|
| 910 | + <?php _e('Password', 'give'); ?> |
|
| 911 | + <?php if (give_no_guest_checkout($form_id)) { ?> |
|
| 912 | 912 | <span class="give-required-indicator">*</span> |
| 913 | 913 | <?php } ?> |
| 914 | 914 | </label> |
| 915 | - <input class="<?php if ( give_no_guest_checkout( $form_id ) ) { |
|
| 915 | + <input class="<?php if (give_no_guest_checkout($form_id)) { |
|
| 916 | 916 | echo 'required '; |
| 917 | - } ?>give-input" type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" placeholder="<?php _e( 'Your password', 'give' ); ?>"/> |
|
| 917 | + } ?>give-input" type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" placeholder="<?php _e('Your password', 'give'); ?>"/> |
|
| 918 | 918 | <input type="hidden" name="give-purchase-var" value="needs-to-login"/> |
| 919 | 919 | </p> |
| 920 | 920 | |
| 921 | 921 | <p id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix"> |
| 922 | - <input type="submit" class="give-submit give-btn button" name="give_login_submit" value="<?php _e( 'Login', 'give' ); ?>"/> |
|
| 923 | - <?php if ( $show_register_form !== 'login' ) { ?> |
|
| 924 | - <input type="button" data-action="give_cancel_login" class="give-cancel-login give-btn button" name="give_login_cancel" value="<?php _e( 'Cancel', 'give' ); ?>"/> |
|
| 922 | + <input type="submit" class="give-submit give-btn button" name="give_login_submit" value="<?php _e('Login', 'give'); ?>"/> |
|
| 923 | + <?php if ($show_register_form !== 'login') { ?> |
|
| 924 | + <input type="button" data-action="give_cancel_login" class="give-cancel-login give-btn button" name="give_login_cancel" value="<?php _e('Cancel', 'give'); ?>"/> |
|
| 925 | 925 | <?php } ?> |
| 926 | 926 | <span class="give-loading-animation"></span> |
| 927 | 927 | </p> |
| 928 | - <?php do_action( 'give_checkout_login_fields_after' ); ?> |
|
| 928 | + <?php do_action('give_checkout_login_fields_after'); ?> |
|
| 929 | 929 | </fieldset><!--end #give-login-fields--> |
| 930 | 930 | <?php |
| 931 | 931 | echo ob_get_clean(); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | -add_action( 'give_purchase_form_login_fields', 'give_get_login_fields', 10, 1 ); |
|
| 934 | +add_action('give_purchase_form_login_fields', 'give_get_login_fields', 10, 1); |
|
| 935 | 935 | |
| 936 | 936 | /** |
| 937 | 937 | * Payment Mode Select |
@@ -947,48 +947,48 @@ discard block |
||
| 947 | 947 | * |
| 948 | 948 | * @return void |
| 949 | 949 | */ |
| 950 | -function give_payment_mode_select( $form_id ) { |
|
| 950 | +function give_payment_mode_select($form_id) { |
|
| 951 | 951 | |
| 952 | 952 | $gateways = give_get_enabled_payment_gateways(); |
| 953 | 953 | |
| 954 | - do_action( 'give_payment_mode_top', $form_id ); ?> |
|
| 954 | + do_action('give_payment_mode_top', $form_id); ?> |
|
| 955 | 955 | |
| 956 | 956 | <fieldset id="give-payment-mode-select"> |
| 957 | - <?php do_action( 'give_payment_mode_before_gateways_wrap' ); ?> |
|
| 957 | + <?php do_action('give_payment_mode_before_gateways_wrap'); ?> |
|
| 958 | 958 | <div id="give-payment-mode-wrap"> |
| 959 | - <legend class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', __( 'Select Payment Method', 'give' ) ); ?> |
|
| 960 | - <span class="give-loading-text"><span class="give-loading-animation"></span> <?php _e( 'Loading...', 'give' ); ?></span></legend> |
|
| 959 | + <legend class="give-payment-mode-label"><?php echo apply_filters('give_checkout_payment_method_text', __('Select Payment Method', 'give')); ?> |
|
| 960 | + <span class="give-loading-text"><span class="give-loading-animation"></span> <?php _e('Loading...', 'give'); ?></span></legend> |
|
| 961 | 961 | <?php |
| 962 | 962 | |
| 963 | - do_action( 'give_payment_mode_before_gateways' ) ?> |
|
| 963 | + do_action('give_payment_mode_before_gateways') ?> |
|
| 964 | 964 | |
| 965 | 965 | <ul id="give-gateway-radio-list"> |
| 966 | - <?php foreach ( $gateways as $gateway_id => $gateway ) : |
|
| 967 | - $checked = checked( $gateway_id, give_get_default_gateway( $form_id ), false ); |
|
| 966 | + <?php foreach ($gateways as $gateway_id => $gateway) : |
|
| 967 | + $checked = checked($gateway_id, give_get_default_gateway($form_id), false); |
|
| 968 | 968 | $checked_class = $checked ? ' give-gateway-option-selected' : ''; |
| 969 | - echo '<li><label for="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" class="give-gateway-option' . $checked_class . '" id="give-gateway-option-' . esc_attr( $gateway_id ) . '">'; |
|
| 970 | - echo '<input type="radio" name="payment-mode" class="give-gateway" id="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" value="' . esc_attr( $gateway_id ) . '"' . $checked . '>' . esc_html( $gateway['checkout_label'] ); |
|
| 969 | + echo '<li><label for="give-gateway-'.esc_attr($gateway_id).'-'.$form_id.'" class="give-gateway-option'.$checked_class.'" id="give-gateway-option-'.esc_attr($gateway_id).'">'; |
|
| 970 | + echo '<input type="radio" name="payment-mode" class="give-gateway" id="give-gateway-'.esc_attr($gateway_id).'-'.$form_id.'" value="'.esc_attr($gateway_id).'"'.$checked.'>'.esc_html($gateway['checkout_label']); |
|
| 971 | 971 | echo '</label></li>'; |
| 972 | 972 | endforeach; ?> |
| 973 | 973 | </ul> |
| 974 | - <?php do_action( 'give_payment_mode_after_gateways' ); ?> |
|
| 974 | + <?php do_action('give_payment_mode_after_gateways'); ?> |
|
| 975 | 975 | </div> |
| 976 | - <?php do_action( 'give_payment_mode_after_gateways_wrap' ); ?> |
|
| 976 | + <?php do_action('give_payment_mode_after_gateways_wrap'); ?> |
|
| 977 | 977 | </fieldset> |
| 978 | 978 | |
| 979 | - <?php do_action( 'give_payment_mode_bottom', $form_id ); ?> |
|
| 979 | + <?php do_action('give_payment_mode_bottom', $form_id); ?> |
|
| 980 | 980 | |
| 981 | 981 | <div id="give_purchase_form_wrap"> |
| 982 | 982 | |
| 983 | - <?php do_action( 'give_purchase_form', $form_id ); ?> |
|
| 983 | + <?php do_action('give_purchase_form', $form_id); ?> |
|
| 984 | 984 | |
| 985 | 985 | </div><!-- the checkout fields are loaded into this--> |
| 986 | 986 | |
| 987 | - <?php do_action( 'give_purchase_form_wrap_bottom', $form_id ); |
|
| 987 | + <?php do_action('give_purchase_form_wrap_bottom', $form_id); |
|
| 988 | 988 | |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | -add_action( 'give_payment_mode_select', 'give_payment_mode_select' ); |
|
| 991 | +add_action('give_payment_mode_select', 'give_payment_mode_select'); |
|
| 992 | 992 | |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -1003,35 +1003,35 @@ discard block |
||
| 1003 | 1003 | * |
| 1004 | 1004 | * @return void |
| 1005 | 1005 | */ |
| 1006 | -function give_terms_agreement( $form_id ) { |
|
| 1006 | +function give_terms_agreement($form_id) { |
|
| 1007 | 1007 | |
| 1008 | - $form_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
| 1009 | - $label = get_post_meta( $form_id, '_give_agree_label', true ); |
|
| 1010 | - $terms = get_post_meta( $form_id, '_give_agree_text', true ); |
|
| 1008 | + $form_option = get_post_meta($form_id, '_give_terms_option', true); |
|
| 1009 | + $label = get_post_meta($form_id, '_give_agree_label', true); |
|
| 1010 | + $terms = get_post_meta($form_id, '_give_agree_text', true); |
|
| 1011 | 1011 | |
| 1012 | - if ( $form_option === 'yes' && ! empty( $terms ) ) { ?> |
|
| 1012 | + if ($form_option === 'yes' && ! empty($terms)) { ?> |
|
| 1013 | 1013 | <fieldset id="give_terms_agreement"> |
| 1014 | 1014 | <div id="give_terms" style="display:none;"> |
| 1015 | 1015 | <?php |
| 1016 | - do_action( 'give_before_terms' ); |
|
| 1017 | - echo wpautop( stripslashes( $terms ) ); |
|
| 1018 | - do_action( 'give_after_terms' ); |
|
| 1016 | + do_action('give_before_terms'); |
|
| 1017 | + echo wpautop(stripslashes($terms)); |
|
| 1018 | + do_action('give_after_terms'); |
|
| 1019 | 1019 | ?> |
| 1020 | 1020 | </div> |
| 1021 | 1021 | <div id="give_show_terms"> |
| 1022 | - <a href="#" class="give_terms_links"><?php _e( 'Show Terms', 'give' ); ?></a> |
|
| 1023 | - <a href="#" class="give_terms_links" style="display:none;"><?php _e( 'Hide Terms', 'give' ); ?></a> |
|
| 1022 | + <a href="#" class="give_terms_links"><?php _e('Show Terms', 'give'); ?></a> |
|
| 1023 | + <a href="#" class="give_terms_links" style="display:none;"><?php _e('Hide Terms', 'give'); ?></a> |
|
| 1024 | 1024 | </div> |
| 1025 | 1025 | |
| 1026 | 1026 | <label |
| 1027 | - for="give_agree_to_terms"><?php echo ! empty( $label ) ? stripslashes( $label ) : __( 'Agree to Terms?', 'give' ); ?></label> |
|
| 1027 | + for="give_agree_to_terms"><?php echo ! empty($label) ? stripslashes($label) : __('Agree to Terms?', 'give'); ?></label> |
|
| 1028 | 1028 | <input name="give_agree_to_terms" class="required" type="checkbox" id="give_agree_to_terms" value="1"/> |
| 1029 | 1029 | </fieldset> |
| 1030 | 1030 | <?php |
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | -add_action( 'give_purchase_form_before_submit', 'give_terms_agreement', 10, 1 ); |
|
| 1034 | +add_action('give_purchase_form_before_submit', 'give_terms_agreement', 10, 1); |
|
| 1035 | 1035 | |
| 1036 | 1036 | /** |
| 1037 | 1037 | * Checkout Final Total |
@@ -1043,27 +1043,27 @@ discard block |
||
| 1043 | 1043 | * @since 1.0 |
| 1044 | 1044 | * @return void |
| 1045 | 1045 | */ |
| 1046 | -function give_checkout_final_total( $form_id ) { |
|
| 1046 | +function give_checkout_final_total($form_id) { |
|
| 1047 | 1047 | |
| 1048 | - if ( isset( $_POST['give_total'] ) ) { |
|
| 1049 | - $total = apply_filters( 'give_donation_total', $_POST['give_total'] ); |
|
| 1048 | + if (isset($_POST['give_total'])) { |
|
| 1049 | + $total = apply_filters('give_donation_total', $_POST['give_total']); |
|
| 1050 | 1050 | } else { |
| 1051 | 1051 | //default total |
| 1052 | - $total = give_get_default_form_amount( $form_id ); |
|
| 1052 | + $total = give_get_default_form_amount($form_id); |
|
| 1053 | 1053 | } |
| 1054 | 1054 | //Only proceed if give_total available |
| 1055 | - if ( empty( $total ) ) { |
|
| 1055 | + if (empty($total)) { |
|
| 1056 | 1056 | return; |
| 1057 | 1057 | } |
| 1058 | 1058 | ?> |
| 1059 | 1059 | <p id="give-final-total-wrap" class="form-wrap "> |
| 1060 | - <span class="give-donation-total-label"><?php echo apply_filters( 'give_donation_total_label', esc_attr__( 'Donation Total:', 'give' ) ); ?></span> |
|
| 1061 | - <span class="give-final-total-amount" data-total="<?php echo give_format_amount( $total ); ?>"><?php echo give_currency_filter( give_format_amount( $total ) ); ?></span> |
|
| 1060 | + <span class="give-donation-total-label"><?php echo apply_filters('give_donation_total_label', esc_attr__('Donation Total:', 'give')); ?></span> |
|
| 1061 | + <span class="give-final-total-amount" data-total="<?php echo give_format_amount($total); ?>"><?php echo give_currency_filter(give_format_amount($total)); ?></span> |
|
| 1062 | 1062 | </p> |
| 1063 | 1063 | <?php |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | -add_action( 'give_purchase_form_before_submit', 'give_checkout_final_total', 999 ); |
|
| 1066 | +add_action('give_purchase_form_before_submit', 'give_checkout_final_total', 999); |
|
| 1067 | 1067 | |
| 1068 | 1068 | |
| 1069 | 1069 | /** |
@@ -1075,22 +1075,22 @@ discard block |
||
| 1075 | 1075 | * |
| 1076 | 1076 | * @return void |
| 1077 | 1077 | */ |
| 1078 | -function give_checkout_submit( $form_id ) { |
|
| 1078 | +function give_checkout_submit($form_id) { |
|
| 1079 | 1079 | ?> |
| 1080 | 1080 | <fieldset id="give_purchase_submit"> |
| 1081 | - <?php do_action( 'give_purchase_form_before_submit', $form_id ); ?> |
|
| 1081 | + <?php do_action('give_purchase_form_before_submit', $form_id); ?> |
|
| 1082 | 1082 | |
| 1083 | - <?php give_checkout_hidden_fields( $form_id ); ?> |
|
| 1083 | + <?php give_checkout_hidden_fields($form_id); ?> |
|
| 1084 | 1084 | |
| 1085 | - <?php echo give_checkout_button_purchase( $form_id ); ?> |
|
| 1085 | + <?php echo give_checkout_button_purchase($form_id); ?> |
|
| 1086 | 1086 | |
| 1087 | - <?php do_action( 'give_purchase_form_after_submit', $form_id ); ?> |
|
| 1087 | + <?php do_action('give_purchase_form_after_submit', $form_id); ?> |
|
| 1088 | 1088 | |
| 1089 | 1089 | </fieldset> |
| 1090 | 1090 | <?php |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | -add_action( 'give_purchase_form_after_cc_form', 'give_checkout_submit', 9999 ); |
|
| 1093 | +add_action('give_purchase_form_after_cc_form', 'give_checkout_submit', 9999); |
|
| 1094 | 1094 | |
| 1095 | 1095 | |
| 1096 | 1096 | /** |
@@ -1103,10 +1103,10 @@ discard block |
||
| 1103 | 1103 | * |
| 1104 | 1104 | * @return string |
| 1105 | 1105 | */ |
| 1106 | -function give_checkout_button_purchase( $form_id ) { |
|
| 1106 | +function give_checkout_button_purchase($form_id) { |
|
| 1107 | 1107 | |
| 1108 | - $display_label_field = get_post_meta( $form_id, '_give_checkout_label', true ); |
|
| 1109 | - $display_label = ( ! empty( $display_label_field ) ? $display_label_field : __( 'Donate Now', 'give' ) ); |
|
| 1108 | + $display_label_field = get_post_meta($form_id, '_give_checkout_label', true); |
|
| 1109 | + $display_label = ( ! empty($display_label_field) ? $display_label_field : __('Donate Now', 'give')); |
|
| 1110 | 1110 | |
| 1111 | 1111 | ob_start(); |
| 1112 | 1112 | |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | <span class="give-loading-animation"></span> |
| 1118 | 1118 | </div> |
| 1119 | 1119 | <?php |
| 1120 | - return apply_filters( 'give_checkout_button_purchase', ob_get_clean(), $form_id ); |
|
| 1120 | + return apply_filters('give_checkout_button_purchase', ob_get_clean(), $form_id); |
|
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | /** |
@@ -1131,11 +1131,11 @@ discard block |
||
| 1131 | 1131 | * |
| 1132 | 1132 | * @return void |
| 1133 | 1133 | */ |
| 1134 | -function give_agree_to_terms_js( $form_id ) { |
|
| 1134 | +function give_agree_to_terms_js($form_id) { |
|
| 1135 | 1135 | |
| 1136 | - $form_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
| 1136 | + $form_option = get_post_meta($form_id, '_give_terms_option', true); |
|
| 1137 | 1137 | |
| 1138 | - if ( $form_option === 'yes' ) { |
|
| 1138 | + if ($form_option === 'yes') { |
|
| 1139 | 1139 | ?> |
| 1140 | 1140 | <script type="text/javascript"> |
| 1141 | 1141 | jQuery(document).ready(function ($) { |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | } |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | -add_action( 'give_checkout_form_top', 'give_agree_to_terms_js', 10, 2 ); |
|
| 1154 | +add_action('give_checkout_form_top', 'give_agree_to_terms_js', 10, 2); |
|
| 1155 | 1155 | |
| 1156 | 1156 | |
| 1157 | 1157 | /** |
@@ -1164,19 +1164,19 @@ discard block |
||
| 1164 | 1164 | * |
| 1165 | 1165 | * @return void |
| 1166 | 1166 | */ |
| 1167 | -function give_form_content( $form_id, $args ) { |
|
| 1167 | +function give_form_content($form_id, $args) { |
|
| 1168 | 1168 | |
| 1169 | - $show_content = ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) |
|
| 1169 | + $show_content = (isset($args['show_content']) && ! empty($args['show_content'])) |
|
| 1170 | 1170 | ? $args['show_content'] |
| 1171 | - : get_post_meta( $form_id, '_give_content_option', true ); |
|
| 1171 | + : get_post_meta($form_id, '_give_content_option', true); |
|
| 1172 | 1172 | |
| 1173 | - if ( $show_content !== 'none' ) { |
|
| 1173 | + if ($show_content !== 'none') { |
|
| 1174 | 1174 | //add action according to value |
| 1175 | - add_action( $show_content, 'give_form_display_content' ); |
|
| 1175 | + add_action($show_content, 'give_form_display_content'); |
|
| 1176 | 1176 | } |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | -add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
|
| 1179 | +add_action('give_pre_form_output', 'give_form_content', 10, 2); |
|
| 1180 | 1180 | |
| 1181 | 1181 | /** |
| 1182 | 1182 | * Show Give Goals |
@@ -1189,24 +1189,24 @@ discard block |
||
| 1189 | 1189 | * @return mixed |
| 1190 | 1190 | */ |
| 1191 | 1191 | |
| 1192 | -function give_show_goal_progress( $form_id, $args ) { |
|
| 1192 | +function give_show_goal_progress($form_id, $args) { |
|
| 1193 | 1193 | |
| 1194 | - $goal_option = get_post_meta( $form_id, '_give_goal_option', true ); |
|
| 1195 | - $form = new Give_Donate_Form( $form_id ); |
|
| 1194 | + $goal_option = get_post_meta($form_id, '_give_goal_option', true); |
|
| 1195 | + $form = new Give_Donate_Form($form_id); |
|
| 1196 | 1196 | $goal = $form->goal; |
| 1197 | 1197 | $income = $form->get_earnings(); |
| 1198 | - $color = get_post_meta( $form_id, '_give_goal_color', true ); |
|
| 1199 | - $show_text = (bool) isset( $args['show_text'] ) ? filter_var( $args['show_text'], FILTER_VALIDATE_BOOLEAN ) : true; |
|
| 1200 | - $show_bar = (bool) isset( $args['show_bar'] ) ? filter_var( $args['show_bar'], FILTER_VALIDATE_BOOLEAN ) : true; |
|
| 1198 | + $color = get_post_meta($form_id, '_give_goal_color', true); |
|
| 1199 | + $show_text = (bool) isset($args['show_text']) ? filter_var($args['show_text'], FILTER_VALIDATE_BOOLEAN) : true; |
|
| 1200 | + $show_bar = (bool) isset($args['show_bar']) ? filter_var($args['show_bar'], FILTER_VALIDATE_BOOLEAN) : true; |
|
| 1201 | 1201 | |
| 1202 | 1202 | //Sanity check - respect shortcode args |
| 1203 | - if ( isset( $args['show_goal'] ) && $args['show_goal'] === false ) { |
|
| 1203 | + if (isset($args['show_goal']) && $args['show_goal'] === false) { |
|
| 1204 | 1204 | return false; |
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | //Sanity check - ensure form has goal set to output |
| 1208 | - if ( empty( $form->ID ) |
|
| 1209 | - || ( is_singular( 'give_forms' ) && $goal_option !== 'yes' ) |
|
| 1208 | + if (empty($form->ID) |
|
| 1209 | + || (is_singular('give_forms') && $goal_option !== 'yes') |
|
| 1210 | 1210 | || $goal_option !== 'yes' |
| 1211 | 1211 | || $goal == 0 |
| 1212 | 1212 | ) { |
@@ -1214,26 +1214,26 @@ discard block |
||
| 1214 | 1214 | return false; |
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | - $progress = round( ( $income / $goal ) * 100, 2 ); |
|
| 1217 | + $progress = round(($income / $goal) * 100, 2); |
|
| 1218 | 1218 | |
| 1219 | - if ( $income > $goal ) { |
|
| 1219 | + if ($income > $goal) { |
|
| 1220 | 1220 | $progress = 100; |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | $output = '<div class="give-goal-progress">'; |
| 1224 | 1224 | |
| 1225 | 1225 | //Goal Progress Text |
| 1226 | - if ( ! empty( $show_text ) ) { |
|
| 1226 | + if ( ! empty($show_text)) { |
|
| 1227 | 1227 | $output .= '<div class="raised">'; |
| 1228 | - $output .= sprintf( _x( '%s of %s raised', 'This text displays the amount of income raised compared to the goal.', 'give' ), '<span class="income">' . give_currency_filter( give_format_amount( $income ) ) . '</span>', '<span class="goal-text">' . give_currency_filter( give_format_amount( $goal ) ) ) . '</span>'; |
|
| 1228 | + $output .= sprintf(_x('%s of %s raised', 'This text displays the amount of income raised compared to the goal.', 'give'), '<span class="income">'.give_currency_filter(give_format_amount($income)).'</span>', '<span class="goal-text">'.give_currency_filter(give_format_amount($goal))).'</span>'; |
|
| 1229 | 1229 | $output .= '</div>'; |
| 1230 | 1230 | } |
| 1231 | 1231 | //Goal Progress Bar |
| 1232 | - if ( ! empty( $show_bar ) ) { |
|
| 1232 | + if ( ! empty($show_bar)) { |
|
| 1233 | 1233 | $output .= '<div class="give-progress-bar">'; |
| 1234 | - $output .= '<span style="width: ' . esc_attr( $progress ) . '%;'; |
|
| 1235 | - if ( ! empty( $color ) ) { |
|
| 1236 | - $output .= 'background-color:' . $color; |
|
| 1234 | + $output .= '<span style="width: '.esc_attr($progress).'%;'; |
|
| 1235 | + if ( ! empty($color)) { |
|
| 1236 | + $output .= 'background-color:'.$color; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | $output .= '"></span>'; |
| 1239 | 1239 | $output .= '</div><!-- /.give-progress-bar -->'; |
@@ -1241,13 +1241,13 @@ discard block |
||
| 1241 | 1241 | |
| 1242 | 1242 | $output .= '</div><!-- /.goal-progress -->'; |
| 1243 | 1243 | |
| 1244 | - echo apply_filters( 'give_goal_output', $output ); |
|
| 1244 | + echo apply_filters('give_goal_output', $output); |
|
| 1245 | 1245 | |
| 1246 | 1246 | return false; |
| 1247 | 1247 | |
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | -add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
|
| 1250 | +add_action('give_pre_form', 'give_show_goal_progress', 10, 2); |
|
| 1251 | 1251 | |
| 1252 | 1252 | /** |
| 1253 | 1253 | * Renders Post Form Content |
@@ -1259,17 +1259,17 @@ discard block |
||
| 1259 | 1259 | * @return void |
| 1260 | 1260 | * @since 1.0 |
| 1261 | 1261 | */ |
| 1262 | -function give_form_display_content( $form_id ) { |
|
| 1262 | +function give_form_display_content($form_id) { |
|
| 1263 | 1263 | |
| 1264 | - $content = wpautop( get_post_meta( $form_id, '_give_form_content', true ) ); |
|
| 1264 | + $content = wpautop(get_post_meta($form_id, '_give_form_content', true)); |
|
| 1265 | 1265 | |
| 1266 | - if ( give_get_option( 'disable_the_content_filter' ) !== 'on' ) { |
|
| 1267 | - $content = apply_filters( 'the_content', $content ); |
|
| 1266 | + if (give_get_option('disable_the_content_filter') !== 'on') { |
|
| 1267 | + $content = apply_filters('the_content', $content); |
|
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | - $output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap" >' . $content . '</div>'; |
|
| 1270 | + $output = '<div id="give-form-content-'.$form_id.'" class="give-form-content-wrap" >'.$content.'</div>'; |
|
| 1271 | 1271 | |
| 1272 | - echo apply_filters( 'give_form_content_output', $output ); |
|
| 1272 | + echo apply_filters('give_form_content_output', $output); |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | |
@@ -1282,16 +1282,16 @@ discard block |
||
| 1282 | 1282 | * |
| 1283 | 1283 | * @return void |
| 1284 | 1284 | */ |
| 1285 | -function give_checkout_hidden_fields( $form_id ) { |
|
| 1285 | +function give_checkout_hidden_fields($form_id) { |
|
| 1286 | 1286 | |
| 1287 | - do_action( 'give_hidden_fields_before', $form_id ); |
|
| 1288 | - if ( is_user_logged_in() ) { ?> |
|
| 1287 | + do_action('give_hidden_fields_before', $form_id); |
|
| 1288 | + if (is_user_logged_in()) { ?> |
|
| 1289 | 1289 | <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
| 1290 | 1290 | <?php } ?> |
| 1291 | 1291 | <input type="hidden" name="give_action" value="purchase"/> |
| 1292 | - <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
|
| 1292 | + <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway($form_id); ?>"/> |
|
| 1293 | 1293 | <?php |
| 1294 | - do_action( 'give_hidden_fields_after', $form_id ); |
|
| 1294 | + do_action('give_hidden_fields_after', $form_id); |
|
| 1295 | 1295 | |
| 1296 | 1296 | } |
| 1297 | 1297 | |
@@ -1306,20 +1306,20 @@ discard block |
||
| 1306 | 1306 | * |
| 1307 | 1307 | * @return string $content Filtered content |
| 1308 | 1308 | */ |
| 1309 | -function give_filter_success_page_content( $content ) { |
|
| 1309 | +function give_filter_success_page_content($content) { |
|
| 1310 | 1310 | |
| 1311 | 1311 | global $give_options; |
| 1312 | 1312 | |
| 1313 | - if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
|
| 1314 | - if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
|
| 1315 | - $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
|
| 1313 | + if (isset($give_options['success_page']) && isset($_GET['payment-confirmation']) && is_page($give_options['success_page'])) { |
|
| 1314 | + if (has_filter('give_payment_confirm_'.$_GET['payment-confirmation'])) { |
|
| 1315 | + $content = apply_filters('give_payment_confirm_'.$_GET['payment-confirmation'], $content); |
|
| 1316 | 1316 | } |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | return $content; |
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | -add_filter( 'the_content', 'give_filter_success_page_content' ); |
|
| 1322 | +add_filter('the_content', 'give_filter_success_page_content'); |
|
| 1323 | 1323 | |
| 1324 | 1324 | |
| 1325 | 1325 | /** |
@@ -1331,11 +1331,11 @@ discard block |
||
| 1331 | 1331 | |
| 1332 | 1332 | function give_test_mode_frontend_warning() { |
| 1333 | 1333 | |
| 1334 | - $test_mode = give_get_option( 'test_mode' ); |
|
| 1334 | + $test_mode = give_get_option('test_mode'); |
|
| 1335 | 1335 | |
| 1336 | - if ( $test_mode == 'on' ) { |
|
| 1337 | - echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>' . __( 'Notice', 'give' ) . '</strong>: ' . esc_attr__( 'Test mode is enabled. While in test mode no live transactions are processed.', 'give' ) . '</p></div>'; |
|
| 1336 | + if ($test_mode == 'on') { |
|
| 1337 | + echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>'.__('Notice', 'give').'</strong>: '.esc_attr__('Test mode is enabled. While in test mode no live transactions are processed.', 'give').'</p></div>'; |
|
| 1338 | 1338 | } |
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | -add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
|
| 1341 | +add_action('give_pre_form', 'give_test_mode_frontend_warning', 10); |
|
@@ -740,8 +740,11 @@ |
||
| 740 | 740 | } |
| 741 | 741 | ?> |
| 742 | 742 | </select> |
| 743 | - <?php else : ?> |
|
| 744 | - <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php _e( 'State / Province', 'give' ); ?>"/> |
|
| 743 | + <?php else { |
|
| 744 | + : ?> |
|
| 745 | + <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php _e( 'State / Province', 'give' ); |
|
| 746 | +} |
|
| 747 | +?>"/> |
|
| 745 | 748 | <?php endif; ?> |
| 746 | 749 | </p> |
| 747 | 750 | <?php do_action( 'give_cc_billing_bottom' ); ?> |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * @param int $year Year |
| 625 | 625 | * @param int $hour Hour |
| 626 | 626 | * |
| 627 | - * @return int $earnings Earnings |
|
| 627 | + * @return double $earnings Earnings |
|
| 628 | 628 | */ |
| 629 | 629 | function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) { |
| 630 | 630 | |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | * |
| 947 | 947 | * @param int $payment_id Payment ID |
| 948 | 948 | * |
| 949 | - * @return array $user_info User Info Meta Values |
|
| 949 | + * @return string $user_info User Info Meta Values |
|
| 950 | 950 | */ |
| 951 | 951 | function give_get_payment_meta_user_info( $payment_id ) { |
| 952 | 952 | $payment_meta = give_get_payment_meta( $payment_id ); |
@@ -1639,7 +1639,7 @@ discard block |
||
| 1639 | 1639 | * @param array $where |
| 1640 | 1640 | * @param obj $wp_comment_query WordPress Comment Query Object |
| 1641 | 1641 | * |
| 1642 | - * @return array $where |
|
| 1642 | + * @return string $where |
|
| 1643 | 1643 | */ |
| 1644 | 1644 | function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) { |
| 1645 | 1645 | global $wpdb; |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Payment Functions |
|
| 4 | - * |
|
| 5 | - * @package Give |
|
| 6 | - * @subpackage Payments |
|
| 7 | - * @copyright Copyright (c) 2015, WordImpress |
|
| 8 | - * @license http://opensource.org/licenses/gpl-1.0.php GNU Public License |
|
| 9 | - * @since 1.0 |
|
| 10 | - */ |
|
| 3 | + * Payment Functions |
|
| 4 | + * |
|
| 5 | + * @package Give |
|
| 6 | + * @subpackage Payments |
|
| 7 | + * @copyright Copyright (c) 2015, WordImpress |
|
| 8 | + * @license http://opensource.org/licenses/gpl-1.0.php GNU Public License |
|
| 9 | + * @since 1.0 |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
@@ -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 | |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return object $payments Payments retrieved from the database |
| 34 | 34 | */ |
| 35 | -function give_get_payments( $args = array() ) { |
|
| 35 | +function give_get_payments($args = array()) { |
|
| 36 | 36 | |
| 37 | 37 | // Fallback to post objects to ensure backwards compatibility |
| 38 | - if ( ! isset( $args['output'] ) ) { |
|
| 38 | + if ( ! isset($args['output'])) { |
|
| 39 | 39 | $args['output'] = 'posts'; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $args = apply_filters( 'give_get_payments_args', $args ); |
|
| 43 | - $payments = new Give_Payments_Query( $args ); |
|
| 42 | + $args = apply_filters('give_get_payments_args', $args); |
|
| 43 | + $payments = new Give_Payments_Query($args); |
|
| 44 | 44 | |
| 45 | 45 | return $payments->get_payments(); |
| 46 | 46 | } |
@@ -55,44 +55,44 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return mixed |
| 57 | 57 | */ |
| 58 | -function give_get_payment_by( $field = '', $value = '' ) { |
|
| 58 | +function give_get_payment_by($field = '', $value = '') { |
|
| 59 | 59 | |
| 60 | - if ( empty( $field ) || empty( $value ) ) { |
|
| 60 | + if (empty($field) || empty($value)) { |
|
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - switch ( strtolower( $field ) ) { |
|
| 64 | + switch (strtolower($field)) { |
|
| 65 | 65 | |
| 66 | 66 | case 'id': |
| 67 | - $payment = get_post( $value ); |
|
| 67 | + $payment = get_post($value); |
|
| 68 | 68 | |
| 69 | - if ( get_post_type( $payment ) != 'give_payment' ) { |
|
| 69 | + if (get_post_type($payment) != 'give_payment') { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | break; |
| 74 | 74 | |
| 75 | 75 | case 'key': |
| 76 | - $payment = give_get_payments( array( |
|
| 76 | + $payment = give_get_payments(array( |
|
| 77 | 77 | 'meta_key' => '_give_payment_purchase_key', |
| 78 | 78 | 'meta_value' => $value, |
| 79 | 79 | 'posts_per_page' => 1 |
| 80 | - ) ); |
|
| 80 | + )); |
|
| 81 | 81 | |
| 82 | - if ( $payment ) { |
|
| 82 | + if ($payment) { |
|
| 83 | 83 | $payment = $payment[0]; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | break; |
| 87 | 87 | |
| 88 | 88 | case 'payment_number': |
| 89 | - $payment = give_get_payments( array( |
|
| 89 | + $payment = give_get_payments(array( |
|
| 90 | 90 | 'meta_key' => '_give_payment_number', |
| 91 | 91 | 'meta_value' => $value, |
| 92 | 92 | 'posts_per_page' => 1 |
| 93 | - ) ); |
|
| 93 | + )); |
|
| 94 | 94 | |
| 95 | - if ( $payment ) { |
|
| 95 | + if ($payment) { |
|
| 96 | 96 | $payment = $payment[0]; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | return false; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ( $payment ) { |
|
| 105 | + if ($payment) { |
|
| 106 | 106 | return $payment; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -118,97 +118,97 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return int|bool Payment ID if payment is inserted, false otherwise |
| 120 | 120 | */ |
| 121 | -function give_insert_payment( $payment_data = array() ) { |
|
| 122 | - if ( empty( $payment_data ) ) { |
|
| 121 | +function give_insert_payment($payment_data = array()) { |
|
| 122 | + if (empty($payment_data)) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // Make sure the payment is inserted with the correct timezone |
| 127 | - date_default_timezone_set( give_get_timezone_id() ); |
|
| 127 | + date_default_timezone_set(give_get_timezone_id()); |
|
| 128 | 128 | |
| 129 | 129 | // Construct the payment title |
| 130 | - if ( isset( $payment_data['user_info']['first_name'] ) || isset( $payment_data['user_info']['last_name'] ) ) { |
|
| 131 | - $payment_title = $payment_data['user_info']['first_name'] . ' ' . $payment_data['user_info']['last_name']; |
|
| 130 | + if (isset($payment_data['user_info']['first_name']) || isset($payment_data['user_info']['last_name'])) { |
|
| 131 | + $payment_title = $payment_data['user_info']['first_name'].' '.$payment_data['user_info']['last_name']; |
|
| 132 | 132 | } else { |
| 133 | 133 | $payment_title = $payment_data['user_email']; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Find the next payment number, if enabled |
| 137 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
| 137 | + if (give_get_option('enable_sequential')) { |
|
| 138 | 138 | $number = give_get_next_payment_number(); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $args = apply_filters( 'give_insert_payment_args', array( |
|
| 141 | + $args = apply_filters('give_insert_payment_args', array( |
|
| 142 | 142 | 'post_title' => $payment_title, |
| 143 | - 'post_status' => isset( $payment_data['status'] ) ? $payment_data['status'] : 'pending', |
|
| 143 | + 'post_status' => isset($payment_data['status']) ? $payment_data['status'] : 'pending', |
|
| 144 | 144 | 'post_type' => 'give_payment', |
| 145 | - 'post_parent' => isset( $payment_data['parent'] ) ? $payment_data['parent'] : null, |
|
| 146 | - 'post_date' => isset( $payment_data['post_date'] ) ? $payment_data['post_date'] : null, |
|
| 147 | - 'post_date_gmt' => isset( $payment_data['post_date'] ) ? get_gmt_from_date( $payment_data['post_date'] ) : null |
|
| 148 | - ), $payment_data ); |
|
| 145 | + 'post_parent' => isset($payment_data['parent']) ? $payment_data['parent'] : null, |
|
| 146 | + 'post_date' => isset($payment_data['post_date']) ? $payment_data['post_date'] : null, |
|
| 147 | + 'post_date_gmt' => isset($payment_data['post_date']) ? get_gmt_from_date($payment_data['post_date']) : null |
|
| 148 | + ), $payment_data); |
|
| 149 | 149 | |
| 150 | 150 | // Create a blank payment |
| 151 | - $payment = wp_insert_post( $args ); |
|
| 151 | + $payment = wp_insert_post($args); |
|
| 152 | 152 | |
| 153 | - if ( $payment ) { |
|
| 153 | + if ($payment) { |
|
| 154 | 154 | |
| 155 | 155 | $payment_meta = array( |
| 156 | 156 | 'currency' => $payment_data['currency'], |
| 157 | 157 | 'form_title' => $payment_data['give_form_title'], |
| 158 | 158 | 'form_id' => $payment_data['give_form_id'], |
| 159 | - 'price_id' => give_get_price_id( $payment_data['give_form_id'], $payment_data['price'] ), |
|
| 159 | + 'price_id' => give_get_price_id($payment_data['give_form_id'], $payment_data['price']), |
|
| 160 | 160 | 'user_info' => $payment_data['user_info'], |
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | 163 | $mode = give_is_test_mode() ? 'test' : 'live'; |
| 164 | - $gateway = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : ''; |
|
| 165 | - $gateway = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway; |
|
| 164 | + $gateway = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : ''; |
|
| 165 | + $gateway = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway; |
|
| 166 | 166 | |
| 167 | - if ( ! $payment_data['price'] ) { |
|
| 167 | + if ( ! $payment_data['price']) { |
|
| 168 | 168 | // Ensures the _give_payment_total meta key is created for donations with an amount of 0 |
| 169 | 169 | $payment_data['price'] = '0.00'; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Create or update a customer |
| 173 | - $customer = new Give_Customer( $payment_data['user_email'] ); |
|
| 173 | + $customer = new Give_Customer($payment_data['user_email']); |
|
| 174 | 174 | |
| 175 | 175 | // If we didn't find a customer and the user is logged in, check by user_id #437 |
| 176 | - if ( empty( $customer->id ) && is_user_logged_in() ) { |
|
| 177 | - $customer = new Give_Customer( get_current_user_id(), true ); |
|
| 176 | + if (empty($customer->id) && is_user_logged_in()) { |
|
| 177 | + $customer = new Give_Customer(get_current_user_id(), true); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $customer_data = array( |
| 181 | - 'name' => $payment_data['user_info']['first_name'] . ' ' . $payment_data['user_info']['last_name'], |
|
| 181 | + 'name' => $payment_data['user_info']['first_name'].' '.$payment_data['user_info']['last_name'], |
|
| 182 | 182 | 'email' => $payment_data['user_email'], |
| 183 | 183 | 'user_id' => $payment_data['user_info']['id'] |
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | - if ( empty( $customer->id ) ) { |
|
| 187 | - $customer->create( $customer_data ); |
|
| 186 | + if (empty($customer->id)) { |
|
| 187 | + $customer->create($customer_data); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $customer->attach_payment( $payment, false ); |
|
| 190 | + $customer->attach_payment($payment, false); |
|
| 191 | 191 | |
| 192 | 192 | // Record the payment details |
| 193 | - give_update_payment_meta( $payment, '_give_payment_meta', apply_filters( 'give_payment_meta', $payment_meta, $payment_data ) ); |
|
| 194 | - give_update_payment_meta( $payment, '_give_payment_user_id', $payment_data['user_info']['id'] ); |
|
| 195 | - give_update_payment_meta( $payment, '_give_payment_customer_id', $customer->id ); |
|
| 196 | - give_update_payment_meta( $payment, '_give_payment_user_email', $payment_data['user_email'] ); |
|
| 197 | - give_update_payment_meta( $payment, '_give_payment_user_ip', give_get_ip() ); |
|
| 198 | - give_update_payment_meta( $payment, '_give_payment_purchase_key', $payment_data['purchase_key'] ); |
|
| 199 | - give_update_payment_meta( $payment, '_give_payment_total', $payment_data['price'] ); |
|
| 200 | - give_update_payment_meta( $payment, '_give_payment_mode', $mode ); |
|
| 201 | - give_update_payment_meta( $payment, '_give_payment_gateway', $gateway ); |
|
| 202 | - |
|
| 203 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
| 204 | - give_update_payment_meta( $payment, '_give_payment_number', give_format_payment_number( $number ) ); |
|
| 205 | - update_option( 'give_last_payment_number', $number ); |
|
| 193 | + give_update_payment_meta($payment, '_give_payment_meta', apply_filters('give_payment_meta', $payment_meta, $payment_data)); |
|
| 194 | + give_update_payment_meta($payment, '_give_payment_user_id', $payment_data['user_info']['id']); |
|
| 195 | + give_update_payment_meta($payment, '_give_payment_customer_id', $customer->id); |
|
| 196 | + give_update_payment_meta($payment, '_give_payment_user_email', $payment_data['user_email']); |
|
| 197 | + give_update_payment_meta($payment, '_give_payment_user_ip', give_get_ip()); |
|
| 198 | + give_update_payment_meta($payment, '_give_payment_purchase_key', $payment_data['purchase_key']); |
|
| 199 | + give_update_payment_meta($payment, '_give_payment_total', $payment_data['price']); |
|
| 200 | + give_update_payment_meta($payment, '_give_payment_mode', $mode); |
|
| 201 | + give_update_payment_meta($payment, '_give_payment_gateway', $gateway); |
|
| 202 | + |
|
| 203 | + if (give_get_option('enable_sequential')) { |
|
| 204 | + give_update_payment_meta($payment, '_give_payment_number', give_format_payment_number($number)); |
|
| 205 | + update_option('give_last_payment_number', $number); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Clear the user's purchased cache |
| 209 | - delete_transient( 'give_user_' . $payment_data['user_info']['id'] . '_purchases' ); |
|
| 209 | + delete_transient('give_user_'.$payment_data['user_info']['id'].'_purchases'); |
|
| 210 | 210 | |
| 211 | - do_action( 'give_insert_payment', $payment, $payment_data ); |
|
| 211 | + do_action('give_insert_payment', $payment, $payment_data); |
|
| 212 | 212 | |
| 213 | 213 | return $payment; // Return the ID |
| 214 | 214 | |
@@ -228,43 +228,43 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @return void |
| 230 | 230 | */ |
| 231 | -function give_update_payment_status( $payment_id, $new_status = 'publish' ) { |
|
| 231 | +function give_update_payment_status($payment_id, $new_status = 'publish') { |
|
| 232 | 232 | |
| 233 | - if ( $new_status == 'completed' || $new_status == 'complete' ) { |
|
| 233 | + if ($new_status == 'completed' || $new_status == 'complete') { |
|
| 234 | 234 | $new_status = 'publish'; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( empty( $payment_id ) ) { |
|
| 237 | + if (empty($payment_id)) { |
|
| 238 | 238 | return; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $payment = get_post( $payment_id ); |
|
| 241 | + $payment = get_post($payment_id); |
|
| 242 | 242 | |
| 243 | - if ( is_wp_error( $payment ) || ! is_object( $payment ) ) { |
|
| 243 | + if (is_wp_error($payment) || ! is_object($payment)) { |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | $old_status = $payment->post_status; |
| 248 | 248 | |
| 249 | - if ( $old_status === $new_status ) { |
|
| 249 | + if ($old_status === $new_status) { |
|
| 250 | 250 | return; // Don't permit status changes that aren't changes |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $do_change = apply_filters( 'give_should_update_payment_status', true, $payment_id, $new_status, $old_status ); |
|
| 253 | + $do_change = apply_filters('give_should_update_payment_status', true, $payment_id, $new_status, $old_status); |
|
| 254 | 254 | |
| 255 | - if ( $do_change ) { |
|
| 255 | + if ($do_change) { |
|
| 256 | 256 | |
| 257 | - do_action( 'give_before_payment_status_change', $payment_id, $new_status, $old_status ); |
|
| 257 | + do_action('give_before_payment_status_change', $payment_id, $new_status, $old_status); |
|
| 258 | 258 | |
| 259 | 259 | $update_fields = array( |
| 260 | 260 | 'ID' => $payment_id, |
| 261 | 261 | 'post_status' => $new_status, |
| 262 | - 'edit_date' => current_time( 'mysql' ) |
|
| 262 | + 'edit_date' => current_time('mysql') |
|
| 263 | 263 | ); |
| 264 | 264 | |
| 265 | - wp_update_post( apply_filters( 'give_update_payment_status_fields', $update_fields ) ); |
|
| 265 | + wp_update_post(apply_filters('give_update_payment_status_fields', $update_fields)); |
|
| 266 | 266 | |
| 267 | - do_action( 'give_update_payment_status', $payment_id, $new_status, $old_status ); |
|
| 267 | + do_action('give_update_payment_status', $payment_id, $new_status, $old_status); |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | } |
@@ -280,48 +280,48 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @return void |
| 282 | 282 | */ |
| 283 | -function give_delete_purchase( $payment_id = 0 ) { |
|
| 283 | +function give_delete_purchase($payment_id = 0) { |
|
| 284 | 284 | global $give_logs; |
| 285 | 285 | |
| 286 | - $post = get_post( $payment_id ); |
|
| 286 | + $post = get_post($payment_id); |
|
| 287 | 287 | |
| 288 | - if ( ! $post ) { |
|
| 288 | + if ( ! $post) { |
|
| 289 | 289 | return; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $form_id = give_get_payment_form_id( $payment_id ); |
|
| 292 | + $form_id = give_get_payment_form_id($payment_id); |
|
| 293 | 293 | |
| 294 | - give_undo_purchase( $form_id, $payment_id ); |
|
| 294 | + give_undo_purchase($form_id, $payment_id); |
|
| 295 | 295 | |
| 296 | - $amount = give_get_payment_amount( $payment_id ); |
|
| 296 | + $amount = give_get_payment_amount($payment_id); |
|
| 297 | 297 | $status = $post->post_status; |
| 298 | - $donor_id = give_get_payment_customer_id( $payment_id ); |
|
| 298 | + $donor_id = give_get_payment_customer_id($payment_id); |
|
| 299 | 299 | |
| 300 | - if ( $status == 'revoked' || $status == 'publish' ) { |
|
| 300 | + if ($status == 'revoked' || $status == 'publish') { |
|
| 301 | 301 | // Only decrease earnings if they haven't already been decreased (or were never increased for this payment) |
| 302 | - give_decrease_total_earnings( $amount ); |
|
| 302 | + give_decrease_total_earnings($amount); |
|
| 303 | 303 | // Clear the This Month earnings (this_monththis_month is NOT a typo) |
| 304 | - delete_transient( md5( 'give_earnings_this_monththis_month' ) ); |
|
| 304 | + delete_transient(md5('give_earnings_this_monththis_month')); |
|
| 305 | 305 | |
| 306 | - if ( $donor_id ) { |
|
| 306 | + if ($donor_id) { |
|
| 307 | 307 | |
| 308 | 308 | // Decrement the stats for the donor |
| 309 | - Give()->customers->decrement_stats( $donor_id, $amount ); |
|
| 309 | + Give()->customers->decrement_stats($donor_id, $amount); |
|
| 310 | 310 | |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - do_action( 'give_payment_delete', $payment_id ); |
|
| 314 | + do_action('give_payment_delete', $payment_id); |
|
| 315 | 315 | |
| 316 | - if ( $donor_id ) { |
|
| 316 | + if ($donor_id) { |
|
| 317 | 317 | |
| 318 | 318 | // Remove the payment ID from the donor |
| 319 | - Give()->customers->remove_payment( $donor_id, $payment_id ); |
|
| 319 | + Give()->customers->remove_payment($donor_id, $payment_id); |
|
| 320 | 320 | |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Remove the payment |
| 324 | - wp_delete_post( $payment_id, true ); |
|
| 324 | + wp_delete_post($payment_id, true); |
|
| 325 | 325 | |
| 326 | 326 | // Remove related sale log entries |
| 327 | 327 | $give_logs->delete_logs( |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | ) |
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | - do_action( 'give_payment_deleted', $payment_id ); |
|
| 338 | + do_action('give_payment_deleted', $payment_id); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -348,19 +348,19 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | * @return void |
| 350 | 350 | */ |
| 351 | -function give_undo_purchase( $form_id, $payment_id ) { |
|
| 351 | +function give_undo_purchase($form_id, $payment_id) { |
|
| 352 | 352 | |
| 353 | - if ( give_is_test_mode() ) { |
|
| 353 | + if (give_is_test_mode()) { |
|
| 354 | 354 | return; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $amount = give_get_payment_amount( $payment_id ); |
|
| 357 | + $amount = give_get_payment_amount($payment_id); |
|
| 358 | 358 | |
| 359 | 359 | // decrease earnings |
| 360 | - give_decrease_earnings( $form_id, $amount ); |
|
| 360 | + give_decrease_earnings($form_id, $amount); |
|
| 361 | 361 | |
| 362 | 362 | // decrease purchase count |
| 363 | - give_decrease_purchase_count( $form_id ); |
|
| 363 | + give_decrease_purchase_count($form_id); |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | 366 | } |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return array $count Number of payments sorted by payment status |
| 379 | 379 | */ |
| 380 | -function give_count_payments( $args = array() ) { |
|
| 380 | +function give_count_payments($args = array()) { |
|
| 381 | 381 | |
| 382 | 382 | global $wpdb; |
| 383 | 383 | |
@@ -388,17 +388,17 @@ discard block |
||
| 388 | 388 | 'end-date' => null, |
| 389 | 389 | ); |
| 390 | 390 | |
| 391 | - $args = wp_parse_args( $args, $defaults ); |
|
| 391 | + $args = wp_parse_args($args, $defaults); |
|
| 392 | 392 | |
| 393 | 393 | $join = ''; |
| 394 | 394 | $where = "WHERE p.post_type = 'give_payment'"; |
| 395 | 395 | |
| 396 | 396 | // Count payments for a specific user |
| 397 | - if ( ! empty( $args['user'] ) ) { |
|
| 397 | + if ( ! empty($args['user'])) { |
|
| 398 | 398 | |
| 399 | - if ( is_email( $args['user'] ) ) { |
|
| 399 | + if (is_email($args['user'])) { |
|
| 400 | 400 | $field = 'email'; |
| 401 | - } elseif ( is_numeric( $args['user'] ) ) { |
|
| 401 | + } elseif (is_numeric($args['user'])) { |
|
| 402 | 402 | $field = 'id'; |
| 403 | 403 | } else { |
| 404 | 404 | $field = ''; |
@@ -406,18 +406,18 @@ discard block |
||
| 406 | 406 | |
| 407 | 407 | $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
| 408 | 408 | |
| 409 | - if ( ! empty( $field ) ) { |
|
| 409 | + if ( ! empty($field)) { |
|
| 410 | 410 | $where .= " |
| 411 | 411 | AND m.meta_key = '_give_payment_user_{$field}' |
| 412 | 412 | AND m.meta_value = '{$args['user']}'"; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Count payments for a search |
| 416 | - } elseif ( ! empty( $args['s'] ) ) { |
|
| 416 | + } elseif ( ! empty($args['s'])) { |
|
| 417 | 417 | |
| 418 | - if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) { |
|
| 418 | + if (is_email($args['s']) || strlen($args['s']) == 32) { |
|
| 419 | 419 | |
| 420 | - if ( is_email( $args['s'] ) ) { |
|
| 420 | + if (is_email($args['s'])) { |
|
| 421 | 421 | $field = '_give_payment_user_email'; |
| 422 | 422 | } else { |
| 423 | 423 | $field = '_give_payment_purchase_key'; |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | AND m.meta_key = '{$field}' |
| 430 | 430 | AND m.meta_value = '{$args['s']}'"; |
| 431 | 431 | |
| 432 | - } elseif ( is_numeric( $args['s'] ) ) { |
|
| 432 | + } elseif (is_numeric($args['s'])) { |
|
| 433 | 433 | |
| 434 | 434 | $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
| 435 | 435 | $where .= " |
@@ -443,48 +443,48 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | // Limit payments count by date |
| 446 | - if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) { |
|
| 446 | + if ( ! empty($args['start-date']) && false !== strpos($args['start-date'], '/')) { |
|
| 447 | 447 | |
| 448 | - $date_parts = explode( '/', $args['start-date'] ); |
|
| 449 | - $month = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0; |
|
| 450 | - $day = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0; |
|
| 451 | - $year = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0; |
|
| 448 | + $date_parts = explode('/', $args['start-date']); |
|
| 449 | + $month = ! empty($date_parts[0]) && is_numeric($date_parts[0]) ? $date_parts[0] : 0; |
|
| 450 | + $day = ! empty($date_parts[1]) && is_numeric($date_parts[1]) ? $date_parts[1] : 0; |
|
| 451 | + $year = ! empty($date_parts[2]) && is_numeric($date_parts[2]) ? $date_parts[2] : 0; |
|
| 452 | 452 | |
| 453 | - $is_date = checkdate( $month, $day, $year ); |
|
| 454 | - if ( false !== $is_date ) { |
|
| 453 | + $is_date = checkdate($month, $day, $year); |
|
| 454 | + if (false !== $is_date) { |
|
| 455 | 455 | |
| 456 | - $date = new DateTime( $args['start-date'] ); |
|
| 457 | - $where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) ); |
|
| 456 | + $date = new DateTime($args['start-date']); |
|
| 457 | + $where .= $wpdb->prepare(" AND p.post_date >= '%s'", $date->format('Y-m-d')); |
|
| 458 | 458 | |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | // Fixes an issue with the payments list table counts when no end date is specified (partiy with stats class) |
| 462 | - if ( empty( $args['end-date'] ) ) { |
|
| 462 | + if (empty($args['end-date'])) { |
|
| 463 | 463 | $args['end-date'] = $args['start-date']; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if ( ! empty ( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) { |
|
| 468 | + if ( ! empty ($args['end-date']) && false !== strpos($args['end-date'], '/')) { |
|
| 469 | 469 | |
| 470 | - $date_parts = explode( '/', $args['end-date'] ); |
|
| 470 | + $date_parts = explode('/', $args['end-date']); |
|
| 471 | 471 | |
| 472 | - $month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0; |
|
| 473 | - $day = ! empty( $date_parts[1] ) ? $date_parts[1] : 0; |
|
| 474 | - $year = ! empty( $date_parts[2] ) ? $date_parts[2] : 0; |
|
| 472 | + $month = ! empty($date_parts[0]) ? $date_parts[0] : 0; |
|
| 473 | + $day = ! empty($date_parts[1]) ? $date_parts[1] : 0; |
|
| 474 | + $year = ! empty($date_parts[2]) ? $date_parts[2] : 0; |
|
| 475 | 475 | |
| 476 | - $is_date = checkdate( $month, $day, $year ); |
|
| 477 | - if ( false !== $is_date ) { |
|
| 476 | + $is_date = checkdate($month, $day, $year); |
|
| 477 | + if (false !== $is_date) { |
|
| 478 | 478 | |
| 479 | - $date = new DateTime( $args['end-date'] ); |
|
| 480 | - $where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) ); |
|
| 479 | + $date = new DateTime($args['end-date']); |
|
| 480 | + $where .= $wpdb->prepare(" AND p.post_date <= '%s'", $date->format('Y-m-d')); |
|
| 481 | 481 | |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $where = apply_filters( 'give_count_payments_where', $where ); |
|
| 487 | - $join = apply_filters( 'give_count_payments_join', $join ); |
|
| 486 | + $where = apply_filters('give_count_payments_where', $where); |
|
| 487 | + $join = apply_filters('give_count_payments_join', $join); |
|
| 488 | 488 | |
| 489 | 489 | $query = "SELECT p.post_status,count( * ) AS num_posts |
| 490 | 490 | FROM $wpdb->posts p |
@@ -493,35 +493,35 @@ discard block |
||
| 493 | 493 | GROUP BY p.post_status |
| 494 | 494 | "; |
| 495 | 495 | |
| 496 | - $cache_key = md5( implode( '|', $args ) . $where ); |
|
| 496 | + $cache_key = md5(implode('|', $args).$where); |
|
| 497 | 497 | |
| 498 | - $count = wp_cache_get( $cache_key, 'counts' ); |
|
| 499 | - if ( false !== $count ) { |
|
| 498 | + $count = wp_cache_get($cache_key, 'counts'); |
|
| 499 | + if (false !== $count) { |
|
| 500 | 500 | return $count; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - $count = $wpdb->get_results( $query, ARRAY_A ); |
|
| 503 | + $count = $wpdb->get_results($query, ARRAY_A); |
|
| 504 | 504 | |
| 505 | 505 | $stats = array(); |
| 506 | 506 | $statuses = get_post_stati(); |
| 507 | - if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) { |
|
| 508 | - unset( $statuses['private'] ); |
|
| 507 | + if (isset($statuses['private']) && empty($args['s'])) { |
|
| 508 | + unset($statuses['private']); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - foreach ( $statuses as $state ) { |
|
| 512 | - $stats[ $state ] = 0; |
|
| 511 | + foreach ($statuses as $state) { |
|
| 512 | + $stats[$state] = 0; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - foreach ( (array) $count as $row ) { |
|
| 516 | - if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) { |
|
| 515 | + foreach ((array) $count as $row) { |
|
| 516 | + if ('private' == $row['post_status'] && empty($args['s'])) { |
|
| 517 | 517 | continue; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - $stats[ $row['post_status'] ] = $row['num_posts']; |
|
| 520 | + $stats[$row['post_status']] = $row['num_posts']; |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | $stats = (object) $stats; |
| 524 | - wp_cache_set( $cache_key, $stats, 'counts' ); |
|
| 524 | + wp_cache_set($cache_key, $stats, 'counts'); |
|
| 525 | 525 | |
| 526 | 526 | return $stats; |
| 527 | 527 | } |
@@ -536,10 +536,10 @@ discard block |
||
| 536 | 536 | * |
| 537 | 537 | * @return bool true if payment exists, false otherwise |
| 538 | 538 | */ |
| 539 | -function give_check_for_existing_payment( $payment_id ) { |
|
| 540 | - $payment = get_post( $payment_id ); |
|
| 539 | +function give_check_for_existing_payment($payment_id) { |
|
| 540 | + $payment = get_post($payment_id); |
|
| 541 | 541 | |
| 542 | - if ( $payment && $payment->post_status == 'publish' ) { |
|
| 542 | + if ($payment && $payment->post_status == 'publish') { |
|
| 543 | 543 | return true; // Payment exists |
| 544 | 544 | } |
| 545 | 545 | |
@@ -556,21 +556,21 @@ discard block |
||
| 556 | 556 | * |
| 557 | 557 | * @return bool|mixed if payment status exists, false otherwise |
| 558 | 558 | */ |
| 559 | -function give_get_payment_status( $payment, $return_label = false ) { |
|
| 560 | - if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) { |
|
| 559 | +function give_get_payment_status($payment, $return_label = false) { |
|
| 560 | + if ( ! is_object($payment) || ! isset($payment->post_status)) { |
|
| 561 | 561 | return false; |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | $statuses = give_get_payment_statuses(); |
| 565 | - if ( ! is_array( $statuses ) || empty( $statuses ) ) { |
|
| 565 | + if ( ! is_array($statuses) || empty($statuses)) { |
|
| 566 | 566 | return false; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - if ( array_key_exists( $payment->post_status, $statuses ) ) { |
|
| 570 | - if ( true === $return_label ) { |
|
| 571 | - return $statuses[ $payment->post_status ]; |
|
| 569 | + if (array_key_exists($payment->post_status, $statuses)) { |
|
| 570 | + if (true === $return_label) { |
|
| 571 | + return $statuses[$payment->post_status]; |
|
| 572 | 572 | } else { |
| 573 | - return array_search( $payment->post_status, $statuses ); |
|
| 573 | + return array_search($payment->post_status, $statuses); |
|
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | |
@@ -585,17 +585,17 @@ discard block |
||
| 585 | 585 | */ |
| 586 | 586 | function give_get_payment_statuses() { |
| 587 | 587 | $payment_statuses = array( |
| 588 | - 'pending' => __( 'Pending', 'give' ), |
|
| 589 | - 'publish' => __( 'Complete', 'give' ), |
|
| 590 | - 'refunded' => __( 'Refunded', 'give' ), |
|
| 591 | - 'failed' => __( 'Failed', 'give' ), |
|
| 592 | - 'cancelled' => __( 'Cancelled', 'give' ), |
|
| 593 | - 'abandoned' => __( 'Abandoned', 'give' ), |
|
| 594 | - 'preapproval' => __( 'Pre-Approved', 'give' ), |
|
| 595 | - 'revoked' => __( 'Revoked', 'give' ) |
|
| 588 | + 'pending' => __('Pending', 'give'), |
|
| 589 | + 'publish' => __('Complete', 'give'), |
|
| 590 | + 'refunded' => __('Refunded', 'give'), |
|
| 591 | + 'failed' => __('Failed', 'give'), |
|
| 592 | + 'cancelled' => __('Cancelled', 'give'), |
|
| 593 | + 'abandoned' => __('Abandoned', 'give'), |
|
| 594 | + 'preapproval' => __('Pre-Approved', 'give'), |
|
| 595 | + 'revoked' => __('Revoked', 'give') |
|
| 596 | 596 | ); |
| 597 | 597 | |
| 598 | - return apply_filters( 'give_payment_statuses', $payment_statuses ); |
|
| 598 | + return apply_filters('give_payment_statuses', $payment_statuses); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | * @return array $payment_status All the available payment statuses |
| 608 | 608 | */ |
| 609 | 609 | function give_get_payment_status_keys() { |
| 610 | - $statuses = array_keys( give_get_payment_statuses() ); |
|
| 611 | - asort( $statuses ); |
|
| 610 | + $statuses = array_keys(give_get_payment_statuses()); |
|
| 611 | + asort($statuses); |
|
| 612 | 612 | |
| 613 | - return array_values( $statuses ); |
|
| 613 | + return array_values($statuses); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | * |
| 626 | 626 | * @return int $earnings Earnings |
| 627 | 627 | */ |
| 628 | -function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) { |
|
| 628 | +function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) { |
|
| 629 | 629 | |
| 630 | 630 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead |
| 631 | 631 | |
@@ -636,40 +636,40 @@ discard block |
||
| 636 | 636 | 'nopaging' => true, |
| 637 | 637 | 'year' => $year, |
| 638 | 638 | 'monthnum' => $month_num, |
| 639 | - 'post_status' => array( 'publish', 'revoked' ), |
|
| 639 | + 'post_status' => array('publish', 'revoked'), |
|
| 640 | 640 | 'fields' => 'ids', |
| 641 | 641 | 'update_post_term_cache' => false |
| 642 | 642 | ); |
| 643 | - if ( ! empty( $day ) ) { |
|
| 643 | + if ( ! empty($day)) { |
|
| 644 | 644 | $args['day'] = $day; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if ( ! empty( $hour ) ) { |
|
| 647 | + if ( ! empty($hour)) { |
|
| 648 | 648 | $args['hour'] = $hour; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - $args = apply_filters( 'give_get_earnings_by_date_args', $args ); |
|
| 652 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 651 | + $args = apply_filters('give_get_earnings_by_date_args', $args); |
|
| 652 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 653 | 653 | |
| 654 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
| 654 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
| 655 | 655 | $earnings = false; |
| 656 | 656 | } else { |
| 657 | - $earnings = get_transient( $key ); |
|
| 657 | + $earnings = get_transient($key); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - if ( false === $earnings ) { |
|
| 661 | - $sales = get_posts( $args ); |
|
| 660 | + if (false === $earnings) { |
|
| 661 | + $sales = get_posts($args); |
|
| 662 | 662 | $earnings = 0; |
| 663 | - if ( $sales ) { |
|
| 664 | - $sales = implode( ',', $sales ); |
|
| 665 | - $earnings += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})" ); |
|
| 663 | + if ($sales) { |
|
| 664 | + $sales = implode(',', $sales); |
|
| 665 | + $earnings += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})"); |
|
| 666 | 666 | |
| 667 | 667 | } |
| 668 | 668 | // Cache the results for one hour |
| 669 | - set_transient( $key, $earnings, HOUR_IN_SECONDS ); |
|
| 669 | + set_transient($key, $earnings, HOUR_IN_SECONDS); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - return round( $earnings, 2 ); |
|
| 672 | + return round($earnings, 2); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | * |
| 685 | 685 | * @return int $count Sales |
| 686 | 686 | */ |
| 687 | -function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) { |
|
| 687 | +function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) { |
|
| 688 | 688 | |
| 689 | 689 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead |
| 690 | 690 | $args = array( |
@@ -692,37 +692,37 @@ discard block |
||
| 692 | 692 | 'nopaging' => true, |
| 693 | 693 | 'year' => $year, |
| 694 | 694 | 'fields' => 'ids', |
| 695 | - 'post_status' => array( 'publish', 'revoked' ), |
|
| 695 | + 'post_status' => array('publish', 'revoked'), |
|
| 696 | 696 | 'update_post_meta_cache' => false, |
| 697 | 697 | 'update_post_term_cache' => false |
| 698 | 698 | ); |
| 699 | 699 | |
| 700 | - if ( ! empty( $month_num ) ) { |
|
| 700 | + if ( ! empty($month_num)) { |
|
| 701 | 701 | $args['monthnum'] = $month_num; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - if ( ! empty( $day ) ) { |
|
| 704 | + if ( ! empty($day)) { |
|
| 705 | 705 | $args['day'] = $day; |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | - if ( ! empty( $hour ) ) { |
|
| 708 | + if ( ! empty($hour)) { |
|
| 709 | 709 | $args['hour'] = $hour; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - $args = apply_filters( 'give_get_sales_by_date_args', $args ); |
|
| 713 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 712 | + $args = apply_filters('give_get_sales_by_date_args', $args); |
|
| 713 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 714 | 714 | |
| 715 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
| 715 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
| 716 | 716 | $count = false; |
| 717 | 717 | } else { |
| 718 | - $count = get_transient( $key ); |
|
| 718 | + $count = get_transient($key); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - if ( false === $count ) { |
|
| 722 | - $sales = new WP_Query( $args ); |
|
| 721 | + if (false === $count) { |
|
| 722 | + $sales = new WP_Query($args); |
|
| 723 | 723 | $count = (int) $sales->post_count; |
| 724 | 724 | // Cache the results for one hour |
| 725 | - set_transient( $key, $count, HOUR_IN_SECONDS ); |
|
| 725 | + set_transient($key, $count, HOUR_IN_SECONDS); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | return $count; |
@@ -737,14 +737,14 @@ discard block |
||
| 737 | 737 | * |
| 738 | 738 | * @return bool true if complete, false otherwise |
| 739 | 739 | */ |
| 740 | -function give_is_payment_complete( $payment_id ) { |
|
| 741 | - $payment = get_post( $payment_id ); |
|
| 740 | +function give_is_payment_complete($payment_id) { |
|
| 741 | + $payment = get_post($payment_id); |
|
| 742 | 742 | $ret = false; |
| 743 | - if ( $payment && $payment->post_status == 'publish' ) { |
|
| 743 | + if ($payment && $payment->post_status == 'publish') { |
|
| 744 | 744 | $ret = true; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status ); |
|
| 747 | + return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment->post_status); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | /** |
@@ -768,29 +768,29 @@ discard block |
||
| 768 | 768 | */ |
| 769 | 769 | function give_get_total_earnings() { |
| 770 | 770 | |
| 771 | - $total = get_option( 'give_earnings_total', 0 ); |
|
| 771 | + $total = get_option('give_earnings_total', 0); |
|
| 772 | 772 | |
| 773 | 773 | // If no total stored in DB, use old method of calculating total earnings |
| 774 | - if ( ! $total ) { |
|
| 774 | + if ( ! $total) { |
|
| 775 | 775 | |
| 776 | 776 | global $wpdb; |
| 777 | 777 | |
| 778 | - $total = get_transient( 'give_earnings_total' ); |
|
| 778 | + $total = get_transient('give_earnings_total'); |
|
| 779 | 779 | |
| 780 | - if ( false === $total ) { |
|
| 780 | + if (false === $total) { |
|
| 781 | 781 | |
| 782 | 782 | $total = (float) 0; |
| 783 | 783 | |
| 784 | - $args = apply_filters( 'give_get_total_earnings_args', array( |
|
| 784 | + $args = apply_filters('give_get_total_earnings_args', array( |
|
| 785 | 785 | 'offset' => 0, |
| 786 | - 'number' => - 1, |
|
| 787 | - 'status' => array( 'publish', 'revoked' ), |
|
| 786 | + 'number' => -1, |
|
| 787 | + 'status' => array('publish', 'revoked'), |
|
| 788 | 788 | 'fields' => 'ids' |
| 789 | - ) ); |
|
| 789 | + )); |
|
| 790 | 790 | |
| 791 | 791 | |
| 792 | - $payments = give_get_payments( $args ); |
|
| 793 | - if ( $payments ) { |
|
| 792 | + $payments = give_get_payments($args); |
|
| 793 | + if ($payments) { |
|
| 794 | 794 | |
| 795 | 795 | /* |
| 796 | 796 | * If performing a purchase, we need to skip the very last payment in the database, since it calls |
@@ -798,30 +798,30 @@ discard block |
||
| 798 | 798 | * first purchase |
| 799 | 799 | */ |
| 800 | 800 | |
| 801 | - if ( did_action( 'give_update_payment_status' ) ) { |
|
| 802 | - array_pop( $payments ); |
|
| 801 | + if (did_action('give_update_payment_status')) { |
|
| 802 | + array_pop($payments); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | - if ( ! empty( $payments ) ) { |
|
| 806 | - $payments = implode( ',', $payments ); |
|
| 807 | - $total += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" ); |
|
| 805 | + if ( ! empty($payments)) { |
|
| 806 | + $payments = implode(',', $payments); |
|
| 807 | + $total += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})"); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // Cache results for 1 day. This cache is cleared automatically when a payment is made |
| 813 | - set_transient( 'give_earnings_total', $total, 86400 ); |
|
| 813 | + set_transient('give_earnings_total', $total, 86400); |
|
| 814 | 814 | |
| 815 | 815 | // Store the total for the first time |
| 816 | - update_option( 'give_earnings_total', $total ); |
|
| 816 | + update_option('give_earnings_total', $total); |
|
| 817 | 817 | } |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - if ( $total < 0 ) { |
|
| 820 | + if ($total < 0) { |
|
| 821 | 821 | $total = 0; // Don't ever show negative earnings |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | - return apply_filters( 'give_total_earnings', round( $total, give_currency_decimal_filter() ) ); |
|
| 824 | + return apply_filters('give_total_earnings', round($total, give_currency_decimal_filter())); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
@@ -833,10 +833,10 @@ discard block |
||
| 833 | 833 | * |
| 834 | 834 | * @return float $total Total earnings |
| 835 | 835 | */ |
| 836 | -function give_increase_total_earnings( $amount = 0 ) { |
|
| 836 | +function give_increase_total_earnings($amount = 0) { |
|
| 837 | 837 | $total = give_get_total_earnings(); |
| 838 | 838 | $total += $amount; |
| 839 | - update_option( 'give_earnings_total', $total ); |
|
| 839 | + update_option('give_earnings_total', $total); |
|
| 840 | 840 | |
| 841 | 841 | return $total; |
| 842 | 842 | } |
@@ -850,13 +850,13 @@ discard block |
||
| 850 | 850 | * |
| 851 | 851 | * @return float $total Total earnings |
| 852 | 852 | */ |
| 853 | -function give_decrease_total_earnings( $amount = 0 ) { |
|
| 853 | +function give_decrease_total_earnings($amount = 0) { |
|
| 854 | 854 | $total = give_get_total_earnings(); |
| 855 | 855 | $total -= $amount; |
| 856 | - if ( $total < 0 ) { |
|
| 856 | + if ($total < 0) { |
|
| 857 | 857 | $total = 0; |
| 858 | 858 | } |
| 859 | - update_option( 'give_earnings_total', $total ); |
|
| 859 | + update_option('give_earnings_total', $total); |
|
| 860 | 860 | |
| 861 | 861 | return $total; |
| 862 | 862 | } |
@@ -872,28 +872,28 @@ discard block |
||
| 872 | 872 | * |
| 873 | 873 | * @return mixed $meta Payment Meta |
| 874 | 874 | */ |
| 875 | -function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) { |
|
| 875 | +function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) { |
|
| 876 | 876 | |
| 877 | - $meta = get_post_meta( $payment_id, $meta_key, $single ); |
|
| 877 | + $meta = get_post_meta($payment_id, $meta_key, $single); |
|
| 878 | 878 | |
| 879 | - if ( $meta_key === '_give_payment_meta' ) { |
|
| 879 | + if ($meta_key === '_give_payment_meta') { |
|
| 880 | 880 | |
| 881 | - if ( empty( $meta['key'] ) ) { |
|
| 882 | - $meta['key'] = give_get_payment_key( $payment_id ); |
|
| 881 | + if (empty($meta['key'])) { |
|
| 882 | + $meta['key'] = give_get_payment_key($payment_id); |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - if ( empty( $meta['email'] ) ) { |
|
| 886 | - $meta['email'] = give_get_payment_user_email( $payment_id ); |
|
| 885 | + if (empty($meta['email'])) { |
|
| 886 | + $meta['email'] = give_get_payment_user_email($payment_id); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - if ( empty( $meta['date'] ) ) { |
|
| 890 | - $meta['date'] = get_post_field( 'post_date', $payment_id ); |
|
| 889 | + if (empty($meta['date'])) { |
|
| 890 | + $meta['date'] = get_post_field('post_date', $payment_id); |
|
| 891 | 891 | } |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | - $meta = apply_filters( 'give_get_payment_meta_' . $meta_key, $meta, $payment_id ); |
|
| 894 | + $meta = apply_filters('give_get_payment_meta_'.$meta_key, $meta, $payment_id); |
|
| 895 | 895 | |
| 896 | - return apply_filters( 'give_get_payment_meta', $meta, $payment_id, $meta_key ); |
|
| 896 | + return apply_filters('give_get_payment_meta', $meta, $payment_id, $meta_key); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -906,26 +906,26 @@ discard block |
||
| 906 | 906 | * |
| 907 | 907 | * @return mixed Meta ID if successful, false if unsuccessful |
| 908 | 908 | */ |
| 909 | -function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 909 | +function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 910 | 910 | |
| 911 | - if ( empty( $payment_id ) || empty( $meta_key ) ) { |
|
| 911 | + if (empty($payment_id) || empty($meta_key)) { |
|
| 912 | 912 | return; |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
| 915 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
| 916 | 916 | |
| 917 | - $current_meta = give_get_payment_meta( $payment_id ); |
|
| 918 | - $current_meta[ $meta_key ] = $meta_value; |
|
| 917 | + $current_meta = give_get_payment_meta($payment_id); |
|
| 918 | + $current_meta[$meta_key] = $meta_value; |
|
| 919 | 919 | |
| 920 | 920 | $meta_key = '_give_payment_meta'; |
| 921 | 921 | $meta_value = $current_meta; |
| 922 | 922 | |
| 923 | - } else if ( $meta_key == 'email' || $meta_key == '_give_payment_user_email' ) { |
|
| 923 | + } else if ($meta_key == 'email' || $meta_key == '_give_payment_user_email') { |
|
| 924 | 924 | |
| 925 | - $meta_value = apply_filters( 'give_give_update_payment_meta_' . $meta_key, $meta_value, $payment_id ); |
|
| 926 | - update_post_meta( $payment_id, '_give_payment_user_email', $meta_value ); |
|
| 925 | + $meta_value = apply_filters('give_give_update_payment_meta_'.$meta_key, $meta_value, $payment_id); |
|
| 926 | + update_post_meta($payment_id, '_give_payment_user_email', $meta_value); |
|
| 927 | 927 | |
| 928 | - $current_meta = give_get_payment_meta( $payment_id ); |
|
| 928 | + $current_meta = give_get_payment_meta($payment_id); |
|
| 929 | 929 | $current_meta['user_info']['email'] = $meta_value; |
| 930 | 930 | |
| 931 | 931 | $meta_key = '_give_payment_meta'; |
@@ -933,9 +933,9 @@ discard block |
||
| 933 | 933 | |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - $meta_value = apply_filters( 'give_give_update_payment_meta_' . $meta_key, $meta_value, $payment_id ); |
|
| 936 | + $meta_value = apply_filters('give_give_update_payment_meta_'.$meta_key, $meta_value, $payment_id); |
|
| 937 | 937 | |
| 938 | - return update_post_meta( $payment_id, $meta_key, $meta_value, $prev_value ); |
|
| 938 | + return update_post_meta($payment_id, $meta_key, $meta_value, $prev_value); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -947,11 +947,11 @@ discard block |
||
| 947 | 947 | * |
| 948 | 948 | * @return array $user_info User Info Meta Values |
| 949 | 949 | */ |
| 950 | -function give_get_payment_meta_user_info( $payment_id ) { |
|
| 951 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
| 952 | - $user_info = isset( $payment_meta['user_info'] ) ? maybe_unserialize( $payment_meta['user_info'] ) : false; |
|
| 950 | +function give_get_payment_meta_user_info($payment_id) { |
|
| 951 | + $payment_meta = give_get_payment_meta($payment_id); |
|
| 952 | + $user_info = isset($payment_meta['user_info']) ? maybe_unserialize($payment_meta['user_info']) : false; |
|
| 953 | 953 | |
| 954 | - return apply_filters( 'give_payment_meta_user_info', $user_info ); |
|
| 954 | + return apply_filters('give_payment_meta_user_info', $user_info); |
|
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | /** |
@@ -964,12 +964,12 @@ discard block |
||
| 964 | 964 | * |
| 965 | 965 | * @return int $form_id |
| 966 | 966 | */ |
| 967 | -function give_get_payment_form_id( $payment_id ) { |
|
| 968 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
| 967 | +function give_get_payment_form_id($payment_id) { |
|
| 968 | + $payment_meta = give_get_payment_meta($payment_id); |
|
| 969 | 969 | |
| 970 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0; |
|
| 970 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0; |
|
| 971 | 971 | |
| 972 | - return apply_filters( 'give_get_payment_form_id', $form_id ); |
|
| 972 | + return apply_filters('give_get_payment_form_id', $form_id); |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
@@ -981,10 +981,10 @@ discard block |
||
| 981 | 981 | * |
| 982 | 982 | * @return string $email User Email |
| 983 | 983 | */ |
| 984 | -function give_get_payment_user_email( $payment_id ) { |
|
| 985 | - $email = give_get_payment_meta( $payment_id, '_give_payment_user_email', true ); |
|
| 984 | +function give_get_payment_user_email($payment_id) { |
|
| 985 | + $email = give_get_payment_meta($payment_id, '_give_payment_user_email', true); |
|
| 986 | 986 | |
| 987 | - return apply_filters( 'give_payment_user_email', $email ); |
|
| 987 | + return apply_filters('give_payment_user_email', $email); |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -996,11 +996,11 @@ discard block |
||
| 996 | 996 | * |
| 997 | 997 | * @return bool If the payment is associted with a user (false) or not (true) |
| 998 | 998 | */ |
| 999 | -function give_is_guest_payment( $payment_id ) { |
|
| 1000 | - $payment_user_id = give_get_payment_user_id( $payment_id ); |
|
| 1001 | - $is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true; |
|
| 999 | +function give_is_guest_payment($payment_id) { |
|
| 1000 | + $payment_user_id = give_get_payment_user_id($payment_id); |
|
| 1001 | + $is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true; |
|
| 1002 | 1002 | |
| 1003 | - return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id ); |
|
| 1003 | + return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
@@ -1012,38 +1012,38 @@ discard block |
||
| 1012 | 1012 | * |
| 1013 | 1013 | * @return string $user_id User ID |
| 1014 | 1014 | */ |
| 1015 | -function give_get_payment_user_id( $payment_id ) { |
|
| 1015 | +function give_get_payment_user_id($payment_id) { |
|
| 1016 | 1016 | |
| 1017 | 1017 | $user_id = - 1; |
| 1018 | 1018 | |
| 1019 | 1019 | // check the customer record first |
| 1020 | - $customer_id = give_get_payment_customer_id( $payment_id ); |
|
| 1021 | - $customer = new Give_Customer( $customer_id ); |
|
| 1020 | + $customer_id = give_get_payment_customer_id($payment_id); |
|
| 1021 | + $customer = new Give_Customer($customer_id); |
|
| 1022 | 1022 | |
| 1023 | - if ( ! empty( $customer->user_id ) && $customer->user_id > 0 ) { |
|
| 1023 | + if ( ! empty($customer->user_id) && $customer->user_id > 0) { |
|
| 1024 | 1024 | $user_id = $customer->user_id; |
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | // check the payment meta if we're still not finding a user with the customer record |
| 1028 | - if ( empty( $user_id ) || $user_id < 1 ) { |
|
| 1029 | - $payment_meta_user_id = give_get_payment_meta( $payment_id, '_give_payment_user_id', true ); |
|
| 1028 | + if (empty($user_id) || $user_id < 1) { |
|
| 1029 | + $payment_meta_user_id = give_get_payment_meta($payment_id, '_give_payment_user_id', true); |
|
| 1030 | 1030 | |
| 1031 | - if ( ! empty( $payment_meta_user_id ) ) { |
|
| 1031 | + if ( ! empty($payment_meta_user_id)) { |
|
| 1032 | 1032 | $user_id = $payment_meta_user_id; |
| 1033 | 1033 | } |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | // Last ditch effort is to connect payment email with a user in the user table |
| 1037 | - if ( empty( $user_id ) || $user_id < 1 ) { |
|
| 1038 | - $payment_email = give_get_payment_user_email( $payment_id ); |
|
| 1039 | - $user = get_user_by( 'email', $payment_email ); |
|
| 1037 | + if (empty($user_id) || $user_id < 1) { |
|
| 1038 | + $payment_email = give_get_payment_user_email($payment_id); |
|
| 1039 | + $user = get_user_by('email', $payment_email); |
|
| 1040 | 1040 | |
| 1041 | - if ( false !== $user ) { |
|
| 1041 | + if (false !== $user) { |
|
| 1042 | 1042 | $user_id = $user->ID; |
| 1043 | 1043 | } |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | - return apply_filters( 'give_payment_user_id', (int) $user_id ); |
|
| 1046 | + return apply_filters('give_payment_user_id', (int) $user_id); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1055,10 +1055,10 @@ discard block |
||
| 1055 | 1055 | * |
| 1056 | 1056 | * @return string $donor_id Donor ID |
| 1057 | 1057 | */ |
| 1058 | -function give_get_payment_customer_id( $payment_id ) { |
|
| 1059 | - $customer_id = get_post_meta( $payment_id, '_give_payment_customer_id', true ); |
|
| 1058 | +function give_get_payment_customer_id($payment_id) { |
|
| 1059 | + $customer_id = get_post_meta($payment_id, '_give_payment_customer_id', true); |
|
| 1060 | 1060 | |
| 1061 | - return apply_filters( '_give_payment_customer_id', $customer_id ); |
|
| 1061 | + return apply_filters('_give_payment_customer_id', $customer_id); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1070,10 +1070,10 @@ discard block |
||
| 1070 | 1070 | * |
| 1071 | 1071 | * @return string $ip User IP |
| 1072 | 1072 | */ |
| 1073 | -function give_get_payment_user_ip( $payment_id ) { |
|
| 1074 | - $ip = give_get_payment_meta( $payment_id, '_give_payment_user_ip', true ); |
|
| 1073 | +function give_get_payment_user_ip($payment_id) { |
|
| 1074 | + $ip = give_get_payment_meta($payment_id, '_give_payment_user_ip', true); |
|
| 1075 | 1075 | |
| 1076 | - return apply_filters( 'give_payment_user_ip', $ip ); |
|
| 1076 | + return apply_filters('give_payment_user_ip', $ip); |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | /** |
@@ -1085,17 +1085,17 @@ discard block |
||
| 1085 | 1085 | * |
| 1086 | 1086 | * @return string $date The date the payment was completed |
| 1087 | 1087 | */ |
| 1088 | -function give_get_payment_completed_date( $payment_id = 0 ) { |
|
| 1088 | +function give_get_payment_completed_date($payment_id = 0) { |
|
| 1089 | 1089 | |
| 1090 | - $payment = get_post( $payment_id ); |
|
| 1090 | + $payment = get_post($payment_id); |
|
| 1091 | 1091 | |
| 1092 | - if ( 'pending' == $payment->post_status || 'preapproved' == $payment->post_status ) { |
|
| 1092 | + if ('pending' == $payment->post_status || 'preapproved' == $payment->post_status) { |
|
| 1093 | 1093 | return false; // This payment was never completed |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - $date = ( $date = give_get_payment_meta( $payment_id, '_give_completed_date', true ) ) ? $date : $payment->modified_date; |
|
| 1096 | + $date = ($date = give_get_payment_meta($payment_id, '_give_completed_date', true)) ? $date : $payment->modified_date; |
|
| 1097 | 1097 | |
| 1098 | - return apply_filters( 'give_payment_completed_date', $date, $payment_id ); |
|
| 1098 | + return apply_filters('give_payment_completed_date', $date, $payment_id); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | /** |
@@ -1107,10 +1107,10 @@ discard block |
||
| 1107 | 1107 | * |
| 1108 | 1108 | * @return string $gateway Gateway |
| 1109 | 1109 | */ |
| 1110 | -function give_get_payment_gateway( $payment_id ) { |
|
| 1111 | - $gateway = give_get_payment_meta( $payment_id, '_give_payment_gateway', true ); |
|
| 1110 | +function give_get_payment_gateway($payment_id) { |
|
| 1111 | + $gateway = give_get_payment_meta($payment_id, '_give_payment_gateway', true); |
|
| 1112 | 1112 | |
| 1113 | - return apply_filters( 'give_payment_gateway', $gateway ); |
|
| 1113 | + return apply_filters('give_payment_gateway', $gateway); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | /** |
@@ -1122,11 +1122,11 @@ discard block |
||
| 1122 | 1122 | * |
| 1123 | 1123 | * @return string $currency The currency code |
| 1124 | 1124 | */ |
| 1125 | -function give_get_payment_currency_code( $payment_id = 0 ) { |
|
| 1126 | - $meta = give_get_payment_meta( $payment_id ); |
|
| 1127 | - $currency = isset( $meta['currency'] ) ? $meta['currency'] : give_get_currency(); |
|
| 1125 | +function give_get_payment_currency_code($payment_id = 0) { |
|
| 1126 | + $meta = give_get_payment_meta($payment_id); |
|
| 1127 | + $currency = isset($meta['currency']) ? $meta['currency'] : give_get_currency(); |
|
| 1128 | 1128 | |
| 1129 | - return apply_filters( 'give_payment_currency_code', $currency, $payment_id ); |
|
| 1129 | + return apply_filters('give_payment_currency_code', $currency, $payment_id); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | /** |
@@ -1138,10 +1138,10 @@ discard block |
||
| 1138 | 1138 | * |
| 1139 | 1139 | * @return string $currency The currency name |
| 1140 | 1140 | */ |
| 1141 | -function give_get_payment_currency( $payment_id = 0 ) { |
|
| 1142 | - $currency = give_get_payment_currency_code( $payment_id ); |
|
| 1141 | +function give_get_payment_currency($payment_id = 0) { |
|
| 1142 | + $currency = give_get_payment_currency_code($payment_id); |
|
| 1143 | 1143 | |
| 1144 | - return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id ); |
|
| 1144 | + return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1153,10 +1153,10 @@ discard block |
||
| 1153 | 1153 | * |
| 1154 | 1154 | * @return string $key Purchase key |
| 1155 | 1155 | */ |
| 1156 | -function give_get_payment_key( $payment_id = 0 ) { |
|
| 1157 | - $key = give_get_payment_meta( $payment_id, '_give_payment_purchase_key', true ); |
|
| 1156 | +function give_get_payment_key($payment_id = 0) { |
|
| 1157 | + $key = give_get_payment_meta($payment_id, '_give_payment_purchase_key', true); |
|
| 1158 | 1158 | |
| 1159 | - return apply_filters( 'give_payment_key', $key, $payment_id ); |
|
| 1159 | + return apply_filters('give_payment_key', $key, $payment_id); |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | /** |
@@ -1170,15 +1170,15 @@ discard block |
||
| 1170 | 1170 | * |
| 1171 | 1171 | * @return string $number Payment order number |
| 1172 | 1172 | */ |
| 1173 | -function give_get_payment_number( $payment_id = 0 ) { |
|
| 1173 | +function give_get_payment_number($payment_id = 0) { |
|
| 1174 | 1174 | |
| 1175 | 1175 | $number = $payment_id; |
| 1176 | 1176 | |
| 1177 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
| 1177 | + if (give_get_option('enable_sequential')) { |
|
| 1178 | 1178 | |
| 1179 | - $number = give_get_payment_meta( $payment_id, '_give_payment_number', true ); |
|
| 1179 | + $number = give_get_payment_meta($payment_id, '_give_payment_number', true); |
|
| 1180 | 1180 | |
| 1181 | - if ( ! $number ) { |
|
| 1181 | + if ( ! $number) { |
|
| 1182 | 1182 | |
| 1183 | 1183 | $number = $payment_id; |
| 1184 | 1184 | |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | - return apply_filters( 'give_payment_number', $number, $payment_id ); |
|
| 1189 | + return apply_filters('give_payment_number', $number, $payment_id); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | /** |
@@ -1198,23 +1198,23 @@ discard block |
||
| 1198 | 1198 | * |
| 1199 | 1199 | * @return string The formatted payment number |
| 1200 | 1200 | */ |
| 1201 | -function give_format_payment_number( $number ) { |
|
| 1201 | +function give_format_payment_number($number) { |
|
| 1202 | 1202 | |
| 1203 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
| 1203 | + if ( ! give_get_option('enable_sequential')) { |
|
| 1204 | 1204 | return $number; |
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | - if ( ! is_numeric( $number ) ) { |
|
| 1207 | + if ( ! is_numeric($number)) { |
|
| 1208 | 1208 | return $number; |
| 1209 | 1209 | } |
| 1210 | 1210 | |
| 1211 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
| 1212 | - $number = absint( $number ); |
|
| 1213 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
| 1211 | + $prefix = give_get_option('sequential_prefix'); |
|
| 1212 | + $number = absint($number); |
|
| 1213 | + $postfix = give_get_option('sequential_postfix'); |
|
| 1214 | 1214 | |
| 1215 | - $formatted_number = $prefix . $number . $postfix; |
|
| 1215 | + $formatted_number = $prefix.$number.$postfix; |
|
| 1216 | 1216 | |
| 1217 | - return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix ); |
|
| 1217 | + return apply_filters('give_format_payment_number', $formatted_number, $prefix, $number, $postfix); |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | /** |
@@ -1227,17 +1227,17 @@ discard block |
||
| 1227 | 1227 | */ |
| 1228 | 1228 | function give_get_next_payment_number() { |
| 1229 | 1229 | |
| 1230 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
| 1230 | + if ( ! give_get_option('enable_sequential')) { |
|
| 1231 | 1231 | return false; |
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | - $number = get_option( 'give_last_payment_number' ); |
|
| 1235 | - $start = give_get_option( 'sequential_start', 1 ); |
|
| 1234 | + $number = get_option('give_last_payment_number'); |
|
| 1235 | + $start = give_get_option('sequential_start', 1); |
|
| 1236 | 1236 | $increment_number = true; |
| 1237 | 1237 | |
| 1238 | - if ( false !== $number ) { |
|
| 1238 | + if (false !== $number) { |
|
| 1239 | 1239 | |
| 1240 | - if ( empty( $number ) ) { |
|
| 1240 | + if (empty($number)) { |
|
| 1241 | 1241 | |
| 1242 | 1242 | $number = $start; |
| 1243 | 1243 | $increment_number = false; |
@@ -1247,24 +1247,24 @@ discard block |
||
| 1247 | 1247 | } else { |
| 1248 | 1248 | |
| 1249 | 1249 | // This case handles the first addition of the new option, as well as if it get's deleted for any reason |
| 1250 | - $payments = new Give_Payments_Query( array( |
|
| 1250 | + $payments = new Give_Payments_Query(array( |
|
| 1251 | 1251 | 'number' => 1, |
| 1252 | 1252 | 'order' => 'DESC', |
| 1253 | 1253 | 'orderby' => 'ID', |
| 1254 | 1254 | 'output' => 'posts', |
| 1255 | 1255 | 'fields' => 'ids' |
| 1256 | - ) ); |
|
| 1256 | + )); |
|
| 1257 | 1257 | $last_payment = $payments->get_payments(); |
| 1258 | 1258 | |
| 1259 | - if ( $last_payment ) { |
|
| 1259 | + if ($last_payment) { |
|
| 1260 | 1260 | |
| 1261 | - $number = give_get_payment_number( $last_payment[0] ); |
|
| 1261 | + $number = give_get_payment_number($last_payment[0]); |
|
| 1262 | 1262 | |
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | - if ( ! empty( $number ) && $number !== $last_payment[0] ) { |
|
| 1265 | + if ( ! empty($number) && $number !== $last_payment[0]) { |
|
| 1266 | 1266 | |
| 1267 | - $number = give_remove_payment_prefix_postfix( $number ); |
|
| 1267 | + $number = give_remove_payment_prefix_postfix($number); |
|
| 1268 | 1268 | |
| 1269 | 1269 | } else { |
| 1270 | 1270 | |
@@ -1274,13 +1274,13 @@ discard block |
||
| 1274 | 1274 | |
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | - $increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number ); |
|
| 1277 | + $increment_number = apply_filters('give_increment_payment_number', $increment_number, $number); |
|
| 1278 | 1278 | |
| 1279 | - if ( $increment_number ) { |
|
| 1280 | - $number ++; |
|
| 1279 | + if ($increment_number) { |
|
| 1280 | + $number++; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | - return apply_filters( 'give_get_next_payment_number', $number ); |
|
| 1283 | + return apply_filters('give_get_next_payment_number', $number); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | /** |
@@ -1292,25 +1292,25 @@ discard block |
||
| 1292 | 1292 | * |
| 1293 | 1293 | * @return string The new Payment number without prefix and postfix |
| 1294 | 1294 | */ |
| 1295 | -function give_remove_payment_prefix_postfix( $number ) { |
|
| 1295 | +function give_remove_payment_prefix_postfix($number) { |
|
| 1296 | 1296 | |
| 1297 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
| 1298 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
| 1297 | + $prefix = give_get_option('sequential_prefix'); |
|
| 1298 | + $postfix = give_get_option('sequential_postfix'); |
|
| 1299 | 1299 | |
| 1300 | 1300 | // Remove prefix |
| 1301 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 1301 | + $number = preg_replace('/'.$prefix.'/', '', $number, 1); |
|
| 1302 | 1302 | |
| 1303 | 1303 | // Remove the postfix |
| 1304 | - $length = strlen( $number ); |
|
| 1305 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 1306 | - if ( false !== $postfix_pos ) { |
|
| 1307 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 1304 | + $length = strlen($number); |
|
| 1305 | + $postfix_pos = strrpos($number, $postfix); |
|
| 1306 | + if (false !== $postfix_pos) { |
|
| 1307 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | // Ensure it's a whole number |
| 1311 | - $number = intval( $number ); |
|
| 1311 | + $number = intval($number); |
|
| 1312 | 1312 | |
| 1313 | - return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix ); |
|
| 1313 | + return apply_filters('give_remove_payment_prefix_postfix', $number, $prefix, $postfix); |
|
| 1314 | 1314 | |
| 1315 | 1315 | } |
| 1316 | 1316 | |
@@ -1326,10 +1326,10 @@ discard block |
||
| 1326 | 1326 | * |
| 1327 | 1327 | * @return string $amount Fully formatted payment amount |
| 1328 | 1328 | */ |
| 1329 | -function give_payment_amount( $payment_id = 0 ) { |
|
| 1330 | - $amount = give_get_payment_amount( $payment_id ); |
|
| 1329 | +function give_payment_amount($payment_id = 0) { |
|
| 1330 | + $amount = give_get_payment_amount($payment_id); |
|
| 1331 | 1331 | |
| 1332 | - return give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment_id ) ); |
|
| 1332 | + return give_currency_filter(give_format_amount($amount), give_get_payment_currency_code($payment_id)); |
|
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | /** |
@@ -1342,20 +1342,20 @@ discard block |
||
| 1342 | 1342 | * |
| 1343 | 1343 | * @return mixed|void |
| 1344 | 1344 | */ |
| 1345 | -function give_get_payment_amount( $payment_id ) { |
|
| 1345 | +function give_get_payment_amount($payment_id) { |
|
| 1346 | 1346 | |
| 1347 | - $amount = give_get_payment_meta( $payment_id, '_give_payment_total', true ); |
|
| 1347 | + $amount = give_get_payment_meta($payment_id, '_give_payment_total', true); |
|
| 1348 | 1348 | |
| 1349 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
| 1350 | - $meta = give_get_payment_meta( $payment_id, '_give_payment_meta', true ); |
|
| 1351 | - $meta = maybe_unserialize( $meta ); |
|
| 1349 | + if (empty($amount) && '0.00' != $amount) { |
|
| 1350 | + $meta = give_get_payment_meta($payment_id, '_give_payment_meta', true); |
|
| 1351 | + $meta = maybe_unserialize($meta); |
|
| 1352 | 1352 | |
| 1353 | - if ( isset( $meta['amount'] ) ) { |
|
| 1353 | + if (isset($meta['amount'])) { |
|
| 1354 | 1354 | $amount = $meta['amount']; |
| 1355 | 1355 | } |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | - return apply_filters( 'give_payment_amount', floatval( $amount ), $payment_id ); |
|
| 1358 | + return apply_filters('give_payment_amount', floatval($amount), $payment_id); |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | |
@@ -1368,19 +1368,19 @@ discard block |
||
| 1368 | 1368 | * |
| 1369 | 1369 | * @return string The Transaction ID |
| 1370 | 1370 | */ |
| 1371 | -function give_get_payment_transaction_id( $payment_id = 0 ) { |
|
| 1371 | +function give_get_payment_transaction_id($payment_id = 0) { |
|
| 1372 | 1372 | |
| 1373 | 1373 | $transaction_id = false; |
| 1374 | - $transaction_id = give_get_payment_meta( $payment_id, '_give_payment_transaction_id', true ); |
|
| 1374 | + $transaction_id = give_get_payment_meta($payment_id, '_give_payment_transaction_id', true); |
|
| 1375 | 1375 | |
| 1376 | - if ( empty( $transaction_id ) ) { |
|
| 1376 | + if (empty($transaction_id)) { |
|
| 1377 | 1377 | |
| 1378 | - $gateway = give_get_payment_gateway( $payment_id ); |
|
| 1379 | - $transaction_id = apply_filters( 'give_get_payment_transaction_id-' . $gateway, $payment_id ); |
|
| 1378 | + $gateway = give_get_payment_gateway($payment_id); |
|
| 1379 | + $transaction_id = apply_filters('give_get_payment_transaction_id-'.$gateway, $payment_id); |
|
| 1380 | 1380 | |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | - return apply_filters( 'give_get_payment_transaction_id', $transaction_id, $payment_id ); |
|
| 1383 | + return apply_filters('give_get_payment_transaction_id', $transaction_id, $payment_id); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1393,15 +1393,15 @@ discard block |
||
| 1393 | 1393 | * |
| 1394 | 1394 | * @return bool|mixed |
| 1395 | 1395 | */ |
| 1396 | -function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) { |
|
| 1396 | +function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') { |
|
| 1397 | 1397 | |
| 1398 | - if ( empty( $payment_id ) || empty( $transaction_id ) ) { |
|
| 1398 | + if (empty($payment_id) || empty($transaction_id)) { |
|
| 1399 | 1399 | return false; |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | - $transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
| 1402 | + $transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id); |
|
| 1403 | 1403 | |
| 1404 | - return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id ); |
|
| 1404 | + return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id); |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | /** |
@@ -1415,12 +1415,12 @@ discard block |
||
| 1415 | 1415 | * |
| 1416 | 1416 | * @return int $purchase Purchase ID |
| 1417 | 1417 | */ |
| 1418 | -function give_get_purchase_id_by_key( $key ) { |
|
| 1418 | +function give_get_purchase_id_by_key($key) { |
|
| 1419 | 1419 | global $wpdb; |
| 1420 | 1420 | |
| 1421 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1421 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key)); |
|
| 1422 | 1422 | |
| 1423 | - if ( $purchase != null ) { |
|
| 1423 | + if ($purchase != null) { |
|
| 1424 | 1424 | return $purchase; |
| 1425 | 1425 | } |
| 1426 | 1426 | |
@@ -1439,12 +1439,12 @@ discard block |
||
| 1439 | 1439 | * |
| 1440 | 1440 | * @return int $purchase Purchase ID |
| 1441 | 1441 | */ |
| 1442 | -function give_get_purchase_id_by_transaction_id( $key ) { |
|
| 1442 | +function give_get_purchase_id_by_transaction_id($key) { |
|
| 1443 | 1443 | global $wpdb; |
| 1444 | 1444 | |
| 1445 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1445 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 1446 | 1446 | |
| 1447 | - if ( $purchase != null ) { |
|
| 1447 | + if ($purchase != null) { |
|
| 1448 | 1448 | return $purchase; |
| 1449 | 1449 | } |
| 1450 | 1450 | |
@@ -1461,19 +1461,19 @@ discard block |
||
| 1461 | 1461 | * |
| 1462 | 1462 | * @return array $notes Payment Notes |
| 1463 | 1463 | */ |
| 1464 | -function give_get_payment_notes( $payment_id = 0, $search = '' ) { |
|
| 1464 | +function give_get_payment_notes($payment_id = 0, $search = '') { |
|
| 1465 | 1465 | |
| 1466 | - if ( empty( $payment_id ) && empty( $search ) ) { |
|
| 1466 | + if (empty($payment_id) && empty($search)) { |
|
| 1467 | 1467 | return false; |
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | - remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
| 1471 | - remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
| 1470 | + remove_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
| 1471 | + remove_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
| 1472 | 1472 | |
| 1473 | - $notes = get_comments( array( 'post_id' => $payment_id, 'order' => 'ASC', 'search' => $search ) ); |
|
| 1473 | + $notes = get_comments(array('post_id' => $payment_id, 'order' => 'ASC', 'search' => $search)); |
|
| 1474 | 1474 | |
| 1475 | - add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
| 1476 | - add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
| 1475 | + add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
| 1476 | + add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
| 1477 | 1477 | |
| 1478 | 1478 | return $notes; |
| 1479 | 1479 | } |
@@ -1489,19 +1489,19 @@ discard block |
||
| 1489 | 1489 | * |
| 1490 | 1490 | * @return int The new note ID |
| 1491 | 1491 | */ |
| 1492 | -function give_insert_payment_note( $payment_id = 0, $note = '' ) { |
|
| 1493 | - if ( empty( $payment_id ) ) { |
|
| 1492 | +function give_insert_payment_note($payment_id = 0, $note = '') { |
|
| 1493 | + if (empty($payment_id)) { |
|
| 1494 | 1494 | return false; |
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | - do_action( 'give_pre_insert_payment_note', $payment_id, $note ); |
|
| 1497 | + do_action('give_pre_insert_payment_note', $payment_id, $note); |
|
| 1498 | 1498 | |
| 1499 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
| 1499 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
| 1500 | 1500 | 'comment_post_ID' => $payment_id, |
| 1501 | 1501 | 'comment_content' => $note, |
| 1502 | 1502 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
| 1503 | - 'comment_date' => current_time( 'mysql' ), |
|
| 1504 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
| 1503 | + 'comment_date' => current_time('mysql'), |
|
| 1504 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
| 1505 | 1505 | 'comment_approved' => 1, |
| 1506 | 1506 | 'comment_parent' => 0, |
| 1507 | 1507 | 'comment_author' => '', |
@@ -1510,9 +1510,9 @@ discard block |
||
| 1510 | 1510 | 'comment_author_email' => '', |
| 1511 | 1511 | 'comment_type' => 'give_payment_note' |
| 1512 | 1512 | |
| 1513 | - ) ) ); |
|
| 1513 | + ))); |
|
| 1514 | 1514 | |
| 1515 | - do_action( 'give_insert_payment_note', $note_id, $payment_id, $note ); |
|
| 1515 | + do_action('give_insert_payment_note', $note_id, $payment_id, $note); |
|
| 1516 | 1516 | |
| 1517 | 1517 | return $note_id; |
| 1518 | 1518 | } |
@@ -1527,14 +1527,14 @@ discard block |
||
| 1527 | 1527 | * |
| 1528 | 1528 | * @return bool True on success, false otherwise |
| 1529 | 1529 | */ |
| 1530 | -function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) { |
|
| 1531 | - if ( empty( $comment_id ) ) { |
|
| 1530 | +function give_delete_payment_note($comment_id = 0, $payment_id = 0) { |
|
| 1531 | + if (empty($comment_id)) { |
|
| 1532 | 1532 | return false; |
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | - do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id ); |
|
| 1536 | - $ret = wp_delete_comment( $comment_id, true ); |
|
| 1537 | - do_action( 'give_post_delete_payment_note', $comment_id, $payment_id ); |
|
| 1535 | + do_action('give_pre_delete_payment_note', $comment_id, $payment_id); |
|
| 1536 | + $ret = wp_delete_comment($comment_id, true); |
|
| 1537 | + do_action('give_post_delete_payment_note', $comment_id, $payment_id); |
|
| 1538 | 1538 | |
| 1539 | 1539 | return $ret; |
| 1540 | 1540 | } |
@@ -1549,32 +1549,32 @@ discard block |
||
| 1549 | 1549 | * |
| 1550 | 1550 | * @return string |
| 1551 | 1551 | */ |
| 1552 | -function give_get_payment_note_html( $note, $payment_id = 0 ) { |
|
| 1552 | +function give_get_payment_note_html($note, $payment_id = 0) { |
|
| 1553 | 1553 | |
| 1554 | - if ( is_numeric( $note ) ) { |
|
| 1555 | - $note = get_comment( $note ); |
|
| 1554 | + if (is_numeric($note)) { |
|
| 1555 | + $note = get_comment($note); |
|
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | - if ( ! empty( $note->user_id ) ) { |
|
| 1559 | - $user = get_userdata( $note->user_id ); |
|
| 1558 | + if ( ! empty($note->user_id)) { |
|
| 1559 | + $user = get_userdata($note->user_id); |
|
| 1560 | 1560 | $user = $user->display_name; |
| 1561 | 1561 | } else { |
| 1562 | - $user = __( 'System', 'give' ); |
|
| 1562 | + $user = __('System', 'give'); |
|
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | - $date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' ); |
|
| 1565 | + $date_format = get_option('date_format').', '.get_option('time_format'); |
|
| 1566 | 1566 | |
| 1567 | - $delete_note_url = wp_nonce_url( add_query_arg( array( |
|
| 1567 | + $delete_note_url = wp_nonce_url(add_query_arg(array( |
|
| 1568 | 1568 | 'give-action' => 'delete_payment_note', |
| 1569 | 1569 | 'note_id' => $note->comment_ID, |
| 1570 | 1570 | 'payment_id' => $payment_id |
| 1571 | - ) ), 'give_delete_payment_note_' . $note->comment_ID ); |
|
| 1571 | + )), 'give_delete_payment_note_'.$note->comment_ID); |
|
| 1572 | 1572 | |
| 1573 | - $note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">'; |
|
| 1573 | + $note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">'; |
|
| 1574 | 1574 | $note_html .= '<p>'; |
| 1575 | - $note_html .= '<strong>' . $user . '</strong> – <span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>'; |
|
| 1575 | + $note_html .= '<strong>'.$user.'</strong> – <span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>'; |
|
| 1576 | 1576 | $note_html .= $note->comment_content; |
| 1577 | - $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 ) . '" title="' . __( 'Delete this payment note', 'give' ) . '">' . __( 'Delete', 'give' ) . '</a>'; |
|
| 1577 | + $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).'" title="'.__('Delete this payment note', 'give').'">'.__('Delete', 'give').'</a>'; |
|
| 1578 | 1578 | $note_html .= '</p>'; |
| 1579 | 1579 | $note_html .= '</div>'; |
| 1580 | 1580 | |
@@ -1592,20 +1592,20 @@ discard block |
||
| 1592 | 1592 | * |
| 1593 | 1593 | * @return void |
| 1594 | 1594 | */ |
| 1595 | -function give_hide_payment_notes( $query ) { |
|
| 1595 | +function give_hide_payment_notes($query) { |
|
| 1596 | 1596 | global $wp_version; |
| 1597 | 1597 | |
| 1598 | - if ( version_compare( floatval( $wp_version ), '4.1', '>=' ) ) { |
|
| 1599 | - $types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array(); |
|
| 1600 | - if ( ! is_array( $types ) ) { |
|
| 1601 | - $types = array( $types ); |
|
| 1598 | + if (version_compare(floatval($wp_version), '4.1', '>=')) { |
|
| 1599 | + $types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array(); |
|
| 1600 | + if ( ! is_array($types)) { |
|
| 1601 | + $types = array($types); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | $types[] = 'give_payment_note'; |
| 1604 | 1604 | $query->query_vars['type__not_in'] = $types; |
| 1605 | 1605 | } |
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | -add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
| 1608 | +add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
| 1609 | 1609 | |
| 1610 | 1610 | /** |
| 1611 | 1611 | * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets |
@@ -1617,17 +1617,17 @@ discard block |
||
| 1617 | 1617 | * |
| 1618 | 1618 | * @return array $clauses Updated comment clauses |
| 1619 | 1619 | */ |
| 1620 | -function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) { |
|
| 1620 | +function give_hide_payment_notes_pre_41($clauses, $wp_comment_query) { |
|
| 1621 | 1621 | global $wpdb, $wp_version; |
| 1622 | 1622 | |
| 1623 | - if ( version_compare( floatval( $wp_version ), '4.1', '<' ) ) { |
|
| 1623 | + if (version_compare(floatval($wp_version), '4.1', '<')) { |
|
| 1624 | 1624 | $clauses['where'] .= ' AND comment_type != "give_payment_note"'; |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | 1627 | return $clauses; |
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | -add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
| 1630 | +add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
| 1631 | 1631 | |
| 1632 | 1632 | |
| 1633 | 1633 | /** |
@@ -1640,15 +1640,15 @@ discard block |
||
| 1640 | 1640 | * |
| 1641 | 1641 | * @return array $where |
| 1642 | 1642 | */ |
| 1643 | -function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) { |
|
| 1643 | +function give_hide_payment_notes_from_feeds($where, $wp_comment_query) { |
|
| 1644 | 1644 | global $wpdb; |
| 1645 | 1645 | |
| 1646 | - $where .= $wpdb->prepare( " AND comment_type != %s", 'give_payment_note' ); |
|
| 1646 | + $where .= $wpdb->prepare(" AND comment_type != %s", 'give_payment_note'); |
|
| 1647 | 1647 | |
| 1648 | 1648 | return $where; |
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | -add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 ); |
|
| 1651 | +add_filter('comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2); |
|
| 1652 | 1652 | |
| 1653 | 1653 | |
| 1654 | 1654 | /** |
@@ -1662,32 +1662,32 @@ discard block |
||
| 1662 | 1662 | * |
| 1663 | 1663 | * @return array Array of comment counts |
| 1664 | 1664 | */ |
| 1665 | -function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) { |
|
| 1665 | +function give_remove_payment_notes_in_comment_counts($stats, $post_id) { |
|
| 1666 | 1666 | global $wpdb, $pagenow; |
| 1667 | 1667 | |
| 1668 | - if ( 'index.php' != $pagenow ) { |
|
| 1668 | + if ('index.php' != $pagenow) { |
|
| 1669 | 1669 | return $stats; |
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | $post_id = (int) $post_id; |
| 1673 | 1673 | |
| 1674 | - if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) { |
|
| 1674 | + if (apply_filters('give_count_payment_notes_in_comments', false)) { |
|
| 1675 | 1675 | return $stats; |
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | - $stats = wp_cache_get( "comments-{$post_id}", 'counts' ); |
|
| 1678 | + $stats = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1679 | 1679 | |
| 1680 | - if ( false !== $stats ) { |
|
| 1680 | + if (false !== $stats) { |
|
| 1681 | 1681 | return $stats; |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | 1684 | $where = 'WHERE comment_type != "give_payment_note"'; |
| 1685 | 1685 | |
| 1686 | - if ( $post_id > 0 ) { |
|
| 1687 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1686 | + if ($post_id > 0) { |
|
| 1687 | + $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id); |
|
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1690 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
| 1691 | 1691 | |
| 1692 | 1692 | $total = 0; |
| 1693 | 1693 | $approved = array( |
@@ -1697,30 +1697,30 @@ discard block |
||
| 1697 | 1697 | 'trash' => 'trash', |
| 1698 | 1698 | 'post-trashed' => 'post-trashed' |
| 1699 | 1699 | ); |
| 1700 | - foreach ( (array) $count as $row ) { |
|
| 1700 | + foreach ((array) $count as $row) { |
|
| 1701 | 1701 | // Don't count post-trashed toward totals |
| 1702 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
| 1702 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { |
|
| 1703 | 1703 | $total += $row['num_comments']; |
| 1704 | 1704 | } |
| 1705 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 1706 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 1705 | + if (isset($approved[$row['comment_approved']])) { |
|
| 1706 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1707 | 1707 | } |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | $stats['total_comments'] = $total; |
| 1711 | - foreach ( $approved as $key ) { |
|
| 1712 | - if ( empty( $stats[ $key ] ) ) { |
|
| 1713 | - $stats[ $key ] = 0; |
|
| 1711 | + foreach ($approved as $key) { |
|
| 1712 | + if (empty($stats[$key])) { |
|
| 1713 | + $stats[$key] = 0; |
|
| 1714 | 1714 | } |
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | $stats = (object) $stats; |
| 1718 | - wp_cache_set( "comments-{$post_id}", $stats, 'counts' ); |
|
| 1718 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1719 | 1719 | |
| 1720 | 1720 | return $stats; |
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | -add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 ); |
|
| 1723 | +add_filter('wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2); |
|
| 1724 | 1724 | |
| 1725 | 1725 | |
| 1726 | 1726 | /** |
@@ -1733,9 +1733,9 @@ discard block |
||
| 1733 | 1733 | * |
| 1734 | 1734 | * @return string $where Modified where clause |
| 1735 | 1735 | */ |
| 1736 | -function give_filter_where_older_than_week( $where = '' ) { |
|
| 1736 | +function give_filter_where_older_than_week($where = '') { |
|
| 1737 | 1737 | // Payments older than one week |
| 1738 | - $start = date( 'Y-m-d', strtotime( '-7 days' ) ); |
|
| 1738 | + $start = date('Y-m-d', strtotime('-7 days')); |
|
| 1739 | 1739 | $where .= " AND post_date <= '{$start}'"; |
| 1740 | 1740 | |
| 1741 | 1741 | return $where; |
@@ -1752,20 +1752,20 @@ discard block |
||
| 1752 | 1752 | * |
| 1753 | 1753 | * @return string $price_id |
| 1754 | 1754 | */ |
| 1755 | -function give_get_price_id( $form_id, $price ) { |
|
| 1755 | +function give_get_price_id($form_id, $price) { |
|
| 1756 | 1756 | |
| 1757 | 1757 | $price_id = 0; |
| 1758 | 1758 | |
| 1759 | - if ( give_has_variable_prices( $form_id ) ) { |
|
| 1759 | + if (give_has_variable_prices($form_id)) { |
|
| 1760 | 1760 | |
| 1761 | - $levels = maybe_unserialize( get_post_meta( $form_id, '_give_donation_levels', true ) ); |
|
| 1761 | + $levels = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true)); |
|
| 1762 | 1762 | |
| 1763 | - foreach ( $levels as $level ) { |
|
| 1763 | + foreach ($levels as $level) { |
|
| 1764 | 1764 | |
| 1765 | - $level_amount = (float) give_sanitize_amount( $level['_give_amount'] ); |
|
| 1765 | + $level_amount = (float) give_sanitize_amount($level['_give_amount']); |
|
| 1766 | 1766 | |
| 1767 | 1767 | //check that this indeed the recurring price |
| 1768 | - if ( $level_amount == $price ) { |
|
| 1768 | + if ($level_amount == $price) { |
|
| 1769 | 1769 | |
| 1770 | 1770 | $price_id = $level['_give_id']['level_id']; |
| 1771 | 1771 | |
@@ -1789,14 +1789,14 @@ discard block |
||
| 1789 | 1789 | * |
| 1790 | 1790 | * @return mixed array if payment fees found, false otherwise |
| 1791 | 1791 | */ |
| 1792 | -function give_get_payment_fees( $payment_id = 0, $type = 'all' ) { |
|
| 1793 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
| 1792 | +function give_get_payment_fees($payment_id = 0, $type = 'all') { |
|
| 1793 | + $payment_meta = give_get_payment_meta($payment_id); |
|
| 1794 | 1794 | $fees = array(); |
| 1795 | - $payment_fees = isset( $payment_meta['fees'] ) ? $payment_meta['fees'] : false; |
|
| 1796 | - if ( ! empty( $payment_fees ) && is_array( $payment_fees ) ) { |
|
| 1797 | - foreach ( $payment_fees as $fee_id => $fee ) { |
|
| 1798 | - if ( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1799 | - unset( $payment_fees[ $fee_id ] ); |
|
| 1795 | + $payment_fees = isset($payment_meta['fees']) ? $payment_meta['fees'] : false; |
|
| 1796 | + if ( ! empty($payment_fees) && is_array($payment_fees)) { |
|
| 1797 | + foreach ($payment_fees as $fee_id => $fee) { |
|
| 1798 | + if ('all' != $type && ! empty($fee['type']) && $type != $fee['type']) { |
|
| 1799 | + unset($payment_fees[$fee_id]); |
|
| 1800 | 1800 | } else { |
| 1801 | 1801 | $fees[] = array( |
| 1802 | 1802 | 'id' => $fee_id, |
@@ -1807,5 +1807,5 @@ discard block |
||
| 1807 | 1807 | } |
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | - return apply_filters( 'give_get_payment_fees', $fees, $payment_id ); |
|
| 1810 | + return apply_filters('give_get_payment_fees', $fees, $payment_id); |
|
| 1811 | 1811 | } |
| 1812 | 1812 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @access private |
| 23 | 23 | * @since 1.0 |
| 24 | - * @return void |
|
| 24 | + * @return false|null |
|
| 25 | 25 | */ |
| 26 | 26 | function give_process_purchase_form() { |
| 27 | 27 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * |
| 327 | 327 | * @since 1.0.1 |
| 328 | 328 | * |
| 329 | - * @param $payment_mode |
|
| 329 | + * @param string $payment_mode |
|
| 330 | 330 | * |
| 331 | 331 | * @return mixed|void |
| 332 | 332 | */ |
@@ -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 | |
@@ -25,34 +25,34 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function give_process_purchase_form() { |
| 27 | 27 | |
| 28 | - do_action( 'give_pre_process_purchase' ); |
|
| 28 | + do_action('give_pre_process_purchase'); |
|
| 29 | 29 | |
| 30 | 30 | // Validate the form $_POST data |
| 31 | 31 | $valid_data = give_purchase_form_validate_fields(); |
| 32 | 32 | |
| 33 | 33 | // Allow themes and plugins to hook to errors |
| 34 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
| 34 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
| 35 | 35 | |
| 36 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
| 36 | + $is_ajax = isset($_POST['give_ajax']); |
|
| 37 | 37 | |
| 38 | 38 | // Process the login form |
| 39 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
| 39 | + if (isset($_POST['give_login_submit'])) { |
|
| 40 | 40 | give_process_form_login(); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Validate the user |
| 44 | - $user = give_get_purchase_form_user( $valid_data ); |
|
| 44 | + $user = give_get_purchase_form_user($valid_data); |
|
| 45 | 45 | |
| 46 | - if ( give_get_errors() || ! $user ) { |
|
| 47 | - if ( $is_ajax ) { |
|
| 48 | - do_action( 'give_ajax_checkout_errors' ); |
|
| 46 | + if (give_get_errors() || ! $user) { |
|
| 47 | + if ($is_ajax) { |
|
| 48 | + do_action('give_ajax_checkout_errors'); |
|
| 49 | 49 | give_die(); |
| 50 | 50 | } else { |
| 51 | 51 | return false; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( $is_ajax ) { |
|
| 55 | + if ($is_ajax) { |
|
| 56 | 56 | echo 'success'; |
| 57 | 57 | give_die(); |
| 58 | 58 | } |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | 'address' => $user['address'] |
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 69 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 70 | 70 | |
| 71 | 71 | // Setup purchase information |
| 72 | 72 | $purchase_data = array( |
| 73 | - 'price' => ( isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00' ), |
|
| 74 | - 'purchase_key' => strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ), |
|
| 73 | + 'price' => (isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'), |
|
| 74 | + 'purchase_key' => strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))), |
|
| 75 | 75 | 'user_email' => $user['user_email'], |
| 76 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 77 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 76 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 77 | + 'user_info' => stripslashes_deep($user_info), |
|
| 78 | 78 | 'post_data' => $_POST, |
| 79 | 79 | 'gateway' => $valid_data['gateway'], |
| 80 | 80 | 'card_info' => $valid_data['cc_info'] |
@@ -84,36 +84,36 @@ discard block |
||
| 84 | 84 | $valid_data['user'] = $user; |
| 85 | 85 | |
| 86 | 86 | // Allow themes and plugins to hook before the gateway |
| 87 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 87 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 88 | 88 | |
| 89 | 89 | //Sanity check for price |
| 90 | - if ( ! $purchase_data['price'] ) { |
|
| 90 | + if ( ! $purchase_data['price']) { |
|
| 91 | 91 | // Revert to manual |
| 92 | 92 | $purchase_data['gateway'] = 'manual'; |
| 93 | 93 | $_POST['give-gateway'] = 'manual'; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Allow the purchase data to be modified before it is sent to the gateway |
| 97 | - $purchase_data = apply_filters( 'give_purchase_data_before_gateway', $purchase_data, $valid_data ); |
|
| 97 | + $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); |
|
| 98 | 98 | |
| 99 | 99 | // Setup the data we're storing in the purchase session |
| 100 | 100 | $session_data = $purchase_data; |
| 101 | 101 | |
| 102 | 102 | // Make sure credit card numbers are never stored in sessions |
| 103 | - unset( $session_data['card_info']['card_number'] ); |
|
| 103 | + unset($session_data['card_info']['card_number']); |
|
| 104 | 104 | |
| 105 | 105 | // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. |
| 106 | - give_set_purchase_session( $session_data ); |
|
| 106 | + give_set_purchase_session($session_data); |
|
| 107 | 107 | |
| 108 | 108 | // Send info to the gateway for payment processing |
| 109 | - give_send_to_gateway( $purchase_data['gateway'], $purchase_data ); |
|
| 109 | + give_send_to_gateway($purchase_data['gateway'], $purchase_data); |
|
| 110 | 110 | give_die(); |
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -add_action( 'give_purchase', 'give_process_purchase_form' ); |
|
| 115 | -add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' ); |
|
| 116 | -add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' ); |
|
| 114 | +add_action('give_purchase', 'give_process_purchase_form'); |
|
| 115 | +add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form'); |
|
| 116 | +add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form'); |
|
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | 119 | * Process the checkout login form |
@@ -124,32 +124,32 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | function give_process_form_login() { |
| 126 | 126 | |
| 127 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
| 127 | + $is_ajax = isset($_POST['give_ajax']); |
|
| 128 | 128 | |
| 129 | 129 | $user_data = give_purchase_form_validate_user_login(); |
| 130 | 130 | |
| 131 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
| 132 | - if ( $is_ajax ) { |
|
| 133 | - do_action( 'give_ajax_checkout_errors' ); |
|
| 131 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
| 132 | + if ($is_ajax) { |
|
| 133 | + do_action('give_ajax_checkout_errors'); |
|
| 134 | 134 | give_die(); |
| 135 | 135 | } else { |
| 136 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
| 136 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
| 137 | 137 | exit; |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
| 141 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
| 142 | 142 | |
| 143 | - if ( $is_ajax ) { |
|
| 143 | + if ($is_ajax) { |
|
| 144 | 144 | echo 'success'; |
| 145 | 145 | give_die(); |
| 146 | 146 | } else { |
| 147 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
| 147 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' ); |
|
| 152 | -add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' ); |
|
| 151 | +add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login'); |
|
| 152 | +add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login'); |
|
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Purchase Form Validate Fields |
@@ -161,40 +161,40 @@ discard block |
||
| 161 | 161 | function give_purchase_form_validate_fields() { |
| 162 | 162 | |
| 163 | 163 | // Check if there is $_POST |
| 164 | - if ( empty( $_POST ) ) { |
|
| 164 | + if (empty($_POST)) { |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
| 168 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
| 169 | 169 | |
| 170 | 170 | // Start an array to collect valid data |
| 171 | 171 | $valid_data = array( |
| 172 | 172 | 'gateway' => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here) |
| 173 | - 'need_new_user' => false, // New user flag |
|
| 174 | - 'need_user_login' => false, // Login user flag |
|
| 175 | - 'logged_user_data' => array(), // Logged user collected data |
|
| 176 | - 'new_user_data' => array(), // New user collected data |
|
| 177 | - 'login_user_data' => array(), // Login user collected data |
|
| 178 | - 'guest_user_data' => array(), // Guest user collected data |
|
| 173 | + 'need_new_user' => false, // New user flag |
|
| 174 | + 'need_user_login' => false, // Login user flag |
|
| 175 | + 'logged_user_data' => array(), // Logged user collected data |
|
| 176 | + 'new_user_data' => array(), // New user collected data |
|
| 177 | + 'login_user_data' => array(), // Login user collected data |
|
| 178 | + 'guest_user_data' => array(), // Guest user collected data |
|
| 179 | 179 | 'cc_info' => give_purchase_form_validate_cc() // Credit card info |
| 180 | 180 | ); |
| 181 | 181 | |
| 182 | 182 | // Validate agree to terms |
| 183 | - $terms_option = get_post_meta( $form_id, '_give_terms_option', true ); |
|
| 184 | - if ( isset( $terms_option ) && $terms_option === 'yes' ) { |
|
| 183 | + $terms_option = get_post_meta($form_id, '_give_terms_option', true); |
|
| 184 | + if (isset($terms_option) && $terms_option === 'yes') { |
|
| 185 | 185 | give_purchase_form_validate_agree_to_terms(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( is_user_logged_in() ) { |
|
| 188 | + if (is_user_logged_in()) { |
|
| 189 | 189 | // Collect logged in user data |
| 190 | 190 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
| 191 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
| 191 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
| 192 | 192 | // Set new user registration as required |
| 193 | 193 | $valid_data['need_new_user'] = true; |
| 194 | 194 | // Validate new user data |
| 195 | 195 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
| 196 | 196 | // Check if login validation is needed |
| 197 | - } else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
| 197 | + } else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
| 198 | 198 | // Set user login as required |
| 199 | 199 | $valid_data['need_user_login'] = true; |
| 200 | 200 | // Validate users login info |
@@ -217,35 +217,35 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | function give_purchase_form_validate_gateway() { |
| 219 | 219 | |
| 220 | - $gateway = give_get_default_gateway( $_REQUEST['give-form-id'] ); |
|
| 220 | + $gateway = give_get_default_gateway($_REQUEST['give-form-id']); |
|
| 221 | 221 | |
| 222 | 222 | // Check if a gateway value is present |
| 223 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
| 223 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
| 224 | 224 | |
| 225 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
| 225 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
| 226 | 226 | |
| 227 | 227 | //Is amount being donated in LIVE mode above 0.00? |
| 228 | - if ( '0.00' == $_REQUEST['give-amount'] && ! give_is_test_mode() ) { |
|
| 228 | + if ('0.00' == $_REQUEST['give-amount'] && ! give_is_test_mode()) { |
|
| 229 | 229 | |
| 230 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
| 230 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
| 231 | 231 | |
| 232 | 232 | } //Check for a minimum custom amount |
| 233 | - elseif ( ! give_verify_minimum_price() ) { |
|
| 233 | + elseif ( ! give_verify_minimum_price()) { |
|
| 234 | 234 | |
| 235 | - $minimum = give_currency_filter( give_format_amount( give_get_form_minimum_price( $_REQUEST['give-form-id'] ) ) ); |
|
| 236 | - $error_message = __( 'This form has a minimum donation amount of %s', 'give' ); |
|
| 235 | + $minimum = give_currency_filter(give_format_amount(give_get_form_minimum_price($_REQUEST['give-form-id']))); |
|
| 236 | + $error_message = __('This form has a minimum donation amount of %s', 'give'); |
|
| 237 | 237 | |
| 238 | - give_set_error( 'invalid_donation_minimum', sprintf( $error_message, $minimum ) ); |
|
| 238 | + give_set_error('invalid_donation_minimum', sprintf($error_message, $minimum)); |
|
| 239 | 239 | |
| 240 | 240 | } //Is this test mode zero donation? Let it through but set to manual gateway |
| 241 | - elseif ( '0.00' == $_REQUEST['give-amount'] && give_is_test_mode() ) { |
|
| 241 | + elseif ('0.00' == $_REQUEST['give-amount'] && give_is_test_mode()) { |
|
| 242 | 242 | |
| 243 | 243 | $gateway = 'manual'; |
| 244 | 244 | |
| 245 | 245 | } //Check if this gateway is active |
| 246 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
| 246 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
| 247 | 247 | |
| 248 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'give' ) ); |
|
| 248 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'give')); |
|
| 249 | 249 | |
| 250 | 250 | } |
| 251 | 251 | |
@@ -264,23 +264,23 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | function give_verify_minimum_price() { |
| 266 | 266 | |
| 267 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
| 267 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
| 268 | 268 | $form_id = $_REQUEST['give-form-id']; |
| 269 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
| 270 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
| 269 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
| 270 | + $variable_prices = give_has_variable_prices($form_id); |
|
| 271 | 271 | |
| 272 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
| 272 | + if ($variable_prices && ! empty($price_id)) { |
|
| 273 | 273 | |
| 274 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
| 274 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
| 275 | 275 | |
| 276 | - if ( $price_level_amount == $amount ) { |
|
| 276 | + if ($price_level_amount == $amount) { |
|
| 277 | 277 | return true; |
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
| 281 | + $minimum = give_get_form_minimum_price($form_id); |
|
| 282 | 282 | |
| 283 | - if ( $minimum > $amount ) { |
|
| 283 | + if ($minimum > $amount) { |
|
| 284 | 284 | return false; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -296,9 +296,9 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function give_purchase_form_validate_agree_to_terms() { |
| 298 | 298 | // Validate agree to terms |
| 299 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
| 299 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
| 300 | 300 | // User did not agree |
| 301 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms of use', 'give' ) ) ); |
|
| 301 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms of use', 'give'))); |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
@@ -312,47 +312,47 @@ discard block |
||
| 312 | 312 | * |
| 313 | 313 | * @return array |
| 314 | 314 | */ |
| 315 | -function give_purchase_form_required_fields( $form_id ) { |
|
| 315 | +function give_purchase_form_required_fields($form_id) { |
|
| 316 | 316 | |
| 317 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
| 317 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
| 318 | 318 | |
| 319 | 319 | $required_fields = array( |
| 320 | 320 | 'give_email' => array( |
| 321 | 321 | 'error_id' => 'invalid_email', |
| 322 | - 'error_message' => __( 'Please enter a valid email address', 'give' ) |
|
| 322 | + 'error_message' => __('Please enter a valid email address', 'give') |
|
| 323 | 323 | ), |
| 324 | 324 | 'give_first' => array( |
| 325 | 325 | 'error_id' => 'invalid_first_name', |
| 326 | - 'error_message' => __( 'Please enter your first name', 'give' ) |
|
| 326 | + 'error_message' => __('Please enter your first name', 'give') |
|
| 327 | 327 | ) |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - $require_address = give_require_billing_address( $payment_mode ); |
|
| 330 | + $require_address = give_require_billing_address($payment_mode); |
|
| 331 | 331 | |
| 332 | - if ( $require_address ) { |
|
| 333 | - $required_fields['card_address'] = array( |
|
| 332 | + if ($require_address) { |
|
| 333 | + $required_fields['card_address'] = array( |
|
| 334 | 334 | 'error_id' => 'invalid_card_address', |
| 335 | - 'error_message' => __( 'Please enter your primary billing address', 'give' ) |
|
| 335 | + 'error_message' => __('Please enter your primary billing address', 'give') |
|
| 336 | 336 | ); |
| 337 | - $required_fields['card_zip'] = array( |
|
| 337 | + $required_fields['card_zip'] = array( |
|
| 338 | 338 | 'error_id' => 'invalid_zip_code', |
| 339 | - 'error_message' => __( 'Please enter your zip / postal code', 'give' ) |
|
| 339 | + 'error_message' => __('Please enter your zip / postal code', 'give') |
|
| 340 | 340 | ); |
| 341 | - $required_fields['card_city'] = array( |
|
| 341 | + $required_fields['card_city'] = array( |
|
| 342 | 342 | 'error_id' => 'invalid_city', |
| 343 | - 'error_message' => __( 'Please enter your billing city', 'give' ) |
|
| 343 | + 'error_message' => __('Please enter your billing city', 'give') |
|
| 344 | 344 | ); |
| 345 | 345 | $required_fields['billing_country'] = array( |
| 346 | 346 | 'error_id' => 'invalid_country', |
| 347 | - 'error_message' => __( 'Please select your billing country', 'give' ) |
|
| 347 | + 'error_message' => __('Please select your billing country', 'give') |
|
| 348 | 348 | ); |
| 349 | - $required_fields['card_state'] = array( |
|
| 349 | + $required_fields['card_state'] = array( |
|
| 350 | 350 | 'error_id' => 'invalid_state', |
| 351 | - 'error_message' => __( 'Please enter billing state / province', 'give' ) |
|
| 351 | + 'error_message' => __('Please enter billing state / province', 'give') |
|
| 352 | 352 | ); |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return apply_filters( 'give_purchase_form_required_fields', $required_fields, $form_id ); |
|
| 355 | + return apply_filters('give_purchase_form_required_fields', $required_fields, $form_id); |
|
| 356 | 356 | |
| 357 | 357 | } |
| 358 | 358 | |
@@ -365,16 +365,16 @@ discard block |
||
| 365 | 365 | * |
| 366 | 366 | * @return mixed|void |
| 367 | 367 | */ |
| 368 | -function give_require_billing_address( $payment_mode ) { |
|
| 368 | +function give_require_billing_address($payment_mode) { |
|
| 369 | 369 | |
| 370 | 370 | $return = false; |
| 371 | 371 | |
| 372 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
| 372 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
| 373 | 373 | $return = true; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // Let payment gateways and other extensions determine if address fields should be required |
| 377 | - return apply_filters( 'give_require_billing_address', $return ); |
|
| 377 | + return apply_filters('give_require_billing_address', $return); |
|
| 378 | 378 | |
| 379 | 379 | } |
| 380 | 380 | |
@@ -388,43 +388,43 @@ discard block |
||
| 388 | 388 | function give_purchase_form_validate_logged_in_user() { |
| 389 | 389 | global $user_ID; |
| 390 | 390 | |
| 391 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
| 391 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
| 392 | 392 | |
| 393 | 393 | // Start empty array to collect valid user data |
| 394 | 394 | $valid_user_data = array( |
| 395 | 395 | // Assume there will be errors |
| 396 | - 'user_id' => - 1 |
|
| 396 | + 'user_id' => -1 |
|
| 397 | 397 | ); |
| 398 | 398 | |
| 399 | 399 | // Verify there is a user_ID |
| 400 | - if ( $user_ID > 0 ) { |
|
| 400 | + if ($user_ID > 0) { |
|
| 401 | 401 | // Get the logged in user data |
| 402 | - $user_data = get_userdata( $user_ID ); |
|
| 402 | + $user_data = get_userdata($user_ID); |
|
| 403 | 403 | |
| 404 | 404 | // Loop through required fields and show error messages |
| 405 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
| 406 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
| 407 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
| 405 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
| 406 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
| 407 | + give_set_error($value['error_id'], $value['error_message']); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // Verify data |
| 412 | - if ( $user_data ) { |
|
| 412 | + if ($user_data) { |
|
| 413 | 413 | // Collected logged in user data |
| 414 | 414 | $valid_user_data = array( |
| 415 | 415 | 'user_id' => $user_ID, |
| 416 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
| 417 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
| 418 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
| 416 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
| 417 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
| 418 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
| 422 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
| 421 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
| 422 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | } else { |
| 426 | 426 | // Set invalid user error |
| 427 | - give_set_error( 'invalid_user', __( 'The user information is invalid', 'give' ) ); |
|
| 427 | + give_set_error('invalid_user', __('The user information is invalid', 'give')); |
|
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | 430 | |
@@ -442,92 +442,92 @@ discard block |
||
| 442 | 442 | function give_purchase_form_validate_new_user() { |
| 443 | 443 | |
| 444 | 444 | $registering_new_user = false; |
| 445 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
| 445 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
| 446 | 446 | |
| 447 | 447 | // Start an empty array to collect valid user data |
| 448 | 448 | $valid_user_data = array( |
| 449 | 449 | // Assume there will be errors |
| 450 | - 'user_id' => - 1, |
|
| 450 | + 'user_id' => -1, |
|
| 451 | 451 | // Get first name |
| 452 | - 'user_first' => isset( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : '', |
|
| 452 | + 'user_first' => isset($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : '', |
|
| 453 | 453 | // Get last name |
| 454 | - 'user_last' => isset( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : '', |
|
| 454 | + 'user_last' => isset($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : '', |
|
| 455 | 455 | ); |
| 456 | 456 | |
| 457 | 457 | // Check the new user's credentials against existing ones |
| 458 | - $user_login = isset( $_POST['give_user_login'] ) ? trim( $_POST['give_user_login'] ) : false; |
|
| 459 | - $user_email = isset( $_POST['give_email'] ) ? trim( $_POST['give_email'] ) : false; |
|
| 460 | - $user_pass = isset( $_POST['give_user_pass'] ) ? trim( $_POST['give_user_pass'] ) : false; |
|
| 461 | - $pass_confirm = isset( $_POST['give_user_pass_confirm'] ) ? trim( $_POST['give_user_pass_confirm'] ) : false; |
|
| 458 | + $user_login = isset($_POST['give_user_login']) ? trim($_POST['give_user_login']) : false; |
|
| 459 | + $user_email = isset($_POST['give_email']) ? trim($_POST['give_email']) : false; |
|
| 460 | + $user_pass = isset($_POST['give_user_pass']) ? trim($_POST['give_user_pass']) : false; |
|
| 461 | + $pass_confirm = isset($_POST['give_user_pass_confirm']) ? trim($_POST['give_user_pass_confirm']) : false; |
|
| 462 | 462 | |
| 463 | 463 | // Loop through required fields and show error messages |
| 464 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
| 465 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
| 466 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
| 464 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
| 465 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
| 466 | + give_set_error($value['error_id'], $value['error_message']); |
|
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | // Check if we have an username to register |
| 471 | - if ( $user_login && strlen( $user_login ) > 0 ) { |
|
| 471 | + if ($user_login && strlen($user_login) > 0) { |
|
| 472 | 472 | $registering_new_user = true; |
| 473 | 473 | |
| 474 | 474 | // We have an user name, check if it already exists |
| 475 | - if ( username_exists( $user_login ) ) { |
|
| 475 | + if (username_exists($user_login)) { |
|
| 476 | 476 | // Username already registered |
| 477 | - give_set_error( 'username_unavailable', __( 'Username already taken', 'give' ) ); |
|
| 477 | + give_set_error('username_unavailable', __('Username already taken', 'give')); |
|
| 478 | 478 | // Check if it's valid |
| 479 | - } else if ( ! give_validate_username( $user_login ) ) { |
|
| 479 | + } else if ( ! give_validate_username($user_login)) { |
|
| 480 | 480 | // Invalid username |
| 481 | - if ( is_multisite() ) { |
|
| 482 | - give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give' ) ); |
|
| 481 | + if (is_multisite()) { |
|
| 482 | + give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'give')); |
|
| 483 | 483 | } else { |
| 484 | - give_set_error( 'username_invalid', __( 'Invalid username', 'give' ) ); |
|
| 484 | + give_set_error('username_invalid', __('Invalid username', 'give')); |
|
| 485 | 485 | } |
| 486 | 486 | } else { |
| 487 | 487 | // All the checks have run and it's good to go |
| 488 | 488 | $valid_user_data['user_login'] = $user_login; |
| 489 | 489 | } |
| 490 | 490 | } else { |
| 491 | - if ( give_no_guest_checkout( $form_id ) ) { |
|
| 492 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation', 'give' ) ); |
|
| 491 | + if (give_no_guest_checkout($form_id)) { |
|
| 492 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation', 'give')); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | // Check if we have an email to verify |
| 497 | - if ( $user_email && strlen( $user_email ) > 0 ) { |
|
| 497 | + if ($user_email && strlen($user_email) > 0) { |
|
| 498 | 498 | // Validate email |
| 499 | - if ( ! is_email( $user_email ) ) { |
|
| 500 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
| 499 | + if ( ! is_email($user_email)) { |
|
| 500 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
| 501 | 501 | // Check if email exists |
| 502 | - } else if ( email_exists( $user_email ) && $registering_new_user ) { |
|
| 503 | - give_set_error( 'email_used', __( 'Email already used', 'give' ) ); |
|
| 502 | + } else if (email_exists($user_email) && $registering_new_user) { |
|
| 503 | + give_set_error('email_used', __('Email already used', 'give')); |
|
| 504 | 504 | } else { |
| 505 | 505 | // All the checks have run and it's good to go |
| 506 | 506 | $valid_user_data['user_email'] = $user_email; |
| 507 | 507 | } |
| 508 | 508 | } else { |
| 509 | 509 | // No email |
| 510 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
| 510 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // Check password |
| 514 | - if ( $user_pass && $pass_confirm ) { |
|
| 514 | + if ($user_pass && $pass_confirm) { |
|
| 515 | 515 | // Verify confirmation matches |
| 516 | - if ( $user_pass != $pass_confirm ) { |
|
| 516 | + if ($user_pass != $pass_confirm) { |
|
| 517 | 517 | // Passwords do not match |
| 518 | - give_set_error( 'password_mismatch', __( 'Passwords don\'t match', 'give' ) ); |
|
| 518 | + give_set_error('password_mismatch', __('Passwords don\'t match', 'give')); |
|
| 519 | 519 | } else { |
| 520 | 520 | // All is good to go |
| 521 | 521 | $valid_user_data['user_pass'] = $user_pass; |
| 522 | 522 | } |
| 523 | 523 | } else { |
| 524 | 524 | // Password or confirmation missing |
| 525 | - if ( ! $user_pass && $registering_new_user ) { |
|
| 525 | + if ( ! $user_pass && $registering_new_user) { |
|
| 526 | 526 | // The password is invalid |
| 527 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
| 528 | - } else if ( ! $pass_confirm && $registering_new_user ) { |
|
| 527 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
| 528 | + } else if ( ! $pass_confirm && $registering_new_user) { |
|
| 529 | 529 | // Confirmation password is invalid |
| 530 | - give_set_error( 'confirmation_empty', __( 'Enter the password confirmation', 'give' ) ); |
|
| 530 | + give_set_error('confirmation_empty', __('Enter the password confirmation', 'give')); |
|
| 531 | 531 | } |
| 532 | 532 | } |
| 533 | 533 | |
@@ -546,34 +546,34 @@ discard block |
||
| 546 | 546 | // Start an array to collect valid user data |
| 547 | 547 | $valid_user_data = array( |
| 548 | 548 | // Assume there will be errors |
| 549 | - 'user_id' => - 1 |
|
| 549 | + 'user_id' => -1 |
|
| 550 | 550 | ); |
| 551 | 551 | |
| 552 | 552 | // Username |
| 553 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
| 554 | - give_set_error( 'must_log_in', __( 'You must login or register to complete your donation', 'give' ) ); |
|
| 553 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
| 554 | + give_set_error('must_log_in', __('You must login or register to complete your donation', 'give')); |
|
| 555 | 555 | |
| 556 | 556 | return $valid_user_data; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Get the user by login |
| 560 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
| 560 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
| 561 | 561 | |
| 562 | 562 | // Check if user exists |
| 563 | - if ( $user_data ) { |
|
| 563 | + if ($user_data) { |
|
| 564 | 564 | // Get password |
| 565 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
| 565 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
| 566 | 566 | |
| 567 | 567 | // Check user_pass |
| 568 | - if ( $user_pass ) { |
|
| 568 | + if ($user_pass) { |
|
| 569 | 569 | // Check if password is valid |
| 570 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
| 570 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
| 571 | 571 | // Incorrect password |
| 572 | 572 | give_set_error( |
| 573 | 573 | 'password_incorrect', |
| 574 | 574 | sprintf( |
| 575 | - __( 'The password you entered is incorrect. %sReset Password%s', 'give' ), |
|
| 576 | - '<a href="' . wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) . '" title="' . __( 'Lost Password', 'give' ) . '">', |
|
| 575 | + __('The password you entered is incorrect. %sReset Password%s', 'give'), |
|
| 576 | + '<a href="'.wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]").'" title="'.__('Lost Password', 'give').'">', |
|
| 577 | 577 | '</a>' |
| 578 | 578 | ) |
| 579 | 579 | ); |
@@ -591,11 +591,11 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | } else { |
| 593 | 593 | // Empty password |
| 594 | - give_set_error( 'password_empty', __( 'Enter a password', 'give' ) ); |
|
| 594 | + give_set_error('password_empty', __('Enter a password', 'give')); |
|
| 595 | 595 | } |
| 596 | 596 | } else { |
| 597 | 597 | // no username |
| 598 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist', 'give' ) ); |
|
| 598 | + give_set_error('username_incorrect', __('The username you entered does not exist', 'give')); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | return $valid_user_data; |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | */ |
| 611 | 611 | function give_purchase_form_validate_guest_user() { |
| 612 | 612 | |
| 613 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
| 613 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
| 614 | 614 | |
| 615 | 615 | // Start an array to collect valid user data |
| 616 | 616 | $valid_user_data = array( |
@@ -619,32 +619,32 @@ discard block |
||
| 619 | 619 | ); |
| 620 | 620 | |
| 621 | 621 | // Show error message if user must be logged in |
| 622 | - if ( give_logged_in_only() ) { |
|
| 623 | - give_set_error( 'logged_in_only', __( 'You must be logged into an account to donation', 'give' ) ); |
|
| 622 | + if (give_logged_in_only()) { |
|
| 623 | + give_set_error('logged_in_only', __('You must be logged into an account to donation', 'give')); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | // Get the guest email |
| 627 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
| 627 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
| 628 | 628 | |
| 629 | 629 | // Check email |
| 630 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
| 630 | + if ($guest_email && strlen($guest_email) > 0) { |
|
| 631 | 631 | // Validate email |
| 632 | - if ( ! is_email( $guest_email ) ) { |
|
| 632 | + if ( ! is_email($guest_email)) { |
|
| 633 | 633 | // Invalid email |
| 634 | - give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) ); |
|
| 634 | + give_set_error('email_invalid', __('Invalid email', 'give')); |
|
| 635 | 635 | } else { |
| 636 | 636 | // All is good to go |
| 637 | 637 | $valid_user_data['user_email'] = $guest_email; |
| 638 | 638 | } |
| 639 | 639 | } else { |
| 640 | 640 | // No email |
| 641 | - give_set_error( 'email_empty', __( 'Enter an email', 'give' ) ); |
|
| 641 | + give_set_error('email_empty', __('Enter an email', 'give')); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | // Loop through required fields and show error messages |
| 645 | - foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) { |
|
| 646 | - if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
| 647 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
| 645 | + foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) { |
|
| 646 | + if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
| 647 | + give_set_error($value['error_id'], $value['error_message']); |
|
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | |
@@ -660,42 +660,42 @@ discard block |
||
| 660 | 660 | * @since 1.0 |
| 661 | 661 | * @return integer |
| 662 | 662 | */ |
| 663 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
| 663 | +function give_register_and_login_new_user($user_data = array()) { |
|
| 664 | 664 | // Verify the array |
| 665 | - if ( empty( $user_data ) ) { |
|
| 666 | - return - 1; |
|
| 665 | + if (empty($user_data)) { |
|
| 666 | + return -1; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - if ( give_get_errors() ) { |
|
| 670 | - return - 1; |
|
| 669 | + if (give_get_errors()) { |
|
| 670 | + return -1; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
| 674 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
| 675 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
| 676 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
| 677 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
| 678 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
| 679 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
| 680 | - 'role' => get_option( 'default_role' ) |
|
| 681 | - ), $user_data ); |
|
| 673 | + $user_args = apply_filters('give_insert_user_args', array( |
|
| 674 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
| 675 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
| 676 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
| 677 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
| 678 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
| 679 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
| 680 | + 'role' => get_option('default_role') |
|
| 681 | + ), $user_data); |
|
| 682 | 682 | |
| 683 | 683 | // Insert new user |
| 684 | - $user_id = wp_insert_user( $user_args ); |
|
| 684 | + $user_id = wp_insert_user($user_args); |
|
| 685 | 685 | |
| 686 | 686 | // Validate inserted user |
| 687 | - if ( is_wp_error( $user_id ) ) { |
|
| 688 | - return - 1; |
|
| 687 | + if (is_wp_error($user_id)) { |
|
| 688 | + return -1; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | // Allow themes and plugins to filter the user data |
| 692 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
| 692 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
| 693 | 693 | |
| 694 | 694 | // Allow themes and plugins to hook |
| 695 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
| 695 | + do_action('give_insert_user', $user_id, $user_data); |
|
| 696 | 696 | |
| 697 | 697 | // Login new user |
| 698 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
| 698 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
| 699 | 699 | |
| 700 | 700 | // Return user id |
| 701 | 701 | return $user_id; |
@@ -710,27 +710,27 @@ discard block |
||
| 710 | 710 | * @since 1.0 |
| 711 | 711 | * @return array |
| 712 | 712 | */ |
| 713 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
| 713 | +function give_get_purchase_form_user($valid_data = array()) { |
|
| 714 | 714 | // Initialize user |
| 715 | 715 | $user = false; |
| 716 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 716 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 717 | 717 | |
| 718 | - if ( $is_ajax ) { |
|
| 718 | + if ($is_ajax) { |
|
| 719 | 719 | // Do not create or login the user during the ajax submission (check for errors only) |
| 720 | 720 | return true; |
| 721 | - } else if ( is_user_logged_in() ) { |
|
| 721 | + } else if (is_user_logged_in()) { |
|
| 722 | 722 | // Set the valid user as the logged in collected data |
| 723 | 723 | |
| 724 | 724 | $user = $valid_data['logged_in_user']; |
| 725 | - } else if ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
| 725 | + } else if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
| 726 | 726 | // New user registration |
| 727 | - if ( $valid_data['need_new_user'] === true ) { |
|
| 727 | + if ($valid_data['need_new_user'] === true) { |
|
| 728 | 728 | // Set user |
| 729 | 729 | $user = $valid_data['new_user_data']; |
| 730 | 730 | // Register and login new user |
| 731 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
| 731 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
| 732 | 732 | // User login |
| 733 | - } else if ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
| 733 | + } else if ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
| 734 | 734 | |
| 735 | 735 | /* |
| 736 | 736 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -745,48 +745,48 @@ discard block |
||
| 745 | 745 | // Set user |
| 746 | 746 | $user = $valid_data['login_user_data']; |
| 747 | 747 | // Login user |
| 748 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
| 748 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | // Check guest checkout |
| 753 | - if ( false === $user && false === give_no_guest_checkout( $_POST['give-form-id'] ) ) { |
|
| 753 | + if (false === $user && false === give_no_guest_checkout($_POST['give-form-id'])) { |
|
| 754 | 754 | // Set user |
| 755 | 755 | $user = $valid_data['guest_user_data']; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | // Verify we have an user |
| 759 | - if ( false === $user || empty( $user ) ) { |
|
| 759 | + if (false === $user || empty($user)) { |
|
| 760 | 760 | // Return false |
| 761 | 761 | return false; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | // Get user first name |
| 765 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
| 766 | - $user['user_first'] = isset( $_POST["give_first"] ) ? strip_tags( trim( $_POST["give_first"] ) ) : ''; |
|
| 765 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
| 766 | + $user['user_first'] = isset($_POST["give_first"]) ? strip_tags(trim($_POST["give_first"])) : ''; |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | // Get user last name |
| 770 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
| 771 | - $user['user_last'] = isset( $_POST["give_last"] ) ? strip_tags( trim( $_POST["give_last"] ) ) : ''; |
|
| 770 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
| 771 | + $user['user_last'] = isset($_POST["give_last"]) ? strip_tags(trim($_POST["give_last"])) : ''; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | // Get the user's billing address details |
| 775 | 775 | $user['address'] = array(); |
| 776 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
| 777 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
| 778 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
| 779 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
| 780 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
| 781 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
| 782 | - |
|
| 783 | - if ( empty( $user['address']['country'] ) ) { |
|
| 776 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
| 777 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
| 778 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
| 779 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
| 780 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
| 781 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
| 782 | + |
|
| 783 | + if (empty($user['address']['country'])) { |
|
| 784 | 784 | $user['address'] = false; |
| 785 | 785 | } // Country will always be set if address fields are present |
| 786 | 786 | |
| 787 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
| 787 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
| 788 | 788 | // Store the address in the user's meta so the cart can be pre-populated with it on return purchases |
| 789 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
| 789 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | // Return valid user |
@@ -805,16 +805,16 @@ discard block |
||
| 805 | 805 | $card_data = give_get_purchase_cc_info(); |
| 806 | 806 | |
| 807 | 807 | // Validate the card zip |
| 808 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
| 809 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
| 810 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid', 'give' ) ); |
|
| 808 | + if ( ! empty($card_data['card_zip'])) { |
|
| 809 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
| 810 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid', 'give')); |
|
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | //Ensure no spaces |
| 815 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
| 816 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); //no "+" signs |
|
| 817 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
| 815 | + if ( ! empty($card_data['card_number'])) { |
|
| 816 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); //no "+" signs |
|
| 817 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | // This should validate card numbers at some point too |
@@ -830,17 +830,17 @@ discard block |
||
| 830 | 830 | */ |
| 831 | 831 | function give_get_purchase_cc_info() { |
| 832 | 832 | $cc_info = array(); |
| 833 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 834 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 835 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 836 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 837 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 838 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
| 839 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
| 840 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
| 841 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
| 842 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
| 843 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
| 833 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 834 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 835 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 836 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 837 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 838 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
| 839 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
| 840 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
| 841 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
| 842 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
| 843 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
| 844 | 844 | |
| 845 | 845 | // Return cc info |
| 846 | 846 | return $cc_info; |
@@ -856,14 +856,14 @@ discard block |
||
| 856 | 856 | * |
| 857 | 857 | * @return bool|mixed|void |
| 858 | 858 | */ |
| 859 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 859 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 860 | 860 | $ret = false; |
| 861 | 861 | |
| 862 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
| 862 | + if (empty($zip) || empty($country_code)) { |
|
| 863 | 863 | return $ret; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - $country_code = strtoupper( $country_code ); |
|
| 866 | + $country_code = strtoupper($country_code); |
|
| 867 | 867 | |
| 868 | 868 | $zip_regex = array( |
| 869 | 869 | "AD" => "AD\d{3}", |
@@ -1023,11 +1023,11 @@ discard block |
||
| 1023 | 1023 | "ZM" => "\d{5}" |
| 1024 | 1024 | ); |
| 1025 | 1025 | |
| 1026 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
| 1026 | + if ( ! isset ($zip_regex[$country_code]) || preg_match("/".$zip_regex[$country_code]."/i", $zip)) { |
|
| 1027 | 1027 | $ret = true; |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1030 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | |
@@ -1037,48 +1037,48 @@ discard block |
||
| 1037 | 1037 | * @since 1.0 |
| 1038 | 1038 | * @return void |
| 1039 | 1039 | */ |
| 1040 | -function give_check_purchase_email( $valid_data, $posted ) { |
|
| 1040 | +function give_check_purchase_email($valid_data, $posted) { |
|
| 1041 | 1041 | $is_banned = false; |
| 1042 | 1042 | $banned = give_get_banned_emails(); |
| 1043 | 1043 | |
| 1044 | - if ( empty( $banned ) ) { |
|
| 1044 | + if (empty($banned)) { |
|
| 1045 | 1045 | return; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - if ( is_user_logged_in() ) { |
|
| 1048 | + if (is_user_logged_in()) { |
|
| 1049 | 1049 | |
| 1050 | 1050 | // The user is logged in, check that their account email is not banned |
| 1051 | - $user_data = get_userdata( get_current_user_id() ); |
|
| 1052 | - if ( give_is_email_banned( $user_data->user_email ) ) { |
|
| 1051 | + $user_data = get_userdata(get_current_user_id()); |
|
| 1052 | + if (give_is_email_banned($user_data->user_email)) { |
|
| 1053 | 1053 | |
| 1054 | 1054 | $is_banned = true; |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
| 1057 | + if (give_is_email_banned($posted['give_email'])) { |
|
| 1058 | 1058 | $is_banned = true; |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | - } elseif ( isset( $posted['give-purchase-var'] ) && $posted['give-purchase-var'] == 'needs-to-login' ) { |
|
| 1061 | + } elseif (isset($posted['give-purchase-var']) && $posted['give-purchase-var'] == 'needs-to-login') { |
|
| 1062 | 1062 | |
| 1063 | 1063 | // The user is logging in, check that their email is not banned |
| 1064 | - $user_data = get_user_by( 'login', $posted['give_user_login'] ); |
|
| 1065 | - if ( $user_data && give_is_email_banned( $user_data->user_email ) ) { |
|
| 1064 | + $user_data = get_user_by('login', $posted['give_user_login']); |
|
| 1065 | + if ($user_data && give_is_email_banned($user_data->user_email)) { |
|
| 1066 | 1066 | $is_banned = true; |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | } else { |
| 1070 | 1070 | |
| 1071 | 1071 | // Guest purchase, check that the email is not banned |
| 1072 | - if ( give_is_email_banned( $posted['give_email'] ) ) { |
|
| 1072 | + if (give_is_email_banned($posted['give_email'])) { |
|
| 1073 | 1073 | $is_banned = true; |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - if ( $is_banned ) { |
|
| 1078 | + if ($is_banned) { |
|
| 1079 | 1079 | // Set an error and give the donor a general error (don't alert them that they were banned) |
| 1080 | - give_set_error( 'email_banned', __( 'An internal error has occurred, please try again or contact support.', 'give' ) ); |
|
| 1080 | + give_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'give')); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | -add_action( 'give_checkout_error_checks', 'give_check_purchase_email', 10, 2 ); |
|
| 1084 | +add_action('give_checkout_error_checks', 'give_check_purchase_email', 10, 2); |
|
@@ -270,7 +270,7 @@ |
||
| 270 | 270 | * @access public |
| 271 | 271 | * @since 1.0 |
| 272 | 272 | * |
| 273 | - * @param $username string - the username to validate |
|
| 273 | + * @param string $username string - the username to validate |
|
| 274 | 274 | * |
| 275 | 275 | * @return bool |
| 276 | 276 | */ |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return bool|object List of all user purchases |
| 32 | 32 | */ |
| 33 | -function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
| 33 | +function give_get_users_purchases($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
| 34 | 34 | |
| 35 | - if ( empty( $user ) ) { |
|
| 35 | + if (empty($user)) { |
|
| 36 | 36 | $user = get_current_user_id(); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ( 0 === $user ) { |
|
| 39 | + if (0 === $user) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $status = $status === 'complete' ? 'publish' : $status; |
| 44 | 44 | |
| 45 | - if ( $pagination ) { |
|
| 46 | - if ( get_query_var( 'paged' ) ) { |
|
| 47 | - $paged = get_query_var( 'paged' ); |
|
| 48 | - } else if ( get_query_var( 'page' ) ) { |
|
| 49 | - $paged = get_query_var( 'page' ); |
|
| 45 | + if ($pagination) { |
|
| 46 | + if (get_query_var('paged')) { |
|
| 47 | + $paged = get_query_var('paged'); |
|
| 48 | + } else if (get_query_var('page')) { |
|
| 49 | + $paged = get_query_var('page'); |
|
| 50 | 50 | } else { |
| 51 | 51 | $paged = 1; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $args = apply_filters( 'give_get_users_purchases_args', array( |
|
| 55 | + $args = apply_filters('give_get_users_purchases_args', array( |
|
| 56 | 56 | 'user' => $user, |
| 57 | 57 | 'number' => $number, |
| 58 | 58 | 'status' => $status, |
| 59 | 59 | 'orderby' => 'date' |
| 60 | - ) ); |
|
| 60 | + )); |
|
| 61 | 61 | |
| 62 | - if ( $pagination ) { |
|
| 62 | + if ($pagination) { |
|
| 63 | 63 | |
| 64 | 64 | $args['page'] = $paged; |
| 65 | 65 | |
@@ -69,20 +69,20 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
| 73 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
| 72 | + $by_user_id = is_numeric($user) ? true : false; |
|
| 73 | + $customer = new Give_Customer($user, $by_user_id); |
|
| 74 | 74 | |
| 75 | - if ( ! empty( $customer->payment_ids ) ) { |
|
| 75 | + if ( ! empty($customer->payment_ids)) { |
|
| 76 | 76 | |
| 77 | - unset( $args['user'] ); |
|
| 78 | - $args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) ); |
|
| 77 | + unset($args['user']); |
|
| 78 | + $args['post__in'] = array_map('absint', explode(',', $customer->payment_ids)); |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $purchases = give_get_payments( apply_filters( 'give_get_users_purchases_args', $args ) ); |
|
| 82 | + $purchases = give_get_payments(apply_filters('give_get_users_purchases_args', $args)); |
|
| 83 | 83 | |
| 84 | 84 | // No purchases |
| 85 | - if ( ! $purchases ) { |
|
| 85 | + if ( ! $purchases) { |
|
| 86 | 86 | return false; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -101,64 +101,64 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @return bool|object List of unique forms purchased by user |
| 103 | 103 | */ |
| 104 | -function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
|
| 105 | - if ( empty( $user ) ) { |
|
| 104 | +function give_get_users_completed_donations($user = 0, $status = 'complete') { |
|
| 105 | + if (empty($user)) { |
|
| 106 | 106 | $user = get_current_user_id(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if ( empty( $user ) ) { |
|
| 109 | + if (empty($user)) { |
|
| 110 | 110 | return false; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
| 113 | + $by_user_id = is_numeric($user) ? true : false; |
|
| 114 | 114 | |
| 115 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
| 115 | + $customer = new Give_Customer($user, $by_user_id); |
|
| 116 | 116 | |
| 117 | - if ( empty( $customer->payment_ids ) ) { |
|
| 117 | + if (empty($customer->payment_ids)) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Get all the items purchased |
| 122 | - $payment_ids = array_reverse( explode( ',', $customer->payment_ids ) ); |
|
| 123 | - $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
|
| 124 | - if ( ! empty( $limit_payments ) ) { |
|
| 125 | - $payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
|
| 122 | + $payment_ids = array_reverse(explode(',', $customer->payment_ids)); |
|
| 123 | + $limit_payments = apply_filters('give_users_completed_donations_payments', 50); |
|
| 124 | + if ( ! empty($limit_payments)) { |
|
| 125 | + $payment_ids = array_slice($payment_ids, 0, $limit_payments); |
|
| 126 | 126 | } |
| 127 | 127 | $donation_data = array(); |
| 128 | - foreach ( $payment_ids as $payment_id ) { |
|
| 129 | - $donation_data[] = give_get_payment_meta( $payment_id ); |
|
| 128 | + foreach ($payment_ids as $payment_id) { |
|
| 129 | + $donation_data[] = give_get_payment_meta($payment_id); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( empty( $donation_data ) ) { |
|
| 132 | + if (empty($donation_data)) { |
|
| 133 | 133 | return false; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Grab only the post ids "form_id" of the forms purchased on this order |
| 137 | 137 | $completed_donations_ids = array(); |
| 138 | - foreach ( $donation_data as $purchase_meta ) { |
|
| 138 | + foreach ($donation_data as $purchase_meta) { |
|
| 139 | 139 | $completed_donations_ids[] = $purchase_meta['form_id']; |
| 140 | 140 | } |
| 141 | - if ( empty( $completed_donations_ids ) ) { |
|
| 141 | + if (empty($completed_donations_ids)) { |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Only include each product purchased once |
| 146 | - $form_ids = array_unique( $completed_donations_ids ); |
|
| 146 | + $form_ids = array_unique($completed_donations_ids); |
|
| 147 | 147 | |
| 148 | 148 | // Make sure we still have some products and a first item |
| 149 | - if ( empty ( $form_ids ) || ! isset( $form_ids[0] ) ) { |
|
| 149 | + if (empty ($form_ids) || ! isset($form_ids[0])) { |
|
| 150 | 150 | return false; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $post_type = get_post_type( $form_ids[0] ); |
|
| 153 | + $post_type = get_post_type($form_ids[0]); |
|
| 154 | 154 | |
| 155 | - $args = apply_filters( 'give_get_users_completed_donations_args', array( |
|
| 155 | + $args = apply_filters('give_get_users_completed_donations_args', array( |
|
| 156 | 156 | 'include' => $form_ids, |
| 157 | 157 | 'post_type' => $post_type, |
| 158 | - 'posts_per_page' => - 1 |
|
| 159 | - ) ); |
|
| 158 | + 'posts_per_page' => -1 |
|
| 159 | + )); |
|
| 160 | 160 | |
| 161 | - return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
|
| 161 | + return apply_filters('give_users_completed_donations_list', get_posts($args)); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return bool - true if has purchased, false other wise. |
| 176 | 176 | */ |
| 177 | -function give_has_purchases( $user_id = null ) { |
|
| 178 | - if ( empty( $user_id ) ) { |
|
| 177 | +function give_has_purchases($user_id = null) { |
|
| 178 | + if (empty($user_id)) { |
|
| 179 | 179 | $user_id = get_current_user_id(); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( give_get_users_purchases( $user_id, 1 ) ) { |
|
| 182 | + if (give_get_users_purchases($user_id, 1)) { |
|
| 183 | 183 | return true; // User has at least one purchase |
| 184 | 184 | } |
| 185 | 185 | |
@@ -199,32 +199,32 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return array |
| 201 | 201 | */ |
| 202 | -function give_get_purchase_stats_by_user( $user = '' ) { |
|
| 202 | +function give_get_purchase_stats_by_user($user = '') { |
|
| 203 | 203 | |
| 204 | - if ( is_email( $user ) ) { |
|
| 204 | + if (is_email($user)) { |
|
| 205 | 205 | |
| 206 | 206 | $field = 'email'; |
| 207 | 207 | |
| 208 | - } elseif ( is_numeric( $user ) ) { |
|
| 208 | + } elseif (is_numeric($user)) { |
|
| 209 | 209 | |
| 210 | 210 | $field = 'user_id'; |
| 211 | 211 | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $stats = array(); |
| 215 | - $customer = Give()->customers->get_customer_by( $field, $user ); |
|
| 215 | + $customer = Give()->customers->get_customer_by($field, $user); |
|
| 216 | 216 | |
| 217 | - if ( $customer ) { |
|
| 217 | + if ($customer) { |
|
| 218 | 218 | |
| 219 | - $customer = new Give_Customer( $customer->id ); |
|
| 219 | + $customer = new Give_Customer($customer->id); |
|
| 220 | 220 | |
| 221 | - $stats['purchases'] = absint( $customer->purchase_count ); |
|
| 222 | - $stats['total_spent'] = give_sanitize_amount( $customer->purchase_value ); |
|
| 221 | + $stats['purchases'] = absint($customer->purchase_count); |
|
| 222 | + $stats['total_spent'] = give_sanitize_amount($customer->purchase_value); |
|
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
| 227 | - return (array) apply_filters( 'give_purchase_stats_by_user', $stats, $user ); |
|
| 227 | + return (array) apply_filters('give_purchase_stats_by_user', $stats, $user); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return int - the total number of purchases |
| 242 | 242 | */ |
| 243 | -function give_count_purchases_of_customer( $user = null ) { |
|
| 244 | - if ( empty( $user ) ) { |
|
| 243 | +function give_count_purchases_of_customer($user = null) { |
|
| 244 | + if (empty($user)) { |
|
| 245 | 245 | $user = get_current_user_id(); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $stats = ! empty( $user ) ? give_get_purchase_stats_by_user( $user ) : false; |
|
| 248 | + $stats = ! empty($user) ? give_get_purchase_stats_by_user($user) : false; |
|
| 249 | 249 | |
| 250 | - return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
|
| 250 | + return isset($stats['purchases']) ? $stats['purchases'] : 0; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | * |
| 261 | 261 | * @return float - the total amount the user has spent |
| 262 | 262 | */ |
| 263 | -function give_purchase_total_of_user( $user = null ) { |
|
| 263 | +function give_purchase_total_of_user($user = null) { |
|
| 264 | 264 | |
| 265 | - $stats = give_get_purchase_stats_by_user( $user ); |
|
| 265 | + $stats = give_get_purchase_stats_by_user($user); |
|
| 266 | 266 | |
| 267 | 267 | return $stats['total_spent']; |
| 268 | 268 | } |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return bool |
| 280 | 280 | */ |
| 281 | -function give_validate_username( $username ) { |
|
| 282 | - $sanitized = sanitize_user( $username, false ); |
|
| 283 | - $valid = ( $sanitized == $username ); |
|
| 281 | +function give_validate_username($username) { |
|
| 282 | + $sanitized = sanitize_user($username, false); |
|
| 283 | + $valid = ($sanitized == $username); |
|
| 284 | 284 | |
| 285 | - return (bool) apply_filters( 'give_validate_username', $valid, $username ); |
|
| 285 | + return (bool) apply_filters('give_validate_username', $valid, $username); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | |
@@ -299,32 +299,32 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return void |
| 301 | 301 | */ |
| 302 | -function give_add_past_purchases_to_new_user( $user_id ) { |
|
| 302 | +function give_add_past_purchases_to_new_user($user_id) { |
|
| 303 | 303 | |
| 304 | - $email = get_the_author_meta( 'user_email', $user_id ); |
|
| 304 | + $email = get_the_author_meta('user_email', $user_id); |
|
| 305 | 305 | |
| 306 | - $payments = give_get_payments( array( 's' => $email ) ); |
|
| 306 | + $payments = give_get_payments(array('s' => $email)); |
|
| 307 | 307 | |
| 308 | - if ( $payments ) { |
|
| 309 | - foreach ( $payments as $payment ) { |
|
| 310 | - if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) { |
|
| 308 | + if ($payments) { |
|
| 309 | + foreach ($payments as $payment) { |
|
| 310 | + if (intval(give_get_payment_user_id($payment->ID)) > 0) { |
|
| 311 | 311 | continue; |
| 312 | 312 | } // This payment already associated with an account |
| 313 | 313 | |
| 314 | - $meta = give_get_payment_meta( $payment->ID ); |
|
| 315 | - $meta['user_info'] = maybe_unserialize( $meta['user_info'] ); |
|
| 314 | + $meta = give_get_payment_meta($payment->ID); |
|
| 315 | + $meta['user_info'] = maybe_unserialize($meta['user_info']); |
|
| 316 | 316 | $meta['user_info']['id'] = $user_id; |
| 317 | 317 | $meta['user_info'] = $meta['user_info']; |
| 318 | 318 | |
| 319 | 319 | // Store the updated user ID in the payment meta |
| 320 | - give_update_payment_meta( $payment->ID, '_give_payment_meta', $meta ); |
|
| 321 | - give_update_payment_meta( $payment->ID, '_give_payment_user_id', $user_id ); |
|
| 320 | + give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); |
|
| 321 | + give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | -add_action( 'user_register', 'give_add_past_purchases_to_new_user' ); |
|
| 327 | +add_action('user_register', 'give_add_past_purchases_to_new_user'); |
|
| 328 | 328 | |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -346,34 +346,34 @@ discard block |
||
| 346 | 346 | * @since 1.0 |
| 347 | 347 | * @return array - The donor's address, if any |
| 348 | 348 | */ |
| 349 | -function give_get_donor_address( $user_id = 0 ) { |
|
| 350 | - if ( empty( $user_id ) ) { |
|
| 349 | +function give_get_donor_address($user_id = 0) { |
|
| 350 | + if (empty($user_id)) { |
|
| 351 | 351 | $user_id = get_current_user_id(); |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $address = get_user_meta( $user_id, '_give_user_address', true ); |
|
| 354 | + $address = get_user_meta($user_id, '_give_user_address', true); |
|
| 355 | 355 | |
| 356 | - if ( ! isset( $address['line1'] ) ) { |
|
| 356 | + if ( ! isset($address['line1'])) { |
|
| 357 | 357 | $address['line1'] = ''; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( ! isset( $address['line2'] ) ) { |
|
| 360 | + if ( ! isset($address['line2'])) { |
|
| 361 | 361 | $address['line2'] = ''; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( ! isset( $address['city'] ) ) { |
|
| 364 | + if ( ! isset($address['city'])) { |
|
| 365 | 365 | $address['city'] = ''; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( ! isset( $address['zip'] ) ) { |
|
| 368 | + if ( ! isset($address['zip'])) { |
|
| 369 | 369 | $address['zip'] = ''; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if ( ! isset( $address['country'] ) ) { |
|
| 372 | + if ( ! isset($address['country'])) { |
|
| 373 | 373 | $address['country'] = ''; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if ( ! isset( $address['state'] ) ) { |
|
| 376 | + if ( ! isset($address['state'])) { |
|
| 377 | 377 | $address['state'] = ''; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -393,25 +393,25 @@ discard block |
||
| 393 | 393 | * |
| 394 | 394 | * @return void |
| 395 | 395 | */ |
| 396 | -function give_new_user_notification( $user_id = 0, $user_data = array() ) { |
|
| 396 | +function give_new_user_notification($user_id = 0, $user_data = array()) { |
|
| 397 | 397 | |
| 398 | - if ( empty( $user_id ) || empty( $user_data ) ) { |
|
| 398 | + if (empty($user_id) || empty($user_data)) { |
|
| 399 | 399 | return; |
| 400 | 400 | } |
| 401 | - $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
| 402 | - $message = sprintf( esc_attr__( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; |
|
| 403 | - $message .= sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n\r\n"; |
|
| 404 | - $message .= sprintf( esc_attr__( 'E-mail: %s' ), $user_data['user_email'] ) . "\r\n"; |
|
| 401 | + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
| 402 | + $message = sprintf(esc_attr__('New user registration on your site %s:'), $blogname)."\r\n\r\n"; |
|
| 403 | + $message .= sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n\r\n"; |
|
| 404 | + $message .= sprintf(esc_attr__('E-mail: %s'), $user_data['user_email'])."\r\n"; |
|
| 405 | 405 | |
| 406 | - @wp_mail( get_option( 'admin_email' ), sprintf( esc_attr__( '[%s] New User Registration' ), $blogname ), $message ); |
|
| 406 | + @wp_mail(get_option('admin_email'), sprintf(esc_attr__('[%s] New User Registration'), $blogname), $message); |
|
| 407 | 407 | |
| 408 | - $message = sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n"; |
|
| 409 | - $message .= sprintf( esc_attr__( 'Password: %s' ), esc_attr__( '[Password entered during donation]', 'give' ) ) . "\r\n"; |
|
| 408 | + $message = sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n"; |
|
| 409 | + $message .= sprintf(esc_attr__('Password: %s'), esc_attr__('[Password entered during donation]', 'give'))."\r\n"; |
|
| 410 | 410 | |
| 411 | - $message .= '<a href="' . wp_login_url() . '"> ' . esc_attr__( 'Click Here to Login', 'give' ) . ' »</a>' . "\r\n"; |
|
| 411 | + $message .= '<a href="'.wp_login_url().'"> '.esc_attr__('Click Here to Login', 'give').' »</a>'."\r\n"; |
|
| 412 | 412 | |
| 413 | - wp_mail( $user_data['user_email'], sprintf( esc_attr__( '[%s] Your username and password' ), $blogname ), $message ); |
|
| 413 | + wp_mail($user_data['user_email'], sprintf(esc_attr__('[%s] Your username and password'), $blogname), $message); |
|
| 414 | 414 | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | -add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); |
|
| 417 | +add_action('give_insert_user', 'give_new_user_notification', 10, 2); |
|
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | * @return void |
| 24 | 24 | */ |
| 25 | 25 | function give_get_actions() { |
| 26 | - if ( isset( $_GET['give_action'] ) ) { |
|
| 27 | - do_action( 'give_' . $_GET['give_action'], $_GET ); |
|
| 26 | + if (isset($_GET['give_action'])) { |
|
| 27 | + do_action('give_'.$_GET['give_action'], $_GET); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | -add_action( 'init', 'give_get_actions' ); |
|
| 31 | +add_action('init', 'give_get_actions'); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Hooks Give actions, when present in the $_POST superglobal. Every give_action |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | 41 | function give_post_actions() { |
| 42 | - if ( isset( $_POST['give_action'] ) ) { |
|
| 43 | - do_action( 'give_' . $_POST['give_action'], $_POST ); |
|
| 42 | + if (isset($_POST['give_action'])) { |
|
| 43 | + do_action('give_'.$_POST['give_action'], $_POST); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | -add_action( 'init', 'give_post_actions' ); |
|
| 48 | 47 | \ No newline at end of file |
| 48 | +add_action('init', 'give_post_actions'); |
|
| 49 | 49 | \ No newline at end of file |