Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugin_Installer
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 add_logs_link
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Adds link to Logs on the "Plugin updated successfully" page.
4 *
5 * @package brianhenryie/bh-wp-logger
6 */
7
8namespace BrianHenryIE\WP_Logger\Admin;
9
10use BrianHenryIE\WP_Logger\Logger_Settings_Interface;
11
12/**
13 * Appends a Logs link to the "Return to plugins installer" link on the plugin update page.
14 */
15class Plugin_Installer {
16
17    /**
18     * Settings used to generate the href.
19     *
20     * @uses Settings_Interface::get_plugin_basename()
21     * @uses Settings_Interface::get_plugin_slug()
22     * @uses Settings_Interface::get_plugin_name()
23     */
24    protected Logger_Settings_Interface $settings;
25
26    /**
27     * Constructor.
28     *
29     * @param Logger_Settings_Interface $settings The plugin settings.
30     */
31    public function __construct( Logger_Settings_Interface $settings ) {
32        $this->settings = $settings;
33    }
34
35    /**
36     * Add the Logs page link to the existing links.
37     *
38     * @hooked install_plugin_complete_actions
39     * @see \Plugin_Installer_Skin::after()
40     *
41     * @param string[] $install_actions Array of plugin action links.
42     * @param object   $_api            Object containing WordPress.org API plugin data. Empty
43     *                                  for non-API installs, such as when a plugin is installed
44     *                                  via upload.
45     * @param string   $plugin_file     Path to the plugin file relative to the plugins directory.
46     *
47     * @return string[]
48     */
49    public function add_logs_link( $install_actions, $_api, $plugin_file ): array {
50
51        if ( $plugin_file !== $this->settings->get_plugin_basename() ) {
52            return $install_actions;
53        }
54
55        $install_actions[] = '•';
56
57        $logs_url          = admin_url( '/admin.php?page=' . $this->settings->get_plugin_slug() . '-logs' );
58        $install_actions[] = '<a href="' . esc_url( $logs_url ) . '">Go to ' . esc_html( $this->settings->get_plugin_name() ) . ' logs</a>';
59
60        return $install_actions;
61    }
62}