class-give-forms-query.php
6 years ago
functions.php
2 years ago
template.php
2 years ago
widget.php
6 years ago
template.php
2534 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Give Form Template |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Forms |
| 7 | * @copyright Copyright (c) 2016, GiveWP |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 1.0 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Get Donation Form. |
| 19 | * |
| 20 | * @param array $args An array of form arguments. |
| 21 | * |
| 22 | * @return string Donation form. |
| 23 | * @since 1.0 |
| 24 | */ |
| 25 | function give_get_donation_form( $args = [] ) { |
| 26 | |
| 27 | global $post; |
| 28 | static $count = 1; |
| 29 | |
| 30 | $args = wp_parse_args( $args, give_get_default_form_shortcode_args() ); |
| 31 | |
| 32 | // Backward compatibility for `form_id` function param. |
| 33 | // If are calling this function directly with `form_id` the use `id` instead. |
| 34 | $args['id'] = ! empty( $args['form_id'] ) ? absint( $args['form_id'] ) : $args['id']; |
| 35 | |
| 36 | // If `id` is not set then maybe we are single donation form page, so lets render form. |
| 37 | if ( empty( $args['id'] ) && is_object( $post ) && $post->ID ) { |
| 38 | $args['id'] = $post->ID; |
| 39 | } |
| 40 | |
| 41 | // set `form_id` for backward compatibility because many legacy filters and functions are using it. |
| 42 | $args['form_id'] = $args['id']; |
| 43 | |
| 44 | /** |
| 45 | * Fire the filter |
| 46 | * Note: we will deprecate this filter soon. Use give_get_default_form_shortcode_args instead |
| 47 | * |
| 48 | * @deprecated 2.4.1 |
| 49 | */ |
| 50 | $args = apply_filters( 'give_form_args_defaults', $args ); |
| 51 | |
| 52 | $form = new Give_Donate_Form( $args['id'] ); |
| 53 | |
| 54 | // Bail out, if no form ID. |
| 55 | if ( empty( $form->ID ) ) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | $args['id_prefix'] = "{$form->ID}-{$count}"; |
| 60 | $payment_mode = give_get_chosen_gateway( $form->ID ); |
| 61 | |
| 62 | $form_action = add_query_arg( |
| 63 | apply_filters( |
| 64 | 'give_form_action_args', |
| 65 | [ |
| 66 | 'payment-mode' => $payment_mode, |
| 67 | 'form-id' => $form->ID, |
| 68 | ] |
| 69 | ), |
| 70 | give_get_current_page_url() |
| 71 | ); |
| 72 | |
| 73 | // Sanity Check: Donation form not published or user doesn't have permission to view drafts. |
| 74 | if ( |
| 75 | ( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) ) |
| 76 | || ( 'trash' === $form->post_status ) |
| 77 | ) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // Get the form wrap CSS classes. |
| 82 | $form_wrap_classes = $form->get_form_wrap_classes( $args ); |
| 83 | |
| 84 | // Get the <form> tag wrap CSS classes. |
| 85 | $form_classes = $form->get_form_classes( $args ); |
| 86 | |
| 87 | ob_start(); |
| 88 | |
| 89 | /** |
| 90 | * Fires while outputting donation form, before the form wrapper div. |
| 91 | * |
| 92 | * @param int Give_Donate_Form::ID The form ID. |
| 93 | * @param array $args An array of form arguments. |
| 94 | * |
| 95 | * @since 1.0 |
| 96 | */ |
| 97 | do_action( 'give_pre_form_output', $form->ID, $args, $form ); |
| 98 | |
| 99 | ?> |
| 100 | <div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>"> |
| 101 | <?php |
| 102 | if ( $form->is_close_donation_form() ) { |
| 103 | |
| 104 | $form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' ) : ''; |
| 105 | |
| 106 | // Get Goal thank you message. |
| 107 | $goal_achieved_message = give_get_meta( $form->ID, '_give_form_goal_achieved_message', true ); |
| 108 | $goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : ''; |
| 109 | |
| 110 | // Print thank you message. |
| 111 | echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form ); |
| 112 | |
| 113 | } else { |
| 114 | /** |
| 115 | * Show form title: |
| 116 | * 1. if admin set form display_style to button or modal |
| 117 | */ |
| 118 | $form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' ); |
| 119 | |
| 120 | if ( ! doing_action( 'give_single_form_summary' ) && true === $args['show_title'] ) { |
| 121 | echo $form_title; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Fires while outputting donation form, before the form. |
| 126 | * |
| 127 | * @param int Give_Donate_Form::ID The form ID. |
| 128 | * @param array $args An array of form arguments. |
| 129 | * @param Give_Donate_Form $form Form object. |
| 130 | * |
| 131 | * @since 1.0 |
| 132 | */ |
| 133 | do_action( 'give_pre_form', $form->ID, $args, $form ); |
| 134 | |
| 135 | // Set form html tags. |
| 136 | $form_html_tags = [ |
| 137 | 'id' => "give-form-{$args['id_prefix']}", |
| 138 | 'class' => $form_classes, |
| 139 | 'action' => esc_url_raw( $form_action ), |
| 140 | 'data-id' => $args['id_prefix'] |
| 141 | ]; |
| 142 | |
| 143 | /** |
| 144 | * Filter the form html tags. |
| 145 | * |
| 146 | * @param array $form_html_tags Array of form html tags. |
| 147 | * @param Give_Donate_Form $form Form object. |
| 148 | * |
| 149 | * @since 1.8.17 |
| 150 | */ |
| 151 | $form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form ); |
| 152 | ?> |
| 153 | <form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post"> |
| 154 | <!-- The following field is for robots only, invisible to humans: --> |
| 155 | <span class="give-hidden" style="display: none !important;"> |
| 156 | <label for="give-form-honeypot-<?php echo $form->ID; ?>"></label> |
| 157 | <input id="give-form-honeypot-<?php echo $form->ID; ?>" type="text" name="give-honeypot" |
| 158 | class="give-honeypot give-hidden"/> |
| 159 | </span> |
| 160 | |
| 161 | <?php |
| 162 | /** |
| 163 | * Fires while outputting donation form, before all other fields. |
| 164 | * |
| 165 | * @param int Give_Donate_Form::ID The form ID. |
| 166 | * @param array $args An array of form arguments. |
| 167 | * @param Give_Donate_Form $form Form object. |
| 168 | * |
| 169 | * @since 1.0 |
| 170 | */ |
| 171 | do_action( 'give_donation_form_top', $form->ID, $args, $form ); |
| 172 | |
| 173 | /** |
| 174 | * Fires while outputting donation form, for payment gateway fields. |
| 175 | * |
| 176 | * @param int Give_Donate_Form::ID The form ID. |
| 177 | * @param array $args An array of form arguments. |
| 178 | * @param Give_Donate_Form $form Form object. |
| 179 | * |
| 180 | * @since 1.7 |
| 181 | */ |
| 182 | do_action( 'give_payment_mode_select', $form->ID, $args, $form ); |
| 183 | |
| 184 | /** |
| 185 | * Fires while outputting donation form, after all other fields. |
| 186 | * |
| 187 | * @param int Give_Donate_Form::ID The form ID. |
| 188 | * @param array $args An array of form arguments. |
| 189 | * @param Give_Donate_Form $form Form object. |
| 190 | * |
| 191 | * @since 1.0 |
| 192 | */ |
| 193 | do_action( 'give_donation_form_bottom', $form->ID, $args, $form ); |
| 194 | |
| 195 | ?> |
| 196 | </form> |
| 197 | |
| 198 | <?php |
| 199 | /** |
| 200 | * Fires while outputting donation form, after the form. |
| 201 | * |
| 202 | * @param int Give_Donate_Form::ID The form ID. |
| 203 | * @param array $args An array of form arguments. |
| 204 | * @param Give_Donate_Form $form Form object. |
| 205 | * |
| 206 | * @since 1.0 |
| 207 | */ |
| 208 | do_action( 'give_post_form', $form->ID, $args, $form ); |
| 209 | |
| 210 | } |
| 211 | ?> |
| 212 | |
| 213 | </div><!--end #give-form-<?php echo absint( $form->ID ); ?>--> |
| 214 | <?php |
| 215 | |
| 216 | /** |
| 217 | * Fires while outputting donation form, after the form wrapper div. |
| 218 | * |
| 219 | * @param int Give_Donate_Form::ID The form ID. |
| 220 | * @param array $args An array of form arguments. |
| 221 | * |
| 222 | * @since 1.0 |
| 223 | */ |
| 224 | do_action( 'give_post_form_output', $form->ID, $args ); |
| 225 | |
| 226 | $final_output = ob_get_clean(); |
| 227 | $count ++; |
| 228 | |
| 229 | echo apply_filters( 'give_donate_form', $final_output, $args ); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Give Show Donation Form. |
| 234 | * |
| 235 | * Renders the Donation Form, hooks are provided to add to the checkout form. |
| 236 | * The default Donation Form rendered displays a list of the enabled payment |
| 237 | * gateways, a user registration form (if enable) and a credit card info form |
| 238 | * if credit cards are enabled. |
| 239 | * |
| 240 | * @param int $form_id The form ID. |
| 241 | * |
| 242 | * @return string |
| 243 | * @since 1.0 |
| 244 | */ |
| 245 | function give_show_purchase_form( $form_id, $args ) { |
| 246 | |
| 247 | $payment_mode = give_get_chosen_gateway( $form_id ); |
| 248 | |
| 249 | if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) { |
| 250 | $form_id = $_POST['give_form_id']; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Fire before donation form render. |
| 255 | * |
| 256 | * @since 1.7 |
| 257 | */ |
| 258 | do_action( 'give_payment_fields_top', $form_id ); |
| 259 | |
| 260 | if ( give_can_checkout() && isset( $form_id ) ) { |
| 261 | |
| 262 | /** |
| 263 | * Fires while displaying donation form, before registration login. |
| 264 | * |
| 265 | * @since 1.7 |
| 266 | */ |
| 267 | do_action( 'give_donation_form_before_register_login', $form_id, $args ); |
| 268 | |
| 269 | /** |
| 270 | * Fire when register/login form fields render. |
| 271 | * |
| 272 | * @since 1.7 |
| 273 | */ |
| 274 | do_action( 'give_donation_form_register_login_fields', $form_id, $args ); |
| 275 | |
| 276 | /** |
| 277 | * Fire when credit card form fields render. |
| 278 | * |
| 279 | * @since 1.7 |
| 280 | */ |
| 281 | do_action( 'give_donation_form_before_cc_form', $form_id, $args ); |
| 282 | |
| 283 | // Load the credit card form and allow gateways to load their own if they wish. |
| 284 | if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) { |
| 285 | /** |
| 286 | * Fires while displaying donation form, credit card form fields for a given gateway. |
| 287 | * |
| 288 | * @param int $form_id The form ID. |
| 289 | * |
| 290 | * @since 1.0 |
| 291 | */ |
| 292 | do_action( "give_{$payment_mode}_cc_form", $form_id, $args ); |
| 293 | } else { |
| 294 | /** |
| 295 | * Fires while displaying donation form, credit card form fields. |
| 296 | * |
| 297 | * @param int $form_id The form ID. |
| 298 | * |
| 299 | * @since 1.0 |
| 300 | */ |
| 301 | do_action( 'give_cc_form', $form_id, $args ); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Fire after credit card form fields render. |
| 306 | * |
| 307 | * @since 1.7 |
| 308 | */ |
| 309 | do_action( 'give_donation_form_after_cc_form', $form_id, $args ); |
| 310 | |
| 311 | } else { |
| 312 | /** |
| 313 | * Fire if user can not donate. |
| 314 | * |
| 315 | * @since 1.7 |
| 316 | */ |
| 317 | do_action( 'give_donation_form_no_access', $form_id ); |
| 318 | |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Fire after donation form rendered. |
| 323 | * |
| 324 | * @since 1.7 |
| 325 | */ |
| 326 | do_action( 'give_payment_fields_bottom', $form_id, $args ); |
| 327 | } |
| 328 | |
| 329 | add_action( 'give_donation_form', 'give_show_purchase_form', 10, 2 ); |
| 330 | |
| 331 | /** |
| 332 | * Give Show Login/Register Form Fields. |
| 333 | * |
| 334 | * @param int $form_id The form ID. |
| 335 | * |
| 336 | * @return void |
| 337 | * @since 1.4.1 |
| 338 | */ |
| 339 | function give_show_register_login_fields( $form_id ) { |
| 340 | |
| 341 | $show_register_form = give_show_login_register_option( $form_id ); |
| 342 | |
| 343 | if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
| 344 | ?> |
| 345 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 346 | <?php |
| 347 | /** |
| 348 | * Fire if user registration form render. |
| 349 | * |
| 350 | * @since 1.7 |
| 351 | */ |
| 352 | do_action( 'give_donation_form_register_fields', $form_id ); |
| 353 | ?> |
| 354 | </div> |
| 355 | <?php |
| 356 | elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
| 357 | ?> |
| 358 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 359 | <?php |
| 360 | /** |
| 361 | * Fire if user login form render. |
| 362 | * |
| 363 | * @since 1.7 |
| 364 | */ |
| 365 | do_action( 'give_donation_form_login_fields', $form_id ); |
| 366 | ?> |
| 367 | </div> |
| 368 | <?php |
| 369 | endif; |
| 370 | |
| 371 | if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) { |
| 372 | /** |
| 373 | * Fire when user info render. |
| 374 | * |
| 375 | * @since 1.7 |
| 376 | */ |
| 377 | do_action( 'give_donation_form_after_user_info', $form_id ); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' ); |
| 382 | |
| 383 | /** |
| 384 | * Donation Amount Field. |
| 385 | * |
| 386 | * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount |
| 387 | * enabled the field will output as a customizable input. |
| 388 | * |
| 389 | * @param int $form_id The form ID. |
| 390 | * @param array $args An array of form arguments. |
| 391 | * |
| 392 | * @return void |
| 393 | * @since 1.0 |
| 394 | */ |
| 395 | function give_output_donation_amount_top( $form_id = 0, $args = [] ) { |
| 396 | |
| 397 | $give_options = give_get_settings(); |
| 398 | $variable_pricing = give_has_variable_prices( $form_id ); |
| 399 | $allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 400 | $currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before'; |
| 401 | $symbol = give_currency_symbol( give_get_currency( $form_id, $args ) ); |
| 402 | $currency_output = '<span class="give-currency-symbol give-currency-position-' . esc_attr($currency_position) . '">' . esc_html($symbol) . '</span>'; |
| 403 | $default_amount = give_format_amount( |
| 404 | give_get_default_form_amount( $form_id ), |
| 405 | [ |
| 406 | 'sanitize' => false, |
| 407 | 'currency' => give_get_currency( $form_id ), |
| 408 | ] |
| 409 | ); |
| 410 | $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
| 411 | |
| 412 | /** |
| 413 | * Fires while displaying donation form, before donation level fields. |
| 414 | * |
| 415 | * @param int $form_id The form ID. |
| 416 | * @param array $args An array of form arguments. |
| 417 | * |
| 418 | * @since 1.0 |
| 419 | */ |
| 420 | do_action( 'give_before_donation_levels', $form_id, $args ); |
| 421 | |
| 422 | // Set Price, No Custom Amount Allowed means hidden price field. |
| 423 | if ( ! give_is_setting_enabled( $allow_custom_amount ) ) { |
| 424 | ?> |
| 425 | <label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
| 426 | <input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" |
| 427 | value="<?php echo esc_attr($default_amount); ?>" required aria-required="true"/> |
| 428 | <div class="set-price give-donation-amount form-row-wide"> |
| 429 | <?php |
| 430 | if ( 'before' === $currency_position ) { |
| 431 | echo $currency_output; |
| 432 | } |
| 433 | ?> |
| 434 | <span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span> |
| 435 | <?php |
| 436 | if ( 'after' === $currency_position ) { |
| 437 | echo $currency_output; |
| 438 | } |
| 439 | ?> |
| 440 | </div> |
| 441 | <?php |
| 442 | } else { |
| 443 | // Custom Amount Allowed. |
| 444 | ?> |
| 445 | <div class="give-total-wrap"> |
| 446 | <div class="give-donation-amount form-row-wide"> |
| 447 | <?php |
| 448 | if ( 'before' === $currency_position ) { |
| 449 | echo $currency_output; |
| 450 | } |
| 451 | ?> |
| 452 | <label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
| 453 | <input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="text" inputmode="decimal" |
| 454 | placeholder="" value="<?php echo esc_attr($default_amount); ?>" autocomplete="off"> |
| 455 | <?php |
| 456 | if ( 'after' === $currency_position ) { |
| 457 | echo $currency_output; |
| 458 | } |
| 459 | ?> |
| 460 | </div> |
| 461 | </div> |
| 462 | <?php |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Fires while displaying donation form, after donation amount field(s). |
| 467 | * |
| 468 | * @param int $form_id The form ID. |
| 469 | * @param array $args An array of form arguments. |
| 470 | * |
| 471 | * @since 1.0 |
| 472 | */ |
| 473 | do_action( 'give_after_donation_amount', $form_id, $args ); |
| 474 | |
| 475 | // Custom Amount Text |
| 476 | if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { |
| 477 | ?> |
| 478 | <p class="give-custom-amount-text"><?php echo esc_html($custom_amount_text); ?></p> |
| 479 | <?php |
| 480 | } |
| 481 | |
| 482 | // Output Variable Pricing Levels. |
| 483 | if ( $variable_pricing ) { |
| 484 | give_output_levels( $form_id ); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Fires while displaying donation form, after donation level fields. |
| 489 | * |
| 490 | * @param int $form_id The form ID. |
| 491 | * @param array $args An array of form arguments. |
| 492 | * |
| 493 | * @since 1.0 |
| 494 | */ |
| 495 | do_action( 'give_after_donation_levels', $form_id, $args ); |
| 496 | } |
| 497 | |
| 498 | add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 ); |
| 499 | |
| 500 | /** |
| 501 | * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons. |
| 502 | * |
| 503 | * @since 1.0 |
| 504 | * |
| 505 | * @param int $form_id The form ID. |
| 506 | * @return string Donation levels. |
| 507 | */ |
| 508 | function give_output_levels( $form_id ) { |
| 509 | |
| 510 | /** |
| 511 | * Filter the variable pricing |
| 512 | * |
| 513 | * @param array $prices Array of variable prices. |
| 514 | * @param int $form Form ID. |
| 515 | * |
| 516 | * @since 1.0 |
| 517 | * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices. |
| 518 | * Check Give_Donate_Form::get_prices(). |
| 519 | */ |
| 520 | $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
| 521 | |
| 522 | $display_style = give_get_meta( $form_id, '_give_display_style', true ); |
| 523 | $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 524 | $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
| 525 | |
| 526 | if ( empty( $custom_amount_text ) ) { |
| 527 | $custom_amount_text = esc_html__( 'Custom Amount', 'give' ); |
| 528 | } |
| 529 | |
| 530 | $output = ''; |
| 531 | |
| 532 | switch ( $display_style ) { |
| 533 | case 'buttons': |
| 534 | $output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; |
| 535 | |
| 536 | foreach ( $prices as $price ) { |
| 537 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], [ 'sanitize' => false ] ), [ 'currency_code' => give_get_currency( $form_id ) ] ), $form_id, $price ); |
| 538 | $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( give_is_default_level_id( $price ) ? 'give-default-level' : '' ), $form_id, $price ); |
| 539 | |
| 540 | $formatted_amount = give_format_amount( |
| 541 | $price['_give_amount'], |
| 542 | [ |
| 543 | 'sanitize' => false, |
| 544 | 'currency' => give_get_currency( $form_id ), |
| 545 | ] |
| 546 | ); |
| 547 | |
| 548 | $output .= sprintf( |
| 549 | '<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>', |
| 550 | esc_attr($price['_give_id']['level_id']), |
| 551 | esc_attr($level_classes), |
| 552 | esc_attr($formatted_amount), |
| 553 | array_key_exists( '_give_default', $price ) ? 1 : 0, |
| 554 | esc_html($level_text) |
| 555 | ); |
| 556 | } |
| 557 | |
| 558 | // Custom Amount. |
| 559 | if ( |
| 560 | give_is_setting_enabled( $custom_amount ) |
| 561 | && ! empty( $custom_amount_text ) |
| 562 | ) { |
| 563 | |
| 564 | $output .= sprintf( |
| 565 | '<li><button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">%1$s</button></li>', |
| 566 | esc_html( $custom_amount_text ) |
| 567 | ); |
| 568 | } |
| 569 | |
| 570 | $output .= '</ul>'; |
| 571 | |
| 572 | break; |
| 573 | |
| 574 | case 'radios': |
| 575 | $output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">'; |
| 576 | |
| 577 | foreach ( $prices as $price ) { |
| 578 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], [ 'sanitize' => false ] ), [ 'currency_code' => give_get_currency( $form_id ) ] ), $form_id, $price ); |
| 579 | $level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id, $price ); |
| 580 | |
| 581 | $formatted_amount = give_format_amount( |
| 582 | $price['_give_amount'], |
| 583 | [ |
| 584 | 'sanitize' => false, |
| 585 | 'currency' => give_get_currency( $form_id ), |
| 586 | ] |
| 587 | ); |
| 588 | |
| 589 | $output .= sprintf( |
| 590 | '<li><input type="radio" data-price-id="%1$s" class="%2$s" value="%3$s" name="give-radio-donation-level" id="give-radio-level-%1$s" %4$s data-default="%5$s"><label for="give-radio-level-%1$s">%6$s</label></li>', |
| 591 | esc_attr($price['_give_id']['level_id']), |
| 592 | esc_attr($level_classes), |
| 593 | esc_attr($formatted_amount), |
| 594 | ( give_is_default_level_id( $price ) ? 'checked="checked"' : '' ), |
| 595 | array_key_exists( '_give_default', $price ) ? 1 : 0, |
| 596 | esc_html($level_text) |
| 597 | ); |
| 598 | } |
| 599 | |
| 600 | // Custom Amount. |
| 601 | if ( |
| 602 | give_is_setting_enabled( $custom_amount ) |
| 603 | && ! empty( $custom_amount_text ) |
| 604 | ) { |
| 605 | $output .= sprintf( |
| 606 | '<li><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"><label for="give-radio-level-custom">%1$s</label></li>', |
| 607 | esc_html( $custom_amount_text ) |
| 608 | ); |
| 609 | } |
| 610 | |
| 611 | $output .= '</ul>'; |
| 612 | |
| 613 | break; |
| 614 | |
| 615 | case 'dropdown': |
| 616 | $output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>'; |
| 617 | $output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">'; |
| 618 | |
| 619 | // first loop through prices. |
| 620 | foreach ( $prices as $price ) { |
| 621 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], [ 'sanitize' => false ] ), [ 'currency_code' => give_get_currency( $form_id ) ] ), $form_id, $price ); |
| 622 | $level_classes = apply_filters( |
| 623 | 'give_form_level_classes', |
| 624 | 'give-donation-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), |
| 625 | $form_id, |
| 626 | $price |
| 627 | ); |
| 628 | |
| 629 | $formatted_amount = give_format_amount( |
| 630 | $price['_give_amount'], |
| 631 | [ |
| 632 | 'sanitize' => false, |
| 633 | 'currency' => give_get_currency( $form_id ), |
| 634 | ] |
| 635 | ); |
| 636 | |
| 637 | $output .= sprintf( |
| 638 | '<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>', |
| 639 | esc_attr($price['_give_id']['level_id']), |
| 640 | esc_attr($level_classes), |
| 641 | esc_attr($formatted_amount), |
| 642 | ( give_is_default_level_id( $price ) ? 'selected="selected"' : '' ), |
| 643 | array_key_exists( '_give_default', $price ) ? 1 : 0, |
| 644 | esc_html($level_text) |
| 645 | ); |
| 646 | } |
| 647 | |
| 648 | // Custom Amount. |
| 649 | if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { |
| 650 | $output .= sprintf( |
| 651 | '<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>', |
| 652 | esc_html( $custom_amount_text ) |
| 653 | ); |
| 654 | } |
| 655 | |
| 656 | $output .= '</select>'; |
| 657 | |
| 658 | break; |
| 659 | } |
| 660 | |
| 661 | echo apply_filters( 'give_form_level_output', $output, $form_id ); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * Display Reveal & Lightbox Button. |
| 666 | * |
| 667 | * Outputs a button to reveal form fields. |
| 668 | * |
| 669 | * @param int $form_id The form ID. |
| 670 | * @param array $args An array of form arguments. |
| 671 | * |
| 672 | * @return string Checkout button. |
| 673 | * @since 1.0 |
| 674 | */ |
| 675 | function give_display_checkout_button( $form_id, $args ) { |
| 676 | $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
| 677 | ? $args['display_style'] |
| 678 | : give_get_meta( $form_id, '_give_payment_display', true ); |
| 679 | |
| 680 | if ( 'button' === $display_option ) { |
| 681 | add_action( 'give_post_form', 'give_add_button_open_form', 10, 2 ); |
| 682 | return ''; |
| 683 | } |
| 684 | |
| 685 | if ( $display_option === 'onpage' ) { |
| 686 | return ''; |
| 687 | } |
| 688 | |
| 689 | $display_label_field = give_get_meta( $form_id, '_give_reveal_label', true ); |
| 690 | $display_label = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 691 | |
| 692 | $output = '<button type="button" class="give-btn give-btn-' . esc_attr($display_option) . '">' . esc_html($display_label) . '</button>'; |
| 693 | |
| 694 | /** |
| 695 | * filter the button html |
| 696 | * |
| 697 | * @param string $output Button HTML. |
| 698 | * @param int $form_id Form ID. |
| 699 | * @param array $args Shortcode argument |
| 700 | */ |
| 701 | echo apply_filters( 'give_display_checkout_button', $output, $form_id, $args ); |
| 702 | } |
| 703 | |
| 704 | add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 ); |
| 705 | |
| 706 | /** |
| 707 | * Display MagnificPopup Button. |
| 708 | * |
| 709 | * @since 2.5.11 |
| 710 | * |
| 711 | * @param $form_id |
| 712 | * @param $args |
| 713 | * |
| 714 | * @return string |
| 715 | */ |
| 716 | function give_add_button_open_form( $form_id, $args ) { |
| 717 | $display_label_field = give_get_meta( $form_id, '_give_reveal_label', true ); |
| 718 | $display_label = ! empty( $args['continue_button_title'] ) |
| 719 | ? $args['continue_button_title'] |
| 720 | : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 721 | |
| 722 | $output = sprintf( |
| 723 | '<button type="button" class="give-btn give-btn-modal">%1$s</button>', |
| 724 | esc_html($display_label) |
| 725 | ); |
| 726 | |
| 727 | /** |
| 728 | * filter the button html |
| 729 | * |
| 730 | * @param string $output Button HTML. |
| 731 | * @param int $form_id Form ID. |
| 732 | * @param array $args Shortcode argument |
| 733 | */ |
| 734 | echo apply_filters( 'give_display_checkout_button', $output, $form_id, $args ); |
| 735 | |
| 736 | // Remove action otherwise button will be added to coming form. |
| 737 | // @see https://github.com/impress-org/givewp/issues/4395 |
| 738 | remove_action( 'give_post_form', 'give_add_button_open_form', 10 ); |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided. |
| 743 | * |
| 744 | * @since 3.1.0 Add the give_user_info_fields_user_info filter |
| 745 | * @since 2.25.0 add radio group to conditionally enable/disable company name field |
| 746 | * @since 1.0 |
| 747 | * |
| 748 | * @param int $form_id The form ID. |
| 749 | * |
| 750 | * @return void |
| 751 | * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation |
| 752 | */ |
| 753 | function give_user_info_fields( $form_id ) { |
| 754 | |
| 755 | // Get user info. |
| 756 | $give_user_info = apply_filters('give_user_info_fields_user_info', _give_get_prefill_form_field_values( $form_id ), $form_id ); |
| 757 | |
| 758 | $title = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : ''; |
| 759 | $first_name = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; |
| 760 | $last_name = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; |
| 761 | $company_name = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : ''; |
| 762 | $email = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; |
| 763 | $title_prefixes = give_get_name_title_prefixes( $form_id ); |
| 764 | |
| 765 | /** |
| 766 | * Fire before user personal information fields |
| 767 | * |
| 768 | * @since 1.7 |
| 769 | */ |
| 770 | do_action( 'give_donation_form_before_personal_info', $form_id ); |
| 771 | |
| 772 | $title_prefix_classes = ''; |
| 773 | if ( give_is_name_title_prefix_enabled( $form_id ) ) { |
| 774 | $title_prefix_classes = 'give-title-prefix-wrap'; |
| 775 | } |
| 776 | ?> |
| 777 | <fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>"> |
| 778 | <legend> |
| 779 | <?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?> |
| 780 | </legend> |
| 781 | |
| 782 | <?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?> |
| 783 | <p id="give-title-wrap" class="form-row form-row-title form-row-responsive"> |
| 784 | <label class="give-label" for="give-title"> |
| 785 | <?php esc_attr_e( 'Title', 'give' ); ?> |
| 786 | <?php if ( give_field_is_required( 'give_title', $form_id ) ) : ?> |
| 787 | <span class="give-required-indicator">*</span> |
| 788 | <?php endif ?> |
| 789 | <?php echo Give()->tooltips->render_help( __( 'Title is used to personalize your donation record..', 'give' ) ); ?> |
| 790 | </label> |
| 791 | <select |
| 792 | class="give-input" |
| 793 | type="text" |
| 794 | name="give_title" |
| 795 | id="give-title" |
| 796 | <?php |
| 797 | echo(give_field_is_required('give_title', $form_id) ? ' required aria-required="true" ' : ''); ?> |
| 798 | > |
| 799 | <?php |
| 800 | foreach ($title_prefixes as $key => $value) { ?> |
| 801 | <option |
| 802 | value="<?php |
| 803 | echo esc_html($value); ?>" <?php |
| 804 | selected($value, $title, true); ?>><?php |
| 805 | echo esc_html($value); ?></option> |
| 806 | <?php |
| 807 | } ?> |
| 808 | </select> |
| 809 | </p> |
| 810 | <?php |
| 811 | } ?> |
| 812 | |
| 813 | <p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive"> |
| 814 | <label class="give-label" for="give-first"> |
| 815 | <?php |
| 816 | esc_attr_e('First Name', 'give'); ?> |
| 817 | <?php |
| 818 | if (give_field_is_required('give_first', $form_id)) : ?> |
| 819 | <span class="give-required-indicator">*</span> |
| 820 | <?php |
| 821 | endif ?> |
| 822 | <?php |
| 823 | echo Give()->tooltips->render_help(__('First Name is used to personalize your donation record.', |
| 824 | 'give')); ?> |
| 825 | </label> |
| 826 | <input |
| 827 | class="give-input required" |
| 828 | type="text" |
| 829 | name="give_first" |
| 830 | autocomplete="given-name" |
| 831 | placeholder="<?php |
| 832 | esc_attr_e('First Name', 'give'); ?>" |
| 833 | id="give-first" |
| 834 | value="<?php |
| 835 | echo esc_html($first_name); ?>" |
| 836 | <?php |
| 837 | echo(give_field_is_required('give_first', $form_id) ? ' required aria-required="true" ' : ''); ?> |
| 838 | /> |
| 839 | </p> |
| 840 | |
| 841 | <p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive"> |
| 842 | <label class="give-label" for="give-last"> |
| 843 | <?php |
| 844 | esc_attr_e('Last Name', 'give'); ?> |
| 845 | <?php |
| 846 | if (give_field_is_required('give_last', $form_id)) : ?> |
| 847 | <span class="give-required-indicator">*</span> |
| 848 | <?php |
| 849 | endif ?> |
| 850 | <?php |
| 851 | echo Give()->tooltips->render_help(__('Last Name is used to personalize your donation record.', |
| 852 | 'give')); ?> |
| 853 | </label> |
| 854 | |
| 855 | <input |
| 856 | class="give-input<?php |
| 857 | echo(give_field_is_required('give_last', $form_id) ? ' required' : ''); ?>" |
| 858 | type="text" |
| 859 | name="give_last" |
| 860 | autocomplete="family-name" |
| 861 | id="give-last" |
| 862 | placeholder="<?php |
| 863 | esc_attr_e('Last Name', 'give'); ?>" |
| 864 | value="<?php |
| 865 | echo esc_html($last_name); ?>" |
| 866 | <?php |
| 867 | echo(give_field_is_required('give_last', $form_id) ? ' required aria-required="true" ' : ''); ?> |
| 868 | /> |
| 869 | </p> |
| 870 | |
| 871 | <?php |
| 872 | if (give_is_company_field_enabled($form_id)) : |
| 873 | $give_company = give_field_is_required('give_company_name', $form_id); |
| 874 | |
| 875 | if ( ! $give_company) : |
| 876 | ?> |
| 877 | <div id="give-company-radio-list-wrap" class="form-row form-row-wide"> |
| 878 | <label><?php |
| 879 | esc_html_e('Is this donation on behalf of a company?', 'give'); ?></label> |
| 880 | <ul id="<?php |
| 881 | echo esc_attr('give-company-name-radio-list'); ?>" class="give-company-radio-list"> |
| 882 | <li> |
| 883 | <input |
| 884 | checked |
| 885 | type="radio" |
| 886 | id="<?php |
| 887 | echo esc_attr('give-no-company'); ?>" |
| 888 | class="give_company_option" |
| 889 | name="give_company_option" |
| 890 | value="no" |
| 891 | /> |
| 892 | <label for="<?php |
| 893 | echo esc_attr('give-no-company'); ?>" class="give-company-option" |
| 894 | id="<?php |
| 895 | echo esc_attr('give-no-company'); ?>"> |
| 896 | <?php |
| 897 | esc_html_e('No', 'give'); ?> |
| 898 | </label> |
| 899 | </li> |
| 900 | <li> |
| 901 | <input |
| 902 | type="radio" |
| 903 | id="<?php |
| 904 | echo esc_attr('give-has-company'); ?>" |
| 905 | class="give_company_option" |
| 906 | name="give_company_option" |
| 907 | value="yes" |
| 908 | /> |
| 909 | <label for="<?php |
| 910 | echo esc_attr('give-has-company'); ?>" class="give-company-option" |
| 911 | id="<?php |
| 912 | echo esc_attr('give-has-company'); ?>"> |
| 913 | <?php |
| 914 | esc_html_e('Yes', 'give'); ?> |
| 915 | </label> |
| 916 | </li> |
| 917 | </ul> |
| 918 | </div> |
| 919 | <?php |
| 920 | endif; ?> |
| 921 | <p id="give-company-wrap" class="form-row form-row-wide"> |
| 922 | <label class="give-label" for="give-company"> |
| 923 | <?php |
| 924 | esc_attr_e('Company Name', 'give'); ?> |
| 925 | <?php |
| 926 | if ($give_company) : ?> |
| 927 | <span class="give-required-indicator">*</span> |
| 928 | <?php |
| 929 | endif; ?> |
| 930 | <?php |
| 931 | echo Give()->tooltips->render_help(__('Donate on behalf of Company', 'give')); ?> |
| 932 | </label> |
| 933 | <input |
| 934 | class="give-input<?php |
| 935 | echo($give_company ? ' required' : ''); ?>" |
| 936 | type="text" |
| 937 | name="give_company_name" |
| 938 | placeholder="<?php |
| 939 | esc_attr_e('Company Name', 'give'); ?>" |
| 940 | id="give-company" |
| 941 | value="<?php |
| 942 | echo esc_html($company_name); ?>" |
| 943 | <?php |
| 944 | echo($give_company ? ' required aria-required="true" ' : ''); ?> |
| 945 | /> |
| 946 | </p> |
| 947 | <?php |
| 948 | endif ?> |
| 949 | |
| 950 | <?php |
| 951 | /** |
| 952 | * Fire before user email field |
| 953 | * |
| 954 | * @since 1.7 |
| 955 | */ |
| 956 | do_action('give_donation_form_before_email', $form_id); |
| 957 | ?> |
| 958 | <p id="give-email-wrap" class="form-row form-row-wide"> |
| 959 | <label class="give-label" for="give-email"> |
| 960 | <?php |
| 961 | esc_attr_e('Email Address', 'give'); ?> |
| 962 | <?php |
| 963 | if (give_field_is_required('give_email', $form_id)) { ?> |
| 964 | <span class="give-required-indicator">*</span> |
| 965 | <?php |
| 966 | } ?> |
| 967 | <?php |
| 968 | echo Give()->tooltips->render_help(__('We will send the donation receipt to this address.', 'give')); ?> |
| 969 | </label> |
| 970 | <input |
| 971 | class="give-input required" |
| 972 | type="email" |
| 973 | name="give_email" |
| 974 | autocomplete="email" |
| 975 | placeholder="<?php |
| 976 | esc_attr_e('Email Address', 'give'); ?>" |
| 977 | id="give-email" |
| 978 | value="<?php |
| 979 | echo esc_html($email); ?>" |
| 980 | <?php |
| 981 | echo(give_field_is_required('give_email', $form_id) ? ' required aria-required="true" ' : ''); ?> |
| 982 | /> |
| 983 | |
| 984 | </p> |
| 985 | |
| 986 | <?php |
| 987 | if (give_is_anonymous_donation_field_enabled($form_id)) : ?> |
| 988 | <?php |
| 989 | $is_anonymous_donation = isset($_POST['give_anonymous_donation']) ? absint($_POST['give_anonymous_donation']) : 0; ?> |
| 990 | <p id="give-anonymous-donation-wrap" class="form-row form-row-wide"> |
| 991 | <label class="give-label" for="give-anonymous-donation"> |
| 992 | <input |
| 993 | type="checkbox" |
| 994 | class="give-input<?php |
| 995 | echo(give_field_is_required('give_anonymous_donation', $form_id) ? ' required' : ''); ?>" |
| 996 | name="give_anonymous_donation" |
| 997 | id="give-anonymous-donation" |
| 998 | value="1" |
| 999 | <?php |
| 1000 | echo(give_field_is_required('give_anonymous_donation', |
| 1001 | $form_id) ? ' required aria-required="true" ' : ''); ?> |
| 1002 | <?php |
| 1003 | checked(1, $is_anonymous_donation); ?> |
| 1004 | > |
| 1005 | <?php |
| 1006 | /** |
| 1007 | * Filters the checkbox label. |
| 1008 | * |
| 1009 | * @since 2.4.1 |
| 1010 | */ |
| 1011 | echo apply_filters('give_anonymous_donation_checkbox_label', |
| 1012 | __('Make this an anonymous donation.', 'give'), $form_id); |
| 1013 | |
| 1014 | if ( give_field_is_required( 'give_comment', $form_id ) ) { |
| 1015 | ?> |
| 1016 | <span class="give-required-indicator">*</span> |
| 1017 | <?php } ?> |
| 1018 | <?php |
| 1019 | // Conditional tooltip text when comments enabled: |
| 1020 | // https://github.com/impress-org/give/issues/3911 |
| 1021 | $anonymous_donation_tooltip = give_is_donor_comment_field_enabled( $form_id ) ? esc_html__( 'Would you like to prevent your name, image, and comment from being displayed publicly?', 'give' ) : esc_html__( 'Would you like to prevent your name and image from being displayed publicly?', 'give' ); |
| 1022 | |
| 1023 | echo Give()->tooltips->render_help( $anonymous_donation_tooltip ); |
| 1024 | ?> |
| 1025 | |
| 1026 | </label> |
| 1027 | </p> |
| 1028 | <?php endif; ?> |
| 1029 | |
| 1030 | <?php if ( give_is_donor_comment_field_enabled( $form_id ) ) : ?> |
| 1031 | <p id="give-comment-wrap" class="form-row form-row-wide"> |
| 1032 | <label class="give-label" for="give-comment"> |
| 1033 | <?php _e( 'Comment', 'give' ); ?> |
| 1034 | <?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?> |
| 1035 | <span class="give-required-indicator">*</span> |
| 1036 | <?php } ?> |
| 1037 | <?php echo Give()->tooltips->render_help( __( 'Would you like to add a comment to this donation?', 'give' ) ); ?> |
| 1038 | </label> |
| 1039 | |
| 1040 | <textarea |
| 1041 | class="give-input<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required' : '' ); ?>" |
| 1042 | name="give_comment" |
| 1043 | placeholder="<?php _e( 'Leave a comment', 'give' ); ?>" |
| 1044 | id="give-comment" |
| 1045 | <?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 1046 | ><?php echo isset( $_POST['give_comment'] ) ? give_clean( $_POST['give_comment'] ) : ''; ?></textarea> |
| 1047 | |
| 1048 | </p> |
| 1049 | <?php endif; ?> |
| 1050 | <?php |
| 1051 | /** |
| 1052 | * Fire after user email field |
| 1053 | * |
| 1054 | * @since 1.7 |
| 1055 | */ |
| 1056 | do_action( 'give_donation_form_after_email', $form_id ); |
| 1057 | |
| 1058 | /** |
| 1059 | * Fire after personal email field |
| 1060 | * |
| 1061 | * @since 1.7 |
| 1062 | */ |
| 1063 | do_action( 'give_donation_form_user_info', $form_id ); |
| 1064 | ?> |
| 1065 | </fieldset> |
| 1066 | <?php |
| 1067 | /** |
| 1068 | * Fire after user personal information fields |
| 1069 | * |
| 1070 | * @since 1.7 |
| 1071 | */ |
| 1072 | do_action( 'give_donation_form_after_personal_info', $form_id ); |
| 1073 | } |
| 1074 | |
| 1075 | add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' ); |
| 1076 | add_action( 'give_register_fields_before', 'give_user_info_fields' ); |
| 1077 | |
| 1078 | /** |
| 1079 | * Renders the credit card info form. |
| 1080 | * |
| 1081 | * @param int $form_id The form ID. |
| 1082 | * |
| 1083 | * @return void |
| 1084 | * @since 1.0 |
| 1085 | */ |
| 1086 | function give_get_cc_form( $form_id ) { |
| 1087 | |
| 1088 | ob_start(); |
| 1089 | |
| 1090 | /** |
| 1091 | * Fires while rendering credit card info form, before the fields. |
| 1092 | * |
| 1093 | * @param int $form_id The form ID. |
| 1094 | * |
| 1095 | * @since 1.0 |
| 1096 | */ |
| 1097 | do_action( 'give_before_cc_fields', $form_id ); |
| 1098 | ?> |
| 1099 | <fieldset id="give_cc_fields-<?php echo $form_id; ?>" class="give-do-validate"> |
| 1100 | <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend> |
| 1101 | <?php if ( is_ssl() ) : ?> |
| 1102 | <div id="give_secure_site_wrapper-<?php echo $form_id; ?>"> |
| 1103 | <span class="give-icon padlock"></span> |
| 1104 | <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span> |
| 1105 | </div> |
| 1106 | <?php endif; ?> |
| 1107 | <p id="give-card-number-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive"> |
| 1108 | <label for="card_number-<?php echo $form_id; ?>" class="give-label"> |
| 1109 | <?php _e( 'Card Number', 'give' ); ?> |
| 1110 | <span class="give-required-indicator">*</span> |
| 1111 | <?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?> |
| 1112 | <span class="card-type"></span> |
| 1113 | </label> |
| 1114 | |
| 1115 | <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id; ?>" |
| 1116 | class="card-number give-input required" placeholder="<?php _e( 'Card Number', 'give' ); ?>" |
| 1117 | required aria-required="true"/> |
| 1118 | </p> |
| 1119 | |
| 1120 | <p id="give-card-cvc-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-responsive"> |
| 1121 | <label for="card_cvc-<?php echo $form_id; ?>" class="give-label"> |
| 1122 | <?php _e( 'CVC', 'give' ); ?> |
| 1123 | <span class="give-required-indicator">*</span> |
| 1124 | <?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?> |
| 1125 | </label> |
| 1126 | |
| 1127 | <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id; ?>" |
| 1128 | class="card-cvc give-input required" placeholder="<?php _e( 'CVC', 'give' ); ?>" |
| 1129 | required aria-required="true"/> |
| 1130 | </p> |
| 1131 | |
| 1132 | <p id="give-card-name-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive"> |
| 1133 | <label for="card_name-<?php echo $form_id; ?>" class="give-label"> |
| 1134 | <?php _e( 'Cardholder Name', 'give' ); ?> |
| 1135 | <span class="give-required-indicator">*</span> |
| 1136 | <?php echo Give()->tooltips->render_help( __( 'The name of the credit card account holder.', 'give' ) ); ?> |
| 1137 | </label> |
| 1138 | |
| 1139 | <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id; ?>" |
| 1140 | class="card-name give-input required" placeholder="<?php esc_attr_e( 'Cardholder Name', 'give' ); ?>" |
| 1141 | required aria-required="true"/> |
| 1142 | </p> |
| 1143 | <?php |
| 1144 | /** |
| 1145 | * Fires while rendering credit card info form, before expiration fields. |
| 1146 | * |
| 1147 | * @param int $form_id The form ID. |
| 1148 | * |
| 1149 | * @since 1.0 |
| 1150 | */ |
| 1151 | do_action( 'give_before_cc_expiration' ); |
| 1152 | ?> |
| 1153 | <p class="card-expiration form-row form-row-one-third form-row-responsive"> |
| 1154 | <label for="card_expiry-<?php echo $form_id; ?>" class="give-label"> |
| 1155 | <?php _e( 'Expiration', 'give' ); ?> |
| 1156 | <span class="give-required-indicator">*</span> |
| 1157 | <?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?> |
| 1158 | </label> |
| 1159 | |
| 1160 | <input type="hidden" id="card_exp_month-<?php echo $form_id; ?>" name="card_exp_month" |
| 1161 | class="card-expiry-month"/> |
| 1162 | <input type="hidden" id="card_exp_year-<?php echo $form_id; ?>" name="card_exp_year" |
| 1163 | class="card-expiry-year"/> |
| 1164 | |
| 1165 | <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id; ?>" |
| 1166 | class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>" |
| 1167 | required aria-required="true"/> |
| 1168 | </p> |
| 1169 | <?php |
| 1170 | /** |
| 1171 | * Fires while rendering credit card info form, after expiration fields. |
| 1172 | * |
| 1173 | * @param int $form_id The form ID. |
| 1174 | * |
| 1175 | * @since 1.0 |
| 1176 | */ |
| 1177 | do_action( 'give_after_cc_expiration', $form_id ); |
| 1178 | ?> |
| 1179 | </fieldset> |
| 1180 | <?php |
| 1181 | /** |
| 1182 | * Fires while rendering credit card info form, before the fields. |
| 1183 | * |
| 1184 | * @param int $form_id The form ID. |
| 1185 | * |
| 1186 | * @since 1.0 |
| 1187 | */ |
| 1188 | do_action( 'give_after_cc_fields', $form_id ); |
| 1189 | |
| 1190 | echo ob_get_clean(); |
| 1191 | } |
| 1192 | |
| 1193 | add_action( 'give_cc_form', 'give_get_cc_form' ); |
| 1194 | |
| 1195 | /** |
| 1196 | * Outputs the default credit card address fields. |
| 1197 | * |
| 1198 | * @since 3.1.0 Add the give_default_cc_address_fields_user_info filter |
| 1199 | * @since 1.0 |
| 1200 | * |
| 1201 | * @param int $form_id The form ID. |
| 1202 | * @param bool $return Whether to return the output or echo it. * |
| 1203 | * |
| 1204 | * @return void|string |
| 1205 | */ |
| 1206 | function give_default_cc_address_fields($form_id, $return = false) |
| 1207 | { |
| 1208 | // Get user info. |
| 1209 | $give_user_info = apply_filters('give_default_cc_address_fields_user_info', _give_get_prefill_form_field_values( $form_id ), $form_id); |
| 1210 | |
| 1211 | ob_start(); |
| 1212 | ?> |
| 1213 | <fieldset id="give_cc_address" class="cc-address"> |
| 1214 | <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend> |
| 1215 | <?php |
| 1216 | /** |
| 1217 | * Fires while rendering credit card billing form, before address fields. |
| 1218 | * |
| 1219 | * @param int $form_id The form ID. |
| 1220 | * |
| 1221 | * @since 1.0 |
| 1222 | */ |
| 1223 | do_action( 'give_cc_billing_top' ); |
| 1224 | |
| 1225 | // For Country. |
| 1226 | $selected_country = give_get_country(); |
| 1227 | if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
| 1228 | $selected_country = $give_user_info['billing_country']; |
| 1229 | } |
| 1230 | $countries = give_get_country_list(); |
| 1231 | |
| 1232 | // For state. |
| 1233 | $selected_state = ''; |
| 1234 | if ( $selected_country === give_get_country() ) { |
| 1235 | // Get default selected state by admin. |
| 1236 | $selected_state = give_get_state(); |
| 1237 | } |
| 1238 | // Get the last payment made by user states. |
| 1239 | if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) { |
| 1240 | $selected_state = $give_user_info['card_state']; |
| 1241 | } |
| 1242 | // Get the country code. |
| 1243 | if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
| 1244 | $selected_country = $give_user_info['billing_country']; |
| 1245 | } |
| 1246 | |
| 1247 | // Get the country list that does not require city. |
| 1248 | $city_required = ! array_key_exists( $selected_country, give_city_not_required_country_list() ); |
| 1249 | |
| 1250 | ?> |
| 1251 | <p id="give-card-country-wrap" class="form-row form-row-wide"> |
| 1252 | <label for="billing_country" class="give-label"> |
| 1253 | <?php esc_html_e( 'Country', 'give' ); ?> |
| 1254 | <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?> |
| 1255 | <span class="give-required-indicator">*</span> |
| 1256 | <?php endif; ?> |
| 1257 | <span class="give-tooltip give-icon give-icon-question" |
| 1258 | data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span> |
| 1259 | </label> |
| 1260 | |
| 1261 | <select |
| 1262 | name="billing_country" |
| 1263 | autocomplete="country" |
| 1264 | id="billing_country" |
| 1265 | class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>" |
| 1266 | <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 1267 | > |
| 1268 | <?php |
| 1269 | foreach ( $countries as $country_code => $country ) { |
| 1270 | echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
| 1271 | } |
| 1272 | ?> |
| 1273 | </select> |
| 1274 | </p> |
| 1275 | |
| 1276 | <p id="give-card-address-wrap" class="form-row form-row-wide"> |
| 1277 | <label for="card_address" class="give-label"> |
| 1278 | <?php _e( 'Address 1', 'give' ); ?> |
| 1279 | <?php |
| 1280 | if ( give_field_is_required( 'card_address', $form_id ) ) : |
| 1281 | ?> |
| 1282 | <span class="give-required-indicator">*</span> |
| 1283 | <?php endif; ?> |
| 1284 | <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?> |
| 1285 | </label> |
| 1286 | |
| 1287 | <input |
| 1288 | type="text" |
| 1289 | id="card_address" |
| 1290 | name="card_address" |
| 1291 | autocomplete="address-line1" |
| 1292 | class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>" |
| 1293 | placeholder="<?php _e( 'Address line 1', 'give' ); ?>" |
| 1294 | value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>" |
| 1295 | <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 1296 | /> |
| 1297 | </p> |
| 1298 | |
| 1299 | <p id="give-card-address-2-wrap" class="form-row form-row-wide"> |
| 1300 | <label for="card_address_2" class="give-label"> |
| 1301 | <?php _e( 'Address 2', 'give' ); ?> |
| 1302 | <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?> |
| 1303 | <span class="give-required-indicator">*</span> |
| 1304 | <?php endif; ?> |
| 1305 | <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?> |
| 1306 | </label> |
| 1307 | |
| 1308 | <input |
| 1309 | type="text" |
| 1310 | id="card_address_2" |
| 1311 | name="card_address_2" |
| 1312 | autocomplete="address-line2" |
| 1313 | class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>" |
| 1314 | placeholder="<?php _e( 'Address line 2', 'give' ); ?>" |
| 1315 | value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>" |
| 1316 | <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 1317 | /> |
| 1318 | </p> |
| 1319 | |
| 1320 | <p id="give-card-city-wrap" class="form-row form-row-wide"> |
| 1321 | <label for="card_city" class="give-label"> |
| 1322 | <?php _e( 'City', 'give' ); ?> |
| 1323 | <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?> |
| 1324 | <span class="give-required-indicator <?php echo( $city_required ? '' : 'give-hidden' ); ?>">*</span> |
| 1325 | <?php endif; ?> |
| 1326 | <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?> |
| 1327 | </label> |
| 1328 | <input |
| 1329 | type="text" |
| 1330 | id="card_city" |
| 1331 | name="card_city" |
| 1332 | autocomplete="address-level2" |
| 1333 | class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>" |
| 1334 | placeholder="<?php _e( 'City', 'give' ); ?>" |
| 1335 | value="<?php echo( isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : '' ); ?>" |
| 1336 | <?php echo( give_field_is_required( 'card_city', $form_id ) && $city_required ? ' required aria-required="true" ' : '' ); ?> |
| 1337 | /> |
| 1338 | </p> |
| 1339 | |
| 1340 | <?php |
| 1341 | /** |
| 1342 | * State field logic. |
| 1343 | */ |
| 1344 | $state_label = __( 'State', 'give' ); |
| 1345 | $states_label = give_get_states_label(); |
| 1346 | // Check if $country code exists in the array key for states label. |
| 1347 | if ( array_key_exists( $selected_country, $states_label ) ) { |
| 1348 | $state_label = $states_label[ $selected_country ]; |
| 1349 | } |
| 1350 | $states = give_get_states( $selected_country ); |
| 1351 | // Get the country list that do not have any states. |
| 1352 | $no_states_country = give_no_states_country_list(); |
| 1353 | // Get the country list that does not require states. |
| 1354 | $states_not_required_country_list = give_states_not_required_country_list(); |
| 1355 | // Used to determine if state is required. |
| 1356 | $require_state = ! array_key_exists( $selected_country, $no_states_country ) && give_field_is_required( 'card_state', $form_id ); |
| 1357 | // Used to determine is state input should be marked as required. |
| 1358 | $validate_state = ! array_key_exists( $selected_country, $states_not_required_country_list ) && give_field_is_required( 'card_state', $form_id ); |
| 1359 | // Check if post code is required |
| 1360 | $postcode_required = $selected_country |
| 1361 | ? ! array_key_exists( $selected_country, give_get_country_list_without_postcodes() ) && give_field_is_required( 'card_zip', $form_id ) |
| 1362 | : give_field_is_required( 'card_zip', $form_id ); |
| 1363 | ?> |
| 1364 | <p id="give-card-state-wrap" |
| 1365 | class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && ! $require_state ) ? 'give-hidden' : ''; ?> "> |
| 1366 | <label for="card_state" class="give-label"> |
| 1367 | <span class="state-label-text"><?php echo $state_label; ?></span> |
| 1368 | <span |
| 1369 | class="give-required-indicator <?php echo $validate_state ? '' : 'give-hidden'; ?> ">*</span> |
| 1370 | <span class="give-tooltip give-icon give-icon-question" |
| 1371 | data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span> |
| 1372 | </label> |
| 1373 | <?php |
| 1374 | |
| 1375 | if ( ! empty( $states ) ) : |
| 1376 | ?> |
| 1377 | <select |
| 1378 | name="card_state" |
| 1379 | autocomplete="address-level1" |
| 1380 | id="card_state" |
| 1381 | class="card_state give-select<?php echo $validate_state ? ' required' : ''; ?>" |
| 1382 | <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?>> |
| 1383 | <?php |
| 1384 | foreach ( $states as $state_code => $state ) { |
| 1385 | echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
| 1386 | } |
| 1387 | ?> |
| 1388 | </select> |
| 1389 | <?php else : ?> |
| 1390 | <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" |
| 1391 | placeholder="<?php echo $state_label; ?>" value="<?php echo $selected_state; ?>" |
| 1392 | <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?> |
| 1393 | /> |
| 1394 | <?php endif; ?> |
| 1395 | </p> |
| 1396 | |
| 1397 | <p id="give-card-zip-wrap" class="form-row <?php echo $require_state ? 'form-row-last' : ''; ?> form-row-responsive"> |
| 1398 | <label for="card_zip" class="give-label"> |
| 1399 | <?php _e( 'Zip / Postal Code', 'give' ); ?> |
| 1400 | <span class="give-required-indicator<?php echo ( $postcode_required ? '' : ' give-hidden' ); ?>">*</span> |
| 1401 | <?php echo Give()->tooltips->render_help( __( 'The zip or postal code for your billing address.', 'give' ) ); ?> |
| 1402 | </label> |
| 1403 | |
| 1404 | <input |
| 1405 | type="text" |
| 1406 | size="4" |
| 1407 | id="card_zip" |
| 1408 | name="card_zip" |
| 1409 | autocomplete="postal-code" |
| 1410 | class="card-zip give-input<?php echo( $postcode_required ? ' required' : '' ); ?>" |
| 1411 | placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>" |
| 1412 | value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>" |
| 1413 | <?php echo( $postcode_required ? ' required aria-required="true" ' : '' ); ?> |
| 1414 | /> |
| 1415 | </p> |
| 1416 | <?php |
| 1417 | /** |
| 1418 | * Fires while rendering credit card billing form, after address fields. |
| 1419 | * |
| 1420 | * @param int $form_id The form ID. |
| 1421 | * |
| 1422 | * @since 1.0 |
| 1423 | */ |
| 1424 | do_action( 'give_cc_billing_bottom' ); |
| 1425 | ?> |
| 1426 | </fieldset> |
| 1427 | <?php |
| 1428 | |
| 1429 | if ($return) { |
| 1430 | return ob_get_clean(); |
| 1431 | } |
| 1432 | |
| 1433 | echo ob_get_clean(); |
| 1434 | } |
| 1435 | |
| 1436 | add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
| 1437 | |
| 1438 | |
| 1439 | /** |
| 1440 | * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form |
| 1441 | * is provided for the user to create an account. |
| 1442 | * |
| 1443 | * @param int $form_id The form ID. |
| 1444 | * |
| 1445 | * @return string |
| 1446 | * @since 1.0 |
| 1447 | */ |
| 1448 | function give_get_register_fields( $form_id ) { |
| 1449 | |
| 1450 | global $user_ID; |
| 1451 | |
| 1452 | if ( is_user_logged_in() ) { |
| 1453 | $user_data = get_userdata( $user_ID ); |
| 1454 | } |
| 1455 | |
| 1456 | $show_register_form = give_show_login_register_option( $form_id ); |
| 1457 | |
| 1458 | ob_start(); |
| 1459 | ?> |
| 1460 | <fieldset id="give-register-fields-<?php echo $form_id; ?>"> |
| 1461 | |
| 1462 | <?php |
| 1463 | /** |
| 1464 | * Fires while rendering user registration form, before registration fields. |
| 1465 | * |
| 1466 | * @param int $form_id The form ID. |
| 1467 | * |
| 1468 | * @since 1.0 |
| 1469 | */ |
| 1470 | do_action( 'give_register_fields_before', $form_id ); |
| 1471 | ?> |
| 1472 | |
| 1473 | <fieldset id="give-register-account-fields-<?php echo $form_id; ?>"> |
| 1474 | <?php |
| 1475 | /** |
| 1476 | * Fires while rendering user registration form, before account fields. |
| 1477 | * |
| 1478 | * @param int $form_id The form ID. |
| 1479 | * |
| 1480 | * @since 1.0 |
| 1481 | */ |
| 1482 | do_action( 'give_register_account_fields_before', $form_id ); |
| 1483 | |
| 1484 | $class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first'; |
| 1485 | // Add attributes to checkbox, if Guest Checkout is disabled. |
| 1486 | $is_guest_checkout = give_is_setting_enabled( give_get_meta( $form_id, '_give_logged_in_only', true ) ); |
| 1487 | ?> |
| 1488 | |
| 1489 | <?php |
| 1490 | /** |
| 1491 | * If Guest Checkout is enabled, display label and checkbox - unchecked. |
| 1492 | * If Guest Checkout it disabled, display hidden checkbox - checked. |
| 1493 | * @since 2.9.6 |
| 1494 | * @since 2.9.7 Create account checkbox is hidden when guest registration is disabled. |
| 1495 | */ |
| 1496 | ?> |
| 1497 | <div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive"> |
| 1498 | <?php |
| 1499 | $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true ); |
| 1500 | if ( give_is_setting_enabled( $is_guest_checkout ) ) { |
| 1501 | ?> |
| 1502 | <label for="give-create-account-<?php echo $form_id; ?>"> |
| 1503 | <input type="checkbox" id="give-create-account-<?php echo $form_id; ?>" name="give_create_account" class="give-input" value="on" /> |
| 1504 | <?php |
| 1505 | _e( 'Create an account', 'give' ); |
| 1506 | echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) ); |
| 1507 | ?> |
| 1508 | </label> |
| 1509 | <?php } else { ?> |
| 1510 | <input type="hidden" id="give-create-account-<?php echo $form_id; ?>" name="give_create_account" class="give-input" value="on" checked /> |
| 1511 | <?php } ?> |
| 1512 | <?php |
| 1513 | echo str_replace( |
| 1514 | '/>', |
| 1515 | 'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>', |
| 1516 | give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false ) |
| 1517 | ); |
| 1518 | ?> |
| 1519 | </div> |
| 1520 | |
| 1521 | <?php if ( 'both' === $show_register_form ) { ?> |
| 1522 | <div class="give-login-account-wrap form-row form-row-last form-row-responsive"> |
| 1523 | <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?> |
| 1524 | <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login" |
| 1525 | data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a> |
| 1526 | </p> |
| 1527 | <p class="give-loading-text"> |
| 1528 | <span class="give-loading-animation"></span> |
| 1529 | </p> |
| 1530 | </div> |
| 1531 | <?php } ?> |
| 1532 | |
| 1533 | <?php |
| 1534 | /** |
| 1535 | * Fires while rendering user registration form, after account fields. |
| 1536 | * |
| 1537 | * @param int $form_id The form ID. |
| 1538 | * |
| 1539 | * @since 1.0 |
| 1540 | */ |
| 1541 | do_action( 'give_register_account_fields_after', $form_id ); |
| 1542 | ?> |
| 1543 | </fieldset> |
| 1544 | |
| 1545 | <?php |
| 1546 | /** |
| 1547 | * Fires while rendering user registration form, after registration fields. |
| 1548 | * |
| 1549 | * @param int $form_id The form ID. |
| 1550 | * |
| 1551 | * @since 1.0 |
| 1552 | */ |
| 1553 | do_action( 'give_register_fields_after', $form_id ); |
| 1554 | ?> |
| 1555 | |
| 1556 | <input type="hidden" name="give-purchase-var" value="needs-to-register"/> |
| 1557 | |
| 1558 | <?php |
| 1559 | /** |
| 1560 | * Fire after register or login form render |
| 1561 | * |
| 1562 | * @since 1.7 |
| 1563 | */ |
| 1564 | do_action( 'give_donation_form_user_info', $form_id ); |
| 1565 | ?> |
| 1566 | |
| 1567 | </fieldset> |
| 1568 | <?php |
| 1569 | echo ob_get_clean(); |
| 1570 | } |
| 1571 | |
| 1572 | add_action( 'give_donation_form_register_fields', 'give_get_register_fields' ); |
| 1573 | |
| 1574 | /** |
| 1575 | * Gets the login fields for the login form on the checkout. This function hooks |
| 1576 | * on the give_donation_form_login_fields to display the login form if a user already |
| 1577 | * had an account. |
| 1578 | * |
| 1579 | * @param int $form_id The form ID. |
| 1580 | * |
| 1581 | * @return string |
| 1582 | * @since 1.0 |
| 1583 | */ |
| 1584 | function give_get_login_fields( $form_id ) { |
| 1585 | |
| 1586 | $form_id = isset( $_POST['form_id'] ) ? give_clean( $_POST['form_id'] ) : $form_id; |
| 1587 | $show_register_form = give_show_login_register_option( $form_id ); |
| 1588 | |
| 1589 | ob_start(); |
| 1590 | ?> |
| 1591 | <fieldset id="give-login-fields-<?php echo esc_attr( $form_id ); ?>"> |
| 1592 | <legend> |
| 1593 | <?php |
| 1594 | echo apply_filters( 'give_account_login_fieldset_heading', __( 'Log In to Your Account', 'give' ) ); |
| 1595 | if ( ! give_logged_in_only( $form_id ) ) { |
| 1596 | echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>'; |
| 1597 | } |
| 1598 | ?> |
| 1599 | </legend> |
| 1600 | <?php if ( $show_register_form === 'both' ) { ?> |
| 1601 | <p class="give-new-account-link"> |
| 1602 | <?php _e( 'Don\'t have an account?', 'give' ); ?> |
| 1603 | <a href="<?php echo esc_url( remove_query_arg( 'login' ) ); ?>" class="give-checkout-register-cancel" |
| 1604 | data-action="give_checkout_register"> |
| 1605 | <?php |
| 1606 | if ( give_logged_in_only( $form_id ) ) { |
| 1607 | _e( 'Register as a part of your donation »', 'give' ); |
| 1608 | } else { |
| 1609 | _e( 'Register or donate as a guest »', 'give' ); |
| 1610 | } |
| 1611 | ?> |
| 1612 | </a> |
| 1613 | </p> |
| 1614 | <p class="give-loading-text"> |
| 1615 | <span class="give-loading-animation"></span> |
| 1616 | </p> |
| 1617 | <?php } ?> |
| 1618 | <?php |
| 1619 | /** |
| 1620 | * Fires while rendering checkout login form, before the fields. |
| 1621 | * |
| 1622 | * @param int $form_id The form ID. |
| 1623 | * |
| 1624 | * @since 1.0 |
| 1625 | */ |
| 1626 | do_action( 'give_donation_form_login_fields_before', $form_id ); |
| 1627 | ?> |
| 1628 | <div class="give-user-login-fields-container"> |
| 1629 | <div id="give-user-login-wrap-<?php echo esc_attr( $form_id ); ?>" class="form-row form-row-first form-row-responsive"> |
| 1630 | <label class="give-label" for="give-user-login-<?php echo esc_attr( $form_id ); ?>"> |
| 1631 | <?php _e( 'Username or Email Address', 'give' ); ?> |
| 1632 | <?php if ( give_logged_in_only( $form_id ) ) { ?> |
| 1633 | <span class="give-required-indicator">*</span> |
| 1634 | <?php } ?> |
| 1635 | </label> |
| 1636 | |
| 1637 | <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" |
| 1638 | type="text" |
| 1639 | name="give_user_login" id="give-user-login-<?php echo esc_attr( $form_id ); ?>" value="" |
| 1640 | placeholder="<?php _e( 'Your username or email', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
| 1641 | </div> |
| 1642 | |
| 1643 | <div id="give-user-pass-wrap-<?php echo esc_attr( $form_id ); ?>" |
| 1644 | class="give_login_password form-row form-row-last form-row-responsive"> |
| 1645 | <label class="give-label" for="give-user-pass-<?php echo esc_attr( $form_id ); ?>"> |
| 1646 | <?php _e( 'Password', 'give' ); ?> |
| 1647 | <?php if ( give_logged_in_only( $form_id ) ) { ?> |
| 1648 | <span class="give-required-indicator">*</span> |
| 1649 | <?php } ?> |
| 1650 | </label> |
| 1651 | <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" |
| 1652 | type="password" name="give_user_pass" id="give-user-pass-<?php echo esc_attr( $form_id ); ?>" |
| 1653 | placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
| 1654 | <?php if ( give_logged_in_only( $form_id ) ) : ?> |
| 1655 | <input type="hidden" name="give-purchase-var" value="needs-to-login"/> |
| 1656 | <?php endif; ?> |
| 1657 | </div> |
| 1658 | </div> |
| 1659 | |
| 1660 | <div id="give-user-login-submit-<?php echo esc_attr( $form_id ); ?>" class="give-clearfix"> |
| 1661 | <input type="submit" class="give-submit give-btn button" name="give_login_submit" |
| 1662 | value="<?php _e( 'Login', 'give' ); ?>"/> |
| 1663 | <?php if ( $show_register_form !== 'login' ) { ?> |
| 1664 | <input type="button" data-action="give_cancel_login" |
| 1665 | class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel" |
| 1666 | value="<?php _e( 'Cancel', 'give' ); ?>"/> |
| 1667 | <?php } ?> |
| 1668 | <span class="give-loading-animation"></span> |
| 1669 | <div id="give-forgot-password-wrap-<?php echo esc_attr( $form_id ); ?>" class="give_login_forgot_password"> |
| 1670 | <span class="give-forgot-password "> |
| 1671 | <a href="<?php echo wp_lostpassword_url(); ?>" target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a> |
| 1672 | </span> |
| 1673 | </div> |
| 1674 | </div> |
| 1675 | <?php |
| 1676 | /** |
| 1677 | * Fires while rendering checkout login form, after the fields. |
| 1678 | * |
| 1679 | * @param int $form_id The form ID. |
| 1680 | * |
| 1681 | * @since 1.0 |
| 1682 | */ |
| 1683 | do_action( 'give_donation_form_login_fields_after', $form_id ); |
| 1684 | ?> |
| 1685 | </fieldset><!--end #give-login-fields--> |
| 1686 | <?php |
| 1687 | echo ob_get_clean(); |
| 1688 | } |
| 1689 | |
| 1690 | add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 ); |
| 1691 | |
| 1692 | /** |
| 1693 | * Payment Mode Select. |
| 1694 | * |
| 1695 | * Renders the payment mode form by getting all the enabled payment gateways and |
| 1696 | * outputting them as radio buttons for the user to choose the payment gateway. If |
| 1697 | * a default payment gateway has been chosen from the Give Settings, it will be |
| 1698 | * automatically selected. |
| 1699 | * |
| 1700 | * @param int $form_id The form ID. |
| 1701 | * |
| 1702 | * @return void |
| 1703 | * @since 1.0 |
| 1704 | */ |
| 1705 | function give_payment_mode_select( $form_id, $args ) { |
| 1706 | $gateways = give_get_enabled_payment_gateways($form_id, 2); |
| 1707 | $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
| 1708 | |
| 1709 | /** |
| 1710 | * Fires while selecting payment gateways, before the fields. |
| 1711 | * |
| 1712 | * @since 1.7 |
| 1713 | * |
| 1714 | * @param int $form_id The form ID. |
| 1715 | * |
| 1716 | */ |
| 1717 | do_action( 'give_payment_mode_top', $form_id ); |
| 1718 | ?> |
| 1719 | |
| 1720 | <fieldset id="give-payment-mode-select"<?php echo count( $gateways ) <= 1 ? ' style="display: none;"' : ''; ?>> |
| 1721 | <?php |
| 1722 | /** |
| 1723 | * Fires while selecting payment gateways, before the wrap div. |
| 1724 | * |
| 1725 | * @since 1.7 |
| 1726 | * |
| 1727 | * @param int $form_id The form ID. |
| 1728 | * |
| 1729 | */ |
| 1730 | do_action( 'give_payment_mode_before_gateways_wrap' ); |
| 1731 | ?> |
| 1732 | <legend |
| 1733 | class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?> |
| 1734 | <span class="give-loading-text"><span |
| 1735 | class="give-loading-animation"></span> |
| 1736 | </span> |
| 1737 | </legend> |
| 1738 | |
| 1739 | <div id="give-payment-mode-wrap"> |
| 1740 | <?php |
| 1741 | /** |
| 1742 | * Fires while selecting payment gateways, before the gateways list. |
| 1743 | * |
| 1744 | * @since 1.7 |
| 1745 | */ |
| 1746 | do_action( 'give_payment_mode_before_gateways' ) |
| 1747 | ?> |
| 1748 | <ul id="give-gateway-radio-list"> |
| 1749 | <?php |
| 1750 | /** |
| 1751 | * Loop through the active payment gateways. |
| 1752 | */ |
| 1753 | $selected_gateway = give_get_chosen_gateway( $form_id ); |
| 1754 | |
| 1755 | foreach ( $gateways as $gateway_id => $gateway ) : |
| 1756 | // Determine the default gateway. |
| 1757 | $checked = checked( $gateway_id, $selected_gateway, false ); |
| 1758 | $checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; |
| 1759 | $is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true; |
| 1760 | |
| 1761 | if ( true === $is_payment_method_visible ) { |
| 1762 | ?> |
| 1763 | <li<?php echo $checked_class; ?>> |
| 1764 | <input type="radio" name="payment-mode" class="give-gateway" |
| 1765 | id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
| 1766 | value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>> |
| 1767 | <label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
| 1768 | class="give-gateway-option" |
| 1769 | id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
| 1770 | </li> |
| 1771 | <?php |
| 1772 | } |
| 1773 | endforeach; |
| 1774 | ?> |
| 1775 | </ul> |
| 1776 | <?php |
| 1777 | /** |
| 1778 | * Fires while selecting payment gateways, before the gateways list. |
| 1779 | * |
| 1780 | * @since 1.7 |
| 1781 | */ |
| 1782 | do_action( 'give_payment_mode_after_gateways' ); |
| 1783 | ?> |
| 1784 | </div> |
| 1785 | <?php |
| 1786 | /** |
| 1787 | * Fires while selecting payment gateways, after the wrap div. |
| 1788 | * |
| 1789 | * @param int $form_id The form ID. |
| 1790 | * |
| 1791 | * @since 1.7 |
| 1792 | */ |
| 1793 | do_action( 'give_payment_mode_after_gateways_wrap' ); |
| 1794 | ?> |
| 1795 | </fieldset> |
| 1796 | |
| 1797 | <?php |
| 1798 | /** |
| 1799 | * Fires while selecting payment gateways, after the fields. |
| 1800 | * |
| 1801 | * @param int $form_id The form ID. |
| 1802 | * |
| 1803 | * @since 1.7 |
| 1804 | */ |
| 1805 | do_action( 'give_payment_mode_bottom', $form_id ); |
| 1806 | ?> |
| 1807 | |
| 1808 | <div id="give_purchase_form_wrap"> |
| 1809 | |
| 1810 | <?php |
| 1811 | /** |
| 1812 | * Fire after payment field render. |
| 1813 | * |
| 1814 | * @since 1.7 |
| 1815 | */ |
| 1816 | do_action( 'give_donation_form', $form_id, $args ); |
| 1817 | ?> |
| 1818 | |
| 1819 | </div> |
| 1820 | |
| 1821 | <?php |
| 1822 | /** |
| 1823 | * Fire after donation form render. |
| 1824 | * |
| 1825 | * @since 1.7 |
| 1826 | */ |
| 1827 | do_action( 'give_donation_form_wrap_bottom', $form_id ); |
| 1828 | } |
| 1829 | |
| 1830 | add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 ); |
| 1831 | |
| 1832 | /** |
| 1833 | * Renders the Checkout Agree to Terms, this displays a checkbox for users to |
| 1834 | * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are |
| 1835 | * set in the Give Settings. |
| 1836 | * |
| 1837 | * @param int $form_id The form ID. |
| 1838 | * |
| 1839 | * @return bool |
| 1840 | * @since 1.0 |
| 1841 | */ |
| 1842 | function give_terms_agreement( $form_id ) { |
| 1843 | $form_option = give_get_meta( $form_id, '_give_terms_option', true ); |
| 1844 | |
| 1845 | // Bailout if per form and global term and conditions is not setup. |
| 1846 | if ( |
| 1847 | give_is_setting_enabled( $form_option, 'global' ) |
| 1848 | && give_is_setting_enabled( give_get_option( 'terms' ) ) |
| 1849 | ) { |
| 1850 | $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) ); |
| 1851 | $terms = $terms = give_get_option( 'agreement_text', '' ); |
| 1852 | $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display§ion=term-and-conditions' ); |
| 1853 | |
| 1854 | } elseif ( give_is_setting_enabled( $form_option ) ) { |
| 1855 | $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' ); |
| 1856 | $terms = give_get_meta( $form_id, '_give_agree_text', true ); |
| 1857 | $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' ); |
| 1858 | |
| 1859 | } else { |
| 1860 | return false; |
| 1861 | } |
| 1862 | |
| 1863 | // Bailout: Check if term and conditions text is empty or not. |
| 1864 | if ( empty( $terms ) ) { |
| 1865 | if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) { |
| 1866 | echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url ); |
| 1867 | } |
| 1868 | |
| 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | /** |
| 1873 | * Filter the form term content |
| 1874 | * |
| 1875 | * @since 2.1.5 |
| 1876 | */ |
| 1877 | $terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id ); |
| 1878 | |
| 1879 | ?> |
| 1880 | <fieldset id="give_terms_agreement"> |
| 1881 | <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend> |
| 1882 | <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;"> |
| 1883 | <?php |
| 1884 | /** |
| 1885 | * Fires while rendering terms of agreement, before the fields. |
| 1886 | * |
| 1887 | * @since 1.0 |
| 1888 | */ |
| 1889 | do_action( 'give_before_terms' ); |
| 1890 | |
| 1891 | echo $terms; |
| 1892 | /** |
| 1893 | * Fires while rendering terms of agreement, after the fields. |
| 1894 | * |
| 1895 | * @since 1.0 |
| 1896 | */ |
| 1897 | do_action( 'give_after_terms' ); |
| 1898 | ?> |
| 1899 | </div> |
| 1900 | <div id="give_show_terms"> |
| 1901 | <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1902 | aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a> |
| 1903 | <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1904 | aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a> |
| 1905 | </div> |
| 1906 | |
| 1907 | <input name="give_agree_to_terms" class="required" type="checkbox" |
| 1908 | id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/> |
| 1909 | <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label> |
| 1910 | |
| 1911 | </fieldset> |
| 1912 | <?php |
| 1913 | } |
| 1914 | |
| 1915 | add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 ); |
| 1916 | |
| 1917 | /** |
| 1918 | * Checkout Final Total. |
| 1919 | * |
| 1920 | * Shows the final donation total at the bottom of the checkout page. |
| 1921 | * |
| 1922 | * @param int $form_id The form ID. |
| 1923 | * |
| 1924 | * @return void |
| 1925 | * @since 1.0 |
| 1926 | */ |
| 1927 | function give_checkout_final_total( $form_id ) { |
| 1928 | |
| 1929 | $total = isset( $_POST['give_total'] ) ? |
| 1930 | apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'], [ 'currency' => give_get_currency( $form_id ) ] ) ) : |
| 1931 | give_get_default_form_amount( $form_id ); |
| 1932 | |
| 1933 | // Only proceed if give_total available. |
| 1934 | if ( empty( $total ) ) { |
| 1935 | return; |
| 1936 | } |
| 1937 | ?> |
| 1938 | <p id="give-final-total-wrap" class="form-wrap "> |
| 1939 | <?php |
| 1940 | /** |
| 1941 | * Fires before the donation total label |
| 1942 | * |
| 1943 | * @since 2.0.5 |
| 1944 | */ |
| 1945 | do_action( 'give_donation_final_total_label_before', $form_id ); |
| 1946 | ?> |
| 1947 | <span class="give-donation-total-label"> |
| 1948 | <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?> |
| 1949 | </span> |
| 1950 | <span class="give-final-total-amount" |
| 1951 | data-total="<?php echo give_format_amount( $total, [ 'sanitize' => false ] ); ?>"> |
| 1952 | <?php |
| 1953 | echo give_currency_filter( |
| 1954 | give_format_amount( |
| 1955 | $total, |
| 1956 | [ |
| 1957 | 'sanitize' => false, |
| 1958 | 'currency' => give_get_currency( $form_id ), |
| 1959 | ] |
| 1960 | ), |
| 1961 | [ 'currency_code' => give_get_currency( $form_id ) ] |
| 1962 | ); |
| 1963 | ?> |
| 1964 | </span> |
| 1965 | <?php |
| 1966 | /** |
| 1967 | * Fires after the donation final total label |
| 1968 | * |
| 1969 | * @since 2.0.5 |
| 1970 | */ |
| 1971 | do_action( 'give_donation_final_total_label_after', $form_id ); |
| 1972 | ?> |
| 1973 | </p> |
| 1974 | <?php |
| 1975 | } |
| 1976 | |
| 1977 | add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 ); |
| 1978 | |
| 1979 | /** |
| 1980 | * Renders the Checkout Submit section. |
| 1981 | * |
| 1982 | * @param int $form_id The donation form ID. |
| 1983 | * @param array $args List of arguments. |
| 1984 | * |
| 1985 | * @return void |
| 1986 | * @since 1.0 |
| 1987 | */ |
| 1988 | function give_checkout_submit( $form_id, $args ) { |
| 1989 | ?> |
| 1990 | <fieldset id="give_purchase_submit" class="give-donation-submit"> |
| 1991 | <?php |
| 1992 | /** |
| 1993 | * Fire before donation form submit. |
| 1994 | * |
| 1995 | * @since 1.7 |
| 1996 | */ |
| 1997 | do_action( 'give_donation_form_before_submit', $form_id, $args ); |
| 1998 | |
| 1999 | give_checkout_hidden_fields( $form_id, $args ); |
| 2000 | |
| 2001 | echo give_get_donation_form_submit_button( $form_id, $args ); |
| 2002 | |
| 2003 | /** |
| 2004 | * Fire after donation form submit. |
| 2005 | * |
| 2006 | * @since 1.7 |
| 2007 | */ |
| 2008 | do_action( 'give_donation_form_after_submit', $form_id, $args ); |
| 2009 | ?> |
| 2010 | </fieldset> |
| 2011 | <?php |
| 2012 | } |
| 2013 | |
| 2014 | add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 ); |
| 2015 | |
| 2016 | /** |
| 2017 | * Give Donation form submit button. |
| 2018 | * |
| 2019 | * @param int $form_id The form ID. |
| 2020 | * @param array $args |
| 2021 | * |
| 2022 | * @return string |
| 2023 | * @since 1.8.8 |
| 2024 | */ |
| 2025 | function give_get_donation_form_submit_button( $form_id, $args = [] ) { |
| 2026 | |
| 2027 | $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true ); |
| 2028 | $display_label_field = apply_filters( 'give_donation_form_submit_button_text', $display_label_field, $form_id, $args ); |
| 2029 | $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 2030 | ob_start(); |
| 2031 | ?> |
| 2032 | <div class="give-submit-button-wrap give-clearfix"> |
| 2033 | <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" |
| 2034 | value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/> |
| 2035 | <span class="give-loading-animation"></span> |
| 2036 | </div> |
| 2037 | <?php |
| 2038 | return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args ); |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * Show Give Goals. |
| 2043 | * |
| 2044 | * @param int $form_id The form ID. |
| 2045 | * @param array $args An array of form arguments. |
| 2046 | * |
| 2047 | * @return mixed |
| 2048 | * @since 1.6 Add template for Give Goals Shortcode. |
| 2049 | * More info is on https://github.com/impress-org/give/issues/411 |
| 2050 | * |
| 2051 | * @since 1.0 |
| 2052 | */ |
| 2053 | function give_show_goal_progress( $form_id, $args = [] ) { |
| 2054 | |
| 2055 | ob_start(); |
| 2056 | give_get_template( |
| 2057 | 'shortcode-goal', |
| 2058 | [ |
| 2059 | 'form_id' => $form_id, |
| 2060 | 'args' => $args, |
| 2061 | ] |
| 2062 | ); |
| 2063 | |
| 2064 | /** |
| 2065 | * Filter progress bar output |
| 2066 | * |
| 2067 | * @since 2.0 |
| 2068 | */ |
| 2069 | echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args ); |
| 2070 | |
| 2071 | return true; |
| 2072 | } |
| 2073 | |
| 2074 | add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
| 2075 | |
| 2076 | /** |
| 2077 | * Show Give Totals Progress. |
| 2078 | * |
| 2079 | * @param int $total Total amount based on shortcode parameter. |
| 2080 | * @param int $total_goal Total Goal amount passed by Admin. |
| 2081 | * |
| 2082 | * @return mixed |
| 2083 | * @since 2.1 |
| 2084 | */ |
| 2085 | function give_show_goal_totals_progress( $total, $total_goal ) { |
| 2086 | |
| 2087 | // Bail out if total goal is set as an array. |
| 2088 | if ( isset( $total_goal ) && is_array( $total_goal ) ) { |
| 2089 | return false; |
| 2090 | } |
| 2091 | |
| 2092 | ob_start(); |
| 2093 | give_get_template( |
| 2094 | 'shortcode-totals-progress', |
| 2095 | [ |
| 2096 | 'total' => $total, |
| 2097 | 'total_goal' => $total_goal, |
| 2098 | ] |
| 2099 | ); |
| 2100 | |
| 2101 | echo apply_filters( 'give_total_progress_output', ob_get_clean() ); |
| 2102 | |
| 2103 | return true; |
| 2104 | } |
| 2105 | |
| 2106 | add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 ); |
| 2107 | |
| 2108 | /** |
| 2109 | * Get form content position. |
| 2110 | * |
| 2111 | * @param $form_id |
| 2112 | * @param $args |
| 2113 | * |
| 2114 | * @return mixed|string |
| 2115 | * @since 1.8 |
| 2116 | */ |
| 2117 | function give_get_form_content_placement( $form_id, $args ) { |
| 2118 | $show_content = ''; |
| 2119 | |
| 2120 | if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) { |
| 2121 | // Content positions. |
| 2122 | $content_placement = [ |
| 2123 | 'above' => 'give_pre_form', |
| 2124 | 'below' => 'give_post_form', |
| 2125 | ]; |
| 2126 | |
| 2127 | // Check if content position already decoded. |
| 2128 | if ( in_array( $args['show_content'], $content_placement ) ) { |
| 2129 | return $args['show_content']; |
| 2130 | } |
| 2131 | |
| 2132 | $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' ); |
| 2133 | |
| 2134 | } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) { |
| 2135 | $show_content = give_get_meta( $form_id, '_give_content_placement', true ); |
| 2136 | |
| 2137 | } |
| 2138 | |
| 2139 | return $show_content; |
| 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * Adds Actions to Render Form Content. |
| 2144 | * |
| 2145 | * @param int $form_id The form ID. |
| 2146 | * @param array $args An array of form arguments. |
| 2147 | * |
| 2148 | * @return void|bool |
| 2149 | * @since 1.0 |
| 2150 | */ |
| 2151 | function give_form_content( $form_id, $args ) { |
| 2152 | |
| 2153 | $show_content = give_get_form_content_placement( $form_id, $args ); |
| 2154 | |
| 2155 | // Bailout. |
| 2156 | if ( empty( $show_content ) ) { |
| 2157 | return false; |
| 2158 | } |
| 2159 | |
| 2160 | // Add action according to value. |
| 2161 | add_action( $show_content, 'give_form_display_content', 10, 2 ); |
| 2162 | } |
| 2163 | |
| 2164 | add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
| 2165 | |
| 2166 | /** |
| 2167 | * Renders Post Form Content. |
| 2168 | * |
| 2169 | * Displays content for Give forms; fired by action from give_form_content. |
| 2170 | * |
| 2171 | * @param int $form_id The form ID. |
| 2172 | * @param array $args An array of form arguments. |
| 2173 | * |
| 2174 | * @return void |
| 2175 | * @since 1.0 |
| 2176 | */ |
| 2177 | function give_form_display_content( $form_id, $args ) { |
| 2178 | $content = give_get_meta( $form_id, '_give_form_content', true ); |
| 2179 | $show_content = give_get_form_content_placement( $form_id, $args ); |
| 2180 | |
| 2181 | if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) { |
| 2182 | |
| 2183 | // Do not restore wpautop if we are still parsing blocks. |
| 2184 | $priority = has_filter( 'the_content', '_restore_wpautop_hook' ); |
| 2185 | if ( false !== $priority && doing_filter( 'the_content' ) ) { |
| 2186 | remove_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
| 2187 | } |
| 2188 | |
| 2189 | $content = apply_filters( 'the_content', $content ); |
| 2190 | |
| 2191 | // Restore wpautop after done with blocks parsing. |
| 2192 | if ( $priority ) { |
| 2193 | // Run wpautop manually if parsing block |
| 2194 | $content = wpautop( $content ); |
| 2195 | |
| 2196 | add_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
| 2197 | } |
| 2198 | } else { |
| 2199 | $content = wpautop( do_shortcode( $content ) ); |
| 2200 | } |
| 2201 | |
| 2202 | $output = sprintf( |
| 2203 | '<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>', |
| 2204 | $form_id, |
| 2205 | $show_content, |
| 2206 | $content |
| 2207 | ); |
| 2208 | |
| 2209 | /** |
| 2210 | * Filter form content html |
| 2211 | * |
| 2212 | * @param string $output |
| 2213 | * @param int $form_id |
| 2214 | * @param array $args |
| 2215 | * |
| 2216 | * @since 1.0 |
| 2217 | */ |
| 2218 | echo apply_filters( 'give_form_content_output', $output, $form_id, $args ); |
| 2219 | |
| 2220 | // remove action to prevent content output on addition forms on page. |
| 2221 | // @see: https://github.com/impress-org/give/issues/634. |
| 2222 | remove_action( $show_content, 'give_form_display_content' ); |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * Renders the hidden Checkout fields. |
| 2227 | * |
| 2228 | * @param int $form_id The form ID. |
| 2229 | * @param array $args Shortcode args. |
| 2230 | * |
| 2231 | * @return void |
| 2232 | * @since 1.0 |
| 2233 | */ |
| 2234 | function give_checkout_hidden_fields( $form_id, $args = [] ) { |
| 2235 | |
| 2236 | /** |
| 2237 | * Fires while rendering hidden checkout fields, before the fields. |
| 2238 | * |
| 2239 | * @param int $form_id The form ID. |
| 2240 | * |
| 2241 | * @since 1.0 |
| 2242 | */ |
| 2243 | do_action( 'give_hidden_fields_before', $form_id, $args ); |
| 2244 | |
| 2245 | if ( is_user_logged_in() ) { |
| 2246 | ?> |
| 2247 | <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
| 2248 | <?php } ?> |
| 2249 | <input type="hidden" name="give_action" value="purchase"/> |
| 2250 | <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
| 2251 | <?php |
| 2252 | /** |
| 2253 | * Fires while rendering hidden checkout fields, after the fields. |
| 2254 | * |
| 2255 | * @param int $form_id The form ID. |
| 2256 | * |
| 2257 | * @since 1.0 |
| 2258 | */ |
| 2259 | do_action( 'give_hidden_fields_after', $form_id, $args ); |
| 2260 | |
| 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * Filter Success Page Content. |
| 2265 | * |
| 2266 | * Applies filters to the success page content. |
| 2267 | * |
| 2268 | * @param string $content Content before filters. |
| 2269 | * |
| 2270 | * @return string $content Filtered content. |
| 2271 | * @since 1.0 |
| 2272 | */ |
| 2273 | function give_filter_success_page_content( $content ) { |
| 2274 | |
| 2275 | $give_options = give_get_settings(); |
| 2276 | |
| 2277 | if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
| 2278 | if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
| 2279 | $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | return $content; |
| 2284 | } |
| 2285 | |
| 2286 | add_filter( 'the_content', 'give_filter_success_page_content' ); |
| 2287 | |
| 2288 | /** |
| 2289 | * Test Mode Frontend Warning. |
| 2290 | * |
| 2291 | * Displays a notice on the frontend for donation forms. |
| 2292 | * |
| 2293 | * @since 1.1 |
| 2294 | */ |
| 2295 | function give_test_mode_frontend_warning() { |
| 2296 | |
| 2297 | if ( give_is_test_mode() ) { |
| 2298 | echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>' . esc_html__( 'Notice:', 'give' ) . '</strong> ' . esc_html__( 'Test mode is enabled. While in test mode no live donations are processed.', 'give' ) . '</p></div>'; |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
| 2303 | |
| 2304 | /** |
| 2305 | * Members-only Form. |
| 2306 | * |
| 2307 | * If "Disable Guest Donations" and "Display Register / Login" is set to none. |
| 2308 | * |
| 2309 | * @param string $final_output |
| 2310 | * @param array $args |
| 2311 | * |
| 2312 | * @return string |
| 2313 | * @since 1.4.1 |
| 2314 | */ |
| 2315 | function give_members_only_form( $final_output, $args ) { |
| 2316 | |
| 2317 | $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0; |
| 2318 | |
| 2319 | // Sanity Check: Must have form_id & not be logged in. |
| 2320 | if ( empty( $form_id ) || is_user_logged_in() ) { |
| 2321 | return $final_output; |
| 2322 | } |
| 2323 | |
| 2324 | // Logged in only and Register / Login set to none. |
| 2325 | if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) { |
| 2326 | |
| 2327 | $final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false ); |
| 2328 | |
| 2329 | return apply_filters( 'give_members_only_output', $final_output, $form_id ); |
| 2330 | |
| 2331 | } |
| 2332 | |
| 2333 | return $final_output; |
| 2334 | |
| 2335 | } |
| 2336 | |
| 2337 | add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 ); |
| 2338 | |
| 2339 | |
| 2340 | /** |
| 2341 | * Add donation form hidden fields. |
| 2342 | * |
| 2343 | * @param int $form_id |
| 2344 | * @param array $args |
| 2345 | * @param Give_Donate_Form $form |
| 2346 | * |
| 2347 | * @since 1.8.17 |
| 2348 | */ |
| 2349 | function __give_form_add_donation_hidden_field( $form_id, $args, $form ) { |
| 2350 | $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
| 2351 | ?> |
| 2352 | <input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/> |
| 2353 | <input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/> |
| 2354 | <input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/> |
| 2355 | <input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
| 2356 | <input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
| 2357 | <?php |
| 2358 | // Get the custom option amount. |
| 2359 | $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 2360 | |
| 2361 | // If custom amount enabled. |
| 2362 | if ( give_is_setting_enabled( $custom_amount ) ) { |
| 2363 | ?> |
| 2364 | <input type="hidden" name="give-form-minimum" |
| 2365 | value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/> |
| 2366 | <input type="hidden" name="give-form-maximum" |
| 2367 | value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/> |
| 2368 | <?php |
| 2369 | } |
| 2370 | |
| 2371 | $data_attr = sprintf( |
| 2372 | 'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"', |
| 2373 | time(), |
| 2374 | give_get_nonce_life(), |
| 2375 | absint( Give()->session->has_session() ) |
| 2376 | ); |
| 2377 | |
| 2378 | // WP nonce field. |
| 2379 | echo str_replace( |
| 2380 | '/>', |
| 2381 | "{$data_attr}/>", |
| 2382 | give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false ) |
| 2383 | ); |
| 2384 | |
| 2385 | // Price ID hidden field for variable (multi-level) donation forms. |
| 2386 | if ( give_has_variable_prices( $form_id ) ) { |
| 2387 | // Get the default price ID. |
| 2388 | $default_price = give_form_get_default_level( $form_id ); |
| 2389 | $price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0; |
| 2390 | |
| 2391 | echo sprintf( |
| 2392 | '<input type="hidden" name="give-price-id" value="%s"/>', |
| 2393 | $price_id |
| 2394 | ); |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 ); |
| 2399 | |
| 2400 | /** |
| 2401 | * Add currency settings on donation form. |
| 2402 | * |
| 2403 | * @param array $form_html_tags |
| 2404 | * @param Give_Donate_Form $form |
| 2405 | * |
| 2406 | * @return array |
| 2407 | * @since 1.8.17 |
| 2408 | */ |
| 2409 | function __give_form_add_currency_settings( $form_html_tags, $form ) { |
| 2410 | $form_currency = give_get_currency( $form->ID ); |
| 2411 | $currency_settings = give_get_currency_formatting_settings( $form_currency ); |
| 2412 | |
| 2413 | // Check if currency exist. |
| 2414 | if ( empty( $currency_settings ) ) { |
| 2415 | return $form_html_tags; |
| 2416 | } |
| 2417 | |
| 2418 | $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency ); |
| 2419 | $form_html_tags['data-currency_code'] = $form_currency; |
| 2420 | |
| 2421 | if ( ! empty( $currency_settings ) ) { |
| 2422 | foreach ( $currency_settings as $key => $value ) { |
| 2423 | $form_html_tags[ "data-{$key}" ] = $value; |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | return $form_html_tags; |
| 2428 | } |
| 2429 | |
| 2430 | add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 ); |
| 2431 | |
| 2432 | /** |
| 2433 | * Adds classes to progress bar container. |
| 2434 | * |
| 2435 | * @param string $class_goal |
| 2436 | * |
| 2437 | * @return string |
| 2438 | * @since 2.1 |
| 2439 | */ |
| 2440 | function add_give_goal_progress_class( $class_goal ) { |
| 2441 | $class_goal = 'progress progress-striped active'; |
| 2442 | |
| 2443 | return $class_goal; |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Adds classes to progress bar span tag. |
| 2448 | * |
| 2449 | * @param string $class_bar |
| 2450 | * |
| 2451 | * @return string |
| 2452 | * @since 2.1 |
| 2453 | */ |
| 2454 | function add_give_goal_progress_bar_class( $class_bar ) { |
| 2455 | $class_bar = 'bar'; |
| 2456 | |
| 2457 | return $class_bar; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * Add a class to the form wrap on the grid page. |
| 2462 | * |
| 2463 | * @param array $class Array of form wrapper classes. |
| 2464 | * @param int $id ID of the form. |
| 2465 | * @param array $args Additional args. |
| 2466 | * |
| 2467 | * @return array |
| 2468 | * @since 2.1 |
| 2469 | */ |
| 2470 | function add_class_for_form_grid( $class, $id, $args ) { |
| 2471 | $class[] = 'give-form-grid-wrap'; |
| 2472 | |
| 2473 | foreach ( $class as $index => $item ) { |
| 2474 | if ( false !== strpos( $item, 'give-display-' ) ) { |
| 2475 | unset( $class[ $index ] ); |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | return $class; |
| 2480 | } |
| 2481 | |
| 2482 | /** |
| 2483 | * Add hidden field to Form Grid page |
| 2484 | * |
| 2485 | * @param int $form_id The form ID. |
| 2486 | * @param array $args An array of form arguments. |
| 2487 | * @param Give_Donate_Form $form Form object. |
| 2488 | * |
| 2489 | * @since 2.1 |
| 2490 | */ |
| 2491 | function give_is_form_grid_page_hidden_field( $id, $args, $form ) { |
| 2492 | echo '<input type="hidden" name="is-form-grid" value="true" />'; |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * Redirect to the same paginated URL on the Form Grid page |
| 2497 | * and adds query parameters to open the popup again after |
| 2498 | * redirection. |
| 2499 | * |
| 2500 | * @param string $redirect URL for redirection. |
| 2501 | * @param array $args Array of additional args. |
| 2502 | * |
| 2503 | * @return string |
| 2504 | * @since 2.1 |
| 2505 | */ |
| 2506 | function give_redirect_and_popup_form( $redirect, $args ) { |
| 2507 | |
| 2508 | // Check the page has Form Grid. |
| 2509 | $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : ''; |
| 2510 | |
| 2511 | if ( 'true' === $is_form_grid ) { |
| 2512 | |
| 2513 | $payment_mode = give_clean( $_POST['payment-mode'] ); |
| 2514 | $form_id = $args['form-id']; |
| 2515 | |
| 2516 | // Get the URL without Query parameters. |
| 2517 | $redirect = strtok( $redirect, '?' ); |
| 2518 | |
| 2519 | // Add query parameters 'form-id' and 'payment-mode'. |
| 2520 | $redirect = add_query_arg( |
| 2521 | [ |
| 2522 | 'form-id' => $form_id, |
| 2523 | 'payment-mode' => $payment_mode, |
| 2524 | ], |
| 2525 | $redirect |
| 2526 | ); |
| 2527 | } |
| 2528 | |
| 2529 | // Return the modified URL. |
| 2530 | return esc_url_raw( $redirect ); |
| 2531 | } |
| 2532 | |
| 2533 | add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 ); |
| 2534 |