Changed source root directory

This commit is contained in:
2026-03-05 16:30:11 +01:00
parent dc85447ee1
commit 538f85d7a2
5868 changed files with 749734 additions and 99 deletions

View File

@@ -0,0 +1,91 @@
<?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 = apply_filters( 'mainwp_child_get_encrypted_option', false, 'mainwp_child_server', false );
$server = str_replace( 'wp-admin/', '', $server );
if( $server ) {
$this->base_url = $server . '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();