172 lines
5 KiB
PHP
172 lines
5 KiB
PHP
<?php
|
|
/**
|
|
* Email Queue Admin Page
|
|
*
|
|
* Displays queued and sent emails with status information.
|
|
*
|
|
* @package ROBOTSTXT_SMTP_Newsletter
|
|
* @since 2.2.0
|
|
*/
|
|
|
|
namespace Robotstxt_SMTP_Newsletter\Admin;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Emails List Page class.
|
|
*
|
|
* Provides admin UI for viewing email queue.
|
|
*/
|
|
class Emails_List_Page {
|
|
|
|
/**
|
|
* Register admin page hooks.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function register() {
|
|
add_submenu_page(
|
|
'newsletter_main_main',
|
|
__( 'Email Queue', 'robotstxt-smtp-newsletter' ),
|
|
__( 'Email Queue', 'robotstxt-smtp-newsletter' ),
|
|
'manage_options',
|
|
'robotstxt-smtp-newsletter-emails',
|
|
array( __CLASS__, 'render_page' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render admin page.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function render_page() {
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
wp_die( esc_html__( 'Insufficient permissions', 'robotstxt-smtp-newsletter' ) );
|
|
}
|
|
|
|
$queue = \Robotstxt_SMTP_Newsletter\Queue::get_instance();
|
|
$page = isset( $_GET['paged'] ) ? max( 1, intval( $_GET['paged'] ) ) : 1;
|
|
$per_page = 50;
|
|
$offset = ( $page - 1 ) * $per_page;
|
|
|
|
$emails = $queue->get_recent_emails( $per_page, $offset );
|
|
$total_emails = $queue->count_total_emails();
|
|
$total_pages = ceil( $total_emails / $per_page );
|
|
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php esc_html_e( 'Email Queue', 'robotstxt-smtp-newsletter' ); ?></h1>
|
|
|
|
<p class="description">
|
|
<?php
|
|
printf(
|
|
/* translators: %d: total emails in queue */
|
|
esc_html__( 'Total emails in database: %d', 'robotstxt-smtp-newsletter' ),
|
|
number_format_i18n( $total_emails )
|
|
);
|
|
?>
|
|
</p>
|
|
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th style="width:50px;"><?php esc_html_e( 'ID', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'To', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'Subject', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'Campaign', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'Status', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'Created', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
<th><?php esc_html_e( 'Sent', 'robotstxt-smtp-newsletter' ); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if ( empty( $emails ) ) : ?>
|
|
<tr>
|
|
<td colspan="7" style="text-align:center; padding:40px;">
|
|
<p><?php esc_html_e( 'No emails in queue', 'robotstxt-smtp-newsletter' ); ?></p>
|
|
</td>
|
|
</tr>
|
|
<?php else : ?>
|
|
<?php foreach ( $emails as $email ) : ?>
|
|
<tr>
|
|
<td><?php echo absint( $email->id ); ?></td>
|
|
<td><?php echo esc_html( $email->to_email ); ?></td>
|
|
<td>
|
|
<strong><?php echo esc_html( $email->subject ); ?></strong>
|
|
<?php if ( ! empty( $email->last_error ) ) : ?>
|
|
<br><small style="color:#d9534f;">
|
|
<?php echo esc_html( $email->last_error ); ?>
|
|
</small>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo esc_html( $email->campaign_name ?? '-' ); ?></td>
|
|
<td>
|
|
<?php
|
|
if ( $email->sent_at ) {
|
|
echo '<span style="color:#5cb85c;">✓ ' . esc_html__( 'Sent', 'robotstxt-smtp-newsletter' ) . '</span>';
|
|
} elseif ( $email->locked_at ) {
|
|
echo '<span style="color:#f0ad4e;">⏳ ' . esc_html__( 'Processing', 'robotstxt-smtp-newsletter' ) . '</span>';
|
|
} elseif ( $email->attempts >= 3 ) {
|
|
echo '<span style="color:#d9534f;">✗ ' . esc_html__( 'Failed', 'robotstxt-smtp-newsletter' ) . '</span>';
|
|
} else {
|
|
echo '<span style="color:#999;">⏸ ' . esc_html__( 'Pending', 'robotstxt-smtp-newsletter' ) . '</span>';
|
|
if ( $email->attempts > 0 ) {
|
|
echo sprintf(
|
|
' <small>(%s)</small>',
|
|
sprintf(
|
|
/* translators: %d: number of retry attempts */
|
|
esc_html__( 'Retry %d', 'robotstxt-smtp-newsletter' ),
|
|
absint( $email->attempts )
|
|
)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
$created_time = mysql2date( 'Y-m-d H:i:s', $email->created_at );
|
|
echo esc_html( $created_time );
|
|
?>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
if ( $email->sent_at ) {
|
|
$sent_time = mysql2date( 'Y-m-d H:i:s', $email->sent_at );
|
|
echo esc_html( $sent_time );
|
|
} else {
|
|
echo '-';
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php if ( $total_pages > 1 ) : ?>
|
|
<div class="tablenav bottom">
|
|
<div class="tablenav-pages">
|
|
<?php
|
|
echo paginate_links(
|
|
array(
|
|
'base' => add_query_arg( 'paged', '%#%' ),
|
|
'format' => '',
|
|
'prev_text' => __( '«' ),
|
|
'next_text' => __( '»' ),
|
|
'total' => $total_pages,
|
|
'current' => $page,
|
|
)
|
|
);
|
|
?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|