Plugin Directory

Changeset 2280329


Ignore:
Timestamp:
04/09/2020 03:22:50 PM (6 years ago)
Author:
orangetoolz
Message:

SendGrid mailer added

Location:
cf7-db-tool
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • cf7-db-tool/trunk/assets/js/cf7-db-mail-provider.js

    r2279382 r2280329  
    22var MailgunInput = document.querySelectorAll(".mailgun-input");
    33var SendGridInput = document.querySelectorAll(".sendgrid-input");
     4var chooseMailer = document.querySelector("#choose-mailer");
    45
    56(function ($) {
     
    78    $(document).ready(function(){
    89
    9 
    10         $('#choose-mailer').on('change', function() {
    11 
    12             var SelectedProvider = $(this).find(":selected").val();
    13 
    14             console.log(MailgunInput);
    15             console.log(SendGridInput);
    16 
    17             console.log(SelectedProvider);
    18 
    19             if(SelectedProvider == 'Mailgun'){
     10        $('.active_mail_provider').on('change', function(){
     11            if(this.checked){
     12                chooseMailer.setAttribute('required','true');
     13            }
     14            else{
     15                chooseMailer.removeAttribute('required');
     16                SendGridInput.forEach(function(sendGridFiled){
     17                    sendGridFiled.removeAttribute('required');
     18                });
     19                MailgunInput.forEach(function(mailgunFiled){
     20                    mailgunFiled.removeAttribute('required');
     21                });
    2022
    2123            }
     24        });
     25
     26        $("#choose-mailer").on('change', function() {
     27
     28            var SelectedProvider = $(this).find(":selected").val().trim();
     29            if(SelectedProvider == 'Mailgun'){
     30                MailgunInput.forEach(function(mailgunFiled){
     31                    mailgunFiled.setAttribute('required','true');
     32                });
     33                SendGridInput.forEach(function(sendGridFiled){
     34                    sendGridFiled.removeAttribute('required');
     35                });
     36            }
    2237            if(SelectedProvider == 'SendGrid'){
     38                SendGridInput.forEach(function(sendGridFiled){
     39                    sendGridFiled.setAttribute('required','true');
     40                });
     41                MailgunInput.forEach(function(mailgunFiled){
     42                    mailgunFiled.removeAttribute('required');
     43                });
    2344
    2445            }
    25 
    26 
    27 
    2846        });
    29 
    3047    });
    3148})(jQuery);
  • cf7-db-tool/trunk/cf7-db-tool.php

    r2279382 r2280329  
    88 * Text Domain: cf7-db-tool
    99 * Tags: contact, cf7, zapier, integration, webhook, bulk mail, contact form 7, db, export, save, wpcf7, contact form 7 db,  contact form 7 database, contact form 7 data export, contact form 7 database addon
    10  * Version: 4.2.5
     10 * Version: 4.2.6
    1111 */
    1212
    13 define('CF7_DBT_VERSION', '4.2.5');
    14 define('CF7_DBT_DB_VERSION', '4.2.5');
     13define('CF7_DBT_VERSION', '4.2.6');
     14define('CF7_DBT_DB_VERSION', '4.2.6');
    1515define('CF7_DBT_PATH', __DIR__);
    1616define('CF7_DBT_URL', plugins_url(basename(CF7_DBT_PATH)));
  • cf7-db-tool/trunk/readme.txt

    r2279382 r2280329  
    44Requires at least: 4.8
    55Tested up to: 5.4
    6 Stable tag: 4.2.5
     6Stable tag: 4.2.6
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • cf7-db-tool/trunk/src/BulkMail.php

    r2278615 r2280329  
    9393
    9494                $active_mailer = get_option('active_mailer');
    95                 if($active_mailer){
    96                     require_once 'connected_mail/mailgun.php';
    97 
    98                     if($dbtool_group_email === 'yes' ){
    99 
    100                         $result =  sendmailbymailgun($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
    101 
    102                         if(in_array('id',array_keys($result))){
    103                             $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>';
     95                $mailProvider = get_option( 'select_mailer' );
     96
     97                if($active_mailer ){
     98
     99                    if('Mailgun'===$mailProvider){
     100                        require_once 'connected_mail/mailgun.php';
     101                        if($dbtool_group_email === 'yes' ){
     102
     103                            $result =  sendmailbymailgun($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
     104
     105                            if(in_array('id',array_keys($result))){
     106                                $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>';
     107                            }
     108                            else{
     109                                $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>';
     110                            }
     111                        }else{
     112                            foreach( $recipients as $recipient ) {
     113                                $result =  sendmailbymailgun($recipient,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
     114
     115                                if(in_array('id',array_keys($result))){
     116                                    $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>';
     117                                }else{
     118                                    $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>';
     119                                }
     120                            }
    104121                        }
     122                    }
     123                    elseif('SendGrid'===$mailProvider){
     124                        require_once 'connected_mail/sendgrid.php';
     125
     126                        if($dbtool_group_email === 'yes' ){
     127
     128                            $result =  sendmailBySendGrid($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
     129                            $result = json_decode($result, true);
     130                            if(!$result){
     131                                $send_mail_message = '<div class="error">' . __( 'Please Check the API URL', 'dbtool-toolkit' ) . '</div>';
     132                            }
     133                            elseif(in_array('errors',array_keys($result))){
     134                                $send_mail_message = '<div class="error">' . __( 'Bad username / password', 'dbtool-toolkit' ) . '</div>';
     135                            }else{
     136                                $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'dbtool-toolkit' ) . '</div>';
     137                            }
     138
     139                        }
    105140                        else{
    106                             $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'dbtool-toolkit' ) . '</div>';
    107                         }
    108                     }else{
    109                         foreach( $recipients as $recipient ) {
    110                             $result =  sendmailbymailgun($recipient,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
    111 
    112                             if(in_array('id',array_keys($result))){
    113                                 $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>';
    114                             }else{
    115                                 $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'dbtool-toolkit' ) . esc_html($recipient) . '</div>';
    116                             }
    117                         }
    118                     }
    119 
    120 
    121                 }
     141                            foreach( $recipients as $recipient ) {
     142                                var_dump($recipient);
     143                                $result =  sendmailBySendGrid($dbtool_recipient_emails,'',$from_name,$from_email,$dbtool_subject,$dbtool_body, $attachments);
     144                                $result = json_decode($result, true);
     145                                if(!$result){
     146                                    $send_mail_message = '<div class="error">' . __( 'Please Check the API URL', 'dbtool-toolkit' ) . '</div>';
     147                                    break;
     148                                }
     149                                elseif(in_array('errors',array_keys($result))){
     150                                    $send_mail_message = '<div class="error">' . __( 'Bad username / password, Check your uasername & password', 'dbtool-toolkit' ) . '</div>';
     151                                    break;
     152                                }else{
     153                                    $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'dbtool-toolkit' ) . esc_html($recipient) . '!</div>';
     154                                }
     155                            }
     156                        }
     157                    }
     158                }
     159
    122160                else{
    123161                    if ( $dbtool_group_email === 'yes' ) {
  • cf7-db-tool/trunk/src/Plugin.php

    r2279382 r2280329  
    187187        register_setting('mail-provider-support-group', 'mailgun-key');
    188188        // Mailgun api url & Api Key
    189 //      register_setting('mail-provider-support-group', 'sendgrid-api-url');
    190 //      register_setting('mail-provider-support-group', 'sendgrid-user');
    191 //      register_setting('mail-provider-support-group', 'sendgrid-password');
     189        register_setting('mail-provider-support-group', 'sendgrid-api-url');
     190        register_setting('mail-provider-support-group', 'sendgrid-user');
     191        register_setting('mail-provider-support-group', 'sendgrid-password');
    192192
    193193        /**
     
    196196        add_settings_section( 'section_mail_setting', 'Active & Choose Mail Provider', [$this, 'active_mail_provider__section_cb'], 'mail-support-options' );
    197197        add_settings_section( 'mailgun_mail_setting', 'Mailgun Mail Settings ', [$this, 'mailgun_section_cb'], 'mail-support-options' );
    198         //add_settings_section( 'sendgrid_mail_setting', 'SendGrid Mail Settings ', [$this, 'sendgrid_section_cb'], 'mail-support-options' );
     198        add_settings_section( 'sendgrid_mail_setting', 'SendGrid Mail Settings ', [$this, 'sendgrid_section_cb'], 'mail-support-options' );
    199199
    200200        /**
     
    208208        add_settings_field('mailgun_key','Mailgun API KEY', [$this, 'mailgun_key_field_cb'],'mail-support-options','mailgun_mail_setting');
    209209        //For Sendgrid
    210 //      add_settings_field('sendgrid_url','SendGrid API URL', [$this, 'sendgrid_api_url'],'mail-support-options','sendgrid_mail_setting');
    211 //      add_settings_field('sendgrid_username','SendGrid Username', [$this, 'sendgrid_userName'],'mail-support-options','sendgrid_mail_setting');
    212 //      add_settings_field('sendgrid_password','SendGrid Password', [$this, 'sendgrid_userPassword'],'mail-support-options','sendgrid_mail_setting');
     210        add_settings_field('sendgrid_url','SendGrid API URL', [$this, 'sendgrid_api_url'],'mail-support-options','sendgrid_mail_setting');
     211        add_settings_field('sendgrid_username','SendGrid Username', [$this, 'sendgrid_userName'],'mail-support-options','sendgrid_mail_setting');
     212        add_settings_field('sendgrid_password','SendGrid Password', [$this, 'sendgrid_userPassword'],'mail-support-options','sendgrid_mail_setting');
    213213    }
    214214
     
    221221        $active_mailer = get_option('active_mailer');
    222222        $checkded =  ($active_mailer? 'checked' : '');
    223         echo '<label><input type="checkbox"  '.$checkded.'  name="active_mailer" value="1"> Active Thirdparty Mail Service </label>';
     223        echo '<label><input type="checkbox"  '.$checkded.'  name="active_mailer" class="active_mail_provider" value="1"> Active Thirdparty Mail Service </label>';
    224224    }
    225225
     
    227227    public function target_mail_provider(){
    228228        $selec_provider = get_option( 'select_mailer' );
     229
    229230        $mailerList = array('Mailgun','SendGrid');
    230231        $output='';
    231         echo '<select name="select_mailer"  id="choose-mailer">';
     232        echo '<select name="select_mailer"  required id="choose-mailer">';
    232233        echo '<option value="">Select Provider</option>';
    233234        foreach ($mailerList as $mailer ) {
    234             $output .='<option value="'.$mailer.'" > '.$mailer.'</option>';
     235            if($selec_provider == $mailer ){
     236                $selected = 'selected';
     237            }else{
     238                $selected = '';
     239            }
     240            $output .='<option value="'.$mailer.' "  '.$selected.'> '.$mailer.'</option>';
    235241        }
    236242        echo $output;
    237243        echo '</select>';
    238 
    239244    }
    240245
     
    261266    public function sendgrid_api_url(){
    262267        $sendGridApi = get_option('sendgrid-api-url');
    263         $sendGridApi =  ($sendGridApi? $sendGridApi : '');
     268        $sendGridApi =  ($sendGridApi? $sendGridApi : 'https://api.sendgrid.com/');
    264269        echo '<input type="url" class="sendgrid-input"  value="'.$sendGridApi.'" name="sendgrid-api-url" placeholder="https://api.sendgrid.com/"> ';
    265270    }
     
    324329            );
    325330        }elseif ('cf7-db-tool_page_Mail-Settings' == $hook){
    326             //wp_enqueue_script('cf7-dbt-mail-provider', CF7_DBT_URL . '/assets/js/cf7-db-mail-provider.js', ['jquery'], CF7_DBT_VERSION,true);
     331            wp_enqueue_script('cf7-dbt-mail-provider', CF7_DBT_URL . '/assets/js/cf7-db-mail-provider.js', ['jquery'], CF7_DBT_VERSION,true);
    327332        }
    328333
Note: See TracChangeset for help on using the changeset viewer.