Completed
Push — master ( 3b08d7...894d17 )
by Sudar
01:42
created

AdminUIEnhancer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 102
ccs 15
cts 35
cp 0.4286
rs 10
wmc 8
lcom 2
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A load() 0 6 1
A insert_addon_store_link() 0 8 2
A insert_view_logs_link() 0 6 1
A hook_footer_links() 0 3 1
A add_credit_links() 0 9 1
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
	 * @inheritdoc
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" target="_blank">' .
69 1
			           __( 'Buy Addons', 'email-log' ) . '</a>';
70 1
		}
71
72 2
		return $links;
73
	}
74
75
	/**
76
	 * Add link to 'View logs' page in plugin listing page.
77
	 *
78
	 * @param array $links List of links.
79
	 *
80
	 * @return array Modified list of links.
81
	 */
82 1
	public function insert_view_logs_link( $links ) {
83 1
		$settings_link = '<a href="admin.php?page=email-log">' . __( 'View Logs', 'email-log' ) . '</a>';
84 1
		array_unshift( $links, $settings_link );
85
86 1
		return $links;
87
	}
88
89
	/**
90
	 * Hook Footer links.
91
	 */
92
	public function hook_footer_links() {
93
		add_action( 'in_admin_footer', array( $this, 'add_credit_links' ) );
94
	}
95
96
	/**
97
	 * Adds Footer links.
98
	 *
99
	 * @since Genesis
100
	 *
101
	 * @see   Function relied on
102
	 * @link  http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
103
	 */
104
	public function add_credit_links() {
105
		$plugin_data = get_plugin_data( $this->plugin_file );
106
		printf(
107
			'%1$s ' . __( 'plugin', 'email-log' ) . ' | ' . __( 'Version', 'email-log' ) . ' %2$s | ' . __( 'by', 'email-log' ) . ' %3$s<br />',
108
			$plugin_data['Title'],
109
			$plugin_data['Version'],
110
			$plugin_data['Author']
111
		);
112
	}
113
}
114