tab-log.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Log tab.
  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. defined( 'ABSPATH' ) || exit;
  11. // phpcs:ignore WordPress.Security.NonceVerification.Recommended
  12. $wcmq_level = isset( $_GET['level'] ) ? sanitize_key( wp_unslash( $_GET['level'] ) ) : '';
  13. if ( ! in_array( $wcmq_level, array( 'debug', 'info', 'warning', 'error' ), true ) ) {
  14. $wcmq_level = '';
  15. }
  16. $wcmq_paged = Studiou_WCMQ_Admin::current_page();
  17. $wcmq_total = Studiou_WCMQ_DB::count_log_rows( $wcmq_level );
  18. $wcmq_offset = ( $wcmq_paged - 1 ) * Studiou_WCMQ_Admin::PER_PAGE;
  19. $wcmq_rows = Studiou_WCMQ_DB::get_log_rows( $wcmq_level, Studiou_WCMQ_Admin::PER_PAGE, $wcmq_offset );
  20. $wcmq_levels = array(
  21. '' => __( 'All', 'studiou-wc-mail-queue' ),
  22. 'error' => __( 'Errors', 'studiou-wc-mail-queue' ),
  23. 'warning' => __( 'Warnings', 'studiou-wc-mail-queue' ),
  24. 'info' => __( 'Info', 'studiou-wc-mail-queue' ),
  25. 'debug' => __( 'Debug', 'studiou-wc-mail-queue' ),
  26. );
  27. ?>
  28. <ul class="subsubsub">
  29. <?php foreach ( $wcmq_levels as $wcmq_slug => $wcmq_label ) : ?>
  30. <li>
  31. <a href="<?php echo esc_url( Studiou_WCMQ_Admin::tab_url( 'log', $wcmq_slug ? array( 'level' => $wcmq_slug ) : array() ) ); ?>"
  32. class="<?php echo $wcmq_level === $wcmq_slug ? 'current' : ''; ?>">
  33. <?php echo esc_html( $wcmq_label ); ?>
  34. </a>
  35. </li>
  36. <?php endforeach; ?>
  37. </ul>
  38. <div class="clear"></div>
  39. <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="studiou-wcmq-clear-log-form">
  40. <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
  41. <input type="hidden" name="action" value="studiou_wcmq_clear_log" />
  42. <p>
  43. <button type="submit" class="button button-secondary" id="studiou-wcmq-clear-log">
  44. <?php esc_html_e( 'Clear log', 'studiou-wc-mail-queue' ); ?>
  45. </button>
  46. </p>
  47. </form>
  48. <table class="wp-list-table widefat fixed striped">
  49. <thead>
  50. <tr>
  51. <th style="width:60px"><?php esc_html_e( 'ID', 'studiou-wc-mail-queue' ); ?></th>
  52. <th style="width:90px"><?php esc_html_e( 'Level', 'studiou-wc-mail-queue' ); ?></th>
  53. <th style="width:170px"><?php esc_html_e( 'Time', 'studiou-wc-mail-queue' ); ?></th>
  54. <th style="width:80px"><?php esc_html_e( 'Row', 'studiou-wc-mail-queue' ); ?></th>
  55. <th><?php esc_html_e( 'Message', 'studiou-wc-mail-queue' ); ?></th>
  56. </tr>
  57. </thead>
  58. <tbody>
  59. <?php if ( empty( $wcmq_rows ) ) : ?>
  60. <tr><td colspan="5"><?php esc_html_e( 'The log is empty.', 'studiou-wc-mail-queue' ); ?></td></tr>
  61. <?php else : ?>
  62. <?php foreach ( $wcmq_rows as $wcmq_row ) : ?>
  63. <tr>
  64. <td><?php echo (int) $wcmq_row->id; ?></td>
  65. <td>
  66. <span class="studiou-wcmq-level studiou-wcmq-level-<?php echo esc_attr( $wcmq_row->level ); ?>">
  67. <?php echo esc_html( $wcmq_row->level ); ?>
  68. </span>
  69. </td>
  70. <td><?php echo wp_kses_post( Studiou_WCMQ_Admin::format_time( $wcmq_row->created_at ) ); ?></td>
  71. <td><?php echo $wcmq_row->queue_id ? (int) $wcmq_row->queue_id : '&mdash;'; ?></td>
  72. <td><?php echo esc_html( $wcmq_row->message ); ?></td>
  73. </tr>
  74. <?php endforeach; ?>
  75. <?php endif; ?>
  76. </tbody>
  77. </table>
  78. <?php
  79. Studiou_WCMQ_Admin::render_pagination(
  80. 'log',
  81. $wcmq_total,
  82. $wcmq_paged,
  83. $wcmq_level ? array( 'level' => $wcmq_level ) : array()
  84. );