feat(admin): dashboard widget shown only when there are failed queue items
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user