Scripts.php
2.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
namespace ACA\GravityForms\Service;
use AC\Asset\Location\Absolute;
use AC\Asset\Script;
use AC\Asset\Style;
use AC\ListScreen;
use AC\Registerable;
use ACA\GravityForms\ListScreen\Entry;
class Scripts implements Registerable
{
private $location;
public function __construct(Absolute $location)
{
$this->location = $location;
}
public function register(): void
{
add_action('ac/admin_scripts', [$this, 'admin_scripts']);
add_action('ac/table_scripts', [$this, 'table_scripts']);
add_filter("gform_noconflict_styles", [$this, 'allowed_acp_styles']);
add_filter("gform_noconflict_scripts", [$this, 'allowed_acp_scripts']);
}
public function admin_scripts(): void
{
wp_enqueue_style('gform_font_awesome');
}
public function table_scripts(ListScreen $list_screen): void
{
if ( ! $list_screen instanceof Entry) {
return;
}
$style = new Style('aca-gf-table', $this->location->with_suffix('assets/css/table.css'));
$style->enqueue();
$script = new Script('aca-gf-table', $this->location->with_suffix('assets/js/table.js'));
$script->enqueue();
wp_enqueue_script('wp-tinymce');
}
public function allowed_acp_styles($objects)
{
global $wp_styles;
foreach ($wp_styles->queue as $handle) {
if ( ! $this->is_acp_asset($handle)) {
continue;
}
$objects[] = $handle;
}
return $objects;
}
public function allowed_acp_scripts($objects)
{
global $wp_scripts;
foreach ($wp_scripts->queue as $handle) {
if ( ! $this->is_acp_asset($handle)) {
continue;
}
$objects[] = $handle;
}
return $objects;
}
private function is_acp_asset(string $key): bool
{
$acp_prefixes = ['ac-', 'acp-', 'aca-', 'editor', 'mce-view', 'quicktags', 'common', 'tinymce'];
foreach ($acp_prefixes as $prefix) {
if (strpos($key, $prefix) !== false) {
return true;
}
}
return false;
}
}