*/ class Alpha_sms_Public { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; private $options; /** * @var false */ private $pluginActive; /** * Cached OTP storage key for the current visitor. * * @var string|null */ private $otpTransientKey = null; /** * Maximum number of OTP requests allowed for guest checkout within the rate limit window. * * @var int */ private $checkoutOtpRateLimit = 4; /** * Time window in seconds for guest checkout OTP rate limiting. * * @var int */ private $checkoutOtpRateWindow = 900; /** * Initialize the class and set its properties. * * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. * * @since 1.0.0 */ public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; $this->options = get_option($this->plugin_name); $this->pluginActive = !empty($this->options['api_key']); } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Alpha_sms_Loader as all of the hooks are defined * in that particular class. * * The Alpha_sms_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name, plugin_dir_url(__FILE__) . 'css/alpha_sms-public.css', [], $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Alpha_sms_Loader as all of the hooks are defined * in that particular class. * * The Alpha_sms_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name, plugin_dir_url(__FILE__) . 'js/alpha_sms-public.js', ['jquery'], $this->version, false ); // adding a js variable for ajax form submit url wp_localize_script( $this->plugin_name, $this->plugin_name . '_object', ['ajaxurl' => admin_url('admin-ajax.php')] ); } /** * Woocommerce * show phone number on register page and my account */ public function wc_phone_on_register() { if (!$this->pluginActive || !$this->options['wc_reg']) { return; } $user = wp_get_current_user(); $value = isset($_POST['billing_phone']) ? sanitize_text_field($_POST['billing_phone']) : $user->billing_phone; ?>

