Completed
Pull Request — master (#110)
by Maria Daniel Deepak
07:40
created

DashboardWidget::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php namespace EmailLog\Core\UI\Component;
2
3
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
4
5
/**
6
 * Enhance Admin UI and add links about EmailLog in the following places.
7
 * - Plugin List page.
8
 * - Footer for all EmailLog pages.
9
 *
10
 * @since 2.0.0
11
 */
12
class DashboardWidget {
13
14
	/**
15
	 * Plugin file name.
16
	 *
17
	 * @var string
18
	 */
19
	protected $plugin_file;
20
21
	/**
22
	 * Plugin basename.
23
	 *
24
	 * @var string
25
	 */
26
	protected $plugin_basename;
27
28
	/**
29
	 * Initialize the component and store the plugin basename.
30
	 *
31
	 * @param string|null $file Plugin file.
32
	 */
33
	public function __construct( $file = null ) {
34
		if ( null === $file ) {
35
			$email_log = email_log();
36
			$file      = $email_log->get_plugin_file();
37
		}
38
39
		$this->plugin_file     = $file;
40
		$this->plugin_basename = plugin_basename( $file );
41
	}
42
43
	/**
44
	 * Setup hooks.
45
	 *
46
	 * @inheritdoc
47
	 */
48
	public function load() {
49
		add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) );
50
	}
51
52
	/**
53
	 * Adds the dashboard widget to display Email Log activity.
54
	 */
55
	public function add_dashboard_widget() {
56
57
		wp_add_dashboard_widget(
58
			'email_log_dashboard_widget',
59
			__( 'Email Log Activity', 'email-log' ),
60
			array( $this, 'display_email_log_activity' )
61
		);
62
	}
63
64
	/**
65
	 * Outputs the contents on the Dashboard Widget.
66
	 */
67
	public function display_email_log_activity() {
68
		$email_log  = email_log();
69
		$logs_count = $email_log->table_manager->fetch_logs_count();
70
71
		ob_start();
72
		?>
73
		<p>Total number of emails logged: <strong><?php echo $logs_count; ?></strong></p>
74
		<p><a href="">Click here</a> to view Email Logs.</p>
75
		<?php
76
		echo ob_get_clean();
77
	}
78
}