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 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Licence_Management_Tab
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_licence_tab
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 get_licence_tab_html
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Add licence UI to the plugins.php "View Details" modal, aka `plugin-information-tabs`.
4 *
5 * @see install_plugin_information()
6 *
7 * @package brianhenryie/bh-wp-plugin-updater
8 */
9
10namespace BrianHenryIE\WP_Plugin_Updater\Admin;
11
12use BrianHenryIE\WP_Plugin_Updater\API_Interface;
13use BrianHenryIE\WP_Plugin_Updater\Settings_Interface;
14
15class Licence_Management_Tab {
16
17    /**
18     * Constructor.
19     *
20     * @param API_Interface      $api
21     * @param Settings_Interface $settings
22     */
23    public function __construct(
24        protected API_Interface $api, // TODO: remove, not in use.
25        protected Settings_Interface $settings,
26    ) {
27    }
28
29    /**
30     * Add the `licence` section to the plugin's data.
31     *
32     * TODO: The HTML is just a loading icon. The React JS will render the actual content.
33     *
34     * Add the minimal data required for the modal, if necessary: slug, name.
35     *
36     * @hooked plugins_api ?
37     *
38     * $api->sections as $section_name => $content
39     *  // $update_plugins = get_site_transient( 'update_plugins' );
40     *
41     * @param false|object|array $res The result object or array. Default false.
42     * @param string             $action The type of information being requested from the Plugin Installation API.
43     * @param object             $args Plugin API arguments.
44     */
45    public function add_licence_tab( $res, $action, $args ) {
46
47        if ( $this->settings->get_plugin_slug() !== $args->slug ) {
48            return $res;
49        }
50
51        if ( false === $res ) {
52            $res = new \stdClass();
53        }
54
55        $res->sections['licence'] = $this->get_licence_tab_html();
56
57        return $res;
58    }
59
60    /**
61     * TODO: Print a loading icon in the licence tab while the React JS renders.
62     */
63    protected function get_licence_tab_html(): string {
64        return '';
65    }
66}