summaryrefslogtreecommitdiff
path: root/Postman/Postman.php
diff options
context:
space:
mode:
Diffstat (limited to 'Postman/Postman.php')
-rw-r--r--Postman/Postman.php95
1 files changed, 71 insertions, 24 deletions
diff --git a/Postman/Postman.php b/Postman/Postman.php
index b0f70e0..1610da5 100644
--- a/Postman/Postman.php
+++ b/Postman/Postman.php
@@ -19,6 +19,14 @@ class Postman {
const ADMINISTRATOR_ROLE_NAME = 'administrator';
const MANAGE_POSTMAN_CAPABILITY_NAME = 'manage_postman_smtp';
const MANAGE_POSTMAN_CAPABILITY_LOGS = 'manage_postman_logs';
+
+ /**
+ * Use the text domain directly instead of this constant, as it
+ * causes issues with https://translate.wordpress.org.
+ *
+ * @deprecated
+ * @see https://github.com/yehudah/Post-SMTP/issues/1#issuecomment-421940923
+ */
const TEXT_DOMAIN = 'post-smtp';
private $logger;
@@ -30,7 +38,7 @@ class Postman {
/**
* The constructor
*
- * @param unknown $rootPluginFilenameAndPath
+ * @param mixed $rootPluginFilenameAndPath
* - the __FILE__ of the caller
*/
public function __construct( $rootPluginFilenameAndPath, $version ) {
@@ -56,11 +64,12 @@ class Postman {
require_once 'Postman-Email-Log/PostmanEmailLogPostType.php';
require_once 'Postman-Mail/PostmanMyMailConnector.php';
require_once 'Postman-Mail/PostmanContactForm7.php';
+ require_once 'Phpmailer/PostsmtpMailer.php';
//require_once 'Postman-Mail/PostmanWooCommerce.php';
// get plugin metadata - alternative to get_plugin_data
$this->pluginData = array(
- 'name' => __( 'Postman SMTP', Postman::TEXT_DOMAIN ),
+ 'name' => __( 'Postman SMTP', 'post-smtp' ),
'version' => $version,
);
@@ -83,13 +92,21 @@ class Postman {
// register the email transports
$this->registerTransports( $rootPluginFilenameAndPath );
- // store an instance of the WpMailBinder
- $this->wpMailBinder = PostmanWpMailBinder::getInstance();
+ // store an instance of the WpMailBinder
+ $this->wpMailBinder = PostmanWpMailBinder::getInstance();
- // bind to wp_mail - this has to happen before the "init" action
- // this design allows other plugins to register a Postman transport and call bind()
- // bind may be called more than once
- $this->wpMailBinder->bind();
+ $mailer = PostmanOptions::getInstance()->getSmtpMailer();
+ $this->logger->trace( 'SMTP Mailer: ' . $mailer );
+
+ if ( $mailer && $mailer !== 'phpmailer') {
+
+ // bind to wp_mail - this has to happen before the "init" action
+ // this design allows other plugins to register a Postman transport and call bind()
+ // bind may be called more than once
+ $this->wpMailBinder->bind();
+ } else {
+ PostmanWpMailBinder::getInstance()->bound = true;
+ }
// registers the custom post type for all callers
PostmanEmailLogPostType::automaticallyCreatePostType();
@@ -163,9 +180,9 @@ 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 - you better upgrade, but we can try to fix it.', Postman::TEXT_DOMAIN );
- $text = __( 'Click here to fix', Postman::TEXT_DOMAIN );
+ $title = __( 'Post SMTP notice!', 'post-smtp' );
+ $intro = __( 'WPML is installed and has a known bug with Post SMTP and few other plugins - you better upgrade, but we can try to fix it.', 'post-smtp' );
+ $text = __( 'Click here to fix', 'post-smtp' );
$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 );
@@ -305,7 +322,8 @@ class Postman {
// I've adopted their error message as well, for shits and giggles .... :D
$reflFunc = new ReflectionFunction( 'wp_mail' );
- $message = __( 'Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', Postman::TEXT_DOMAIN );
+ $message = __( 'Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', 'post-smtp' );
+
$plugin_full_path = $reflFunc->getFileName();
if ( strpos( $plugin_full_path, 'plugins' ) !== false ) {
@@ -323,6 +341,12 @@ class Postman {
}
$message .= '<br><strong>More info that may help</strong> - ' . $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
+
+ // PHPmailer Recommandation
+ ob_start();
+ Postman::getMailerTypeRecommend();
+ $message .= ob_get_clean();
+
$this->messageHandler->addError( $message );
}
} else {
@@ -359,6 +383,25 @@ class Postman {
}
}
+ public static function getMailerTypeRecommend() {
+ ?>
+ <div>
+ <p style="font-size: 18px; font-weight: bold;">Please notice</p>
+ <p style="font-size: 14px; line-height: 1.7;">
+ <?php _e('Post SMTP v2 includes and new feature called: <b>Mailer Type</b>.', 'post-smtp' ); ?><br>
+ <?php _e('I highly recommend to change and <strong>TEST</strong> Post SMTP with the value <code>PHPMailer</code>.', 'post-smtp' ); ?><br>
+ <?php _e('if it will not work properly you can change back to the default value: <code>PostSMTP</code>.', 'post-smtp' ); ?><br>
+ <a target="_blank" href="<?php echo POST_URL; ?>/style/images/mailer-type.gif">
+ <figure>
+ <img width="180" src="<?php echo POST_URL; ?>/style/images/mailer-type.gif" alt="how to set mailer type">
+ <figcaption><?php _e('click to enlarge image.', 'post-smtp' ); ?></figcaption>
+ </figure>
+ </a>
+ </p>
+ </div>
+ <?php
+ }
+
/**
* Returns the plugin version number and name
* Part of the Postman API
@@ -382,8 +425,8 @@ class Postman {
}
$msg = PostmanTransportRegistry::getInstance()->getReadyMessage();
$message = sprintf( $msg['message'] );
- $goToSettings = sprintf( '<a href="%s">%s</a>', PostmanUtils::getSettingsPageUrl(), __( 'Settings', Postman::TEXT_DOMAIN ) );
- $goToEmailLog = sprintf( '%s', _x( 'Email Log', 'The log of Emails that have been delivered', Postman::TEXT_DOMAIN ) );
+ $goToSettings = sprintf( '<a href="%s">%s</a>', PostmanUtils::getSettingsPageUrl(), __( 'Settings', 'post-smtp' ) );
+ $goToEmailLog = sprintf( '%s', _x( 'Email Log', 'The log of Emails that have been delivered', 'post-smtp' ) );
if ( PostmanOptions::getInstance()->isMailLoggingEnabled() ) {
$goToEmailLog = sprintf( '<a href="%s">%s</a>', PostmanUtils::getEmailLogPageUrl(), $goToEmailLog );
}
@@ -404,15 +447,19 @@ class Postman {
* The Gmail API used to be a separate plugin which was registered when that plugin
* was loaded. But now both the SMTP, Gmail API and other transports are registered here.
*
- * @param unknown $pluginData
+ * @param mixed $pluginData
*/
private function registerTransports( $rootPluginFilenameAndPath ) {
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanDefaultModuleTransport( $rootPluginFilenameAndPath ) );
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanSmtpModuleTransport( $rootPluginFilenameAndPath ) );
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanGmailApiModuleTransport( $rootPluginFilenameAndPath ) );
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanMandrillTransport( $rootPluginFilenameAndPath ) );
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanSendGridTransport( $rootPluginFilenameAndPath ) );
- PostmanTransportRegistry::getInstance()->registerTransport( new PostmanMailgunTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry = PostmanTransportRegistry::getInstance();
+
+ $postman_transport_registry->registerTransport( new PostmanDefaultModuleTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry->registerTransport( new PostmanSmtpModuleTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry->registerTransport( new PostmanGmailApiModuleTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry->registerTransport( new PostmanMandrillTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry->registerTransport( new PostmanSendGridTransport( $rootPluginFilenameAndPath ) );
+ $postman_transport_registry->registerTransport( new PostmanMailgunTransport( $rootPluginFilenameAndPath ) );
+
+ do_action( 'postsmtp_register_transport', $postman_transport_registry );
}
/**
@@ -433,12 +480,12 @@ class Postman {
$shortLocale = substr( get_locale(), 0, 2 );
if ( $shortLocale != 'en' ) {
$langDir = 'post-smtp/Postman/languages';
- $success = load_plugin_textdomain( Postman::TEXT_DOMAIN, false, $langDir );
+ $success = load_plugin_textdomain( 'post-smtp', false, $langDir );
if ( $this->logger->isDebug() ) {
if ( $success ) {
$this->logger->debug( sprintf( 'local translation file loaded for locale=%s', get_locale() ) );
} else {
- $this->logger->debug( sprintf( 'failed to load local translation file: locale=%s file=%s/%s-%s.mo', get_locale(), $langDir, Postman::TEXT_DOMAIN, get_locale() ) );
+ $this->logger->debug( sprintf( 'failed to load local translation file: locale=%s file=%s/%s-%s.mo', get_locale(), $langDir, 'post-smtp', get_locale() ) );
}
}
}
@@ -460,7 +507,7 @@ if ( ! function_exists( 'str_getcsv' ) ) {
/**
* PHP version less than 5.3 don't have str_getcsv natively.
*
- * @param unknown $string
+ * @param mixed $string
* @return multitype:
*/
function str_getcsv( $string ) {