first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
interface Postman_Notify {
public function send_message( $message );
}

View File

@@ -0,0 +1,29 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class PostmanMailNotify implements Postman_Notify {
public function send_message($message)
{
$notification_emails = PostmanNotifyOptions::getInstance()->get_notification_email();
/**
* Filters The Notification Emails
*
* @notification_emails String
*/
$notification_emails = apply_filters( 'post_smtp_notify_email', $notification_emails );
$domain = get_bloginfo( 'url' );
$notification_emails = explode( ',', $notification_emails );
//Lets start informing authorities ;')
foreach( $notification_emails as $to_email ) {
mail( $to_email, "{$domain}: " . __( 'Post SMTP email error', 'post-smtp' ), $message , '', "-f{$to_email}" );
}
}
}

View File

@@ -0,0 +1,374 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
require_once 'INotify.php';
require_once 'PostmanMailNotify.php';
require_once 'PostmanPushoverNotify.php';
require_once 'PostmanSlackNotify.php';
require_once 'PostmanNotifyOptions.php';
class PostmanNotify {
const NOTIFICATIONS_OPTIONS = 'postman_notifications_options';
const NOTIFICATIONS_SECTION = 'postman_notifications_section';
const NOTIFICATIONS_PUSHOVER_CRED = 'postman_pushover_cred';
const NOTIFICATIONS_SLACK_CRED = 'postman_slack_cred';
const CHROME_EXTENSION = 'postman_chrome_extension';
const NOTIFICATION_EMAIL = 'notification_email';
private $options;
public function __construct() {
$this->options = PostmanNotifyOptions::getInstance();
add_filter( 'post_smtp_admin_tabs', array( $this, 'tabs' ) );
add_action( 'post_smtp_settings_menu', array( $this, 'menu' ) );
add_action( 'post_smtp_settings_fields', array( $this, 'settings' ) );
add_action( 'post_smtp_on_failed', array( $this, 'notify' ), 10, 5 );
add_filter( 'post_smtp_sanitize', array( $this, 'sanitize' ), 10, 3 );
}
public function menu() {
print '<section id="notifications">';
do_settings_sections( self::NOTIFICATIONS_OPTIONS );
$currentKey = $this->options->getNotificationService();
$pushover = $currentKey == 'pushover' ? 'block' : 'none';
$slack = $currentKey == 'slack' ? 'block' : 'none';
$notification_email = $currentKey == 'default' ? 'block' : 'none';
echo '<div id="email_notify" style="display: '.$notification_email.';">';
do_settings_sections( self::NOTIFICATION_EMAIL );
echo '</div>';
echo '<div id="pushover_cred" style="display: ' . $pushover . ';">';
do_settings_sections( self::NOTIFICATIONS_PUSHOVER_CRED );
echo '</div>';
echo '<div id="slack_cred" style="display: ' . $slack . ';">';
do_settings_sections( self::NOTIFICATIONS_SLACK_CRED );
echo '</div>';
do_action( 'post_smtp_notification_settings' );
do_settings_sections( self::CHROME_EXTENSION );
print '</section>';
}
public function sanitize($new_input, $input, $sanitizer) {
// Notifications
$sanitizer->sanitizeString( 'Pushover Service', PostmanNotifyOptions::NOTIFICATION_SERVICE, $input, $new_input, $this->options->getNotificationService() );
$sanitizer->sanitizePassword( 'Pushover Username', PostmanNotifyOptions::PUSHOVER_USER, $input, $new_input, $this->options->getPushoverUser() );
$sanitizer->sanitizePassword( 'Pushover Token', PostmanNotifyOptions::PUSHOVER_TOKEN, $input, $new_input, $this->options->getPushoverToken() );
$sanitizer->sanitizePassword( 'Slack Token', PostmanNotifyOptions::SLACK_TOKEN, $input, $new_input, $this->options->getSlackToken() );
// Chrome extension
$sanitizer->sanitizeString( 'Push Chrome Extension', PostmanNotifyOptions::NOTIFICATION_USE_CHROME, $input, $new_input );
$sanitizer->sanitizePassword( 'Push Chrome Extension UID', PostmanNotifyOptions::NOTIFICATION_CHROME_UID, $input, $new_input, $this->options->getNotificationChromeUid() );
//Email Notification
$sanitizer->sanitizeString( 'Email Notification', PostmanNotifyOptions::NOTIFICATION_EMAIL, $input, $new_input, $this->options->get_notification_email() );
return $new_input;
}
public function tabs($tabs) {
$tabs['notifications'] = __( 'Notifications', 'post-smtp' );
return $tabs;
}
public function settings() {
// Notifications
add_settings_section( self::NOTIFICATIONS_SECTION, _x( 'Notifications Settings', 'Configuration Section Title', 'post-smtp' ), array(
$this,
'notification_selection',
), self::NOTIFICATIONS_OPTIONS );
// Pushover
add_settings_section( 'pushover_credentials', _x( 'Pushover Credentials', 'Configuration Section Title', 'post-smtp' ), array(
$this,
'section',
), self::NOTIFICATIONS_PUSHOVER_CRED );
add_settings_field( PostmanNotifyOptions::PUSHOVER_USER, _x( 'Pushover User Key', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'pushover_user_callback',
), self::NOTIFICATIONS_PUSHOVER_CRED, 'pushover_credentials' );
add_settings_field( PostmanNotifyOptions::PUSHOVER_TOKEN, _x( 'Pushover App Token', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'pushover_token_callback',
), self::NOTIFICATIONS_PUSHOVER_CRED, 'pushover_credentials' );
// Slack
add_settings_section( 'slack_credentials', _x( 'Slack Credentials', 'Configuration Section Title', 'post-smtp' ), array(
$this,
'section',
), self::NOTIFICATIONS_SLACK_CRED );
add_settings_field( PostmanNotifyOptions::SLACK_TOKEN, _x( 'Slack Webhook', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'slack_token_callback',
), self::NOTIFICATIONS_SLACK_CRED, 'slack_credentials' );
//Email Notification
add_settings_section(
'email_notification',
'',
array( $this, 'email_notification' ),
self::NOTIFICATION_EMAIL
);
add_settings_section(
'chrome_notification',
'Setup Chrome extension (optional)',
array( $this, 'chrome_extension' ),
self::CHROME_EXTENSION
);
add_settings_field( PostmanNotifyOptions::NOTIFICATION_USE_CHROME, _x( 'Push to chrome extension', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'notification_use_chrome_callback',
), self::CHROME_EXTENSION, 'chrome_notification' );
add_settings_field( 'notification_chrome_uid', _x( 'Chrome Extension UID', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'notification_chrome_uid_callback',
), self::CHROME_EXTENSION, 'chrome_notification' );
}
public function notification_use_chrome_callback() {
$value = $this->options->useChromeExtension() ? 'checked="checked"' : '' ;
$id = PostmanNotifyOptions::NOTIFICATION_USE_CHROME;
?>
<label class="ps-switch-1">
<input type="checkbox" name="<?php echo 'postman_options[' . esc_attr( $id ) . ']'; ?>" id="<?php echo 'input_' . esc_attr( $id ); ?>" class="<?php echo 'input_' . esc_attr( $id ); ?>" <?php echo esc_attr( $value ); ?> />
<span class="slider round"></span>
</label>
<?php
}
public function notification_chrome_uid_callback() {
printf( '<input type="password" id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', 'postman_options', 'notification_chrome_uid', PostmanUtils::obfuscatePassword( $this->options->getNotificationChromeUid() ) );
}
public function pushover_user_callback() {
printf( '<input type="password" id="pushover_user" name="%s[%s]" value="%s" />', 'postman_options', PostmanNotifyOptions::PUSHOVER_USER, $this->options->getPushoverUser() );
}
public function pushover_token_callback() {
printf( '<input type="password" id="pushover_token" name="%s[%s]" value="%s" />', 'postman_options', PostmanNotifyOptions::PUSHOVER_TOKEN, $this->options->getPushoverToken() );
}
public function slack_token_callback() {
printf( '<input type="password" id="slack_token" name="%s[%s]" value="%s" />', 'postman_options', PostmanNotifyOptions::SLACK_TOKEN, $this->options->getSlackToken() );
echo '<a target="_blank" href="https://slack.postmansmtp.com/">' . __( 'Get your webhook URL here', 'post-smtp' ) . '</a>';
}
/**
* @param PostmanEmailLog $log
* @param PostmanMessage $message
* @param string $transcript
* @param PostmanTransport $transport
* @param string $errorMessage
*/
public function notify ($log, $postmanMessage, $transcript, $transport, $errorMessage ) {
$message = __( 'You getting this message because an error detected while delivered your email.', 'post-smtp' );
$message .= "\r\n" . sprintf( __( 'For the domain: %1$s','post-smtp' ), get_bloginfo('url') );
$message .= "\r\n" . __( 'The log to paste when you open a support issue:', 'post-smtp' ) . "\r\n";
if ( $errorMessage && ! empty( $errorMessage ) ) {
$message = $message . $errorMessage;
$notification_service = PostmanNotifyOptions::getInstance()->getNotificationService();
switch ($notification_service) {
case 'none':
$notifyer = false;
break;
case 'default':
$notifyer = new PostmanMailNotify;
break;
case 'pushover':
$notifyer = new PostmanPushoverNotify;
break;
case 'slack':
$notifyer = new PostmanSlackNotify;
break;
default:
$notifyer = new PostmanMailNotify;
}
$notifyer = apply_filters('post_smtp_notifier', $notifyer, $notification_service);
// Notifications
if ( $notifyer ) {
$notifyer->send_message($message, $log);
}
$this->push_to_chrome($errorMessage);
}
}
public function push_to_chrome($message) {
$push_chrome = PostmanNotifyOptions::getInstance()->useChromeExtension();
if ( $push_chrome ) {
$uid = PostmanNotifyOptions::getInstance()->getNotificationChromeUid();
if ( empty( $uid ) ) {
return;
}
$url = 'https://chrome.postmansmtp.com/' . $uid;
$args = array(
'body' => array(
'message' => $message
)
);
$response = wp_remote_post( $url , $args );
if ( is_wp_error( $response ) ) {
error_log( 'Chrome notification error: ' . $response->get_error_message() );
}
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
error_log( 'Chrome notification error HTTP Error:' . wp_remote_retrieve_response_code( $response ) );
}
}
}
/**
* Section
*
* @since 2.4.0
* @version 1.0.0
*/
public function section() {
}
/**
* Notification Selection
*
* @since 2.4.0
* @version 1.0.0
*/
public function notification_selection() {
$options = apply_filters( 'post_smtp_notification_service', array(
'none' => __( 'None', 'post-smtp' ),
'default' => __( 'Admin Email', 'post-smtp' ),
'slack' => __( 'Slack', 'post-smtp' ),
'pushover' => __( 'Pushover', 'post-smtp' )
) );
$currentKey = $this->options->getNotificationService();
$logs_url = admin_url( 'admin.php?page=postman_email_log' );
echo '<p>' . sprintf(
esc_html( 'Select a service to notify you when an email delivery will fail. It helps keep track, so you can resend any such emails from the %s if required.', 'post-smtp' ),
'<a href="'.$logs_url.'" target="_blank">log section</a>'
) . '</p>';
?>
<div class="ps-notify-radios">
<?php
foreach( $options as $key => $value ) {
$checked = $currentKey == $key ? 'checked' : '';
?>
<div class="ps-notify-radio-outer">
<div class="ps-notify-radio">
<input type="radio" value="<?php echo esc_attr( $key ); ?>" name="postman_options[notification_service]" id="ps-notify-<?php echo esc_attr( $key ); ?>" class="input_notification_service" <?php echo esc_attr( $checked ); ?> />
<label for="ps-notify-<?php echo esc_attr( $key ); ?>">
<img src="<?php echo esc_url( POST_SMTP_ASSETS . "images/icons/{$key}.png" ) ?>" />
<div class="ps-notify-tick-container">
<div class="ps-notify-tick"><span class="dashicons dashicons-yes"></span></div>
</div>
</label>
</div>
<h4><?php echo esc_html( $value ); ?></h4>
</div>
<?php
}
if( !class_exists( 'PostSMTPTwilio' ) ) {
?>
<a href="https://postmansmtp.com/extensions/twilio-extension-pro/" target="_blank">
<div class="ps-notify-radio-outer">
<div class="ps-notify-radio pro-container">
<label for="ps-notify-twilio-pro">
<img src="<?php echo esc_url( POST_SMTP_ASSETS . 'images/icons/pro.png' ) ?>" class="pro-icon" />
<img src="<?php echo esc_url( POST_SMTP_ASSETS . 'images/icons/twilio.png' ) ?>" />
</label>
</div>
<h4>Twilio(SMS)</h4>
</div>
</a>
<?php
}
?>
</div>
<?php
}
/**
* Email Notification | Section call-back
*
* @since 2.4.0
* @version 1.0.0
*/
public function email_notification() {
$notification_emails = PostmanNotifyOptions::getInstance()->get_notification_email();
?>
<input type="text" name="postman_options[notification_email]" value="<?php echo esc_attr( $notification_emails ); ?>" />
<?php
}
/**
* Chrome Extenstion | Section call-back
*
* @since 2.4.0
* @version 1.0.0
*/
public function chrome_extension() {
?>
<div class="ps-chrome-extension">
<p><?php _e( 'You can also get notifications in chrome for Post SMTP in case of email delivery failure.', 'post-smtp' ) ?></p>
<a target="_blank" class="ps-chrome-download" href="https://chrome.google.com/webstore/detail/npklmbkpbknkmbohdbpikeidiaekjoch">
<img src="<?php echo esc_url( POST_SMTP_ASSETS . 'images/logos/chrome-24x24.png' ) ?>" />
<?php esc_html_e( 'Download Chrome extension', 'post-smtp' ); ?>
</a>
<a href="https://postmansmtp.com/post-smtp-1-9-6-new-chrome-extension/" target="_blank"><?php _e( 'Detailed Documentation.', 'post-smtp' ) ?></a>
</div>
<?php
}
}
new PostmanNotify();

