Skip to content

Commit

Permalink
fix(shortcode): Add proper redirection on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Apr 16, 2018
1 parent 3aecd9a commit 7b357a0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
52 changes: 52 additions & 0 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2048,10 +2048,62 @@ function add_give_goal_progress_bar_class( $class_bar ) {
* @param int $id ID of the form.
* @param array $args Additional args.
*
* @since 2.1
*
* @return array
*/
function add_class_for_form_grid( $class, $id, $args ) {
$class[] = 'give-form-grid-wrap';

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 is_form_grid_page_hidden_field( $id, $args, $form ) {
echo '<input type="hidden" name="is-form-grid" value="true" />';
}

/**
* 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.
*
* @since 2.1
* @return string
*/
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( array(
'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 );
7 changes: 6 additions & 1 deletion includes/process-donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
* @return mixed
*/
function give_process_donation_form() {

if ( ! give_verify_donation_form_nonce() && ! wp_doing_ajax() ) {
give_send_back_to_checkout();
}

$is_ajax = isset( $_POST['give_ajax'] );

// Verify donation form nonce.
Expand Down Expand Up @@ -1325,4 +1330,4 @@ function give_donation_form_validate_name_fields() {
if ( $is_first_name || $is_last_name ) {
give_set_error( 'invalid_name', esc_html__( '<First Name | Last Name> cannot contain email address.', 'give' ) );
}
}
}
1 change: 1 addition & 0 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ function give_form_grid_shortcode( $atts ) {
add_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class', 10, 1 );
add_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class', 10, 1 );
add_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10, 3 );
add_action( 'give_donation_form_top', 'is_form_grid_page_hidden_field', 10, 3 );

echo '<div class="give-wrap">';
echo '<div class="give-grid give-grid--' . esc_attr( $atts['columns'] ) . '">';
Expand Down

0 comments on commit 7b357a0

Please sign in to comment.