/** * Important: bind() may be called multiple times * * Replace wp_mail() after making sure: * 1) the plugin has not already bound to wp_mail and * 2) wp_mail is available for use * 3) the plugin is properly configured. * 4) the plugin's prerequisites are met. */ function bind() { if (!$this->bound) { $binderOptions = PostmanOptions::getInstance(); $binderAuthorizationToken = PostmanOAuthToken::getInstance(); $ready = true; if (function_exists('wp_mail')) { // If the function exists, it's probably because another plugin has // replaced the pluggable function first, and we set an error flag. // this is an error message because it is a Bind error $this->logger->error('wp_mail is already bound, Postman can not use it'); $this->bindError = true; } if (!PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($binderOptions, $binderAuthorizationToken)) { // this is a debug message because bound may be called again with a NEW transport that IS configured // this is a debug message because it is not up to the Binder to report transport errors $this->logger->debug('Transport is not configured and ready'); $ready = false; } if (!PostmanPreRequisitesCheck::isReady()) { // this is a debug message because it is not up to the Binder to report transport errors $this->logger->debug('Prerequisite check failed'); $ready = false; } if ($ready && !$this->bindError) { $this->logger->debug('Binding to wp_mail()'); $this->replacePluggableFunctionWpMail(); } } }
/** * Important: bind() may be called multiple times * * Replace wp_mail() after making sure: * 1) the plugin has not already bound to wp_mail and * 2) wp_mail is available for use * 3) the plugin is properly configured. * 4) the plugin's prerequisites are met. */ function bind() { if (!$this->bound) { $ready = true; if (function_exists('wp_mail')) { // If the function exists, it's probably because another plugin has // replaced the pluggable function first, and we set an error flag. // this is an error message because it is a Bind error if ($this->logger->isTrace()) { $this->logger->trace('wp_mail is already bound, Postman can not use it'); } $this->bindError = true; $ready = false; } if (!PostmanPreRequisitesCheck::isReady()) { // this is a debug message because it is not up to the Binder to report transport errors if ($this->logger->isTrace()) { $this->logger->trace('Prerequisite check failed'); } $ready = false; } if ($ready) { if ($this->logger->isTrace()) { $this->logger->trace('Binding to wp_mail()'); } $this->replacePluggableFunctionWpMail(); } } }
/** * Print the human-readable plugin state */ public function print_postman_status() { if (!PostmanPreRequisitesCheck::isReady()) { printf('<p><span style="color:red">%s</span></p>', __('Error: Postman is missing a required PHP library.', Postman::TEXT_DOMAIN)); } else { if ($this->wpMailBinder->isUnboundDueToException()) { printf('<p><span style="color:red">%s</span></p>', __('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)); } else { if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) { printf('<p><span style="background-color:yellow">%s</span></p>', __('Postman is in <em>non-Production</em> mode and is dumping all emails.', Postman::TEXT_DOMAIN)); } else { if (PostmanTransportRegistry::getInstance()->getSelectedTransport()->isConfiguredAndReady()) { printf('<p class="wp-menu-image dashicons-before dashicons-email"> %s </p>', sprintf(_n('<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> email.', '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> emails.', PostmanState::getInstance()->getSuccessfulDeliveries(), Postman::TEXT_DOMAIN), PostmanState::getInstance()->getSuccessfulDeliveries())); } else { printf('<p><span style="color:red">%s</span></p>', __('Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN)); } } $currentTransport = PostmanTransportRegistry::getInstance()->getActiveTransport(); $deliveryDetails = $currentTransport->getDeliveryDetails($this->options); printf('<p>%s</p>', $deliveryDetails); } } }
/** * Print the human-readable plugin state */ public function print_postman_status() { if (!PostmanPreRequisitesCheck::isReady()) { printf('<p><span style="color:red">%s</span></p>', __('Error: Postman is missing a required PHP library.', 'postman-smtp')); } else { if ($this->wpMailBinder->isUnboundDueToException()) { printf('<p><span style="color:red">%s</span></p>', __('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-smtp')); } else { if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) { printf('<p><span style="background-color:yellow">%s</span></p>', __('Postman is in <em>non-Production</em> mode and is dumping all emails.', 'postman-smtp')); } else { if (PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($this->options, $this->authorizationToken)) { printf('<p class="wp-menu-image dashicons-before dashicons-email"> %s </p>', sprintf(_n('<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> email.', '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> emails.', PostmanStats::getInstance()->getSuccessfulDeliveries(), 'postman-smtp'), PostmanStats::getInstance()->getSuccessfulDeliveries())); $currentTransport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $deliveryDetails = $currentTransport->getDeliveryDetails($this->options); printf('<p>%s</p>', $deliveryDetails); } else { printf('<p><span>%s %s</span></p>', __('Postman is <em>not</em> handling email delivery.', 'postman-smtp'), sprintf(__('<a href="%s">Configure</a> the plugin.', 'postman-smtp'), PostmanUtils::getSettingsPageUrl())); } } } } }
/** * Options page callback */ public function outputDefaultContent() { // Set class property print '<div class="wrap">'; $this->displayTopNavigation(); if (PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($this->options, $this->authorizationToken) && PostmanPreRequisitesCheck::isReady()) { if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) { printf('<p><span style="background-color:yellow">%s</span></p>', __('Postman is in <em>non-Production</em> mode and is dumping all emails.', 'postman-smtp')); } else { printf('<p><span style="color:green;padding:2px 5px; font-size:1.2em">%s</span></p>', __('Postman is configured.', 'postman-smtp')); $currentTransport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $deliveryDetails = $currentTransport->getDeliveryDetails($this->options); printf('<p style="margin:0 10px"><span>%s</span></p>', $deliveryDetails); } /* translators: where %d is the number of emails delivered */ printf('<p style="margin:10px 10px"><span>%s', sprintf(_n('Postman has delivered <span style="color:green">%d</span> email for you.', 'Postman has delivered <span style="color:green">%d</span> emails for you.', PostmanStats::getInstance()->getSuccessfulDeliveries(), 'postman-smtp'), PostmanStats::getInstance()->getSuccessfulDeliveries())); if ($this->options->isMailLoggingEnabled()) { print ' '; printf('<a href="%s">%s</a>.</span></p>', PostmanUtils::getEmailLogPageUrl(), __('View the log', 'postman-smtp')); } if (PostmanState::getInstance()->isTimeToReviewPostman() && !PostmanOptions::getInstance()->isNew()) { print '</br><hr width="70%"></br>'; /* translators: where %s is the URL to the WordPress.org review and ratings page */ printf('%s</span></p>', sprintf(__('Please consider <a href="%s">leaving a review</a> to help spread the word! :D', 'postman-smtp'), 'https://wordpress.org/support/view/plugin-reviews/postman-smtp?filter=5')); } } else { printf('<p><span style="color:red; padding:2px 5px; font-size:1.1em">%s</span></p>', __('Postman is <em>not</em> handling email delivery.', 'postman-smtp')); if ($this->options->isNew()) { printf('<h3>%s</h3>', __('Thank-you for choosing Postman!', 'postman-smtp')); /* translators: where %s is the URL of the Setup Wizard */ printf('<p><span>%s</span></p>', sprintf(__('Let\'s get started! All users are strongly encouraged to <a href="%s">run the Setup Wizard</a>.', 'postman-smtp'), $this->getPageUrl(self::CONFIGURATION_WIZARD_SLUG))); } } }
/** * Options page callback */ public function outputDefaultContent() { // Set class property print '<div class="wrap">'; $this->displayTopNavigation(); if (!PostmanPreRequisitesCheck::isReady()) { printf('<p><span style="color:red; padding:2px 0; font-size:1.1em">%s</span></p>', __('Postman is unable to run. Email delivery is being handled by WordPress (or another plugin).', Postman::TEXT_DOMAIN)); } else { $statusMessage = PostmanTransportRegistry::getInstance()->getReadyMessage(); if (PostmanTransportRegistry::getInstance()->getActiveTransport()->isConfiguredAndReady()) { if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) { printf('<p><span style="background-color:yellow">%s</span></p>', $statusMessage); } else { printf('<p><span style="color:green;padding:2px 0; font-size:1.1em">%s</span></p>', $statusMessage); } } else { printf('<p><span style="color:red; padding:2px 0; font-size:1.1em">%s</span></p>', $statusMessage); } $this->printDeliveryDetails(); /* translators: where %d is the number of emails delivered */ print '<p style="margin:10px 10px"><span>'; printf(_n('Postman has delivered <span style="color:green">%d</span> email.', 'Postman has delivered <span style="color:green">%d</span> emails.', PostmanState::getInstance()->getSuccessfulDeliveries(), Postman::TEXT_DOMAIN), PostmanState::getInstance()->getSuccessfulDeliveries()); if ($this->options->isMailLoggingEnabled()) { print ' '; printf(__('The last %d email attempts are recorded <a href="%s">in the log</a>.', Postman::TEXT_DOMAIN), PostmanOptions::getInstance()->getMailLoggingMaxEntries(), PostmanUtils::getEmailLogPageUrl()); } print '</span></p>'; } if ($this->options->isNew()) { printf('<h3 style="padding-top:10px">%s</h3>', __('Thank-you for choosing Postman!', Postman::TEXT_DOMAIN)); /* translators: where %s is the URL of the Setup Wizard */ printf('<p><span>%s</span></p>', sprintf(__('Let\'s get started! All users are strongly encouraged to <a href="%s">run the Setup Wizard</a>.', Postman::TEXT_DOMAIN), $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG))); printf('<p><span>%s</span></p>', sprintf(__('Alternately, <a href="%s">manually configure</a> your own settings and/or modify advanced options.', Postman::TEXT_DOMAIN), $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_SLUG))); } else { if (PostmanState::getInstance()->isTimeToReviewPostman() && !PostmanOptions::getInstance()->isNew()) { print '</br><hr width="70%"></br>'; /* translators: where %s is the URL to the WordPress.org review and ratings page */ printf('%s</span></p>', sprintf(__('Please consider <a href="%s">leaving a review</a> to help spread the word! :D', Postman::TEXT_DOMAIN), 'https://wordpress.org/support/view/plugin-reviews/postman-smtp?filter=5')); } printf('<p><span>%s :-)</span></p>', sprintf(__('Postman needs translators! Please take a moment to <a href="%s">translate a few sentences on-line</a>', Postman::TEXT_DOMAIN), 'https://translate.wordpress.org/projects/wp-plugins/postman-smtp/stable')); } printf('<p><span>%s</span></p>', __('<b style="background-color:yellow">New for v1.7!</style></b> Send mail with the Mandrill or SendGrid APIs.', Postman::TEXT_DOMAIN)); }