Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugins_Page
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 action_links
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * The plugin page output of the plugin.
4 *
5 * @author     BrianHenryIE <BrianHenryIE@gmail.com>
6 * @link       https://BrianHenryIE.com
7 * @since      1.0.0
8 * @package brianhenryie/bh-wc-checkout-rate-limiter
9 */
10
11namespace BrianHenryIE\Checkout_Rate_Limiter\Admin;
12
13use BrianHenryIE\Checkout_Rate_Limiter\Settings_Interface;
14use Psr\Log\LoggerAwareTrait;
15use Psr\Log\LoggerInterface;
16
17/**
18 * This class adds a `Settings` link on the plugins.php page.
19 */
20class Plugins_Page {
21
22    use LoggerAwareTrait;
23
24    /**
25     * The plugin's settings.
26     *
27     * @var Settings_Interface
28     */
29    protected Settings_Interface $settings;
30
31    /**
32     * Instantiate Plugins_Page.
33     *
34     * TODO The logger is not being used.
35     *
36     * @param Settings_Interface $settings The plugin settings.
37     * @param LoggerInterface    $logger PSR logger.
38     */
39    public function __construct( Settings_Interface $settings, LoggerInterface $logger ) {
40        $this->settings = $settings;
41        $this->setLogger( $logger );
42    }
43
44    /**
45     * Add link to settings page in plugins.php list.
46     *
47     * @hooked plugin_action_links_{basename}
48     *
49     * @param array<int|string, string>   $action_links The existing plugin links (usually "Deactivate").
50     * @param ?string                     $_plugin_basename The plugin's directory/filename.php.
51     * @param ?array<string, string|bool> $_plugin_data Associative array including PluginURI, slug, Author, Version. See `get_plugin_data()`.
52     * @param ?string                     $_context     The plugin context. By default this can include 'all', 'active', 'inactive',
53     *                                                'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
54     *
55     * @return array<int|string, string> The links to display below the plugin name on plugins.php.
56     */
57    public function action_links( array $action_links, ?string $_plugin_basename, ?array $_plugin_data, ?string $_context ): array {
58
59        $settings_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=checkout-rate-limiting' );
60
61        array_unshift( $action_links, '<a href="' . $settings_url . '">Settings</a>' );
62
63        return $action_links;
64    }
65
66}