pluginActive || !$this->options['wp_reg']) { return; } require_once 'partials/add-otp-on-login-form.php'; ?> pluginActive || !$this->options['wc_reg']) { return; } require_once 'partials/add-otp-on-wc-reg-form.php'; ?> validateNumber(sanitize_text_field($_POST['billing_phone'])); } if (isset($_POST['password']) && empty($_POST['password']) && strlen($_POST['password']) < 8) { $response = ['status' => 400, 'message' => __('Weak - Please enter a stronger password.')]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } if (!$user_phone) { $response = ['status' => 400, 'message' => __('The phone number you entered is not valid!')]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } $is_checkout_request = !empty($_POST['action_type']) && $_POST['action_type'] === 'wc_checkout'; if ($is_checkout_request && !is_user_logged_in() && $this->is_checkout_rate_limited()) { $response = [ 'status' => 429, 'message' => __('You have reached the maximum number of OTP requests. Please try again in 15 minutes.'), ]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } // check for already send otp by checking expiration $otp_expires = $this->get_otp_store_value('alpha_sms_expires'); if (!empty($otp_expires) && strtotime($otp_expires) > strtotime(ALPHA_SMS_TIMESTAMP)) { $response = [ 'status' => 400, 'message' => 'OTP already sent to a phone number. Please try again after ' . date('i:s', strtotime($otp_expires) - strtotime(ALPHA_SMS_TIMESTAMP) . ' min'), ]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } //we will send sms $otp_code = $this->generateOTP(); $body = 'Your OTP for ' . get_bloginfo() . ' registration is ' . $otp_code . '. Valid for 2 min. Contact us if you need help.'; if ($is_checkout_request) { $body = 'Your OTP for secure order checkout on ' . get_bloginfo() . ' is ' . $otp_code . '. Use it within 2 min to complete the checkout process.'; } $sms_response = $this->SendSMS($user_phone, $body); if ($sms_response->error === 0) { // save info in database for later verification if ($this->log_login_register_action( $user_phone, $otp_code )) { if ($is_checkout_request && !is_user_logged_in()) { $this->record_checkout_otp_request(); } $response = [ 'status' => 200, 'message' => 'A OTP (One Time Passcode) has been sent. Please enter the OTP in the field below to verify your phone.', ]; } else { $response = ['status' => 400, 'message' => __('Error occurred while sending OTP. Please try again.')]; } echo wp_kses_post(json_encode($response)); wp_die(); exit; } $response = ['status' => '400', 'message' => __('Error occurred while sending OTP. Contact Administrator.')]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } /** * Validate Bangladeshi phone number format * * @param $num * * @return false|int|string */ public function validateNumber($num) { if (!$num) { return false; } $num = ltrim(trim($num), "+88"); $number = '88' . ltrim($num, "88"); $ext = ["88017", "88013", "88016", "88015", "88018", "88019", "88014"]; if (is_numeric($number) && strlen($number) === 13 && in_array(substr($number, 0, 5), $ext, true)) { return $number; } return false; } /** * Generate 6 digit otp code * * @return string */ public function generateOTP() { $otp = ''; for ($i = 0; $i < 6; $i++) { $otp .= mt_rand(0, 9); } return $otp; } /** * Send SMS via sms api * * @param $to * @param $body * * @return false|mixed */ public function SendSMS($to, $body) { if (!$this->pluginActive) { return false; } $api_key = !empty($this->options['api_key']) ? $this->options['api_key'] : ''; $sender_id = !empty($this->options['sender_id']) ? trim($this->options['sender_id']) : ''; require_once ALPHA_SMS_PATH . 'includes/sms.class.php'; $sms = new AlphaSMS($api_key); $sms->numbers = $to; $sms->body = $body; $sms->sender_id = $sender_id; return $sms->Send(); } /** * After sending OTP to the user, store the OTP metadata for verification. * * @param $mobile_phone * @param $otp_code * * @return bool */ public function log_login_register_action( $mobile_phone, $otp_code ) { $dateTime = new DateTime(ALPHA_SMS_TIMESTAMP); $dateTime->modify('+3 minutes'); $expires_at = $dateTime->format('Y-m-d H:i:s'); $stored = $this->set_transient_otp_data( [ 'alpha_sms_otp_phone' => $mobile_phone, 'alpha_sms_otp_code' => $otp_code, 'alpha_sms_expires' => $expires_at, ], $expires_at ); if (!$stored) { return false; } $snapshot = $this->get_transient_otp_data(); return !empty($snapshot['alpha_sms_otp_code']); } /** * Determine whether the visitor has reached the OTP request limit for guest checkout. * * @return bool */ private function is_checkout_rate_limited() { $now = $this->get_current_timestamp(); $requests = $this->filter_checkout_otp_requests($now); $this->persist_checkout_otp_requests($requests, $now); return count($requests) >= $this->get_checkout_rate_limit(); } /** * Record a successful OTP request for guest checkout. */ private function record_checkout_otp_request() { $now = $this->get_current_timestamp(); $requests = $this->filter_checkout_otp_requests($now); $requests[] = $now; $limit = $this->get_checkout_rate_limit(); if (count($requests) > $limit) { $requests = array_slice($requests, -$limit); } $this->persist_checkout_otp_requests($requests, $now); } /** * Retrieve the maximum number of OTP requests allowed in the rate limit window. * * @return int */ private function get_checkout_rate_limit() { return (int) $this->checkoutOtpRateLimit; } /** * Retrieve the guest checkout OTP rate limit window in seconds. * * @return int */ private function get_checkout_rate_window() { return (int) $this->checkoutOtpRateWindow; } /** * Fetch stored OTP request timestamps for guest checkout. * * @return array */ private function get_checkout_otp_requests() { $data = $this->get_transient_otp_data(); if (empty($data['alpha_sms_checkout_otp_requests']) || !is_array($data['alpha_sms_checkout_otp_requests'])) { return []; } return array_map('intval', $data['alpha_sms_checkout_otp_requests']); } /** * Remove OTP request timestamps that fall outside the rate limit window. * * @param int $now * * @return array */ private function filter_checkout_otp_requests($now) { $window = $this->get_checkout_rate_window(); $earliest = $now - $window; $requests = $this->get_checkout_otp_requests(); $filtered = []; foreach ($requests as $request) { if ($request >= $earliest) { $filtered[] = $request; } } return array_values($filtered); } /** * Persist filtered OTP request timestamps back to the transient store. * * @param array $requests * @param int $now */ private function persist_checkout_otp_requests(array $requests, $now) { $expiryTimestamp = $now + $this->get_checkout_rate_window(); $expires_at = date('Y-m-d H:i:s', $expiryTimestamp); $data = [ 'alpha_sms_checkout_otp_requests' => $requests, ]; $this->set_transient_otp_data($data, $expires_at); } /** * Resolve the current timestamp for rate limiting operations. * * @return int */ private function get_current_timestamp() { $timestamp = defined('ALPHA_SMS_TIMESTAMP') ? strtotime(ALPHA_SMS_TIMESTAMP) : time(); if (!$timestamp) { $timestamp = time(); } return $timestamp; } /** * Verify otp and register the user * * @param $customer_id */ public function register_the_customer($customer_id) { if (!$this->pluginActive || (!$this->options['wp_reg'] && !$this->options['wc_reg'])) { return; } if (isset($_POST['billing_phone']) && $this->validateNumber(sanitize_text_field($_POST['billing_phone']))) { update_user_meta( $customer_id, 'billing_phone', sanitize_text_field($this->validateNumber($_POST['billing_phone'])) ); } } /** * Default WordPress * show phone number on register page */ public function wp_phone_on_register() { if (!$this->pluginActive || !$this->options['wp_reg']) { return; } $billing_phone = (!empty($_POST['billing_phone'])) ? sanitize_text_field($_POST['billing_phone']) : ''; ?>

