ID ) {
$args['id'] = $post->ID;
}
// set `form_id` for backward compatibility because many legacy filters and functions are using it.
$args['form_id'] = $args['id'];
/**
* Fire the filter
* Note: we will deprecate this filter soon. Use give_get_default_form_shortcode_args instead
*
* @deprecated 2.4.1
*/
$args = apply_filters( 'give_form_args_defaults', $args );
$form = new Give_Donate_Form( $args['id'] );
// Bail out, if no form ID.
if ( empty( $form->ID ) ) {
return false;
}
$args['id_prefix'] = "{$form->ID}-{$count}";
$payment_mode = give_get_chosen_gateway( $form->ID );
$form_action = add_query_arg(
apply_filters(
'give_form_action_args',
[
'payment-mode' => $payment_mode,
'form-id' => $form->ID,
]
),
give_get_current_page_url()
);
// Sanity Check: Donation form not published or user doesn't have permission to view drafts.
if (
( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
|| ( 'trash' === $form->post_status )
) {
return false;
}
// Get the form wrap CSS classes.
$form_wrap_classes = $form->get_form_wrap_classes( $args );
// Get the
';
}
}
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
/**
* Members-only Form.
*
* If "Disable Guest Donations" and "Display Register / Login" is set to none.
*
* @param string $final_output
* @param array $args
*
* @return string
* @since 1.4.1
*/
function give_members_only_form( $final_output, $args ) {
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
// Sanity Check: Must have form_id & not be logged in.
if ( empty( $form_id ) || is_user_logged_in() ) {
return $final_output;
}
// Logged in only and Register / Login set to none.
if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
$final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
return apply_filters( 'give_members_only_output', $final_output, $form_id );
}
return $final_output;
}
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
/**
* Add donation form hidden fields.
*
* @param int $form_id
* @param array $args
* @param Give_Donate_Form $form
*
* @since 1.8.17
*/
function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
?>
session->has_session() )
);
// WP nonce field.
echo str_replace(
'/>',
"{$data_attr}/>",
give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
);
// Price ID hidden field for variable (multi-level) donation forms.
if ( give_has_variable_prices( $form_id ) ) {
// Get the default price ID.
$default_price = give_form_get_default_level( $form_id );
$price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
echo sprintf(
'',
$price_id
);
}
}
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
/**
* Add currency settings on donation form.
*
* @param array $form_html_tags
* @param Give_Donate_Form $form
*
* @return array
* @since 1.8.17
*/
function __give_form_add_currency_settings( $form_html_tags, $form ) {
$form_currency = give_get_currency( $form->ID );
$currency_settings = give_get_currency_formatting_settings( $form_currency );
// Check if currency exist.
if ( empty( $currency_settings ) ) {
return $form_html_tags;
}
$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
$form_html_tags['data-currency_code'] = $form_currency;
if ( ! empty( $currency_settings ) ) {
foreach ( $currency_settings as $key => $value ) {
$form_html_tags[ "data-{$key}" ] = $value;
}
}
return $form_html_tags;
}
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
/**
* Adds classes to progress bar container.
*
* @param string $class_goal
*
* @return string
* @since 2.1
*/
function add_give_goal_progress_class( $class_goal ) {
$class_goal = 'progress progress-striped active';
return $class_goal;
}
/**
* Adds classes to progress bar span tag.
*
* @param string $class_bar
*
* @return string
* @since 2.1
*/
function add_give_goal_progress_bar_class( $class_bar ) {
$class_bar = 'bar';
return $class_bar;
}
/**
* Add a class to the form wrap on the grid page.
*
* @param array $class Array of form wrapper classes.
* @param int $id ID of the form.
* @param array $args Additional args.
*
* @return array
* @since 2.1
*/
function add_class_for_form_grid( $class, $id, $args ) {
$class[] = 'give-form-grid-wrap';
foreach ( $class as $index => $item ) {
if ( false !== strpos( $item, 'give-display-' ) ) {
unset( $class[ $index ] );
}
}
return $class;
}
/**
* Add hidden field to Form Grid page
*
* @param int $form_id The form ID.
* @param array $args An array of form arguments.
* @param Give_Donate_Form $form Form object.
*
* @since 2.1
*/
function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
echo '';
}
/**
* Redirect to the same paginated URL on the Form Grid page
* and adds query parameters to open the popup again after
* redirection.
*
* @param string $redirect URL for redirection.
* @param array $args Array of additional args.
*
* @return string
* @since 2.1
*/
function give_redirect_and_popup_form( $redirect, $args ) {
// Check the page has Form Grid.
$is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
if ( 'true' === $is_form_grid ) {
$payment_mode = give_clean( $_POST['payment-mode'] );
$form_id = $args['form-id'];
// Get the URL without Query parameters.
$redirect = strtok( $redirect, '?' );
// Add query parameters 'form-id' and 'payment-mode'.
$redirect = add_query_arg(
[
'form-id' => $form_id,
'payment-mode' => $payment_mode,
],
$redirect
);
}
// Return the modified URL.
return $redirect;
}
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );