givewp icon indicating copy to clipboard operation
givewp copied to clipboard

give_checkout_error_checks hook runs twice

Open onaralili opened this issue 3 years ago • 0 comments

User Story

As a plugin developer, I want to do a custom validation and log the result.

Details

So we have a plugin that uses give_checkout_error_checks hook to validate a submission for spam detection/card testing attack. There are two cases: either validation fails or passes. In both cases, we log the activity. For some reason, hook runs twice in case of successful validation.

I removed our code and hooked a simple empty function add_action( 'give_checkout_error_checks', 'myplugin_givewp_pre_submission', 10, 1 ); to confirm the issue.

Expected Behavior

give_checkout_error_checks fires once.

Steps to Reproduce

  1. Enable debugging in WordPress
  2. Create a function that hooks to give_checkout_error_checks in either a plugin's main file or in functions.php add_action( 'give_checkout_error_checks', 'myplugin_givewp_pre_submission', 10, 1 );
function myplugin_givewp_pre_submission($data) { 
    error_log( "Give fires..." ); // Write to debug.log
    return $data;
}
  1. Check debug.log

Visuals

Additional Context

System Information

Details
  • Give Version 2.22.1
  • WP Version 6.0.2

Acceptance Criteria

  • [ ] give_checkout_error_checks fires once
  • [ ] Proposal of an alternative hook that fires once and able to set error using give_set_error to prevent submission/donation.

onaralili avatar Sep 23 '22 14:09 onaralili