View File

@@ -0,0 +1,88 @@
<?php
class PostmanNotifyOptions {
const DEFAULT_NOTIFICATION_SERVICE = 'default';
const NOTIFICATION_SERVICE = 'notification_service';
const NOTIFICATION_USE_CHROME = 'notification_use_chrome';
const NOTIFICATION_CHROME_UID = 'notification_chrome_uid';
const PUSHOVER_USER = 'pushover_user';
const PUSHOVER_TOKEN = 'pushover_token';
const SLACK_TOKEN = 'slack_token';
const NOTIFICATION_EMAIL = 'notification_email';
private $options;
private static $instance;
public static function getInstance()
{
if ( ! self::$instance ) {
self::$instance = new static;
}
return self::$instance;
}
private function __construct()
{
$this->options = get_option( 'postman_options' );
}
public function getNotificationService() {
if ( isset( $this->options [ self::NOTIFICATION_SERVICE ] ) ) {
return $this->options [ self::NOTIFICATION_SERVICE ];
} else {
return self::DEFAULT_NOTIFICATION_SERVICE;
}
}
public function getPushoverUser() {
if ( isset( $this->options [ self::PUSHOVER_USER ] ) ) {
return base64_decode( $this->options [ self::PUSHOVER_USER ] );
}
}
public function getPushoverToken() {
if ( isset( $this->options [ self::PUSHOVER_TOKEN ] ) ) {
return base64_decode( $this->options [ self::PUSHOVER_TOKEN ] );
}
}
public function getSlackToken() {
if ( isset( $this->options [ self::SLACK_TOKEN ] ) ) {
return base64_decode( $this->options [ self::SLACK_TOKEN ] );
}
}
public function useChromeExtension() {
if ( isset( $this->options [ self::NOTIFICATION_USE_CHROME ] ) ) {
return $this->options [ self::NOTIFICATION_USE_CHROME ];
}
}
public function getNotificationChromeUid() {
if ( isset( $this->options [ self::NOTIFICATION_CHROME_UID ] ) ) {
return base64_decode( $this->options [ self::NOTIFICATION_CHROME_UID ] );
}
}
/**
* Get Notification Email
*
* @since 2.4.0
* @version 1.0.0
*/
public function get_notification_email() {
if ( isset( $this->options[self::NOTIFICATION_EMAIL] ) ) {
return $this->options[self::NOTIFICATION_EMAIL];
}
return get_bloginfo( 'admin_email' );
}
}

