I wrote two plugins that utilize the registration_errors filter:
add_filter( 'registration_errors', 'process_payment', 10, 3 );
add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 );
When add_user_to_SF
returns errors, the process_payment
function runs successfully (I know this because it processes a payment).
How can I set this up so that when one of them returns an error the other doesn’t run and user registration doesn’t happen?
Identifying errors via error code
Run
add_user_to_SF
with an earlier priority, to make it execute firstLet’s assume you have two possible errors in your
add_user_to_SF
:Then check for those errors in the latter function by using the
$errors
object’sget_error_codes
method:Via a flag
The following is a mock-up of how you’d do it with a flag as a class property: