Scripts.php
1.66 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
60
61
62
63
64
65
66
67
68
<?php
namespace ACP\Admin;
use AC\Asset;
use AC\Asset\Enqueueable;
use AC\Registerable;
use ACP\Access\PermissionsStorage;
use ACP\Asset\Script;
use ACP\Transient\LicenseCheckTransient;
class Scripts implements Registerable {
/**
* @var Asset\Location\Absolute
*/
private $location;
/**
* @var PermissionsStorage
*/
private $permission_storage;
/**
* @var bool
*/
private $network_active;
public function __construct( Asset\Location\Absolute $location, PermissionsStorage $permission_storage, $network_active ) {
$this->location = $location;
$this->permission_storage = $permission_storage;
$this->network_active = (bool) $network_active;
}
public function register() {
add_action( 'ac/admin_scripts', [ $this, 'register_usage_limiter' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'register_daily_license_check' ] );
}
public function register_usage_limiter() {
if ( $this->permission_storage->retrieve()->has_usage_permission() ) {
return;
}
$assets = [
new Asset\Style( 'acp-usage-limiter', $this->location->with_suffix( 'assets/core/css/usage-limiter.css' ) ),
new Asset\Script( 'acp-usage-limiter', $this->location->with_suffix( 'assets/core/js/usage-limiter.js' ) ),
];
array_map( [ $this, 'enqueue' ], $assets );
}
public function register_daily_license_check() {
$transient = new LicenseCheckTransient( $this->network_active );
if ( $transient->is_expired() ) {
$script = new Script\LicenseCheck( $this->location->with_suffix( 'assets/core/js/license-check.js' ) );
$script->enqueue();
$transient->save( DAY_IN_SECONDS );
}
}
private function enqueue( Enqueueable $assets ) {
$assets->enqueue();
}
}