/** * */ public function sendTestMailAction() { if (!$this->_verifyNonce('psn-form-test-mail')) { $this->getAdminNotices()->persistError(__('Invalid access.', 'psn')); $this->_gotoIndex(); } $this->_email = new IfwPsn_Wp_Email(); $subject = sprintf(__('Test Email from %s', 'psn'), $this->_pm->getEnv()->getName()); $body = IfwPsn_Wp_Proxy_Filter::apply('psn_send_test_mail_body', sprintf(__('This is a test email generated by %s on %s (%s)', 'psn'), $this->_pm->getEnv()->getName(), IfwPsn_Wp_Proxy_Blog::getName(), IfwPsn_Wp_Proxy_Blog::getUrl()), $this->_email); switch (trim($this->_request->get('recipient'))) { case 'custom': $recipient = esc_attr($_POST['custom_recipient']); break; case 'admin': default: $recipient = IfwPsn_Wp_Proxy_Blog::getAdminEmail(); break; } $recipient = IfwPsn_Wp_Proxy_Filter::apply('psn_send_test_mail_recipient', $recipient); if (empty($recipient)) { $resultMsg = __('Invalid recipient.', 'psn') . ' ' . __('Test email could not be sent.', 'psn'); $this->getAdminNotices()->persistError($resultMsg); } else { $this->_email->setTo($recipient)->setSubject($subject)->setMessage($body); IfwPsn_Wp_Proxy_Action::doAction('psn_send_test_mail', $this->_email); if ($this->_email->send()) { // mail sent successfully $resultMsg = __('Test email has been sent successfully.', 'psn'); $this->getAdminNotices()->persistUpdated($resultMsg); IfwPsn_Wp_Proxy_Action::doAction('psn_send_test_mail_success', $this); } else { // email could not be sent $resultMsg = __('Test email could not be sent.', 'psn'); $this->getAdminNotices()->persistError($resultMsg); IfwPsn_Wp_Proxy_Action::doAction('psn_send_test_mail_failure', $this); } IfwPsn_Wp_Proxy_Action::doAction('psn_after_test_email_send', $this->_email); } $this->_gotoIndex(); }
/** * Get the blog admins display_name (if there is a user matching the blog admin email) * @return WP_User|null */ public static function getAdminDisplayName() { $adminDisplayName = null; if (function_exists('get_user_by')) { $user = self::getByEmail(IfwPsn_Wp_Proxy_Blog::getAdminEmail()); if ($user instanceof WP_User) { $adminDisplayName = $user->display_name; } } else { $u = IfwPsn_Wp_ORM_Model::factory('IfwPsn_Wp_Model_User')->where_equal('user_email', IfwPsn_Wp_Proxy_Blog::getAdminEmail())->find_one(); if ($u instanceof IfwPsn_Wp_Model_User) { $adminDisplayName = $u->get('display_name'); } } return $adminDisplayName; }
/** * Prepares TO, CC and BCC recipients * * @param Psn_Model_Rule $rule * @param $post */ protected function _prepareRecipients(Psn_Model_Rule $rule, $post) { // recipient handling (To, Cc, Bcc) $recipientSelections = array(array('name' => 'recipient_selection', 'modelGetter' => 'getRecipient', 'serviceAdder' => 'addTo', 'custom_field_name' => 'to'), array('name' => 'cc_selection', 'modelGetter' => 'getCcSelect', 'serviceAdder' => 'addCc', 'custom_field_name' => 'cc'), array('name' => 'bcc_selection', 'modelGetter' => 'getBccSelect', 'serviceAdder' => 'addBcc', 'custom_field_name' => 'bcc')); foreach ($recipientSelections as $recSel) { $recipient = $rule->{$recSel}['modelGetter'](); if (in_array('admin', $recipient)) { $this->{$recSel}['serviceAdder'](IfwPsn_Wp_Proxy_Blog::getAdminEmail()); } if (in_array('author', $recipient)) { $this->{$recSel}['serviceAdder'](IfwPsn_Wp_Proxy_User::getEmail($post->post_author)); } // handle dynamic recipients managed by modules IfwPsn_Wp_Proxy_Action::doAction('psn_service_email_' . $recSel['name'], $this); // check for custom recipient $custom_recipient = $rule->get($recSel['custom_field_name']); if (!empty($custom_recipient)) { $custom_recipient = $rule->getReplacer()->replace($custom_recipient); $customRecipientStack = explode(',', $custom_recipient); foreach ($customRecipientStack as $customRecipientEmail) { $this->{$recSel}['serviceAdder'](trim($customRecipientEmail)); } } } }