UpdatePlugins.php
1 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
<?php
namespace ACP\RequestHandler\Ajax;
use AC;
use AC\Nonce;
use ACP\ActivationTokenFactory;
use ACP\RequestAjaxHandler;
use ACP\Transient\UpdateCheckTransient;
use ACP\Updates\PluginDataUpdater;
class UpdatePlugins implements RequestAjaxHandler {
/**
* @var ActivationTokenFactory
*/
private $activation_token_factory;
/**
* @var PluginDataUpdater
*/
private $updater;
/**
* @var UpdateCheckTransient
*/
private $cache;
public function __construct( ActivationTokenFactory $activation_token_factory, PluginDataUpdater $updater, UpdateCheckTransient $cache ) {
$this->activation_token_factory = $activation_token_factory;
$this->updater = $updater;
$this->cache = $cache;
}
public function handle(): void {
$request = new AC\Request();
if ( ! ( new Nonce\Ajax() )->verify( $request ) ) {
wp_send_json_error();
}
if ( $this->cache->is_expired() ) {
$this->updater->update( $this->activation_token_factory->create() );
$this->cache->save( HOUR_IN_SECONDS * 12 );
}
}
}