@@ -31,18 +31,19 @@ class Plugin
31
31
protected $ url ;
32
32
33
33
/**
34
- * The version of the plugin.
35
- * @var string
34
+ * The data of the plugin.
35
+ * @var array
36
36
*/
37
- protected $ version ;
37
+ protected $ data ;
38
38
39
39
/**
40
- * __construct method
40
+ * Constructor.
41
41
* @param string $pluginFile The full path and filename of the plugin.
42
42
*/
43
43
public function __construct (string $ pluginFile )
44
44
{
45
45
$ this ->pluginFile = $ pluginFile ;
46
+ require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
46
47
}
47
48
48
49
/**
@@ -53,11 +54,10 @@ public function loaded()
53
54
$ this ->setBasename ()
54
55
->setDirectory ()
55
56
->setUrl ()
56
- ->setVersion ();
57
+ ->setData ();
57
58
}
58
59
59
60
/**
60
- * getFile method
61
61
* Get the full path and filename of the plugin.
62
62
* @return string The full path and filename.
63
63
*/
@@ -67,7 +67,6 @@ public function getFile(): string
67
67
}
68
68
69
69
/**
70
- * getBasename method
71
70
* Get the basename of the plugin.
72
71
* @return string The basename.
73
72
*/
@@ -77,7 +76,6 @@ public function getBasename(): string
77
76
}
78
77
79
78
/**
80
- * setBasename method
81
79
* Set the basename of the plugin.
82
80
* @return object This Plugin object.
83
81
*/
@@ -88,7 +86,6 @@ public function setBasename(): object
88
86
}
89
87
90
88
/**
91
- * getDirectory method
92
89
* Get the filesystem directory path (with trailing slash) for the plugin.
93
90
* @return string The filesystem directory path.
94
91
*/
@@ -98,29 +95,26 @@ public function getDirectory(): string
98
95
}
99
96
100
97
/**
101
- * setDirectory method
102
98
* Set the filesystem directory path (with trailing slash) for the plugin.
103
99
* @return object This Plugin object.
104
100
*/
105
101
public function setDirectory (): object
106
102
{
107
- $ this ->directory = rtrim (plugin_dir_path ($ this ->pluginFile ), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
103
+ $ this ->directory = rtrim (plugin_dir_path ($ this ->pluginFile ), ' / ' ) . ' / ' ;
108
104
return $ this ;
109
105
}
110
106
111
107
/**
112
- * getPath method
113
108
* Get the filesystem directory path (with trailing slash) for the plugin.
114
109
* @param string $path The path name.
115
110
* @return string The filesystem directory path.
116
111
*/
117
112
public function getPath (string $ path = '' ): string
118
113
{
119
- return $ this ->directory . ($ path ? trim ($ path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR : '' );
114
+ return $ this ->directory . ($ path ? trim ($ path , ' / ' ) . ' / ' : '' );
120
115
}
121
116
122
117
/**
123
- * getUrl method
124
118
* Get the URL directory path (with trailing slash) for the plugin.
125
119
* @param string $path The path name.
126
120
* @return string The URL directory path.
@@ -131,7 +125,6 @@ public function getUrl(string $path = ''): string
131
125
}
132
126
133
127
/**
134
- * setUrl method
135
128
* Set the URL directory path (with trailing slash) for the plugin.
136
129
* @return object This Plugin object.
137
130
*/
@@ -142,7 +135,6 @@ public function setUrl(): object
142
135
}
143
136
144
137
/**
145
- * getSlug method
146
138
* Get the slug of the plugin.
147
139
* @return string The slug.
148
140
*/
@@ -152,31 +144,58 @@ public function getSlug(): string
152
144
}
153
145
154
146
/**
155
- * getVersion method
147
+ * Set the data of the plugin.
148
+ * @return object This Plugin object.
149
+ */
150
+ public function setData (): object
151
+ {
152
+ $ this ->data = get_plugin_data ($ this ->pluginFile , false , false );
153
+ return $ this ;
154
+ }
155
+
156
+ /**
157
+ * Get the data of the plugin.
158
+ * @return array The data.
159
+ */
160
+ public function getData (): array
161
+ {
162
+ return $ this ->data ;
163
+ }
164
+
165
+ /**
166
+ * Get the name of the plugin.
167
+ * @return string The name.
168
+ */
169
+ public function getName (): string
170
+ {
171
+ return $ this ->data ['Name ' ];
172
+ }
173
+
174
+ /**
156
175
* Get the version of the plugin.
157
176
* @return string The version.
158
177
*/
159
178
public function getVersion (): string
160
179
{
161
- if (defined ('WP_DEBUG ' ) && WP_DEBUG ) {
162
- return bin2hex (random_bytes (4 ));
163
- }
164
- return $ this ->version ;
180
+ return $ this ->data ['Version ' ];
165
181
}
166
182
167
183
/**
168
- * getVersion method
169
- * Set the version of the plugin.
170
- * @return object This Plugin object.
184
+ * Get the required WordPress version of the plugin.
185
+ * @return string The required WordPress version.
171
186
*/
172
- public function setVersion (): object
187
+ public function getRequiresWP (): string
173
188
{
174
- $ headers = ['Version ' => 'Version ' ];
175
- $ fileData = get_file_data ($ this ->pluginFile , $ headers , 'plugin ' );
176
- if (isset ($ fileData ['Version ' ])) {
177
- $ this ->version = $ fileData ['Version ' ];
178
- };
179
- return $ this ;
189
+ return $ this ->data ['RequiresWP ' ];
190
+ }
191
+
192
+ /**
193
+ * Get the required PHP version of the plugin.
194
+ * @return string The required PHP version.
195
+ */
196
+ public function getRequiresPHP (): string
197
+ {
198
+ return $ this ->data ['RequiresPHP ' ];
180
199
}
181
200
182
201
/**
@@ -187,15 +206,6 @@ public function __call(string $name, array $arguments)
187
206
{
188
207
if (!method_exists ($ this , $ name )) {
189
208
$ message = sprintf ('Call to undefined method %1$s::%2$s ' , __CLASS__ , $ name );
190
- do_action (
191
- 'rrze.log.error ' ,
192
- $ message ,
193
- [
194
- 'class ' => __CLASS__ ,
195
- 'method ' => $ name ,
196
- 'arguments ' => $ arguments
197
- ]
198
- );
199
209
if (defined ('WP_DEBUG ' ) && WP_DEBUG ) {
200
210
throw new \Exception ($ message );
201
211
}
0 commit comments