I have a gateway plugin and I added the code below to redirect
the customer to a custom page when the payment fails.
My question is, do I need to add exit();
after the end of the redirect_url
which is inside the if statement?
I have seen some codes with exit
and some without
.
else {
//failed
$this->msg['class'] = 'error';
$this->msg['message'] = __( "Your Transaction Has Failed Due to Some Technical Error. Please Try Again.<br/><br/>", 'toBeTranslatd');
$order->update_status('failed');
$order->add_order_note('Failed');
$order->add_order_note($this->msg['message']);
$redirect_url = home_url( '/payment-faild/' );
$lang_code = get_post_meta( $order_id, 'wpml_language', true );
if ( $lang_code === ar ) {
$redirect_url = apply_filters( 'wpml_permalink', $redirect_url, $lang_code );
//exit(); // Do I need this or delete it?
}
}
CodePudding user response:
Wordpress provides two functions for this:
and
And here's what wordpress recommends:
Note:
wp_redirect()
andwp_safe_redirect()
do not exit automatically, and should almost always be followed by a call to exit;
CodePudding user response:
wp_redirect() or wp_safe_redirect() does not exit or die automatically, and should almost always be followed by a call to exit or die();
Reference : https://developer.wordpress.org/reference/functions/wp_redirect
Thank you.