| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /**
- * Queue tab.
- *
- * @package studiou-wc-mail-queue
- * @copyright 2026 QUADARAX
- * @author Dalibor Votruba <dvotruba@quadarax.com>
- * @license GPL-2.0-or-later
- */
- defined( 'ABSPATH' ) || exit;
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
- $wcmq_filter = isset( $_GET['state'] ) ? sanitize_key( wp_unslash( $_GET['state'] ) ) : '';
- if ( ! in_array( $wcmq_filter, array( 'pending', 'sending', 'sent', 'failed' ), true ) ) {
- $wcmq_filter = '';
- }
- $wcmq_paged = Studiou_WCMQ_Admin::current_page();
- $wcmq_total = Studiou_WCMQ_DB::count_rows( $wcmq_filter );
- $wcmq_offset = ( $wcmq_paged - 1 ) * Studiou_WCMQ_Admin::PER_PAGE;
- $wcmq_rows = Studiou_WCMQ_DB::get_rows( $wcmq_filter, Studiou_WCMQ_Admin::PER_PAGE, $wcmq_offset );
- $wcmq_states = array(
- '' => __( 'All', 'studiou-wc-mail-queue' ),
- 'pending' => __( 'Pending', 'studiou-wc-mail-queue' ),
- 'sending' => __( 'Sending', 'studiou-wc-mail-queue' ),
- 'sent' => __( 'Sent', 'studiou-wc-mail-queue' ),
- 'failed' => __( 'Failed', 'studiou-wc-mail-queue' ),
- );
- ?>
- <ul class="subsubsub">
- <?php foreach ( $wcmq_states as $wcmq_slug => $wcmq_label ) : ?>
- <li>
- <a href="<?php echo esc_url( Studiou_WCMQ_Admin::tab_url( 'queue', $wcmq_slug ? array( 'state' => $wcmq_slug ) : array() ) ); ?>"
- class="<?php echo $wcmq_filter === $wcmq_slug ? 'current' : ''; ?>">
- <?php echo esc_html( $wcmq_label ); ?>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- <div class="clear"></div>
- <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="studiou-wcmq-queue-form">
- <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
- <input type="hidden" name="action" value="studiou_wcmq_queue_action" />
- <div class="tablenav top">
- <div class="alignleft actions">
- <select name="wcmq_action">
- <option value=""><?php esc_html_e( 'Bulk actions', 'studiou-wc-mail-queue' ); ?></option>
- <option value="retry"><?php esc_html_e( 'Retry now', 'studiou-wc-mail-queue' ); ?></option>
- <option value="delete"><?php esc_html_e( 'Delete', 'studiou-wc-mail-queue' ); ?></option>
- </select>
- <button type="submit" class="button" id="studiou-wcmq-apply"><?php esc_html_e( 'Apply', 'studiou-wc-mail-queue' ); ?></button>
- </div>
- </div>
- <table class="wp-list-table widefat fixed striped">
- <thead>
- <tr>
- <td class="check-column"><input type="checkbox" id="studiou-wcmq-check-all" /></td>
- <th><?php esc_html_e( 'ID', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Email type', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Order', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Recipient', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'State', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Tries', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Scheduled', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Sent', 'studiou-wc-mail-queue' ); ?></th>
- <th><?php esc_html_e( 'Last error', 'studiou-wc-mail-queue' ); ?></th>
- </tr>
- </thead>
- <tbody>
- <?php if ( empty( $wcmq_rows ) ) : ?>
- <tr><td colspan="10"><?php esc_html_e( 'The queue is empty.', 'studiou-wc-mail-queue' ); ?></td></tr>
- <?php else : ?>
- <?php foreach ( $wcmq_rows as $wcmq_row ) : ?>
- <tr>
- <th scope="row" class="check-column">
- <input type="checkbox" name="rows[]" value="<?php echo (int) $wcmq_row->id; ?>" />
- </th>
- <td><?php echo (int) $wcmq_row->id; ?></td>
- <td><code><?php echo esc_html( $wcmq_row->context ); ?></code></td>
- <td>
- <?php
- // Never hardcode the HPOS URL: `page=wc-orders` is not a
- // registered admin page when order storage is legacy posts.
- // WC_Order::get_edit_order_url() resolves both, and returns
- // nothing useful for an order deleted since enqueue.
- $wcmq_order_id = (int) $wcmq_row->order_id;
- $wcmq_edit_url = '';
- if ( $wcmq_order_id > 0 && function_exists( 'wc_get_order' ) ) {
- $wcmq_order = wc_get_order( $wcmq_order_id );
- if ( $wcmq_order instanceof WC_Order ) {
- $wcmq_edit_url = $wcmq_order->get_edit_order_url();
- }
- }
- if ( $wcmq_edit_url ) {
- printf( '<a href="%s">#%d</a>', esc_url( $wcmq_edit_url ), $wcmq_order_id );
- } elseif ( $wcmq_order_id > 0 ) {
- // Order no longer exists.
- printf( '<span title="%s">#%d</span>', esc_attr__( 'Order no longer exists', 'studiou-wc-mail-queue' ), $wcmq_order_id );
- } else {
- echo '—';
- }
- ?>
- </td>
- <td><?php echo esc_html( $wcmq_row->recipient ); ?></td>
- <td>
- <span class="studiou-wcmq-state studiou-wcmq-state-<?php echo esc_attr( $wcmq_row->state ); ?>">
- <?php echo esc_html( $wcmq_row->state ); ?>
- </span>
- </td>
- <td>
- <?php
- echo (int) $wcmq_row->attempts;
- if ( (int) $wcmq_row->reclaims > 0 ) {
- printf(
- ' <abbr title="%s">(+%d)</abbr>',
- esc_attr__( 'Crash recoveries', 'studiou-wc-mail-queue' ),
- (int) $wcmq_row->reclaims
- );
- }
- ?>
- </td>
- <td><?php echo wp_kses_post( Studiou_WCMQ_Admin::format_time( $wcmq_row->scheduled_at ) ); ?></td>
- <td><?php echo wp_kses_post( Studiou_WCMQ_Admin::format_time( $wcmq_row->sent_at ) ); ?></td>
- <td class="studiou-wcmq-error"><?php echo esc_html( (string) $wcmq_row->last_error ); ?></td>
- </tr>
- <?php endforeach; ?>
- <?php endif; ?>
- </tbody>
- </table>
- <?php
- Studiou_WCMQ_Admin::render_pagination(
- 'queue',
- $wcmq_total,
- $wcmq_paged,
- $wcmq_filter ? array( 'state' => $wcmq_filter ) : array()
- );
- ?>
- </form>
|