Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Created January 24, 2016 19:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2ndkauboy/25c50c0540c9635c5a63 to your computer and use it in GitHub Desktop.
Save 2ndkauboy/25c50c0540c9635c5a63 to your computer and use it in GitHub Desktop.
Enables a debugger for the contact form 7 plugin that will add the error info to the AJAX response
<?php
/**
* Plugin Name: Debug for Contact Form 7
* Description: Enables a debugger for the contact form 7 plugin that will add the error info to the AJAX response
* Version: 1.0.0
* Author: Bernhard Kau
* Author URI: https://kau-boys.de
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0
*/
/**
* @param array $items The items for the JSON response
* @param array $result The result of the mail submission
*
* @global PHPMailer $phpmailer The global PHPMailer object
*
* @return array The items array
*/
function debug_for_contact_form_7_add_error_to_ajax_response( $items, $result ) {
if ( 'mail_failed' == $result['status'] ) {
global $phpmailer;
$items['errorInfo'] = $phpmailer->ErrorInfo;
}
return $items;
}
add_action( 'wpcf7_ajax_json_echo', 'debug_for_contact_form_7_add_error_to_ajax_response', 10, 2 );
@jolution
Copy link

jolution commented Nov 3, 2020

The status text for a spam report can also be "spam". Maybe an if ($result['status'] == "spam") would be useful as an addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment