@@ -13,35 +13,35 @@ |
||
13 | 13 | class RewriteRules |
14 | 14 | { |
15 | 15 | |
16 | - const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
16 | + const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function flush() |
|
25 | - { |
|
26 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
27 | - } |
|
19 | + /** |
|
20 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function flush() |
|
25 | + { |
|
26 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function flushRewriteRules() |
|
36 | - { |
|
37 | - if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
38 | - add_action( |
|
39 | - 'shutdown', |
|
40 | - static function () { |
|
41 | - flush_rewrite_rules(); |
|
42 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
43 | - } |
|
44 | - ); |
|
45 | - } |
|
46 | - } |
|
30 | + /** |
|
31 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function flushRewriteRules() |
|
36 | + { |
|
37 | + if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
38 | + add_action( |
|
39 | + 'shutdown', |
|
40 | + static function () { |
|
41 | + flush_rewrite_rules(); |
|
42 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
43 | + } |
|
44 | + ); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
38 | 38 | add_action( |
39 | 39 | 'shutdown', |
40 | - static function () { |
|
40 | + static function() { |
|
41 | 41 | flush_rewrite_rules(); |
42 | 42 | update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
43 | 43 | } |
@@ -21,270 +21,270 @@ |
||
21 | 21 | class Mirror |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var ReflectionClass[] $classes |
|
26 | - */ |
|
27 | - private $classes = []; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ReflectionMethod[] $constructors |
|
31 | - */ |
|
32 | - private $constructors = []; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var ReflectionParameter[][] $parameters |
|
36 | - */ |
|
37 | - private $parameters = []; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var ReflectionParameter[][] $parameters |
|
41 | - */ |
|
42 | - private $parameter_classes = []; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var ReflectionProperty[][] $properties |
|
46 | - */ |
|
47 | - private $properties = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var ReflectionMethod[][] $methods |
|
51 | - */ |
|
52 | - private $methods = []; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $class_name |
|
57 | - * @return ReflectionClass |
|
58 | - * @throws ReflectionException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
61 | - public function getReflectionClass($class_name) |
|
62 | - { |
|
63 | - if (! is_string($class_name)) { |
|
64 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | - } |
|
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | - } |
|
69 | - return $this->classes[ $class_name ]; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $class_name |
|
75 | - * @return ReflectionMethod |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function getConstructor($class_name) |
|
80 | - { |
|
81 | - if (! is_string($class_name)) { |
|
82 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | - } |
|
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
85 | - $reflection_class = $this->getReflectionClass($class_name); |
|
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | - } |
|
88 | - return $this->constructors[ $class_name ]; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param ReflectionClass $reflection_class |
|
94 | - * @return ReflectionMethod |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | - { |
|
100 | - return $this->getConstructor($reflection_class->getName()); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $class_name |
|
106 | - * @return ReflectionParameter[] |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public function getParameters($class_name) |
|
111 | - { |
|
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
113 | - $constructor = $this->getConstructor($class_name); |
|
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | - } |
|
116 | - return $this->parameters[ $class_name ]; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param ReflectionClass $reflection_class |
|
122 | - * @return ReflectionParameter[] |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - * @throws ReflectionException |
|
125 | - */ |
|
126 | - public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | - { |
|
128 | - return $this->getParameters($reflection_class->getName()); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param ReflectionMethod $constructor |
|
134 | - * @return ReflectionParameter[] |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | - { |
|
140 | - return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param ReflectionParameter $param |
|
146 | - * @param string $class_name |
|
147 | - * @param string $index |
|
148 | - * @return string|null |
|
149 | - */ |
|
150 | - public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
151 | - { |
|
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
154 | - } |
|
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = []; |
|
157 | - } |
|
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
160 | - } |
|
161 | - // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
162 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | - ? $this->getParameterClassNameLegacy($param) |
|
164 | - : $this->getParameterClassNamePhp8($param); |
|
165 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param ReflectionParameter $param |
|
171 | - * @return string|null |
|
172 | - * @since 4.10.13.p |
|
173 | - */ |
|
174 | - private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
175 | - { |
|
176 | - $reflection_class = $param->getClass(); |
|
177 | - return $reflection_class instanceof ReflectionClass |
|
178 | - ? $param->getClass()->getName() |
|
179 | - : null; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
185 | - * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
186 | - * which can either be a ReflectionNamedType or ReflectionUnionType |
|
187 | - * |
|
188 | - * @param ReflectionParameter $param |
|
189 | - * @return null |
|
190 | - * @since 4.10.13.p |
|
191 | - */ |
|
192 | - private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
193 | - { |
|
194 | - $reflection_type = $param->getType(); |
|
195 | - |
|
196 | - if ($reflection_type instanceof \ReflectionNamedType) { |
|
197 | - return $reflection_type->getName(); |
|
198 | - } |
|
199 | - |
|
200 | - if ($reflection_type instanceof \ReflectionUnionType) { |
|
201 | - $reflection_types = $reflection_type->getTypes(); |
|
202 | - if (is_array($reflection_types)) { |
|
203 | - $first = reset($reflection_types); |
|
204 | - return $first->getName(); |
|
205 | - } |
|
206 | - } |
|
207 | - return null; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param ReflectionParameter $param |
|
213 | - * @param string $class_name |
|
214 | - * @param string $index |
|
215 | - * @return string|null |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
219 | - { |
|
220 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
222 | - } |
|
223 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | - $this->parameter_classes[ $class_name ] = []; |
|
225 | - } |
|
226 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
228 | - } |
|
229 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | - ? $param->getDefaultValue() |
|
231 | - : null; |
|
232 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param string $class_name |
|
238 | - * @return ReflectionProperty[] |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws ReflectionException |
|
241 | - */ |
|
242 | - public function getProperties($class_name) |
|
243 | - { |
|
244 | - if (! isset($this->properties[ $class_name ])) { |
|
245 | - $reflection_class = $this->getReflectionClass($class_name); |
|
246 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
247 | - } |
|
248 | - return $this->properties[ $class_name ]; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param ReflectionClass $reflection_class |
|
254 | - * @return ReflectionProperty[] |
|
255 | - * @throws InvalidDataTypeException |
|
256 | - * @throws ReflectionException |
|
257 | - */ |
|
258 | - public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
259 | - { |
|
260 | - return $this->getProperties($reflection_class->getName()); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $class_name |
|
266 | - * @return ReflectionMethod[] |
|
267 | - * @throws InvalidDataTypeException |
|
268 | - * @throws ReflectionException |
|
269 | - */ |
|
270 | - public function getMethods($class_name) |
|
271 | - { |
|
272 | - if (! isset($this->methods[ $class_name ])) { |
|
273 | - $reflection_class = $this->getReflectionClass($class_name); |
|
274 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
275 | - } |
|
276 | - return $this->methods[ $class_name ]; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * @param ReflectionClass $reflection_class ) |
|
282 | - * @return ReflectionMethod[] |
|
283 | - * @throws InvalidDataTypeException |
|
284 | - * @throws ReflectionException |
|
285 | - */ |
|
286 | - public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
287 | - { |
|
288 | - return $this->getMethods($reflection_class->getName()); |
|
289 | - } |
|
24 | + /** |
|
25 | + * @var ReflectionClass[] $classes |
|
26 | + */ |
|
27 | + private $classes = []; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ReflectionMethod[] $constructors |
|
31 | + */ |
|
32 | + private $constructors = []; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var ReflectionParameter[][] $parameters |
|
36 | + */ |
|
37 | + private $parameters = []; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var ReflectionParameter[][] $parameters |
|
41 | + */ |
|
42 | + private $parameter_classes = []; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var ReflectionProperty[][] $properties |
|
46 | + */ |
|
47 | + private $properties = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var ReflectionMethod[][] $methods |
|
51 | + */ |
|
52 | + private $methods = []; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $class_name |
|
57 | + * @return ReflectionClass |
|
58 | + * @throws ReflectionException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | + public function getReflectionClass($class_name) |
|
62 | + { |
|
63 | + if (! is_string($class_name)) { |
|
64 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | + } |
|
66 | + if (! isset($this->classes[ $class_name ])) { |
|
67 | + $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | + } |
|
69 | + return $this->classes[ $class_name ]; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $class_name |
|
75 | + * @return ReflectionMethod |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function getConstructor($class_name) |
|
80 | + { |
|
81 | + if (! is_string($class_name)) { |
|
82 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | + } |
|
84 | + if (! isset($this->constructors[ $class_name ])) { |
|
85 | + $reflection_class = $this->getReflectionClass($class_name); |
|
86 | + $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | + } |
|
88 | + return $this->constructors[ $class_name ]; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param ReflectionClass $reflection_class |
|
94 | + * @return ReflectionMethod |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | + { |
|
100 | + return $this->getConstructor($reflection_class->getName()); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $class_name |
|
106 | + * @return ReflectionParameter[] |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public function getParameters($class_name) |
|
111 | + { |
|
112 | + if (! isset($this->parameters[ $class_name ])) { |
|
113 | + $constructor = $this->getConstructor($class_name); |
|
114 | + $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | + } |
|
116 | + return $this->parameters[ $class_name ]; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param ReflectionClass $reflection_class |
|
122 | + * @return ReflectionParameter[] |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + * @throws ReflectionException |
|
125 | + */ |
|
126 | + public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | + { |
|
128 | + return $this->getParameters($reflection_class->getName()); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param ReflectionMethod $constructor |
|
134 | + * @return ReflectionParameter[] |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | + { |
|
140 | + return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param ReflectionParameter $param |
|
146 | + * @param string $class_name |
|
147 | + * @param string $index |
|
148 | + * @return string|null |
|
149 | + */ |
|
150 | + public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
151 | + { |
|
152 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
154 | + } |
|
155 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | + $this->parameter_classes[ $class_name ] = []; |
|
157 | + } |
|
158 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
160 | + } |
|
161 | + // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
162 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | + ? $this->getParameterClassNameLegacy($param) |
|
164 | + : $this->getParameterClassNamePhp8($param); |
|
165 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param ReflectionParameter $param |
|
171 | + * @return string|null |
|
172 | + * @since 4.10.13.p |
|
173 | + */ |
|
174 | + private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
175 | + { |
|
176 | + $reflection_class = $param->getClass(); |
|
177 | + return $reflection_class instanceof ReflectionClass |
|
178 | + ? $param->getClass()->getName() |
|
179 | + : null; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
185 | + * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
186 | + * which can either be a ReflectionNamedType or ReflectionUnionType |
|
187 | + * |
|
188 | + * @param ReflectionParameter $param |
|
189 | + * @return null |
|
190 | + * @since 4.10.13.p |
|
191 | + */ |
|
192 | + private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
193 | + { |
|
194 | + $reflection_type = $param->getType(); |
|
195 | + |
|
196 | + if ($reflection_type instanceof \ReflectionNamedType) { |
|
197 | + return $reflection_type->getName(); |
|
198 | + } |
|
199 | + |
|
200 | + if ($reflection_type instanceof \ReflectionUnionType) { |
|
201 | + $reflection_types = $reflection_type->getTypes(); |
|
202 | + if (is_array($reflection_types)) { |
|
203 | + $first = reset($reflection_types); |
|
204 | + return $first->getName(); |
|
205 | + } |
|
206 | + } |
|
207 | + return null; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param ReflectionParameter $param |
|
213 | + * @param string $class_name |
|
214 | + * @param string $index |
|
215 | + * @return string|null |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
219 | + { |
|
220 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
222 | + } |
|
223 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | + $this->parameter_classes[ $class_name ] = []; |
|
225 | + } |
|
226 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
228 | + } |
|
229 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | + ? $param->getDefaultValue() |
|
231 | + : null; |
|
232 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param string $class_name |
|
238 | + * @return ReflectionProperty[] |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws ReflectionException |
|
241 | + */ |
|
242 | + public function getProperties($class_name) |
|
243 | + { |
|
244 | + if (! isset($this->properties[ $class_name ])) { |
|
245 | + $reflection_class = $this->getReflectionClass($class_name); |
|
246 | + $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
247 | + } |
|
248 | + return $this->properties[ $class_name ]; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param ReflectionClass $reflection_class |
|
254 | + * @return ReflectionProperty[] |
|
255 | + * @throws InvalidDataTypeException |
|
256 | + * @throws ReflectionException |
|
257 | + */ |
|
258 | + public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
259 | + { |
|
260 | + return $this->getProperties($reflection_class->getName()); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $class_name |
|
266 | + * @return ReflectionMethod[] |
|
267 | + * @throws InvalidDataTypeException |
|
268 | + * @throws ReflectionException |
|
269 | + */ |
|
270 | + public function getMethods($class_name) |
|
271 | + { |
|
272 | + if (! isset($this->methods[ $class_name ])) { |
|
273 | + $reflection_class = $this->getReflectionClass($class_name); |
|
274 | + $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
275 | + } |
|
276 | + return $this->methods[ $class_name ]; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * @param ReflectionClass $reflection_class ) |
|
282 | + * @return ReflectionMethod[] |
|
283 | + * @throws InvalidDataTypeException |
|
284 | + * @throws ReflectionException |
|
285 | + */ |
|
286 | + public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
287 | + { |
|
288 | + return $this->getMethods($reflection_class->getName()); |
|
289 | + } |
|
290 | 290 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getReflectionClass($class_name) |
62 | 62 | { |
63 | - if (! is_string($class_name)) { |
|
63 | + if ( ! is_string($class_name)) { |
|
64 | 64 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
65 | 65 | } |
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
66 | + if ( ! isset($this->classes[$class_name])) { |
|
67 | + $this->classes[$class_name] = new ReflectionClass($class_name); |
|
68 | 68 | } |
69 | - return $this->classes[ $class_name ]; |
|
69 | + return $this->classes[$class_name]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getConstructor($class_name) |
80 | 80 | { |
81 | - if (! is_string($class_name)) { |
|
81 | + if ( ! is_string($class_name)) { |
|
82 | 82 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
83 | 83 | } |
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
84 | + if ( ! isset($this->constructors[$class_name])) { |
|
85 | 85 | $reflection_class = $this->getReflectionClass($class_name); |
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | + $this->constructors[$class_name] = $reflection_class->getConstructor(); |
|
87 | 87 | } |
88 | - return $this->constructors[ $class_name ]; |
|
88 | + return $this->constructors[$class_name]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getParameters($class_name) |
111 | 111 | { |
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
112 | + if ( ! isset($this->parameters[$class_name])) { |
|
113 | 113 | $constructor = $this->getConstructor($class_name); |
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | + $this->parameters[$class_name] = $constructor->getParameters(); |
|
115 | 115 | } |
116 | - return $this->parameters[ $class_name ]; |
|
116 | + return $this->parameters[$class_name]; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
151 | 151 | { |
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
152 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
154 | 154 | } |
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = []; |
|
155 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
156 | + $this->parameter_classes[$class_name] = []; |
|
157 | 157 | } |
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
158 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
159 | + $this->parameter_classes[$class_name][$index] = []; |
|
160 | 160 | } |
161 | 161 | // ReflectionParameter::getClass() is deprecated in PHP 8+ |
162 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
162 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | 163 | ? $this->getParameterClassNameLegacy($param) |
164 | 164 | : $this->getParameterClassNamePhp8($param); |
165 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
165 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -217,19 +217,19 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
219 | 219 | { |
220 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
220 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) { |
|
221 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
222 | 222 | } |
223 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | - $this->parameter_classes[ $class_name ] = []; |
|
223 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
224 | + $this->parameter_classes[$class_name] = []; |
|
225 | 225 | } |
226 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
226 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
227 | + $this->parameter_classes[$class_name][$index] = []; |
|
228 | 228 | } |
229 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
229 | + $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | 230 | ? $param->getDefaultValue() |
231 | 231 | : null; |
232 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
232 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function getProperties($class_name) |
243 | 243 | { |
244 | - if (! isset($this->properties[ $class_name ])) { |
|
244 | + if ( ! isset($this->properties[$class_name])) { |
|
245 | 245 | $reflection_class = $this->getReflectionClass($class_name); |
246 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
246 | + $this->properties[$class_name] = $reflection_class->getProperties(); |
|
247 | 247 | } |
248 | - return $this->properties[ $class_name ]; |
|
248 | + return $this->properties[$class_name]; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function getMethods($class_name) |
271 | 271 | { |
272 | - if (! isset($this->methods[ $class_name ])) { |
|
272 | + if ( ! isset($this->methods[$class_name])) { |
|
273 | 273 | $reflection_class = $this->getReflectionClass($class_name); |
274 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
274 | + $this->methods[$class_name] = $reflection_class->getMethods(); |
|
275 | 275 | } |
276 | - return $this->methods[ $class_name ]; |
|
276 | + return $this->methods[$class_name]; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 |
@@ -22,1237 +22,1237 @@ |
||
22 | 22 | class EE_Register_Addon implements EEI_Plugin_API |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * possibly truncated version of the EE core version string |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected static $_core_version = ''; |
|
31 | - |
|
32 | - /** |
|
33 | - * Holds values for registered addons |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected static $_settings = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | - * EE core with knowledge of ALL the addons out there. |
|
45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | - * minimum plugin version. |
|
49 | - * @access protected |
|
50 | - */ |
|
51 | - protected static $_incompatible_addons = array( |
|
52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | - 'Promotions' => '1.0.0.rc.084', |
|
54 | - ); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | - * not just '4.3.0'. |
|
60 | - * So if the addon developer doesn't provide that full version string, |
|
61 | - * fill in the blanks for them |
|
62 | - * |
|
63 | - * @param string $min_core_version |
|
64 | - * @return string always like '4.3.0.rc.000' |
|
65 | - */ |
|
66 | - protected static function _effective_version($min_core_version) |
|
67 | - { |
|
68 | - // versions: 4 . 3 . 1 . p . 123 |
|
69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | - $version_parts = explode('.', $min_core_version); |
|
71 | - // check they specified the micro version (after 2nd period) |
|
72 | - if (! isset($version_parts[2])) { |
|
73 | - $version_parts[2] = '0'; |
|
74 | - } |
|
75 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | - if (! isset($version_parts[3])) { |
|
78 | - $version_parts[3] = 'dev'; |
|
79 | - } |
|
80 | - if (! isset($version_parts[4])) { |
|
81 | - $version_parts[4] = '000'; |
|
82 | - } |
|
83 | - return implode('.', $version_parts); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns whether or not the min core version requirement of the addon is met |
|
89 | - * |
|
90 | - * @param string $min_core_version the minimum core version required by the addon |
|
91 | - * @param string $actual_core_version the actual core version, optional |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public static function _meets_min_core_version_requirement( |
|
95 | - $min_core_version, |
|
96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | - ) { |
|
98 | - return version_compare( |
|
99 | - self::_effective_version($actual_core_version), |
|
100 | - self::_effective_version($min_core_version), |
|
101 | - '>=' |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Method for registering new EE_Addons. |
|
108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | - * |
|
117 | - * @since 4.3.0 |
|
118 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | - * @param array $setup_args { |
|
120 | - * An array of arguments provided for registering |
|
121 | - * the message type. |
|
122 | - * @type string $class_name the addon's main file name. |
|
123 | - * If left blank, generated from the addon name, |
|
124 | - * changes something like "calendar" to |
|
125 | - * "EE_Calendar" |
|
126 | - * @type string $min_core_version the minimum version of EE Core that the |
|
127 | - * addon will work with. eg "4.8.1.rc.084" |
|
128 | - * @type string $version the "software" version for the addon. eg |
|
129 | - * "1.0.0.p" for a first stable release, or |
|
130 | - * "1.0.0.rc.043" for a version in progress |
|
131 | - * @type string $main_file_path the full server path to the main file |
|
132 | - * loaded directly by WP |
|
133 | - * @type DomainInterface $domain child class of |
|
134 | - * EventEspresso\core\domain\DomainBase |
|
135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | - * for the addon's Domain class |
|
137 | - * (see EventEspresso\core\domain\Domain) |
|
138 | - * @type string $admin_path full server path to the folder where the |
|
139 | - * addon\'s admin files reside |
|
140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | - * first invoked, can be used for hooking into |
|
142 | - * any admin page |
|
143 | - * @type string $config_section the section name for this addon's |
|
144 | - * configuration settings section |
|
145 | - * (defaults to "addons") |
|
146 | - * @type string $config_class the class name for this addon's |
|
147 | - * configuration settings object |
|
148 | - * @type string $config_name the class name for this addon's |
|
149 | - * configuration settings object |
|
150 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | - * server paths to those files. |
|
152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | - * folders containing classes that might be |
|
154 | - * invoked by the addon |
|
155 | - * @type string $dms_paths [Required] an array of full server paths to |
|
156 | - * folders that contain data migration scripts. |
|
157 | - * The key should be the EE_Addon class name that |
|
158 | - * this set of data migration scripts belongs to. |
|
159 | - * If the EE_Addon class is namespaced, then this |
|
160 | - * needs to be the Fully Qualified Class Name |
|
161 | - * @type string $module_paths an array of full server paths to any |
|
162 | - * EED_Modules used by the addon |
|
163 | - * @type string $shortcode_paths an array of full server paths to folders |
|
164 | - * that contain EES_Shortcodes |
|
165 | - * @type string $widget_paths an array of full server paths to folders |
|
166 | - * that contain WP_Widgets |
|
167 | - * @type string $pue_options |
|
168 | - * @type array $capabilities an array indexed by role name |
|
169 | - * (i.e administrator,author ) and the values |
|
170 | - * are an array of caps to add to the role. |
|
171 | - * 'administrator' => array( |
|
172 | - * 'read_addon', |
|
173 | - * 'edit_addon', |
|
174 | - * etc. |
|
175 | - * ). |
|
176 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | - * for any addons that need to register any |
|
178 | - * special meta mapped capabilities. Should |
|
179 | - * be indexed where the key is the |
|
180 | - * EE_Meta_Capability_Map class name and the |
|
181 | - * values are the arguments sent to the class. |
|
182 | - * @type array $model_paths array of folders containing DB models |
|
183 | - * @see EE_Register_Model |
|
184 | - * @type array $class_paths array of folders containing DB classes |
|
185 | - * @see EE_Register_Model |
|
186 | - * @type array $model_extension_paths array of folders containing DB model |
|
187 | - * extensions |
|
188 | - * @see EE_Register_Model_Extension |
|
189 | - * @type array $class_extension_paths array of folders containing DB class |
|
190 | - * extensions |
|
191 | - * @see EE_Register_Model_Extension |
|
192 | - * @type array message_types { |
|
193 | - * An array of message types with the key as |
|
194 | - * the message type name and the values as |
|
195 | - * below: |
|
196 | - * @type string $mtfilename [Required] The filename of the message type |
|
197 | - * being registered. This will be the main |
|
198 | - * EE_{Message Type Name}_message_type class. |
|
199 | - * for example: |
|
200 | - * EE_Declined_Registration_message_type.class.php |
|
201 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | - * messages autoloader for the new message type. |
|
203 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | - * type should activate with. Each value in |
|
205 | - * the |
|
206 | - * array |
|
207 | - * should match the name property of a |
|
208 | - * EE_messenger. Optional. |
|
209 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | - * type should validate with. Each value in |
|
211 | - * the |
|
212 | - * array |
|
213 | - * should match the name property of an |
|
214 | - * EE_messenger. |
|
215 | - * Optional. |
|
216 | - * } |
|
217 | - * @type array $custom_post_types |
|
218 | - * @type array $custom_taxonomies |
|
219 | - * @type array $payment_method_paths each element is the folder containing the |
|
220 | - * EE_PMT_Base child class |
|
221 | - * (eg, |
|
222 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | - * which contains the files |
|
224 | - * EE_PMT_Payomatic.pm.php) |
|
225 | - * @type array $default_terms |
|
226 | - * @type array $namespace { |
|
227 | - * An array with two items for registering the |
|
228 | - * addon's namespace. (If, for some reason, you |
|
229 | - * require additional namespaces, |
|
230 | - * use |
|
231 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | - * directly) |
|
233 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | - * @type string $FQNS the namespace prefix |
|
235 | - * @type string $DIR a base directory for class files in the |
|
236 | - * namespace. |
|
237 | - * } |
|
238 | - * } |
|
239 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | - * privacy policy classes) or FQCNs (specific |
|
241 | - * classnames of privacy policy classes) |
|
242 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | - * privacy policy classes) or FQCNs (specific |
|
244 | - * classnames of privacy policy classes) |
|
245 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | - * privacy policy classes) or FQCNs (specific |
|
247 | - * classnames of privacy policy classes) |
|
248 | - * @return void |
|
249 | - * @throws DomainException |
|
250 | - * @throws EE_Error |
|
251 | - * @throws InvalidArgumentException |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws InvalidInterfaceException |
|
254 | - */ |
|
255 | - public static function register($addon_name = '', array $setup_args = array()) |
|
256 | - { |
|
257 | - // required fields MUST be present, so let's make sure they are. |
|
258 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
259 | - // get class name for addon |
|
260 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
261 | - // setup $_settings array from incoming values. |
|
262 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
263 | - // setup PUE |
|
264 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
265 | - // does this addon work with this version of core or WordPress ? |
|
266 | - // does this addon work with this version of core or WordPress ? |
|
267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | - return; |
|
269 | - } |
|
270 | - // register namespaces |
|
271 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | - // check if this is an activation request |
|
273 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | - // dont bother setting up the rest of the addon atm |
|
275 | - return; |
|
276 | - } |
|
277 | - // we need cars |
|
278 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | - // register new models and extensions |
|
280 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | - // setup DMS |
|
282 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | - // if config_class is present let's register config. |
|
284 | - EE_Register_Addon::_register_config($addon_name); |
|
285 | - // register admin pages |
|
286 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | - // add to list of modules to be registered |
|
288 | - EE_Register_Addon::_register_modules($addon_name); |
|
289 | - // add to list of shortcodes to be registered |
|
290 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | - // add to list of widgets to be registered |
|
292 | - EE_Register_Addon::_register_widgets($addon_name); |
|
293 | - // register capability related stuff. |
|
294 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | - // any message type to register? |
|
296 | - EE_Register_Addon::_register_message_types($addon_name); |
|
297 | - // any custom post type/ custom capabilities or default terms to register |
|
298 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | - // and any payment methods |
|
300 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | - // and privacy policy generators |
|
302 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | - // and privacy policy generators |
|
304 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | - // and privacy policy generators |
|
306 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | - // load and instantiate main addon class |
|
308 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $addon_name |
|
316 | - * @param array $setup_args |
|
317 | - * @return void |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - // required fields MUST be present, so let's make sure they are. |
|
323 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | - throw new EE_Error( |
|
325 | - __( |
|
326 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | - 'event_espresso' |
|
328 | - ) |
|
329 | - ); |
|
330 | - } |
|
331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | - throw new EE_Error( |
|
333 | - sprintf( |
|
334 | - __( |
|
335 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - implode(',', array_keys($setup_args)) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - // check that addon has not already been registered with that name |
|
343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | - throw new EE_Error( |
|
345 | - sprintf( |
|
346 | - __( |
|
347 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - $addon_name |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $addon_name |
|
359 | - * @param array $setup_args |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | - { |
|
364 | - if (empty($setup_args['class_name'])) { |
|
365 | - // generate one by first separating name with spaces |
|
366 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | - // capitalize, then replace spaces with underscores |
|
368 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | - } else { |
|
370 | - $class_name = $setup_args['class_name']; |
|
371 | - } |
|
372 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | - ? $class_name |
|
375 | - : 'EE_' . $class_name; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @param string $class_name |
|
381 | - * @param array $setup_args |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | - { |
|
386 | - // setup $_settings array from incoming values. |
|
387 | - $addon_settings = array( |
|
388 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | - 'class_name' => $class_name, |
|
390 | - // the addon slug for use in URLs, etc |
|
391 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | - ? (string) $setup_args['plugin_slug'] |
|
393 | - : '', |
|
394 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | - ? (string) $setup_args['plugin_action_slug'] |
|
397 | - : '', |
|
398 | - // the "software" version for the addon |
|
399 | - 'version' => isset($setup_args['version']) |
|
400 | - ? (string) $setup_args['version'] |
|
401 | - : '', |
|
402 | - // the minimum version of EE Core that the addon will work with |
|
403 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | - ? (string) $setup_args['min_core_version'] |
|
405 | - : '', |
|
406 | - // the minimum version of WordPress that the addon will work with |
|
407 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | - ? (string) $setup_args['min_wp_version'] |
|
409 | - : EE_MIN_WP_VER_REQUIRED, |
|
410 | - // full server path to main file (file loaded directly by WP) |
|
411 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | - ? (string) $setup_args['main_file_path'] |
|
413 | - : '', |
|
414 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | - ? $setup_args['domain'] |
|
417 | - : null, |
|
418 | - // Fully Qualified Class Name for the addon's Domain class |
|
419 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | - ? (string) $setup_args['domain_fqcn'] |
|
421 | - : '', |
|
422 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | - 'admin_path' => isset($setup_args['admin_path']) |
|
424 | - ? (string) $setup_args['admin_path'] : '', |
|
425 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | - ? (string) $setup_args['admin_callback'] |
|
428 | - : '', |
|
429 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | - 'config_section' => isset($setup_args['config_section']) |
|
431 | - ? (string) $setup_args['config_section'] |
|
432 | - : 'addons', |
|
433 | - // the class name for this addon's configuration settings object |
|
434 | - 'config_class' => isset($setup_args['config_class']) |
|
435 | - ? (string) $setup_args['config_class'] : '', |
|
436 | - // the name given to the config for this addons' configuration settings object (optional) |
|
437 | - 'config_name' => isset($setup_args['config_name']) |
|
438 | - ? (string) $setup_args['config_name'] : '', |
|
439 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | - ? (array) $setup_args['autoloader_paths'] |
|
442 | - : array(), |
|
443 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | - ? (array) $setup_args['autoloader_folders'] |
|
446 | - : array(), |
|
447 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | - ? (array) $setup_args['dms_paths'] |
|
452 | - : array(), |
|
453 | - // array of full server paths to any EED_Modules used by the addon |
|
454 | - 'module_paths' => isset($setup_args['module_paths']) |
|
455 | - ? (array) $setup_args['module_paths'] |
|
456 | - : array(), |
|
457 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | - ? (array) $setup_args['shortcode_paths'] |
|
460 | - : array(), |
|
461 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | - ? (array) $setup_args['shortcode_fqcns'] |
|
463 | - : array(), |
|
464 | - // array of full server paths to any WP_Widgets used by the addon |
|
465 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | - ? (array) $setup_args['widget_paths'] |
|
467 | - : array(), |
|
468 | - // array of PUE options used by the addon |
|
469 | - 'pue_options' => isset($setup_args['pue_options']) |
|
470 | - ? (array) $setup_args['pue_options'] |
|
471 | - : array(), |
|
472 | - 'message_types' => isset($setup_args['message_types']) |
|
473 | - ? (array) $setup_args['message_types'] |
|
474 | - : array(), |
|
475 | - 'capabilities' => isset($setup_args['capabilities']) |
|
476 | - ? (array) $setup_args['capabilities'] |
|
477 | - : array(), |
|
478 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | - ? (array) $setup_args['capability_maps'] |
|
480 | - : array(), |
|
481 | - 'model_paths' => isset($setup_args['model_paths']) |
|
482 | - ? (array) $setup_args['model_paths'] |
|
483 | - : array(), |
|
484 | - 'class_paths' => isset($setup_args['class_paths']) |
|
485 | - ? (array) $setup_args['class_paths'] |
|
486 | - : array(), |
|
487 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | - ? (array) $setup_args['model_extension_paths'] |
|
489 | - : array(), |
|
490 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | - ? (array) $setup_args['class_extension_paths'] |
|
492 | - : array(), |
|
493 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | - ? (array) $setup_args['custom_post_types'] |
|
495 | - : array(), |
|
496 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | - ? (array) $setup_args['custom_taxonomies'] |
|
498 | - : array(), |
|
499 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | - ? (array) $setup_args['payment_method_paths'] |
|
501 | - : array(), |
|
502 | - 'default_terms' => isset($setup_args['default_terms']) |
|
503 | - ? (array) $setup_args['default_terms'] |
|
504 | - : array(), |
|
505 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | - // that can be used for adding upgrading/marketing info |
|
507 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
508 | - 'namespace' => isset( |
|
509 | - $setup_args['namespace']['FQNS'], |
|
510 | - $setup_args['namespace']['DIR'] |
|
511 | - ) |
|
512 | - ? (array) $setup_args['namespace'] |
|
513 | - : array(), |
|
514 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
515 | - ? (array) $setup_args['privacy_policies'] |
|
516 | - : '', |
|
517 | - ); |
|
518 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
519 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
520 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
521 | - && ! empty($addon_settings['admin_path']) |
|
522 | - ? $addon_settings['plugin_slug'] |
|
523 | - : $addon_settings['plugin_action_slug']; |
|
524 | - // full server path to main file (file loaded directly by WP) |
|
525 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
526 | - return $addon_settings; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param string $addon_name |
|
532 | - * @param array $addon_settings |
|
533 | - * @return boolean |
|
534 | - */ |
|
535 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
536 | - { |
|
537 | - global $wp_version; |
|
538 | - $incompatibility_message = ''; |
|
539 | - // check whether this addon version is compatible with EE core |
|
540 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
541 | - && ! self::_meets_min_core_version_requirement( |
|
542 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
543 | - $addon_settings['version'] |
|
544 | - ) |
|
545 | - ) { |
|
546 | - $incompatibility_message = sprintf( |
|
547 | - __( |
|
548 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
549 | - 'event_espresso' |
|
550 | - ), |
|
551 | - $addon_name, |
|
552 | - '<br />', |
|
553 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
554 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
555 | - '</span><br />' |
|
556 | - ); |
|
557 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
558 | - ) { |
|
559 | - $incompatibility_message = sprintf( |
|
560 | - __( |
|
561 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
562 | - 'event_espresso' |
|
563 | - ), |
|
564 | - $addon_name, |
|
565 | - self::_effective_version($addon_settings['min_core_version']), |
|
566 | - self::_effective_version(espresso_version()), |
|
567 | - '<br />', |
|
568 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
569 | - '</span><br />' |
|
570 | - ); |
|
571 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
572 | - $incompatibility_message = sprintf( |
|
573 | - __( |
|
574 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
575 | - 'event_espresso' |
|
576 | - ), |
|
577 | - $addon_name, |
|
578 | - $addon_settings['min_wp_version'], |
|
579 | - '<br />', |
|
580 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
581 | - '</span><br />' |
|
582 | - ); |
|
583 | - } |
|
584 | - if (! empty($incompatibility_message)) { |
|
585 | - // remove 'activate' from the REQUEST |
|
586 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
587 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
588 | - if (current_user_can('activate_plugins')) { |
|
589 | - // show an error message indicating the plugin didn't activate properly |
|
590 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
591 | - } |
|
592 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
593 | - return false; |
|
594 | - } |
|
595 | - // addon IS compatible |
|
596 | - return true; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * if plugin update engine is being used for auto-updates, |
|
602 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
603 | - * (not needed if PUE is not being used) |
|
604 | - * |
|
605 | - * @param string $addon_name |
|
606 | - * @param string $class_name |
|
607 | - * @param array $setup_args |
|
608 | - * @return void |
|
609 | - */ |
|
610 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
611 | - { |
|
612 | - if (! empty($setup_args['pue_options'])) { |
|
613 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
614 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
615 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
616 | - : 'espresso_' . strtolower($class_name), |
|
617 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
618 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
619 | - : plugin_basename($setup_args['main_file_path']), |
|
620 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
621 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
622 | - : '24', |
|
623 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
624 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
625 | - : false, |
|
626 | - ); |
|
627 | - add_action( |
|
628 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
629 | - array('EE_Register_Addon', 'load_pue_update') |
|
630 | - ); |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
637 | - * |
|
638 | - * @param array $addon_settings |
|
639 | - * @return void |
|
640 | - */ |
|
641 | - private static function _setup_namespaces(array $addon_settings) |
|
642 | - { |
|
643 | - // |
|
644 | - if (isset( |
|
645 | - $addon_settings['namespace']['FQNS'], |
|
646 | - $addon_settings['namespace']['DIR'] |
|
647 | - )) { |
|
648 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
649 | - $addon_settings['namespace']['FQNS'], |
|
650 | - $addon_settings['namespace']['DIR'] |
|
651 | - ); |
|
652 | - } |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @param string $addon_name |
|
658 | - * @param array $addon_settings |
|
659 | - * @return bool |
|
660 | - * @throws InvalidArgumentException |
|
661 | - * @throws InvalidDataTypeException |
|
662 | - * @throws InvalidInterfaceException |
|
663 | - */ |
|
664 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
665 | - { |
|
666 | - // this is an activation request |
|
667 | - if (did_action('activate_plugin')) { |
|
668 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
669 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
670 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
671 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
672 | - if (! isset(self::$_settings[ $addon_name ]) |
|
673 | - || (isset(self::$_settings[ $addon_name ]) |
|
674 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
675 | - ) |
|
676 | - ) { |
|
677 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
678 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
679 | - $addon->set_activation_indicator_option(); |
|
680 | - // dont bother setting up the rest of the addon. |
|
681 | - // we know it was just activated and the request will end soon |
|
682 | - } |
|
683 | - return true; |
|
684 | - } |
|
685 | - // make sure this was called in the right place! |
|
686 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
687 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
688 | - ) { |
|
689 | - EE_Error::doing_it_wrong( |
|
690 | - __METHOD__, |
|
691 | - sprintf( |
|
692 | - __( |
|
693 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
694 | - 'event_espresso' |
|
695 | - ), |
|
696 | - $addon_name |
|
697 | - ), |
|
698 | - '4.3.0' |
|
699 | - ); |
|
700 | - } |
|
701 | - // make sure addon settings are set correctly without overwriting anything existing |
|
702 | - if (isset(self::$_settings[ $addon_name ])) { |
|
703 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | - } else { |
|
705 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | - } |
|
707 | - return false; |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * @param string $addon_name |
|
713 | - * @return void |
|
714 | - * @throws EE_Error |
|
715 | - */ |
|
716 | - private static function _setup_autoloaders($addon_name) |
|
717 | - { |
|
718 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | - // setup autoloader for single file |
|
720 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | - } |
|
722 | - // setup autoloaders for folders |
|
723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | - } |
|
727 | - } |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * register new models and extensions |
|
733 | - * |
|
734 | - * @param string $addon_name |
|
735 | - * @return void |
|
736 | - * @throws EE_Error |
|
737 | - */ |
|
738 | - private static function _register_models_and_extensions($addon_name) |
|
739 | - { |
|
740 | - // register new models |
|
741 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
742 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
743 | - ) { |
|
744 | - EE_Register_Model::register( |
|
745 | - $addon_name, |
|
746 | - array( |
|
747 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
748 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
749 | - ) |
|
750 | - ); |
|
751 | - } |
|
752 | - // register model extensions |
|
753 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
754 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
755 | - ) { |
|
756 | - EE_Register_Model_Extensions::register( |
|
757 | - $addon_name, |
|
758 | - array( |
|
759 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
760 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
761 | - ) |
|
762 | - ); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * @param string $addon_name |
|
769 | - * @return void |
|
770 | - * @throws EE_Error |
|
771 | - */ |
|
772 | - private static function _register_data_migration_scripts($addon_name) |
|
773 | - { |
|
774 | - // setup DMS |
|
775 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
776 | - EE_Register_Data_Migration_Scripts::register( |
|
777 | - $addon_name, |
|
778 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
779 | - ); |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - |
|
784 | - /** |
|
785 | - * @param string $addon_name |
|
786 | - * @return void |
|
787 | - * @throws EE_Error |
|
788 | - */ |
|
789 | - private static function _register_config($addon_name) |
|
790 | - { |
|
791 | - // if config_class is present let's register config. |
|
792 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
793 | - EE_Register_Config::register( |
|
794 | - self::$_settings[ $addon_name ]['config_class'], |
|
795 | - array( |
|
796 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
797 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
798 | - ) |
|
799 | - ); |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * @param string $addon_name |
|
806 | - * @return void |
|
807 | - * @throws EE_Error |
|
808 | - */ |
|
809 | - private static function _register_admin_pages($addon_name) |
|
810 | - { |
|
811 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
812 | - EE_Register_Admin_Page::register( |
|
813 | - $addon_name, |
|
814 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
815 | - ); |
|
816 | - } |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * @param string $addon_name |
|
822 | - * @return void |
|
823 | - * @throws EE_Error |
|
824 | - */ |
|
825 | - private static function _register_modules($addon_name) |
|
826 | - { |
|
827 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
828 | - EE_Register_Module::register( |
|
829 | - $addon_name, |
|
830 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
831 | - ); |
|
832 | - } |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * @param string $addon_name |
|
838 | - * @return void |
|
839 | - * @throws EE_Error |
|
840 | - */ |
|
841 | - private static function _register_shortcodes($addon_name) |
|
842 | - { |
|
843 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
844 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
845 | - ) { |
|
846 | - EE_Register_Shortcode::register( |
|
847 | - $addon_name, |
|
848 | - array( |
|
849 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
850 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
851 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
852 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
853 | - ) |
|
854 | - ); |
|
855 | - } |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * @param string $addon_name |
|
861 | - * @return void |
|
862 | - * @throws EE_Error |
|
863 | - */ |
|
864 | - private static function _register_widgets($addon_name) |
|
865 | - { |
|
866 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
867 | - EE_Register_Widget::register( |
|
868 | - $addon_name, |
|
869 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
870 | - ); |
|
871 | - } |
|
872 | - } |
|
873 | - |
|
874 | - |
|
875 | - /** |
|
876 | - * @param string $addon_name |
|
877 | - * @return void |
|
878 | - * @throws EE_Error |
|
879 | - */ |
|
880 | - private static function _register_capabilities($addon_name) |
|
881 | - { |
|
882 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
883 | - EE_Register_Capabilities::register( |
|
884 | - $addon_name, |
|
885 | - array( |
|
886 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
887 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
888 | - ) |
|
889 | - ); |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * @param string $addon_name |
|
896 | - * @return void |
|
897 | - */ |
|
898 | - private static function _register_message_types($addon_name) |
|
899 | - { |
|
900 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
901 | - add_action( |
|
902 | - 'EE_Brewing_Regular___messages_caf', |
|
903 | - array('EE_Register_Addon', 'register_message_types') |
|
904 | - ); |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param string $addon_name |
|
911 | - * @return void |
|
912 | - * @throws EE_Error |
|
913 | - */ |
|
914 | - private static function _register_custom_post_types($addon_name) |
|
915 | - { |
|
916 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
917 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
918 | - ) { |
|
919 | - EE_Register_CPT::register( |
|
920 | - $addon_name, |
|
921 | - array( |
|
922 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
923 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
924 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
925 | - ) |
|
926 | - ); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * @param string $addon_name |
|
933 | - * @return void |
|
934 | - * @throws InvalidArgumentException |
|
935 | - * @throws InvalidInterfaceException |
|
936 | - * @throws InvalidDataTypeException |
|
937 | - * @throws DomainException |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - private static function _register_payment_methods($addon_name) |
|
941 | - { |
|
942 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
943 | - EE_Register_Payment_Method::register( |
|
944 | - $addon_name, |
|
945 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
946 | - ); |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * @param string $addon_name |
|
953 | - * @return void |
|
954 | - * @throws InvalidArgumentException |
|
955 | - * @throws InvalidInterfaceException |
|
956 | - * @throws InvalidDataTypeException |
|
957 | - * @throws DomainException |
|
958 | - */ |
|
959 | - private static function registerPrivacyPolicies($addon_name) |
|
960 | - { |
|
961 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
962 | - EE_Register_Privacy_Policy::register( |
|
963 | - $addon_name, |
|
964 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
965 | - ); |
|
966 | - } |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * @param string $addon_name |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - private static function registerPersonalDataExporters($addon_name) |
|
975 | - { |
|
976 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
977 | - EE_Register_Personal_Data_Eraser::register( |
|
978 | - $addon_name, |
|
979 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
980 | - ); |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @param string $addon_name |
|
987 | - * @return void |
|
988 | - */ |
|
989 | - private static function registerPersonalDataErasers($addon_name) |
|
990 | - { |
|
991 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
992 | - EE_Register_Personal_Data_Eraser::register( |
|
993 | - $addon_name, |
|
994 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
995 | - ); |
|
996 | - } |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - /** |
|
1001 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1002 | - * |
|
1003 | - * @param string $addon_name |
|
1004 | - * @return EE_Addon |
|
1005 | - * @throws InvalidArgumentException |
|
1006 | - * @throws InvalidInterfaceException |
|
1007 | - * @throws InvalidDataTypeException |
|
1008 | - */ |
|
1009 | - private static function _load_and_init_addon_class($addon_name) |
|
1010 | - { |
|
1011 | - $addon = LoaderFactory::getLoader()->getShared( |
|
1012 | - self::$_settings[ $addon_name ]['class_name'], |
|
1013 | - array('EE_Registry::create(addon)' => true) |
|
1014 | - ); |
|
1015 | - if (! $addon instanceof EE_Addon) { |
|
1016 | - throw new DomainException( |
|
1017 | - sprintf( |
|
1018 | - esc_html__( |
|
1019 | - 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
1020 | - 'event_espresso' |
|
1021 | - ), |
|
1022 | - $addon_name |
|
1023 | - ) |
|
1024 | - ); |
|
1025 | - } |
|
1026 | - // setter inject dep map if required |
|
1027 | - if ($addon->dependencyMap() === null) { |
|
1028 | - $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
1029 | - } |
|
1030 | - // setter inject domain if required |
|
1031 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1032 | - |
|
1033 | - $addon->set_name($addon_name); |
|
1034 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1035 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1036 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1037 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1038 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1039 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1040 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1041 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1042 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1043 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1044 | - // setup the add-on's pue_slug if we have one. |
|
1045 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1046 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1047 | - } |
|
1048 | - // unfortunately this can't be hooked in upon construction, |
|
1049 | - // because we don't have the plugin's mainfile path upon construction. |
|
1050 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1051 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1052 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1053 | - add_action( |
|
1054 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1055 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - return $addon; |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * @param string $addon_name |
|
1064 | - * @param EE_Addon $addon |
|
1065 | - * @since 4.10.13.p |
|
1066 | - */ |
|
1067 | - private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
1068 | - { |
|
1069 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1070 | - // using supplied Domain object |
|
1071 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1072 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1073 | - : null; |
|
1074 | - // or construct one using Domain FQCN |
|
1075 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1076 | - $domain = LoaderFactory::getLoader()->getShared( |
|
1077 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1078 | - [ |
|
1079 | - new EventEspresso\core\domain\values\FilePath( |
|
1080 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1081 | - ), |
|
1082 | - EventEspresso\core\domain\values\Version::fromString( |
|
1083 | - self::$_settings[ $addon_name ]['version'] |
|
1084 | - ), |
|
1085 | - ] |
|
1086 | - ); |
|
1087 | - } |
|
1088 | - if ($domain instanceof DomainInterface) { |
|
1089 | - $addon->setDomain($domain); |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * load_pue_update - Update notifications |
|
1097 | - * |
|
1098 | - * @return void |
|
1099 | - * @throws InvalidArgumentException |
|
1100 | - * @throws InvalidDataTypeException |
|
1101 | - * @throws InvalidInterfaceException |
|
1102 | - */ |
|
1103 | - public static function load_pue_update() |
|
1104 | - { |
|
1105 | - // load PUE client |
|
1106 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1107 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1108 | - // cycle thru settings |
|
1109 | - foreach (self::$_settings as $settings) { |
|
1110 | - if (! empty($settings['pue_options'])) { |
|
1111 | - // initiate the class and start the plugin update engine! |
|
1112 | - new PluginUpdateEngineChecker( |
|
1113 | - // host file URL |
|
1114 | - $license_server, |
|
1115 | - // plugin slug(s) |
|
1116 | - array( |
|
1117 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1118 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1119 | - ), |
|
1120 | - // options |
|
1121 | - array( |
|
1122 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1123 | - 'lang_domain' => 'event_espresso', |
|
1124 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1125 | - 'option_key' => 'ee_site_license_key', |
|
1126 | - 'options_page_slug' => 'event_espresso', |
|
1127 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1128 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1129 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1130 | - ) |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - } |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1139 | - * |
|
1140 | - * @since 4.4.0 |
|
1141 | - * @return void |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public static function register_message_types() |
|
1145 | - { |
|
1146 | - foreach (self::$_settings as $settings) { |
|
1147 | - if (! empty($settings['message_types'])) { |
|
1148 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1149 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1150 | - } |
|
1151 | - } |
|
1152 | - } |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1158 | - * |
|
1159 | - * @param string $addon_name the name for the addon that was previously registered |
|
1160 | - * @throws DomainException |
|
1161 | - * @throws InvalidArgumentException |
|
1162 | - * @throws InvalidDataTypeException |
|
1163 | - * @throws InvalidInterfaceException |
|
1164 | - *@since 4.3.0 |
|
1165 | - */ |
|
1166 | - public static function deregister($addon_name = '') |
|
1167 | - { |
|
1168 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1169 | - try { |
|
1170 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1171 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1172 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1173 | - // setup DMS |
|
1174 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1175 | - } |
|
1176 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1177 | - // register admin page |
|
1178 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1179 | - } |
|
1180 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1181 | - // add to list of modules to be registered |
|
1182 | - EE_Register_Module::deregister($addon_name); |
|
1183 | - } |
|
1184 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1185 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1186 | - ) { |
|
1187 | - // add to list of shortcodes to be registered |
|
1188 | - EE_Register_Shortcode::deregister($addon_name); |
|
1189 | - } |
|
1190 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1191 | - // if config_class present let's register config. |
|
1192 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1193 | - } |
|
1194 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1195 | - // add to list of widgets to be registered |
|
1196 | - EE_Register_Widget::deregister($addon_name); |
|
1197 | - } |
|
1198 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1199 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1200 | - ) { |
|
1201 | - // add to list of shortcodes to be registered |
|
1202 | - EE_Register_Model::deregister($addon_name); |
|
1203 | - } |
|
1204 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1205 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1206 | - ) { |
|
1207 | - // add to list of shortcodes to be registered |
|
1208 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1209 | - } |
|
1210 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1211 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1212 | - EE_Register_Message_Type::deregister($message_type); |
|
1213 | - } |
|
1214 | - } |
|
1215 | - // deregister capabilities for addon |
|
1216 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1217 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1218 | - ) { |
|
1219 | - EE_Register_Capabilities::deregister($addon_name); |
|
1220 | - } |
|
1221 | - // deregister custom_post_types for addon |
|
1222 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1223 | - EE_Register_CPT::deregister($addon_name); |
|
1224 | - } |
|
1225 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1226 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1227 | - } |
|
1228 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1229 | - if ($addon instanceof EE_Addon) { |
|
1230 | - remove_action( |
|
1231 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1232 | - array($addon, 'deactivation') |
|
1233 | - ); |
|
1234 | - remove_action( |
|
1235 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1236 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1237 | - ); |
|
1238 | - // remove `after_registration` call |
|
1239 | - remove_action( |
|
1240 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1241 | - array($addon, 'after_registration'), |
|
1242 | - 999 |
|
1243 | - ); |
|
1244 | - } |
|
1245 | - EE_Registry::instance()->removeAddon($class_name); |
|
1246 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1247 | - // the add-on was not yet registered in the registry, |
|
1248 | - // so RegistryContainer::__get() throws this exception. |
|
1249 | - // also no need to worry about this or log it, |
|
1250 | - // it's ok to deregister an add-on before its registered in the registry |
|
1251 | - } catch (Exception $e) { |
|
1252 | - new ExceptionLogger($e); |
|
1253 | - } |
|
1254 | - unset(self::$_settings[ $addon_name ]); |
|
1255 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1256 | - } |
|
1257 | - } |
|
25 | + /** |
|
26 | + * possibly truncated version of the EE core version string |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected static $_core_version = ''; |
|
31 | + |
|
32 | + /** |
|
33 | + * Holds values for registered addons |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected static $_settings = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | + * EE core with knowledge of ALL the addons out there. |
|
45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | + * minimum plugin version. |
|
49 | + * @access protected |
|
50 | + */ |
|
51 | + protected static $_incompatible_addons = array( |
|
52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | + 'Promotions' => '1.0.0.rc.084', |
|
54 | + ); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | + * not just '4.3.0'. |
|
60 | + * So if the addon developer doesn't provide that full version string, |
|
61 | + * fill in the blanks for them |
|
62 | + * |
|
63 | + * @param string $min_core_version |
|
64 | + * @return string always like '4.3.0.rc.000' |
|
65 | + */ |
|
66 | + protected static function _effective_version($min_core_version) |
|
67 | + { |
|
68 | + // versions: 4 . 3 . 1 . p . 123 |
|
69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | + $version_parts = explode('.', $min_core_version); |
|
71 | + // check they specified the micro version (after 2nd period) |
|
72 | + if (! isset($version_parts[2])) { |
|
73 | + $version_parts[2] = '0'; |
|
74 | + } |
|
75 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | + if (! isset($version_parts[3])) { |
|
78 | + $version_parts[3] = 'dev'; |
|
79 | + } |
|
80 | + if (! isset($version_parts[4])) { |
|
81 | + $version_parts[4] = '000'; |
|
82 | + } |
|
83 | + return implode('.', $version_parts); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns whether or not the min core version requirement of the addon is met |
|
89 | + * |
|
90 | + * @param string $min_core_version the minimum core version required by the addon |
|
91 | + * @param string $actual_core_version the actual core version, optional |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public static function _meets_min_core_version_requirement( |
|
95 | + $min_core_version, |
|
96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | + ) { |
|
98 | + return version_compare( |
|
99 | + self::_effective_version($actual_core_version), |
|
100 | + self::_effective_version($min_core_version), |
|
101 | + '>=' |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Method for registering new EE_Addons. |
|
108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | + * |
|
117 | + * @since 4.3.0 |
|
118 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | + * @param array $setup_args { |
|
120 | + * An array of arguments provided for registering |
|
121 | + * the message type. |
|
122 | + * @type string $class_name the addon's main file name. |
|
123 | + * If left blank, generated from the addon name, |
|
124 | + * changes something like "calendar" to |
|
125 | + * "EE_Calendar" |
|
126 | + * @type string $min_core_version the minimum version of EE Core that the |
|
127 | + * addon will work with. eg "4.8.1.rc.084" |
|
128 | + * @type string $version the "software" version for the addon. eg |
|
129 | + * "1.0.0.p" for a first stable release, or |
|
130 | + * "1.0.0.rc.043" for a version in progress |
|
131 | + * @type string $main_file_path the full server path to the main file |
|
132 | + * loaded directly by WP |
|
133 | + * @type DomainInterface $domain child class of |
|
134 | + * EventEspresso\core\domain\DomainBase |
|
135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | + * for the addon's Domain class |
|
137 | + * (see EventEspresso\core\domain\Domain) |
|
138 | + * @type string $admin_path full server path to the folder where the |
|
139 | + * addon\'s admin files reside |
|
140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | + * first invoked, can be used for hooking into |
|
142 | + * any admin page |
|
143 | + * @type string $config_section the section name for this addon's |
|
144 | + * configuration settings section |
|
145 | + * (defaults to "addons") |
|
146 | + * @type string $config_class the class name for this addon's |
|
147 | + * configuration settings object |
|
148 | + * @type string $config_name the class name for this addon's |
|
149 | + * configuration settings object |
|
150 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | + * server paths to those files. |
|
152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | + * folders containing classes that might be |
|
154 | + * invoked by the addon |
|
155 | + * @type string $dms_paths [Required] an array of full server paths to |
|
156 | + * folders that contain data migration scripts. |
|
157 | + * The key should be the EE_Addon class name that |
|
158 | + * this set of data migration scripts belongs to. |
|
159 | + * If the EE_Addon class is namespaced, then this |
|
160 | + * needs to be the Fully Qualified Class Name |
|
161 | + * @type string $module_paths an array of full server paths to any |
|
162 | + * EED_Modules used by the addon |
|
163 | + * @type string $shortcode_paths an array of full server paths to folders |
|
164 | + * that contain EES_Shortcodes |
|
165 | + * @type string $widget_paths an array of full server paths to folders |
|
166 | + * that contain WP_Widgets |
|
167 | + * @type string $pue_options |
|
168 | + * @type array $capabilities an array indexed by role name |
|
169 | + * (i.e administrator,author ) and the values |
|
170 | + * are an array of caps to add to the role. |
|
171 | + * 'administrator' => array( |
|
172 | + * 'read_addon', |
|
173 | + * 'edit_addon', |
|
174 | + * etc. |
|
175 | + * ). |
|
176 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | + * for any addons that need to register any |
|
178 | + * special meta mapped capabilities. Should |
|
179 | + * be indexed where the key is the |
|
180 | + * EE_Meta_Capability_Map class name and the |
|
181 | + * values are the arguments sent to the class. |
|
182 | + * @type array $model_paths array of folders containing DB models |
|
183 | + * @see EE_Register_Model |
|
184 | + * @type array $class_paths array of folders containing DB classes |
|
185 | + * @see EE_Register_Model |
|
186 | + * @type array $model_extension_paths array of folders containing DB model |
|
187 | + * extensions |
|
188 | + * @see EE_Register_Model_Extension |
|
189 | + * @type array $class_extension_paths array of folders containing DB class |
|
190 | + * extensions |
|
191 | + * @see EE_Register_Model_Extension |
|
192 | + * @type array message_types { |
|
193 | + * An array of message types with the key as |
|
194 | + * the message type name and the values as |
|
195 | + * below: |
|
196 | + * @type string $mtfilename [Required] The filename of the message type |
|
197 | + * being registered. This will be the main |
|
198 | + * EE_{Message Type Name}_message_type class. |
|
199 | + * for example: |
|
200 | + * EE_Declined_Registration_message_type.class.php |
|
201 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | + * messages autoloader for the new message type. |
|
203 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | + * type should activate with. Each value in |
|
205 | + * the |
|
206 | + * array |
|
207 | + * should match the name property of a |
|
208 | + * EE_messenger. Optional. |
|
209 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | + * type should validate with. Each value in |
|
211 | + * the |
|
212 | + * array |
|
213 | + * should match the name property of an |
|
214 | + * EE_messenger. |
|
215 | + * Optional. |
|
216 | + * } |
|
217 | + * @type array $custom_post_types |
|
218 | + * @type array $custom_taxonomies |
|
219 | + * @type array $payment_method_paths each element is the folder containing the |
|
220 | + * EE_PMT_Base child class |
|
221 | + * (eg, |
|
222 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | + * which contains the files |
|
224 | + * EE_PMT_Payomatic.pm.php) |
|
225 | + * @type array $default_terms |
|
226 | + * @type array $namespace { |
|
227 | + * An array with two items for registering the |
|
228 | + * addon's namespace. (If, for some reason, you |
|
229 | + * require additional namespaces, |
|
230 | + * use |
|
231 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | + * directly) |
|
233 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | + * @type string $FQNS the namespace prefix |
|
235 | + * @type string $DIR a base directory for class files in the |
|
236 | + * namespace. |
|
237 | + * } |
|
238 | + * } |
|
239 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | + * privacy policy classes) or FQCNs (specific |
|
241 | + * classnames of privacy policy classes) |
|
242 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | + * privacy policy classes) or FQCNs (specific |
|
244 | + * classnames of privacy policy classes) |
|
245 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | + * privacy policy classes) or FQCNs (specific |
|
247 | + * classnames of privacy policy classes) |
|
248 | + * @return void |
|
249 | + * @throws DomainException |
|
250 | + * @throws EE_Error |
|
251 | + * @throws InvalidArgumentException |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws InvalidInterfaceException |
|
254 | + */ |
|
255 | + public static function register($addon_name = '', array $setup_args = array()) |
|
256 | + { |
|
257 | + // required fields MUST be present, so let's make sure they are. |
|
258 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
259 | + // get class name for addon |
|
260 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
261 | + // setup $_settings array from incoming values. |
|
262 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
263 | + // setup PUE |
|
264 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
265 | + // does this addon work with this version of core or WordPress ? |
|
266 | + // does this addon work with this version of core or WordPress ? |
|
267 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | + return; |
|
269 | + } |
|
270 | + // register namespaces |
|
271 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | + // check if this is an activation request |
|
273 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | + // dont bother setting up the rest of the addon atm |
|
275 | + return; |
|
276 | + } |
|
277 | + // we need cars |
|
278 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | + // register new models and extensions |
|
280 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | + // setup DMS |
|
282 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | + // if config_class is present let's register config. |
|
284 | + EE_Register_Addon::_register_config($addon_name); |
|
285 | + // register admin pages |
|
286 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | + // add to list of modules to be registered |
|
288 | + EE_Register_Addon::_register_modules($addon_name); |
|
289 | + // add to list of shortcodes to be registered |
|
290 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | + // add to list of widgets to be registered |
|
292 | + EE_Register_Addon::_register_widgets($addon_name); |
|
293 | + // register capability related stuff. |
|
294 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | + // any message type to register? |
|
296 | + EE_Register_Addon::_register_message_types($addon_name); |
|
297 | + // any custom post type/ custom capabilities or default terms to register |
|
298 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | + // and any payment methods |
|
300 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | + // and privacy policy generators |
|
302 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | + // and privacy policy generators |
|
304 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | + // and privacy policy generators |
|
306 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | + // load and instantiate main addon class |
|
308 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $addon_name |
|
316 | + * @param array $setup_args |
|
317 | + * @return void |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + // required fields MUST be present, so let's make sure they are. |
|
323 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | + throw new EE_Error( |
|
325 | + __( |
|
326 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | + 'event_espresso' |
|
328 | + ) |
|
329 | + ); |
|
330 | + } |
|
331 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | + throw new EE_Error( |
|
333 | + sprintf( |
|
334 | + __( |
|
335 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + implode(',', array_keys($setup_args)) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + // check that addon has not already been registered with that name |
|
343 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | + throw new EE_Error( |
|
345 | + sprintf( |
|
346 | + __( |
|
347 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + $addon_name |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $addon_name |
|
359 | + * @param array $setup_args |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | + { |
|
364 | + if (empty($setup_args['class_name'])) { |
|
365 | + // generate one by first separating name with spaces |
|
366 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | + // capitalize, then replace spaces with underscores |
|
368 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | + } else { |
|
370 | + $class_name = $setup_args['class_name']; |
|
371 | + } |
|
372 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | + ? $class_name |
|
375 | + : 'EE_' . $class_name; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @param string $class_name |
|
381 | + * @param array $setup_args |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | + { |
|
386 | + // setup $_settings array from incoming values. |
|
387 | + $addon_settings = array( |
|
388 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | + 'class_name' => $class_name, |
|
390 | + // the addon slug for use in URLs, etc |
|
391 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | + ? (string) $setup_args['plugin_slug'] |
|
393 | + : '', |
|
394 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | + ? (string) $setup_args['plugin_action_slug'] |
|
397 | + : '', |
|
398 | + // the "software" version for the addon |
|
399 | + 'version' => isset($setup_args['version']) |
|
400 | + ? (string) $setup_args['version'] |
|
401 | + : '', |
|
402 | + // the minimum version of EE Core that the addon will work with |
|
403 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | + ? (string) $setup_args['min_core_version'] |
|
405 | + : '', |
|
406 | + // the minimum version of WordPress that the addon will work with |
|
407 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | + ? (string) $setup_args['min_wp_version'] |
|
409 | + : EE_MIN_WP_VER_REQUIRED, |
|
410 | + // full server path to main file (file loaded directly by WP) |
|
411 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | + ? (string) $setup_args['main_file_path'] |
|
413 | + : '', |
|
414 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | + ? $setup_args['domain'] |
|
417 | + : null, |
|
418 | + // Fully Qualified Class Name for the addon's Domain class |
|
419 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | + ? (string) $setup_args['domain_fqcn'] |
|
421 | + : '', |
|
422 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | + 'admin_path' => isset($setup_args['admin_path']) |
|
424 | + ? (string) $setup_args['admin_path'] : '', |
|
425 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | + ? (string) $setup_args['admin_callback'] |
|
428 | + : '', |
|
429 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | + 'config_section' => isset($setup_args['config_section']) |
|
431 | + ? (string) $setup_args['config_section'] |
|
432 | + : 'addons', |
|
433 | + // the class name for this addon's configuration settings object |
|
434 | + 'config_class' => isset($setup_args['config_class']) |
|
435 | + ? (string) $setup_args['config_class'] : '', |
|
436 | + // the name given to the config for this addons' configuration settings object (optional) |
|
437 | + 'config_name' => isset($setup_args['config_name']) |
|
438 | + ? (string) $setup_args['config_name'] : '', |
|
439 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | + ? (array) $setup_args['autoloader_paths'] |
|
442 | + : array(), |
|
443 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | + ? (array) $setup_args['autoloader_folders'] |
|
446 | + : array(), |
|
447 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | + ? (array) $setup_args['dms_paths'] |
|
452 | + : array(), |
|
453 | + // array of full server paths to any EED_Modules used by the addon |
|
454 | + 'module_paths' => isset($setup_args['module_paths']) |
|
455 | + ? (array) $setup_args['module_paths'] |
|
456 | + : array(), |
|
457 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | + ? (array) $setup_args['shortcode_paths'] |
|
460 | + : array(), |
|
461 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | + ? (array) $setup_args['shortcode_fqcns'] |
|
463 | + : array(), |
|
464 | + // array of full server paths to any WP_Widgets used by the addon |
|
465 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | + ? (array) $setup_args['widget_paths'] |
|
467 | + : array(), |
|
468 | + // array of PUE options used by the addon |
|
469 | + 'pue_options' => isset($setup_args['pue_options']) |
|
470 | + ? (array) $setup_args['pue_options'] |
|
471 | + : array(), |
|
472 | + 'message_types' => isset($setup_args['message_types']) |
|
473 | + ? (array) $setup_args['message_types'] |
|
474 | + : array(), |
|
475 | + 'capabilities' => isset($setup_args['capabilities']) |
|
476 | + ? (array) $setup_args['capabilities'] |
|
477 | + : array(), |
|
478 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | + ? (array) $setup_args['capability_maps'] |
|
480 | + : array(), |
|
481 | + 'model_paths' => isset($setup_args['model_paths']) |
|
482 | + ? (array) $setup_args['model_paths'] |
|
483 | + : array(), |
|
484 | + 'class_paths' => isset($setup_args['class_paths']) |
|
485 | + ? (array) $setup_args['class_paths'] |
|
486 | + : array(), |
|
487 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | + ? (array) $setup_args['model_extension_paths'] |
|
489 | + : array(), |
|
490 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | + ? (array) $setup_args['class_extension_paths'] |
|
492 | + : array(), |
|
493 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | + ? (array) $setup_args['custom_post_types'] |
|
495 | + : array(), |
|
496 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | + ? (array) $setup_args['custom_taxonomies'] |
|
498 | + : array(), |
|
499 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | + ? (array) $setup_args['payment_method_paths'] |
|
501 | + : array(), |
|
502 | + 'default_terms' => isset($setup_args['default_terms']) |
|
503 | + ? (array) $setup_args['default_terms'] |
|
504 | + : array(), |
|
505 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | + // that can be used for adding upgrading/marketing info |
|
507 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
508 | + 'namespace' => isset( |
|
509 | + $setup_args['namespace']['FQNS'], |
|
510 | + $setup_args['namespace']['DIR'] |
|
511 | + ) |
|
512 | + ? (array) $setup_args['namespace'] |
|
513 | + : array(), |
|
514 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
515 | + ? (array) $setup_args['privacy_policies'] |
|
516 | + : '', |
|
517 | + ); |
|
518 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
519 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
520 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
521 | + && ! empty($addon_settings['admin_path']) |
|
522 | + ? $addon_settings['plugin_slug'] |
|
523 | + : $addon_settings['plugin_action_slug']; |
|
524 | + // full server path to main file (file loaded directly by WP) |
|
525 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
526 | + return $addon_settings; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param string $addon_name |
|
532 | + * @param array $addon_settings |
|
533 | + * @return boolean |
|
534 | + */ |
|
535 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
536 | + { |
|
537 | + global $wp_version; |
|
538 | + $incompatibility_message = ''; |
|
539 | + // check whether this addon version is compatible with EE core |
|
540 | + if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
541 | + && ! self::_meets_min_core_version_requirement( |
|
542 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
543 | + $addon_settings['version'] |
|
544 | + ) |
|
545 | + ) { |
|
546 | + $incompatibility_message = sprintf( |
|
547 | + __( |
|
548 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
549 | + 'event_espresso' |
|
550 | + ), |
|
551 | + $addon_name, |
|
552 | + '<br />', |
|
553 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
554 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
555 | + '</span><br />' |
|
556 | + ); |
|
557 | + } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
558 | + ) { |
|
559 | + $incompatibility_message = sprintf( |
|
560 | + __( |
|
561 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
562 | + 'event_espresso' |
|
563 | + ), |
|
564 | + $addon_name, |
|
565 | + self::_effective_version($addon_settings['min_core_version']), |
|
566 | + self::_effective_version(espresso_version()), |
|
567 | + '<br />', |
|
568 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
569 | + '</span><br />' |
|
570 | + ); |
|
571 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
572 | + $incompatibility_message = sprintf( |
|
573 | + __( |
|
574 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
575 | + 'event_espresso' |
|
576 | + ), |
|
577 | + $addon_name, |
|
578 | + $addon_settings['min_wp_version'], |
|
579 | + '<br />', |
|
580 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
581 | + '</span><br />' |
|
582 | + ); |
|
583 | + } |
|
584 | + if (! empty($incompatibility_message)) { |
|
585 | + // remove 'activate' from the REQUEST |
|
586 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
587 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
588 | + if (current_user_can('activate_plugins')) { |
|
589 | + // show an error message indicating the plugin didn't activate properly |
|
590 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
591 | + } |
|
592 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
593 | + return false; |
|
594 | + } |
|
595 | + // addon IS compatible |
|
596 | + return true; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * if plugin update engine is being used for auto-updates, |
|
602 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
603 | + * (not needed if PUE is not being used) |
|
604 | + * |
|
605 | + * @param string $addon_name |
|
606 | + * @param string $class_name |
|
607 | + * @param array $setup_args |
|
608 | + * @return void |
|
609 | + */ |
|
610 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
611 | + { |
|
612 | + if (! empty($setup_args['pue_options'])) { |
|
613 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
614 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
615 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
616 | + : 'espresso_' . strtolower($class_name), |
|
617 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
618 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
619 | + : plugin_basename($setup_args['main_file_path']), |
|
620 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
621 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
622 | + : '24', |
|
623 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
624 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
625 | + : false, |
|
626 | + ); |
|
627 | + add_action( |
|
628 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
629 | + array('EE_Register_Addon', 'load_pue_update') |
|
630 | + ); |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
637 | + * |
|
638 | + * @param array $addon_settings |
|
639 | + * @return void |
|
640 | + */ |
|
641 | + private static function _setup_namespaces(array $addon_settings) |
|
642 | + { |
|
643 | + // |
|
644 | + if (isset( |
|
645 | + $addon_settings['namespace']['FQNS'], |
|
646 | + $addon_settings['namespace']['DIR'] |
|
647 | + )) { |
|
648 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
649 | + $addon_settings['namespace']['FQNS'], |
|
650 | + $addon_settings['namespace']['DIR'] |
|
651 | + ); |
|
652 | + } |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @param string $addon_name |
|
658 | + * @param array $addon_settings |
|
659 | + * @return bool |
|
660 | + * @throws InvalidArgumentException |
|
661 | + * @throws InvalidDataTypeException |
|
662 | + * @throws InvalidInterfaceException |
|
663 | + */ |
|
664 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
665 | + { |
|
666 | + // this is an activation request |
|
667 | + if (did_action('activate_plugin')) { |
|
668 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
669 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
670 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
671 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
672 | + if (! isset(self::$_settings[ $addon_name ]) |
|
673 | + || (isset(self::$_settings[ $addon_name ]) |
|
674 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
675 | + ) |
|
676 | + ) { |
|
677 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
678 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
679 | + $addon->set_activation_indicator_option(); |
|
680 | + // dont bother setting up the rest of the addon. |
|
681 | + // we know it was just activated and the request will end soon |
|
682 | + } |
|
683 | + return true; |
|
684 | + } |
|
685 | + // make sure this was called in the right place! |
|
686 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
687 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
688 | + ) { |
|
689 | + EE_Error::doing_it_wrong( |
|
690 | + __METHOD__, |
|
691 | + sprintf( |
|
692 | + __( |
|
693 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
694 | + 'event_espresso' |
|
695 | + ), |
|
696 | + $addon_name |
|
697 | + ), |
|
698 | + '4.3.0' |
|
699 | + ); |
|
700 | + } |
|
701 | + // make sure addon settings are set correctly without overwriting anything existing |
|
702 | + if (isset(self::$_settings[ $addon_name ])) { |
|
703 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | + } else { |
|
705 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | + } |
|
707 | + return false; |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * @param string $addon_name |
|
713 | + * @return void |
|
714 | + * @throws EE_Error |
|
715 | + */ |
|
716 | + private static function _setup_autoloaders($addon_name) |
|
717 | + { |
|
718 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | + // setup autoloader for single file |
|
720 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | + } |
|
722 | + // setup autoloaders for folders |
|
723 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | + } |
|
727 | + } |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * register new models and extensions |
|
733 | + * |
|
734 | + * @param string $addon_name |
|
735 | + * @return void |
|
736 | + * @throws EE_Error |
|
737 | + */ |
|
738 | + private static function _register_models_and_extensions($addon_name) |
|
739 | + { |
|
740 | + // register new models |
|
741 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
742 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
743 | + ) { |
|
744 | + EE_Register_Model::register( |
|
745 | + $addon_name, |
|
746 | + array( |
|
747 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
748 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
749 | + ) |
|
750 | + ); |
|
751 | + } |
|
752 | + // register model extensions |
|
753 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
754 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
755 | + ) { |
|
756 | + EE_Register_Model_Extensions::register( |
|
757 | + $addon_name, |
|
758 | + array( |
|
759 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
760 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
761 | + ) |
|
762 | + ); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * @param string $addon_name |
|
769 | + * @return void |
|
770 | + * @throws EE_Error |
|
771 | + */ |
|
772 | + private static function _register_data_migration_scripts($addon_name) |
|
773 | + { |
|
774 | + // setup DMS |
|
775 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
776 | + EE_Register_Data_Migration_Scripts::register( |
|
777 | + $addon_name, |
|
778 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
779 | + ); |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + |
|
784 | + /** |
|
785 | + * @param string $addon_name |
|
786 | + * @return void |
|
787 | + * @throws EE_Error |
|
788 | + */ |
|
789 | + private static function _register_config($addon_name) |
|
790 | + { |
|
791 | + // if config_class is present let's register config. |
|
792 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
793 | + EE_Register_Config::register( |
|
794 | + self::$_settings[ $addon_name ]['config_class'], |
|
795 | + array( |
|
796 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
797 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
798 | + ) |
|
799 | + ); |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * @param string $addon_name |
|
806 | + * @return void |
|
807 | + * @throws EE_Error |
|
808 | + */ |
|
809 | + private static function _register_admin_pages($addon_name) |
|
810 | + { |
|
811 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
812 | + EE_Register_Admin_Page::register( |
|
813 | + $addon_name, |
|
814 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
815 | + ); |
|
816 | + } |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * @param string $addon_name |
|
822 | + * @return void |
|
823 | + * @throws EE_Error |
|
824 | + */ |
|
825 | + private static function _register_modules($addon_name) |
|
826 | + { |
|
827 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
828 | + EE_Register_Module::register( |
|
829 | + $addon_name, |
|
830 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
831 | + ); |
|
832 | + } |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * @param string $addon_name |
|
838 | + * @return void |
|
839 | + * @throws EE_Error |
|
840 | + */ |
|
841 | + private static function _register_shortcodes($addon_name) |
|
842 | + { |
|
843 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
844 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
845 | + ) { |
|
846 | + EE_Register_Shortcode::register( |
|
847 | + $addon_name, |
|
848 | + array( |
|
849 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
850 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
851 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
852 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
853 | + ) |
|
854 | + ); |
|
855 | + } |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * @param string $addon_name |
|
861 | + * @return void |
|
862 | + * @throws EE_Error |
|
863 | + */ |
|
864 | + private static function _register_widgets($addon_name) |
|
865 | + { |
|
866 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
867 | + EE_Register_Widget::register( |
|
868 | + $addon_name, |
|
869 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
870 | + ); |
|
871 | + } |
|
872 | + } |
|
873 | + |
|
874 | + |
|
875 | + /** |
|
876 | + * @param string $addon_name |
|
877 | + * @return void |
|
878 | + * @throws EE_Error |
|
879 | + */ |
|
880 | + private static function _register_capabilities($addon_name) |
|
881 | + { |
|
882 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
883 | + EE_Register_Capabilities::register( |
|
884 | + $addon_name, |
|
885 | + array( |
|
886 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
887 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
888 | + ) |
|
889 | + ); |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * @param string $addon_name |
|
896 | + * @return void |
|
897 | + */ |
|
898 | + private static function _register_message_types($addon_name) |
|
899 | + { |
|
900 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
901 | + add_action( |
|
902 | + 'EE_Brewing_Regular___messages_caf', |
|
903 | + array('EE_Register_Addon', 'register_message_types') |
|
904 | + ); |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param string $addon_name |
|
911 | + * @return void |
|
912 | + * @throws EE_Error |
|
913 | + */ |
|
914 | + private static function _register_custom_post_types($addon_name) |
|
915 | + { |
|
916 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
917 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
918 | + ) { |
|
919 | + EE_Register_CPT::register( |
|
920 | + $addon_name, |
|
921 | + array( |
|
922 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
923 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
924 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
925 | + ) |
|
926 | + ); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * @param string $addon_name |
|
933 | + * @return void |
|
934 | + * @throws InvalidArgumentException |
|
935 | + * @throws InvalidInterfaceException |
|
936 | + * @throws InvalidDataTypeException |
|
937 | + * @throws DomainException |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + private static function _register_payment_methods($addon_name) |
|
941 | + { |
|
942 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
943 | + EE_Register_Payment_Method::register( |
|
944 | + $addon_name, |
|
945 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
946 | + ); |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * @param string $addon_name |
|
953 | + * @return void |
|
954 | + * @throws InvalidArgumentException |
|
955 | + * @throws InvalidInterfaceException |
|
956 | + * @throws InvalidDataTypeException |
|
957 | + * @throws DomainException |
|
958 | + */ |
|
959 | + private static function registerPrivacyPolicies($addon_name) |
|
960 | + { |
|
961 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
962 | + EE_Register_Privacy_Policy::register( |
|
963 | + $addon_name, |
|
964 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
965 | + ); |
|
966 | + } |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * @param string $addon_name |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + private static function registerPersonalDataExporters($addon_name) |
|
975 | + { |
|
976 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
977 | + EE_Register_Personal_Data_Eraser::register( |
|
978 | + $addon_name, |
|
979 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
980 | + ); |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @param string $addon_name |
|
987 | + * @return void |
|
988 | + */ |
|
989 | + private static function registerPersonalDataErasers($addon_name) |
|
990 | + { |
|
991 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
992 | + EE_Register_Personal_Data_Eraser::register( |
|
993 | + $addon_name, |
|
994 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
995 | + ); |
|
996 | + } |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + /** |
|
1001 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1002 | + * |
|
1003 | + * @param string $addon_name |
|
1004 | + * @return EE_Addon |
|
1005 | + * @throws InvalidArgumentException |
|
1006 | + * @throws InvalidInterfaceException |
|
1007 | + * @throws InvalidDataTypeException |
|
1008 | + */ |
|
1009 | + private static function _load_and_init_addon_class($addon_name) |
|
1010 | + { |
|
1011 | + $addon = LoaderFactory::getLoader()->getShared( |
|
1012 | + self::$_settings[ $addon_name ]['class_name'], |
|
1013 | + array('EE_Registry::create(addon)' => true) |
|
1014 | + ); |
|
1015 | + if (! $addon instanceof EE_Addon) { |
|
1016 | + throw new DomainException( |
|
1017 | + sprintf( |
|
1018 | + esc_html__( |
|
1019 | + 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
1020 | + 'event_espresso' |
|
1021 | + ), |
|
1022 | + $addon_name |
|
1023 | + ) |
|
1024 | + ); |
|
1025 | + } |
|
1026 | + // setter inject dep map if required |
|
1027 | + if ($addon->dependencyMap() === null) { |
|
1028 | + $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
1029 | + } |
|
1030 | + // setter inject domain if required |
|
1031 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1032 | + |
|
1033 | + $addon->set_name($addon_name); |
|
1034 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1035 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1036 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1037 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1038 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1039 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1040 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1041 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1042 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1043 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1044 | + // setup the add-on's pue_slug if we have one. |
|
1045 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1046 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1047 | + } |
|
1048 | + // unfortunately this can't be hooked in upon construction, |
|
1049 | + // because we don't have the plugin's mainfile path upon construction. |
|
1050 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1051 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1052 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1053 | + add_action( |
|
1054 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1055 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + return $addon; |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * @param string $addon_name |
|
1064 | + * @param EE_Addon $addon |
|
1065 | + * @since 4.10.13.p |
|
1066 | + */ |
|
1067 | + private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
1068 | + { |
|
1069 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1070 | + // using supplied Domain object |
|
1071 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1072 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1073 | + : null; |
|
1074 | + // or construct one using Domain FQCN |
|
1075 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1076 | + $domain = LoaderFactory::getLoader()->getShared( |
|
1077 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1078 | + [ |
|
1079 | + new EventEspresso\core\domain\values\FilePath( |
|
1080 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1081 | + ), |
|
1082 | + EventEspresso\core\domain\values\Version::fromString( |
|
1083 | + self::$_settings[ $addon_name ]['version'] |
|
1084 | + ), |
|
1085 | + ] |
|
1086 | + ); |
|
1087 | + } |
|
1088 | + if ($domain instanceof DomainInterface) { |
|
1089 | + $addon->setDomain($domain); |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * load_pue_update - Update notifications |
|
1097 | + * |
|
1098 | + * @return void |
|
1099 | + * @throws InvalidArgumentException |
|
1100 | + * @throws InvalidDataTypeException |
|
1101 | + * @throws InvalidInterfaceException |
|
1102 | + */ |
|
1103 | + public static function load_pue_update() |
|
1104 | + { |
|
1105 | + // load PUE client |
|
1106 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1107 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1108 | + // cycle thru settings |
|
1109 | + foreach (self::$_settings as $settings) { |
|
1110 | + if (! empty($settings['pue_options'])) { |
|
1111 | + // initiate the class and start the plugin update engine! |
|
1112 | + new PluginUpdateEngineChecker( |
|
1113 | + // host file URL |
|
1114 | + $license_server, |
|
1115 | + // plugin slug(s) |
|
1116 | + array( |
|
1117 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1118 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1119 | + ), |
|
1120 | + // options |
|
1121 | + array( |
|
1122 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1123 | + 'lang_domain' => 'event_espresso', |
|
1124 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1125 | + 'option_key' => 'ee_site_license_key', |
|
1126 | + 'options_page_slug' => 'event_espresso', |
|
1127 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1128 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1129 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1130 | + ) |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + } |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1139 | + * |
|
1140 | + * @since 4.4.0 |
|
1141 | + * @return void |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public static function register_message_types() |
|
1145 | + { |
|
1146 | + foreach (self::$_settings as $settings) { |
|
1147 | + if (! empty($settings['message_types'])) { |
|
1148 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1149 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1150 | + } |
|
1151 | + } |
|
1152 | + } |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1158 | + * |
|
1159 | + * @param string $addon_name the name for the addon that was previously registered |
|
1160 | + * @throws DomainException |
|
1161 | + * @throws InvalidArgumentException |
|
1162 | + * @throws InvalidDataTypeException |
|
1163 | + * @throws InvalidInterfaceException |
|
1164 | + *@since 4.3.0 |
|
1165 | + */ |
|
1166 | + public static function deregister($addon_name = '') |
|
1167 | + { |
|
1168 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1169 | + try { |
|
1170 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1171 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1172 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1173 | + // setup DMS |
|
1174 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1175 | + } |
|
1176 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1177 | + // register admin page |
|
1178 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1179 | + } |
|
1180 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1181 | + // add to list of modules to be registered |
|
1182 | + EE_Register_Module::deregister($addon_name); |
|
1183 | + } |
|
1184 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1185 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1186 | + ) { |
|
1187 | + // add to list of shortcodes to be registered |
|
1188 | + EE_Register_Shortcode::deregister($addon_name); |
|
1189 | + } |
|
1190 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1191 | + // if config_class present let's register config. |
|
1192 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1193 | + } |
|
1194 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1195 | + // add to list of widgets to be registered |
|
1196 | + EE_Register_Widget::deregister($addon_name); |
|
1197 | + } |
|
1198 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1199 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1200 | + ) { |
|
1201 | + // add to list of shortcodes to be registered |
|
1202 | + EE_Register_Model::deregister($addon_name); |
|
1203 | + } |
|
1204 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1205 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1206 | + ) { |
|
1207 | + // add to list of shortcodes to be registered |
|
1208 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1209 | + } |
|
1210 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1211 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1212 | + EE_Register_Message_Type::deregister($message_type); |
|
1213 | + } |
|
1214 | + } |
|
1215 | + // deregister capabilities for addon |
|
1216 | + if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1217 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1218 | + ) { |
|
1219 | + EE_Register_Capabilities::deregister($addon_name); |
|
1220 | + } |
|
1221 | + // deregister custom_post_types for addon |
|
1222 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1223 | + EE_Register_CPT::deregister($addon_name); |
|
1224 | + } |
|
1225 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1226 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1227 | + } |
|
1228 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1229 | + if ($addon instanceof EE_Addon) { |
|
1230 | + remove_action( |
|
1231 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1232 | + array($addon, 'deactivation') |
|
1233 | + ); |
|
1234 | + remove_action( |
|
1235 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1236 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1237 | + ); |
|
1238 | + // remove `after_registration` call |
|
1239 | + remove_action( |
|
1240 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1241 | + array($addon, 'after_registration'), |
|
1242 | + 999 |
|
1243 | + ); |
|
1244 | + } |
|
1245 | + EE_Registry::instance()->removeAddon($class_name); |
|
1246 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1247 | + // the add-on was not yet registered in the registry, |
|
1248 | + // so RegistryContainer::__get() throws this exception. |
|
1249 | + // also no need to worry about this or log it, |
|
1250 | + // it's ok to deregister an add-on before its registered in the registry |
|
1251 | + } catch (Exception $e) { |
|
1252 | + new ExceptionLogger($e); |
|
1253 | + } |
|
1254 | + unset(self::$_settings[ $addon_name ]); |
|
1255 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1256 | + } |
|
1257 | + } |
|
1258 | 1258 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.14.rc.000'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.14.rc.000'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |