Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Plugin_Installer
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 add_settings_link
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Adds links to Settings and Logs on the "Plugin updated successfully" page.
4 *
5 * @package brianhenryie/bh-wc-shipment-tracking-updates
6 */
7
8namespace BrianHenryIE\WP_Autologin_URLs\Admin;
9
10use BrianHenryIE\WP_Autologin_URLs\Settings_Interface;
11use Psr\Log\LoggerAwareTrait;
12use Psr\Log\LoggerInterface;
13
14/**
15 * Checks is WooCommerce active, then appends the Settings link to the "Return to plugins installer" link on the plugin update page.
16 */
17class Plugin_Installer {
18    use LoggerAwareTrait;
19
20    /**
21     * Settings needed to determine if the current update is for this plugin, then to generate the correct url.
22     *
23     * @uses Settings_Interface::get_plugin_basename()
24     * @uses Settings_Interface::get_plugin_slug()
25     *
26     * @var Settings_Interface
27     */
28    protected Settings_Interface $settings;
29
30    /**
31     * Constructor.
32     *
33     * @param Settings_Interface $settings The plugin settings.
34     * @param LoggerInterface    $logger The plugin's PSR logger.
35     */
36    public function __construct( Settings_Interface $settings, LoggerInterface $logger ) {
37        $this->setLogger( $logger );
38        $this->settings = $settings;
39    }
40
41    /**
42     * Add the settings page link to the existing links.
43     *
44     * These are only displayed on subsequent plugin installs, not the first.
45     *
46     * @hooked install_plugin_complete_actions
47     * @see \Plugin_Installer_Skin::after()
48     *
49     * @param string[] $install_actions Array of plugin action links.
50     * @param object   $_api            Object containing WordPress.org API plugin data. Empty
51     *                                  for non-API installs, such as when a plugin is installed
52     *                                  via upload.
53     * @param string   $plugin_file     Path to the plugin file relative to the plugins directory.
54     *
55     * @return string[]
56     */
57    public function add_settings_link( $install_actions, $_api, $plugin_file ): array {
58
59        if ( $plugin_file !== $this->settings->get_plugin_basename() ) {
60            return $install_actions;
61        }
62
63        $install_actions[] = '•';
64
65        $settings_url      = admin_url( '/options-general.php?page=' . $this->settings->get_plugin_slug() );
66        $install_actions[] = '<a href="' . $settings_url . '">Go to Autologin URLs settings</a>';
67
68        return $install_actions;
69    }
70}