summaryrefslogtreecommitdiff
path: root/Postman
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-12-23 23:23:04 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-12-23 23:23:04 +0000
commit707146a8ea285d5f51e112dabad57785b38f3b3a (patch)
tree1ce0952fd8a89cdc8308f32d09763169cb017dc4 /Postman
parent6eabf1113cb0837b3ee83c058d9d68fca72e1b71 (diff)
downloadPost-SMTP-707146a8ea285d5f51e112dabad57785b38f3b3a.zip
= 1.8 - 2017-12-24
* New: Mailgun API integration * New: New filter controls * New: WPML conflict fix * Fix: Minor old bugs
Diffstat (limited to 'Postman')
-rw-r--r--Postman/Postman-Mail/PostmanMailgunMailEngine.php38
-rw-r--r--Postman/Postman-Mail/PostmanMailgunTransport.php2
-rw-r--r--Postman/Postman-Mail/PostmanTransportRegistry.php2
-rw-r--r--Postman/Postman.php33
-rw-r--r--Postman/PostmanInstaller.php4
-rw-r--r--Postman/PostmanViewController.php2
6 files changed, 74 insertions, 7 deletions
diff --git a/Postman/Postman-Mail/PostmanMailgunMailEngine.php b/Postman/Postman-Mail/PostmanMailgunMailEngine.php
index 360201c..58def41 100644
--- a/Postman/Postman-Mail/PostmanMailgunMailEngine.php
+++ b/Postman/Postman-Mail/PostmanMailgunMailEngine.php
@@ -90,7 +90,7 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
$recipient->log( $this->logger, 'To' );
$recipients[] = $recipient->getEmail();
}
- $this->mailgunMessage['to'] = implode( ',', $recipients );
+ $this->mailgunMessage['to'] = $recipients;
// add the cc recipients
$recipients = array();
@@ -164,7 +164,7 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
$mg = Mailgun::create( $this->apiKey );
// Make the call to the client.
- $result = $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+ $result = $this->processSend( $mg );
if ( $this->logger->isInfo() ) {
$this->logger->info( sprintf( 'Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1 ) );
@@ -181,6 +181,40 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
}
}
+
+ private function processSend( $mg ) {
+
+ if ( count( $this->mailgunMessage['to'] ) == 1 ) {
+
+ return $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+ } else {
+ $chunks = array_chunk( $this->mailgunMessage['to'], 1000, true );
+
+ $result = array();
+ foreach ( $chunks as $key => $emails ) {
+ $this->mailgunMessage['to'] = $emails;
+ $recipient_variables = $this->getRecipientVariables( $emails );
+ $this->mailgunMessage['recipient-variables'] = $recipient_variables;
+
+ $result[] = $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+
+ // Don't have a reason just wait a bit before sending the next chunk
+ sleep(2);
+ }
+
+ return $result;
+ }
+ }
+
+ private function getRecipientVariables( $emails ) {
+ $recipient_variables = array();
+ foreach ( $emails as $key => $email ) {
+ $recipient_variables[$email] = array( 'id' => $key );
+ }
+
+ return json_encode( $recipient_variables );
+ }
+
private function addHeader( $name, $value, $deprecated = '' ) {
if ( $value && ! empty( $value ) ) {
$this->mailgunMessage['h:' . $name] = $value;
diff --git a/Postman/Postman-Mail/PostmanMailgunTransport.php b/Postman/Postman-Mail/PostmanMailgunTransport.php
index c3565ea..9a5e9d2 100644
--- a/Postman/Postman-Mail/PostmanMailgunTransport.php
+++ b/Postman/Postman-Mail/PostmanMailgunTransport.php
@@ -154,7 +154,7 @@ class PostmanMailgunTransport extends PostmanAbstractModuleTransport implements
$overrideItem ['auth_items'] = array(
array(
'selected' => true,
- 'name' => __( 'API Kkey', Postman::TEXT_DOMAIN ),
+ 'name' => __( 'API Key', Postman::TEXT_DOMAIN ),
'value' => 'api_key',
),
);
diff --git a/Postman/Postman-Mail/PostmanTransportRegistry.php b/Postman/Postman-Mail/PostmanTransportRegistry.php
index ceaef7c..77654eb 100644
--- a/Postman/Postman-Mail/PostmanTransportRegistry.php
+++ b/Postman/Postman-Mail/PostmanTransportRegistry.php
@@ -234,7 +234,7 @@ class PostmanTransportRegistry {
return __( 'Postman is configured.', Postman::TEXT_DOMAIN );
}
} else {
- return '<div class="updated error otgs-is-dismissible settings-error notice is-dismissible" style="20px;">' . __( 'Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN ) . '</div>';
+ return __( 'Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN );
}
}
}
diff --git a/Postman/Postman.php b/Postman/Postman.php
index 7eb512a..153257b 100644
--- a/Postman/Postman.php
+++ b/Postman/Postman.php
@@ -117,6 +117,14 @@ class Postman {
'on_plugins_loaded',
) );
+ $active_plugins = (array) get_option( 'active_plugins', array() );
+ if ( in_array( 'sitepress-multilingual-cms/sitepress.php', $active_plugins ) && !get_option( 'postman_wpml_fixed' ) ) {
+ add_action( 'admin_notices', array( $this, 'post_smtp_wpml_admin_notice' ) );
+
+ // Temp: Just a quick solution, need to find a better option.
+ add_action( 'admin_init', array( $this, 'postman_fix_wpml' ) );
+ }
+
// hook on the wp_loaded event
add_action( 'wp_loaded', array(
$this,
@@ -136,6 +144,31 @@ class Postman {
) );
}
+ public function post_smtp_wpml_admin_notice() {
+ $class = 'notice notice-error';
+ $title = __( 'Post SMTP notice!', Postman::TEXT_DOMAIN );
+ $intro = __( 'WPML is installed and has a known bug with Post SMTP and few other plugins.', Postman::TEXT_DOMAIN );
+ $text = __( 'Click here to fix', Postman::TEXT_DOMAIN );
+ $message = '<br><a href="' . esc_url( add_query_arg( 'action', 'postman_fix_wpml', get_permalink() ) ) . '">' . $text . '</a>';
+
+ printf( '<div class="%1$s"><h2>%2$s</h2><p>%3$s</p><p>%4$s</p></div>', esc_attr( $class ), $title, $intro, $message );
+ }
+
+ public function postman_fix_wpml() {
+ if ( isset( $_GET['action'] ) && $_GET['action'] == 'postman_fix_wpml' ) {
+ $wpml_file_path = WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/utilities/wpml-data-encryptor.class.php';
+
+ if ( file_exists( $wpml_file_path ) ) {
+ $content = file_get_contents( $wpml_file_path );
+ $content = str_replace( "require_once ABSPATH . '/wp-includes/pluggable.php';", "//require_once ABSPATH . '/wp-includes/pluggable.php';", $content );
+ file_put_contents( $wpml_file_path, $content );
+ }
+
+ update_option( 'postman_wpml_fixed', true );
+ wp_redirect( esc_url( remove_query_arg( 'action' ) ) );
+ }
+ }
+
/**
* Functions to execute on the plugins_loaded event
*
diff --git a/Postman/PostmanInstaller.php b/Postman/PostmanInstaller.php
index 812f122..4b2603b 100644
--- a/Postman/PostmanInstaller.php
+++ b/Postman/PostmanInstaller.php
@@ -42,7 +42,7 @@ class PostmanInstaller {
$this->addCapability();
}
- $this->add_activation_redirect();
+ //$this->add_activation_redirect();
}
function add_activation_redirect() {
@@ -52,7 +52,7 @@ class PostmanInstaller {
return; }
// Add the transient to redirect
- set_transient( '_post_activation_redirect', true, 30 );
+ //set_transient( '_post_activation_redirect', true, 30 );
}
/**
diff --git a/Postman/PostmanViewController.php b/Postman/PostmanViewController.php
index 60274dc..991ea8a 100644
--- a/Postman/PostmanViewController.php
+++ b/Postman/PostmanViewController.php
@@ -36,7 +36,7 @@ if ( ! class_exists( 'PostmanViewController' ) ) {
// initialize the scripts, stylesheets and form fields
add_action( 'admin_init', array( $this, 'registerStylesAndScripts' ), 0 );
- add_action( 'admin_init', array( $this, 'do_activation_redirect' ) );
+ //add_action( 'admin_init', array( $this, 'do_activation_redirect' ) );
}