Plugin Directory

Changeset 3003278


Ignore:
Timestamp:
11/29/2023 12:30:48 PM (2 years ago)
Author:
sslplugins
Message:

Plugin Updated to 2.0.3

Location:
ssl-wireless-sms-notification/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ssl-wireless-sms-notification/trunk/lib/sslcare-admin-setting.php

    r3003225 r3003278  
    104104        );
    105105
    106         add_settings_field(
    107             'api_url',
    108             __('API URL', $plugin_slug),
    109             array( $this, 'sslcare_api_url_callback'),
    110             'sslcare_notification',
    111             'api_settings_section'
    112         );
    113 
    114106        add_settings_field(
    115107            'api_username',
     
    302294            __('Shipped Alert Template', $plugin_slug),
    303295            array( $this, 'sslcare_shipped_template_callback'),
    304             'sslcare_notification',
    305             'template_settings_section'
    306         );
    307 
    308         add_settings_field(
    309             'sslcare_otp_login_register_template',
    310             __('OTP Login Register Alert Template', $plugin_slug),
    311             array( $this, 'sslcare_otp_login_register_template_callback'),
    312296            'sslcare_notification',
    313297            'template_settings_section'
     
    409393    }
    410394
    411     public function sslcare_api_url_callback() {
    412         $options = get_option( 'sslcare_notification' );
    413 
    414         $api_url = '';
    415         if( isset( $options['api_url'] ) && $options['api_url'] != '' ) {
    416             $api_url = $options['api_url'];
    417         }
    418 
    419         $html = '<input type="text" name="sslcare_notification[api_url]" value="' . $api_url . '" size="65" placeholder="URL of API"/>';
    420         $html .= '<br><label for="api_url">Must input this field.</label>';
    421 
    422         echo $html;
    423     }
    424 
    425395    public function sslcare_username_callback() {
    426396        $options = get_option( 'sslcare_notification' );
     
    745715    }
    746716
    747     public function sslcare_otp_login_register_template_callback() {
    748         $options = get_option( 'sslcare_notification' );
    749 
    750         $sslcare_otp_login_register_template = "Your OTP is {{otp}}.\nThank You\n".get_bloginfo('name');
    751         if( isset( $options['sslcare_otp_login_register_template'] ) && $options['sslcare_otp_login_register_template'] != '' ) {
    752             $sslcare_otp_login_register_template = $options['sslcare_otp_login_register_template'];
    753         }
    754        
    755         $html = '<textarea id="sslcare_otp_login_register_template" rows="4" cols="98" name="sslcare_notification[sslcare_otp_login_register_template]" placeholder="">' . $sslcare_otp_login_register_template . '</textarea>';
    756         $html .= '<br><label for="sslcare_otp_login_register_template"><b>Variables : </b>{{otp}}</label>';
    757         $html .= '<hr>';
    758 
    759         echo $html;
    760     }
     717
    761718
    762719    public function admin_sms_settings_callback() {
     
    839796        }
    840797
    841         if ( isset( $input['api_url'] ) ) {
    842             if (  $input['api_url'] != "" ) {
    843                 $output['api_url'] =  sanitize_textarea_field($input['api_url']) ;
    844             } else {
    845                 add_settings_error( 'sslcare_notification', 'otptxt-error', esc_html__( 'Please enter URL.', $plugin_slug));
    846             }
    847         }
    848 
    849798        if ( isset( $input['api_username'] ) ) {
    850799            if (  $input['api_username'] != "" ) {
     
    1023972        }
    1024973
    1025         if ( isset( $input['sslcare_otp_login_register_template'] ) ) {
    1026             if (  $input['sslcare_otp_login_register_template'] != "" ) {
    1027                 $output['sslcare_otp_login_register_template'] =  sanitize_textarea_field($input['sslcare_otp_login_register_template']) ;
    1028             } else {
    1029                 add_settings_error( 'sslcare_notification', 'otptxt-error', esc_html__( 'Please enter OTP Login Register Alert Template.', $plugin_slug));
    1030             }
    1031         }
    1032 
    1033974        if ( isset( $input['sslcare_admin_sms_alert'] ) ) {
    1034975            if (  $input['sslcare_admin_sms_alert']  ) {
  • ssl-wireless-sms-notification/trunk/lib/sslcare-init.php

    r3003225 r3003278  
    99
    1010            $sslcare_table_name = $wpdb->prefix . "sslcare_woo_alert";
    11             $sslcare_otp_table_name = $wpdb->prefix . "sslcare_otp";
    12             $sslcare_otp_login_register_settings_table_name = $wpdb->prefix . "sslcare_otp_login_register_settings";
    1311
    1412            $charset_collate = '';
     
    3533                dbDelta( $sql );       
    3634            }
    37 
    38             if ($wpdb->get_var("SHOW TABLES LIKE '$sslcare_otp_table_name'") != $sslcare_otp_table_name) {
    39             $sql = "CREATE TABLE $sslcare_otp_table_name (
    40                 id mediumint(15) UNSIGNED NOT NULL AUTO_INCREMENT,
    41                 phone varchar(20) NULL,
    42                 otp int(255) NULL,
    43                 cap_data varchar(100) NULL,
    44                 quantity int(255),
    45                 ip_address varchar(20) NULL,
    46                 sending_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    47                 UNIQUE KEY id (id)
    48                 ) $charset_collate;";
    49                 dbDelta( $sql );       
    50             }
    51 
    52             if ($wpdb->get_var("SHOW TABLES LIKE '$sslcare_otp_login_register_settings_table_name'") != $sslcare_otp_login_register_settings_table_name) {
    53             $sql = "CREATE TABLE $sslcare_otp_login_register_settings_table_name (
    54                 id mediumint(15) UNSIGNED NOT NULL AUTO_INCREMENT,
    55                 enable_otp varchar(20) NULL,
    56                 page_id bigint(20) NULL,
    57                 UNIQUE KEY id (id)
    58                 ) $charset_collate;";
    59                 dbDelta( $sql );       
    60             }
    6135        }
    6236    }
  • ssl-wireless-sms-notification/trunk/lib/sslcare-sms-api.php

    r3003225 r3003278  
    8383        else if($sslcare_api == "ismsplus" && $settings['api_hash_token'] != "")
    8484        {
    85             // Live URL
    86             // $api_url         = "https://smsplus.sslwireless.com/api/v3/send-sms";
    87             // Test URL
    88             // $api_url         = "http://ismsapi.publicdemo.xyz/api/v3/send-sms";
    89             $api_url = $settings['api_url'];
     85            $api_url        = "https://smsplus.sslwireless.com/api/v3/send-sms";
    9086
    9187            $headers = array(
  • ssl-wireless-sms-notification/trunk/lib/sslcare-woo-alert.php

    r3003225 r3003278  
    6969        if($order->get_billing_phone() != "")
    7070        {
    71             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     71            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    7272            $customer_mobile = $order->get_billing_phone();
    7373        }
     
    108108        if($order->get_billing_phone() != "")
    109109        {
    110             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     110            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    111111            $customer_mobile = $order->get_billing_phone();
    112112        }
     
    147147        if($order->get_billing_phone() != "")
    148148        {
    149             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     149            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    150150            $customer_mobile = $order->get_billing_phone();
    151151        }
     
    187187        if($order->get_billing_phone() != "")
    188188        {
    189             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     189            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    190190            $customer_mobile = $order->get_billing_phone();
    191191        }
     
    239239        if($order->get_billing_phone() != "")
    240240        {
    241             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     241            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    242242            $customer_mobile = $order->get_billing_phone();
    243243        }
     
    278278        if($order->get_billing_phone() != "")
    279279        {
    280             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     280            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    281281            $customer_mobile = $order->get_billing_phone();
    282282        }
     
    317317        if($order->get_billing_phone() != "")
    318318        {
    319             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     319            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    320320            $customer_mobile = $order->get_billing_phone();
    321321        }
     
    356356        if($order->get_billing_phone() != "")
    357357        {
    358             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     358            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    359359            $customer_mobile = $order->get_billing_phone();
    360360        }
     
    395395        if($order->get_billing_phone() != "")
    396396        {
    397             $name            = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     397            $name            = $order->get_billing_last_name().' '.$order->get_billing_first_name();
    398398            $customer_mobile = $order->get_billing_phone();
    399399        }
  • ssl-wireless-sms-notification/trunk/readme.txt

    r3003260 r3003278  
    11=== SSL Wireless SMS Notification ===
    2 Contributors: sslplugins
     2Contributors: prabalsslw
    33Tags: SSL Wireless, SSL Care, ISMS, Woocommerce, Notification, bangladesh, official
    4 Author URI: https://sslwireless.com
     4Author URI: prabalsslw.github.io
    55Plugin URI: https://sslwireless.com/
    6 Version: 2.0.3
     6Version: 2.0.0
    77Requires PHP: 5.6
    88Requires at least: 3.6
    9 Tested up to: 6.4.1
    10 Stable tag: 2.0.3
     9Tested up to: 5.4.2
     10Stable tag: 2.0.0
    1111License: GNU General Public License v3.0
    1212License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    36367. Just click `Install` > `Active` and plugin is ready to use.
    37378. Enable plugin, select platform(ISMS or ISMSPlus), Use your API Hash(Only for ISMSPlus), Use your panel credential as `API User/Password`(Only for ISMS), Use `SID` for both platform.
    38 9. If you want to use OTP Login Register Feature go to the OTP Login Register Menu in the Admin Panel. Follow the Guidelines from there. This feature works with Woocommerce My Account.
    39 
    4038
    4139== Plugin Configuration ==
     
    46444. Set the SMS Alert & SMS Template.
    47455. You can also set an Admin phone number and SMS template. If you want to get alert on every successful order.
    48 6. If you want to use the OTP Login Register Feature go to the OTP Login Register Menu in the Admin Panel. Follow the Guidelines from there. This feature works with Woocommerce My Account.
    4946
    5047== Frequently Asked Questions ==
     
    7168* Tested For WC V4.3.0
    7269
    73 = 2.0.3 =
    74 > Release Date - 29 November 2023
    75 
    76 * OTP Login and Registration implemented.
    77 * Tested For WC V8.3.1
    78 
    7970== Upgrade Notice ==
    8071> Release Date - 11 July 2020
    8172> Release Date - 21 July 2020
    82 > Release Date - 29 November 2023
    8373
    8474== Screenshots ==
     
    86762. Plugin configure page 2.
    87773. Plugin configure page 3.
    88 4. Plugin configure page 4.
  • ssl-wireless-sms-notification/trunk/sslWireless.php

    r3003260 r3003278  
    44*  Plugin URI: https://sslwireless.com/
    55*  Description: This plugin allows you to send transactional alert to your customer. This will only work for woocommerce.
    6 *  Version: 2.0.3
    7 *  Stable tag: 2.0.3
    8 *  WC tested up to: 8.3.1
    9 *  Author: SSL Wireless
    10 *  Author URI: sslwireless.com
    11 *  Author Email: reza.farukh@sslwireless.com
     6*  Version: 2.0.0
     7*  Stable tag: 2.0.0
     8*  WC tested up to: 4.3.0
     9*  Author: Prabal Mallick
     10*  Author URI: prabalsslw.github.io
     11*  Author Email: prabalsslw@gmail.com
    1212*  License: GNU General Public License v3.0
    1313*  License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2020 * @since      1.0.0
    2121 * @package    SSLWireless_Woocommerce
    22  * @author     SSL Wireless <reza.farukh@sslwireless.com>
     22 * @author     Prabal Mallick <prabalsslw@gmail.com>
    2323 */
    2424
     
    2828    define( 'SSLW_SMS_URL', plugin_dir_url( __FILE__ ) );
    2929
    30     define ( 'SSLW_SMS_NOTIFICATION_VERSION', '2.0.3');
     30    define ( 'SSLW_SMS_NOTIFICATION_VERSION', '2.0.0');
    3131   
    3232    global $plugin_slug;
    3333    $plugin_slug = 'sslcare';
    3434    $options = get_option( 'sslcare_notification' );
    35 
    36     // echo "<pre>";
    37     // print_r($options);
    38 
    39     global $api_hash_token;
    40     global $api_url;
    41     global $api_username;
    42     global $api_password;
    43     global $sslcare_api_sid;
    44     global $sslcare_otp_login_register_template;
    45 
    46     $api_hash_token = $options['api_hash_token'];
    47     $api_url = $options['api_url'];
    48     $api_username = $options['api_username'];
    49     $api_password = $options['api_password'];
    50     $sslcare_api_sid = $options['sslcare_api_sid'];
    51     $sslcare_otp_login_register_template = $options['sslcare_otp_login_register_template'];
    5235
    5336    require_once( SSLW_SMS_PATH . 'lib/sslcare-init.php' );
     
    9275            'settings' => '<a href="'. esc_url(admin_url( 'admin.php?page=sslcare-notification')) .'">Settings</a>',
    9376            'docs'     => '<a href="https://www.sslwireless.com/enterprise-solutions/api-based-sms/" target="blank">Docs</a>',
    94             'support'  => '<a href="mailto:reza.farukh@sslwireless.com">Support</a>'
     77            'support'  => '<a href="mailto:prabalsslw@gmail.com">Support</a>'
    9578        );
    9679
     
    10184
    10285    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'sslwireless_care_settings_link');
    103 
    104     /* Custom CSS of OTP Login Register file for Backend---*/
    105     function wpdocs_enqueue_custom_admin_style() {
    106         wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ).'lib/asset/css/style-backend-sslcare-otp-login-register.css', false, '1.0.2' );
    107         wp_enqueue_style( 'custom_wp_admin_css' );
    108     }
    109     add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );
    110 
    111      /* An Admin page with Menu for OTP Login Register */
    112     function otp_login_register_admin_menu() {
    113         add_menu_page('OTP Login Register', 'OTP Login Register', 'manage_options', 'sslcare-otp-login-register', 'otp_login_register_page_content');
    114     }
    115 
    116     add_action( 'admin_menu', 'otp_login_register_admin_menu' );
    117 
    118     function otp_login_register_page_content(){ ?>
    119         <div class="admin-custom-container">
    120             <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:20px;">
    121                 <h1 class="title"><?php esc_html_e( 'OTP Login Register Settings', 'my-plugin-textdomain' ); ?></h1>
    122             </div>
    123             <?php
    124                
    125                 global $wpdb;
    126                 $table_otp_login_register_settings = $wpdb->prefix . "sslcare_otp_login_register_settings";
    127                 $checkData = $wpdb->get_row( "SELECT * FROM $table_otp_login_register_settings WHERE id =1");
    128            
    129                 if(isset($_POST['submit_setting'])){                   
    130 
    131                     if($checkData){
    132                         $result = $wpdb->query($wpdb->prepare("UPDATE $table_otp_login_register_settings SET
    133                             enable_otp = '".$_POST['enable_otp']."',
    134                             page_id = '".$_POST['page']."'
    135                         WHERE id=1")); 
    136 
    137                     }else{
    138                         $result = $wpdb->insert($table_otp_login_register_settings, array(
    139                             'enable_otp' => $_POST['enable_otp'],
    140                             'page_id' => $_POST['page'],
    141                         ));
    142                     }
    143 
    144                     if($result){
    145                         $redirect_url = admin_url( '/admin.php?page=sslcare-otp-login-register' );
    146                     }
    147                    
    148                     ?>
    149                    
    150                     <script>
    151                         document.location.href = "<?php echo $redirect_url ?>";
    152                     </script>
    153                    
    154                     <?php
    155                 }
    156             ?>
    157 
    158             <div class="card card-custom">
    159                 <div class="card-body">
    160                     <h2>Guidelines</h2>
    161                     <ul>
    162                         <li>1. Create a page and place this shortcode "[sslcare_otp_login_register]" to the Page.</li>
    163                         <li>2. From below option find Set Login Register Page Here Option</li>
    164                         <li>3. Set this page you created as Login Register Page</li>
    165                     </ul>
    166                 </div>
    167             </div>     
    168             <!-- form -->
    169             <div class="card card-custom">
    170               <div class="card-body">
    171                 <form id="formOtpLoginRegisterSettings" action="" method="POST" autocomplete="off">
    172                   <div class="form-group-custom">
    173                     <label for="title">Enable OTP Login</label>
    174                     <select id="enable_otp" name="enable_otp" required>
    175                         <option value="">Select an option</option>
    176                         <option value='No' <?php if(isset($checkData->enable_otp) && $checkData->enable_otp == 'No') { ?>selected<?php } ?>>No</option>
    177                         <option value='Yes' <?php if(isset($checkData->enable_otp) && $checkData->enable_otp == 'Yes') { ?>selected<?php } ?>>Yes</option>
    178                     </select>   
    179                   </div>
    180                   <div class="form-group-custom">
    181                     <label for="title">Set Login Register Page Here</label>
    182                     <?php
    183                     $pages = get_pages();
    184                     // echo $checkData->page_id;
    185                     ?>
    186                     <select id="page" name="page" required>
    187                         <option value="">Select a Page</option>
    188                         <?php foreach ($pages as $page) { ?>
    189                         <option value='<?php echo $page->ID; ?>'<?php if(isset($checkData->page_id) && $checkData->page_id == $page->ID) { ?>selected<?php } ?>><?php echo $page->post_title; ?></option>
    190                         <?php } ?>
    191                     </select>   
    192                   </div>
    193                   <button class="page-title-action-custom success" name="submit_setting">Save</button>
    194                 </form>
    195               </div><!--/card-block-->
    196             </div><!-- /form card Add a Job -->
    197         </div> 
    198     <?php       
    199     }
    200 
    201     function enqueue_my_script() {
    202         wp_enqueue_script('otp-login-register-script', plugin_dir_url( __FILE__ ) . 'lib/asset/js/otp-login-register.js?v=2.7', array('jquery'), '1.0', true);
    203    
    204         // Localize the script with the nonce
    205         wp_localize_script('otp-login-register-script', 'ajax_otp_login_object', array('plugin_directory' => plugin_dir_url(__FILE__), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('my_unique_login_nonce_action')));
    206 
    207         wp_localize_script('otp-login-register-script', 'ajax_otp_register_object', array('plugin_directory' => plugin_dir_url(__FILE__), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('my_unique_register_nonce_action')));
    208 
    209         wp_localize_script('otp-login-register-script', 'ajax_otp_send_object', array('plugin_directory' => plugin_dir_url(__FILE__), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('my_unique_otp_nonce_action')));
    210 
    211         wp_localize_script('otp-login-register-script', 'ajax_final_login_object', array('plugin_directory' => plugin_dir_url(__FILE__), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('my_unique_otp_nonce_action')));
    212 
    213     }
    214     add_action('wp_enqueue_scripts', 'enqueue_my_script');
    215 
    216     add_action('wp_ajax_otp_login_ajax_action', 'otp_login_ajax_callback');
    217     add_action('wp_ajax_nopriv_otp_login_ajax_action', 'otp_login_ajax_callback');
    218 
    219     add_action('wp_ajax_otp_register_ajax_action', 'otp_register_ajax_callback');
    220     add_action('wp_ajax_nopriv_otp_register_ajax_action', 'otp_register_ajax_callback');
    221 
    222     add_action('wp_ajax_otp_send_ajax_action', 'otp_send_ajax_callback');
    223     add_action('wp_ajax_nopriv_otp_send_ajax_action', 'otp_send_ajax_callback');
    224 
    225     add_action('wp_ajax_final_login_ajax_action', 'final_login_ajax_callback');
    226     add_action('wp_ajax_nopriv_final_login_ajax_action', 'final_login_ajax_callback');
    227 
    228     function otp_login_ajax_callback() {
    229         // Verify the nonce
    230         if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'my_unique_login_nonce_action')) {
    231             // Nonce is valid, perform your AJAX processing here
    232             if(isset($_POST['phone']) && isset($_POST['capData'])){
    233 
    234                 global $api_hash_token;
    235                 global $api_url;
    236                 global $api_username;
    237                 global $api_password;
    238                 global $sslcare_api_sid;
    239                 global $sslcare_otp_login_register_template;
    240 
    241                 $client_ip = $_SERVER['REMOTE_ADDR'];
    242                 $date = date('Y-m-d H:i:s');
    243 
    244                 $phone = $_POST['phone'];
    245 
    246                 $users = get_users(array(
    247                     'meta_key' => 'sslcare_login_phone',
    248                     'meta_value' => $phone,
    249                     'number'      => 1,  // Limit the query to one user
    250                     'count_total' => false, // Don't calculate total users, only need one
    251                 ));
    252 
    253                 if(empty($users)){
    254                     $dataCheck = 'user-not-found';
    255                     echo wp_send_json($dataCheck);
    256                     exit();
    257                 }else{
    258                     $user_id = $users[0]->ID; // Get the user ID
    259                     // Check if the user has no role
    260                     $user = get_userdata($user_id);
    261                     $user_roles = $user->roles;
    262                     if (empty($user_roles)) {
    263                         // User has no role
    264                         // echo 'User has no role.';
    265                         $dataCheck = 'user-has-no-role';
    266                         echo wp_send_json($dataCheck);
    267                         exit();
    268                     }
    269                     if(!empty($users[0]->sslcare_login_phone) && $users[0]->sslcare_login_phone == $phone){
    270    
    271                         $randnum = time().uniqid(rand(11111,99999));
    272                         $otp = rand(11111,99999);
    273 
    274                         // Replace {{otp}} with dynamic code
    275                         $outputString = str_replace('{{otp}}', $otp, $sslcare_otp_login_register_template);
    276 
    277                         // echo wp_send_json($outputString);
    278                         // exit();
    279                         $params = json_encode([
    280                            
    281                                 "api_token" => $api_hash_token,
    282                                 "sid" => $sslcare_api_sid,
    283                                 "msisdn" => $phone,
    284                                 "sms" => $outputString,
    285                                 "csms_id" => $randnum
    286                         ]);
    287 
    288                         $curl = curl_init();
    289                         curl_setopt_array($curl, array(
    290                             CURLOPT_URL => $api_url,
    291                             CURLOPT_RETURNTRANSFER => true,
    292                             CURLOPT_ENCODING => '',
    293                             CURLOPT_MAXREDIRS => 10,
    294                             CURLOPT_TIMEOUT => 0,
    295                             CURLOPT_FOLLOWLOCATION => true,
    296                             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    297                             CURLOPT_CUSTOMREQUEST => 'POST',
    298                             CURLOPT_POSTFIELDS => $params,
    299                             CURLOPT_HTTPHEADER => array(
    300                             'Content-Type: application/json',
    301                             'Accept:application/json'
    302                             ),
    303                         ));
    304                    
    305                         $response = curl_exec($curl);
    306                    
    307                         curl_close($curl);
    308                         // $dataNow = wp_send_json($response);
    309                         $assocArray = json_decode($response, true);
    310                         // print_r($assocArray);
    311    
    312                         global $wpdb;
    313                         $sslcare_otp_table_name = $wpdb->prefix . "sslcare_otp";
    314                         $check_data = $wpdb->get_row( "SELECT * FROM $sslcare_otp_table_name WHERE phone = '".$assocArray['smsinfo'][0]['msisdn']."'");
    315    
    316                         if($check_data){
    317                             $quantity_now = $check_data->quantity + 1;
    318                             if($quantity_now <=20){
    319                                 $result = $wpdb->query($wpdb->prepare("UPDATE $sslcare_otp_table_name SET
    320                                     otp = '".$otp."',
    321                                     cap_data = '".$_POST['capData']."',
    322                                     ip_address = '".$client_ip."',
    323                                     quantity = '".$quantity_now."',
    324                                     sending_time = '".$date."'
    325                                 WHERE id=$check_data->id"));
    326                             }else{
    327                                 $dataCheck = 'sms-limit-exceeded';
    328                                 echo wp_send_json($dataCheck);
    329                                 exit();
    330                             }
    331                         }else{
    332                             $result = $wpdb->insert($sslcare_otp_table_name, array(
    333                                 'phone' => $assocArray['smsinfo'][0]['msisdn'],
    334                                 'otp' => $otp,
    335                                 'cap_data' => $_POST['capData'],
    336                                 'quantity' => 1,
    337                                 'ip_address' => $client_ip,
    338                                 'sending_time' => $date,
    339                             ));
    340                         }
    341                         if($result){
    342                             $twoMinutesLater = date("Y-m-d H:i:s", strtotime($date . " +2 minutes"));
    343                             $dataArray = [
    344                                 "status_code" => $assocArray['status_code'],
    345                                 "sms_status" => $assocArray['smsinfo'][0]['sms_status'],
    346                                 "phone" => $assocArray['smsinfo'][0]['msisdn'],
    347                                 'cap_data' => $_POST['capData'],
    348                                 "future_time" => $twoMinutesLater,
    349                                 "otp_sent_time" => $date,
    350                             ];
    351                             echo wp_send_json($dataArray);
    352                         }else{
    353                             $dataCheck = 'otp-not-sent';
    354                             echo wp_send_json($dataCheck);
    355                             exit();
    356                         }
    357                     }
    358                 }
    359             }
    360         } else {
    361             // Nonce is not valid
    362             echo 'Nonce verification failed.';
    363         }
    364 
    365         wp_die(); // Always include this at the end of your AJAX callback
    366     }
    367 
    368     function otp_register_ajax_callback() {
    369         if(isset($_POST['register'])){
    370             if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'my_unique_register_nonce_action')) {
    371                 // Nonce is valid, process the AJAX request
    372                 // Your AJAX processing code here
    373                 if(isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['capData'])){
    374 
    375                     global $api_hash_token;
    376                     global $api_url;
    377                     global $api_username;
    378                     global $api_password;
    379                     global $sslcare_api_sid;
    380                     global $sslcare_otp_login_register_template;
    381 
    382                     $client_ip = $_SERVER['REMOTE_ADDR'];
    383                     $date = date('Y-m-d H:i:s');
    384 
    385                     $email = $_POST['email'];
    386                     $phone = $_POST['phone'];
    387 
    388                     $users = get_users(array(
    389                         'meta_key' => 'sslcare_login_phone',
    390                         'meta_value' => $phone,
    391                     ));
    392 
    393                     $user = get_user_by('email', $email);
    394                     // Check if a user with the given email is found
    395                     if ($user) {
    396                         $dataCheck = 'user-already-exists';
    397                         echo wp_send_json($dataCheck);
    398                         exit();
    399                     }
    400                     if(!empty($users[0]->sslcare_login_phone)){
    401                         $dataCheck = 'user-already-exists';
    402                         echo wp_send_json($dataCheck);
    403                         exit();
    404                     }
    405                    
    406                     $randnum = time().uniqid(rand(11111,99999));
    407                     $otp = rand(11111,99999);
    408 
    409                     // Replace {{otp}} with dynamic code
    410                     $outputString = str_replace('{{otp}}', $otp, $sslcare_otp_login_register_template);
    411 
    412                     // echo wp_send_json($outputString);
    413                     // exit();
    414                     $params = json_encode([
    415                        
    416                             "api_token" => $api_hash_token,
    417                             "sid" => $sslcare_api_sid,
    418                             "msisdn" => $phone,
    419                             "sms" => $outputString,
    420                             "csms_id" => $randnum
    421                     ]);
    422 
    423                     $curl = curl_init();
    424                     curl_setopt_array($curl, array(
    425                         CURLOPT_URL => $api_url,
    426                         CURLOPT_RETURNTRANSFER => true,
    427                         CURLOPT_ENCODING => '',
    428                         CURLOPT_MAXREDIRS => 10,
    429                         CURLOPT_TIMEOUT => 0,
    430                         CURLOPT_FOLLOWLOCATION => true,
    431                         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    432                         CURLOPT_CUSTOMREQUEST => 'POST',
    433                         CURLOPT_POSTFIELDS => $params,
    434                         CURLOPT_HTTPHEADER => array(
    435                         'Content-Type: application/json',
    436                         'Accept:application/json'
    437                         ),
    438                     ));
    439                
    440                     $response = curl_exec($curl);
    441                
    442                     curl_close($curl);
    443                     // $dataNow = wp_send_json($response);
    444                     $assocArray = json_decode($response, true);
    445                     // print_r($assocArray);
    446 
    447                     global $wpdb;
    448            
    449                     $sslcare_otp_table_name = $wpdb->prefix . "sslcare_otp";
    450                
    451                     $check_data = $wpdb->get_row( "SELECT * FROM $sslcare_otp_table_name WHERE phone = '".$assocArray['smsinfo'][0]['msisdn']."'");
    452 
    453                     if($check_data){
    454                         $quantity_now = $check_data->quantity + 1;
    455                         if($quantity_now <=20){
    456                             $result = $wpdb->query($wpdb->prepare("UPDATE $sslcare_otp_table_name SET
    457                                 otp = '".$otp."',
    458                                 cap_data = '".$_POST['capData']."',
    459                                 ip_address = '".$client_ip."',
    460                                 quantity = '".$quantity_now."',
    461                                 sending_time = '".$date."'
    462                             WHERE id=$check_data->id"));
    463                         }else{
    464                             $dataCheck = 'sms-limit-exceeded';
    465                             echo wp_send_json($dataCheck);
    466                             exit();
    467                         }
    468                     }else{
    469                         $result = $wpdb->insert($sslcare_otp_table_name, array(
    470                             'phone' => $assocArray['smsinfo'][0]['msisdn'],
    471                             'otp' => $otp,
    472                             'cap_data' => $_POST['capData'],
    473                             'quantity' => 1,
    474                             'ip_address' => $client_ip,
    475                             'sending_time' => $date,
    476                         ));
    477                     }
    478                     if($result){
    479                         $twoMinutesLater = date("Y-m-d H:i:s", strtotime($date . " +2 minutes"));
    480                         $dataArray = [
    481                             "status_code" => $assocArray['status_code'],
    482                             "sms_status" => $assocArray['smsinfo'][0]['sms_status'],
    483                             "phone" => $assocArray['smsinfo'][0]['msisdn'],
    484                             "email" => $email,
    485                             "cap_data" => $_POST['capData'],
    486                             "future_time" => $twoMinutesLater,
    487                             "otp_sent_time" => $date,
    488                         ];
    489                         echo wp_send_json($dataArray);
    490                         exit();
    491                     }else{
    492                         $dataCheck = 'otp-not-sent';
    493                         echo wp_send_json($dataCheck);
    494                         exit();
    495                     }
    496                 }
    497                
    498             } else {
    499                 // Nonce is not valid, return an error response or take appropriate action
    500                 wp_send_json_error('Nonce verification failed.');
    501             }
    502         }
    503     }
    504 
    505     function otp_send_ajax_callback() {
    506         if(isset($_POST['register']) || isset($_POST['login'])){
    507             if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'my_unique_otp_nonce_action')) {
    508                 // Nonce is valid, process the AJAX request
    509                 // Your AJAX processing code here
    510                 if(isset($_POST['phone']) && isset($_POST['otp']) && isset($_POST['capData'])){
    511        
    512                     $phone = $_POST['phone'];
    513                     $otp = $_POST['otp'];
    514                     $capData = $_POST['capData'];
    515                
    516                     global $wpdb;
    517                
    518                     $sslcare_otp_table_name = $wpdb->prefix . "sslcare_otp";
    519                
    520                     $result = $wpdb->get_row( "SELECT * FROM $sslcare_otp_table_name WHERE phone = $phone AND otp = $otp AND cap_data = '".$capData."'");
    521                
    522                     if($result){
    523                         if($result->cap_data === $capData){
    524                             $sslcare_login_phone_compatible =  substr($phone, 2);
    525                             $users = get_users(array(
    526                                 'meta_key' => 'sslcare_login_phone',
    527                                 'meta_value' => $sslcare_login_phone_compatible,
    528                             ));
    529 
    530                             if(!empty($users)){
    531                                 $user_id = $users[0]->ID; // Get the user ID
    532                                 $user_data = get_userdata($user_id);
    533                                 $user_email = $user_data->user_email;
    534                                 $dataArray = [
    535                                     "email" => $user_email,
    536                                     "phone" => $phone,
    537                                     // "otp" => $result->otp,
    538                                 ];
    539                             }else{
    540                                 $dataArray = [
    541                                     "email" => $_POST['email'],
    542                                     "phone" => $phone,
    543                                     // "otp" => $result->otp,
    544                                 ];
    545                             }
    546                             // Current datetime
    547                             $currentDatetime = new DateTime();
    548            
    549                             // Another datetime to compare (e.g., a stored datetime from the database)
    550                             $storedDatetime = new DateTime($result->sending_time); // Replace with your stored datetime
    551            
    552                             // Calculate the difference in minutes
    553                             $interval = $currentDatetime->diff($storedDatetime);
    554                             $minutesDifference = $interval->i; // Minutes difference
    555            
    556                             if ($minutesDifference < 2) {
    557                                 // echo "Data inserted Successfully";
    558                                
    559                                 echo wp_send_json($dataArray);
    560                                 // echo 'success';
    561                             }else{
    562                                 $dataCheck = 'otp-expired';
    563                                 echo wp_send_json($dataCheck);
    564                                 exit();
    565                             }
    566                         }
    567                     }else{
    568                         $dataCheck = 'otp-incorrect';
    569                             echo wp_send_json($dataCheck);
    570                         exit();
    571                     }
    572                 }
    573             } else {
    574                 // Nonce is not valid, return an error response or take appropriate action
    575                 wp_send_json_error('Nonce verification failed.');
    576             }
    577         }
    578     }
    579 
    580     function final_login_ajax_callback() {
    581 
    582         //This is for Register only
    583         if(isset($_POST['register'])){
    584             if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'my_unique_otp_nonce_action')) {
    585                 if(isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['register'])){
    586 
    587                     global $wpdb;
    588                
    589                     // Define user information
    590                     $phone = $_POST['phone'];
    591                     $email = $_POST['email'];
    592                     $digits = 9;
    593                     $username = 'user_'.rand(pow(10, $digits-1), pow(10, $digits)-1);
    594                     // $username = 'custom_user';
    595                     $password = 'U8*I6J*V$gKkKGT*';
    596                
    597                     // Create a new user
    598                     $user_id = wp_insert_user(array(
    599                         'user_login' => $username,
    600                         'user_pass' => $password,
    601                         'user_email' => $email,
    602                         'role' => 'customer',  // Set the desired user role (e.g., 'customer' or 'subscriber')
    603                     ));
    604                
    605                     if (is_wp_error($user_id)) {
    606                         // User creation failed, handle the error
    607                         // echo 'User creation failed: ' . $user_id->get_error_message();
    608                         $dataCheck = 'user-already-exists';
    609                         echo wp_send_json($dataCheck);
    610                         exit();
    611                     } else {
    612                         $sslcare_login_phone_compatible =  substr($phone, 2);
    613                         // User creation successful
    614                         // update_user_meta( $user_id, "billing_first_name", 'First Name of Zia' );
    615                         // update_user_meta( $user_id, "billing_last_name", 'Last Name of Zia' );
    616                         update_user_meta( $user_id, "sslcare_login_phone", $sslcare_login_phone_compatible );
    617                         update_user_meta( $user_id, 'billing_phone', $sslcare_login_phone_compatible);
    618                         // update_user_meta( $user_id, "billing_email", $email );
    619                         // echo 'User created with ID: ' . $user_id;
    620                         $user_data = array(
    621                             'user_login' => $username, // Replace with the custom username.
    622                             'user_email' => $email, // Replace with the custom email.
    623                             // 'user_pass' => '', // Leave the password empty.
    624                         );
    625                         $user = get_user_by('login', $user_data['user_login']);
    626                         wp_set_current_user($user->ID, $user->user_login);
    627                         wp_set_auth_cookie($user->ID);
    628                         echo wp_send_json($user_data);
    629                     }
    630                 }
    631             }
    632         }
    633 
    634         //This is for Login only
    635         if(isset($_POST['login'])){
    636             if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'my_unique_otp_nonce_action')) {
    637                 if(isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['login'])){
    638 
    639                     global $wpdb;
    640                
    641                     $sslcare_otp_table_name = $wpdb->prefix . "sslcare_otp";
    642                
    643                     // Define user information
    644                     $phone = $_POST['phone'];
    645                     $email = $_POST['email'];
    646                
    647                     $user = get_user_by('email', $email);
    648                     wp_set_current_user($user->ID, $user->user_login);
    649                     wp_set_auth_cookie($user->ID);
    650                
    651                     $user_data = array(
    652                         'user_login' => $user->user_login, // Replace with the custom username.
    653                         'user_email' => $user->user_email, // Replace with the custom email.
    654                         // 'user_pass' => '', // Leave the password empty.
    655                     );
    656 
    657                     $sslcare_login_phone_compatible =  substr($phone, 2);
    658 
    659                     update_user_meta( $user->ID, 'billing_phone', $sslcare_login_phone_compatible);
    660                    
    661                     echo wp_send_json($user_data);
    662                
    663                 }
    664             }
    665         }
    666     }
    667 
    668 
    669     function sslcare_otp_login_register_shortcode_function($atts) {
    670         ob_start();
    671         // Get the path to the plugin directory
    672         $plugin_dir_path = plugin_dir_path( __FILE__ );
    673         // Include your plugin file
    674         include_once $plugin_dir_path . 'lib/sslcare-otp-login-register.php';
    675         $ret = ob_get_contents();
    676         ob_end_clean();
    677         return $ret;
    678         ?>
    679     <?php
    680     }
    681     add_shortcode('sslcare_otp_login_register', 'sslcare_otp_login_register_shortcode_function');
    682 
    683     function custom_login_redirect($redirect_to, $request, $user) {
    684         return home_url();
    685     }
    686     add_filter('login_redirect', 'custom_login_redirect', 10, 3);
    687 
    688 
    689     add_action('template_redirect', 'custom_my_account_redirect');
    690 
    691     function custom_my_account_redirect() {
    692         global $wpdb;
    693         $table_otp_login_register_settings = $wpdb->prefix . "sslcare_otp_login_register_settings";
    694         $otp_login_register_custom_page = $wpdb->get_row( "SELECT * FROM $table_otp_login_register_settings WHERE id = 1");
    695         if($otp_login_register_custom_page->enable_otp == 'Yes'){
    696             $page_id = $otp_login_register_custom_page->page_id;
    697             if($page_id){
    698                 // Get the page permalink.
    699                 $page_permalink = get_permalink($page_id);
    700                 if (!is_user_logged_in() && is_account_page()) {
    701                     // Replace 'your-custom-url' with the URL you want to redirect users to.
    702                     wp_redirect($page_permalink);
    703                     exit();
    704                 }
    705             }
    706         }
    707     }
    708 
    709     // Display the Phone field on the account details page
    710     function add_sslcare_login_phone_field() {
    711         ?>
    712         <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
    713             <label for="sslcare_login_phone"><?php _e('Phone', 'woocommerce'); ?> (Valid format eg: 01XXXXXXXXX 11 digit only)<span class="required">*</span></label>
    714             <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sslcare_login_phone" id="sslcare_login_phone" pattern="01[3-9]\d{8}" value="<?php echo esc_attr(get_user_meta(get_current_user_id(), 'sslcare_login_phone', true)); ?>" required />
    715         </p>
    716         <?php
    717     }
    718 
    719     add_action('woocommerce_edit_account_form', 'add_sslcare_login_phone_field');
    720 
    721 
    722     // Save Phone to User Meta and Ensure Uniqueness:
    723 
    724     $user_id = get_current_user_id();
    725     function save_sslcare_login_phone_field($user_id) {
    726         $sslcare_login_phone = isset($_POST['sslcare_login_phone']) ? sanitize_text_field($_POST['sslcare_login_phone']) : '';
    727    
    728         // Check if the Phone is already associated with another user
    729         $existing_users = get_users(array('meta_key' => 'sslcare_login_phone', 'meta_value' => $sslcare_login_phone));
    730 
    731         $phone_pattern = "/^01[3-9]\d{8}$/";
    732 
    733         if (!empty($sslcare_login_phone)) {
    734             if (!preg_match($phone_pattern, $sslcare_login_phone)) {
    735                 wc_add_notice(__('Phone format is not supported. Please try to input valid Phone number eg: 01XXXXXXXXX (11 digit only)'), 'error');
    736             }else{
    737                 if (!empty($existing_users)) {
    738                     $sslcare_login_phone_of_this_user = get_user_meta($user_id, 'sslcare_login_phone', true);
    739                     if($sslcare_login_phone_of_this_user === $sslcare_login_phone){
    740                         update_user_meta($user_id, 'sslcare_login_phone', $sslcare_login_phone);
    741                     }else{
    742                         wc_add_notice(__('The Phone you entered is already in use by another user. Please choose a different Phone Number', 'woocommerce'), 'error');
    743                     }
    744                 }else{
    745                     update_user_meta($user_id, 'sslcare_login_phone', $sslcare_login_phone);
    746                     update_user_meta($user_id, 'billing_phone', $sslcare_login_phone);
    747                 }
    748             }
    749         }else{
    750             echo "Error";
    751         }
    752     }
    753    
    754     add_action('woocommerce_save_account_details', 'save_sslcare_login_phone_field');
    755 
    756     // Allow saving account details without entering password
    757     add_filter('woocommerce_save_account_details_requires_password', '__return_false');
    758 
    759     /**
    760      * Validate billing phone during account creation on WooCommerce checkout.
    761      */
    762     function validate_billing_phone_unique($fields, $errors) {
    763         $user_id = get_current_user_id();
    764         $billing_phone = isset($_POST['billing_phone']) ? sanitize_text_field($_POST['billing_phone']) : '';
    765 
    766         // Check if the Phone is already associated with another user
    767         $existing_users = get_users(array('meta_key' => 'sslcare_login_phone', 'meta_value' => $billing_phone));
    768 
    769         $phone_pattern = "/^01[3-9]\d{8}$/";
    770 
    771         $sslcare_login_phone_of_this_user = get_user_meta($user_id, 'sslcare_login_phone', true);
    772 
    773         if (is_user_logged_in()) {
    774             if (!empty($billing_phone)) {
    775                 if (!preg_match($phone_pattern, $billing_phone)) {
    776                     wc_add_notice(__('Phone format is not supported. Please try to input valid Phone number eg: 01XXXXXXXXX (11 digit only)'), 'error');
    777                 }else{
    778                     if (!empty($existing_users)) {
    779                         if($sslcare_login_phone_of_this_user != $billing_phone){
    780                             wc_add_notice(__('The Phone you entered is already in use by another user. Please choose a different Phone Number', 'woocommerce'), 'error');
    781                         }
    782                     }
    783                     if($sslcare_login_phone_of_this_user != $billing_phone){
    784                         wc_add_notice(__('Billing Phone is not allowed to change.'), 'error');
    785                     }
    786                 }
    787             }else{
    788                 echo "Error";
    789             }
    790         }else{
    791             if (!empty($billing_phone)) {
    792                 if (!preg_match($phone_pattern, $billing_phone)) {
    793                     wc_add_notice(__('Phone format is not supported. Please try to input valid Phone number eg: 01XXXXXXXXX (11 digit only)'), 'error');
    794                 }else{
    795                     if (isset($_POST['createaccount'])) {
    796                         $create_account_checked = wc_string_to_bool($_POST['createaccount']);
    797                
    798                         if ($create_account_checked) {
    799                             if (!empty($existing_users)) {
    800                                 wc_add_notice(__('The Phone you entered is already in use by another user. Please choose a different Phone Number', 'woocommerce'), 'error');
    801                             }
    802                         }
    803                     }
    804                 }
    805             }   
    806         }
    807     }
    808 
    809     // Hook into the checkout validation
    810     add_action('woocommerce_after_checkout_validation', 'validate_billing_phone_unique', 10, 2);
    811 
    812     /**
    813      * Update user meta after creating an account during WooCommerce checkout.
    814      */
    815     function update_user_meta_after_checkout($user_id, $posted_data) {
    816         // Check if a user was created
    817         if ($user_id > 0) {
    818             $billing_phone = get_user_meta($user_id, 'billing_phone', true);
    819             update_user_meta($user_id, 'sslcare_login_phone', $billing_phone);
    820         }
    821     }
    822 
    823     add_action('woocommerce_checkout_update_user_meta', 'update_user_meta_after_checkout', 10, 2);
    824 
    825     /**
    826      * Disable billing phone field if the user is logged in.
    827      */
    828     function disable_billing_phone_field($fields) {
    829         // Check if the user is logged in
    830         if (is_user_logged_in()) {
    831             // Disable the billing phone field
    832             $fields['billing']['billing_phone']['custom_attributes']['readonly'] = 'true';
    833             // Remove the billing phone field
    834             // unset($fields['billing']['billing_phone']);
    835         }
    836 
    837         return $fields;
    838     }
    839 
    840     add_filter('woocommerce_checkout_fields', 'disable_billing_phone_field');
    841 
    842     function custom_delete_table_data() {
    843         global $wpdb;
    844    
    845         // Replace 'your_table_name' with the actual name of your table
    846         $sslcare_otp_table_name = $wpdb->prefix . 'sslcare_otp';
    847    
    848         // $result = $wpdb->query($wpdb->prepare("UPDATE $sslcare_otp_table_name SET
    849         //  quantity = 0
    850         // WHERE quantity=5"));
    851         // Delete all data from the table
    852 
    853         // Calculate the timestamp for 24 hours ago
    854         $timestamp = current_time('timestamp') - (24 * 60 * 60);
    855 
    856         $all_data = $wpdb->get_results( "SELECT * FROM $sslcare_otp_table_name");
    857         foreach($all_data as $single_data){
    858             $sending_time = strtotime($single_data->sending_time);
    859             if($sending_time < $timestamp){
    860                 $wpdb->query("DELETE FROM $sslcare_otp_table_name WHERE id=$single_data->id");
    861             }
    862         }
    863     }
    864     // Schedule the event to run daily
    865     add_action('wp', 'schedule_custom_delete');
    866     function schedule_custom_delete() {
    867         if (!wp_next_scheduled('custom_delete_table_data_event')) {
    868             wp_schedule_event(time(), 'daily', 'custom_delete_table_data_event');
    869         }
    870     }
    871     // Hook your function to the scheduled event
    872     add_action('custom_delete_table_data_event', 'custom_delete_table_data');
    873 
    87486?>
Note: See TracChangeset for help on using the changeset viewer.