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