template.php
1930 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Give Form Template |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Forms |
| 7 | * @copyright Copyright (c) 2016, WordImpress |
| 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 | * @since 1.0 |
| 23 | * |
| 24 | * @return string Donation form. |
| 25 | */ |
| 26 | function give_get_donation_form( $args = array() ) { |
| 27 | |
| 28 | global $post; |
| 29 | |
| 30 | $form_id = is_object( $post ) ? $post->ID : 0; |
| 31 | |
| 32 | if ( isset( $args['id'] ) ) { |
| 33 | $form_id = $args['id']; |
| 34 | } |
| 35 | |
| 36 | $defaults = apply_filters( 'give_form_args_defaults', array( |
| 37 | 'form_id' => $form_id, |
| 38 | ) ); |
| 39 | |
| 40 | $args = wp_parse_args( $args, $defaults ); |
| 41 | |
| 42 | $form = new Give_Donate_Form( $args['form_id'] ); |
| 43 | |
| 44 | //bail if no form ID. |
| 45 | if ( empty( $form->ID ) ) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | $payment_mode = give_get_chosen_gateway( $form->ID ); |
| 50 | |
| 51 | $form_action = add_query_arg( apply_filters( 'give_form_action_args', array( |
| 52 | 'payment-mode' => $payment_mode, |
| 53 | ) ), |
| 54 | give_get_current_page_url() |
| 55 | ); |
| 56 | |
| 57 | //Sanity Check: Donation form not published or user doesn't have permission to view drafts. |
| 58 | if ( |
| 59 | ( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) ) |
| 60 | || ( 'trash' === $form->post_status ) |
| 61 | ) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | //Get the form wrap CSS classes. |
| 66 | $form_wrap_classes = $form->get_form_wrap_classes( $args ); |
| 67 | |
| 68 | //Get the <form> tag wrap CSS classes. |
| 69 | $form_classes = $form->get_form_classes( $args ); |
| 70 | |
| 71 | ob_start(); |
| 72 | |
| 73 | /** |
| 74 | * Fires while outputting donation form, before the form wrapper div. |
| 75 | * |
| 76 | * @since 1.0 |
| 77 | * |
| 78 | * @param int $form_id The form ID. |
| 79 | * @param array $args An array of form arguments. |
| 80 | */ |
| 81 | do_action( 'give_pre_form_output', $form->ID, $args, $form ); |
| 82 | |
| 83 | ?> |
| 84 | <div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>"> |
| 85 | |
| 86 | <?php if ( $form->is_close_donation_form() ) { |
| 87 | |
| 88 | // Get Goal thank you message. |
| 89 | $goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true ); |
| 90 | $goal_achieved_message = ! empty( $goal_achieved_message ) ? apply_filters( 'the_content', $goal_achieved_message ) : ''; |
| 91 | |
| 92 | // Print thank you message. |
| 93 | echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form ); |
| 94 | |
| 95 | } else { |
| 96 | /** |
| 97 | * Show form title: |
| 98 | * 1. if show_title params set to true |
| 99 | * 2. if admin set form display_style to button |
| 100 | */ |
| 101 | $form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' ); |
| 102 | if ( |
| 103 | ( |
| 104 | ( isset( $args['show_title'] ) && $args['show_title'] == true ) |
| 105 | || ( 'button' === get_post_meta( $form_id, '_give_payment_display', true ) ) |
| 106 | ) |
| 107 | && ! doing_action( 'give_single_form_summary' ) |
| 108 | ) { |
| 109 | echo $form_title; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Fires while outputting donation form, before the form. |
| 114 | * |
| 115 | * @since 1.0 |
| 116 | * |
| 117 | * @param int $form_id The form ID. |
| 118 | * @param array $args An array of form arguments. |
| 119 | * @param Give_Donate_Form $form Form object. |
| 120 | */ |
| 121 | do_action( 'give_pre_form', $form->ID, $args, $form ); |
| 122 | |
| 123 | // Set form html tags. |
| 124 | $form_html_tags = array( |
| 125 | 'id' => "give-form-{$form_id}", |
| 126 | 'class' => $form_classes, |
| 127 | 'action' => esc_url_raw( $form_action ), |
| 128 | ); |
| 129 | |
| 130 | /** |
| 131 | * Filter the form html tags. |
| 132 | * |
| 133 | * @since 1.8.17 |
| 134 | * |
| 135 | * @param array $form_html_tags Array of form html tags. |
| 136 | * @param Give_Donate_Form $form Form object. |
| 137 | */ |
| 138 | $form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form ); |
| 139 | ?> |
| 140 | <form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post"> |
| 141 | |
| 142 | <!-- The following field is for robots only, invisible to humans: --> |
| 143 | <span class="give-hidden" style="display: none !important;"> |
| 144 | <label for="give-form-honeypot-<?php echo $form_id; ?>"></label> |
| 145 | <input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot" |
| 146 | class="give-honeypot give-hidden"/> |
| 147 | </span> |
| 148 | |
| 149 | <?php |
| 150 | /** |
| 151 | * Fires while outputting donation form, before all other fields. |
| 152 | * |
| 153 | * @since 1.0 |
| 154 | * |
| 155 | * @param int $form_id The form ID. |
| 156 | * @param array $args An array of form arguments. |
| 157 | * @param Give_Donate_Form $form Form object. |
| 158 | */ |
| 159 | do_action( 'give_donation_form_top', $form->ID, $args, $form ); |
| 160 | |
| 161 | /** |
| 162 | * Fires while outputting donation form, for payment gateway fields. |
| 163 | * |
| 164 | * @since 1.7 |
| 165 | * |
| 166 | * @param int $form_id The form ID. |
| 167 | * @param array $args An array of form arguments. |
| 168 | * @param Give_Donate_Form $form Form object. |
| 169 | */ |
| 170 | do_action( 'give_payment_mode_select', $form->ID, $args, $form ); |
| 171 | |
| 172 | /** |
| 173 | * Fires while outputting donation form, after all other fields. |
| 174 | * |
| 175 | * @since 1.0 |
| 176 | * |
| 177 | * @param int $form_id The form ID. |
| 178 | * @param array $args An array of form arguments. |
| 179 | * @param Give_Donate_Form $form Form object. |
| 180 | */ |
| 181 | do_action( 'give_donation_form_bottom', $form->ID, $args, $form ); |
| 182 | |
| 183 | ?> |
| 184 | </form> |
| 185 | |
| 186 | <?php |
| 187 | /** |
| 188 | * Fires while outputting donation form, after the form. |
| 189 | * |
| 190 | * @since 1.0 |
| 191 | * |
| 192 | * @param int $form_id The form ID. |
| 193 | * @param array $args An array of form arguments. |
| 194 | * @param Give_Donate_Form $form Form object. |
| 195 | */ |
| 196 | do_action( 'give_post_form', $form->ID, $args, $form ); |
| 197 | |
| 198 | } |
| 199 | ?> |
| 200 | |
| 201 | </div><!--end #give-form-<?php echo absint( $form->ID ); ?>--> |
| 202 | <?php |
| 203 | |
| 204 | /** |
| 205 | * Fires while outputting donation form, after the form wrapper div. |
| 206 | * |
| 207 | * @since 1.0 |
| 208 | * |
| 209 | * @param int $form_id The form ID. |
| 210 | * @param array $args An array of form arguments. |
| 211 | */ |
| 212 | do_action( 'give_post_form_output', $form->ID, $args ); |
| 213 | |
| 214 | $final_output = ob_get_clean(); |
| 215 | |
| 216 | echo apply_filters( 'give_donate_form', $final_output, $args ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Give Show Donation Form. |
| 221 | * |
| 222 | * Renders the Donation Form, hooks are provided to add to the checkout form. |
| 223 | * The default Donation Form rendered displays a list of the enabled payment |
| 224 | * gateways, a user registration form (if enable) and a credit card info form |
| 225 | * if credit cards are enabled. |
| 226 | * |
| 227 | * @since 1.0 |
| 228 | * |
| 229 | * @param int $form_id The form ID. |
| 230 | * |
| 231 | * @return string |
| 232 | */ |
| 233 | function give_show_purchase_form( $form_id ) { |
| 234 | |
| 235 | $payment_mode = give_get_chosen_gateway( $form_id ); |
| 236 | |
| 237 | if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) { |
| 238 | $form_id = $_POST['give_form_id']; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Fire before donation form render. |
| 243 | * |
| 244 | * @since 1.7 |
| 245 | */ |
| 246 | do_action( 'give_payment_fields_top', $form_id ); |
| 247 | |
| 248 | if ( give_can_checkout() && isset( $form_id ) ) { |
| 249 | |
| 250 | /** |
| 251 | * Fires while displaying donation form, before registration login. |
| 252 | * |
| 253 | * @since 1.7 |
| 254 | */ |
| 255 | do_action( 'give_donation_form_before_register_login', $form_id ); |
| 256 | |
| 257 | /** |
| 258 | * Fire when register/login form fields render. |
| 259 | * |
| 260 | * @since 1.7 |
| 261 | */ |
| 262 | do_action( 'give_donation_form_register_login_fields', $form_id ); |
| 263 | |
| 264 | /** |
| 265 | * Fire when credit card form fields render. |
| 266 | * |
| 267 | * @since 1.7 |
| 268 | */ |
| 269 | do_action( 'give_donation_form_before_cc_form', $form_id ); |
| 270 | |
| 271 | // Load the credit card form and allow gateways to load their own if they wish. |
| 272 | if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) { |
| 273 | /** |
| 274 | * Fires while displaying donation form, credit card form fields for a given gateway. |
| 275 | * |
| 276 | * @since 1.0 |
| 277 | * |
| 278 | * @param int $form_id The form ID. |
| 279 | */ |
| 280 | do_action( "give_{$payment_mode}_cc_form", $form_id ); |
| 281 | } else { |
| 282 | /** |
| 283 | * Fires while displaying donation form, credit card form fields. |
| 284 | * |
| 285 | * @since 1.0 |
| 286 | * |
| 287 | * @param int $form_id The form ID. |
| 288 | */ |
| 289 | do_action( 'give_cc_form', $form_id ); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Fire after credit card form fields render. |
| 294 | * |
| 295 | * @since 1.7 |
| 296 | */ |
| 297 | do_action( 'give_donation_form_after_cc_form', $form_id ); |
| 298 | |
| 299 | } else { |
| 300 | /** |
| 301 | * Fire if user can not donate. |
| 302 | * |
| 303 | * @since 1.7 |
| 304 | */ |
| 305 | do_action( 'give_donation_form_no_access', $form_id ); |
| 306 | |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Fire after donation form rendered. |
| 311 | * |
| 312 | * @since 1.7 |
| 313 | */ |
| 314 | do_action( 'give_payment_fields_bottom', $form_id ); |
| 315 | } |
| 316 | |
| 317 | add_action( 'give_donation_form', 'give_show_purchase_form' ); |
| 318 | |
| 319 | /** |
| 320 | * Give Show Login/Register Form Fields. |
| 321 | * |
| 322 | * @since 1.4.1 |
| 323 | * |
| 324 | * @param int $form_id The form ID. |
| 325 | * |
| 326 | * @return void |
| 327 | */ |
| 328 | function give_show_register_login_fields( $form_id ) { |
| 329 | |
| 330 | $show_register_form = give_show_login_register_option( $form_id ); |
| 331 | |
| 332 | if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
| 333 | ?> |
| 334 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 335 | <?php |
| 336 | /** |
| 337 | * Fire if user registration form render. |
| 338 | * |
| 339 | * @since 1.7 |
| 340 | */ |
| 341 | do_action( 'give_donation_form_register_fields', $form_id ); |
| 342 | ?> |
| 343 | </div> |
| 344 | <?php |
| 345 | elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
| 346 | ?> |
| 347 | <div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
| 348 | <?php |
| 349 | /** |
| 350 | * Fire if user login form render. |
| 351 | * |
| 352 | * @since 1.7 |
| 353 | */ |
| 354 | do_action( 'give_donation_form_login_fields', $form_id ); |
| 355 | ?> |
| 356 | </div> |
| 357 | <?php |
| 358 | endif; |
| 359 | |
| 360 | if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) { |
| 361 | /** |
| 362 | * Fire when user info render. |
| 363 | * |
| 364 | * @since 1.7 |
| 365 | */ |
| 366 | do_action( 'give_donation_form_after_user_info', $form_id ); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' ); |
| 371 | |
| 372 | /** |
| 373 | * Donation Amount Field. |
| 374 | * |
| 375 | * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount |
| 376 | * enabled the field will output as a customizable input. |
| 377 | * |
| 378 | * @since 1.0 |
| 379 | * |
| 380 | * @param int $form_id The form ID. |
| 381 | * @param array $args An array of form arguments. |
| 382 | * |
| 383 | * @return void |
| 384 | */ |
| 385 | function give_output_donation_amount_top( $form_id = 0, $args = array() ) { |
| 386 | |
| 387 | $give_options = give_get_settings(); |
| 388 | $variable_pricing = give_has_variable_prices( $form_id ); |
| 389 | $allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 390 | $currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before'; |
| 391 | $symbol = give_currency_symbol( give_get_currency( $form_id, $args ) ); |
| 392 | $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>'; |
| 393 | $default_amount = give_format_amount( give_get_default_form_amount( $form_id ), array( 'sanitize' => false, 'currency' => give_get_currency( $form_id ) ) ); |
| 394 | $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
| 395 | |
| 396 | /** |
| 397 | * Fires while displaying donation form, before donation level fields. |
| 398 | * |
| 399 | * @since 1.0 |
| 400 | * |
| 401 | * @param int $form_id The form ID. |
| 402 | * @param array $args An array of form arguments. |
| 403 | */ |
| 404 | do_action( 'give_before_donation_levels', $form_id, $args ); |
| 405 | |
| 406 | //Set Price, No Custom Amount Allowed means hidden price field |
| 407 | if ( ! give_is_setting_enabled( $allow_custom_amount ) ) { |
| 408 | ?> |
| 409 | <label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
| 410 | <input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" |
| 411 | value="<?php echo $default_amount; ?>" required aria-required="true"/> |
| 412 | <div class="set-price give-donation-amount form-row-wide"> |
| 413 | <?php if ( $currency_position == 'before' ) { |
| 414 | echo $currency_output; |
| 415 | } ?> |
| 416 | <span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span> |
| 417 | <?php if ( $currency_position == 'after' ) { |
| 418 | echo $currency_output; |
| 419 | } ?> |
| 420 | </div> |
| 421 | <?php |
| 422 | } else { |
| 423 | //Custom Amount Allowed. |
| 424 | ?> |
| 425 | <div class="give-total-wrap"> |
| 426 | <div class="give-donation-amount form-row-wide"> |
| 427 | <?php if ( $currency_position == 'before' ) { |
| 428 | echo $currency_output; |
| 429 | } ?> |
| 430 | <label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
| 431 | <input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" |
| 432 | placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off"> |
| 433 | <?php if ( $currency_position == 'after' ) { |
| 434 | echo $currency_output; |
| 435 | } ?> |
| 436 | </div> |
| 437 | </div> |
| 438 | <?php } |
| 439 | |
| 440 | /** |
| 441 | * Fires while displaying donation form, after donation amounf field(s). |
| 442 | * |
| 443 | * @since 1.0 |
| 444 | * |
| 445 | * @param int $form_id The form ID. |
| 446 | * @param array $args An array of form arguments. |
| 447 | */ |
| 448 | do_action( 'give_after_donation_amount', $form_id, $args ); |
| 449 | |
| 450 | //Custom Amount Text |
| 451 | if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { ?> |
| 452 | <p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p> |
| 453 | <?php } |
| 454 | |
| 455 | //Output Variable Pricing Levels. |
| 456 | if ( $variable_pricing ) { |
| 457 | give_output_levels( $form_id ); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Fires while displaying donation form, after donation level fields. |
| 462 | * |
| 463 | * @since 1.0 |
| 464 | * |
| 465 | * @param int $form_id The form ID. |
| 466 | * @param array $args An array of form arguments. |
| 467 | */ |
| 468 | do_action( 'give_after_donation_levels', $form_id, $args ); |
| 469 | } |
| 470 | |
| 471 | add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 ); |
| 472 | |
| 473 | /** |
| 474 | * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons. |
| 475 | * |
| 476 | * @since 1.0 |
| 477 | * |
| 478 | * @param int $form_id The form ID. |
| 479 | * |
| 480 | * @return string Donation levels. |
| 481 | */ |
| 482 | function give_output_levels( $form_id ) { |
| 483 | |
| 484 | //Get variable pricing. |
| 485 | $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
| 486 | $display_style = give_get_meta( $form_id, '_give_display_style', true ); |
| 487 | $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 488 | $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
| 489 | if ( empty( $custom_amount_text ) ) { |
| 490 | $custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' ); |
| 491 | } |
| 492 | |
| 493 | $output = ''; |
| 494 | |
| 495 | switch ( $display_style ) { |
| 496 | case 'buttons': |
| 497 | |
| 498 | $output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; |
| 499 | |
| 500 | foreach ( $prices as $price ) { |
| 501 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price ); |
| 502 | $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price ); |
| 503 | |
| 504 | $output .= '<li>'; |
| 505 | $output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">'; |
| 506 | $output .= $level_text; |
| 507 | $output .= '</button>'; |
| 508 | $output .= '</li>'; |
| 509 | |
| 510 | } |
| 511 | |
| 512 | //Custom Amount. |
| 513 | if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { |
| 514 | $output .= '<li>'; |
| 515 | $output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">'; |
| 516 | $output .= $custom_amount_text; |
| 517 | $output .= '</button>'; |
| 518 | $output .= '</li>'; |
| 519 | } |
| 520 | |
| 521 | $output .= '</ul>'; |
| 522 | |
| 523 | break; |
| 524 | |
| 525 | case 'radios': |
| 526 | |
| 527 | $output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">'; |
| 528 | |
| 529 | foreach ( $prices as $price ) { |
| 530 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price ); |
| 531 | $level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price ); |
| 532 | |
| 533 | $output .= '<li>'; |
| 534 | $output .= '<input type="radio" data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" name="give-radio-donation-level" id="give-radio-level-' . $price['_give_id']['level_id'] . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">'; |
| 535 | $output .= '<label for="give-radio-level-' . $price['_give_id']['level_id'] . '">' . $level_text . '</label>'; |
| 536 | $output .= '</li>'; |
| 537 | |
| 538 | } |
| 539 | |
| 540 | //Custom Amount. |
| 541 | if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { |
| 542 | $output .= '<li>'; |
| 543 | $output .= '<input type="radio" data-price-id="custom" class="give-radio-input give-radio-input-level give-radio-level-custom" name="give-radio-donation-level" id="give-radio-level-custom" value="custom">'; |
| 544 | $output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>'; |
| 545 | $output .= '</li>'; |
| 546 | } |
| 547 | |
| 548 | $output .= '</ul>'; |
| 549 | |
| 550 | break; |
| 551 | |
| 552 | case 'dropdown': |
| 553 | |
| 554 | $output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>'; |
| 555 | $output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">'; |
| 556 | |
| 557 | //first loop through prices. |
| 558 | foreach ( $prices as $price ) { |
| 559 | $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price ); |
| 560 | $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price ); |
| 561 | |
| 562 | $output .= '<option data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">'; |
| 563 | $output .= $level_text; |
| 564 | $output .= '</option>'; |
| 565 | |
| 566 | } |
| 567 | |
| 568 | //Custom Amount. |
| 569 | if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { |
| 570 | $output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>'; |
| 571 | } |
| 572 | |
| 573 | $output .= '</select>'; |
| 574 | |
| 575 | break; |
| 576 | } |
| 577 | |
| 578 | echo apply_filters( 'give_form_level_output', $output, $form_id ); |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Display Reveal & Lightbox Button. |
| 583 | * |
| 584 | * Outputs a button to reveal form fields. |
| 585 | * |
| 586 | * @since 1.0 |
| 587 | * |
| 588 | * @param int $form_id The form ID. |
| 589 | * @param array $args An array of form arguments. |
| 590 | * |
| 591 | * @return string Checkout button. |
| 592 | */ |
| 593 | function give_display_checkout_button( $form_id, $args ) { |
| 594 | |
| 595 | $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
| 596 | ? $args['display_style'] |
| 597 | : give_get_meta( $form_id, '_give_payment_display', true ); |
| 598 | |
| 599 | if ( 'button' === $display_option ) { |
| 600 | $display_option = 'modal'; |
| 601 | } elseif ( $display_option === 'onpage' ) { |
| 602 | return ''; |
| 603 | } |
| 604 | |
| 605 | $display_label_field = give_get_meta( $form_id, '_give_reveal_label', true ); |
| 606 | $display_label = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 607 | |
| 608 | $output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>'; |
| 609 | |
| 610 | echo apply_filters( 'give_display_checkout_button', $output ); |
| 611 | } |
| 612 | |
| 613 | add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 ); |
| 614 | |
| 615 | /** |
| 616 | * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided. |
| 617 | * |
| 618 | * @since 1.0 |
| 619 | * |
| 620 | * @param int $form_id The form ID. |
| 621 | * |
| 622 | * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation |
| 623 | * |
| 624 | * @return void |
| 625 | */ |
| 626 | function give_user_info_fields( $form_id ) { |
| 627 | // Get user info. |
| 628 | $give_user_info = _give_get_prefill_form_field_values( $form_id ); |
| 629 | |
| 630 | /** |
| 631 | * Fire before user personal information fields |
| 632 | * |
| 633 | * @since 1.7 |
| 634 | */ |
| 635 | do_action( 'give_donation_form_before_personal_info', $form_id ); |
| 636 | ?> |
| 637 | <fieldset id="give_checkout_user_info"> |
| 638 | <legend><?php echo apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ); ?></legend> |
| 639 | <p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive"> |
| 640 | <label class="give-label" for="give-first"> |
| 641 | <?php _e( 'First Name', 'give' ); ?> |
| 642 | <?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?> |
| 643 | <span class="give-required-indicator">*</span> |
| 644 | <?php endif ?> |
| 645 | <?php echo Give()->tooltips->render_help( __( 'We will use this to personalize your account experience.', 'give' ) ); ?> |
| 646 | </label> |
| 647 | <input |
| 648 | class="give-input required" |
| 649 | type="text" |
| 650 | name="give_first" |
| 651 | placeholder="<?php _e( 'First Name', 'give' ); ?>" |
| 652 | id="give-first" |
| 653 | value="<?php echo isset( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; ?>" |
| 654 | <?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 655 | /> |
| 656 | </p> |
| 657 | |
| 658 | <p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive"> |
| 659 | <label class="give-label" for="give-last"> |
| 660 | <?php _e( 'Last Name', 'give' ); ?> |
| 661 | <?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?> |
| 662 | <span class="give-required-indicator">*</span> |
| 663 | <?php endif ?> |
| 664 | <?php echo Give()->tooltips->render_help( __( 'We will use this as well to personalize your account experience.', 'give' ) ); ?> |
| 665 | </label> |
| 666 | |
| 667 | <input |
| 668 | class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>" |
| 669 | type="text" |
| 670 | name="give_last" |
| 671 | id="give-last" |
| 672 | placeholder="<?php _e( 'Last Name', 'give' ); ?>" |
| 673 | value="<?php echo isset( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; ?>" |
| 674 | <?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 675 | /> |
| 676 | </p> |
| 677 | |
| 678 | <?php |
| 679 | /** |
| 680 | * Fire before user email field |
| 681 | * |
| 682 | * @since 1.7 |
| 683 | */ |
| 684 | do_action( 'give_donation_form_before_email', $form_id ); |
| 685 | ?> |
| 686 | <p id="give-email-wrap" class="form-row form-row-wide"> |
| 687 | <label class="give-label" for="give-email"> |
| 688 | <?php _e( 'Email Address', 'give' ); ?> |
| 689 | <?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?> |
| 690 | <span class="give-required-indicator">*</span> |
| 691 | <?php } ?> |
| 692 | <?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?> |
| 693 | </label> |
| 694 | |
| 695 | <input |
| 696 | class="give-input required" |
| 697 | type="email" |
| 698 | name="give_email" |
| 699 | placeholder="<?php _e( 'Email Address', 'give' ); ?>" |
| 700 | id="give-email" |
| 701 | value="<?php echo isset( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; ?>" |
| 702 | <?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 703 | /> |
| 704 | |
| 705 | </p> |
| 706 | <?php |
| 707 | /** |
| 708 | * Fire after user email field |
| 709 | * |
| 710 | * @since 1.7 |
| 711 | */ |
| 712 | do_action( 'give_donation_form_after_email', $form_id ); |
| 713 | |
| 714 | /** |
| 715 | * Fire after personal email field |
| 716 | * |
| 717 | * @since 1.7 |
| 718 | */ |
| 719 | do_action( 'give_donation_form_user_info', $form_id ); |
| 720 | ?> |
| 721 | </fieldset> |
| 722 | <?php |
| 723 | /** |
| 724 | * Fire after user personal information fields |
| 725 | * |
| 726 | * @since 1.7 |
| 727 | */ |
| 728 | do_action( 'give_donation_form_after_personal_info', $form_id ); |
| 729 | } |
| 730 | |
| 731 | add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' ); |
| 732 | add_action( 'give_register_fields_before', 'give_user_info_fields' ); |
| 733 | |
| 734 | /** |
| 735 | * Renders the credit card info form. |
| 736 | * |
| 737 | * @since 1.0 |
| 738 | * |
| 739 | * @param int $form_id The form ID. |
| 740 | * |
| 741 | * @return void |
| 742 | */ |
| 743 | function give_get_cc_form( $form_id ) { |
| 744 | |
| 745 | ob_start(); |
| 746 | |
| 747 | /** |
| 748 | * Fires while rendering credit card info form, before the fields. |
| 749 | * |
| 750 | * @since 1.0 |
| 751 | * |
| 752 | * @param int $form_id The form ID. |
| 753 | */ |
| 754 | do_action( 'give_before_cc_fields', $form_id ); |
| 755 | ?> |
| 756 | <fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate"> |
| 757 | <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend> |
| 758 | <?php if ( is_ssl() ) : ?> |
| 759 | <div id="give_secure_site_wrapper-<?php echo $form_id ?>"> |
| 760 | <span class="give-icon padlock"></span> |
| 761 | <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span> |
| 762 | </div> |
| 763 | <?php endif; ?> |
| 764 | <p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive"> |
| 765 | <label for="card_number-<?php echo $form_id ?>" class="give-label"> |
| 766 | <?php _e( 'Card Number', 'give' ); ?> |
| 767 | <span class="give-required-indicator">*</span> |
| 768 | <?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?> |
| 769 | <span class="card-type"></span> |
| 770 | </label> |
| 771 | |
| 772 | <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>" |
| 773 | class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>" |
| 774 | required aria-required="true"/> |
| 775 | </p> |
| 776 | |
| 777 | <p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third form-row-responsive"> |
| 778 | <label for="card_cvc-<?php echo $form_id ?>" class="give-label"> |
| 779 | <?php _e( 'CVC', 'give' ); ?> |
| 780 | <span class="give-required-indicator">*</span> |
| 781 | <?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?> |
| 782 | </label> |
| 783 | |
| 784 | <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>" |
| 785 | class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>" |
| 786 | required aria-required="true"/> |
| 787 | </p> |
| 788 | |
| 789 | <p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive"> |
| 790 | <label for="card_name-<?php echo $form_id ?>" class="give-label"> |
| 791 | <?php _e( 'Name on the Card', 'give' ); ?> |
| 792 | <span class="give-required-indicator">*</span> |
| 793 | <?php echo Give()->tooltips->render_help( __( 'The name printed on the front of your credit card.', 'give' ) ); ?> |
| 794 | </label> |
| 795 | |
| 796 | <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>" |
| 797 | class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>" |
| 798 | required aria-required="true"/> |
| 799 | </p> |
| 800 | <?php |
| 801 | /** |
| 802 | * Fires while rendering credit card info form, before expiration fields. |
| 803 | * |
| 804 | * @since 1.0 |
| 805 | * |
| 806 | * @param int $form_id The form ID. |
| 807 | */ |
| 808 | do_action( 'give_before_cc_expiration' ); |
| 809 | ?> |
| 810 | <p class="card-expiration form-row form-row-one-third form-row-responsive"> |
| 811 | <label for="card_expiry-<?php echo $form_id ?>" class="give-label"> |
| 812 | <?php _e( 'Expiration', 'give' ); ?> |
| 813 | <span class="give-required-indicator">*</span> |
| 814 | <?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?> |
| 815 | </label> |
| 816 | |
| 817 | <input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/> |
| 818 | <input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/> |
| 819 | |
| 820 | <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>" required aria-required="true"/> |
| 821 | </p> |
| 822 | <?php |
| 823 | /** |
| 824 | * Fires while rendering credit card info form, after expiration fields. |
| 825 | * |
| 826 | * @since 1.0 |
| 827 | * |
| 828 | * @param int $form_id The form ID. |
| 829 | */ |
| 830 | do_action( 'give_after_cc_expiration', $form_id ); |
| 831 | ?> |
| 832 | </fieldset> |
| 833 | <?php |
| 834 | /** |
| 835 | * Fires while rendering credit card info form, before the fields. |
| 836 | * |
| 837 | * @since 1.0 |
| 838 | * |
| 839 | * @param int $form_id The form ID. |
| 840 | */ |
| 841 | do_action( 'give_after_cc_fields', $form_id ); |
| 842 | |
| 843 | echo ob_get_clean(); |
| 844 | } |
| 845 | |
| 846 | add_action( 'give_cc_form', 'give_get_cc_form' ); |
| 847 | |
| 848 | /** |
| 849 | * Outputs the default credit card address fields. |
| 850 | * |
| 851 | * @since 1.0 |
| 852 | * |
| 853 | * @param int $form_id The form ID. |
| 854 | * |
| 855 | * @return void |
| 856 | */ |
| 857 | function give_default_cc_address_fields( $form_id ) { |
| 858 | // Get user info. |
| 859 | $give_user_info = _give_get_prefill_form_field_values( $form_id ); |
| 860 | |
| 861 | $logged_in = is_user_logged_in(); |
| 862 | |
| 863 | if ( $logged_in ) { |
| 864 | $user_address = give_get_donor_address( get_current_user_id() ); |
| 865 | } |
| 866 | |
| 867 | ob_start(); |
| 868 | ?> |
| 869 | <fieldset id="give_cc_address" class="cc-address"> |
| 870 | <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend> |
| 871 | <?php |
| 872 | /** |
| 873 | * Fires while rendering credit card billing form, before address fields. |
| 874 | * |
| 875 | * @since 1.0 |
| 876 | * |
| 877 | * @param int $form_id The form ID. |
| 878 | */ |
| 879 | do_action( 'give_cc_billing_top' ); |
| 880 | |
| 881 | // For Country. |
| 882 | $selected_country = give_get_country(); |
| 883 | if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
| 884 | $selected_country = $give_user_info['billing_country']; |
| 885 | } |
| 886 | $countries = give_get_country_list(); |
| 887 | |
| 888 | // For state |
| 889 | $selected_state = ''; |
| 890 | if ( $selected_country === give_get_country() ) { |
| 891 | // Get defalut selected state by admin. |
| 892 | $selected_state = give_get_state(); |
| 893 | } |
| 894 | // Get the last payment made by user states. |
| 895 | if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) { |
| 896 | $selected_state = $give_user_info['card_state']; |
| 897 | } |
| 898 | // Get the country code |
| 899 | if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
| 900 | $selected_country = $give_user_info['billing_country']; |
| 901 | } |
| 902 | $label = __( 'State', 'give' ); |
| 903 | $states_label = give_get_states_label(); |
| 904 | // Check if $country code exists in the array key for states label. |
| 905 | if ( array_key_exists( $selected_country, $states_label ) ) { |
| 906 | $label = $states_label[ $selected_country ]; |
| 907 | } |
| 908 | $states = give_get_states( $selected_country ); |
| 909 | // Get the country list that do not have any states init. |
| 910 | $no_states_country = give_no_states_country_list(); |
| 911 | // Get the country list that does not require states. |
| 912 | $states_not_required_country_list = give_states_not_required_country_list(); |
| 913 | ?> |
| 914 | <p id="give-card-country-wrap" class="form-row form-row-wide"> |
| 915 | <label for="billing_country" class="give-label"> |
| 916 | <?php esc_html_e( 'Country', 'give' ); ?> |
| 917 | <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?> |
| 918 | <span class="give-required-indicator">*</span> |
| 919 | <?php endif; ?> |
| 920 | <span class="give-tooltip give-icon give-icon-question" |
| 921 | data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span> |
| 922 | </label> |
| 923 | |
| 924 | <select |
| 925 | name="billing_country" |
| 926 | id="billing_country" |
| 927 | class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>" |
| 928 | <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 929 | > |
| 930 | <?php |
| 931 | foreach ( $countries as $country_code => $country ) { |
| 932 | echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
| 933 | } |
| 934 | ?> |
| 935 | </select> |
| 936 | </p> |
| 937 | |
| 938 | <p id="give-card-address-wrap" class="form-row form-row-wide"> |
| 939 | <label for="card_address" class="give-label"> |
| 940 | <?php _e( 'Address 1', 'give' ); ?> |
| 941 | <?php |
| 942 | if ( give_field_is_required( 'card_address', $form_id ) ) : ?> |
| 943 | <span class="give-required-indicator">*</span> |
| 944 | <?php endif; ?> |
| 945 | <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?> |
| 946 | </label> |
| 947 | |
| 948 | <input |
| 949 | type="text" |
| 950 | id="card_address" |
| 951 | name="card_address" |
| 952 | class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>" |
| 953 | placeholder="<?php _e( 'Address line 1', 'give' ); ?>" |
| 954 | value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>" |
| 955 | <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 956 | /> |
| 957 | </p> |
| 958 | |
| 959 | <p id="give-card-address-2-wrap" class="form-row form-row-wide"> |
| 960 | <label for="card_address_2" class="give-label"> |
| 961 | <?php _e( 'Address 2', 'give' ); ?> |
| 962 | <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?> |
| 963 | <span class="give-required-indicator">*</span> |
| 964 | <?php endif; ?> |
| 965 | <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?> |
| 966 | </label> |
| 967 | |
| 968 | <input |
| 969 | type="text" |
| 970 | id="card_address_2" |
| 971 | name="card_address_2" |
| 972 | class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>" |
| 973 | placeholder="<?php _e( 'Address line 2', 'give' ); ?>" |
| 974 | value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>" |
| 975 | <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 976 | /> |
| 977 | </p> |
| 978 | |
| 979 | <p id="give-card-city-wrap" class="form-row form-row-wide"> |
| 980 | <label for="card_city" class="give-label"> |
| 981 | <?php _e( 'City', 'give' ); ?> |
| 982 | <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?> |
| 983 | <span class="give-required-indicator">*</span> |
| 984 | <?php endif; ?> |
| 985 | <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?> |
| 986 | </label> |
| 987 | <input |
| 988 | type="text" |
| 989 | id="card_city" |
| 990 | name="card_city" |
| 991 | class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>" |
| 992 | placeholder="<?php _e( 'City', 'give' ); ?>" |
| 993 | value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>" |
| 994 | <?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 995 | /> |
| 996 | </p> |
| 997 | |
| 998 | <p id="give-card-state-wrap" |
| 999 | class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?> "> |
| 1000 | <label for="card_state" class="give-label"> |
| 1001 | <span class="state-label-text"><?php echo $label; ?></span> |
| 1002 | <?php if ( give_field_is_required( 'card_state', $form_id ) ) : |
| 1003 | ?> |
| 1004 | <span class="give-required-indicator <?php echo( array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : '' ) ?> ">*</span> |
| 1005 | <?php endif; ?> |
| 1006 | <span class="give-tooltip give-icon give-icon-question" |
| 1007 | data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span> |
| 1008 | </label> |
| 1009 | <?php |
| 1010 | |
| 1011 | if ( ! empty( $states ) ) : ?> |
| 1012 | <select |
| 1013 | name="card_state" |
| 1014 | id="card_state" |
| 1015 | class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>" |
| 1016 | <?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>> |
| 1017 | <?php |
| 1018 | foreach ( $states as $state_code => $state ) { |
| 1019 | echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
| 1020 | } |
| 1021 | ?> |
| 1022 | </select> |
| 1023 | <?php else : ?> |
| 1024 | <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" |
| 1025 | placeholder="<?php echo $label; ?>" value="<?php echo $selected_state; ?>"/> |
| 1026 | <?php endif; ?> |
| 1027 | </p> |
| 1028 | |
| 1029 | <p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive"> |
| 1030 | <label for="card_zip" class="give-label"> |
| 1031 | <?php _e( 'Zip / Postal Code', 'give' ); ?> |
| 1032 | <?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?> |
| 1033 | <span class="give-required-indicator">*</span> |
| 1034 | <?php endif; ?> |
| 1035 | <?php echo Give()->tooltips->render_help( __( 'The ZIP Code or postal code for your billing address.', 'give' ) ); ?> |
| 1036 | </label> |
| 1037 | |
| 1038 | <input |
| 1039 | type="text" |
| 1040 | size="4" |
| 1041 | id="card_zip" |
| 1042 | name="card_zip" |
| 1043 | class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>" |
| 1044 | placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>" |
| 1045 | value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>" |
| 1046 | <?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
| 1047 | /> |
| 1048 | </p> |
| 1049 | <?php |
| 1050 | /** |
| 1051 | * Fires while rendering credit card billing form, after address fields. |
| 1052 | * |
| 1053 | * @since 1.0 |
| 1054 | * |
| 1055 | * @param int $form_id The form ID. |
| 1056 | */ |
| 1057 | do_action( 'give_cc_billing_bottom' ); |
| 1058 | ?> |
| 1059 | </fieldset> |
| 1060 | <?php |
| 1061 | echo ob_get_clean(); |
| 1062 | } |
| 1063 | |
| 1064 | add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
| 1065 | |
| 1066 | |
| 1067 | /** |
| 1068 | * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form |
| 1069 | * is provided for the user to create an account. |
| 1070 | * |
| 1071 | * @since 1.0 |
| 1072 | * |
| 1073 | * @param int $form_id The form ID. |
| 1074 | * |
| 1075 | * @return string |
| 1076 | */ |
| 1077 | function give_get_register_fields( $form_id ) { |
| 1078 | |
| 1079 | global $user_ID; |
| 1080 | |
| 1081 | if ( is_user_logged_in() ) { |
| 1082 | $user_data = get_userdata( $user_ID ); |
| 1083 | } |
| 1084 | |
| 1085 | $show_register_form = give_show_login_register_option( $form_id ); |
| 1086 | |
| 1087 | ob_start(); ?> |
| 1088 | <fieldset id="give-register-fields-<?php echo $form_id; ?>"> |
| 1089 | |
| 1090 | <?php |
| 1091 | /** |
| 1092 | * Fires while rendering user registration form, before registration fields. |
| 1093 | * |
| 1094 | * @since 1.0 |
| 1095 | * |
| 1096 | * @param int $form_id The form ID. |
| 1097 | */ |
| 1098 | do_action( 'give_register_fields_before', $form_id ); |
| 1099 | ?> |
| 1100 | |
| 1101 | <fieldset id="give-register-account-fields-<?php echo $form_id; ?>"> |
| 1102 | <?php |
| 1103 | /** |
| 1104 | * Fires while rendering user registration form, before account fields. |
| 1105 | * |
| 1106 | * @since 1.0 |
| 1107 | * |
| 1108 | * @param int $form_id The form ID. |
| 1109 | */ |
| 1110 | do_action( 'give_register_account_fields_before', $form_id ); |
| 1111 | ?> |
| 1112 | <div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive"> |
| 1113 | <label for="give-create-account-<?php echo $form_id; ?>"> |
| 1114 | <?php |
| 1115 | // Add attributes to checkbox, if Guest Checkout is disabled. |
| 1116 | $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true ); |
| 1117 | $id = 'give-create-account-' . $form_id; |
| 1118 | if ( ! give_is_setting_enabled( $is_guest_checkout ) ) { |
| 1119 | echo Give()->tooltips->render( |
| 1120 | array( |
| 1121 | 'tag_content' => sprintf( |
| 1122 | '<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />', |
| 1123 | $id |
| 1124 | ), |
| 1125 | 'label' => __( 'Registration is required to donate.', 'give' ), |
| 1126 | ) ); |
| 1127 | } else { |
| 1128 | ?> |
| 1129 | <input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>" class="give-input" /> |
| 1130 | <?php |
| 1131 | } |
| 1132 | ?> |
| 1133 | <?php _e( 'Create an account', 'give' ); ?> |
| 1134 | <?php echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) ); ?> |
| 1135 | </label> |
| 1136 | </div> |
| 1137 | |
| 1138 | <?php if ( 'both' === $show_register_form ) { ?> |
| 1139 | <div class="give-login-account-wrap form-row form-row-last form-row-responsive"> |
| 1140 | <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?> |
| 1141 | <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login" |
| 1142 | data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a> |
| 1143 | </p> |
| 1144 | <p class="give-loading-text"> |
| 1145 | <span class="give-loading-animation"></span> |
| 1146 | </p> |
| 1147 | </div> |
| 1148 | <?php } ?> |
| 1149 | |
| 1150 | <?php |
| 1151 | /** |
| 1152 | * Fires while rendering user registration form, after account fields. |
| 1153 | * |
| 1154 | * @since 1.0 |
| 1155 | * |
| 1156 | * @param int $form_id The form ID. |
| 1157 | */ |
| 1158 | do_action( 'give_register_account_fields_after', $form_id ); |
| 1159 | ?> |
| 1160 | </fieldset> |
| 1161 | |
| 1162 | <?php |
| 1163 | /** |
| 1164 | * Fires while rendering user registration form, after registration fields. |
| 1165 | * |
| 1166 | * @since 1.0 |
| 1167 | * |
| 1168 | * @param int $form_id The form ID. |
| 1169 | */ |
| 1170 | do_action( 'give_register_fields_after', $form_id ); |
| 1171 | ?> |
| 1172 | |
| 1173 | <input type="hidden" name="give-purchase-var" value="needs-to-register"/> |
| 1174 | |
| 1175 | <?php |
| 1176 | /** |
| 1177 | * Fire after register or login form render |
| 1178 | * |
| 1179 | * @since 1.7 |
| 1180 | */ |
| 1181 | do_action( 'give_donation_form_user_info', $form_id ); |
| 1182 | ?> |
| 1183 | |
| 1184 | </fieldset> |
| 1185 | <?php |
| 1186 | echo ob_get_clean(); |
| 1187 | } |
| 1188 | |
| 1189 | add_action( 'give_donation_form_register_fields', 'give_get_register_fields' ); |
| 1190 | |
| 1191 | /** |
| 1192 | * Gets the login fields for the login form on the checkout. This function hooks |
| 1193 | * on the give_donation_form_login_fields to display the login form if a user already |
| 1194 | * had an account. |
| 1195 | * |
| 1196 | * @since 1.0 |
| 1197 | * |
| 1198 | * @param int $form_id The form ID. |
| 1199 | * |
| 1200 | * @return string |
| 1201 | */ |
| 1202 | function give_get_login_fields( $form_id ) { |
| 1203 | |
| 1204 | $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id; |
| 1205 | $show_register_form = give_show_login_register_option( $form_id ); |
| 1206 | |
| 1207 | ob_start(); |
| 1208 | ?> |
| 1209 | <fieldset id="give-login-fields-<?php echo $form_id; ?>"> |
| 1210 | <legend><?php echo apply_filters( 'give_account_login_fieldset_heading', __( 'Login to Your Account', 'give' ) ); |
| 1211 | if ( ! give_logged_in_only( $form_id ) ) { |
| 1212 | echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>'; |
| 1213 | } ?> |
| 1214 | </legend> |
| 1215 | <?php if ( $show_register_form == 'both' ) { ?> |
| 1216 | <p class="give-new-account-link"> |
| 1217 | <?php _e( 'Need to create an account?', 'give' ); ?> |
| 1218 | <a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel" |
| 1219 | data-action="give_checkout_register"> |
| 1220 | <?php _e( 'Register', 'give' ); |
| 1221 | if ( ! give_logged_in_only( $form_id ) ) { |
| 1222 | echo ' ' . __( 'and donate as a guest »', 'give' ); |
| 1223 | } ?> |
| 1224 | </a> |
| 1225 | </p> |
| 1226 | <p class="give-loading-text"> |
| 1227 | <span class="give-loading-animation"></span> |
| 1228 | </p> |
| 1229 | <?php } ?> |
| 1230 | <?php |
| 1231 | /** |
| 1232 | * Fires while rendering checkout login form, before the fields. |
| 1233 | * |
| 1234 | * @since 1.0 |
| 1235 | * |
| 1236 | * @param int $form_id The form ID. |
| 1237 | */ |
| 1238 | do_action( 'give_checkout_login_fields_before', $form_id ); |
| 1239 | ?> |
| 1240 | <div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive"> |
| 1241 | <label class="give-label" for="give-user-login-<?php echo $form_id; ?>"> |
| 1242 | <?php _e( 'Username', 'give' ); ?> |
| 1243 | <?php if ( give_logged_in_only( $form_id ) ) { ?> |
| 1244 | <span class="give-required-indicator">*</span> |
| 1245 | <?php } ?> |
| 1246 | </label> |
| 1247 | |
| 1248 | <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text" |
| 1249 | name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" |
| 1250 | placeholder="<?php _e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
| 1251 | </div> |
| 1252 | |
| 1253 | <div id="give-user-pass-wrap-<?php echo $form_id; ?>" |
| 1254 | class="give_login_password form-row form-row-last form-row-responsive"> |
| 1255 | <label class="give-label" for="give-user-pass-<?php echo $form_id; ?>"> |
| 1256 | <?php _e( 'Password', 'give' ); ?> |
| 1257 | <?php if ( give_logged_in_only( $form_id ) ) { ?> |
| 1258 | <span class="give-required-indicator">*</span> |
| 1259 | <?php } ?> |
| 1260 | </label> |
| 1261 | <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" |
| 1262 | type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" |
| 1263 | placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
| 1264 | <input type="hidden" name="give-purchase-var" value="needs-to-login"/> |
| 1265 | </div> |
| 1266 | |
| 1267 | <div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password"> |
| 1268 | <span class="give-forgot-password "> |
| 1269 | <a href="<?php echo wp_lostpassword_url() ?>" |
| 1270 | target="_blank"><?php _e( 'Reset Password', 'give' ) ?></a> |
| 1271 | </span> |
| 1272 | </div> |
| 1273 | |
| 1274 | <div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix"> |
| 1275 | <input type="submit" class="give-submit give-btn button" name="give_login_submit" |
| 1276 | value="<?php _e( 'Login', 'give' ); ?>"/> |
| 1277 | <?php if ( $show_register_form !== 'login' ) { ?> |
| 1278 | <input type="button" data-action="give_cancel_login" |
| 1279 | class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel" |
| 1280 | value="<?php _e( 'Cancel', 'give' ); ?>"/> |
| 1281 | <?php } ?> |
| 1282 | <span class="give-loading-animation"></span> |
| 1283 | </div> |
| 1284 | <?php |
| 1285 | /** |
| 1286 | * Fires while rendering checkout login form, after the fields. |
| 1287 | * |
| 1288 | * @since 1.0 |
| 1289 | * |
| 1290 | * @param int $form_id The form ID. |
| 1291 | */ |
| 1292 | do_action( 'give_checkout_login_fields_after', $form_id ); |
| 1293 | ?> |
| 1294 | </fieldset><!--end #give-login-fields--> |
| 1295 | <?php |
| 1296 | echo ob_get_clean(); |
| 1297 | } |
| 1298 | |
| 1299 | add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 ); |
| 1300 | |
| 1301 | /** |
| 1302 | * Payment Mode Select. |
| 1303 | * |
| 1304 | * Renders the payment mode form by getting all the enabled payment gateways and |
| 1305 | * outputting them as radio buttons for the user to choose the payment gateway. If |
| 1306 | * a default payment gateway has been chosen from the Give Settings, it will be |
| 1307 | * automatically selected. |
| 1308 | * |
| 1309 | * @since 1.0 |
| 1310 | * |
| 1311 | * @param int $form_id The form ID. |
| 1312 | * |
| 1313 | * @return void |
| 1314 | */ |
| 1315 | function give_payment_mode_select( $form_id ) { |
| 1316 | |
| 1317 | $gateways = give_get_enabled_payment_gateways( $form_id ); |
| 1318 | |
| 1319 | /** |
| 1320 | * Fires while selecting payment gateways, before the fields. |
| 1321 | * |
| 1322 | * @since 1.7 |
| 1323 | * |
| 1324 | * @param int $form_id The form ID. |
| 1325 | */ |
| 1326 | do_action( 'give_payment_mode_top', $form_id ); |
| 1327 | ?> |
| 1328 | |
| 1329 | <fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) { |
| 1330 | echo 'style="display: none;"'; |
| 1331 | } ?>> |
| 1332 | <?php |
| 1333 | /** |
| 1334 | * Fires while selecting payment gateways, before the wrap div. |
| 1335 | * |
| 1336 | * @since 1.7 |
| 1337 | * |
| 1338 | * @param int $form_id The form ID. |
| 1339 | */ |
| 1340 | do_action( 'give_payment_mode_before_gateways_wrap' ); |
| 1341 | ?> |
| 1342 | <legend |
| 1343 | class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?> |
| 1344 | <span class="give-loading-text"><span |
| 1345 | class="give-loading-animation"></span> |
| 1346 | </span> |
| 1347 | </legend> |
| 1348 | |
| 1349 | <div id="give-payment-mode-wrap"> |
| 1350 | <?php |
| 1351 | /** |
| 1352 | * Fires while selecting payment gateways, befire the gateways list. |
| 1353 | * |
| 1354 | * @since 1.7 |
| 1355 | */ |
| 1356 | do_action( 'give_payment_mode_before_gateways' ) |
| 1357 | ?> |
| 1358 | <ul id="give-gateway-radio-list"> |
| 1359 | <?php |
| 1360 | /** |
| 1361 | * Loop through the active payment gateways. |
| 1362 | */ |
| 1363 | $selected_gateway = give_get_chosen_gateway( $form_id ); |
| 1364 | |
| 1365 | foreach ( $gateways as $gateway_id => $gateway ) : |
| 1366 | //Determine the default gateway. |
| 1367 | $checked = checked( $gateway_id, $selected_gateway, false ); |
| 1368 | $checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?> |
| 1369 | <li<?php echo $checked_class ?>> |
| 1370 | <input type="radio" name="payment-mode" class="give-gateway" |
| 1371 | id="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>" |
| 1372 | value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>> |
| 1373 | <label for="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>" |
| 1374 | class="give-gateway-option" |
| 1375 | id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
| 1376 | </li> |
| 1377 | <?php |
| 1378 | endforeach; |
| 1379 | ?> |
| 1380 | </ul> |
| 1381 | <?php |
| 1382 | /** |
| 1383 | * Fires while selecting payment gateways, before the gateways list. |
| 1384 | * |
| 1385 | * @since 1.7 |
| 1386 | */ |
| 1387 | do_action( 'give_payment_mode_after_gateways' ); |
| 1388 | ?> |
| 1389 | </div> |
| 1390 | <?php |
| 1391 | /** |
| 1392 | * Fires while selecting payment gateways, after the wrap div. |
| 1393 | * |
| 1394 | * @since 1.7 |
| 1395 | * |
| 1396 | * @param int $form_id The form ID. |
| 1397 | */ |
| 1398 | do_action( 'give_payment_mode_after_gateways_wrap' ); |
| 1399 | ?> |
| 1400 | </fieldset> |
| 1401 | |
| 1402 | <?php |
| 1403 | /** |
| 1404 | * Fires while selecting payment gateways, after the fields. |
| 1405 | * |
| 1406 | * @since 1.7 |
| 1407 | * |
| 1408 | * @param int $form_id The form ID. |
| 1409 | */ |
| 1410 | do_action( 'give_payment_mode_bottom', $form_id ); |
| 1411 | ?> |
| 1412 | |
| 1413 | <div id="give_purchase_form_wrap"> |
| 1414 | |
| 1415 | <?php |
| 1416 | /** |
| 1417 | * Fire after payment field render. |
| 1418 | * |
| 1419 | * @since 1.7 |
| 1420 | */ |
| 1421 | do_action( 'give_donation_form', $form_id ); |
| 1422 | ?> |
| 1423 | |
| 1424 | </div> |
| 1425 | |
| 1426 | <?php |
| 1427 | /** |
| 1428 | * Fire after donation form render. |
| 1429 | * |
| 1430 | * @since 1.7 |
| 1431 | */ |
| 1432 | do_action( 'give_donation_form_wrap_bottom', $form_id ); |
| 1433 | } |
| 1434 | |
| 1435 | add_action( 'give_payment_mode_select', 'give_payment_mode_select' ); |
| 1436 | |
| 1437 | /** |
| 1438 | * Renders the Checkout Agree to Terms, this displays a checkbox for users to |
| 1439 | * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are |
| 1440 | * set in the Give Settings. |
| 1441 | * |
| 1442 | * @since 1.0 |
| 1443 | * |
| 1444 | * @param int $form_id The form ID. |
| 1445 | * |
| 1446 | * @return bool |
| 1447 | */ |
| 1448 | function give_terms_agreement( $form_id ) { |
| 1449 | $form_option = give_get_meta( $form_id, '_give_terms_option', true ); |
| 1450 | |
| 1451 | // Bailout if per form and global term and conditions is not setup. |
| 1452 | if ( |
| 1453 | give_is_setting_enabled( $form_option, 'global' ) |
| 1454 | && give_is_setting_enabled( give_get_option( 'terms' ) ) |
| 1455 | ) { |
| 1456 | $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) ); |
| 1457 | $terms = $terms = give_get_option( 'agreement_text', '' ); |
| 1458 | $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display§ion=term-and-conditions' ); |
| 1459 | |
| 1460 | } elseif ( give_is_setting_enabled( $form_option ) ) { |
| 1461 | $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' ); |
| 1462 | $terms = give_get_meta( $form_id, '_give_agree_text', true ); |
| 1463 | $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' ); |
| 1464 | |
| 1465 | } else { |
| 1466 | return false; |
| 1467 | } |
| 1468 | |
| 1469 | // Bailout: Check if term and conditions text is empty or not. |
| 1470 | if ( empty( $terms ) ) { |
| 1471 | if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) { |
| 1472 | echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url ); |
| 1473 | } |
| 1474 | |
| 1475 | return false; |
| 1476 | } |
| 1477 | |
| 1478 | ?> |
| 1479 | <fieldset id="give_terms_agreement"> |
| 1480 | <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend> |
| 1481 | <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;"> |
| 1482 | <?php |
| 1483 | /** |
| 1484 | * Fires while rendering terms of agreement, before the fields. |
| 1485 | * |
| 1486 | * @since 1.0 |
| 1487 | */ |
| 1488 | do_action( 'give_before_terms' ); |
| 1489 | |
| 1490 | echo wpautop( stripslashes( $terms ) ); |
| 1491 | /** |
| 1492 | * Fires while rendering terms of agreement, after the fields. |
| 1493 | * |
| 1494 | * @since 1.0 |
| 1495 | */ |
| 1496 | do_action( 'give_after_terms' ); |
| 1497 | ?> |
| 1498 | </div> |
| 1499 | <div id="give_show_terms"> |
| 1500 | <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1501 | aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a> |
| 1502 | <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1503 | aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a> |
| 1504 | </div> |
| 1505 | |
| 1506 | <input name="give_agree_to_terms" class="required" type="checkbox" |
| 1507 | id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/> |
| 1508 | <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label> |
| 1509 | |
| 1510 | </fieldset> |
| 1511 | <?php |
| 1512 | } |
| 1513 | |
| 1514 | add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 ); |
| 1515 | |
| 1516 | /** |
| 1517 | * Checkout Final Total. |
| 1518 | * |
| 1519 | * Shows the final donation total at the bottom of the checkout page. |
| 1520 | * |
| 1521 | * @since 1.0 |
| 1522 | * |
| 1523 | * @param int $form_id The form ID. |
| 1524 | * |
| 1525 | * @return void |
| 1526 | */ |
| 1527 | function give_checkout_final_total( $form_id ) { |
| 1528 | |
| 1529 | $total = isset( $_POST['give_total'] ) ? |
| 1530 | apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) : |
| 1531 | give_get_default_form_amount( $form_id ); |
| 1532 | |
| 1533 | |
| 1534 | // Only proceed if give_total available. |
| 1535 | if ( empty( $total ) ) { |
| 1536 | return; |
| 1537 | } |
| 1538 | ?> |
| 1539 | <p id="give-final-total-wrap" class="form-wrap "> |
| 1540 | <span class="give-donation-total-label"> |
| 1541 | <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?> |
| 1542 | </span> |
| 1543 | <span class="give-final-total-amount" |
| 1544 | data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>"> |
| 1545 | <?php echo give_currency_filter( give_format_amount( $total, array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ); ?> |
| 1546 | </span> |
| 1547 | </p> |
| 1548 | <?php |
| 1549 | } |
| 1550 | |
| 1551 | add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 ); |
| 1552 | |
| 1553 | /** |
| 1554 | * Renders the Checkout Submit section. |
| 1555 | * |
| 1556 | * @since 1.0 |
| 1557 | * |
| 1558 | * @param int $form_id The form ID. |
| 1559 | * |
| 1560 | * @return void |
| 1561 | */ |
| 1562 | function give_checkout_submit( $form_id ) { |
| 1563 | ?> |
| 1564 | <fieldset id="give_purchase_submit"> |
| 1565 | <?php |
| 1566 | /** |
| 1567 | * Fire before donation form submit. |
| 1568 | * |
| 1569 | * @since 1.7 |
| 1570 | */ |
| 1571 | do_action( 'give_donation_form_before_submit', $form_id ); |
| 1572 | |
| 1573 | give_checkout_hidden_fields( $form_id ); |
| 1574 | |
| 1575 | echo give_get_donation_form_submit_button( $form_id ); |
| 1576 | |
| 1577 | /** |
| 1578 | * Fire after donation form submit. |
| 1579 | * |
| 1580 | * @since 1.7 |
| 1581 | */ |
| 1582 | do_action( 'give_donation_form_after_submit', $form_id ); |
| 1583 | ?> |
| 1584 | </fieldset> |
| 1585 | <?php |
| 1586 | } |
| 1587 | |
| 1588 | add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 ); |
| 1589 | |
| 1590 | /** |
| 1591 | * Give Donation form submit button. |
| 1592 | * |
| 1593 | * @since 1.8.8 |
| 1594 | * |
| 1595 | * @param int $form_id The form ID. |
| 1596 | * |
| 1597 | * @return string |
| 1598 | */ |
| 1599 | function give_get_donation_form_submit_button( $form_id ) { |
| 1600 | |
| 1601 | $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true ); |
| 1602 | $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 1603 | ob_start(); |
| 1604 | ?> |
| 1605 | <div class="give-submit-button-wrap give-clearfix"> |
| 1606 | <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" |
| 1607 | value="<?php echo $display_label; ?>"/> |
| 1608 | <span class="give-loading-animation"></span> |
| 1609 | </div> |
| 1610 | <?php |
| 1611 | return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id ); |
| 1612 | } |
| 1613 | |
| 1614 | /** |
| 1615 | * Show Give Goals. |
| 1616 | * |
| 1617 | * @since 1.0 |
| 1618 | * @since 1.6 Add template for Give Goals Shortcode. |
| 1619 | * More info is on https://github.com/WordImpress/Give/issues/411 |
| 1620 | * |
| 1621 | * @param int $form_id The form ID. |
| 1622 | * @param array $args An array of form arguments. |
| 1623 | * |
| 1624 | * @return mixed |
| 1625 | */ |
| 1626 | function give_show_goal_progress( $form_id, $args ) { |
| 1627 | |
| 1628 | ob_start(); |
| 1629 | give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) ); |
| 1630 | |
| 1631 | /** |
| 1632 | * Filter progress bar output |
| 1633 | * |
| 1634 | * @since 2.0 |
| 1635 | */ |
| 1636 | echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args ); |
| 1637 | |
| 1638 | return true; |
| 1639 | } |
| 1640 | |
| 1641 | add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
| 1642 | |
| 1643 | |
| 1644 | /** |
| 1645 | * Get form content position. |
| 1646 | * |
| 1647 | * @since 1.8 |
| 1648 | * |
| 1649 | * @param $form_id |
| 1650 | * @param $args |
| 1651 | * |
| 1652 | * @return mixed|string |
| 1653 | */ |
| 1654 | function give_get_form_content_placement( $form_id, $args ) { |
| 1655 | $show_content = ''; |
| 1656 | |
| 1657 | if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) { |
| 1658 | // Content positions. |
| 1659 | $content_placement = array( |
| 1660 | 'above' => 'give_pre_form', |
| 1661 | 'below' => 'give_post_form', |
| 1662 | ); |
| 1663 | |
| 1664 | // Check if content position already decoded. |
| 1665 | if ( in_array( $args['show_content'], $content_placement ) ) { |
| 1666 | return $args['show_content']; |
| 1667 | } |
| 1668 | |
| 1669 | $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' ); |
| 1670 | |
| 1671 | } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) { |
| 1672 | $show_content = give_get_meta( $form_id, '_give_content_placement', true ); |
| 1673 | |
| 1674 | } elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) { |
| 1675 | // Backward compatibility for _give_content_option for v18. |
| 1676 | $show_content = give_get_meta( $form_id, '_give_content_option', true ); |
| 1677 | } |
| 1678 | |
| 1679 | return $show_content; |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | * Adds Actions to Render Form Content. |
| 1684 | * |
| 1685 | * @since 1.0 |
| 1686 | * |
| 1687 | * @param int $form_id The form ID. |
| 1688 | * @param array $args An array of form arguments. |
| 1689 | * |
| 1690 | * @return void|bool |
| 1691 | */ |
| 1692 | function give_form_content( $form_id, $args ) { |
| 1693 | |
| 1694 | $show_content = give_get_form_content_placement( $form_id, $args ); |
| 1695 | |
| 1696 | // Bailout. |
| 1697 | if ( empty( $show_content ) ) { |
| 1698 | return false; |
| 1699 | } |
| 1700 | |
| 1701 | // Add action according to value. |
| 1702 | add_action( $show_content, 'give_form_display_content', 10, 2 ); |
| 1703 | } |
| 1704 | |
| 1705 | add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
| 1706 | |
| 1707 | /** |
| 1708 | * Renders Post Form Content. |
| 1709 | * |
| 1710 | * Displays content for Give forms; fired by action from give_form_content. |
| 1711 | * |
| 1712 | * @since 1.0 |
| 1713 | * |
| 1714 | * @param int $form_id The form ID. |
| 1715 | * @param array $args An array of form arguments. |
| 1716 | * |
| 1717 | * @return void |
| 1718 | */ |
| 1719 | function give_form_display_content( $form_id, $args ) { |
| 1720 | |
| 1721 | $content = wpautop( give_get_meta( $form_id, '_give_form_content', true ) ); |
| 1722 | $show_content = give_get_form_content_placement( $form_id, $args ); |
| 1723 | |
| 1724 | if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) { |
| 1725 | $content = apply_filters( 'the_content', $content ); |
| 1726 | } |
| 1727 | |
| 1728 | $output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>'; |
| 1729 | |
| 1730 | echo apply_filters( 'give_form_content_output', $output ); |
| 1731 | |
| 1732 | // remove action to prevent content output on addition forms on page. |
| 1733 | // @see: https://github.com/WordImpress/Give/issues/634. |
| 1734 | remove_action( $show_content, 'give_form_display_content' ); |
| 1735 | } |
| 1736 | |
| 1737 | /** |
| 1738 | * Renders the hidden Checkout fields. |
| 1739 | * |
| 1740 | * @since 1.0 |
| 1741 | * |
| 1742 | * @param int $form_id The form ID. |
| 1743 | * |
| 1744 | * @return void |
| 1745 | */ |
| 1746 | function give_checkout_hidden_fields( $form_id ) { |
| 1747 | |
| 1748 | /** |
| 1749 | * Fires while rendering hidden checkout fields, before the fields. |
| 1750 | * |
| 1751 | * @since 1.0 |
| 1752 | * |
| 1753 | * @param int $form_id The form ID. |
| 1754 | */ |
| 1755 | do_action( 'give_hidden_fields_before', $form_id ); |
| 1756 | |
| 1757 | if ( is_user_logged_in() ) { ?> |
| 1758 | <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
| 1759 | <?php } ?> |
| 1760 | <input type="hidden" name="give_action" value="purchase"/> |
| 1761 | <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
| 1762 | <?php |
| 1763 | /** |
| 1764 | * Fires while rendering hidden checkout fields, after the fields. |
| 1765 | * |
| 1766 | * @since 1.0 |
| 1767 | * |
| 1768 | * @param int $form_id The form ID. |
| 1769 | */ |
| 1770 | do_action( 'give_hidden_fields_after', $form_id ); |
| 1771 | |
| 1772 | } |
| 1773 | |
| 1774 | /** |
| 1775 | * Filter Success Page Content. |
| 1776 | * |
| 1777 | * Applies filters to the success page content. |
| 1778 | * |
| 1779 | * @since 1.0 |
| 1780 | * |
| 1781 | * @param string $content Content before filters. |
| 1782 | * |
| 1783 | * @return string $content Filtered content. |
| 1784 | */ |
| 1785 | function give_filter_success_page_content( $content ) { |
| 1786 | |
| 1787 | $give_options = give_get_settings(); |
| 1788 | |
| 1789 | if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
| 1790 | if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
| 1791 | $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | return $content; |
| 1796 | } |
| 1797 | |
| 1798 | add_filter( 'the_content', 'give_filter_success_page_content' ); |
| 1799 | |
| 1800 | /** |
| 1801 | * Test Mode Frontend Warning. |
| 1802 | * |
| 1803 | * Displays a notice on the frontend for donation forms. |
| 1804 | * |
| 1805 | * @since 1.1 |
| 1806 | */ |
| 1807 | function give_test_mode_frontend_warning() { |
| 1808 | |
| 1809 | if ( give_is_test_mode() ) { |
| 1810 | 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>'; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
| 1815 | |
| 1816 | /** |
| 1817 | * Members-only Form. |
| 1818 | * |
| 1819 | * If "Disable Guest Donations" and "Display Register / Login" is set to none. |
| 1820 | * |
| 1821 | * @since 1.4.1 |
| 1822 | * |
| 1823 | * @param string $final_output |
| 1824 | * @param array $args |
| 1825 | * |
| 1826 | * @return string |
| 1827 | */ |
| 1828 | function give_members_only_form( $final_output, $args ) { |
| 1829 | |
| 1830 | $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0; |
| 1831 | |
| 1832 | //Sanity Check: Must have form_id & not be logged in. |
| 1833 | if ( empty( $form_id ) || is_user_logged_in() ) { |
| 1834 | return $final_output; |
| 1835 | } |
| 1836 | |
| 1837 | //Logged in only and Register / Login set to none. |
| 1838 | if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) { |
| 1839 | |
| 1840 | $final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false ); |
| 1841 | |
| 1842 | return apply_filters( 'give_members_only_output', $final_output, $form_id ); |
| 1843 | |
| 1844 | } |
| 1845 | |
| 1846 | return $final_output; |
| 1847 | |
| 1848 | } |
| 1849 | |
| 1850 | add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 ); |
| 1851 | |
| 1852 | |
| 1853 | /** |
| 1854 | * Add donation form hidden fields. |
| 1855 | * |
| 1856 | * @since 1.8.17 |
| 1857 | * |
| 1858 | * @param int $form_id |
| 1859 | * @param array $args |
| 1860 | * @param Give_Donate_Form $form |
| 1861 | */ |
| 1862 | function __give_form_add_donation_hidden_field( $form_id, $args, $form ) { |
| 1863 | ?> |
| 1864 | <input type="hidden" name="give-form-id" value="<?php echo $form_id; ?>"/> |
| 1865 | <input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/> |
| 1866 | <input type="hidden" name="give-current-url" |
| 1867 | value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
| 1868 | <input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
| 1869 | <input type="hidden" name="give-form-minimum" |
| 1870 | value="<?php echo give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ); ?>"/> |
| 1871 | <?php |
| 1872 | |
| 1873 | // WP nonce field. |
| 1874 | wp_nonce_field( "donation_form_nonce_{$form_id}", '_wpnonce', false ); |
| 1875 | |
| 1876 | // Price ID hidden field for variable (multi-level) donation forms. |
| 1877 | if ( give_has_variable_prices( $form_id ) ) { |
| 1878 | // Get default selected price ID. |
| 1879 | $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
| 1880 | $price_id = 0; |
| 1881 | //loop through prices. |
| 1882 | foreach ( $prices as $price ) { |
| 1883 | if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) { |
| 1884 | $price_id = $price['_give_id']['level_id']; |
| 1885 | }; |
| 1886 | } |
| 1887 | |
| 1888 | |
| 1889 | echo sprintf( |
| 1890 | '<input type="hidden" name="give-price-id" value="%s"/>', |
| 1891 | $price_id |
| 1892 | ); |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 ); |
| 1897 | |
| 1898 | /** |
| 1899 | * Add currency settings on donation form. |
| 1900 | * |
| 1901 | * @since 1.8.17 |
| 1902 | * |
| 1903 | * @param array $form_html_tags |
| 1904 | * @param Give_Donate_Form $form |
| 1905 | * |
| 1906 | * @return array |
| 1907 | */ |
| 1908 | function __give_form_add_currency_settings( $form_html_tags, $form ) { |
| 1909 | $form_currency = give_get_currency( $form->ID ); |
| 1910 | $currency_settings = give_get_currency_formatting_settings( $form_currency ); |
| 1911 | |
| 1912 | // Check if currency exist. |
| 1913 | if ( empty( $currency_settings ) ) { |
| 1914 | return $form_html_tags; |
| 1915 | } |
| 1916 | |
| 1917 | $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency ); |
| 1918 | $form_html_tags['data-currency_code'] = $form_currency; |
| 1919 | |
| 1920 | if ( ! empty( $currency_settings ) ) { |
| 1921 | foreach ( $currency_settings as $key => $value ) { |
| 1922 | $form_html_tags["data-{$key}"] = $value; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | return $form_html_tags; |
| 1927 | } |
| 1928 | |
| 1929 | add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 ); |
| 1930 |