| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Give Form Functions |
| 4 | 4 | * |
| 5 | - * @package GiveWP | |
| 5 | + * @package WordImpress | |
| 6 | 6 | * @subpackage Includes/Forms |
| 7 | - * @copyright Copyright (c) 2016, GiveWP | |
| 7 | + * @copyright Copyright (c) 2016, WordImpress | |
| 8 | 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | 9 | * @since 1.1 |
| 10 | 10 | */ |
| 11 | 11 | |
| @@ -13,10 +13,8 @@ | ||
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -use Give\Helpers\Form\Utils as FormUtils; | |
| 18 | - | |
| 19 | 17 | /** |
| 20 | 18 | * Filter: Do not show the Give shortcut button on Give Forms CPT |
| 21 | 19 | * |
| 22 | 20 | * @return bool |
| @@ -76,13 +74,8 @@ | ||
| 76 | 74 | if ( empty( $float_labels ) || ( 'global' === $float_labels ) ) { |
| 77 | 75 | $float_labels = give_get_option( 'floatlabels', 'disabled' ); |
| 78 | 76 | } |
| 79 | 77 | |
| 80 | - // If the form is using a non-legacy form template, do not use floating labels | |
| 81 | - if ( ! FormUtils::isLegacyForm( $args['form_id'] ) ) { | |
| 82 | - $float_labels = 'disabled'; | |
| 83 | - } | |
| 84 | - | |
| 85 | 78 | return give_is_setting_enabled( $float_labels ); |
| 86 | 79 | } |
| 87 | 80 | |
| 88 | 81 | /** |
| @@ -111,11 +104,9 @@ | ||
| 111 | 104 | */ |
| 112 | 105 | function give_get_success_page_uri() { |
| 113 | 106 | $give_options = give_get_settings(); |
| 114 | 107 | |
| 115 | - $success_page = isset( $give_options['success_page'] ) | |
| 116 | - ? get_permalink( absint( $give_options['success_page'] ) ) | |
| 117 | - : get_bloginfo( 'url' ); | |
| 108 | + $success_page = isset( $give_options['success_page'] ) ? get_permalink( absint( $give_options['success_page'] ) ) : get_bloginfo( 'url' ); | |
| 118 | 109 | |
| 119 | 110 | return apply_filters( 'give_get_success_page_uri', $success_page ); |
| 120 | 111 | } |
| 121 | 112 | |
| @@ -126,13 +117,12 @@ | ||
| 126 | 117 | * |
| 127 | 118 | * @return bool True if on the Success page, false otherwise. |
| 128 | 119 | */ |
| 129 | 120 | function give_is_success_page() { |
| 130 | - $give_options = give_get_settings(); | |
| 121 | + $give_options = give_get_settings(); | |
| 122 | + $is_success_page = isset( $give_options['success_page'] ) ? is_page( $give_options['success_page'] ) : false; | |
| 131 | 123 | |
| 132 | - $success_page = isset( $give_options['success_page'] ) ? is_page( $give_options['success_page'] ) : false; | |
| 133 | - | |
| 134 | - return apply_filters( 'give_is_success_page', $success_page ); | |
| 124 | + return apply_filters( 'give_is_success_page', $is_success_page ); | |
| 135 | 125 | } |
| 136 | 126 | |
| 137 | 127 | /** |
| 138 | 128 | * Send To Success Page |
| @@ -145,8 +135,9 @@ | ||
| 145 | 135 | * @since 1.0 |
| 146 | 136 | * @return void |
| 147 | 137 | */ |
| 148 | 138 | function give_send_to_success_page( $query_string = null ) { |
| 139 | + | |
| 149 | 140 | $redirect = give_get_success_page_uri(); |
| 150 | 141 | |
| 151 | 142 | if ( $query_string ) { |
| 152 | 143 | $redirect .= $query_string; |
| @@ -151,9 +142,9 @@ | ||
| 151 | 142 | if ( $query_string ) { |
| 152 | 143 | $redirect .= $query_string; |
| 153 | 144 | } |
| 154 | 145 | |
| 155 | - $gateway = isset( $_REQUEST['give-gateway'] ) ? give_clean( $_REQUEST['give-gateway'] ) : ''; | |
| 146 | + $gateway = isset( $_REQUEST['give-gateway'] ) ? $_REQUEST['give-gateway'] : ''; | |
| 156 | 147 | |
| 157 | 148 | wp_redirect( apply_filters( 'give_success_page_redirect', $redirect, $gateway, $query_string ) ); |
| 158 | 149 | give_die(); |
| 159 | 150 | } |
| @@ -163,31 +154,24 @@ | ||
| 163 | 154 | * Send back to donation form. |
| 164 | 155 | * |
| 165 | 156 | * Used to redirect a user back to the donation form if there are errors present. |
| 166 | 157 | * |
| 167 | - * @param array|string $args | |
| 158 | + * @param array $args | |
| 168 | 159 | * |
| 169 | 160 | * @access public |
| 170 | - * @since 2.21.0 Auto set "payment-mode" in redirect url. | |
| 171 | 161 | * @since 1.0 |
| 172 | 162 | * @return Void |
| 173 | 163 | */ |
| 174 | -function give_send_back_to_checkout( $args = [] ) { | |
| 164 | +function give_send_back_to_checkout( $args = array() ) { | |
| 175 | 165 | |
| 176 | 166 | $url = isset( $_POST['give-current-url'] ) ? sanitize_text_field( $_POST['give-current-url'] ) : ''; |
| 177 | 167 | $form_id = 0; |
| 178 | - $defaults = []; | |
| 179 | 168 | |
| 180 | 169 | // Set the form_id. |
| 181 | 170 | if ( isset( $_POST['give-form-id'] ) ) { |
| 182 | - $defaults['form-id'] = (int) sanitize_text_field( $_POST['give-form-id'] ); | |
| 171 | + $form_id = sanitize_text_field( $_POST['give-form-id'] ); | |
| 183 | 172 | } |
| 184 | 173 | |
| 185 | - // Set the payment mode. | |
| 186 | - if ( isset( $_POST['payment-mode'] ) ) { | |
| 187 | - $defaults['payment-mode'] = sanitize_text_field( $_POST['payment-mode'] ); | |
| 188 | - } | |
| 189 | - | |
| 190 | 174 | // Need a URL to continue. If none, redirect back to single form. |
| 191 | 175 | if ( empty( $url ) ) { |
| 192 | 176 | wp_safe_redirect( get_permalink( $form_id ) ); |
| 193 | 177 | give_die(); |
| @@ -192,16 +176,15 @@ | ||
| 192 | 176 | wp_safe_redirect( get_permalink( $form_id ) ); |
| 193 | 177 | give_die(); |
| 194 | 178 | } |
| 195 | 179 | |
| 180 | + $defaults = array( | |
| 181 | + 'form-id' => (int) $form_id, | |
| 182 | + ); | |
| 183 | + | |
| 196 | 184 | // Set the $level_id. |
| 197 | 185 | if ( isset( $_POST['give-price-id'] ) ) { |
| 198 | 186 | $defaults['level-id'] = sanitize_text_field( $_POST['give-price-id'] ); |
| 199 | - | |
| 200 | - // If custom, set amount | |
| 201 | - if( 'custom' === $defaults[ 'level-id' ] ) { | |
| 202 | - $defaults['custom-amount'] = sanitize_text_field( $_POST['give-amount'] ); | |
| 203 | - } | |
| 204 | 187 | } |
| 205 | 188 | |
| 206 | 189 | // Check for backward compatibility. |
| 207 | 190 | if ( is_string( $args ) ) { |
| @@ -210,22 +193,33 @@ | ||
| 210 | 193 | |
| 211 | 194 | $args = wp_parse_args( $args, $defaults ); |
| 212 | 195 | |
| 213 | 196 | // Merge URL query with $args to maintain third-party URL parameters after redirect. |
| 214 | - $redirect = add_query_arg( $args, $url ); | |
| 197 | + $url_data = wp_parse_url( $url ); | |
| 215 | 198 | |
| 216 | - // Precaution: don't allow any CC info. | |
| 217 | - $redirect = remove_query_arg( [ 'card_number', 'card_cvc' ], $redirect ); | |
| 199 | + // Check if an array to prevent notices before parsing. | |
| 200 | + if ( isset( $url_data['query'] ) && ! empty( $url_data['query'] ) ) { | |
| 201 | + parse_str( $url_data['query'], $query ); | |
| 218 | 202 | |
| 219 | - // Redirect them. | |
| 220 | - $redirect .= "#give-form-{$form_id}-wrap"; | |
| 203 | + // Precaution: don't allow any CC info. | |
| 204 | + unset( $query['card_number'] ); | |
| 205 | + unset( $query['card_cvc'] ); | |
| 221 | 206 | |
| 222 | - /** | |
| 223 | - * Filter the redirect url | |
| 224 | - */ | |
| 225 | - wp_safe_redirect( esc_url_raw( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) ) ); | |
| 207 | + } else { | |
| 208 | + // No $url_data so pass empty array. | |
| 209 | + $query = array(); | |
| 210 | + } | |
| 226 | 211 | |
| 212 | + $new_query = array_merge( $args, $query ); | |
| 213 | + $new_query_string = http_build_query( $new_query ); | |
| 214 | + | |
| 215 | + // Assemble URL parts. | |
| 216 | + $redirect = home_url( '/' . $url_data['path'] . '?' . $new_query_string . '#give-form-' . $form_id . '-wrap' ); | |
| 217 | + | |
| 218 | + // Redirect them. | |
| 219 | + wp_safe_redirect( apply_filters( 'give_send_back_to_checkout', $redirect, $args ) ); | |
| 227 | 220 | give_die(); |
| 221 | + | |
| 228 | 222 | } |
| 229 | 223 | |
| 230 | 224 | /** |
| 231 | 225 | * Get Success Page URL |
| @@ -238,10 +232,12 @@ | ||
| 238 | 232 | * @since 1.0 |
| 239 | 233 | * @return string |
| 240 | 234 | */ |
| 241 | 235 | function give_get_success_page_url( $query_string = null ) { |
| 242 | - $success_page = give_get_success_page_uri(); | |
| 243 | 236 | |
| 237 | + $success_page = give_get_option( 'success_page', 0 ); | |
| 238 | + $success_page = get_permalink( $success_page ); | |
| 239 | + | |
| 244 | 240 | if ( $query_string ) { |
| 245 | 241 | $success_page .= $query_string; |
| 246 | 242 | } |
| 247 | 243 | |
| @@ -277,8 +273,9 @@ | ||
| 277 | 273 | $uri = ! empty( $give_options['failure_page'] ) ? |
| 278 | 274 | trailingslashit( get_permalink( $give_options['failure_page'] ) ) : |
| 279 | 275 | home_url(); |
| 280 | 276 | |
| 277 | + | |
| 281 | 278 | if ( $extras ) { |
| 282 | 279 | $uri .= "?{$extras}"; |
| 283 | 280 | } |
| 284 | 281 | |
| @@ -306,21 +303,28 @@ | ||
| 306 | 303 | * |
| 307 | 304 | * @return bool |
| 308 | 305 | */ |
| 309 | 306 | function give_listen_for_failed_payments() { |
| 310 | - $payment_id = ! empty( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : 0; | |
| 311 | - $nonce = ! empty( $_GET['_wpnonce'] ) ? give_clean( $_GET['_wpnonce'] ) : false; | |
| 312 | 307 | |
| 308 | + $failed_page = give_get_option( 'failure_page', 0 ); | |
| 309 | + $payment_id = ! empty( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : 0; | |
| 310 | + $nonce = ! empty( $_GET['_wpnonce'] ) ? give_clean( $_GET['_wpnonce'] ) : false; | |
| 311 | + | |
| 313 | 312 | // Bailout. |
| 314 | - if ( ! $payment_id || ! wp_verify_nonce( $nonce, "give-failed-donation-{$payment_id}" ) ) { | |
| 313 | + if ( ! $failed_page || ! is_page( $failed_page ) || ! $payment_id || ! $nonce ) { | |
| 315 | 314 | return false; |
| 316 | 315 | } |
| 317 | 316 | |
| 317 | + // Security check. | |
| 318 | + if ( ! wp_verify_nonce( $nonce, "give-failed-donation-{$payment_id}" ) ) { | |
| 319 | + wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ) ); | |
| 320 | + } | |
| 321 | + | |
| 318 | 322 | // Set payment status to failure |
| 319 | 323 | give_update_payment_status( $payment_id, 'failed' ); |
| 320 | 324 | } |
| 321 | 325 | |
| 322 | -add_action( 'template_redirect', 'give_listen_for_failed_payments', 0 ); | |
| 326 | +add_action( 'template_redirect', 'give_listen_for_failed_payments' ); | |
| 323 | 327 | |
| 324 | 328 | /** |
| 325 | 329 | * Retrieve the Donation History page URI |
| 326 | 330 | * |
| @@ -337,23 +341,8 @@ | ||
| 337 | 341 | return apply_filters( 'give_get_history_page_uri', $history_page ); |
| 338 | 342 | } |
| 339 | 343 | |
| 340 | 344 | /** |
| 341 | - * Determines if we're currently on the History page. | |
| 342 | - * | |
| 343 | - * @since 1.0 | |
| 344 | - * | |
| 345 | - * @return bool True if on the History page, false otherwise. | |
| 346 | - */ | |
| 347 | -function give_is_history_page() { | |
| 348 | - $give_options = give_get_settings(); | |
| 349 | - | |
| 350 | - $history_page = isset( $give_options['history_page'] ) ? absint( $give_options['history_page'] ) : 0; | |
| 351 | - | |
| 352 | - return apply_filters( 'give_is_history_page', is_page( $history_page ) ); | |
| 353 | -} | |
| 354 | - | |
| 355 | -/** | |
| 356 | 345 | * Check if a field is required |
| 357 | 346 | * |
| 358 | 347 | * @param string $field |
| 359 | 348 | * @param int $form_id |
| @@ -361,9 +350,9 @@ | ||
| 361 | 350 | * @access public |
| 362 | 351 | * @since 1.0 |
| 363 | 352 | * @return bool |
| 364 | 353 | */ |
| 365 | -function give_field_is_required( $field, $form_id ) { | |
| 354 | +function give_field_is_required( $field = '', $form_id ) { | |
| 366 | 355 | |
| 367 | 356 | $required_fields = give_get_required_fields( $form_id ); |
| 368 | 357 | |
| 369 | 358 | return array_key_exists( $field, $required_fields ); |
| @@ -380,25 +369,22 @@ | ||
| 380 | 369 | * @param int $payment_id Payment ID. |
| 381 | 370 | * @param bool|int $price_id Price ID, if any. |
| 382 | 371 | * @param string|null $donation_date The date of the donation. |
| 383 | 372 | * |
| 384 | - * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings. | |
| 385 | - * | |
| 386 | 373 | * @return void |
| 387 | 374 | */ |
| 388 | -function give_record_donation_in_log( $give_form_id, $payment_id, $price_id = false, $donation_date = null ) { | |
| 389 | - $log_data = [ | |
| 390 | - 'log_content' => 'Payment log info', | |
| 375 | +function give_record_donation_in_log( $give_form_id = 0, $payment_id, $price_id = false, $donation_date = null ) { | |
| 376 | + $log_data = array( | |
| 391 | 377 | 'log_parent' => $payment_id, |
| 392 | 378 | 'log_type' => 'sale', |
| 393 | 379 | 'log_date' => isset( $donation_date ) ? $donation_date : null, |
| 394 | 380 | 'log_date_gmt' => isset( $donation_date ) ? $donation_date : null, |
| 395 | - ]; | |
| 381 | + ); | |
| 396 | 382 | |
| 397 | - $log_meta = [ | |
| 383 | + $log_meta = array( | |
| 398 | 384 | 'form_id' => $give_form_id, |
| 399 | 385 | 'price_id' => (int) $price_id, |
| 400 | - ]; | |
| 386 | + ); | |
| 401 | 387 | |
| 402 | 388 | Give()->logs->insert_log( $log_data, $log_meta ); |
| 403 | 389 | } |
| 404 | 390 | |
| @@ -414,41 +400,14 @@ | ||
| 414 | 400 | * @return bool|int |
| 415 | 401 | */ |
| 416 | 402 | function give_increase_donation_count( $form_id = 0, $quantity = 1 ) { |
| 417 | 403 | $quantity = (int) $quantity; |
| 404 | + $form = new Give_Donate_Form( $form_id ); | |
| 418 | 405 | |
| 419 | - /** @var \Give_Donate_Form $form */ | |
| 420 | - $form = new Give_Donate_Form( $form_id ); | |
| 421 | - | |
| 422 | 406 | return $form->increase_sales( $quantity ); |
| 423 | 407 | } |
| 424 | 408 | |
| 425 | 409 | /** |
| 426 | - * Update the goal progress count of a donation form. | |
| 427 | - * | |
| 428 | - * @since 2.4.0 | |
| 429 | - * | |
| 430 | - * @param int $form_id Give Form ID | |
| 431 | - * | |
| 432 | - * @return void | |
| 433 | - */ | |
| 434 | -function give_update_goal_progress( $form_id = 0 ) { | |
| 435 | - | |
| 436 | - // Get goal option meta key | |
| 437 | - $is_goal_enabled = give_is_setting_enabled( give_get_meta( $form_id, '_give_goal_option', true, 'disabled' ) ); | |
| 438 | - | |
| 439 | - // Check, if the form goal is enabled. | |
| 440 | - if ( $is_goal_enabled ) { | |
| 441 | - $goal_stats = give_goal_progress_stats( $form_id ); | |
| 442 | - $form_goal_progress_value = ! empty( $goal_stats['progress'] ) ? $goal_stats['progress'] : 0; | |
| 443 | - } else { | |
| 444 | - $form_goal_progress_value = -1; | |
| 445 | - } | |
| 446 | - | |
| 447 | - give_update_meta( $form_id, '_give_form_goal_progress', $form_goal_progress_value ); | |
| 448 | -} | |
| 449 | - | |
| 450 | -/** | |
| 451 | 410 | * Decreases the sale count of a form. Primarily for when a donation is refunded. |
| 452 | 411 | * |
| 453 | 412 | * @since 1.0 |
| 454 | 413 | * |
| @@ -458,12 +417,10 @@ | ||
| 458 | 417 | * @return bool|int |
| 459 | 418 | */ |
| 460 | 419 | function give_decrease_donation_count( $form_id = 0, $quantity = 1 ) { |
| 461 | 420 | $quantity = (int) $quantity; |
| 421 | + $form = new Give_Donate_Form( $form_id ); | |
| 462 | 422 | |
| 463 | - /** @var \Give_Donate_Form $form */ | |
| 464 | - $form = new Give_Donate_Form( $form_id ); | |
| 465 | - | |
| 466 | 423 | return $form->decrease_sales( $quantity ); |
| 467 | 424 | } |
| 468 | 425 | |
| 469 | 426 | /** |
| @@ -470,23 +427,17 @@ | ||
| 470 | 427 | * Increases the total earnings of a form. |
| 471 | 428 | * |
| 472 | 429 | * @since 1.0 |
| 473 | 430 | * |
| 474 | - * @since 2.1 Pass donation id. | |
| 475 | - * | |
| 476 | 431 | * @param int $give_form_id Give Form ID |
| 477 | 432 | * @param int $amount Earnings |
| 478 | - * @param int $payment_id Donation ID. | |
| 479 | 433 | * |
| 480 | - * @since 2.12.0 default value for the $give_form_id parameter is removed to prevent PHP8 warnings. | |
| 481 | - * | |
| 482 | 434 | * @return bool|int |
| 483 | 435 | */ |
| 484 | -function give_increase_earnings( $give_form_id, $amount, $payment_id = 0 ) { | |
| 485 | - /** @var \Give_Donate_Form $form */ | |
| 436 | +function give_increase_earnings( $give_form_id = 0, $amount ) { | |
| 486 | 437 | $form = new Give_Donate_Form( $give_form_id ); |
| 487 | 438 | |
| 488 | - return $form->increase_earnings( $amount, $payment_id ); | |
| 439 | + return $form->increase_earnings( $amount ); | |
| 489 | 440 | } |
| 490 | 441 | |
| 491 | 442 | /** |
| 492 | 443 | * Decreases the total earnings of a form. |
| @@ -494,23 +445,18 @@ | ||
| 494 | 445 | * Primarily for when a donation is refunded. |
| 495 | 446 | * |
| 496 | 447 | * @since 1.0 |
| 497 | 448 | * |
| 498 | - * @since 2.1 Pass donation id. | |
| 449 | + * @param int $form_id Give Form ID | |
| 450 | + * @param int $amount Earnings | |
| 499 | 451 | * |
| 500 | - * @param int $form_id Give Form ID | |
| 501 | - * @param int $amount Earnings | |
| 502 | - * @param int $payment_id Donation ID. | |
| 503 | - * | |
| 504 | - * @since 2.12.0 default value for the $form_id parameter is removed to prevent PHP8 warnings. | |
| 505 | - * | |
| 506 | 452 | * @return bool|int |
| 507 | 453 | */ |
| 508 | -function give_decrease_form_earnings( $form_id, $amount, $payment_id = 0 ) { | |
| 509 | - /** @var \Give_Donate_Form $form */ | |
| 454 | +function give_decrease_form_earnings( $form_id = 0, $amount ) { | |
| 455 | + | |
| 510 | 456 | $form = new Give_Donate_Form( $form_id ); |
| 511 | 457 | |
| 512 | - return $form->decrease_earnings( $amount, $payment_id ); | |
| 458 | + return $form->decrease_earnings( $amount ); | |
| 513 | 459 | } |
| 514 | 460 | |
| 515 | 461 | |
| 516 | 462 | /** |
| @@ -618,9 +564,9 @@ | ||
| 618 | 564 | |
| 619 | 565 | $prices = give_get_variable_prices( $form_id ); |
| 620 | 566 | $price_name = ''; |
| 621 | 567 | |
| 622 | - if ( ! $prices ) { | |
| 568 | + if ( false === $prices ) { | |
| 623 | 569 | return $price_name; |
| 624 | 570 | } |
| 625 | 571 | |
| 626 | 572 | foreach ( $prices as $price ) { |
| @@ -626,16 +572,16 @@ | ||
| 626 | 572 | foreach ( $prices as $price ) { |
| 627 | 573 | |
| 628 | 574 | if ( intval( $price['_give_id']['level_id'] ) === intval( $price_id ) ) { |
| 629 | 575 | |
| 630 | - $price_text = apply_filters( 'give_form_level_text', isset( $price['_give_text'] ) ? $price['_give_text'] : '', $form_id, $price ); | |
| 576 | + $price_text = isset( $price['_give_text'] ) ? $price['_give_text'] : ''; | |
| 631 | 577 | $price_fallback = $use_fallback ? |
| 632 | 578 | give_currency_filter( |
| 633 | 579 | give_format_amount( |
| 634 | 580 | $price['_give_amount'], |
| 635 | - [ 'sanitize' => false ] | |
| 581 | + array( 'sanitize' => false ) | |
| 636 | 582 | ), |
| 637 | - [ 'decode_currency' => true ] | |
| 583 | + array( 'decode_currency' => true ) | |
| 638 | 584 | ) : ''; |
| 639 | 585 | $price_name = ! empty( $price_text ) ? $price_text : $price_fallback; |
| 640 | 586 | |
| 641 | 587 | } |
| @@ -662,11 +608,12 @@ | ||
| 662 | 608 | |
| 663 | 609 | $range = sprintf( |
| 664 | 610 | '<span class="give_price_range_%1$s">%2$s</span><span class="give_price_range_sep"> – </span><span class="give_price_range_%3$s">%4$s</span>', |
| 665 | 611 | 'asc' === $order_type ? 'low' : 'high', |
| 666 | - 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ), | |
| 612 | + 'asc' === $order_type ? give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ), | |
| 667 | 613 | 'asc' === $order_type ? 'high' : 'low', |
| 668 | - 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, [ 'sanitize' => false ] ) ) : give_currency_filter( give_format_amount( $low, [ 'sanitize' => false ] ) ) | |
| 614 | + 'asc' === $order_type ? give_currency_filter( give_format_amount( $high, array( 'sanitize' => false ) ) ) : give_currency_filter( give_format_amount( $low, array( 'sanitize' => false ) ) ) | |
| 615 | + | |
| 669 | 616 | ); |
| 670 | 617 | |
| 671 | 618 | if ( ! $formatted ) { |
| 672 | 619 | $range = wp_strip_all_tags( $range ); |
| @@ -820,28 +767,8 @@ | ||
| 820 | 767 | |
| 821 | 768 | } |
| 822 | 769 | |
| 823 | 770 | /** |
| 824 | - * Return the maximum price amount of form. | |
| 825 | - * | |
| 826 | - * @since 2.1 | |
| 827 | - * | |
| 828 | - * @param int $form_id Donate Form ID | |
| 829 | - * | |
| 830 | - * @return bool|float | |
| 831 | - */ | |
| 832 | -function give_get_form_maximum_price( $form_id = 0 ) { | |
| 833 | - | |
| 834 | - if ( empty( $form_id ) ) { | |
| 835 | - return false; | |
| 836 | - } | |
| 837 | - | |
| 838 | - $form = new Give_Donate_Form( $form_id ); | |
| 839 | - | |
| 840 | - return $form->get_maximum_price(); | |
| 841 | -} | |
| 842 | - | |
| 843 | -/** | |
| 844 | 771 | * Displays a formatted price for a donation form |
| 845 | 772 | * |
| 846 | 773 | * @since 1.0 |
| 847 | 774 | * |
| @@ -913,22 +840,12 @@ | ||
| 913 | 840 | foreach ( $prices as $price ) { |
| 914 | 841 | if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] == $price_id ) { |
| 915 | 842 | $amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00; |
| 916 | 843 | break; |
| 917 | - } | |
| 844 | + }; | |
| 918 | 845 | } |
| 919 | 846 | |
| 920 | - /** | |
| 921 | - * Filter the price amount | |
| 922 | - * | |
| 923 | - * @since 1.0 | |
| 924 | - */ | |
| 925 | - return apply_filters( | |
| 926 | - 'give_get_price_option_amount', | |
| 927 | - give_maybe_sanitize_amount( $amount, [ 'currency' => give_get_currency( $form_id ) ] ), | |
| 928 | - $form_id, | |
| 929 | - $price_id | |
| 930 | - ); | |
| 847 | + return apply_filters( 'give_get_price_option_amount', give_maybe_sanitize_amount( $amount ), $form_id, $price_id ); | |
| 931 | 848 | } |
| 932 | 849 | |
| 933 | 850 | /** |
| 934 | 851 | * Returns the goal of a form |
| @@ -986,9 +903,9 @@ | ||
| 986 | 903 | $form_id = get_the_ID(); |
| 987 | 904 | } |
| 988 | 905 | |
| 989 | 906 | $goal = give_get_form_goal( $form_id ); |
| 990 | - $goal_format = give_get_form_goal_format( $form_id ); | |
| 907 | + $goal_format = give_get_form_goal_format($form_id); | |
| 991 | 908 | |
| 992 | 909 | if ( 'donation' === $goal_format ) { |
| 993 | 910 | $goal = "{$goal} donations"; |
| 994 | 911 | } else { |
| @@ -1063,17 +980,15 @@ | ||
| 1063 | 980 | * |
| 1064 | 981 | * @return array |
| 1065 | 982 | */ |
| 1066 | 983 | function _give_get_prefill_form_field_values( $form_id ) { |
| 1067 | - $logged_in_donor_info = []; | |
| 984 | + $logged_in_donor_info = array(); | |
| 1068 | 985 | |
| 1069 | 986 | if ( is_user_logged_in() ) : |
| 1070 | 987 | $donor_data = get_userdata( get_current_user_id() ); |
| 1071 | - $donor = new Give_Donor( get_current_user_id(), true ); | |
| 1072 | - $donor_address = $donor->get_donor_address(); | |
| 1073 | - $company_name = $donor->get_company_name(); | |
| 988 | + $donor_address = give_get_donor_address( get_current_user_id() ); | |
| 1074 | 989 | |
| 1075 | - $logged_in_donor_info = [ | |
| 990 | + $logged_in_donor_info = array( | |
| 1076 | 991 | // First name. |
| 1077 | 992 | 'give_first' => $donor_data->first_name, |
| 1078 | 993 | |
| 1079 | 994 | // Last name. |
| @@ -1078,14 +993,8 @@ | ||
| 1078 | 993 | |
| 1079 | 994 | // Last name. |
| 1080 | 995 | 'give_last' => $donor_data->last_name, |
| 1081 | 996 | |
| 1082 | - // Title Prefix. | |
| 1083 | - 'give_title' => $donor->get_meta( '_give_donor_title_prefix', true ), | |
| 1084 | - | |
| 1085 | - // Company name. | |
| 1086 | - 'company_name' => $company_name, | |
| 1087 | - | |
| 1088 | 997 | // Email. |
| 1089 | 998 | 'give_email' => $donor_data->user_email, |
| 1090 | 999 | |
| 1091 | 1000 | // Street address 1. |
| @@ -1104,9 +1013,9 @@ | ||
| 1104 | 1013 | 'card_city' => $donor_address['city'], |
| 1105 | 1014 | |
| 1106 | 1015 | // Zipcode |
| 1107 | 1016 | 'card_zip' => $donor_address['zip'], |
| 1108 | - ]; | |
| 1017 | + ); | |
| 1109 | 1018 | endif; |
| 1110 | 1019 | |
| 1111 | 1020 | // Bailout: Auto fill form field values only form form which donor is donating. |
| 1112 | 1021 | if ( |
| @@ -1121,484 +1030,10 @@ | ||
| 1121 | 1030 | $give_purchase_data = Give()->session->get( 'give_purchase' ); |
| 1122 | 1031 | |
| 1123 | 1032 | // Get donor info from form data. |
| 1124 | 1033 | $give_donor_info_in_session = empty( $give_purchase_data['post_data'] ) |
| 1125 | - ? [] | |
| 1034 | + ? array() | |
| 1126 | 1035 | : $give_purchase_data['post_data']; |
| 1127 | 1036 | |
| 1128 | 1037 | // Output. |
| 1129 | 1038 | return wp_parse_args( $give_donor_info_in_session, $logged_in_donor_info ); |
| 1130 | -} | |
| 1131 | - | |
| 1132 | -/** | |
| 1133 | - * Get donor count of form | |
| 1134 | - * | |
| 1135 | - * @since 2.1.0 | |
| 1136 | - * | |
| 1137 | - * @param int $form_id | |
| 1138 | - * @param array $args | |
| 1139 | - * | |
| 1140 | - * @return int | |
| 1141 | - */ | |
| 1142 | -function give_get_form_donor_count( $form_id, $args = [] ) { | |
| 1143 | - global $wpdb; | |
| 1144 | - | |
| 1145 | - $cache_key = Give_Cache::get_key( "form_donor_count_{$form_id}", $args, false ); | |
| 1146 | - $donor_count = absint( Give_Cache::get_db_query( $cache_key ) ); | |
| 1147 | - | |
| 1148 | - if ( $form_id && ! $donor_count ) { | |
| 1149 | - // Set arguments. | |
| 1150 | - $args = wp_parse_args( | |
| 1151 | - $args, | |
| 1152 | - [ | |
| 1153 | - 'unique' => true, | |
| 1154 | - ] | |
| 1155 | - ); | |
| 1156 | - | |
| 1157 | - $donation_meta_table = Give()->payment_meta->table_name; | |
| 1158 | - $donation_id_col_name = Give()->payment_meta->get_meta_type() . '_id'; | |
| 1159 | - | |
| 1160 | - $distinct = $args['unique'] ? 'DISTINCT meta_value' : 'meta_value'; | |
| 1161 | - | |
| 1162 | - $query = $wpdb->prepare( | |
| 1163 | - " | |
| 1164 | - SELECT COUNT({$distinct}) | |
| 1165 | - FROM {$donation_meta_table} | |
| 1166 | - WHERE meta_key=%s | |
| 1167 | - AND {$donation_id_col_name} IN( | |
| 1168 | - SELECT {$donation_id_col_name} | |
| 1169 | - FROM {$donation_meta_table} as pm | |
| 1170 | - INNER JOIN {$wpdb->posts} as p | |
| 1171 | - ON pm.{$donation_id_col_name}=p.ID | |
| 1172 | - WHERE pm.meta_key=%s | |
| 1173 | - AND pm.meta_value=%s | |
| 1174 | - AND p.post_status=%s | |
| 1175 | - ) | |
| 1176 | - ", | |
| 1177 | - '_give_payment_donor_id', | |
| 1178 | - '_give_payment_form_id', | |
| 1179 | - $form_id, | |
| 1180 | - 'publish' | |
| 1181 | - ); | |
| 1182 | - | |
| 1183 | - $donor_count = absint( $wpdb->get_var( $query ) ); | |
| 1184 | - } | |
| 1185 | - | |
| 1186 | - /** | |
| 1187 | - * Filter the donor count | |
| 1188 | - * | |
| 1189 | - * @since 2.1.0 | |
| 1190 | - */ | |
| 1191 | - $donor_count = apply_filters( 'give_get_form_donor_count', $donor_count, $form_id, $args ); | |
| 1192 | - | |
| 1193 | - return $donor_count; | |
| 1194 | -} | |
| 1195 | - | |
| 1196 | -/** | |
| 1197 | - * Verify the form status. | |
| 1198 | - * | |
| 1199 | - * @param int $form_id Donation Form ID. | |
| 1200 | - * | |
| 1201 | - * @since 2.1 | |
| 1202 | - * | |
| 1203 | - * @return void | |
| 1204 | - */ | |
| 1205 | -function give_set_form_closed_status( $form_id ) { | |
| 1206 | - | |
| 1207 | - // Bailout. | |
| 1208 | - if ( empty( $form_id ) ) { | |
| 1209 | - return; | |
| 1210 | - } | |
| 1211 | - | |
| 1212 | - $open_form = false; | |
| 1213 | - $is_goal_enabled = give_is_setting_enabled( give_get_meta( $form_id, '_give_goal_option', true, 'disabled' ) ); | |
| 1214 | - | |
| 1215 | - // Proceed, if the form goal is enabled. | |
| 1216 | - if ( $is_goal_enabled ) { | |
| 1217 | - | |
| 1218 | - $close_form_when_goal_achieved = give_is_setting_enabled( give_get_meta( $form_id, '_give_close_form_when_goal_achieved', true, 'disabled' ) ); | |
| 1219 | - | |
| 1220 | - // Proceed, if close form when goal achieved option is enabled. | |
| 1221 | - if ( $close_form_when_goal_achieved ) { | |
| 1222 | - | |
| 1223 | - $form = new Give_Donate_Form( $form_id ); | |
| 1224 | - $goal_progress_stats = give_goal_progress_stats( $form ); | |
| 1225 | - | |
| 1226 | - // Verify whether the form is closed or not after processing data. | |
| 1227 | - $closed = $goal_progress_stats['raw_goal'] <= $goal_progress_stats['raw_actual']; | |
| 1228 | - | |
| 1229 | - // Update form meta if verified that the form is closed. | |
| 1230 | - if ( $closed ) { | |
| 1231 | - give_update_meta( $form_id, '_give_form_status', 'closed' ); | |
| 1232 | - } else { | |
| 1233 | - $open_form = true; | |
| 1234 | - } | |
| 1235 | - } else { | |
| 1236 | - $open_form = true; | |
| 1237 | - } | |
| 1238 | - } else { | |
| 1239 | - $open_form = true; | |
| 1240 | - } | |
| 1241 | - | |
| 1242 | - // If $open_form is true, then update form status to open. | |
| 1243 | - if ( $open_form ) { | |
| 1244 | - give_update_meta( $form_id, '_give_form_status', 'open' ); | |
| 1245 | - } | |
| 1246 | -} | |
| 1247 | - | |
| 1248 | -/** | |
| 1249 | - * Show Form Goal Stats in Admin ( Listing and Detail page ) | |
| 1250 | - * | |
| 1251 | - * @since 2.19.0 Prevent divide by zero issue in goal percentage calculation logic. | |
| 1252 | - * | |
| 1253 | - * @param int $form_id Form ID. | |
| 1254 | - * | |
| 1255 | - * @since 2.1.0 | |
| 1256 | - * | |
| 1257 | - * @return string | |
| 1258 | - */ | |
| 1259 | -function give_admin_form_goal_stats( $form_id ) { | |
| 1260 | - | |
| 1261 | - $html = ''; | |
| 1262 | - $goal_stats = give_goal_progress_stats( $form_id ); | |
| 1263 | - $percent_complete = $goal_stats['raw_goal'] ? round( ( $goal_stats['raw_actual'] / $goal_stats['raw_goal'] ), 3 ) * 100 : 0; | |
| 1264 | - | |
| 1265 | - $html .= sprintf( | |
| 1266 | - '<div class="give-admin-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="%1$s"> | |
| 1267 | -<span style="width:%1$s%%;"></span> | |
| 1268 | -</div>', | |
| 1269 | - esc_attr( $goal_stats['progress'] ) | |
| 1270 | - ); | |
| 1271 | - | |
| 1272 | - $html .= sprintf( | |
| 1273 | - ( 'percentage' !== $goal_stats['format'] ) ? | |
| 1274 | - '<div class="give-goal-text"><span>%1$s</span> %2$s <a href="%3$s">%4$s</a> %5$s ' : | |
| 1275 | - '<div class="give-goal-text"><a href="%3$s">%1$s </a>', | |
| 1276 | - ( 'percentage' !== $goal_stats['format'] ) ? $goal_stats['actual'] : $percent_complete . '%', | |
| 1277 | - ( 'percentage' !== $goal_stats['format'] ) ? __( 'of', 'give' ) : '', | |
| 1278 | - esc_url( admin_url( "post.php?post={$form_id}&action=edit&give_tab=donation_goal_options" ) ), | |
| 1279 | - $goal_stats['goal'], | |
| 1280 | - ( 'donors' === $goal_stats['format'] ? __( 'donors', 'give' ) : ( 'donation' === $goal_stats['format'] ? __( 'donations', 'give' ) : '' ) ) | |
| 1281 | - ); | |
| 1282 | - | |
| 1283 | - if ( $goal_stats['raw_actual'] >= $goal_stats['raw_goal'] ) { | |
| 1284 | - $html .= sprintf( '<span class="give-admin-goal-achieved"><span class="dashicons dashicons-star-filled"></span> %s</span>', __( 'Goal achieved', 'give' ) ); | |
| 1285 | - } | |
| 1286 | - | |
| 1287 | - $html .= '</div>'; | |
| 1288 | - | |
| 1289 | - return $html; | |
| 1290 | -} | |
| 1291 | - | |
| 1292 | -/** | |
| 1293 | - * Get the default donation form's level id. | |
| 1294 | - * | |
| 1295 | - * @since 2.2.0 | |
| 1296 | - * | |
| 1297 | - * @param integer $form_id Donation Form ID. | |
| 1298 | - * | |
| 1299 | - * @return null | array | |
| 1300 | - */ | |
| 1301 | -function give_form_get_default_level( $form_id ) { | |
| 1302 | - $default_level = null; | |
| 1303 | - | |
| 1304 | - // If donation form has variable prices. | |
| 1305 | - if ( give_has_variable_prices( $form_id ) ) { | |
| 1306 | - /** | |
| 1307 | - * Filter the variable pricing | |
| 1308 | - * | |
| 1309 | - * @since 1.0 | |
| 1310 | - * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices. | |
| 1311 | - * Check Give_Donate_Form::get_prices(). | |
| 1312 | - * | |
| 1313 | - * @param array $prices Array of variable prices. | |
| 1314 | - * @param int $form Form ID. | |
| 1315 | - */ | |
| 1316 | - $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); | |
| 1317 | - | |
| 1318 | - // Go through each of the level and get the default level id. | |
| 1319 | - foreach ( $prices as $level ) { | |
| 1320 | - if ( | |
| 1321 | - isset( $level['_give_default'] ) | |
| 1322 | - && $level['_give_default'] === 'default' | |
| 1323 | - ) { | |
| 1324 | - $default_level = $level; | |
| 1325 | - } | |
| 1326 | - } | |
| 1327 | - } | |
| 1328 | - | |
| 1329 | - /** | |
| 1330 | - * Filter the default donation level id. | |
| 1331 | - * | |
| 1332 | - * @since 2.2.0 | |
| 1333 | - * | |
| 1334 | - * @param array $default_level Default level price data. | |
| 1335 | - * @param integer $form_id Donation form ID. | |
| 1336 | - */ | |
| 1337 | - return apply_filters( 'give_form_get_default_level', $default_level, $form_id ); | |
| 1338 | -} | |
| 1339 | - | |
| 1340 | -/** | |
| 1341 | - * Get the default level id. | |
| 1342 | - * | |
| 1343 | - * @since 2.2.0 | |
| 1344 | - * | |
| 1345 | - * @param array|integer $price_or_level_id Price level data. | |
| 1346 | - * @param boolean|integer $form_id Donation Form ID. | |
| 1347 | - * | |
| 1348 | - * @return boolean | |
| 1349 | - */ | |
| 1350 | -function give_is_default_level_id( $price_or_level_id, $form_id = 0 ) { | |
| 1351 | - $is_default = false; | |
| 1352 | - | |
| 1353 | - if ( | |
| 1354 | - ! empty( $form_id ) | |
| 1355 | - && is_numeric( $price_or_level_id ) | |
| 1356 | - ) { | |
| 1357 | - // Get default level id. | |
| 1358 | - $form_price_data = give_form_get_default_level( $form_id ); | |
| 1359 | - | |
| 1360 | - $is_default = ! is_null( $form_price_data ) && ( $price_or_level_id === absint( $form_price_data['_give_id']['level_id'] ) ); | |
| 1361 | - } | |
| 1362 | - | |
| 1363 | - $is_default = false === $is_default && is_array( $price_or_level_id ) ? | |
| 1364 | - ( isset( $price_or_level_id['_give_default'] ) && $price_or_level_id['_give_default'] === 'default' ) | |
| 1365 | - : $is_default; | |
| 1366 | - | |
| 1367 | - /** | |
| 1368 | - * Allow developers to modify the default level id checks. | |
| 1369 | - * | |
| 1370 | - * @since 2.2.0 | |
| 1371 | - * | |
| 1372 | - * @param bool $is_default True if it is default price level id otherwise false. | |
| 1373 | - * @param array|integer $price_or_level_id Price Data. | |
| 1374 | - */ | |
| 1375 | - return apply_filters( 'give_is_default_level_id', $is_default, $price_or_level_id ); | |
| 1376 | -} | |
| 1377 | - | |
| 1378 | - | |
| 1379 | -/** | |
| 1380 | - * Get Name Title Prefixes (a.k.a. Salutation) value. | |
| 1381 | - * | |
| 1382 | - * @param int $form_id Donation Form ID. | |
| 1383 | - * | |
| 1384 | - * @since 2.2.0 | |
| 1385 | - * | |
| 1386 | - * @return array | |
| 1387 | - */ | |
| 1388 | -function give_get_name_title_prefixes( $form_id = 0 ) { | |
| 1389 | - | |
| 1390 | - $name_title_prefix = give_is_name_title_prefix_enabled( $form_id ); | |
| 1391 | - $title_prefixes = give_get_option( 'title_prefixes', give_get_default_title_prefixes() ); | |
| 1392 | - | |
| 1393 | - // If form id exists, then fetch form specific title prefixes. | |
| 1394 | - if ( intval( $form_id ) > 0 && $name_title_prefix ) { | |
| 1395 | - | |
| 1396 | - $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true ); | |
| 1397 | - if ( 'global' !== $form_title_prefix ) { | |
| 1398 | - $form_title_prefixes = give_get_meta( $form_id, '_give_title_prefixes', true, give_get_default_title_prefixes() ); | |
| 1399 | - | |
| 1400 | - // Check whether the form based title prefixes exists or not. | |
| 1401 | - if ( is_array( $form_title_prefixes ) && count( $form_title_prefixes ) > 0 ) { | |
| 1402 | - $title_prefixes = $form_title_prefixes; | |
| 1403 | - } | |
| 1404 | - } | |
| 1405 | - } | |
| 1406 | - | |
| 1407 | - return array_filter( (array) $title_prefixes ); | |
| 1408 | -} | |
| 1409 | - | |
| 1410 | -/** | |
| 1411 | - * Check whether the name title prefix is enabled or not. | |
| 1412 | - * | |
| 1413 | - * @param int $form_id Donation Form ID. | |
| 1414 | - * @param string $status Status to set status based on option value. | |
| 1415 | - * | |
| 1416 | - * @since 2.2.0 | |
| 1417 | - * | |
| 1418 | - * @return bool | |
| 1419 | - */ | |
| 1420 | -function give_is_name_title_prefix_enabled( $form_id = 0, $status = '' ) { | |
| 1421 | - if ( empty( $status ) ) { | |
| 1422 | - $status = [ 'required', 'optional' ]; | |
| 1423 | - } else { | |
| 1424 | - $status = [ $status ]; | |
| 1425 | - } | |
| 1426 | - | |
| 1427 | - $title_prefix_status = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status ); | |
| 1428 | - | |
| 1429 | - if ( intval( $form_id ) > 0 ) { | |
| 1430 | - $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true ); | |
| 1431 | - | |
| 1432 | - if ( 'disabled' === $form_title_prefix ) { | |
| 1433 | - $title_prefix_status = false; | |
| 1434 | - } elseif ( in_array( $form_title_prefix, $status, true ) ) { | |
| 1435 | - $title_prefix_status = give_is_setting_enabled( $form_title_prefix, $status ); | |
| 1436 | - } | |
| 1437 | - } | |
| 1438 | - | |
| 1439 | - return $title_prefix_status; | |
| 1440 | - | |
| 1441 | -} | |
| 1442 | - | |
| 1443 | -/** | |
| 1444 | - * Get Donor Name with Title Prefix | |
| 1445 | - * | |
| 1446 | - * @param int|Give_Donor $donor Donor Information. | |
| 1447 | - * | |
| 1448 | - * @since 2.2.0 | |
| 1449 | - * | |
| 1450 | - * @return object | |
| 1451 | - */ | |
| 1452 | -function give_get_name_with_title_prefixes( $donor ) { | |
| 1453 | - | |
| 1454 | - // Prepare Give_Donor object, if $donor is numeric. | |
| 1455 | - if ( is_numeric( $donor ) ) { | |
| 1456 | - $donor = new Give_Donor( $donor ); | |
| 1457 | - } | |
| 1458 | - | |
| 1459 | - $title_prefix = Give()->donor_meta->get_meta( $donor->id, '_give_donor_title_prefix', true ); | |
| 1460 | - | |
| 1461 | - // Update Donor name, if non empty title prefix. | |
| 1462 | - if ( ! empty( $title_prefix ) ) { | |
| 1463 | - $donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name ); | |
| 1464 | - } | |
| 1465 | - | |
| 1466 | - return $donor; | |
| 1467 | -} | |
| 1468 | - | |
| 1469 | -/** | |
| 1470 | - * This function will generate donor name with title prefix if it is required. | |
| 1471 | - * | |
| 1472 | - * @param string $title_prefix Title Prefix of Donor | |
| 1473 | - * @param string $name Donor Name. | |
| 1474 | - * | |
| 1475 | - * @since 2.2.0 | |
| 1476 | - * | |
| 1477 | - * @return string | |
| 1478 | - */ | |
| 1479 | -function give_get_donor_name_with_title_prefixes( $title_prefix, $name ) { | |
| 1480 | - | |
| 1481 | - $donor_name = $name; | |
| 1482 | - | |
| 1483 | - if ( ! empty( $title_prefix ) && ! empty( $name ) ) { | |
| 1484 | - $donor_name = "{$title_prefix} {$name}"; | |
| 1485 | - } | |
| 1486 | - | |
| 1487 | - return trim( $donor_name ); | |
| 1488 | -} | |
| 1489 | - | |
| 1490 | -/** | |
| 1491 | - * This function will fetch the default list of title prefixes. | |
| 1492 | - * | |
| 1493 | - * @since 2.2.0 | |
| 1494 | - * | |
| 1495 | - * @return array | |
| 1496 | - */ | |
| 1497 | -function give_get_default_title_prefixes() { | |
| 1498 | - /** | |
| 1499 | - * Filter the data | |
| 1500 | - * Set default title prefixes. | |
| 1501 | - * | |
| 1502 | - * @since 2.2.0 | |
| 1503 | - */ | |
| 1504 | - return apply_filters( | |
| 1505 | - 'give_get_default_title_prefixes', | |
| 1506 | - [ | |
| 1507 | - 'Mr.' => __( 'Mr.', 'give' ), | |
| 1508 | - 'Mrs.' => __( 'Mrs.', 'give' ), | |
| 1509 | - 'Ms.' => __( 'Ms.', 'give' ), | |
| 1510 | - ] | |
| 1511 | - ); | |
| 1512 | -} | |
| 1513 | - | |
| 1514 | -/** | |
| 1515 | - * This function will check whether the name title prefix field is required or not. | |
| 1516 | - * | |
| 1517 | - * @param int $form_id Donation Form ID. | |
| 1518 | - * | |
| 1519 | - * @since 2.2.0 | |
| 1520 | - * | |
| 1521 | - * @return bool | |
| 1522 | - */ | |
| 1523 | -function give_is_name_title_prefix_required( $form_id = 0 ) { | |
| 1524 | - | |
| 1525 | - // Bail out, if name title prefix is not enabled. | |
| 1526 | - if ( ! give_is_name_title_prefix_enabled( $form_id ) ) { | |
| 1527 | - return false; | |
| 1528 | - } | |
| 1529 | - | |
| 1530 | - $status = [ 'optional' ]; | |
| 1531 | - $is_optional = give_is_setting_enabled( give_get_option( 'name_title_prefix' ), $status ); | |
| 1532 | - | |
| 1533 | - if ( intval( $form_id ) > 0 ) { | |
| 1534 | - $form_title_prefix = give_get_meta( $form_id, '_give_name_title_prefix', true ); | |
| 1535 | - | |
| 1536 | - if ( 'required' === $form_title_prefix ) { | |
| 1537 | - $is_optional = false; | |
| 1538 | - } elseif ( 'optional' === $form_title_prefix ) { | |
| 1539 | - $is_optional = true; | |
| 1540 | - } | |
| 1541 | - } | |
| 1542 | - | |
| 1543 | - return ( ! $is_optional ); | |
| 1544 | -} | |
| 1545 | - | |
| 1546 | -/** | |
| 1547 | - * Deletes form meta when the form is permanently deleted from the trash. | |
| 1548 | - * | |
| 1549 | - * @since 2.3.0 | |
| 1550 | - * | |
| 1551 | - * @param integer $id Donation Form ID which needs to be deleted. | |
| 1552 | - * | |
| 1553 | - * @return void | |
| 1554 | - */ | |
| 1555 | -function give_handle_form_meta_on_delete( $id ) { | |
| 1556 | - | |
| 1557 | - global $wpdb; | |
| 1558 | - | |
| 1559 | - $form = get_post( $id ); | |
| 1560 | - $get_data = give_clean( $_GET ); | |
| 1561 | - | |
| 1562 | - if ( | |
| 1563 | - 'give_forms' === $form->post_type && | |
| 1564 | - 'trash' === $form->post_status && | |
| 1565 | - ( | |
| 1566 | - ( isset( $get_data['action'] ) && 'delete' === $get_data['action'] ) || | |
| 1567 | - ! empty( $get_data['delete_all'] ) | |
| 1568 | - ) | |
| 1569 | - ) { | |
| 1570 | - $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->formmeta} WHERE form_id = '%d'", $form->ID ) ); | |
| 1571 | - } | |
| 1572 | -} | |
| 1573 | - | |
| 1574 | -add_action( 'before_delete_post', 'give_handle_form_meta_on_delete', 10, 1 ); | |
| 1575 | - | |
| 1576 | - | |
| 1577 | -/** | |
| 1578 | - * Get the list of default parameters for the form shortcode. | |
| 1579 | - * | |
| 1580 | - * @return array | |
| 1581 | - * @since 2.4.1 | |
| 1582 | - */ | |
| 1583 | -function give_get_default_form_shortcode_args() { | |
| 1584 | - $default = [ | |
| 1585 | - 'id' => '', | |
| 1586 | - 'show_title' => true, | |
| 1587 | - 'show_goal' => true, | |
| 1588 | - 'show_content' => '', | |
| 1589 | - 'float_labels' => '', | |
| 1590 | - 'display_style' => '', | |
| 1591 | - 'continue_button_title' => '', | |
| 1592 | - | |
| 1593 | - // This attribute belong to form template functionality. | |
| 1594 | - // You can use this attribute to set modal open button background color. | |
| 1595 | - 'button_color' => '#28C77B', | |
| 1596 | - ]; | |
| 1597 | - | |
| 1598 | - /** | |
| 1599 | - * Fire the filter | |
| 1600 | - */ | |
| 1601 | - $default = apply_filters( 'give_get_default_form_shortcode_args', $default ); | |
| 1602 | - | |
| 1603 | - return $default; | |
| 1604 | 1039 | } |