diff options
author | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2018-04-24 03:11:12 +0000 |
---|---|---|
committer | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2018-04-24 03:11:12 +0000 |
commit | ecfab3b1bb489542c68991aca482f9b6e52ff036 (patch) | |
tree | 5df22b85c34e2482ed1e03dc5a0dc78fbdd29886 /Postman | |
parent | ab8b46da49e1b2da2710b5c69c7b411d30138ead (diff) | |
download | Post-SMTP-ecfab3b1bb489542c68991aca482f9b6e52ff036.zip |
didn't noice contact form 7 file was not added to svn
git-svn-id: https://plugins.svn.wordpress.org/post-smtp/trunk@1863329 b8457f37-d9ea-0310-8a92-e5e31aec5664
Diffstat (limited to 'Postman')
-rw-r--r-- | Postman/Postman-Mail/PostmanContactForm7.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Postman/Postman-Mail/PostmanContactForm7.php b/Postman/Postman-Mail/PostmanContactForm7.php new file mode 100644 index 0000000..64f4f5f --- /dev/null +++ b/Postman/Postman-Mail/PostmanContactForm7.php @@ -0,0 +1,39 @@ +<?php +class Postsmtp_ContactForm7 { + + private $result_error; + + public function __construct() { + add_action( 'wpcf7_mail_failed', array( $this, 'save_error' ) ); + add_filter( 'wpcf7_ajax_json_echo', array( $this, 'change_rest_response' ), 10, 2 ); + } + + public function save_error($contact_form) { + $this->result_error = apply_filters( 'postman_wp_mail_result', null ); + } + + public function change_rest_response( $response ) { + if ( $response['status'] == 'mail_failed' ) { + $message = $this->result_error ['exception']->getMessage(); + + if ( ! $message || $message == '' ) { + return $response; + } + + $currentTransport = PostmanOptions::getInstance()->getTransportType(); + $result = json_decode($message); + $is_json = (json_last_error() == JSON_ERROR_NONE); + + switch ($currentTransport) { + case 'gmail_api': + $response['message'] = $is_json ? $result->error->message : $message; + break; + default: + $response['message'] = $is_json ? json_encode(json_decode($message), JSON_PRETTY_PRINT) : $message; + } + } + + return $response; + } + +} |