Plugin Directory

Changeset 3485473


Ignore:
Timestamp:
03/18/2026 09:49:57 AM (10 days ago)
Author:
wpexpertsio
Message:

Release 1.0.6

Location:
post-smtp-for-mainwp/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • post-smtp-for-mainwp/trunk/includes/class-post-smtp-mwp-page.php

    r3464830 r3485473  
    3737            add_action( 'admin_post_post_smtp_mwp_save_sites', array( $this, 'save_sites' ) );
    3838            add_action( 'wp_ajax_post-smtp-request-mwp-child', array( $this, 'request_child' ) );
     39            add_action( 'post_smtp_wizard_configuration_saved', array( $this, 'broadcast_configuration_to_children' ) );
    3940        }
    4041
     
    294295
    295296                    $response = wp_remote_post(
    296                         "{$site_url}wp-json/psmwp/v1/activate-from-mainwp",
     297                        "{$site_url}index.php/wp-json/psmwp/v1/activate-from-mainwp",
    297298                        array(
    298299                            'headers' => array(
     
    301302                            'body'    => array(
    302303                                'action' => $what,
     304                                'parent_configured' => $this->is_post_smtp_configured()
    303305                            ),
    304306                        )
     
    357359            }
    358360        }
     361
     362        /**
     363         * Broadcast configuration to children
     364         *
     365         * @since 1.0.0
     366         * @version 1.0.0
     367         */
     368        public function broadcast_configuration_to_children() {
     369
     370            $sites = get_option( 'post_smtp_mainwp_sites' );
     371
     372            if ( empty( $sites ) ) {
     373                return;
     374            }
     375
     376            $child_enabled = apply_filters( 'mainwp_extension_enabled_check', __FILE__ );
     377            $child_key     = $child_enabled['key'];
     378            $option        = array( 'pubkey' => true );
     379
     380            foreach ( $sites as $site_id => $site_data ) {
     381
     382                if ( isset( $site_data['enable_on_child_site'] ) && $site_data['enable_on_child_site'] ) {
     383                   
     384                    $website = apply_filters( 'mainwp_getdbsites', __FILE__, $child_key, array( $site_id ), array(), $option );
     385                   
     386                    if( empty( $website ) || ! isset( $website[ $site_id ] ) ) {
     387                        continue;
     388                    }
     389
     390                    $website  = $website[ $site_id ];
     391                    $api_key  = md5( $website->pubkey );
     392                    $site_url = $website->url;
     393
     394                    wp_remote_post(
     395                        "{$site_url}index.php/wp-json/psmwp/v1/activate-from-mainwp",
     396                        array(
     397                            'headers' => array(
     398                                'API-Key' => $api_key,
     399                            ),
     400                            'body'    => array(
     401                                'action' => 'enable_post_smtp',
     402                                'parent_configured' => $this->is_post_smtp_configured()
     403                            ),
     404                            'blocking' => false
     405                        )
     406                    );
     407
     408                }
     409            }
     410
     411        }
     412
     413        /**
     414         * Is Post SMTP Configured
     415         *
     416         * @return bool
     417         * @since 1.0.0
     418         * @version 1.0.0
     419         */
     420        private function is_post_smtp_configured() {
     421           
     422            $options = get_option( PostmanOptions::POSTMAN_OPTIONS );
     423            $transport_type = isset( $options[ PostmanOptions::TRANSPORT_TYPE ] ) ? $options[ PostmanOptions::TRANSPORT_TYPE ] : '';
     424            if ( $transport_type !== 'default'  && $transport_type !== '') {
     425                return true;
     426            }
     427            return false;
     428           
     429        }
    359430    }
    360431
  • post-smtp-for-mainwp/trunk/includes/class-post-smtp-mwp-table.php

    r3464830 r3485473  
    168168        public function logs_args( $args ) {
    169169
    170             if ( 'site_id' === $args['order_by'] ) {
    171 
     170            if ( isset( $args['order_by'] ) && 'site_id' === $args['order_by'] ) {
     171       
    172172                $args['order_by'] = 'lm.meta_value';
    173 
    174             }
    175 
     173            }
     174       
    176175            return $args;
    177176        }
  • post-smtp-for-mainwp/trunk/includes/rest-api/v1/class-post-smtp-mwp-rest-api.php

    r3464830 r3485473  
    3030         */
    3131        private $site = false;
     32
     33        /**
     34         * Email log IDs created for the current request (primary + fallback attempts).
     35         *
     36         * @var array
     37         */
     38        private $current_log_ids = array();
    3239
    3340        /**
     
    130137        public function send_email( WP_REST_Request $request ) {
    131138
    132             $result  = false;
    133             $headers = $request->get_headers();
    134             $api_key = empty( $request->get_header( 'api_key' ) ) ? '' : sanitize_text_field( $request->get_header( 'api_key' ) );
    135             $site_id = empty( $request->get_header( 'site_id' ) ) ? '' : sanitize_text_field( $request->get_header( 'site_id' ) );
     139            $result           = false;
     140            $headers          = $request->get_headers();
     141            $api_key          = empty( $request->get_header( 'api_key' ) ) ? '' : sanitize_text_field( $request->get_header( 'api_key' ) );
     142            $site_id          = empty( $request->get_header( 'site_id' ) ) ? '' : sanitize_text_field( $request->get_header( 'site_id' ) );
     143            $this->current_log_ids = array();
    136144
    137145            if ( isset( $_GET['actionnonce'] ) // phpcs:disable WordPress.Security.NonceVerification
     
    149157                    $result        = apply_filters( 'mainwp_fetchurlverifyaction', __FILE__, $child_key, $this->site_id, $params );
    150158
    151                     // All set, let's send email xD.
    152                     if ( is_array( $result ) && ! empty( $result['success'] ) ) {
    153 
    154                         // Override settings if checked in MainWP -> Extensions -> Post SMTP -> Enable Individual Settings.
    155                         $this->override_settings();
    156 
    157                         $params      = $request->get_params();
    158                         $to          = isset( $params['to'] ) ? $params['to'] : '';
    159                         $subject     = isset( $params['subject'] ) ? $params['subject'] : '';
    160                         $message     = isset( $params['message'] ) ? $params['message'] : '';
    161                         $headers     = isset( $params['headers'] ) ? $params['headers'] : '';
    162                         $attachments = isset( $params['attachments'] ) ? $params['attachments'] : array();
    163 
    164                         // Lets upload files on server.
    165                         if ( ! empty( $attachments ) ) {
    166 
    167                             $_attachments = $attachments;
    168                             $attachments  = array();
    169                             foreach ( $_attachments as $key => $attachment ) {
    170 
    171                                 // Get the contents of the file.
    172                                 $file_info     = pathinfo( $key );
    173                                 $absolute_path = strstr( $file_info['dirname'], 'uploads/' );
    174                                 $absolute_path = str_replace( 'uploads', '', $absolute_path );
    175                                 $absolute_path = '/';
    176 
    177                                 // Define the filename and destination directory.
    178                                 $filename   = $file_info['basename'];
    179                                 $upload_dir = wp_upload_dir();
    180 
    181                                 // Create the file in the upload directory.
    182                                 $file_path   = $upload_dir['path'] . $absolute_path . $filename;
    183                                 $file_url    = $upload_dir['url'] . $absolute_path . $filename;
    184                                 $wp_filetype = wp_check_filetype( $filename, null );
    185                                 $file_data   = wp_upload_bits( $filename, null, $attachment );
    186 
    187                                 // Check if the file was successfully uploaded.
    188                                 if ( ! $file_data['error'] ) {
    189                                     // The file was uploaded successfully.
    190                                     // Insert the file into the media library.
    191                                     $attachment = array(
    192                                         'post_mime_type' => $wp_filetype['type'],
    193                                         'post_title'     => sanitize_file_name( $filename ),
    194                                         'post_content'   => '',
    195                                         'post_status'    => 'inherit',
    196                                     );
    197 
    198                                     $attachment_id = wp_insert_attachment( $attachment, $file_data['file'] );
    199 
    200                                     $attachments[] = $file_path;
    201 
     159                    if ( ! is_array( $result ) || empty( $result['success'] ) ) {
     160
     161                        wp_send_json_error(
     162                            array(
     163                                'message' => __( 'MainWP verification failed, email not sent.', 'post-smtp' ),
     164                            ),
     165                            403
     166                        );
     167                    }
     168
     169                    // All set, let's send email.
     170                    // Override settings if checked in MainWP -> Extensions -> Post SMTP -> Enable Individual Settings.
     171                    $this->override_settings();
     172
     173                    $params      = $request->get_params();
     174                    $to          = isset( $params['to'] ) ? $params['to'] : '';
     175                    $subject     = isset( $params['subject'] ) ? $params['subject'] : '';
     176                    $message     = isset( $params['message'] ) ? $params['message'] : '';
     177                    $headers     = isset( $params['headers'] ) ? $params['headers'] : '';
     178                    $attachments = isset( $params['attachments'] ) ? $params['attachments'] : array();
     179
     180                    // Lets upload files on server.
     181                    if ( ! empty( $attachments ) ) {
     182
     183                        $_attachments = $attachments;
     184                        $attachments  = array();
     185                        foreach ( $_attachments as $key => $attachment ) {
     186
     187                            // Get the contents of the file.
     188                            $file_info     = pathinfo( $key );
     189                            $absolute_path = strstr( $file_info['dirname'], 'uploads/' );
     190                            $absolute_path = str_replace( 'uploads', '', $absolute_path );
     191                            $absolute_path = '/';
     192
     193                            // Define the filename and destination directory.
     194                            $filename   = $file_info['basename'];
     195                            $upload_dir = wp_upload_dir();
     196
     197                            // Create the file in the upload directory.
     198                            $file_path   = $upload_dir['path'] . $absolute_path . $filename;
     199                            $file_url    = $upload_dir['url'] . $absolute_path . $filename;
     200                            $wp_filetype = wp_check_filetype( $filename, null );
     201                            $file_data   = wp_upload_bits( $filename, null, $attachment );
     202
     203                            // Check if the file was successfully uploaded.
     204                            if ( ! $file_data['error'] ) {
     205                                // The file was uploaded successfully.
     206                                // Insert the file into the media library.
     207                                $attachment = array(
     208                                    'post_mime_type' => $wp_filetype['type'],
     209                                    'post_title'     => sanitize_file_name( $filename ),
     210                                    'post_content'   => '',
     211                                    'post_status'    => 'inherit',
     212                                );
     213
     214                                $attachment_id = wp_insert_attachment( $attachment, $file_data['file'] );
     215
     216                                $attachments[] = $file_path;
     217
     218                            }
     219                        }
     220                    }
     221
     222                    $mail_result = wp_mail( $to, $subject, $message, $headers, $attachments );
     223
     224                    $logs_data = array();
     225                    $last_log  = null;
     226
     227                    if ( ! empty( $this->current_log_ids ) ) {
     228                        // Load log details for this send (primary + fallback attempts) so we can return them to the child site.
     229                        if ( ! class_exists( 'PostmanEmailQueryLog' ) && defined( 'POST_SMTP_PATH' ) ) {
     230                            require_once POST_SMTP_PATH . '/Postman/Postman-Email-Log/PostmanEmailQueryLog.php';
     231                        }
     232
     233                        if ( class_exists( 'PostmanEmailQueryLog' ) ) {
     234                            $email_query_log = new PostmanEmailQueryLog();
     235
     236                            foreach ( $this->current_log_ids as $log_id ) {
     237                                $log_row = $email_query_log->get_log( $log_id );
     238
     239                                if ( is_array( $log_row ) ) {
     240                                    $logs_data[] = $log_row;
     241                                    $last_log    = $log_row;
    202242                                }
    203243                            }
    204244                        }
    205 
    206                         $result = wp_mail( $to, $subject, $message, $headers, $attachments );
    207 
     245                    }
     246
     247                    $last_log_id = ! empty( $this->current_log_ids ) ? end( $this->current_log_ids ) : 0;
     248
     249                    if ( $mail_result ) {
     250                        wp_send_json_success(
     251                            array(
     252                                'message'  => __( 'Email sent successfully from MainWP dashboard site.', 'post-smtp' ),
     253                                // Backwards-compatible single-log fields.
     254                                'log_id'   => $last_log_id,
     255                                'log'      => $last_log,
     256                                // New: full set of logs for this send (primary + fallback attempts).
     257                                'log_ids'  => $this->current_log_ids,
     258                                'logs'     => $logs_data,
     259                            ),
     260                            200
     261                        );
     262                    } else {
     263                        wp_send_json_error(
     264                            array(
     265                                'message'  => __( 'Email sending failed on MainWP dashboard site.', 'post-smtp' ),
     266                                // Backwards-compatible single-log fields.
     267                                'log_id'   => $last_log_id,
     268                                'log'      => $last_log,
     269                                // New: full set of logs for this send (primary + fallback attempts).
     270                                'log_ids'  => $this->current_log_ids,
     271                                'logs'     => $logs_data,
     272                            ),
     273                            500
     274                        );
    208275                    }
    209276                }
    210277            }
    211278
    212             return $result;
     279            // If we reached here, something in the initial validation failed.
     280            wp_send_json_error(
     281                array(
     282                    'message' => __( 'Invalid request, email not sent.', 'post-smtp' ),
     283                ),
     284                400
     285            );
    213286        }
    214287
     
    224297
    225298            // Store Site ID, if log has been created :).
     299            $this->current_log_ids[] = (int) $log_id;
     300
    226301            if ( $this->site_id ) {
    227302
  • post-smtp-for-mainwp/trunk/mainwp-post-smtp-extension.php

    r3464830 r3485473  
    44 * Plugin URI: https://mainwp.com/extension/post-smtp/
    55 * Description: MainWP Post SMTP extension allows you to manage SMTP of you all your child sites from one central location.
    6  * Version: 1.0.5
     6 * Version: 1.0.6
    77 * Author: Post SMTP
    88 * Text Domain: post-smtp
  • post-smtp-for-mainwp/trunk/readme.txt

    r3464831 r3485473  
    44Requires at least: 4.7
    55Tested up to: 6.9
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    119119== Changelog ==
    120120
    121 = 1.0.5 Feb 19, 2026 =
     121= 1.0.6 - Mar 18, 2026 =
     122* TWEAK – Sync button in the header to synchronize all settings from the parent to child sites directly from the MainWP dashboard.
     123* TWEAK – Added compatibility for email failure alerts.
     124* FIX – Resolved an issue with email log synchronization from child sites to the parent site.
     125
     126= 1.0.5 - Feb 19, 2026 =
    122127* Reverted the last update.
    123128
    124 = 1.0.4 Feb 19, 2026 =
     129= 1.0.4 - Feb 19, 2026 =
    125130* TWEAK – Sync button in the header to synchronize all settings from the parent to child sites directly from the MainWP dashboard.
    126131* TWEAK – Added compatibility for email failure alerts.
Note: See TracChangeset for help on using the changeset viewer.