'info-outline', 'description' => __('What was sent, and anything waiting or failed.', 'agumail'), )); agumail_admin_register_action('status_retry', 'agumail_status_retry', array('id' => 'int')); agumail_admin_register_action('status_retry_all', 'agumail_status_retry_all'); agumail_admin_register_action('status_discard', 'agumail_status_discard', array('id' => 'int', 'version' => 'int')); agumail_admin_register_action('status_discard_all', 'agumail_status_discard_all'); } /** AguMail took a batch: when, where, how many. Written from the drain and the bulk sync, never a shopper's request. */ function agumail_status_record_sent($endpoint, $count) { update_option('agumail_last_sent', array('at' => agumail_time(), 'endpoint' => (string) $endpoint, 'count' => (int) $count), false); } // ───────────────────────────────────────────────────────────────────────────── // Actions. // ───────────────────────────────────────────────────────────────────────────── function agumail_status_request_id(array $request) { return isset($request['id']) ? absint($request['id']) : 0; } function agumail_status_retry(array $request) { $id = agumail_status_request_id($request); if (!$id || !agumail_outbox_retry($id)) { return new WP_Error('agumail_status_missing', __('That item is no longer in the queue.', 'agumail')); } return __('The item goes again with the next send.', 'agumail'); } function agumail_status_retry_all() { $count = agumail_outbox_retry_failed(); /* translators: number of items */ return sprintf(_n('%s item goes again with the next send.', '%s items go again with the next send.', $count, 'agumail'), number_format_i18n($count)); } /** * Discards the failed item as the page showed it: a row that changed since (a * customer answered again, and it went back in line) is kept. */ function agumail_status_discard(array $request) { $id = agumail_status_request_id($request); $version = isset($request['version']) ? absint($request['version']) : 0; if (!$id || !$version || !agumail_outbox_discard($id, $version)) { return new WP_Error('agumail_status_missing', __('That item changed or is no longer in the failed list, so it was kept. Reload the page to see it now.', 'agumail')); } return __('The item was discarded. AguMail will not receive it.', 'agumail'); } function agumail_status_discard_all() { $count = agumail_outbox_discard_failed(); /* translators: number of items */ return sprintf(_n('%s item was discarded.', '%s items were discarded.', $count, 'agumail'), number_format_i18n($count)); } // ───────────────────────────────────────────────────────────────────────────── // The section. // ───────────────────────────────────────────────────────────────────────────── function agumail_status_type_labels() { return array( 'contact' => __('Contacts', 'agumail'), 'user' => __('Customer accounts', 'agumail'), 'product' => __('Products', 'agumail'), 'order' => __('Orders', 'agumail'), 'cart' => __('Carts', 'agumail'), 'signup' => __('Form signups', 'agumail'), 'order_contact' => __('Checkout subscribers', 'agumail'), ); } /** A UTC DATETIME from the tables, as a timestamp. */ function agumail_status_time($datetime) { $time = $datetime ? strtotime($datetime . ' UTC') : false; return $time ? $time : 0; } function agumail_status_ago($timestamp) { /* translators: a length of time, such as 5 mins */ return sprintf(__('%s ago', 'agumail'), human_time_diff((int) $timestamp, agumail_time())); } function agumail_status_render_section() { $stats = agumail_outbox_stats(); echo '
| ' . esc_html__('Queue', 'agumail') . ' | '; agumail_status_render_queue($stats); echo ' |
|---|---|
| ' . esc_html__('Store data sync', 'agumail') . ' | ' . esc_html(agumail_bulk_summary(agumail_bulk_state())) . ' ' . esc_html__('Store data', 'agumail') . ' |
' . esc_html__('WooCommerce > Status > Logs, source agumail. Shoppers\' addresses are masked there.', 'agumail') . '
' . esc_html__('Tools > Scheduled Actions. Warnings and errors also go to the WordPress debug log while WP_DEBUG_LOG is on, with addresses masked.', 'agumail') . '
| ' . esc_html__('Type', 'agumail') . ' | ' . esc_html__('Waiting', 'agumail') . ' | ' . esc_html__('Failed', 'agumail') . ' |
|---|---|---|
| ' . esc_html($label !== '' ? $label : $type) . ' | ' . esc_html(number_format_i18n($stats['by_type'][$type]['pending'])) . ' | ' . esc_html(number_format_i18n($stats['by_type'][$type]['failed'])) . ' |
' . esc_html(sprintf(__('Oldest waiting item: queued %s.', 'agumail'), agumail_status_ago($oldest))) . '
'; } } /** What a queued item is, for the merchant: the order or product number, the address, the cart, who signed up on which form. */ function agumail_status_item_label(array $row) { $key = (string) $row['object_key']; switch ($row['type']) { case 'order': /* translators: the order number */ return sprintf(__('Order #%s', 'agumail'), $key); case 'product': /* translators: the product id */ return sprintf(__('Product #%s', 'agumail'), $key); case 'user': $user = get_userdata((int) $key); /* translators: the account's email address, or its id */ return $user ? sprintf(__('Customer account %s', 'agumail'), $user->user_email) : sprintf(__('Customer account #%s', 'agumail'), $key); case 'cart': /* translators: the cart id */ return sprintf(__('Cart %s', 'agumail'), $key); case 'order_contact': /* translators: the order number */ return sprintf(__('Checkout subscriber from order #%s', 'agumail'), $key); case 'contact': return $key; case 'signup': $record = is_array($row['payload']) ? $row['payload'] : array(); if (!empty($record['email']) && !empty($record['form']['name'])) { /* translators: 1: the email address that signed up, 2: the name of the form they used */ return sprintf(__('%1$s from %2$s', 'agumail'), $record['email'], $record['form']['name']); } /* translators: the queued signup's key */ return sprintf(__('Form signup %s', 'agumail'), $key); } return $row['type'] . ' ' . $key; } function agumail_status_render_failed($total) { if ($total <= 0) { return; } echo '' . esc_html(sprintf(_n( 'AguMail refused %s item, or it failed too many times. Retry sends it again with the next send; Discard drops it.', 'AguMail refused %s items, or they failed too many times. Retry sends them again with the next send; Discard drops them.', $total, 'agumail'), number_format_i18n($total))) . '
'; echo '| ' . esc_html__('Item', 'agumail') . ' | ' . esc_html__('Error', 'agumail') . ' | ' . '' . esc_html__('Tries', 'agumail') . ' | ' . esc_html__('Last tried', 'agumail') . ' | ' . '' . esc_html__('Actions', 'agumail') . ' |
|---|---|---|---|---|
| ' . esc_html(agumail_status_item_label($row)) . ' | ' . esc_html((string) $row['last_error']) . ' | ' . esc_html(number_format_i18n((int) $row['attempts'])) . ' | ' . esc_html($tried ? agumail_status_ago($tried) : '') . ' | ' . '' . esc_html__('Retry', 'agumail') . ' | ' . '' . esc_html__('Discard', 'agumail') . '' . ' |
' . esc_html(sprintf(__('Showing the %1$s most recent of %2$s.', 'agumail'), number_format_i18n(AGUMAIL_STATUS_FAILED_SHOWN), number_format_i18n($total))) . '
'; } } function agumail_status_button($action, $label, $confirm) { echo ''; }