From f627e0d82c18a1ed60eead38ce38746ded43adc6 Mon Sep 17 00:00:00 2001 From: yehudah Date: Sun, 17 Feb 2019 20:56:03 +0000 Subject: = 1.9.7 - 2019-02-17 * New: Fallback Feature - Configure a backup SMTP when emails are failing. * New: WordPress Multisite compability - with global settings. * New: Email Log capability - give other user cheking the logs. * Fixed: compatibility with mailster plugin * Fixed: Mandrill exception bug - Thanks to Niels de Blaauw from Level-Level --- .../PostmanEmailLogController.php | 2 +- .../Postman-Email-Log/PostmanEmailLogService.php | 41 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'Postman/Postman-Email-Log') diff --git a/Postman/Postman-Email-Log/PostmanEmailLogController.php b/Postman/Postman-Email-Log/PostmanEmailLogController.php index d1f0057..be08232 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogController.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogController.php @@ -302,7 +302,7 @@ class PostmanEmailLogController { $pageTitle = sprintf( __( '%s Email Log', Postman::TEXT_DOMAIN ), __( 'Post SMTP', Postman::TEXT_DOMAIN ) ); $pluginName = _x( 'Email Log', 'The log of Emails that have been delivered', Postman::TEXT_DOMAIN ); - $page = add_submenu_page( PostmanViewController::POSTMAN_MENU_SLUG, $pageTitle, $pluginName, 'read_private_posts', 'postman_email_log', array( $this, 'postman_render_email_page' ) ); + $page = add_submenu_page( PostmanViewController::POSTMAN_MENU_SLUG, $pageTitle, $pluginName, Postman::MANAGE_POSTMAN_CAPABILITY_LOGS, 'postman_email_log', array( $this, 'postman_render_email_page' ) ); // When the plugin options page is loaded, also load the stylesheet add_action( 'admin_print_styles-' . $page, array( diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index 103dcc1..dd51974 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -16,6 +16,10 @@ if ( ! class_exists( 'PostmanEmailLog' ) ) { public $originalSubject; public $originalMessage; public $originalHeaders; + + public function setStatusMessage( $message ) { + $this->statusMessage .= $message; + } } } @@ -95,7 +99,7 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { public function writeFailureLog( PostmanEmailLog $log, PostmanMessage $message = null, $transcript, PostmanModuleTransport $transport, $statusMessage ) { if ( PostmanOptions::getInstance()->isMailLoggingEnabled() ) { $this->createLog( $log, $message, $transcript, $statusMessage, false, $transport ); - $this->writeToEmailLog( $log ); + $this->writeToEmailLog( $log,$message ); } } @@ -104,21 +108,43 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { * * From http://wordpress.stackexchange.com/questions/8569/wp-insert-post-php-function-and-custom-fields */ - private function writeToEmailLog( PostmanEmailLog $log ) { + private function writeToEmailLog( PostmanEmailLog $log, PostmanMessage $message = null ) { + + $options = PostmanOptions::getInstance(); + + $this->checkForLogErrors( $log ,$message ); + $new_status = $log->statusMessage; + + if ( $options->is_fallback && empty( $log->statusMessage ) ) { + $new_status = 'Sent ( ** Fallback ** )'; + } + + if ( $options->is_fallback && ! empty( $log->statusMessage ) ) { + $new_status = '( ** Fallback ** ) ' . $log->statusMessage; + } - $this->checkForLogErrors( $log ); // nothing here is sanitized as WordPress should take care of // making database writes safe $my_post = array( 'post_type' => PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG, 'post_title' => $log->subject, 'post_content' => $log->body, - 'post_excerpt' => $log->statusMessage, + 'post_excerpt' => $new_status, 'post_status' => PostmanEmailLogService::POSTMAN_CUSTOM_POST_STATUS_PRIVATE, ); // Insert the post into the database (WordPress gives us the Post ID) - $post_id = wp_insert_post( $my_post ); + $post_id = wp_insert_post( $my_post, true ); + + if ( is_wp_error( $post_id ) ) { + add_action( 'admin_notices', function() use( $post_id ) { + $class = 'notice notice-error'; + $message = $post_id->get_error_message(); + + printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); + }); + } + $this->logger->debug( sprintf( 'Saved message #%s to the database', $post_id ) ); $this->logger->trace( $log ); @@ -155,7 +181,7 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $purger->truncateLogItems( PostmanOptions::getInstance()->getMailLoggingMaxEntries() ); } - private function checkForLogErrors( PostmanEmailLog $log ) { + private function checkForLogErrors( PostmanEmailLog $log, $postMessage ) { $message = __( 'You getting this message because an error detected while delivered your email.', Postman::TEXT_DOMAIN ); $message .= "\r\n" . sprintf( __( 'For the domain: %1$s',Postman::TEXT_DOMAIN ), get_bloginfo('url') ); $message .= "\r\n" . __( 'The log to paste when you open a support issue:', Postman::TEXT_DOMAIN ) . "\r\n"; @@ -180,7 +206,8 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $notifyer = new PostmanMailNotify; } - $notify = new PostmanNotify( $notifyer, $message ); + // Notifications + $notify = new PostmanNotify( $notifyer ); $notify->send($message, $log); $notify->push_to_chrome($log->statusMessage); } -- cgit v1.2.3