PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.7.19
Admin Columns v4.7.19
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Entity / Plugin.php
codepress-admin-columns / classes / Entity Last commit date
Plugin.php 6 months ago
Plugin.php
151 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Entity;
6
7 use AC\Plugin\Version;
8 use AC\PluginUpdate;
9
10 class Plugin
11 {
12
13 private string $basename;
14
15 private string $dir;
16
17 private string $url;
18
19 private Version $version;
20
21 public function __construct(string $basename, string $dir, string $url, Version $version)
22 {
23 $this->basename = $basename;
24 $this->dir = $dir;
25 $this->url = $url;
26 $this->version = $version;
27 }
28
29 public static function create(string $file, Version $version): self
30 {
31 return new self(
32 plugin_basename($file),
33 plugin_dir_path($file),
34 plugin_dir_url($file),
35 $version
36 );
37 }
38
39 public function get_version(): Version
40 {
41 return $this->version;
42 }
43
44 public function get_basename(): string
45 {
46 return $this->basename;
47 }
48
49 public function get_dir(): string
50 {
51 return $this->dir;
52 }
53
54 public function get_url(): string
55 {
56 return $this->url;
57 }
58
59 public function get_dirname(): string
60 {
61 return dirname($this->basename);
62 }
63
64 public function is_installed(): bool
65 {
66 return null !== $this->get_header_data();
67 }
68
69 public function is_active(): bool
70 {
71 require_once ABSPATH . 'wp-admin/includes/plugin.php';
72
73 return is_plugin_active($this->basename);
74 }
75
76 public function is_network_active(): bool
77 {
78 require_once ABSPATH . 'wp-admin/includes/plugin.php';
79
80 return is_plugin_active_for_network($this->basename);
81 }
82
83 public function get_name(): ?string
84 {
85 return $this->get_header_var('Name');
86 }
87
88 private function get_plugins(): array
89 {
90 require_once ABSPATH . 'wp-admin/includes/plugin.php';
91
92 // use `get_plugins` (cached) over `get_plugin_data` (non cached)
93 return get_plugins();
94 }
95
96 private function get_plugin_updates(): array
97 {
98 require_once ABSPATH . 'wp-admin/includes/plugin.php';
99
100 return get_plugin_updates();
101 }
102
103 public function has_update(): bool
104 {
105 return null !== $this->get_update();
106 }
107
108 public function get_update(): ?PluginUpdate
109 {
110 $updates = $this->get_plugin_updates();
111
112 if ( ! array_key_exists($this->basename, $updates)) {
113 return null;
114 }
115
116 $data = $updates[$this->basename];
117
118 if ( ! property_exists($data, 'update')) {
119 return null;
120 }
121
122 if ( ! property_exists($data->update, 'new_version')) {
123 return null;
124 }
125
126 $version = new Version($data->update->new_version);
127
128 if ( ! $version->is_valid() || $version->is_lte($this->version)) {
129 return null;
130 }
131
132 $package = property_exists($data->update, 'package') && $data->update->package
133 ? $data->update->package
134 : null;
135
136 return new PluginUpdate(new Version($data->update->new_version), $package);
137 }
138
139 private function get_header_data(): ?array
140 {
141 $plugins = $this->get_plugins();
142
143 return $plugins[$this->basename] ?? null;
144 }
145
146 private function get_header_var(string $var): ?string
147 {
148 return $this->get_header_data()[$var] ?? null;
149 }
150
151 }