AdminUIEnhancer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 46.88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 101
ccs 15
cts 32
cp 0.4688
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 5 1
A add_credit_links() 0 7 1
A insert_view_logs_link() 0 6 1
A hook_footer_links() 0 2 1
A __construct() 0 8 2
A insert_addon_store_link() 0 7 2
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 AdminUIEnhancer {
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 4
	public function __construct( $file = null ) {
34 4
		if ( null === $file ) {
35
			$email_log = email_log();
36
			$file      = $email_log->get_plugin_file();
37
		}
38
39 4
		$this->plugin_file     = $file;
40 4
		$this->plugin_basename = plugin_basename( $file );
41 4
	}
42
43
	/**
44
	 * Setup hooks.
45
	 *
46
	 *
47
	 */
48
	public function load() {
49
		add_filter( 'plugin_row_meta', array( $this, 'insert_addon_store_link' ), 10, 2 );
50
		add_filter( 'plugin_action_links_' . $this->plugin_basename, array( $this, 'insert_view_logs_link' ) );
51
52
		add_action( 'el_admin_footer', array( $this, 'hook_footer_links' ) );
53
	}
54
55
	/**
56
	 * Add link to Add-ons store.
57
	 *
58
	 * @see  Additional links in the Plugin listing is based on
59
	 * @link http://zourbuth.com/archives/751/creating-additional-wordpress-plugin-links-row-meta/
60
	 *
61
	 * @param array  $links Array with default links to display in plugins page.
62
	 * @param string $file  The name of the plugin file.
63
	 *
64
	 * @return array Modified list of links to display in plugins page.
65
	 */
66 2
	public function insert_addon_store_link( $links, $file ) {
67 2
		if ( $file === $this->plugin_basename ) {
68 1
			$links[] = '<a href="https://wpemaillog.com/store/?utm_campaign=Upsell&utm_medium=wpadmin&utm_source=plugin-page" rel="noopener" target="_blank">' .
69 1
			           __( 'Buy Addons', 'email-log' ) . '</a>';
70
		}
71
72 2
		return $links;
73
	}
74
75
	/**
76
	 * Add link to 'View logs' page in plugin listing page.
77
	 *
78
	 * @since 2.3.0 Added Settings link.
79
	 *
80
	 * @param array $links List of links.
81
	 *
82
	 * @return array Modified list of links.
83
	 */
84 1
	public function insert_view_logs_link( $links ) {
85 1
		$view_logs_link = '<a href="admin.php?page=email-log">' . __( 'View Logs', 'email-log' ) . '</a>';
86 1
		$settings_link  = '<a href="admin.php?page=email-log-settings">' . __( 'Settings', 'email-log' ) . '</a>';
87 1
		array_unshift( $links, $view_logs_link, $settings_link );
88
89 1
		return $links;
90
	}
91
92
	/**
93
	 * Hook Footer links.
94
	 */
95
	public function hook_footer_links() {
96
		add_action( 'in_admin_footer', array( $this, 'add_credit_links' ) );
97
	}
98
99
	/**
100
	 * Adds Footer links.
101
	 *
102
	 * @since Genesis
103
	 * @see   Function relied on
104
	 * @link  http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
105
	 */
106
	public function add_credit_links() {
107
		$plugin_data = get_plugin_data( $this->plugin_file );
108
		printf(
109
			'%1$s ' . __( 'plugin', 'email-log' ) . ' | ' . __( 'Version', 'email-log' ) . ' %2$s | ' . __( 'by', 'email-log' ) . ' %3$s<br />',
110
			$plugin_data['Title'],
111
			$plugin_data['Version'],
112
			$plugin_data['Author']
113
		);
114
	}
115
}
116