admin-page.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Admin page shell: header, state banner, tab bar.
  4. *
  5. * @package studiou-wc-mail-queue
  6. * @copyright 2026 QUADARAX
  7. * @author Dalibor Votruba <dvotruba@quadarax.com>
  8. * @license GPL-2.0-or-later
  9. *
  10. * @var string $tab Active tab slug.
  11. */
  12. defined( 'ABSPATH' ) || exit;
  13. $wcmq_state = Studiou_WCMQ_State::get();
  14. $wcmq_counts = Studiou_WCMQ_DB::counts_by_state();
  15. $wcmq_tabs = array(
  16. 'settings' => __( 'Settings', 'studiou-wc-mail-queue' ),
  17. 'queue' => __( 'Queue', 'studiou-wc-mail-queue' ),
  18. 'log' => __( 'Log', 'studiou-wc-mail-queue' ),
  19. );
  20. ?>
  21. <div class="wrap studiou-wcmq">
  22. <h1><?php esc_html_e( 'WooCommerce Mail Queue', 'studiou-wc-mail-queue' ); ?></h1>
  23. <p class="studiou-wcmq-status">
  24. <?php
  25. if ( Studiou_WCMQ_Settings::STATE_ENABLED === $wcmq_state ) {
  26. printf(
  27. '<span class="studiou-wcmq-badge studiou-wcmq-badge-on">%s</span> ',
  28. esc_html__( 'Enabled', 'studiou-wc-mail-queue' )
  29. );
  30. printf(
  31. /* translators: 1: mails per minute, 2: seconds between mails */
  32. esc_html__( 'Sending at most %1$d mail(s) per minute (one every %2$d seconds).', 'studiou-wc-mail-queue' ),
  33. (int) Studiou_WCMQ_Settings::rate(),
  34. (int) Studiou_WCMQ_Settings::interval()
  35. );
  36. } elseif ( Studiou_WCMQ_Settings::STATE_DRAINING === $wcmq_state ) {
  37. printf(
  38. '<span class="studiou-wcmq-badge studiou-wcmq-badge-draining">%s</span> ',
  39. esc_html__( 'Draining', 'studiou-wc-mail-queue' )
  40. );
  41. printf(
  42. /* translators: %d: rows remaining */
  43. esc_html__( 'New mail sends immediately. %d queued mail(s) still to send.', 'studiou-wc-mail-queue' ),
  44. (int) ( $wcmq_counts['pending'] + $wcmq_counts['sending'] )
  45. );
  46. } else {
  47. printf(
  48. '<span class="studiou-wcmq-badge studiou-wcmq-badge-off">%s</span> ',
  49. esc_html__( 'Disabled', 'studiou-wc-mail-queue' )
  50. );
  51. esc_html_e( 'All mail sends immediately, exactly as stock WooCommerce.', 'studiou-wc-mail-queue' );
  52. }
  53. ?>
  54. </p>
  55. <ul class="studiou-wcmq-counts">
  56. <li><strong><?php echo (int) $wcmq_counts['pending']; ?></strong> <?php esc_html_e( 'pending', 'studiou-wc-mail-queue' ); ?></li>
  57. <li><strong><?php echo (int) $wcmq_counts['sending']; ?></strong> <?php esc_html_e( 'sending', 'studiou-wc-mail-queue' ); ?></li>
  58. <li><strong><?php echo (int) $wcmq_counts['sent']; ?></strong> <?php esc_html_e( 'sent', 'studiou-wc-mail-queue' ); ?></li>
  59. <li class="<?php echo $wcmq_counts['failed'] ? 'studiou-wcmq-has-failed' : ''; ?>">
  60. <strong><?php echo (int) $wcmq_counts['failed']; ?></strong> <?php esc_html_e( 'failed', 'studiou-wc-mail-queue' ); ?>
  61. </li>
  62. </ul>
  63. <h2 class="nav-tab-wrapper">
  64. <?php foreach ( $wcmq_tabs as $wcmq_slug => $wcmq_label ) : ?>
  65. <a href="<?php echo esc_url( Studiou_WCMQ_Admin::tab_url( $wcmq_slug ) ); ?>"
  66. class="nav-tab <?php echo $tab === $wcmq_slug ? 'nav-tab-active' : ''; ?>">
  67. <?php echo esc_html( $wcmq_label ); ?>
  68. </a>
  69. <?php endforeach; ?>
  70. </h2>
  71. <?php
  72. $wcmq_partial = STUDIOU_WCMQ_DIR . 'views/tab-' . $tab . '.php';
  73. if ( file_exists( $wcmq_partial ) ) {
  74. include $wcmq_partial;
  75. }
  76. ?>
  77. </div>