pluginActive && $this->options['wp_reg'] && !empty($_POST['action_type']) && $_POST['action_type'] === 'wp_reg' ) { $this->register_form_validation($errors, $sanitized_user_login, $user_email); } return $errors; } /** * Register Form Validation * * @param $errors * @param $sanitized_user_login * @param $user_email * * @return mixed */ public function register_form_validation($errors, $sanitized_user_login, $user_email) { $enable_guest_checkout = get_option('woocommerce_enable_guest_checkout'); $enable_guest_checkout = $enable_guest_checkout === 'yes' ? true : false; $action_type = isset($_REQUEST['action_type']) ? sanitize_text_field($_REQUEST['action_type']) : ''; $shouldValidate = $this->pluginActive && ( (!empty($this->options['otp_checkout']) && !$enable_guest_checkout) || (!empty($this->options['wc_reg']) && $action_type === 'wc_reg') || (!empty($this->options['wp_reg']) && $action_type === 'wp_reg') ); if (!$shouldValidate) { return $errors; } if ( empty($_REQUEST['billing_phone']) || !is_numeric($_REQUEST['billing_phone']) || !$this->validateNumber(sanitize_text_field($_REQUEST['billing_phone'])) ) { $errors->add('phone_error', __('You phone number is not valid.', $this->plugin_name)); } $billing_phone = $this->validateNumber(sanitize_text_field($_REQUEST['billing_phone'])); $hasPhoneNumber = get_users('meta_value=' . $billing_phone); if (!empty($hasPhoneNumber)) { $errors->add('duplicate_phone_error', __('Mobile number is already used!', $this->plugin_name)); } if (!empty($_REQUEST['otp_code'])) { $otp_code = sanitize_text_field($_REQUEST['otp_code']); $valid_user = $this->authenticate_otp(trim($otp_code)); if ($valid_user) { $this->deletePastData(); return $errors; } } // otp validation failed or no otp provided $errors->add('otp_error', __('Invalid OTP entered!', $this->plugin_name)); return $errors; } /** * Validate guest checkout otp * * @param $errors * @param $sanitized_user_login * @param $user_email * * @return mixed */ public function validate_guest_checkout_otp() { $enable_guest_checkout = get_option('woocommerce_enable_guest_checkout'); $enable_guest_checkout = $enable_guest_checkout === 'yes' ? true : false; if (!$this->pluginActive || !$this->options['otp_checkout'] || !$enable_guest_checkout) { return; } if (!empty($_REQUEST['otp_code'])) { $otp_code = sanitize_text_field($_REQUEST['otp_code']); $valid_user = $this->authenticate_otp(trim($otp_code)); if ($valid_user) { $this->deletePastData(); } else { wc_add_notice(__('Please enter a valid OTP.', 'woocommerce'), 'error'); } } else { wc_add_notice(__('Please enter a valid OTP.', 'woocommerce'), 'error'); } } /** * Select otp from db and compare * * @param $otp_code * * @return bool */ public function authenticate_otp($otp_code) { $otp_code_session = $this->get_otp_store_value('alpha_sms_otp_code'); $otp_expires_session = $this->get_otp_store_value('alpha_sms_expires'); if (!empty($otp_code_session) && !empty($otp_expires_session)) { if (strtotime($otp_expires_session) > strtotime(ALPHA_SMS_TIMESTAMP)) { if ($otp_code === $otp_code_session) { return true; } } } return false; } /** * Clear stored OTP data for the current visitor. */ public function deletePastData() { $this->clear_transient_otp_data(); } /** * Retrieve a stored OTP value from the WordPress transient store. * * @param string $key * * @return mixed|string */ private function get_otp_store_value($key) { $data = $this->get_transient_otp_data(); return isset($data[$key]) ? $data[$key] : ''; } /** * Resolve the transient key used to persist OTP state for the visitor. * * @return string */ private function get_otp_transient_key() { if (!empty($this->otpTransientKey)) { return $this->otpTransientKey; } $session_id = ''; if (isset($_COOKIE['alpha_sms_session'])) { $session_id = sanitize_text_field(wp_unslash($_COOKIE['alpha_sms_session'])); } if (empty($session_id)) { $session_id = sanitize_key(wp_generate_password(32, false, false)); if (!headers_sent()) { $path = defined('COOKIEPATH') ? COOKIEPATH : '/'; $domain = defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : ''; $secure = function_exists('is_ssl') ? is_ssl() : false; $ttl = defined('DAY_IN_SECONDS') ? DAY_IN_SECONDS : 86400; setcookie('alpha_sms_session', $session_id, time() + $ttl, $path, $domain, $secure, true); } $_COOKIE['alpha_sms_session'] = $session_id; } $this->otpTransientKey = 'alpha_sms_otp_' . $session_id; return $this->otpTransientKey; } /** * Fetch the stored OTP payload from WordPress transients. * * @return array */ private function get_transient_otp_data() { $transient_key = $this->get_otp_transient_key(); if (empty($transient_key)) { return []; } $data = get_transient($transient_key); return is_array($data) ? $data : []; } /** * Persist OTP data to WordPress transients. * * @param array $data * @param string $expires_at * * @return bool */ private function set_transient_otp_data(array $data, $expires_at) { $transient_key = $this->get_otp_transient_key(); if (empty($transient_key)) { return false; } $payload = array_merge($this->get_transient_otp_data(), $data); $expiration = $this->calculate_transient_expiration($expires_at); return set_transient($transient_key, $payload, $expiration); } /** * Clear any stored OTP data from WordPress transients. */ private function clear_transient_otp_data() { $transient_key = $this->get_otp_transient_key(); if (empty($transient_key)) { return; } delete_transient($transient_key); } /** * Determine how long OTP data should live in transients. * * @param string $expires_at * * @return int */ private function calculate_transient_expiration($expires_at) { $minimum = defined('MINUTE_IN_SECONDS') ? MINUTE_IN_SECONDS : 60; $fallback = 3 * $minimum; if (empty($expires_at)) { return $fallback; } $expires_timestamp = strtotime($expires_at); if (!$expires_timestamp) { return $fallback; } $now = defined('ALPHA_SMS_TIMESTAMP') ? strtotime(ALPHA_SMS_TIMESTAMP) : time(); if (!$now) { $now = time(); } $ttl = $expires_timestamp - $now; if ($ttl <= 0) { return $minimum; } return $ttl; } /** * Woocommerce validate phone and validate otp * * @param $errors * @param $sanitized_user_login * @param $user_email * * @return mixed */ public function wc_register_form_validation($errors, $sanitized_user_login, $user_email) { if (!$this->pluginActive) { return $errors; } if ($this->options['otp_checkout'] || ($this->options['wc_reg'] && $_POST['action_type'] === 'wc_reg')) { $this->register_form_validation($errors, $sanitized_user_login, $user_email); } return $errors; } /** * Alert customer and admins when a new order is placed * * @param $order_id */ public function wc_new_order_alert($order_id) { if (!$order_id) { return; } // new order status pending notification for customer $this->wc_order_status_change_alert($order_id, 'pending', 'pending'); // option not enabled if (!$this->pluginActive || !isset($this->options['order_status_admin']) || !$this->options['order_status_admin']) { return; } // send sms to all admins if enabled $order = new WC_Order($order_id); $admin_msg = $this->options['ADMIN_STATUS_SMS']; $search = [ '[store_name]', '[billing_first_name]', '[order_id]', '[order_status]', '[order_currency]', '[order_amount]', '[order_date_created]', '[order_date_completed]' ]; $order_created = date('d M Y', strtotime($order->get_date_created())); $order_completed = !empty($order->get_date_completed()) ? date('d M Y', strtotime($order->get_date_completed())) : ''; $replace = [ get_bloginfo(), $order->get_billing_first_name(), $order_id, 'pending', $order->get_currency(), $order->get_total(), $order_created, $order_completed ]; $admin_msg = str_replace($search, $replace, $admin_msg); // if admin phone is not provided then send to all admins $admin_phones[] = $this->options['admin_phones']; if (empty($admin_phones)) { $admin_phones = $this->admin_phones(); } if (!empty($admin_phones)) { $numbers = implode(',', $admin_phones); $this->SendSMS($numbers, $admin_msg); } } /** * Alert customer and user when order status changes * * @param $order_id * @param $old_status * @param $new_status */ public function wc_order_status_change_alert($order_id, $old_status, $new_status) { if (!$order_id) { return; } $order = new WC_Order($order_id); // Get the Customer billing phone $billing_phone = $order->get_billing_phone(); //we will send sms $status = str_replace('-', '_', $order->data['status']); // option not enabled if ( !$this->pluginActive || !isset($this->options['order_status_' . $status]) || !$this->options['order_status_' . $status] ) { return; } $buyer_msg = !empty($this->options['ORDER_STATUS_' . strtoupper($status) . '_SMS']) ? $this->options['ORDER_STATUS_' . strtoupper($status) . '_SMS'] : NULL; $search = [ '[store_name]', '[billing_first_name]', '[order_id]', '[order_status]', '[order_currency]', '[order_amount]', '[order_date_created]', '[order_date_completed]' ]; $order_created = date('d M Y', strtotime($order->get_date_created())); $order_completed = !empty($order->get_date_completed()) ? date('d M Y', strtotime($order->get_date_completed())) : ''; $replace = [ get_bloginfo(), $order->get_billing_first_name(), $order_id, $new_status, $order->get_currency(), $order->get_total(), $order_created, $order_completed ]; $buyer_msg = str_replace($search, $replace, $buyer_msg); if (empty($buyer_msg)) { $order->add_order_note(__($this->plugin_name . ': Order message not found.', $this->plugin_name)); return; } $response = $this->SendSMS($billing_phone, $buyer_msg); if ($response->error === 0) { $order->add_order_note(__('Alpha SMS : Notified customer about his order ' . $order->data['status'] . ' status', $this->plugin_name)); } else { $order->add_order_note(__('Alpha SMS : ' . $response->msg, $this->plugin_name)); } } /** * Get all the phone number associated with administration role * * @return array */ public function admin_phones() { $admin_ids = get_users(['fields' => 'ID', 'role' => 'administrator']); $numbers = []; foreach ($admin_ids as $userid) { $number = $this->validateNumber(get_user_meta($userid, 'mobile_phone', true)); if ($number) { $numbers[] = $number; } } return $numbers; } /** * WordPress login with Phone Number methods * */ public function login_enqueue_style() { if ($this->options['wp_login'] || $this->options['wp_reg']) { wp_enqueue_style( $this->plugin_name, plugin_dir_url(__FILE__) . 'css/otp-login-form.css', [], $this->version, 'all' ); } } public function login_enqueue_script() { if (!$this->pluginActive) { return; } if ($this->options['wp_login'] || $this->options['wp_reg']) { wp_enqueue_script( $this->plugin_name, plugin_dir_url(__FILE__) . 'js/otp-login-form.js', ['jquery'], $this->version, false ); wp_localize_script( $this->plugin_name, $this->plugin_name . '_object', ['ajaxurl' => admin_url('admin-ajax.php')] ); } } /** * Add OTP view in Wp login form * */ public function add_otp_field_in_wp_login_form() { if (!$this->pluginActive || !$this->options['wp_login']) { return; } require_once 'partials/add-otp-on-login-form.php'; ?> pluginActive || !$this->options['wc_login']) { return; } require_once 'partials/add-otp-on-login-form.php'; ?> plugin_name); //Nonce is checked, get the POST data and sign user on $info = []; $info['user_login'] = sanitize_text_field($_POST['log']); $info['user_password'] = sanitize_text_field($_POST['pwd']); $info['remember'] = sanitize_text_field($_POST['rememberme']); $userdata = get_user_by('login', $info['user_login']); if (!$userdata) { $userdata = get_user_by('email', $info['user_login']); } // wp_authenticate() $user_id = $userdata->data->ID; $result = wp_check_password($info['user_password'], $userdata->data->user_pass, $user_id); if (!$user_id || !$result) { $response = ['status' => 401, 'message' => __('Wrong username or password!')]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } $user_phone = get_user_meta($user_id, 'mobile_phone', true); if (!$user_phone) { $user_phone = get_user_meta($user_id, 'billing_phone', true); } // if user phone number is not valid then login without verification if (!$user_phone || !$this->validateNumber($user_phone)) { $response = ['status' => 402, 'message' => __('No phone number found')]; echo wp_kses_post(json_encode($response)); wp_die(); exit; } //we will send sms $otp_code = $this->generateOTP(); $number = $user_phone; $body = 'Your one time password for ' . get_bloginfo() . ' login is ' . $otp_code . ' . Only valid for 2 min.'; $sms_response = $this->SendSMS($number, $body); if ($sms_response->error === 0) { // save info in database for later verification $log_info = $this->log_login_register_action($user_phone, $otp_code); if ($log_info) { $response = ['status' => 200, 'message' => 'Please enter the verification code sent to your phone.']; } else { $response = ['status' => 500, 'message' => 'Something went wrong. Please try again.']; } echo wp_kses_post(json_encode($response)); exit; } $response = ['status' => '400', 'message' => 'Error sending Otp Code. Please contact administrator.']; echo wp_kses_post(json_encode($response)); wp_die(); exit; } /** * Login the user verifying otp code * * @param $user * @param $username * * @return User|WP_Error */ public function login_user($user, $username) { if (empty($user->data)) { return $user; } if (!$this->pluginActive || (!$this->options['wp_login'] && !$this->options['wc_login'])) { return $user; } if (empty($_POST['action_type'])) { $error = new WP_Error(); $error->add( 'empty_password', __('Error: Authentication Error!', $this->plugin_name) ); } if (($this->options['wp_login'] && $_POST['action_type'] == 'wp_login') || ($this->options['wc_login'] && $_POST['action_type'] == 'wc_login') ) { return $this->startOTPChallenge($user, $username); } return $user; } /** * @param $user * @param $username * * @return mixed|WP_Error */ public function startOTPChallenge($user, $username) { $user_phone = get_user_meta($user->data->ID, 'mobile_phone', true); if (!$user_phone) { $user_phone = get_user_meta($user->data->ID, 'billing_phone', true); } if (!$user_phone || !$this->validateNumber($user_phone)) { return $user; } if (empty($_REQUEST['otp_code'])) { $error = new WP_Error(); $error->add( 'empty_password', __('Error: Wrong OTP Code!', $this->plugin_name) ); return $error; } $otp_code = sanitize_text_field($_REQUEST['otp_code']); $valid_user = $this->authenticate_otp($otp_code); if ($valid_user) { $this->deletePastData(); return $user; } return new WP_Error( 'invalid_password', __('OTP is not valid', $this->plugin_name) ); } /** * Woocommerce otp form in checkout */ public function otp_form_at_checkout() { if (!$this->pluginActive || !$this->options['otp_checkout']) { return; } if (!is_user_logged_in()) { require_once 'partials/add-otp-checkout-form.php'; ?> getBalance(); return $response && $response->error === 0; } }