-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdminWidget.php
41 lines (28 loc) · 1.05 KB
/
AdminWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php declare( strict_types=1 );
namespace lloc\Nowpayments;
use lloc\Nowpayments\Services\ApiStatusService;
class AdminWidget {
public const WIDGET_ID = 'nowpayments_status_widget';
public function __construct(
protected readonly ApiStatusService $api_status_service
) { }
public static function init( ApiStatusService $api_status_service ): AdminWidget {
$obj = new self( $api_status_service );
add_action( 'wp_dashboard_setup', array( $obj, 'add_dashboard_widget' ) );
return $obj;
}
public function add_dashboard_widget(): void {
$widget_name = __( 'Nowpayments Status', 'wp-nowpayments-integration' );
wp_add_dashboard_widget( self::WIDGET_ID, $widget_name, array( $this, 'render' ) );
}
public function render(): void {
$data = $this->api_status_service->get_data();
/* translators: 1: service name, 2: message */
$format = __( '%1$s responds with "%2$s".', 'wp-nowpayments-integration' );
echo wp_kses_post(
'<div>' .
sprintf( $format, '<strong>' . $data['info'] . '</strong>', $data['status'] ) .
'</div>'
);
}
}