Completed
Push — master ( 49679a...617b2a )
by Sudar
02:03
created

AdminUIEnhancer::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
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 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 $file Plugin file.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $file not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

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