Changeset 3362984
- Timestamp:
- 09/17/2025 08:21:58 AM (7 months ago)
- Location:
- alpha-sms
- Files:
-
- 49 added
- 4 edited
-
tags/1.0.12 (added)
-
tags/1.0.12/LICENSE.txt (added)
-
tags/1.0.12/README.txt (added)
-
tags/1.0.12/admin (added)
-
tags/1.0.12/admin/class-alpha_sms-admin.php (added)
-
tags/1.0.12/admin/css (added)
-
tags/1.0.12/admin/css/alpha_sms-admin.css (added)
-
tags/1.0.12/admin/index.php (added)
-
tags/1.0.12/admin/js (added)
-
tags/1.0.12/admin/js/alpha_sms-admin.js (added)
-
tags/1.0.12/admin/partials (added)
-
tags/1.0.12/admin/partials/alpha_sms-admin-display_campaign.php (added)
-
tags/1.0.12/admin/partials/alpha_sms-admin-display_settings.php (added)
-
tags/1.0.12/alpha_sms.php (added)
-
tags/1.0.12/assets (added)
-
tags/1.0.12/assets/banner-1544x500.png (added)
-
tags/1.0.12/assets/banner-772x250.png (added)
-
tags/1.0.12/assets/icon-128x128.png (added)
-
tags/1.0.12/assets/icon-256x256.png (added)
-
tags/1.0.12/assets/screenshot-1.jpg (added)
-
tags/1.0.12/assets/screenshot-2.jpg (added)
-
tags/1.0.12/assets/smsBanner.ai (added)
-
tags/1.0.12/includes (added)
-
tags/1.0.12/includes/class-alpha_sms-activator.php (added)
-
tags/1.0.12/includes/class-alpha_sms-background.php (added)
-
tags/1.0.12/includes/class-alpha_sms-deactivator.php (added)
-
tags/1.0.12/includes/class-alpha_sms-i18n.php (added)
-
tags/1.0.12/includes/class-alpha_sms-loader.php (added)
-
tags/1.0.12/includes/class-alpha_sms.php (added)
-
tags/1.0.12/includes/index.php (added)
-
tags/1.0.12/includes/sms.class.php (added)
-
tags/1.0.12/index.php (added)
-
tags/1.0.12/languages (added)
-
tags/1.0.12/languages/alpha_sms.pot (added)
-
tags/1.0.12/public (added)
-
tags/1.0.12/public/class-alpha_sms-public.php (added)
-
tags/1.0.12/public/css (added)
-
tags/1.0.12/public/css/alpha_sms-public.css (added)
-
tags/1.0.12/public/css/otp-login-form.css (added)
-
tags/1.0.12/public/index.php (added)
-
tags/1.0.12/public/js (added)
-
tags/1.0.12/public/js/alpha_sms-public.js (added)
-
tags/1.0.12/public/js/otp-login-form.js (added)
-
tags/1.0.12/public/partials (added)
-
tags/1.0.12/public/partials/add-otp-checkout-form.php (added)
-
tags/1.0.12/public/partials/add-otp-on-login-form.php (added)
-
tags/1.0.12/public/partials/add-otp-on-wc-reg-form.php (added)
-
tags/1.0.12/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/class-alpha_sms-admin.php (modified) (6 diffs)
-
trunk/alpha_sms.php (modified) (2 diffs)
-
trunk/includes/class-alpha_sms-background.php (added)
-
trunk/includes/class-alpha_sms.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
alpha-sms/trunk/README.txt
r3362903 r3362984 3 3 Tags: order notification, order SMS, woocommerce sms integration, sms plugin, mobile verification, OTP, SMS notifications, two-step verification, OTP verification, SMS, signup security, user verification, user security, SMS gateway, order SMS, order notifications, WordPress OTP, 2FA, login OTP, WP SMS 4 4 Requires at least: 3.5 5 Tested up to: 6. 6.25 Tested up to: 6.8.2 6 6 Requires PHP: 5.6 7 Stable tag: 1.0.1 17 Stable tag: 1.0.12 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 60 60 == Changelog == 61 61 62 = 1.0.12 = 63 * Added a background processor so campaign SMS messages are queued individually and sent by scheduled jobs. 64 * Aggregated campaign job results into concise admin notices that highlight failed numbers and the most recent error. 65 62 66 = 1.0.11 = 63 67 * Updated the WooCommerce checkout OTP workflow to clone whichever submit button is present instead of relying on the `#place_order` ID so guest checkout themes remain compatible. -
alpha-sms/trunk/admin/class-alpha_sms-admin.php
r2867587 r3362984 46 46 47 47 /** 48 * Background processor for queued SMS jobs. 49 * 50 * @var Alpha_SMS_Background|null 51 */ 52 private $background; 53 54 /** 48 55 * Initialize the class and set its properties. 49 56 * 50 * @param string $plugin_name The name of this plugin. 51 * @param string $version The version of this plugin. 52 * @since 1.0.0 53 */ 54 public function __construct($plugin_name, $version) 57 * @param string $plugin_name The name of this plugin. 58 * @param string $version The version of this plugin. 59 * @param Alpha_SMS_Background|null $background Optional background processor instance. 60 * @since 1.0.0 61 */ 62 public function __construct($plugin_name, $version, $background = null) 55 63 { 56 64 57 65 $this->plugin_name = $plugin_name; 58 66 $this->version = $version; 67 $this->background = $background; 68 } 69 70 /** 71 * Set the background processor instance. 72 * 73 * @param Alpha_SMS_Background|null $background Background processor. 74 * 75 * @return void 76 */ 77 public function set_background_processor($background) 78 { 79 $this->background = $background; 80 } 81 82 /** 83 * Retrieve the background processor instance. 84 * 85 * @return Alpha_SMS_Background|null 86 */ 87 private function get_background_processor() 88 { 89 if ($this->background instanceof Alpha_SMS_Background) { 90 return $this->background; 91 } 92 93 return null; 59 94 } 60 95 … … 301 336 302 337 // Redirect to plugin page 303 wp_ redirect($_SERVER['HTTP_REFERER']);338 wp_safe_redirect(wp_get_referer()); 304 339 exit(); 305 340 } … … 308 343 309 344 // Redirect to plugin page 310 wp_ redirect($_SERVER['HTTP_REFERER']);345 wp_safe_redirect(wp_get_referer()); 311 346 exit(); 312 347 } … … 322 357 } 323 358 324 // Final Numbers 325 $numbers = implode(',', $numbersArr); 326 327 require_once ALPHA_SMS_PATH . 'includes/sms.class.php'; 328 329 $sms = new AlphaSMS($api_key); 330 $sms->numbers = $numbers; 331 $sms->body = $body; 332 $sms->sender_id = $sender_id; 333 334 $response = $sms->Send(); 335 336 if (!$response) { 337 $this->add_flash_notice(__("Something went wrong, please try again.", $this->plugin_name), "error"); 338 339 } elseif ($response->error !== 0) { 340 $this->add_flash_notice(__($response->msg), 'error'); 341 342 } else { 343 $this->add_flash_notice(__($response->msg), 'success'); 359 $numbersArr = array_map('trim', $numbersArr); 360 $numbersArr = array_filter($numbersArr); 361 $numbersArr = array_unique($numbersArr); 362 363 if (empty($numbersArr)) { 364 $this->add_flash_notice(__("No valid recipients were provided.", $this->plugin_name), "error"); 365 366 // Redirect to plugin page 367 wp_safe_redirect(wp_get_referer()); 368 exit(); 369 } 370 371 $background = $this->get_background_processor(); 372 373 if (!$background) { 374 $this->add_flash_notice(__("Background processing is unavailable. Please try again later.", $this->plugin_name), 375 "error"); 376 377 // Redirect to plugin page 378 wp_safe_redirect(wp_get_referer()); 379 exit(); 380 } 381 382 $queued = 0; 383 $failedQueue = []; 384 385 foreach ($numbersArr as $number) { 386 if ($background->dispatch($number, $body, $sender_id, $api_key)) { 387 $queued++; 388 } else { 389 $failedQueue[] = $number; 390 } 391 } 392 393 if ($queued > 0) { 394 $notice = sprintf( 395 _n('Queued %d SMS message for background sending.', 'Queued %d SMS messages for background sending.', $queued, 396 $this->plugin_name), 397 $queued 398 ); 399 $this->add_flash_notice(esc_html($notice), 'success'); 400 } 401 402 if (!empty($failedQueue)) { 403 $failedQueue = array_map('sanitize_text_field', $failedQueue); 404 $preview = array_slice($failedQueue, 0, 5); 405 $summary = implode(', ', $preview); 406 if ('' === trim($summary)) { 407 $summary = __('unknown recipients', $this->plugin_name); 408 } 409 $message = sprintf( 410 __('Unable to queue %1$d recipient(s): %2$s', $this->plugin_name), 411 count($failedQueue), 412 $summary 413 ); 414 if (count($failedQueue) > count($preview)) { 415 $message .= ' ' . sprintf(__('and %d more.', $this->plugin_name), count($failedQueue) - count($preview)); 416 } 417 418 $this->add_flash_notice(esc_html($message), 'error'); 344 419 } 345 420 346 421 // Redirect to plugin page 347 wp_ redirect($_SERVER['HTTP_REFERER']);422 wp_safe_redirect(wp_get_referer()); 348 423 exit(); 349 424 } … … 392 467 393 468 /** 469 * Persist job results as flash notices for display in the admin area. 470 * 471 * @return void 472 */ 473 private function maybe_add_job_result_notice() 474 { 475 $results = get_option($this->plugin_name . '_job_results', []); 476 477 if (empty($results) || !is_array($results)) { 478 return; 479 } 480 481 $defaults = [ 482 'success' => 0, 483 'failed' => 0, 484 'last_error' => '', 485 'failures' => [], 486 ]; 487 488 $results = wp_parse_args($results, $defaults); 489 490 if (!empty($results['success'])) { 491 $success_notice = sprintf( 492 _n('%d SMS message was sent successfully.', '%d SMS messages were sent successfully.', (int)$results['success'], 493 $this->plugin_name), 494 (int)$results['success'] 495 ); 496 $this->add_flash_notice(esc_html($success_notice), 'success'); 497 } 498 499 if (!empty($results['failed'])) { 500 $error_notice = sprintf( 501 _n('%d SMS message failed to send.', '%d SMS messages failed to send.', (int)$results['failed'], 502 $this->plugin_name), 503 (int)$results['failed'] 504 ); 505 506 if (!empty($results['last_error'])) { 507 $error_notice .= ' ' . sprintf(__('Last error: %s', $this->plugin_name), $results['last_error']); 508 } elseif (!empty($results['failures']) && is_array($results['failures'])) { 509 $details = []; 510 foreach ($results['failures'] as $failure) { 511 $number = isset($failure['number']) ? $failure['number'] : ''; 512 $message = isset($failure['message']) ? $failure['message'] : ''; 513 514 $detail_parts = []; 515 $trimmed_number = trim($number); 516 if ($trimmed_number !== '') { 517 $detail_parts[] = $trimmed_number; 518 } 519 if ($message !== '') { 520 $detail_parts[] = $message; 521 } 522 523 if (!empty($detail_parts)) { 524 $details[] = implode(' - ', $detail_parts); 525 } 526 } 527 528 if (!empty($details)) { 529 $error_notice .= ' ' . sprintf( 530 _n('Latest error: %s', 'Latest errors: %s', count($details), $this->plugin_name), 531 implode('; ', $details) 532 ); 533 } 534 } 535 536 $this->add_flash_notice(esc_html($error_notice), 'error'); 537 } 538 539 delete_option($this->plugin_name . '_job_results'); 540 } 541 542 /** 394 543 * Function executed when the 'admin_notices' action is called, here we check if there are notices on 395 544 * our database and display them, after that, we remove the option to prevent notices being displayed forever. … … 399 548 public function display_flash_notices() 400 549 { 550 $this->maybe_add_job_result_notice(); 551 401 552 $notices = get_option($this->plugin_name . '_notices', []); 402 553 -
alpha-sms/trunk/alpha_sms.php
r3362903 r3362984 17 17 * Plugin URI: https://sms.net.bd/plugins/wordpress 18 18 * Description: WP 2FA Login. SMS OTP Verification for Registration and Login forms, WooCommerce SMS Notification for your shop orders. 19 * Version: 1.0.1 119 * Version: 1.0.12 20 20 * Author: Alpha Net 21 21 * Author URI: https://sms.net.bd/ … … 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define('ALPHA_SMS_VERSION', '1.0.1 1');38 define('ALPHA_SMS_VERSION', '1.0.12'); 39 39 40 40 // plugin constants -
alpha-sms/trunk/includes/class-alpha_sms.php
r3362903 r3362984 77 77 $this->version = ALPHA_SMS_VERSION; 78 78 } else { 79 $this->version = '1.0. 0';79 $this->version = '1.0.12'; 80 80 } 81 81 $this->plugin_name = 'alpha_sms'; … … 113 113 114 114 /** 115 * Background processing utilities. 116 */ 117 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-alpha_sms-background.php'; 118 119 /** 115 120 * The class responsible for defining internationalization functionality 116 121 * of the plugin. … … 159 164 { 160 165 161 $plugin_admin = new Alpha_sms_Admin($this->get_plugin_name(), $this->get_version()); 166 $background = new Alpha_SMS_Background($this->get_plugin_name()); 167 $plugin_admin = new Alpha_sms_Admin($this->get_plugin_name(), $this->get_version(), $background); 168 169 $this->loader->add_action(Alpha_SMS_Background::ACTION_HOOK, $background, 'alpha_sms_send_single_sms', 10, 1); 162 170 163 171 $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
Note: See TracChangeset
for help on using the changeset viewer.