/**
  */
 function __construct($rootPluginFilenameAndPath)
 {
     $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
     $this->logger = new PostmanLogger(get_class($this));
     if (PostmanOptions::getInstance()->isMailLoggingEnabled()) {
         add_action('admin_menu', array($this, 'postmanAddMenuItem'));
     } else {
         $this->logger->trace('not creating PostmanEmailLog admin menu item');
     }
     if (PostmanUtils::isCurrentPagePostmanAdmin('postman_email_log')) {
         $this->logger->trace('on postman email log page');
         // $this->logger->debug ( 'Registering ' . $actionName . ' Action Post handler' );
         add_action('admin_post_delete', array($this, 'delete_log_item'));
         add_action('admin_post_view', array($this, 'view_log_item'));
         add_action('admin_post_transcript', array($this, 'view_transcript_log_item'));
         add_action('admin_init', array($this, 'handle_bulk_action'));
     }
 }
 /**
  * Check for configuration errors and displays messages to the user
  */
 public function check_for_configuration_errors()
 {
     $options = PostmanOptions::getInstance();
     $authToken = PostmanOAuthToken::getInstance();
     // did Postman fail binding to wp_mail()?
     if ($this->wpMailBinder->isUnboundDueToException()) {
         // this message gets printed on ANY WordPress admin page, as it's a pretty fatal error that
         // may occur just by activating a new plugin
         if (PostmanUtils::isAdmin() && is_admin()) {
             // I noticed the wpMandrill and SendGrid plugins have the exact same error message here
             // I've adopted their error message as well, for shits and giggles .... :D
             $this->messageHandler->addError(__('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'));
             // $this->messageHandler->addError ( __ ( 'Error: Postman is properly configured, but the current theme or another plugin is preventing service.', 'postman-smtp' ) );
         }
     } else {
         if (!$this->wpMailBinder->isBound()) {
             $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
             $scribe = PostmanConfigTextHelperFactory::createScribe($options->getHostname(), $transport);
             $readyToSend = PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($options, $authToken);
             $virgin = $options->isNew();
             if (!$readyToSend && !$virgin) {
                 // if the configuration is broken, and the user has started to configure the plugin
                 // show this error message
                 $message = PostmanTransportRegistry::getInstance()->getCurrentTransport()->getMisconfigurationMessage($scribe, $options, $authToken);
                 if ($message) {
                     // output the warning message
                     $this->logger->warn('Transport has a configuration problem: ' . $message);
                     // on pages that are Postman admin pages only, show this error message
                     if (PostmanUtils::isAdmin() && PostmanUtils::isCurrentPagePostmanAdmin()) {
                         $this->messageHandler->addError($message);
                     }
                 }
             }
             // on pages that are NOT Postman admin pages only, show this error message
             if (!PostmanUtils::isCurrentPagePostmanAdmin() && !$readyToSend) {
                 // on pages that are *NOT* Postman admin pages only....
                 // if the configuration is broken
                 // show this error message
                 add_action('admin_notices', array($this, 'display_configuration_required_warning'));
             }
         }
     }
 }
 /**
  */
 public function registerHooks()
 {
     // only administrators should be able to trigger this
     if (PostmanUtils::isAdmin()) {
         //
         $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
         $this->oauthScribe = PostmanConfigTextHelperFactory::createScribe($this->options->getHostname(), $transport);
         // register Ajax handlers
         new PostmanManageConfigurationAjaxHandler();
         new PostmanGetHostnameByEmailAjaxController();
         new PostmanGetPortsToTestViaAjax();
         new PostmanPortTestAjaxController($this->options);
         new PostmanImportConfigurationAjaxController($this->options);
         new PostmanGetDiagnosticsViaAjax($this->options, $this->authorizationToken);
         new PostmanSendTestEmailAjaxController();
         // register content handlers
         $viewController = new PostmanViewController($this->rootPluginFilenameAndPath, $this->options, $this->authorizationToken, $this->oauthScribe, $this);
         // register action handlers
         $this->registerAdminPostAction(self::PURGE_DATA_SLUG, 'handlePurgeDataAction');
         $this->registerAdminPostAction(PostmanUtils::REQUEST_OAUTH2_GRANT_SLUG, 'handleOAuthPermissionRequestAction');
         if (PostmanUtils::isCurrentPagePostmanAdmin()) {
             $this->checkPreRequisites();
         }
     }
 }
Beispiel #4
0
 /**
  * Check for configuration errors and displays messages to the user
  */
 public function check_for_configuration_errors()
 {
     $options = PostmanOptions::getInstance();
     $authToken = PostmanOAuthToken::getInstance();
     // did Postman fail binding to wp_mail()?
     if ($this->wpMailBinder->isUnboundDueToException()) {
         // this message gets printed on ANY WordPress admin page, as it's a fatal error that
         // may occur just by activating a new plugin
         // log the fatal message
         $this->logger->fatal('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.');
         if (PostmanUtils::isAdmin() && is_admin()) {
             // on any admin pages, show this error message
             // I noticed the wpMandrill and SendGrid plugins have the exact same error message here
             // I've adopted their error message as well, for shits and giggles .... :D
             $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);
             $this->messageHandler->addError($message);
         }
     } else {
         $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
         $scribe = $transport->getScribe();
         $virgin = $options->isNew();
         if (!$transport->isConfiguredAndReady()) {
             // if the configuration is broken, and the user has started to configure the plugin
             // show this error message
             $messages = $transport->getConfigurationMessages();
             foreach ($messages as $message) {
                 if ($message) {
                     // log the warning message
                     $this->logger->warn(sprintf('%s Transport has a configuration problem: %s', $transport->getName(), $message));
                     if (PostmanUtils::isAdmin() && PostmanUtils::isCurrentPagePostmanAdmin()) {
                         // on pages that are Postman admin pages only, show this error message
                         $this->messageHandler->addError($message);
                     }
                 }
             }
         }
         // on pages that are NOT Postman admin pages only, show this error message
         if (PostmanUtils::isAdmin() && !PostmanUtils::isCurrentPagePostmanAdmin() && !$transport->isConfiguredAndReady()) {
             // on pages that are *NOT* Postman admin pages only....
             // if the configuration is broken show this error message
             add_action('admin_notices', array($this, 'display_configuration_required_warning'));
         }
     }
 }
 /**
  * Functions to execute on the init event
  *
  * "Typically used by plugins to initialize. The current user is already authenticated by this time."
  * ref: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request
  */
 public function on_init()
 {
     // only administrators should be able to trigger this
     if (PostmanUtils::isAdmin()) {
         //
         $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
         $this->oauthScribe = $transport->getScribe();
         // register content handlers
         $viewController = new PostmanViewController($this->rootPluginFilenameAndPath, $this->options, $this->authorizationToken, $this->oauthScribe, $this);
         // register action handlers
         $this->registerAdminPostAction(self::PURGE_DATA_SLUG, 'handlePurgeDataAction');
         $this->registerAdminPostAction(self::IMPORT_SETTINGS_SLUG, 'importSettingsAction');
         $this->registerAdminPostAction(PostmanUtils::REQUEST_OAUTH2_GRANT_SLUG, 'handleOAuthPermissionRequestAction');
         if (PostmanUtils::isCurrentPagePostmanAdmin()) {
             $this->checkPreRequisites();
         }
     }
 }