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     * Constructor.
19     *
20     * @param Logger_Settings_Interface $settings The plugin settings.
21     */
22    public function __construct(
23        protected Logger_Settings_Interface $settings
24    ) {
25    }
26
27    /**
28     * Add the Logs page link to the existing links.
29     *
30     * @hooked install_plugin_complete_actions
31     * @see \Plugin_Installer_Skin::after()
32     *
33     * @param string[] $install_actions Array of plugin action links.
34     * @param object   $_api            Object containing WordPress.org API plugin data. Empty
35     *                                  for non-API installs, such as when a plugin is installed
36     *                                  via upload.
37     * @param string   $plugin_file     Path to the plugin file relative to the plugins' directory.
38     *
39     * @return string[]
40     */
41    public function add_logs_link( $install_actions, $_api, $plugin_file ): array {
42
43        if ( $plugin_file !== $this->settings->get_plugin_basename() ) {
44            return $install_actions;
45        }
46
47        $install_actions[] = '•';
48
49        $logs_url          = admin_url( '/admin.php?page=' . $this->settings->get_plugin_slug() . '-logs' );
50        $install_actions[] = '<a href="' . esc_url( $logs_url ) . '">Go to ' . esc_html( $this->settings->get_plugin_name() ) . ' logs</a>';
51
52        return $install_actions;
53    }
54}