ViewPluginDetails.php
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace ACP\Updates;
use AC\Registrable;
use ACP\API\Request;
use ACP\RequestDispatcher;
use WP_Error;
/**
* Show changelog when "click view details".
*/
class ViewPluginDetails implements Registrable {
/**
* @var string
*/
private $slug;
/**
* @var RequestDispatcher
*/
private $api;
public function __construct( $slug, RequestDispatcher $api ) {
$this->slug = (string) $slug;
$this->api = $api;
}
public function register() {
add_filter( 'plugins_api', [ $this, 'get_plugin_information' ], 10, 3 );
}
/**
* @param mixed $result
* @param string $action
* @param object $args
*
* @return object|WP_Error
*/
public function get_plugin_information( $result, $action, $args ) {
if ( 'plugin_information' !== $action ) {
return $result;
}
if ( $this->slug !== $args->slug ) {
return $result;
}
$response = $this->api->dispatch( new Request\ProductInformation( $this->slug ) );
if ( $response->has_error() ) {
return $response;
}
return $response->get_body();
}
}