Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.89% |
8 / 9 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
Plugins_Page | |
88.89% |
8 / 9 |
|
66.67% |
2 / 3 |
5.03 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
action_links | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
row_meta | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * The plugin page output of the plugin. |
4 | * |
5 | * @link |
6 | * @since 2.0.0 |
7 | * |
8 | * @package BH_WC_Address_Validation |
9 | * @subpackage BH_WC_Address_Validation/admin |
10 | */ |
11 | |
12 | namespace BrianHenryIE\WC_Address_Validation\Admin; |
13 | |
14 | use BrianHenryIE\WC_Address_Validation\Settings_Interface; |
15 | |
16 | /** |
17 | * This class adds a `Settings` link on the plugins.php page. |
18 | * |
19 | * @package BH_WC_Address_Validation |
20 | * @subpackage BH_WC_Address_Validation/admin |
21 | * @author Brian Henry <BrianHenryIE@gmail.com> |
22 | */ |
23 | class Plugins_Page { |
24 | |
25 | /** |
26 | * The plugin settings. |
27 | * |
28 | * @see Settings_Interface::get_plugin_basename() |
29 | * @see Settings_Interface::get_plugin_slug() |
30 | * |
31 | * @var Settings_Interface |
32 | */ |
33 | protected Settings_Interface $settings; |
34 | |
35 | /** |
36 | * Plugins_Page constructor. |
37 | * |
38 | * @param Settings_Interface $settings The plugin settings. |
39 | */ |
40 | public function __construct( Settings_Interface $settings ) { |
41 | $this->settings = $settings; |
42 | } |
43 | |
44 | /** |
45 | * Add link to settings page in plugins.php list. |
46 | * |
47 | * @param array<int|string, string> $links_array The existing plugin links (usually "Deactivate"). |
48 | * |
49 | * @return array<int|string, string> The links to display below the plugin name on plugins.php. |
50 | */ |
51 | public function action_links( array $links_array ): array { |
52 | |
53 | if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
54 | return $links_array; |
55 | } |
56 | |
57 | $settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=' . $this->settings->get_plugin_slug() ); |
58 | |
59 | array_unshift( $links_array, '<a href="' . $settings_url . '">Settings</a>' ); |
60 | |
61 | return $links_array; |
62 | } |
63 | |
64 | /** |
65 | * Add a link to GitHub repo on the plugins list. |
66 | * |
67 | * @see https://rudrastyh.com/wordpress/plugin_action_links-plugin_row_meta.html |
68 | * |
69 | * @param array<int|string, string> $plugin_meta The meta information/links displayed by the plugin description. |
70 | * @param string $plugin_file_name The plugin filename to match when filtering. |
71 | * @param array<string, string|bool> $_plugin_data Associative array including PluginURI, slug, Author, Version. |
72 | * @param string $_status The plugin status, e.g. 'Inactive'. |
73 | * |
74 | * @return array<int|string, string> The filtered $plugin_meta. |
75 | */ |
76 | public function row_meta( array $plugin_meta, string $plugin_file_name, array $_plugin_data, string $_status ): array { |
77 | |
78 | if ( $this->settings->get_plugin_basename() === $plugin_file_name ) { |
79 | |
80 | $plugin_meta[] = '<a target="_blank" href="https://github.com/BrianHenryIE/' . $this->settings->get_plugin_slug() . '">View plugin on GitHub</a>'; |
81 | } |
82 | |
83 | return $plugin_meta; |
84 | } |
85 | } |