| 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 |
<input type="hidden" name="give_login_nonce" |
| 1681 |
value="<?php echo wp_create_nonce( 'give-login-nonce' ); ?>"/> |
| 1682 |
<?php |
| 1683 |
/** |
| 1684 |
* Fires while rendering checkout login form, after the fields. |
| 1685 |
* |
| 1686 |
* @param int $form_id The form ID. |
| 1687 |
* |
| 1688 |
* @since 1.0 |
| 1689 |
*/ |
| 1690 |
do_action( 'give_donation_form_login_fields_after', $form_id ); |
| 1691 |
?> |
| 1692 |
</fieldset><!--end #give-login-fields--> |
| 1693 |
<?php |
| 1694 |
echo ob_get_clean(); |
| 1695 |
} |
| 1696 |
|
| 1697 |
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 ); |
| 1698 |
|
| 1699 |
/** |
| 1700 |
* Payment Mode Select. |
| 1701 |
* |
| 1702 |
* Renders the payment mode form by getting all the enabled payment gateways and |
| 1703 |
* outputting them as radio buttons for the user to choose the payment gateway. If |
| 1704 |
* a default payment gateway has been chosen from the Give Settings, it will be |
| 1705 |
* automatically selected. |
| 1706 |
* |
| 1707 |
* @param int $form_id The form ID. |
| 1708 |
* |
| 1709 |
* @return void |
| 1710 |
* @since 1.0 |
| 1711 |
*/ |
| 1712 |
function give_payment_mode_select( $form_id, $args ) { |
| 1713 |
$gateways = give_get_enabled_payment_gateways($form_id, 2); |
| 1714 |
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
| 1715 |
|
| 1716 |
/** |
| 1717 |
* Fires while selecting payment gateways, before the fields. |
| 1718 |
* |
| 1719 |
* @since 1.7 |
| 1720 |
* |
| 1721 |
* @param int $form_id The form ID. |
| 1722 |
* |
| 1723 |
*/ |
| 1724 |
do_action( 'give_payment_mode_top', $form_id ); |
| 1725 |
?> |
| 1726 |
|
| 1727 |
<fieldset id="give-payment-mode-select"<?php echo count( $gateways ) <= 1 ? ' style="display: none;"' : ''; ?>> |
| 1728 |
<?php |
| 1729 |
/** |
| 1730 |
* Fires while selecting payment gateways, before the wrap div. |
| 1731 |
* |
| 1732 |
* @since 1.7 |
| 1733 |
* |
| 1734 |
* @param int $form_id The form ID. |
| 1735 |
* |
| 1736 |
*/ |
| 1737 |
do_action( 'give_payment_mode_before_gateways_wrap' ); |
| 1738 |
?> |
| 1739 |
<legend |
| 1740 |
class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?> |
| 1741 |
<span class="give-loading-text"><span |
| 1742 |
class="give-loading-animation"></span> |
| 1743 |
</span> |
| 1744 |
</legend> |
| 1745 |
|
| 1746 |
<div id="give-payment-mode-wrap"> |
| 1747 |
<?php |
| 1748 |
/** |
| 1749 |
* Fires while selecting payment gateways, before the gateways list. |
| 1750 |
* |
| 1751 |
* @since 1.7 |
| 1752 |
*/ |
| 1753 |
do_action( 'give_payment_mode_before_gateways' ) |
| 1754 |
?> |
| 1755 |
<ul id="give-gateway-radio-list"> |
| 1756 |
<?php |
| 1757 |
/** |
| 1758 |
* Loop through the active payment gateways. |
| 1759 |
*/ |
| 1760 |
$selected_gateway = give_get_chosen_gateway( $form_id ); |
| 1761 |
|
| 1762 |
foreach ( $gateways as $gateway_id => $gateway ) : |
| 1763 |
// Determine the default gateway. |
| 1764 |
$checked = checked( $gateway_id, $selected_gateway, false ); |
| 1765 |
$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; |
| 1766 |
$is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true; |
| 1767 |
|
| 1768 |
if ( true === $is_payment_method_visible ) { |
| 1769 |
?> |
| 1770 |
<li<?php echo $checked_class; ?>> |
| 1771 |
<input type="radio" name="payment-mode" class="give-gateway" |
| 1772 |
id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
| 1773 |
value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>> |
| 1774 |
<label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
| 1775 |
class="give-gateway-option" |
| 1776 |
id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
| 1777 |
</li> |
| 1778 |
<?php |
| 1779 |
} |
| 1780 |
endforeach; |
| 1781 |
?> |
| 1782 |
</ul> |
| 1783 |
<?php |
| 1784 |
/** |
| 1785 |
* Fires while selecting payment gateways, before the gateways list. |
| 1786 |
* |
| 1787 |
* @since 1.7 |
| 1788 |
*/ |
| 1789 |
do_action( 'give_payment_mode_after_gateways' ); |
| 1790 |
?> |
| 1791 |
</div> |
| 1792 |
<?php |
| 1793 |
/** |
| 1794 |
* Fires while selecting payment gateways, after the wrap div. |
| 1795 |
* |
| 1796 |
* @param int $form_id The form ID. |
| 1797 |
* |
| 1798 |
* @since 1.7 |
| 1799 |
*/ |
| 1800 |
do_action( 'give_payment_mode_after_gateways_wrap' ); |
| 1801 |
?> |
| 1802 |
</fieldset> |
| 1803 |
|
| 1804 |
<?php |
| 1805 |
/** |
| 1806 |
* Fires while selecting payment gateways, after the fields. |
| 1807 |
* |
| 1808 |
* @param int $form_id The form ID. |
| 1809 |
* |
| 1810 |
* @since 1.7 |
| 1811 |
*/ |
| 1812 |
do_action( 'give_payment_mode_bottom', $form_id ); |
| 1813 |
?> |
| 1814 |
|
| 1815 |
<div id="give_purchase_form_wrap"> |
| 1816 |
|
| 1817 |
<?php |
| 1818 |
/** |
| 1819 |
* Fire after payment field render. |
| 1820 |
* |
| 1821 |
* @since 1.7 |
| 1822 |
*/ |
| 1823 |
do_action( 'give_donation_form', $form_id, $args ); |
| 1824 |
?> |
| 1825 |
|
| 1826 |
</div> |
| 1827 |
|
| 1828 |
<?php |
| 1829 |
/** |
| 1830 |
* Fire after donation form render. |
| 1831 |
* |
| 1832 |
* @since 1.7 |
| 1833 |
*/ |
| 1834 |
do_action( 'give_donation_form_wrap_bottom', $form_id ); |
| 1835 |
} |
| 1836 |
|
| 1837 |
add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 ); |
| 1838 |
|
| 1839 |
/** |
| 1840 |
* Renders the Checkout Agree to Terms, this displays a checkbox for users to |
| 1841 |
* agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are |
| 1842 |
* set in the Give Settings. |
| 1843 |
* |
| 1844 |
* @param int $form_id The form ID. |
| 1845 |
* |
| 1846 |
* @return bool |
| 1847 |
* @since 1.0 |
| 1848 |
*/ |
| 1849 |
function give_terms_agreement( $form_id ) { |
| 1850 |
$form_option = give_get_meta( $form_id, '_give_terms_option', true ); |
| 1851 |
|
| 1852 |
// Bailout if per form and global term and conditions is not setup. |
| 1853 |
if ( |
| 1854 |
give_is_setting_enabled( $form_option, 'global' ) |
| 1855 |
&& give_is_setting_enabled( give_get_option( 'terms' ) ) |
| 1856 |
) { |
| 1857 |
$label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) ); |
| 1858 |
$terms = $terms = give_get_option( 'agreement_text', '' ); |
| 1859 |
$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display§ion=term-and-conditions' ); |
| 1860 |
|
| 1861 |
} elseif ( give_is_setting_enabled( $form_option ) ) { |
| 1862 |
$label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' ); |
| 1863 |
$terms = give_get_meta( $form_id, '_give_agree_text', true ); |
| 1864 |
$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' ); |
| 1865 |
|
| 1866 |
} else { |
| 1867 |
return false; |
| 1868 |
} |
| 1869 |
|
| 1870 |
// Bailout: Check if term and conditions text is empty or not. |
| 1871 |
if ( empty( $terms ) ) { |
| 1872 |
if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) { |
| 1873 |
echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url ); |
| 1874 |
} |
| 1875 |
|
| 1876 |
return false; |
| 1877 |
} |
| 1878 |
|
| 1879 |
/** |
| 1880 |
* Filter the form term content |
| 1881 |
* |
| 1882 |
* @since 2.1.5 |
| 1883 |
*/ |
| 1884 |
$terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id ); |
| 1885 |
|
| 1886 |
?> |
| 1887 |
<fieldset id="give_terms_agreement"> |
| 1888 |
<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend> |
| 1889 |
<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;"> |
| 1890 |
<?php |
| 1891 |
/** |
| 1892 |
* Fires while rendering terms of agreement, before the fields. |
| 1893 |
* |
| 1894 |
* @since 1.0 |
| 1895 |
*/ |
| 1896 |
do_action( 'give_before_terms' ); |
| 1897 |
|
| 1898 |
echo $terms; |
| 1899 |
/** |
| 1900 |
* Fires while rendering terms of agreement, after the fields. |
| 1901 |
* |
| 1902 |
* @since 1.0 |
| 1903 |
*/ |
| 1904 |
do_action( 'give_after_terms' ); |
| 1905 |
?> |
| 1906 |
</div> |
| 1907 |
<div id="give_show_terms"> |
| 1908 |
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1909 |
aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a> |
| 1910 |
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
| 1911 |
aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a> |
| 1912 |
</div> |
| 1913 |
|
| 1914 |
<input name="give_agree_to_terms" class="required" type="checkbox" |
| 1915 |
id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/> |
| 1916 |
<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label> |
| 1917 |
|
| 1918 |
</fieldset> |
| 1919 |
<?php |
| 1920 |
} |
| 1921 |
|
| 1922 |
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 ); |
| 1923 |
|
| 1924 |
/** |
| 1925 |
* Checkout Final Total. |
| 1926 |
* |
| 1927 |
* Shows the final donation total at the bottom of the checkout page. |
| 1928 |
* |
| 1929 |
* @param int $form_id The form ID. |
| 1930 |
* |
| 1931 |
* @return void |
| 1932 |
* @since 1.0 |
| 1933 |
*/ |
| 1934 |
function give_checkout_final_total( $form_id ) { |
| 1935 |
|
| 1936 |
$total = isset( $_POST['give_total'] ) ? |
| 1937 |
apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'], [ 'currency' => give_get_currency( $form_id ) ] ) ) : |
| 1938 |
give_get_default_form_amount( $form_id ); |
| 1939 |
|
| 1940 |
// Only proceed if give_total available. |
| 1941 |
if ( empty( $total ) ) { |
| 1942 |
return; |
| 1943 |
} |
| 1944 |
?> |
| 1945 |
<p id="give-final-total-wrap" class="form-wrap "> |
| 1946 |
<?php |
| 1947 |
/** |
| 1948 |
* Fires before the donation total label |
| 1949 |
* |
| 1950 |
* @since 2.0.5 |
| 1951 |
*/ |
| 1952 |
do_action( 'give_donation_final_total_label_before', $form_id ); |
| 1953 |
?> |
| 1954 |
<span class="give-donation-total-label"> |
| 1955 |
<?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?> |
| 1956 |
</span> |
| 1957 |
<span class="give-final-total-amount" |
| 1958 |
data-total="<?php echo give_format_amount( $total, [ 'sanitize' => false ] ); ?>"> |
| 1959 |
<?php |
| 1960 |
echo give_currency_filter( |
| 1961 |
give_format_amount( |
| 1962 |
$total, |
| 1963 |
[ |
| 1964 |
'sanitize' => false, |
| 1965 |
'currency' => give_get_currency( $form_id ), |
| 1966 |
] |
| 1967 |
), |
| 1968 |
[ 'currency_code' => give_get_currency( $form_id ) ] |
| 1969 |
); |
| 1970 |
?> |
| 1971 |
</span> |
| 1972 |
<?php |
| 1973 |
/** |
| 1974 |
* Fires after the donation final total label |
| 1975 |
* |
| 1976 |
* @since 2.0.5 |
| 1977 |
*/ |
| 1978 |
do_action( 'give_donation_final_total_label_after', $form_id ); |
| 1979 |
?> |
| 1980 |
</p> |
| 1981 |
<?php |
| 1982 |
} |
| 1983 |
|
| 1984 |
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 ); |
| 1985 |
|
| 1986 |
/** |
| 1987 |
* Renders the Checkout Submit section. |
| 1988 |
* |
| 1989 |
* @param int $form_id The donation form ID. |
| 1990 |
* @param array $args List of arguments. |
| 1991 |
* |
| 1992 |
* @return void |
| 1993 |
* @since 1.0 |
| 1994 |
*/ |
| 1995 |
function give_checkout_submit( $form_id, $args ) { |
| 1996 |
?> |
| 1997 |
<fieldset id="give_purchase_submit" class="give-donation-submit"> |
| 1998 |
<?php |
| 1999 |
/** |
| 2000 |
* Fire before donation form submit. |
| 2001 |
* |
| 2002 |
* @since 1.7 |
| 2003 |
*/ |
| 2004 |
do_action( 'give_donation_form_before_submit', $form_id, $args ); |
| 2005 |
|
| 2006 |
give_checkout_hidden_fields( $form_id, $args ); |
| 2007 |
|
| 2008 |
echo give_get_donation_form_submit_button( $form_id, $args ); |
| 2009 |
|
| 2010 |
/** |
| 2011 |
* Fire after donation form submit. |
| 2012 |
* |
| 2013 |
* @since 1.7 |
| 2014 |
*/ |
| 2015 |
do_action( 'give_donation_form_after_submit', $form_id, $args ); |
| 2016 |
?> |
| 2017 |
</fieldset> |
| 2018 |
<?php |
| 2019 |
} |
| 2020 |
|
| 2021 |
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 ); |
| 2022 |
|
| 2023 |
/** |
| 2024 |
* Give Donation form submit button. |
| 2025 |
* |
| 2026 |
* @since 4.16.2 Escape submit button label in form markup. |
| 2027 |
* @since 1.8.8 |
| 2028 |
* |
| 2029 |
* @param int $form_id The form ID. |
| 2030 |
* @param array $args |
| 2031 |
* |
| 2032 |
* @return string |
| 2033 |
*/ |
| 2034 |
function give_get_donation_form_submit_button( $form_id, $args = [] ) { |
| 2035 |
|
| 2036 |
$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true ); |
| 2037 |
$display_label_field = apply_filters( 'give_donation_form_submit_button_text', $display_label_field, $form_id, $args ); |
| 2038 |
$display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
| 2039 |
ob_start(); |
| 2040 |
?> |
| 2041 |
<div class="give-submit-button-wrap give-clearfix"> |
| 2042 |
<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" |
| 2043 |
value="<?php echo esc_attr( $display_label ); ?>" data-before-validation-label="<?php echo esc_attr( $display_label ); ?>"/> |
| 2044 |
<span class="give-loading-animation"></span> |
| 2045 |
</div> |
| 2046 |
<?php |
| 2047 |
return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args ); |
| 2048 |
} |
| 2049 |
|
| 2050 |
/** |
| 2051 |
* Show Give Goals. |
| 2052 |
* |
| 2053 |
* @param int $form_id The form ID. |
| 2054 |
* @param array $args An array of form arguments. |
| 2055 |
* |
| 2056 |
* @return mixed |
| 2057 |
* @since 1.6 Add template for Give Goals Shortcode. |
| 2058 |
* More info is on https://github.com/impress-org/give/issues/411 |
| 2059 |
* |
| 2060 |
* @since 1.0 |
| 2061 |
*/ |
| 2062 |
function give_show_goal_progress( $form_id, $args = [] ) { |
| 2063 |
|
| 2064 |
ob_start(); |
| 2065 |
give_get_template( |
| 2066 |
'shortcode-goal', |
| 2067 |
[ |
| 2068 |
'form_id' => $form_id, |
| 2069 |
'args' => $args, |
| 2070 |
] |
| 2071 |
); |
| 2072 |
|
| 2073 |
/** |
| 2074 |
* Filter progress bar output |
| 2075 |
* |
| 2076 |
* @since 2.0 |
| 2077 |
*/ |
| 2078 |
echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args ); |
| 2079 |
|
| 2080 |
return true; |
| 2081 |
} |
| 2082 |
|
| 2083 |
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
| 2084 |
|
| 2085 |
/** |
| 2086 |
* Show Give Totals Progress. |
| 2087 |
* |
| 2088 |
* @param int $total Total amount based on shortcode parameter. |
| 2089 |
* @param int $total_goal Total Goal amount passed by Admin. |
| 2090 |
* |
| 2091 |
* @return mixed |
| 2092 |
* @since 2.1 |
| 2093 |
*/ |
| 2094 |
function give_show_goal_totals_progress( $total, $total_goal ) { |
| 2095 |
|
| 2096 |
// Bail out if total goal is set as an array. |
| 2097 |
if ( isset( $total_goal ) && is_array( $total_goal ) ) { |
| 2098 |
return false; |
| 2099 |
} |
| 2100 |
|
| 2101 |
ob_start(); |
| 2102 |
give_get_template( |
| 2103 |
'shortcode-totals-progress', |
| 2104 |
[ |
| 2105 |
'total' => $total, |
| 2106 |
'total_goal' => $total_goal, |
| 2107 |
] |
| 2108 |
); |
| 2109 |
|
| 2110 |
echo apply_filters( 'give_total_progress_output', ob_get_clean() ); |
| 2111 |
|
| 2112 |
return true; |
| 2113 |
} |
| 2114 |
|
| 2115 |
add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 ); |
| 2116 |
|
| 2117 |
/** |
| 2118 |
* Get form content position. |
| 2119 |
* |
| 2120 |
* @param $form_id |
| 2121 |
* @param $args |
| 2122 |
* |
| 2123 |
* @return mixed|string |
| 2124 |
* @since 1.8 |
| 2125 |
*/ |
| 2126 |
function give_get_form_content_placement( $form_id, $args ) { |
| 2127 |
$show_content = ''; |
| 2128 |
|
| 2129 |
if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) { |
| 2130 |
// Content positions. |
| 2131 |
$content_placement = [ |
| 2132 |
'above' => 'give_pre_form', |
| 2133 |
'below' => 'give_post_form', |
| 2134 |
]; |
| 2135 |
|
| 2136 |
// Check if content position already decoded. |
| 2137 |
if ( in_array( $args['show_content'], $content_placement ) ) { |
| 2138 |
return $args['show_content']; |
| 2139 |
} |
| 2140 |
|
| 2141 |
$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' ); |
| 2142 |
|
| 2143 |
} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) { |
| 2144 |
$show_content = give_get_meta( $form_id, '_give_content_placement', true ); |
| 2145 |
|
| 2146 |
} |
| 2147 |
|
| 2148 |
return $show_content; |
| 2149 |
} |
| 2150 |
|
| 2151 |
/** |
| 2152 |
* Adds Actions to Render Form Content. |
| 2153 |
* |
| 2154 |
* @param int $form_id The form ID. |
| 2155 |
* @param array $args An array of form arguments. |
| 2156 |
* |
| 2157 |
* @return void|bool |
| 2158 |
* @since 1.0 |
| 2159 |
*/ |
| 2160 |
function give_form_content( $form_id, $args ) { |
| 2161 |
|
| 2162 |
$show_content = give_get_form_content_placement( $form_id, $args ); |
| 2163 |
|
| 2164 |
// Bailout. |
| 2165 |
if ( empty( $show_content ) ) { |
| 2166 |
return false; |
| 2167 |
} |
| 2168 |
|
| 2169 |
// Add action according to value. |
| 2170 |
add_action( $show_content, 'give_form_display_content', 10, 2 ); |
| 2171 |
} |
| 2172 |
|
| 2173 |
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
| 2174 |
|
| 2175 |
/** |
| 2176 |
* Renders Post Form Content. |
| 2177 |
* |
| 2178 |
* Displays content for Give forms; fired by action from give_form_content. |
| 2179 |
* |
| 2180 |
* @param int $form_id The form ID. |
| 2181 |
* @param array $args An array of form arguments. |
| 2182 |
* |
| 2183 |
* @return void |
| 2184 |
* @since 1.0 |
| 2185 |
*/ |
| 2186 |
function give_form_display_content( $form_id, $args ) { |
| 2187 |
$content = give_get_meta( $form_id, '_give_form_content', true ); |
| 2188 |
$show_content = give_get_form_content_placement( $form_id, $args ); |
| 2189 |
|
| 2190 |
if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) { |
| 2191 |
|
| 2192 |
// Do not restore wpautop if we are still parsing blocks. |
| 2193 |
$priority = has_filter( 'the_content', '_restore_wpautop_hook' ); |
| 2194 |
if ( false !== $priority && doing_filter( 'the_content' ) ) { |
| 2195 |
remove_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
| 2196 |
} |
| 2197 |
|
| 2198 |
$content = apply_filters( 'the_content', $content ); |
| 2199 |
|
| 2200 |
// Restore wpautop after done with blocks parsing. |
| 2201 |
if ( $priority ) { |
| 2202 |
// Run wpautop manually if parsing block |
| 2203 |
$content = wpautop( $content ); |
| 2204 |
|
| 2205 |
add_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
| 2206 |
} |
| 2207 |
} else { |
| 2208 |
$content = wpautop( do_shortcode( $content ) ); |
| 2209 |
} |
| 2210 |
|
| 2211 |
$output = sprintf( |
| 2212 |
'<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>', |
| 2213 |
$form_id, |
| 2214 |
$show_content, |
| 2215 |
$content |
| 2216 |
); |
| 2217 |
|
| 2218 |
/** |
| 2219 |
* Filter form content html |
| 2220 |
* |
| 2221 |
* @param string $output |
| 2222 |
* @param int $form_id |
| 2223 |
* @param array $args |
| 2224 |
* |
| 2225 |
* @since 1.0 |
| 2226 |
*/ |
| 2227 |
echo apply_filters( 'give_form_content_output', $output, $form_id, $args ); |
| 2228 |
|
| 2229 |
// remove action to prevent content output on addition forms on page. |
| 2230 |
// @see: https://github.com/impress-org/give/issues/634. |
| 2231 |
remove_action( $show_content, 'give_form_display_content' ); |
| 2232 |
} |
| 2233 |
|
| 2234 |
/** |
| 2235 |
* Renders the hidden Checkout fields. |
| 2236 |
* |
| 2237 |
* @param int $form_id The form ID. |
| 2238 |
* @param array $args Shortcode args. |
| 2239 |
* |
| 2240 |
* @return void |
| 2241 |
* @since 1.0 |
| 2242 |
*/ |
| 2243 |
function give_checkout_hidden_fields( $form_id, $args = [] ) { |
| 2244 |
|
| 2245 |
/** |
| 2246 |
* Fires while rendering hidden checkout fields, before the fields. |
| 2247 |
* |
| 2248 |
* @param int $form_id The form ID. |
| 2249 |
* |
| 2250 |
* @since 1.0 |
| 2251 |
*/ |
| 2252 |
do_action( 'give_hidden_fields_before', $form_id, $args ); |
| 2253 |
|
| 2254 |
if ( is_user_logged_in() ) { |
| 2255 |
?> |
| 2256 |
<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
| 2257 |
<?php } ?> |
| 2258 |
<input type="hidden" name="give_action" value="purchase"/> |
| 2259 |
<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
| 2260 |
<?php |
| 2261 |
/** |
| 2262 |
* Fires while rendering hidden checkout fields, after the fields. |
| 2263 |
* |
| 2264 |
* @param int $form_id The form ID. |
| 2265 |
* |
| 2266 |
* @since 1.0 |
| 2267 |
*/ |
| 2268 |
do_action( 'give_hidden_fields_after', $form_id, $args ); |
| 2269 |
|
| 2270 |
} |
| 2271 |
|
| 2272 |
/** |
| 2273 |
* Filter Success Page Content. |
| 2274 |
* |
| 2275 |
* Applies filters to the success page content. |
| 2276 |
* |
| 2277 |
* @param string $content Content before filters. |
| 2278 |
* |
| 2279 |
* @return string $content Filtered content. |
| 2280 |
* @since 1.0 |
| 2281 |
*/ |
| 2282 |
function give_filter_success_page_content( $content ) { |
| 2283 |
|
| 2284 |
$give_options = give_get_settings(); |
| 2285 |
|
| 2286 |
if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
| 2287 |
if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
| 2288 |
$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
| 2289 |
} |
| 2290 |
} |
| 2291 |
|
| 2292 |
return $content; |
| 2293 |
} |
| 2294 |
|
| 2295 |
add_filter( 'the_content', 'give_filter_success_page_content' ); |
| 2296 |
|
| 2297 |
/** |
| 2298 |
* Test Mode Frontend Warning. |
| 2299 |
* |
| 2300 |
* Displays a notice on the frontend for donation forms. |
| 2301 |
* |
| 2302 |
* @since 1.1 |
| 2303 |
*/ |
| 2304 |
function give_test_mode_frontend_warning() { |
| 2305 |
|
| 2306 |
if ( give_is_test_mode() ) { |
| 2307 |
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>'; |
| 2308 |
} |
| 2309 |
} |
| 2310 |
|
| 2311 |
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
| 2312 |
|
| 2313 |
/** |
| 2314 |
* Members-only Form. |
| 2315 |
* |
| 2316 |
* If "Disable Guest Donations" and "Display Register / Login" is set to none. |
| 2317 |
* |
| 2318 |
* @param string $final_output |
| 2319 |
* @param array $args |
| 2320 |
* |
| 2321 |
* @return string |
| 2322 |
* @since 1.4.1 |
| 2323 |
*/ |
| 2324 |
function give_members_only_form( $final_output, $args ) { |
| 2325 |
|
| 2326 |
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0; |
| 2327 |
|
| 2328 |
// Sanity Check: Must have form_id & not be logged in. |
| 2329 |
if ( empty( $form_id ) || is_user_logged_in() ) { |
| 2330 |
return $final_output; |
| 2331 |
} |
| 2332 |
|
| 2333 |
// Logged in only and Register / Login set to none. |
| 2334 |
if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) { |
| 2335 |
|
| 2336 |
$final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false ); |
| 2337 |
|
| 2338 |
return apply_filters( 'give_members_only_output', $final_output, $form_id ); |
| 2339 |
|
| 2340 |
} |
| 2341 |
|
| 2342 |
return $final_output; |
| 2343 |
|
| 2344 |
} |
| 2345 |
|
| 2346 |
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 ); |
| 2347 |
|
| 2348 |
|
| 2349 |
/** |
| 2350 |
* Add donation form hidden fields. |
| 2351 |
* |
| 2352 |
* @param int $form_id |
| 2353 |
* @param array $args |
| 2354 |
* @param Give_Donate_Form $form |
| 2355 |
* |
| 2356 |
* @since 4.9.0 rename function - PHP 8 compatibility |
| 2357 |
* @since 1.8.17 |
| 2358 |
*/ |
| 2359 |
function give_form_add_donation_hidden_field( $form_id, $args, $form ) { |
| 2360 |
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
| 2361 |
?> |
| 2362 |
<input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/> |
| 2363 |
<input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/> |
| 2364 |
<input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/> |
| 2365 |
<input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
| 2366 |
<input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
| 2367 |
<?php |
| 2368 |
// Get the custom option amount. |
| 2369 |
$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
| 2370 |
|
| 2371 |
// If custom amount enabled. |
| 2372 |
if ( give_is_setting_enabled( $custom_amount ) ) { |
| 2373 |
?> |
| 2374 |
<input type="hidden" name="give-form-minimum" |
| 2375 |
value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/> |
| 2376 |
<input type="hidden" name="give-form-maximum" |
| 2377 |
value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/> |
| 2378 |
<?php |
| 2379 |
} |
| 2380 |
|
| 2381 |
$data_attr = sprintf( |
| 2382 |
'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"', |
| 2383 |
time(), |
| 2384 |
give_get_nonce_life(), |
| 2385 |
absint( Give()->session->has_session() ) |
| 2386 |
); |
| 2387 |
|
| 2388 |
// WP nonce field. |
| 2389 |
echo str_replace( |
| 2390 |
'/>', |
| 2391 |
"{$data_attr}/>", |
| 2392 |
give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false ) |
| 2393 |
); |
| 2394 |
|
| 2395 |
// Price ID hidden field for variable (multi-level) donation forms. |
| 2396 |
if ( give_has_variable_prices( $form_id ) ) { |
| 2397 |
// Get the default price ID. |
| 2398 |
$default_price = give_form_get_default_level( $form_id ); |
| 2399 |
$price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0; |
| 2400 |
|
| 2401 |
echo sprintf( |
| 2402 |
'<input type="hidden" name="give-price-id" value="%s"/>', |
| 2403 |
$price_id |
| 2404 |
); |
| 2405 |
} |
| 2406 |
} |
| 2407 |
|
| 2408 |
add_action( 'give_donation_form_top', 'give_form_add_donation_hidden_field', 0, 3 ); |
| 2409 |
|
| 2410 |
/** |
| 2411 |
* Add currency settings on donation form. |
| 2412 |
* |
| 2413 |
* @param array $form_html_tags |
| 2414 |
* @param Give_Donate_Form $form |
| 2415 |
* |
| 2416 |
* @return array |
| 2417 |
* |
| 2418 |
* @since 4.9.0 rename function - PHP 8 compatibility |
| 2419 |
* @since 1.8.17 |
| 2420 |
*/ |
| 2421 |
function give_form_add_currency_settings( $form_html_tags, $form ) { |
| 2422 |
$form_currency = give_get_currency( $form->ID ); |
| 2423 |
$currency_settings = give_get_currency_formatting_settings( $form_currency ); |
| 2424 |
|
| 2425 |
// Check if currency exist. |
| 2426 |
if ( empty( $currency_settings ) ) { |
| 2427 |
return $form_html_tags; |
| 2428 |
} |
| 2429 |
|
| 2430 |
$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency ); |
| 2431 |
$form_html_tags['data-currency_code'] = $form_currency; |
| 2432 |
|
| 2433 |
if ( ! empty( $currency_settings ) ) { |
| 2434 |
foreach ( $currency_settings as $key => $value ) { |
| 2435 |
$form_html_tags[ "data-{$key}" ] = $value; |
| 2436 |
} |
| 2437 |
} |
| 2438 |
|
| 2439 |
return $form_html_tags; |
| 2440 |
} |
| 2441 |
|
| 2442 |
add_filter( 'give_form_html_tags', 'give_form_add_currency_settings', 0, 2 ); |
| 2443 |
|
| 2444 |
/** |
| 2445 |
* Adds classes to progress bar container. |
| 2446 |
* |
| 2447 |
* @param string $class_goal |
| 2448 |
* |
| 2449 |
* @return string |
| 2450 |
* @since 2.1 |
| 2451 |
*/ |
| 2452 |
function add_give_goal_progress_class( $class_goal ) { |
| 2453 |
$class_goal = 'progress progress-striped active'; |
| 2454 |
|
| 2455 |
return $class_goal; |
| 2456 |
} |
| 2457 |
|
| 2458 |
/** |
| 2459 |
* Adds classes to progress bar span tag. |
| 2460 |
* |
| 2461 |
* @param string $class_bar |
| 2462 |
* |
| 2463 |
* @return string |
| 2464 |
* @since 2.1 |
| 2465 |
*/ |
| 2466 |
function add_give_goal_progress_bar_class( $class_bar ) { |
| 2467 |
$class_bar = 'bar'; |
| 2468 |
|
| 2469 |
return $class_bar; |
| 2470 |
} |
| 2471 |
|
| 2472 |
/** |
| 2473 |
* Add a class to the form wrap on the grid page. |
| 2474 |
* |
| 2475 |
* @param array $class Array of form wrapper classes. |
| 2476 |
* @param int $id ID of the form. |
| 2477 |
* @param array $args Additional args. |
| 2478 |
* |
| 2479 |
* @return array |
| 2480 |
* @since 2.1 |
| 2481 |
*/ |
| 2482 |
function add_class_for_form_grid( $class, $id, $args ) { |
| 2483 |
$class[] = 'give-form-grid-wrap'; |
| 2484 |
|
| 2485 |
foreach ( $class as $index => $item ) { |
| 2486 |
if ( false !== strpos( $item, 'give-display-' ) ) { |
| 2487 |
unset( $class[ $index ] ); |
| 2488 |
} |
| 2489 |
} |
| 2490 |
|
| 2491 |
return $class; |
| 2492 |
} |
| 2493 |
|
| 2494 |
/** |
| 2495 |
* Add hidden field to Form Grid page |
| 2496 |
* |
| 2497 |
* @param int $form_id The form ID. |
| 2498 |
* @param array $args An array of form arguments. |
| 2499 |
* @param Give_Donate_Form $form Form object. |
| 2500 |
* |
| 2501 |
* @since 2.1 |
| 2502 |
*/ |
| 2503 |
function give_is_form_grid_page_hidden_field( $id, $args, $form ) { |
| 2504 |
echo '<input type="hidden" name="is-form-grid" value="true" />'; |
| 2505 |
} |
| 2506 |
|
| 2507 |
/** |
| 2508 |
* Redirect to the same paginated URL on the Form Grid page |
| 2509 |
* and adds query parameters to open the popup again after |
| 2510 |
* redirection. |
| 2511 |
* |
| 2512 |
* @param string $redirect URL for redirection. |
| 2513 |
* @param array $args Array of additional args. |
| 2514 |
* |
| 2515 |
* @return string |
| 2516 |
* @since 2.1 |
| 2517 |
*/ |
| 2518 |
function give_redirect_and_popup_form( $redirect, $args ) { |
| 2519 |
|
| 2520 |
// Check the page has Form Grid. |
| 2521 |
$is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : ''; |
| 2522 |
|
| 2523 |
if ( 'true' === $is_form_grid ) { |
| 2524 |
|
| 2525 |
$payment_mode = give_clean( $_POST['payment-mode'] ); |
| 2526 |
$form_id = $args['form-id']; |
| 2527 |
|
| 2528 |
// Get the URL without Query parameters. |
| 2529 |
$redirect = strtok( $redirect, '?' ); |
| 2530 |
|
| 2531 |
// Add query parameters 'form-id' and 'payment-mode'. |
| 2532 |
$redirect = add_query_arg( |
| 2533 |
[ |
| 2534 |
'form-id' => $form_id, |
| 2535 |
'payment-mode' => $payment_mode, |
| 2536 |
], |
| 2537 |
$redirect |
| 2538 |
); |
| 2539 |
} |
| 2540 |
|
| 2541 |
// Return the modified URL. |
| 2542 |
return esc_url_raw( $redirect ); |
| 2543 |
} |
| 2544 |
|
| 2545 |
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 ); |
| 2546 |
|