Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Plugins_Page | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| action_links | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 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 1.3.0 |
| 7 | * |
| 8 | * @package brianhenryie/bh-wp-autologin-urls |
| 9 | */ |
| 10 | |
| 11 | namespace BrianHenryIE\WP_Autologin_URLs\Admin; |
| 12 | |
| 13 | use BrianHenryIE\WP_Autologin_URLs\Settings_Interface; |
| 14 | |
| 15 | /** |
| 16 | * This class adds a `Settings` link and a `GitHub` link on the plugins.php page. |
| 17 | */ |
| 18 | class Plugins_Page { |
| 19 | |
| 20 | /** |
| 21 | * Needed for the plugin slug and basename. |
| 22 | * |
| 23 | * @var Settings_Interface |
| 24 | */ |
| 25 | protected Settings_Interface $settings; |
| 26 | |
| 27 | /** |
| 28 | * Constructor. |
| 29 | * |
| 30 | * @param Settings_Interface $settings The plugin settings. |
| 31 | */ |
| 32 | public function __construct( Settings_Interface $settings ) { |
| 33 | $this->settings = $settings; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Add link to settings page in plugins.php list. |
| 38 | * |
| 39 | * @hooked plugin_action_links_{basename} |
| 40 | * |
| 41 | * @param array<int|string, string> $links_array The existing plugin links (usually "Deactivate"). May or may not be indexed with a string. |
| 42 | * @param ?string $plugin_file The plugin basename. |
| 43 | * @param ?array<string, string|bool> $plugin_data The parsed plugin header data. |
| 44 | * @param ?string $context 'all'|'active'|'inactive'... |
| 45 | * @return array<int|string, string> The links to display below the plugin name on plugins.php. |
| 46 | */ |
| 47 | public function action_links( array $links_array, ?string $plugin_file, ?array $plugin_data, ?string $context ): array { |
| 48 | |
| 49 | $settings_url = admin_url( '/options-general.php?page=' . $this->settings->get_plugin_slug() ); |
| 50 | |
| 51 | array_unshift( $links_array, '<a href="' . $settings_url . '">Settings</a>' ); |
| 52 | |
| 53 | return $links_array; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Add a link to GitHub repo on the plugins list. |
| 58 | * |
| 59 | * @hooked plugin_row_meta |
| 60 | * |
| 61 | * @see https://rudrastyh.com/wordpress/plugin_action_links-plugin_row_meta.html |
| 62 | * |
| 63 | * @param array<int|string, string> $plugin_meta The meta information/links displayed by the plugin description. |
| 64 | * @param string $plugin_file_name The plugin filename to match when filtering. |
| 65 | * @param array<string, string|bool> $plugin_data Associative array including PluginURI, slug, Author, Version. |
| 66 | * @param string $status The plugin status, e.g. 'Inactive'. |
| 67 | * |
| 68 | * @return array<int|string, string> The filtered $plugin_meta. |
| 69 | */ |
| 70 | public function row_meta( array $plugin_meta, string $plugin_file_name, array $plugin_data, string $status ): array { |
| 71 | |
| 72 | if ( $this->settings->get_plugin_basename() === $plugin_file_name ) { |
| 73 | |
| 74 | $plugin_meta[] = '<a target="_blank" href="https://github.com/BrianHenryIE/' . $this->settings->get_plugin_slug() . '">View on GitHub</a>'; |
| 75 | } |
| 76 | |
| 77 | return $plugin_meta; |
| 78 | } |
| 79 | } |