Plugin Directory

Changeset 996192


Ignore:
Timestamp:
09/24/2014 04:41:05 PM (11 years ago)
Author:
DragonOfDev
Message:

Add smtp hook so that user can use wp_mail by using smtp of sendinblue

Location:
mailin/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mailin/trunk/inc/mailin.php

    r987329 r996192  
    331331                return $this->post("account/deletetoken", json_encode(array("token"=>$key)));
    332332        }
     333        public function get_smtp_details()
     334        {
     335            return $this->get("account/smtpdetail","");
     336        }
    333337}
    334338?>
  • mailin/trunk/page/page-home.php

    r976261 r996192  
    158158        function generate_main_content()
    159159        {
    160             // get list
    161 
    162             $home_settings = get_option(SIB_Manager::home_option_name);
    163 
     160            wp_mail('[email protected]', 'Test email', 'Test message');
    164161            $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key);
    165162            $list_response = $mailin->get_lists();
     
    176173            }
    177174
    178 
    179175            // get campaigns
    180176            $campaign_stat = self::get_campaign_stats();
     
    185181            }
    186182
     183            // check smtp available
     184            if((SIB_Manager::is_done_validation()) && (SIB_Manager::$smtp_details == null)) {
     185                SIB_Manager::update_smtp_details();
     186            }
     187
     188            $home_settings = get_option(SIB_Manager::home_option_name);
    187189
    188190        ?>
     
    305307                    </div>
    306308                    <div class="panel-body">
     309                        <?php
     310                        if(SIB_Manager::$smtp_details['relay'] == false) :
     311                        ?>
     312                            <div id="failure-alert" class="col-md-12 alert alert-danger" role="alert"><?php _e('You still can not use the smtp of SendinBlue. Please confirm at ', 'sib_lang');?><a href="https://mysmtp.sendinblue.com/" target="_blank"><?php _e('here', 'sib_lang'); ?></a> </div>
     313                        <?php
     314                        endif;
     315                        ?>
    307316                        <div id="success-alert" class="col-md-12 alert alert-success" role="alert" style="display: none;"><?php _e('Mail Sent.', 'sib_lang');?></div>
    308317                        <div id="failure-alert" class="col-md-12 alert alert-danger" role="alert" style="display: none;"><?php _e('Please input valid email.', 'sib_lang');?></div>
     
    310319                            <p class="col-md-4 text-left"><?php _e('Activate email through SendinBlue', 'sib_lang'); ?></p>
    311320                            <div class="col-md-3">
    312                                 <label class="col-md-6"><input type="radio" name="activate_email" id="activate_email_radio_yes" value="yes" <?php checked($home_settings['activate_email'], 'yes'); ?>>&nbsp;Yes</label>
     321                                <label class="col-md-6"><input type="radio" name="activate_email" id="activate_email_radio_yes" value="yes" <?php checked($home_settings['activate_email'], 'yes');
     322                                    if(SIB_Manager::$smtp_details['relay'] == false) {
     323                                        echo ' disabled';
     324                                    }
     325                                    ?> >&nbsp;Yes</label>
    313326                                <label class="col-md-6"><input type="radio" name="activate_email" id="activate_email_radio_no" value="no" <?php checked($home_settings['activate_email'], 'no'); ?>>&nbsp;No</label>
    314327                            </div>
     
    545558
    546559            $home_settings = array(
    547                 'activate_email' => 'yes'
     560                'activate_email' => 'no'
    548561            );
    549562            update_option(SIB_Manager::home_option_name, $home_settings);
     
    684697            $account_settings = array();
    685698            update_option(SIB_Manager::account_option_name, $account_settings);
     699            $smtp_details = null;
     700            update_option(SIB_Manager::attribute_smtp_name, $smtp_details);
    686701        }
    687702    }
  • mailin/trunk/readme.txt

    r993701 r996192  
    44Requires at least: 3.0
    55Tested up to: 4.0
    6 Stable tag: 2.1.2
     6Stable tag: 2.2.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4040
    4141== Changelog ==
     42= 2.2.0 =
     43* Update the feautre of smtp activation
     44
    4245= 2.1.2 =
    4346* Update button UI CSS of subscription form
  • mailin/trunk/sendinblue.php

    r993701 r996192  
    44Plugin URI: https://www.sendinblue.com/?r=wporg
    55Description: Easily send emails from your WordPress blog using SendinBlue SMTP and easily add a subscribe form to your site
    6 Version: 2.1.2
     6Version: 2.2.0
    77Author: SendinBlue, Dragonofdev
    88Author URI: https://www.sendinblue.com/?r=wporg
     
    8989
    9090        /**
     91         * plugin smtp details option name
     92         */
     93        const attribute_smtp_name = 'sib_smtp_details';
     94
     95        /**
    9196         * Plugin directory path value. set in constructor
    9297         * @access public
     
    218223         */
    219224        public static $account_user_name;
     225
     226        /**
     227         * smtp details
     228         */
     229        public static $smtp_details;
    220230
    221231        /**
     
    332342                update_option(self::form_subscription_option_name, $form_settings);
    333343            }
     344
     345            // smtp details
     346            self::$smtp_details = get_option(SIB_Manager::attribute_smtp_name, null);
     347            if((self::is_done_validation()) && (self::$smtp_details == null)) {
     348                self::update_smtp_details();
     349            }
     350            $home_settings = get_option(SIB_Manager::home_option_name, array());
     351            if((self::is_done_validation()) && (self::$smtp_details['relay'] == false) ) {
     352
     353                $home_settings['activate_email'] = 'no';
     354                update_option(SIB_Manager::home_option_name, $home_settings);
     355            }
     356
     357            add_action('phpmailer_init', array(&$this, 'smtp_hook'));
     358
    334359        }
    335360
     
    509534
    510535            $home_settings = array(
    511                 'activate_email' => 'yes'
     536                'activate_email' => 'no'
    512537            );
    513538            update_option(SIB_Manager::home_option_name, $home_settings);
     
    12051230        }
    12061231
     1232        /** update smtp details */
     1233        public static function update_smtp_details()
     1234        {
     1235            $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key);
     1236            $response = $mailin->get_smtp_details();
     1237            if($response['code'] == 'success') {
     1238                if($response['data']['relay_data']['status'] == 'enabled') {
     1239                    self::$smtp_details = $response['data']['relay_data']['data'];
     1240                    update_option(self::attribute_smtp_name, self::$smtp_details);
     1241                    return true;
     1242                } else {
     1243                    self::$smtp_details = array(
     1244                        'relay' => false
     1245                    );
     1246                    update_option(self::attribute_smtp_name, self::$smtp_details);
     1247                    $home_settings = get_option(self::home_option_name, array());
     1248                    $home_settings['activate_email'] = 'no';
     1249                    update_option(SIB_Manager::home_option_name, $home_settings);
     1250                    return false;
     1251                }
     1252            }
     1253
     1254            return false;
     1255        }
     1256
     1257        /**
     1258         * Hook phpmailer_init
     1259         */
     1260        function smtp_hook($phpmailer)
     1261        {
     1262            $admin_info = get_userdata(1);
     1263            $home_settings = get_option(self::home_option_name, array());
     1264            if($home_settings['activate_email'] != 'yes')
     1265                return;
     1266            if(self::$smtp_details['relay'] == false)
     1267                return;
     1268            $phpmailer->Mailer = 'smtp';
     1269            $phpmailer->From = $admin_info->user_email;
     1270            $phpmailer->FromName = $admin_info->display_name;
     1271            $phpmailer->Sender = $phpmailer->From; //Return-Path
     1272            $phpmailer->AddReplyTo($phpmailer->From, $phpmailer->FromName); //Reply-To
     1273            $phpmailer->Host       = self::$smtp_details['relay'];
     1274            $phpmailer->SMTPSecure = 'true';
     1275            $phpmailer->Port       = self::$smtp_details['port'];
     1276            $phpmailer->SMTPAuth   = true;
     1277            $phpmailer->Username = self::$smtp_details['username'];
     1278            $phpmailer->Password = self::$smtp_details['password'];
     1279        }
     1280
    12071281    }
    12081282
Note: See TracChangeset for help on using the changeset viewer.