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