make CF7 return a mail_failed error?
Hi @zaus
i think you already are aware of this (it's on the homepage instructions).
the only solution I can find on the back end is to add this function to
plugins\contact-form-7\includes\submission.php
public function set_status($status) {
$this->status = $status;
}
this is obviously not desirable!
I have tagged the author about this here: https://wordpress.org/support/topic/force-an-error-in-hook-returned-from-3rd-party-crm/
even with that you'd have to set a global variable to pass the failure from a Forms3rdPartyIntegration_remote_failure hook function to a wpcf7_mail_sent hook function
eg:
$f3p_fail = false;
add_action('Forms3rdPartyIntegration_remote_failure', f3p_remote_fail', 10, 2);
function f3p_remote_fail($cf7, $debug, $service, $post, $response) {
global $f3p_fail;
$f3p_fail = true;
}
add_filter('wpcf7_skip_mail','do_skip_mail');
function do_skip_mail( ){
global $f3p_fail;
if(!$f3p_fail){
return true; // DO NOT SEND E-MAIL
}
}
add_action("wpcf7_mail_sent", "wpcf7_on_mail_sent");
function wpcf7_on_mail_sent($cf7) {
global $f3p_fail;
if(!$f3p_fail) {
$submission = WPCF7_Submission::get_instance();
$submission->set_status('mail_failed'); // my plugin hack
}
return $cf7;
}
anybody have any other solutions? on_sent_ok is being deprecated. therefore I guess you'd have to add a js listener for wpcf7mailsent, check your error message for a specific string and then change the classes to show the error
thanks J