View File

@@ -0,0 +1,34 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class PostmanPushoverNotify implements Postman_Notify {
public function send_message($message)
{
$options = PostmanNotifyOptions::getInstance();
$api_url = "https://api.pushover.net/1/messages.json";
$app_token = $options->getPushoverToken();
$user_key = $options->getPushoverUser();
$args = array(
'body' => array(
"token" => $app_token,
"user" => $user_key,
"message" => $message,
)
);
$result = wp_remote_post( $api_url, $args );
if ( is_wp_error($result) ) {
error_log( __CLASS__ . ': ' . $result->get_error_message() );
}
$body = json_decode( wp_remote_retrieve_body( $result ), true );
if ( $body['status'] == 0 ) {
error_log( __CLASS__ . ': ' . print_r( $body, true ) );
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class PostmanSlackNotify implements Postman_Notify {
public function send_message($message)
{
$options = PostmanNotifyOptions::getInstance();
$api_url = $options->getSlackToken();
$headers = array(
'content-type' => 'application/json'
);
$body = array(
'text' => $message
);
$args = array(
'headers' => $headers,
'body' => json_encode($body)
);
$result = wp_remote_post( $api_url, $args );
if ( is_wp_error($result) ) {
error_log( __CLASS__ . ': ' . $result->get_error_message() );
}
$code = wp_remote_retrieve_response_code( $result );
$message = wp_remote_retrieve_response_message( $result );
if ( $code != 200 && $message !== 'OK' ) {
error_log( __CLASS__ . ': ' . $message );
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
class StatusSolution {
private $status;
public function __construct() {
add_filter( 'post_smtp_log_solution', array( $this, 'find_solution' ), 10, 4 );
}
public function find_solution( $solution, $status, $log, $message ) {
if ( empty( $status ) ) {
return 'All good, mail sent.';
}
$this->status = addslashes( $status );
$possible_solution = [];
if ( $this->strExists('timed out') ) {
$possible_solution[] = $this->make_clickable('https://postmansmtp.com/office365-smtp-connection-timed-out/');
} elseif ( $this->strExists('timeout') || $this->strExists('open socket' ) ) {
$possible_solution[] = 'Your hosting is blocking the connection, contact their support';
} elseif ( $this->strExists( 'DATA NOT ACCEPTED' ) || $this->strExists('Exception:SendAsDeniedException' ) ) {
$possible_solution[] = $this->make_clickable('https://postmansmtp.com/storedrv-submission-exceptionsendasdeniedexception-mapiexceptionsendasdenied/');
} elseif ( $this->strExists( 'Incorrect authentication data') ) {
$possible_solution[] = $this->make_clickable( 'https://postmansmtp.com/incorrect-authentication-data/' );
} elseif ( $this->strExists( 'Unrecognized authentication type' ) ) {
$possible_solution[] = 'Change "Authentication" type on plugin settings to "Login"';
} elseif ( $this->strExists( 'Error executing "SendRawEmail"' ) ) {
$possible_solution[] = 'Amazon SES - account permission error (review account configuration)';
} elseif ( $this->strExists( 'Please log in via your web browser and then try again' ) ) {
$possible_solution[] = $this->make_clickable( 'https://postmansmtp.com/gmail-gsuite-please-log-in-via-your-web-browser-and-then-try-again/' );
} elseif ( $this->strExists( 'Application-specific password required' ) ) {
$possible_solution[] = 'Two factor authentication is enabled, replace your password with app password.';
$possible_solution[] = $this->make_clickable( 'https://support.google.com/mail/?p=InvalidSecondFactor' );
} elseif ( $this->strExists( 'Username and Password not accepted' ) || $this->strExists( 'Authentication unsuccessful' ) ) {
$possible_solution[] = 'Check you credentials, wrong email or password.';
} elseif ( $this->strExists( 'ErrorSendAsDenied' ) ) {
$possible_solution[] = 'Give the configured account "Send As" permissions on the "From" mailbox (admin.office365.com).';
} elseif ( $this->strExists( 'ErrorParticipantDoesntHaveAnEmailAddress' ) ) {
$possible_solution[] = "Probably office 365 doesn't like shared mailbox in Reply-To field";
} else {
$possible_solution[] = 'Not found, check status column for more info.';
}
return ! empty( $possible_solution ) ? implode( '<br>', $possible_solution ) : '';
}
private function make_clickable($url) {
return '<a target="_blank" href="' . esc_url($url ) . '">' . esc_html( 'Read here' ) . '</a>';
}
private function strExists( $value ) {
return strpos( strtolower( $this->status ), strtolower( addslashes( $value ) ) ) !== false;
}
}
new StatusSolution();

View File

@@ -0,0 +1,90 @@
<?php
if( !class_exists( 'Post_SMTP_MainWP_Child_Request' ) ):
class Post_SMTP_MainWP_Child_Request {
private $base_url = false;
/**
* Constructor
*
* @since 2.6.0
* @version 2.6.0
*/
public function __construct() {
$server = get_option( 'mainwp_child_server' );
if( $server ) {
$this->base_url = parse_url( $server, PHP_URL_SCHEME ) . "://" . parse_url( $server, PHP_URL_HOST ) . "/" . 'wp-json/post-smtp-for-mainwp/v1/send-email';
}
}
/**
* Process email
*
* @param string|array $to Array or comma-separated list of email addresses to send message.
* @param string $subject Email subject
* @param string $message Message contents
* @param string|array $headers Optional. Additional headers.
* @param string|array $attachments Optional. Files to attach.
* @return bool Whether the email contents were sent successfully.
* @since 2.6.0
* @version 2.6.0
*/
public function process_email( $to, $subject, $message, $headers = '', $attachments = array() ) {
$body = array();
$pubkey = get_option( 'mainwp_child_pubkey' );
$pubkey = $pubkey ? md5( $pubkey ) : '';
$request_headers = array(
'Site-Id' => get_option( 'mainwp_child_siteid' ),
'API-Key' => $pubkey
);
//let's manage attachments
if( !empty( $attachments ) && $attachments ) {
$_attachments = $attachments;
$attachments = array();
foreach( $_attachments as $attachment ) {
$attachments[$attachment] = file_get_contents( $attachment );
}
}
$body = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$action_nonce = apply_filters( 'mainwp_child_create_action_nonce', false, 'post-smtp-send-mail' );
$ping_nonce = apply_filters( 'mainwp_child_get_ping_nonce', '' );
$this->base_url = "$this->base_url/?actionnonce={$action_nonce}&pingnonce={$ping_nonce}";
$response = wp_remote_post(
$this->base_url,
array(
'method' => 'POST',
'body' => $body,
'headers' => $request_headers
)
);
if( wp_remote_retrieve_body( $response ) ) {
return true;
}
}
}
endif;

View File

@@ -0,0 +1,32 @@
<?php
if( !function_exists( 'wp_mail' ) ):
/**
* Send an email | Override wp_mail function
*
* @param string|array $to Array or comma-separated list of email addresses to send message.
* @param string $subject Email subject
* @param string $message Message contents
* @param string|array $headers Optional. Additional headers.
* @param string|array $attachments Optional. Files to attach.
* @return bool Whether the email contents were sent successfully.
* @see wp_mail()
* @since 2.6.0
* @version 2.6.0
*/
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
$request = new Post_SMTP_MainWP_Child_Request();
$response = $request->process_email( $to, $subject, $message, $headers, $attachments );
if( is_wp_error( $response ) ) {
return false;
}
return true;
}
endif;

View File

@@ -0,0 +1,128 @@
<?php
if( !class_exists( 'Post_SMTP_MainWP_Child' ) ):
class Post_SMTP_MainWP_Child {
private static $instance;
/**
* Get instance
*
* @return object
* @since 2.6.0
* @version 2.6.0
*/
public static function get_instance() {
if( !isset( self::$instance ) && !( self::$instance instanceof Post_SMTP_MainWP_Child ) ) {
self::$instance = new Post_SMTP_MainWP_Child();
}
return self::$instance;
}
/**
* Constructor
*
* @since 2.6.0
* @version 2.6.0
*/
public function __construct() {
$this->validate();
}
/**
* Validate
*
* @since 2.6.0
* @version 2.6.0
*/
public function validate() {
if( !function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
if( is_plugin_active( 'mainwp-child/mainwp-child.php' ) ) {
$this->init();
}
}
/**
* Init
*
* @since 2.6.0
* @version 2.6.0
*/
public function init() {
require_once 'rest-api/v1/class-psmwp-rest-api.php';
$post_smtp_enabled = get_option( 'post_smtp_use_from_main_site' );
if( $post_smtp_enabled ) {
add_filter( 'post_smtp_dashboard_notice', array( $this, 'update_notice' ) );
add_filter( 'post_smtp_declare_wp_mail', '__return_false' );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
require_once 'classes/class-psmwp-request.php';
require_once 'psmwp-functions.php';
}
}
/**
* Enqueue Admin Scripts.
*
* @since 2.6.0
* @version 1.0.0
*/
public function enqueue_scripts() {
$css = '
.ps-config-bar .dashicons-dismiss {
display: none;
}';
wp_add_inline_style(
'postman_style',
$css
);
}
/**
* Update Dashboard Notice | Filter Callback
*
* @since 2.6.0
* @version 1.0.0
*/
public function update_notice() {
return array(
'error' => false,
'message' => __( 'Post SMTP is being used by MainWP Dashboard Site.', 'post-smtp' )
);
}
}
endif;

View File

@@ -0,0 +1,129 @@
<?php
if( !class_exists( 'PSMWP_Rest_API' ) ):
class PSMWP_Rest_API {
/**
* PSMWP_Rest_API constructor.
*
* @since 2.6.0
* @version 1.0.0
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
/**
* Register routes
*
* @since 2.6.0
* @version 1.0.0
*/
public function register_routes() {
register_rest_route( 'psmwp/v1', '/activate-from-mainwp', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'activate_from_mainwp' ),
'permission_callback' => '__return_true',
) );
}
/**
* Activate from MainWP
*
* @since 2.6.0
* @version 1.0.0
*/
public function activate_from_mainwp( WP_REST_Request $request ) {
$params = $request->get_params();
$headers = $request->get_headers();
$api_key = empty( $request->get_header( 'api_key' ) ) ? '' : sanitize_text_field( $request->get_header( 'api_key' ) );
$action = $request->get_param( 'action' );
//Lets Validate :D
if( $this->validate( $api_key ) ) {
if( $action == 'enable_post_smtp' ) {
update_option( 'post_smtp_use_from_main_site', '1' );
}
if( $action == 'disable_post_smtp' ) {
delete_option( 'post_smtp_use_from_main_site' );
}
wp_send_json_success(
array(),
200
);
}
}
/**
* Validate request
*
* @since 2.6.0
* @version 1.0.0
*/
private function validate( $api_key ) {
if(
empty( $api_key )
) {
wp_send_json(
array(
'code' => 'incomplete_request',
'message' => 'Empty API-Key or Site-URL.'
),
404
);
}
$pubkey = get_option( 'mainwp_child_pubkey' );
$pubkey = $pubkey ? md5( $pubkey ) : '';
if( $pubkey != $api_key ) {
wp_send_json(
array(
'code' => 'incorrect_api_key',
'message' => 'Incorrect API Key.'
),
404
);
}
//Let's allow request
if(
$pubkey == $api_key
) {
return true;
}
}
}
new PSMWP_Rest_API();
endif;

View File

@@ -0,0 +1,17 @@
<?php
require_once 'includes/psmwp-init.php';
/**
* Load Post SMTP for MainWP Child
*
* @since 2.6.0
* @version 2.6.0
*/
function load_post_smtp_for_mainwp_child() {
Post_SMTP_MainWP_Child::get_instance();
}
load_post_smtp_for_mainwp_child();