feat(admin): dashboard widget shown only when there are failed queue items

This commit is contained in:
Vladimir Bryzgalov
2026-04-17 22:50:29 +05:00
parent fef22c1ff8
commit f5816e4648
2 changed files with 45 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Cf7stg;
final class Dashboard_Widget
{
public function register(): void
{
add_action('wp_dashboard_setup', [$this, 'maybe_register_widget']);
}
public function maybe_register_widget(): void
{
if (Queue::count_failed() === 0) return;
wp_add_dashboard_widget(
'cf7stg_dashboard_errors',
'⚠️ CF7 Spam → Telegram: ошибки доставки',
[$this, 'render']
);
}
public function render(): void
{
$failed = Queue::list_failed(10);
$count = Queue::count_failed();
$settings_url = admin_url('options-general.php?page=cf7stg-settings');
include CF7STG_PLUGIN_DIR . 'admin/views/dashboard-widget.php';
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
/** @var array<int,object> $failed */
/** @var int $count */
/** @var string $settings_url */
?>
<p>Есть <b><?php echo (int)$count; ?></b> неотправленных сообщений (TG-API отвечает ошибкой):</p>
<ul style="margin:0 0 8px 18px;list-style:disc">
<?php foreach ($failed as $row): ?>
<li>
<?php echo esc_html((string)$row->created_at); ?> —
<?php echo esc_html((string)$row->last_error); ?>
</li>
<?php endforeach; ?>
</ul>
<p><a href="<?php echo esc_url($settings_url); ?>" class="button">Открыть настройки →</a></p>