@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -22,806 +22,806 @@ discard block |
||
22 | 22 | class EE_Dependency_Map |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | - */ |
|
33 | - const load_new_object = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | - */ |
|
39 | - const load_from_cache = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * When registering a dependency, |
|
43 | - * this indicates to keep any existing dependencies that already exist, |
|
44 | - * and simply discard any new dependencies declared in the incoming data |
|
45 | - */ |
|
46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * When registering a dependency, |
|
50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | - */ |
|
52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @type EE_Dependency_Map $_instance |
|
58 | - */ |
|
59 | - protected static $_instance; |
|
60 | - |
|
61 | - /** |
|
62 | - * @type EE_Request $request |
|
63 | - */ |
|
64 | - protected $_request; |
|
65 | - |
|
66 | - /** |
|
67 | - * @type EE_Response $response |
|
68 | - */ |
|
69 | - protected $_response; |
|
70 | - |
|
71 | - /** |
|
72 | - * @type LoaderInterface $loader |
|
73 | - */ |
|
74 | - protected $loader; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type array $_dependency_map |
|
78 | - */ |
|
79 | - protected $_dependency_map = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * @type array $_class_loaders |
|
83 | - */ |
|
84 | - protected $_class_loaders = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * @type array $_aliases |
|
88 | - */ |
|
89 | - protected $_aliases = array(); |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * EE_Dependency_Map constructor. |
|
95 | - * |
|
96 | - * @param EE_Request $request |
|
97 | - * @param EE_Response $response |
|
98 | - */ |
|
99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | - { |
|
101 | - $this->_request = $request; |
|
102 | - $this->_response = $response; |
|
103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | - do_action('EE_Dependency_Map____construct'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - */ |
|
114 | - public function initialize() |
|
115 | - { |
|
116 | - $this->_register_core_dependencies(); |
|
117 | - $this->_register_core_class_loaders(); |
|
118 | - $this->_register_core_aliases(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @singleton method used to instantiate class object |
|
125 | - * @access public |
|
126 | - * @param EE_Request $request |
|
127 | - * @param EE_Response $response |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | - { |
|
132 | - // check if class object is instantiated, and instantiated properly |
|
133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | - } |
|
136 | - return self::$_instance; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param LoaderInterface $loader |
|
143 | - */ |
|
144 | - public function setLoader(LoaderInterface $loader) |
|
145 | - { |
|
146 | - $this->loader = $loader; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $class |
|
153 | - * @param array $dependencies |
|
154 | - * @param int $overwrite |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public static function register_dependencies( |
|
158 | - $class, |
|
159 | - array $dependencies, |
|
160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | - ) { |
|
162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | - * to the class specified by the first parameter. |
|
170 | - * IMPORTANT !!! |
|
171 | - * The order of elements in the incoming $dependencies array MUST match |
|
172 | - * the order of the constructor parameters for the class in question. |
|
173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | - * |
|
176 | - * @param string $class |
|
177 | - * @param array $dependencies |
|
178 | - * @param int $overwrite |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function registerDependencies( |
|
182 | - $class, |
|
183 | - array $dependencies, |
|
184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | - ) { |
|
186 | - $class = trim($class, '\\'); |
|
187 | - $registered = false; |
|
188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | - } |
|
191 | - // we need to make sure that any aliases used when registering a dependency |
|
192 | - // get resolved to the correct class name |
|
193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | - $alias = self::$_instance->get_alias($dependency); |
|
195 | - if ( |
|
196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | - ) { |
|
199 | - unset($dependencies[$dependency]); |
|
200 | - $dependencies[$alias] = $load_source; |
|
201 | - $registered = true; |
|
202 | - } |
|
203 | - } |
|
204 | - // now add our two lists of dependencies together. |
|
205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | - // so $dependencies is NOT overwritten because it is listed first |
|
207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | - // Union is way faster than array_merge() but should be used with caution... |
|
209 | - // especially with numerically indexed arrays |
|
210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | - // now we need to ensure that the resulting dependencies |
|
212 | - // array only has the entries that are required for the class |
|
213 | - // so first count how many dependencies were originally registered for the class |
|
214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | - // then truncate the final array to match that count |
|
218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
219 | - // otherwise just take the incoming array because nothing previously existed |
|
220 | - : $dependencies; |
|
221 | - return $registered; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $class_name |
|
228 | - * @param string $loader |
|
229 | - * @return bool |
|
230 | - * @throws DomainException |
|
231 | - */ |
|
232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | - { |
|
234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | - throw new DomainException( |
|
236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | - ); |
|
238 | - } |
|
239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | - if ( |
|
241 | - ! is_callable($loader) |
|
242 | - && ( |
|
243 | - strpos($loader, 'load_') !== 0 |
|
244 | - || ! method_exists('EE_Registry', $loader) |
|
245 | - ) |
|
246 | - ) { |
|
247 | - throw new DomainException( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $loader |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $class_name = self::$_instance->get_alias($class_name); |
|
258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | - return true; |
|
261 | - } |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function dependency_map() |
|
271 | - { |
|
272 | - return $this->_dependency_map; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | - * |
|
280 | - * @param string $class_name |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function has($class_name = '') |
|
284 | - { |
|
285 | - // all legacy models have the same dependencies |
|
286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
287 | - $class_name = 'LEGACY_MODELS'; |
|
288 | - } |
|
289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | - * |
|
297 | - * @param string $class_name |
|
298 | - * @param string $dependency |
|
299 | - * @return bool |
|
300 | - */ |
|
301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | - { |
|
303 | - // all legacy models have the same dependencies |
|
304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
305 | - $class_name = 'LEGACY_MODELS'; |
|
306 | - } |
|
307 | - $dependency = $this->get_alias($dependency); |
|
308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | - ? true |
|
310 | - : false; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | - * |
|
318 | - * @param string $class_name |
|
319 | - * @param string $dependency |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | - { |
|
324 | - // all legacy models have the same dependencies |
|
325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
326 | - $class_name = 'LEGACY_MODELS'; |
|
327 | - } |
|
328 | - $dependency = $this->get_alias($dependency); |
|
329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
331 | - : EE_Dependency_Map::not_registered; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param string $class_name |
|
338 | - * @return string | Closure |
|
339 | - */ |
|
340 | - public function class_loader($class_name) |
|
341 | - { |
|
342 | - // all legacy models use load_model() |
|
343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
344 | - return 'load_model'; |
|
345 | - } |
|
346 | - $class_name = $this->get_alias($class_name); |
|
347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function class_loaders() |
|
356 | - { |
|
357 | - return $this->_class_loaders; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * adds an alias for a classname |
|
364 | - * |
|
365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | - */ |
|
369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
370 | - { |
|
371 | - if ($for_class !== '') { |
|
372 | - if (! isset($this->_aliases[$for_class])) { |
|
373 | - $this->_aliases[$for_class] = array(); |
|
374 | - } |
|
375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | - } |
|
377 | - $this->_aliases[$class_name] = $alias; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * returns TRUE if the provided class name has an alias |
|
384 | - * |
|
385 | - * @param string $class_name |
|
386 | - * @param string $for_class |
|
387 | - * @return bool |
|
388 | - */ |
|
389 | - public function has_alias($class_name = '', $for_class = '') |
|
390 | - { |
|
391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | - || ( |
|
393 | - isset($this->_aliases[$class_name]) |
|
394 | - && ! is_array($this->_aliases[$class_name]) |
|
395 | - ); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | - * for example: |
|
404 | - * if the following two entries were added to the _aliases array: |
|
405 | - * array( |
|
406 | - * 'interface_alias' => 'some\namespace\interface' |
|
407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | - * ) |
|
409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | - * to load an instance of 'some\namespace\classname' |
|
411 | - * |
|
412 | - * @param string $class_name |
|
413 | - * @param string $for_class |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function get_alias($class_name = '', $for_class = '') |
|
417 | - { |
|
418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
419 | - return $class_name; |
|
420 | - } |
|
421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | - } |
|
424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | - * This is done by using the following class constants: |
|
433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | - */ |
|
436 | - protected function _register_core_dependencies() |
|
437 | - { |
|
438 | - $this->_dependency_map = array( |
|
439 | - 'EE_Request_Handler' => array( |
|
440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_System' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_Session' => array( |
|
450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
453 | - ), |
|
454 | - 'EE_Cart' => array( |
|
455 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_Front_Controller' => array( |
|
458 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Messenger_Collection_Loader' => array( |
|
463 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | - ), |
|
465 | - 'EE_Message_Type_Collection_Loader' => array( |
|
466 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | - ), |
|
468 | - 'EE_Message_Resource_Manager' => array( |
|
469 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
471 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_Message_Factory' => array( |
|
474 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | - ), |
|
476 | - 'EE_messages' => array( |
|
477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | - ), |
|
479 | - 'EE_Messages_Generator' => array( |
|
480 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
481 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
483 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_Messages_Processor' => array( |
|
486 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
487 | - ), |
|
488 | - 'EE_Messages_Queue' => array( |
|
489 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
490 | - ), |
|
491 | - 'EE_Messages_Template_Defaults' => array( |
|
492 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
493 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
494 | - ), |
|
495 | - 'EE_Message_To_Generate_From_Request' => array( |
|
496 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
497 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
500 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
503 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
504 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
507 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
508 | - ), |
|
509 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
510 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
511 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
514 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
517 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
520 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
523 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
529 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
532 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
535 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
538 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
539 | - ), |
|
540 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
541 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | - ), |
|
543 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
544 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | - ), |
|
546 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
547 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
550 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
551 | - ), |
|
552 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
553 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | - ), |
|
555 | - 'EE_Data_Migration_Class_Base' => array( |
|
556 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
557 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
558 | - ), |
|
559 | - 'EE_DMS_Core_4_1_0' => array( |
|
560 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_DMS_Core_4_2_0' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_3_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_4_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_5_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_6_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_7_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_8_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_9_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
596 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
600 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
603 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
606 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
609 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
610 | - ), |
|
611 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
612 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | - ), |
|
614 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
615 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | - ), |
|
617 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
618 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
619 | - ), |
|
620 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
621 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | - ), |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
624 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | - ), |
|
626 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
627 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
628 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
629 | - ), |
|
630 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
631 | - null, |
|
632 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
635 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'LEGACY_MODELS' => array( |
|
638 | - null, |
|
639 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
640 | - ), |
|
641 | - 'EE_Module_Request_Router' => array( |
|
642 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
643 | - ), |
|
644 | - 'EE_Registration_Processor' => array( |
|
645 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
650 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
651 | - ), |
|
652 | - ); |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * Registers how core classes are loaded. |
|
659 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
660 | - * 'EE_Request_Handler' => 'load_core' |
|
661 | - * 'EE_Messages_Queue' => 'load_lib' |
|
662 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
663 | - * or, if greater control is required, by providing a custom closure. For example: |
|
664 | - * 'Some_Class' => function () { |
|
665 | - * return new Some_Class(); |
|
666 | - * }, |
|
667 | - * This is required for instantiating dependencies |
|
668 | - * where an interface has been type hinted in a class constructor. For example: |
|
669 | - * 'Required_Interface' => function () { |
|
670 | - * return new A_Class_That_Implements_Required_Interface(); |
|
671 | - * }, |
|
672 | - * |
|
673 | - * @throws InvalidInterfaceException |
|
674 | - * @throws InvalidDataTypeException |
|
675 | - * @throws InvalidArgumentException |
|
676 | - */ |
|
677 | - protected function _register_core_class_loaders() |
|
678 | - { |
|
679 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
680 | - //be used in a closure. |
|
681 | - $request = &$this->_request; |
|
682 | - $response = &$this->_response; |
|
683 | - // $loader = &$this->loader; |
|
684 | - $this->_class_loaders = array( |
|
685 | - //load_core |
|
686 | - 'EE_Capabilities' => 'load_core', |
|
687 | - 'EE_Encryption' => 'load_core', |
|
688 | - 'EE_Front_Controller' => 'load_core', |
|
689 | - 'EE_Module_Request_Router' => 'load_core', |
|
690 | - 'EE_Registry' => 'load_core', |
|
691 | - 'EE_Request' => function () use (&$request) { |
|
692 | - return $request; |
|
693 | - }, |
|
694 | - 'EE_Response' => function () use (&$response) { |
|
695 | - return $response; |
|
696 | - }, |
|
697 | - 'EE_Request_Handler' => 'load_core', |
|
698 | - 'EE_Session' => 'load_core', |
|
699 | - 'EE_Cron_Tasks' => 'load_core', |
|
700 | - 'EE_System' => 'load_core', |
|
701 | - 'EE_Maintenance_Mode' => 'load_core', |
|
702 | - 'EE_Register_CPTs' => 'load_core', |
|
703 | - 'EE_Admin' => 'load_core', |
|
704 | - //load_lib |
|
705 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
706 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
707 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
708 | - 'EE_Messenger_Collection' => 'load_lib', |
|
709 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
710 | - 'EE_Messages_Processor' => 'load_lib', |
|
711 | - 'EE_Message_Repository' => 'load_lib', |
|
712 | - 'EE_Messages_Queue' => 'load_lib', |
|
713 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
714 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
715 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
716 | - 'EE_Messages_Generator' => function () { |
|
717 | - return EE_Registry::instance()->load_lib( |
|
718 | - 'Messages_Generator', |
|
719 | - array(), |
|
720 | - false, |
|
721 | - false |
|
722 | - ); |
|
723 | - }, |
|
724 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
725 | - return EE_Registry::instance()->load_lib( |
|
726 | - 'Messages_Template_Defaults', |
|
727 | - $arguments, |
|
728 | - false, |
|
729 | - false |
|
730 | - ); |
|
731 | - }, |
|
732 | - //load_model |
|
733 | - // 'EEM_Attendee' => 'load_model', |
|
734 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
735 | - // 'EEM_Message_Template' => 'load_model', |
|
736 | - //load_helper |
|
737 | - 'EEH_Parse_Shortcodes' => function () { |
|
738 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
739 | - return new EEH_Parse_Shortcodes(); |
|
740 | - } |
|
741 | - return null; |
|
742 | - }, |
|
743 | - 'EE_Template_Config' => function () { |
|
744 | - return EE_Config::instance()->template_settings; |
|
745 | - }, |
|
746 | - 'EE_Currency_Config' => function () { |
|
747 | - return EE_Config::instance()->currency; |
|
748 | - }, |
|
749 | - 'EE_Registration_Config' => function () { |
|
750 | - return EE_Config::instance()->registration; |
|
751 | - }, |
|
752 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
753 | - return LoaderFactory::getLoader(); |
|
754 | - }, |
|
755 | - ); |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * can be used for supplying alternate names for classes, |
|
762 | - * or for connecting interface names to instantiable classes |
|
763 | - */ |
|
764 | - protected function _register_core_aliases() |
|
765 | - { |
|
766 | - $this->_aliases = array( |
|
767 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
768 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
769 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
770 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
771 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
772 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
773 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
774 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
775 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
776 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
777 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
778 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
779 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
780 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
781 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
782 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
783 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
784 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
785 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
786 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
787 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
788 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
789 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
790 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
791 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
792 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
793 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
794 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
795 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
796 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
797 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
798 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
799 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
800 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
801 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
802 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
803 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
804 | - ); |
|
805 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
806 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
807 | - } |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
814 | - * request Primarily used by unit tests. |
|
815 | - * |
|
816 | - * @throws InvalidDataTypeException |
|
817 | - * @throws InvalidInterfaceException |
|
818 | - * @throws InvalidArgumentException |
|
819 | - */ |
|
820 | - public function reset() |
|
821 | - { |
|
822 | - $this->_register_core_class_loaders(); |
|
823 | - $this->_register_core_dependencies(); |
|
824 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | + */ |
|
33 | + const load_new_object = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | + */ |
|
39 | + const load_from_cache = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * When registering a dependency, |
|
43 | + * this indicates to keep any existing dependencies that already exist, |
|
44 | + * and simply discard any new dependencies declared in the incoming data |
|
45 | + */ |
|
46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * When registering a dependency, |
|
50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | + */ |
|
52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @type EE_Dependency_Map $_instance |
|
58 | + */ |
|
59 | + protected static $_instance; |
|
60 | + |
|
61 | + /** |
|
62 | + * @type EE_Request $request |
|
63 | + */ |
|
64 | + protected $_request; |
|
65 | + |
|
66 | + /** |
|
67 | + * @type EE_Response $response |
|
68 | + */ |
|
69 | + protected $_response; |
|
70 | + |
|
71 | + /** |
|
72 | + * @type LoaderInterface $loader |
|
73 | + */ |
|
74 | + protected $loader; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type array $_dependency_map |
|
78 | + */ |
|
79 | + protected $_dependency_map = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * @type array $_class_loaders |
|
83 | + */ |
|
84 | + protected $_class_loaders = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * @type array $_aliases |
|
88 | + */ |
|
89 | + protected $_aliases = array(); |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * EE_Dependency_Map constructor. |
|
95 | + * |
|
96 | + * @param EE_Request $request |
|
97 | + * @param EE_Response $response |
|
98 | + */ |
|
99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | + { |
|
101 | + $this->_request = $request; |
|
102 | + $this->_response = $response; |
|
103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | + do_action('EE_Dependency_Map____construct'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + */ |
|
114 | + public function initialize() |
|
115 | + { |
|
116 | + $this->_register_core_dependencies(); |
|
117 | + $this->_register_core_class_loaders(); |
|
118 | + $this->_register_core_aliases(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @singleton method used to instantiate class object |
|
125 | + * @access public |
|
126 | + * @param EE_Request $request |
|
127 | + * @param EE_Response $response |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | + { |
|
132 | + // check if class object is instantiated, and instantiated properly |
|
133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | + } |
|
136 | + return self::$_instance; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param LoaderInterface $loader |
|
143 | + */ |
|
144 | + public function setLoader(LoaderInterface $loader) |
|
145 | + { |
|
146 | + $this->loader = $loader; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $class |
|
153 | + * @param array $dependencies |
|
154 | + * @param int $overwrite |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public static function register_dependencies( |
|
158 | + $class, |
|
159 | + array $dependencies, |
|
160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | + ) { |
|
162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | + * to the class specified by the first parameter. |
|
170 | + * IMPORTANT !!! |
|
171 | + * The order of elements in the incoming $dependencies array MUST match |
|
172 | + * the order of the constructor parameters for the class in question. |
|
173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | + * |
|
176 | + * @param string $class |
|
177 | + * @param array $dependencies |
|
178 | + * @param int $overwrite |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function registerDependencies( |
|
182 | + $class, |
|
183 | + array $dependencies, |
|
184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | + ) { |
|
186 | + $class = trim($class, '\\'); |
|
187 | + $registered = false; |
|
188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | + } |
|
191 | + // we need to make sure that any aliases used when registering a dependency |
|
192 | + // get resolved to the correct class name |
|
193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | + $alias = self::$_instance->get_alias($dependency); |
|
195 | + if ( |
|
196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | + ) { |
|
199 | + unset($dependencies[$dependency]); |
|
200 | + $dependencies[$alias] = $load_source; |
|
201 | + $registered = true; |
|
202 | + } |
|
203 | + } |
|
204 | + // now add our two lists of dependencies together. |
|
205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | + // so $dependencies is NOT overwritten because it is listed first |
|
207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | + // Union is way faster than array_merge() but should be used with caution... |
|
209 | + // especially with numerically indexed arrays |
|
210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | + // now we need to ensure that the resulting dependencies |
|
212 | + // array only has the entries that are required for the class |
|
213 | + // so first count how many dependencies were originally registered for the class |
|
214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | + // then truncate the final array to match that count |
|
218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
219 | + // otherwise just take the incoming array because nothing previously existed |
|
220 | + : $dependencies; |
|
221 | + return $registered; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $class_name |
|
228 | + * @param string $loader |
|
229 | + * @return bool |
|
230 | + * @throws DomainException |
|
231 | + */ |
|
232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | + { |
|
234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | + throw new DomainException( |
|
236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | + ); |
|
238 | + } |
|
239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | + if ( |
|
241 | + ! is_callable($loader) |
|
242 | + && ( |
|
243 | + strpos($loader, 'load_') !== 0 |
|
244 | + || ! method_exists('EE_Registry', $loader) |
|
245 | + ) |
|
246 | + ) { |
|
247 | + throw new DomainException( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $loader |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $class_name = self::$_instance->get_alias($class_name); |
|
258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | + return true; |
|
261 | + } |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function dependency_map() |
|
271 | + { |
|
272 | + return $this->_dependency_map; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | + * |
|
280 | + * @param string $class_name |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function has($class_name = '') |
|
284 | + { |
|
285 | + // all legacy models have the same dependencies |
|
286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
287 | + $class_name = 'LEGACY_MODELS'; |
|
288 | + } |
|
289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | + * |
|
297 | + * @param string $class_name |
|
298 | + * @param string $dependency |
|
299 | + * @return bool |
|
300 | + */ |
|
301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | + { |
|
303 | + // all legacy models have the same dependencies |
|
304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
305 | + $class_name = 'LEGACY_MODELS'; |
|
306 | + } |
|
307 | + $dependency = $this->get_alias($dependency); |
|
308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | + ? true |
|
310 | + : false; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | + * |
|
318 | + * @param string $class_name |
|
319 | + * @param string $dependency |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | + { |
|
324 | + // all legacy models have the same dependencies |
|
325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
326 | + $class_name = 'LEGACY_MODELS'; |
|
327 | + } |
|
328 | + $dependency = $this->get_alias($dependency); |
|
329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
331 | + : EE_Dependency_Map::not_registered; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param string $class_name |
|
338 | + * @return string | Closure |
|
339 | + */ |
|
340 | + public function class_loader($class_name) |
|
341 | + { |
|
342 | + // all legacy models use load_model() |
|
343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
344 | + return 'load_model'; |
|
345 | + } |
|
346 | + $class_name = $this->get_alias($class_name); |
|
347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function class_loaders() |
|
356 | + { |
|
357 | + return $this->_class_loaders; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * adds an alias for a classname |
|
364 | + * |
|
365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | + */ |
|
369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
370 | + { |
|
371 | + if ($for_class !== '') { |
|
372 | + if (! isset($this->_aliases[$for_class])) { |
|
373 | + $this->_aliases[$for_class] = array(); |
|
374 | + } |
|
375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | + } |
|
377 | + $this->_aliases[$class_name] = $alias; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * returns TRUE if the provided class name has an alias |
|
384 | + * |
|
385 | + * @param string $class_name |
|
386 | + * @param string $for_class |
|
387 | + * @return bool |
|
388 | + */ |
|
389 | + public function has_alias($class_name = '', $for_class = '') |
|
390 | + { |
|
391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | + || ( |
|
393 | + isset($this->_aliases[$class_name]) |
|
394 | + && ! is_array($this->_aliases[$class_name]) |
|
395 | + ); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | + * for example: |
|
404 | + * if the following two entries were added to the _aliases array: |
|
405 | + * array( |
|
406 | + * 'interface_alias' => 'some\namespace\interface' |
|
407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | + * ) |
|
409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | + * to load an instance of 'some\namespace\classname' |
|
411 | + * |
|
412 | + * @param string $class_name |
|
413 | + * @param string $for_class |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function get_alias($class_name = '', $for_class = '') |
|
417 | + { |
|
418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
419 | + return $class_name; |
|
420 | + } |
|
421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | + } |
|
424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | + * This is done by using the following class constants: |
|
433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | + */ |
|
436 | + protected function _register_core_dependencies() |
|
437 | + { |
|
438 | + $this->_dependency_map = array( |
|
439 | + 'EE_Request_Handler' => array( |
|
440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_System' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_Session' => array( |
|
450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
453 | + ), |
|
454 | + 'EE_Cart' => array( |
|
455 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_Front_Controller' => array( |
|
458 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Messenger_Collection_Loader' => array( |
|
463 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | + ), |
|
465 | + 'EE_Message_Type_Collection_Loader' => array( |
|
466 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | + ), |
|
468 | + 'EE_Message_Resource_Manager' => array( |
|
469 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
471 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_Message_Factory' => array( |
|
474 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | + ), |
|
476 | + 'EE_messages' => array( |
|
477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | + ), |
|
479 | + 'EE_Messages_Generator' => array( |
|
480 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
481 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
483 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_Messages_Processor' => array( |
|
486 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
487 | + ), |
|
488 | + 'EE_Messages_Queue' => array( |
|
489 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
490 | + ), |
|
491 | + 'EE_Messages_Template_Defaults' => array( |
|
492 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
493 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
494 | + ), |
|
495 | + 'EE_Message_To_Generate_From_Request' => array( |
|
496 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
497 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
500 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
503 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
504 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
507 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
508 | + ), |
|
509 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
510 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
511 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
514 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
517 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
520 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
523 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
529 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
532 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
535 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
538 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
539 | + ), |
|
540 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
541 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | + ), |
|
543 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
544 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | + ), |
|
546 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
547 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
550 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
551 | + ), |
|
552 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
553 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | + ), |
|
555 | + 'EE_Data_Migration_Class_Base' => array( |
|
556 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
557 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
558 | + ), |
|
559 | + 'EE_DMS_Core_4_1_0' => array( |
|
560 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_DMS_Core_4_2_0' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_3_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_4_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_5_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_6_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_7_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_8_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_9_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
596 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
600 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
603 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
606 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
609 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
610 | + ), |
|
611 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
612 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | + ), |
|
614 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
615 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | + ), |
|
617 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
618 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
619 | + ), |
|
620 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
621 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | + ), |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
624 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | + ), |
|
626 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
627 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
628 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
629 | + ), |
|
630 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
631 | + null, |
|
632 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
635 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'LEGACY_MODELS' => array( |
|
638 | + null, |
|
639 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
640 | + ), |
|
641 | + 'EE_Module_Request_Router' => array( |
|
642 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
643 | + ), |
|
644 | + 'EE_Registration_Processor' => array( |
|
645 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
650 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
651 | + ), |
|
652 | + ); |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * Registers how core classes are loaded. |
|
659 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
660 | + * 'EE_Request_Handler' => 'load_core' |
|
661 | + * 'EE_Messages_Queue' => 'load_lib' |
|
662 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
663 | + * or, if greater control is required, by providing a custom closure. For example: |
|
664 | + * 'Some_Class' => function () { |
|
665 | + * return new Some_Class(); |
|
666 | + * }, |
|
667 | + * This is required for instantiating dependencies |
|
668 | + * where an interface has been type hinted in a class constructor. For example: |
|
669 | + * 'Required_Interface' => function () { |
|
670 | + * return new A_Class_That_Implements_Required_Interface(); |
|
671 | + * }, |
|
672 | + * |
|
673 | + * @throws InvalidInterfaceException |
|
674 | + * @throws InvalidDataTypeException |
|
675 | + * @throws InvalidArgumentException |
|
676 | + */ |
|
677 | + protected function _register_core_class_loaders() |
|
678 | + { |
|
679 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
680 | + //be used in a closure. |
|
681 | + $request = &$this->_request; |
|
682 | + $response = &$this->_response; |
|
683 | + // $loader = &$this->loader; |
|
684 | + $this->_class_loaders = array( |
|
685 | + //load_core |
|
686 | + 'EE_Capabilities' => 'load_core', |
|
687 | + 'EE_Encryption' => 'load_core', |
|
688 | + 'EE_Front_Controller' => 'load_core', |
|
689 | + 'EE_Module_Request_Router' => 'load_core', |
|
690 | + 'EE_Registry' => 'load_core', |
|
691 | + 'EE_Request' => function () use (&$request) { |
|
692 | + return $request; |
|
693 | + }, |
|
694 | + 'EE_Response' => function () use (&$response) { |
|
695 | + return $response; |
|
696 | + }, |
|
697 | + 'EE_Request_Handler' => 'load_core', |
|
698 | + 'EE_Session' => 'load_core', |
|
699 | + 'EE_Cron_Tasks' => 'load_core', |
|
700 | + 'EE_System' => 'load_core', |
|
701 | + 'EE_Maintenance_Mode' => 'load_core', |
|
702 | + 'EE_Register_CPTs' => 'load_core', |
|
703 | + 'EE_Admin' => 'load_core', |
|
704 | + //load_lib |
|
705 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
706 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
707 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
708 | + 'EE_Messenger_Collection' => 'load_lib', |
|
709 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
710 | + 'EE_Messages_Processor' => 'load_lib', |
|
711 | + 'EE_Message_Repository' => 'load_lib', |
|
712 | + 'EE_Messages_Queue' => 'load_lib', |
|
713 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
714 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
715 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
716 | + 'EE_Messages_Generator' => function () { |
|
717 | + return EE_Registry::instance()->load_lib( |
|
718 | + 'Messages_Generator', |
|
719 | + array(), |
|
720 | + false, |
|
721 | + false |
|
722 | + ); |
|
723 | + }, |
|
724 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
725 | + return EE_Registry::instance()->load_lib( |
|
726 | + 'Messages_Template_Defaults', |
|
727 | + $arguments, |
|
728 | + false, |
|
729 | + false |
|
730 | + ); |
|
731 | + }, |
|
732 | + //load_model |
|
733 | + // 'EEM_Attendee' => 'load_model', |
|
734 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
735 | + // 'EEM_Message_Template' => 'load_model', |
|
736 | + //load_helper |
|
737 | + 'EEH_Parse_Shortcodes' => function () { |
|
738 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
739 | + return new EEH_Parse_Shortcodes(); |
|
740 | + } |
|
741 | + return null; |
|
742 | + }, |
|
743 | + 'EE_Template_Config' => function () { |
|
744 | + return EE_Config::instance()->template_settings; |
|
745 | + }, |
|
746 | + 'EE_Currency_Config' => function () { |
|
747 | + return EE_Config::instance()->currency; |
|
748 | + }, |
|
749 | + 'EE_Registration_Config' => function () { |
|
750 | + return EE_Config::instance()->registration; |
|
751 | + }, |
|
752 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
753 | + return LoaderFactory::getLoader(); |
|
754 | + }, |
|
755 | + ); |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * can be used for supplying alternate names for classes, |
|
762 | + * or for connecting interface names to instantiable classes |
|
763 | + */ |
|
764 | + protected function _register_core_aliases() |
|
765 | + { |
|
766 | + $this->_aliases = array( |
|
767 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
768 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
769 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
770 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
771 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
772 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
773 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
774 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
775 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
776 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
777 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
778 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
779 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
780 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
781 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
782 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
783 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
784 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
785 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
786 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
787 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
788 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
789 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
790 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
791 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
792 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
793 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
794 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
795 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
796 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
797 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
798 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
799 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
800 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
801 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
802 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
803 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
804 | + ); |
|
805 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
806 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
807 | + } |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
814 | + * request Primarily used by unit tests. |
|
815 | + * |
|
816 | + * @throws InvalidDataTypeException |
|
817 | + * @throws InvalidInterfaceException |
|
818 | + * @throws InvalidArgumentException |
|
819 | + */ |
|
820 | + public function reset() |
|
821 | + { |
|
822 | + $this->_register_core_class_loaders(); |
|
823 | + $this->_register_core_dependencies(); |
|
824 | + } |
|
825 | 825 | |
826 | 826 | |
827 | 827 | } |
@@ -21,63 +21,63 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @deprecated |
|
26 | - * @param EE_Request $request |
|
27 | - * @param EE_Response $response |
|
28 | - * @return EE_Response |
|
29 | - */ |
|
30 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
31 | - { |
|
32 | - EE_Error::doing_it_wrong( |
|
33 | - __METHOD__, |
|
34 | - esc_html__( |
|
35 | - 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - '4.9.52' |
|
39 | - ); |
|
40 | - return $response; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @deprecated |
|
46 | - * @param string $version_to_check |
|
47 | - * @param string $operator |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
51 | - { |
|
52 | - EE_Error::doing_it_wrong( |
|
53 | - __METHOD__, |
|
54 | - esc_html__( |
|
55 | - 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\RecommendedVersions::compareWordPressVersion() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
56 | - 'event_espresso' |
|
57 | - ), |
|
58 | - '4.9.52', |
|
59 | - '4.10.0' |
|
60 | - ); |
|
61 | - return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @deprecated |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function minimum_wp_version_error() |
|
71 | - { |
|
72 | - EE_Error::doing_it_wrong( |
|
73 | - __METHOD__, |
|
74 | - esc_html__( |
|
75 | - 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\RecommendedVersions::minimumWpVersionError() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
76 | - 'event_espresso' |
|
77 | - ), |
|
78 | - '4.9.52' |
|
79 | - ); |
|
80 | - } |
|
24 | + /** |
|
25 | + * @deprecated |
|
26 | + * @param EE_Request $request |
|
27 | + * @param EE_Response $response |
|
28 | + * @return EE_Response |
|
29 | + */ |
|
30 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
31 | + { |
|
32 | + EE_Error::doing_it_wrong( |
|
33 | + __METHOD__, |
|
34 | + esc_html__( |
|
35 | + 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + '4.9.52' |
|
39 | + ); |
|
40 | + return $response; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @deprecated |
|
46 | + * @param string $version_to_check |
|
47 | + * @param string $operator |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
51 | + { |
|
52 | + EE_Error::doing_it_wrong( |
|
53 | + __METHOD__, |
|
54 | + esc_html__( |
|
55 | + 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\RecommendedVersions::compareWordPressVersion() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
56 | + 'event_espresso' |
|
57 | + ), |
|
58 | + '4.9.52', |
|
59 | + '4.10.0' |
|
60 | + ); |
|
61 | + return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @deprecated |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function minimum_wp_version_error() |
|
71 | + { |
|
72 | + EE_Error::doing_it_wrong( |
|
73 | + __METHOD__, |
|
74 | + esc_html__( |
|
75 | + 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\RecommendedVersions::minimumWpVersionError() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
76 | + 'event_espresso' |
|
77 | + ), |
|
78 | + '4.9.52' |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | 83 |
@@ -19,22 +19,22 @@ |
||
19 | 19 | abstract class EE_Middleware implements EEI_Request_Decorator { |
20 | 20 | |
21 | 21 | /** |
22 | - * @deprecated |
|
22 | + * @deprecated |
|
23 | 23 | * @param EE_Request $request |
24 | 24 | * @param EE_Response $response |
25 | 25 | * @return EE_Response |
26 | 26 | */ |
27 | 27 | protected function process_request_stack( EE_Request $request, EE_Response $response ) { |
28 | - EE_Error::doing_it_wrong( |
|
29 | - __METHOD__, |
|
30 | - esc_html__( |
|
31 | - 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '4.9.52' |
|
35 | - ); |
|
36 | - return $response; |
|
37 | - } |
|
28 | + EE_Error::doing_it_wrong( |
|
29 | + __METHOD__, |
|
30 | + esc_html__( |
|
31 | + 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '4.9.52' |
|
35 | + ); |
|
36 | + return $response; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param EE_Response $response |
25 | 25 | * @return EE_Response |
26 | 26 | */ |
27 | - protected function process_request_stack( EE_Request $request, EE_Response $response ) { |
|
27 | + protected function process_request_stack(EE_Request $request, EE_Response $response) { |
|
28 | 28 | EE_Error::doing_it_wrong( |
29 | 29 | __METHOD__, |
30 | 30 | esc_html__( |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | |
16 | 16 | /** |
17 | - * @deprecated |
|
17 | + * @deprecated |
|
18 | 18 | * @param EE_Request $request |
19 | 19 | * @param EE_Response $response |
20 | 20 | * @return EE_Response |
@@ -30,56 +30,56 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
33 | - * @deprecated |
|
34 | - * @return string |
|
33 | + * @deprecated |
|
34 | + * @return string |
|
35 | 35 | */ |
36 | 36 | public function display_alpha_banner_warning() { |
37 | - EE_Error::doing_it_wrong( |
|
38 | - __METHOD__, |
|
39 | - esc_html__( |
|
40 | - 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
41 | - 'event_espresso' |
|
42 | - ), |
|
43 | - '4.9.52', |
|
44 | - '4.10.0' |
|
45 | - ); |
|
46 | - } |
|
37 | + EE_Error::doing_it_wrong( |
|
38 | + __METHOD__, |
|
39 | + esc_html__( |
|
40 | + 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
41 | + 'event_espresso' |
|
42 | + ), |
|
43 | + '4.9.52', |
|
44 | + '4.10.0' |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | 50 | /** |
51 | - * @deprecated |
|
52 | - * @return void |
|
51 | + * @deprecated |
|
52 | + * @return void |
|
53 | 53 | */ |
54 | 54 | public function alpha_banner_admin_notice() { |
55 | - EE_Error::doing_it_wrong( |
|
56 | - __METHOD__, |
|
57 | - esc_html__( |
|
58 | - 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - '4.9.52', |
|
62 | - '4.10.0' |
|
63 | - ); |
|
64 | - } |
|
55 | + EE_Error::doing_it_wrong( |
|
56 | + __METHOD__, |
|
57 | + esc_html__( |
|
58 | + 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + '4.9.52', |
|
62 | + '4.10.0' |
|
63 | + ); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | 68 | /** |
69 | - * @deprecated |
|
70 | - * @return void |
|
69 | + * @deprecated |
|
70 | + * @return void |
|
71 | 71 | */ |
72 | 72 | public function alpha_banner_warning_notice() { |
73 | - EE_Error::doing_it_wrong( |
|
74 | - __METHOD__, |
|
75 | - esc_html__( |
|
76 | - 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '4.9.52', |
|
80 | - '4.10.0' |
|
81 | - ); |
|
82 | - } |
|
73 | + EE_Error::doing_it_wrong( |
|
74 | + __METHOD__, |
|
75 | + esc_html__( |
|
76 | + 'This method is deprecated. Please use EventEspresso\core\services\request_stack\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice() instead. All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '4.9.52', |
|
80 | + '4.10.0' |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | 85 | } |
@@ -19,11 +19,11 @@ |
||
19 | 19 | * @param EE_Response $response |
20 | 20 | * @return EE_Response |
21 | 21 | */ |
22 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
22 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
23 | 23 | $this->_request = $request; |
24 | 24 | $this->_response = $response; |
25 | 25 | $this->display_alpha_banner_warning(); |
26 | - $this->_response = $this->process_request_stack( $this->_request, $this->_response ); |
|
26 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
27 | 27 | return $this->_response; |
28 | 28 | } |
29 | 29 |
@@ -18,21 +18,21 @@ |
||
18 | 18 | |
19 | 19 | |
20 | 20 | /** |
21 | - * @deprecated |
|
22 | - * @param EE_Request $request |
|
21 | + * @deprecated |
|
22 | + * @param EE_Request $request |
|
23 | 23 | * @param EE_Response $response |
24 | 24 | * @return EE_Response |
25 | 25 | */ |
26 | 26 | public function handle_request( EE_Request $request, EE_Response $response ) { |
27 | - EE_Error::doing_it_wrong( |
|
28 | - __METHOD__, |
|
29 | - esc_html__( |
|
30 | - 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - '4.9.52' |
|
34 | - ); |
|
35 | - return $response; |
|
27 | + EE_Error::doing_it_wrong( |
|
28 | + __METHOD__, |
|
29 | + esc_html__( |
|
30 | + 'All Event Espresso request stack classes have been moved to \core\services\request_stack and are now under the EventEspresso\core\services\request_stack namespace', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + '4.9.52' |
|
34 | + ); |
|
35 | + return $response; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param EE_Response $response |
24 | 24 | * @return EE_Response |
25 | 25 | */ |
26 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
26 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
27 | 27 | EE_Error::doing_it_wrong( |
28 | 28 | __METHOD__, |
29 | 29 | esc_html__( |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\request_stack\middleware\RecommendedVersions; |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -26,470 +26,470 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * This gets set in _setup_cpt |
|
31 | - * It will contain the object for the custom post type. |
|
32 | - * |
|
33 | - * @var EE_CPT_Base |
|
34 | - */ |
|
35 | - protected $_cpt_object; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - protected $_cpt_route = false; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
50 | - * //in this array we define what the custom post type for this route is. |
|
51 | - * array( |
|
52 | - * 'route_name' => 'custom_post_type_slug' |
|
53 | - * ) |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - protected $_cpt_routes = array(); |
|
58 | - |
|
29 | + /** |
|
30 | + * This gets set in _setup_cpt |
|
31 | + * It will contain the object for the custom post type. |
|
32 | + * |
|
33 | + * @var EE_CPT_Base |
|
34 | + */ |
|
35 | + protected $_cpt_object; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + protected $_cpt_route = false; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
50 | + * //in this array we define what the custom post type for this route is. |
|
51 | + * array( |
|
52 | + * 'route_name' => 'custom_post_type_slug' |
|
53 | + * ) |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + protected $_cpt_routes = array(); |
|
58 | + |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
63 | - * in this format: |
|
64 | - * array( |
|
65 | - * 'post_type_slug' => 'edit_route' |
|
66 | - * ) |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - protected $_cpt_edit_routes = array(); |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
76 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
77 | - * _cpt_model_names property should be in the following format: array( |
|
78 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
79 | - * |
|
80 | - * @var array $_cpt_model_names |
|
81 | - */ |
|
82 | - protected $_cpt_model_names = array(); |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @var EE_CPT_Base |
|
87 | - */ |
|
88 | - protected $_cpt_model_obj = false; |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
94 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
95 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
96 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
97 | - * |
|
98 | - * @var array() |
|
99 | - */ |
|
100 | - protected $_autosave_containers = array(); |
|
101 | - protected $_autosave_fields = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
105 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
106 | - * |
|
107 | - * @var array |
|
108 | - */ |
|
109 | - protected $_pagenow_map; |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
115 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
116 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
117 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
118 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
119 | - * |
|
120 | - * @access protected |
|
121 | - * @abstract |
|
122 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
123 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
132 | - * |
|
133 | - * @abstract |
|
134 | - * @access public |
|
135 | - * @param string $post_id The ID of the cpt that was trashed |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - abstract public function trash_cpt_item($post_id); |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
144 | - * |
|
145 | - * @param string $post_id theID of the cpt that was untrashed |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - abstract public function restore_cpt_item($post_id); |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
154 | - * from the db |
|
155 | - * |
|
156 | - * @param string $post_id the ID of the cpt that was deleted |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - abstract public function delete_cpt_item($post_id); |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
165 | - * |
|
166 | - * @access protected |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - protected function _before_page_setup() |
|
170 | - { |
|
171 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
172 | - $this->_cpt_routes = array_merge(array( |
|
173 | - 'create_new' => $this->page_slug, |
|
174 | - 'edit' => $this->page_slug, |
|
175 | - 'trash' => $this->page_slug, |
|
176 | - ), $this->_cpt_routes); |
|
177 | - //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
178 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
179 | - ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
180 | - : get_post_type_object($page); |
|
181 | - //tweak pagenow for page loading. |
|
182 | - if ( ! $this->_pagenow_map) { |
|
183 | - $this->_pagenow_map = array( |
|
184 | - 'create_new' => 'post-new.php', |
|
185 | - 'edit' => 'post.php', |
|
186 | - 'trash' => 'post.php', |
|
187 | - ); |
|
188 | - } |
|
189 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
190 | - //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
191 | - //get current page from autosave |
|
192 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
193 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
194 | - : null; |
|
195 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
196 | - ? $this->_req_data['current_page'] |
|
197 | - : $current_page; |
|
198 | - //autosave... make sure its only for the correct page |
|
199 | - //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
200 | - //setup autosave ajax hook |
|
201 | - //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
202 | - //} |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
209 | - * |
|
210 | - * @param WP_Screen $current_screen |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function modify_pagenow($current_screen) |
|
214 | - { |
|
215 | - global $pagenow, $hook_suffix; |
|
216 | - //possibly reset pagenow. |
|
217 | - if ( ! empty($this->_req_data['page']) |
|
218 | - && $this->_req_data['page'] == $this->page_slug |
|
219 | - && ! empty($this->_req_data['action']) |
|
220 | - && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
221 | - ) { |
|
222 | - $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
223 | - $hook_suffix = $pagenow; |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
231 | - * |
|
232 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
233 | - * automatically register the id for the post metabox as a container. |
|
234 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
235 | - * you would send along the id of a metabox container. |
|
236 | - * @return void |
|
237 | - */ |
|
238 | - protected function _register_autosave_containers($ids) |
|
239 | - { |
|
240 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
247 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
248 | - */ |
|
249 | - protected function _set_autosave_containers() |
|
250 | - { |
|
251 | - global $wp_meta_boxes; |
|
252 | - $containers = array(); |
|
253 | - if (empty($wp_meta_boxes)) { |
|
254 | - return; |
|
255 | - } |
|
256 | - $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
257 | - foreach ($current_metaboxes as $box_context) { |
|
258 | - foreach ($box_context as $box_details) { |
|
259 | - foreach ($box_details as $box) { |
|
260 | - if ( |
|
261 | - is_array($box['callback']) |
|
262 | - && ( |
|
263 | - $box['callback'][0] instanceof EE_Admin_Page |
|
264 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $containers[] = $box['id']; |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
273 | - //add hidden inputs container |
|
274 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - protected function _load_autosave_scripts_styles() |
|
280 | - { |
|
281 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
61 | + /** |
|
62 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
63 | + * in this format: |
|
64 | + * array( |
|
65 | + * 'post_type_slug' => 'edit_route' |
|
66 | + * ) |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + protected $_cpt_edit_routes = array(); |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
76 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
77 | + * _cpt_model_names property should be in the following format: array( |
|
78 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
79 | + * |
|
80 | + * @var array $_cpt_model_names |
|
81 | + */ |
|
82 | + protected $_cpt_model_names = array(); |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @var EE_CPT_Base |
|
87 | + */ |
|
88 | + protected $_cpt_model_obj = false; |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
94 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
95 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
96 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
97 | + * |
|
98 | + * @var array() |
|
99 | + */ |
|
100 | + protected $_autosave_containers = array(); |
|
101 | + protected $_autosave_fields = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
105 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
106 | + * |
|
107 | + * @var array |
|
108 | + */ |
|
109 | + protected $_pagenow_map; |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
115 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
116 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
117 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
118 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
119 | + * |
|
120 | + * @access protected |
|
121 | + * @abstract |
|
122 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
123 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
132 | + * |
|
133 | + * @abstract |
|
134 | + * @access public |
|
135 | + * @param string $post_id The ID of the cpt that was trashed |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + abstract public function trash_cpt_item($post_id); |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
144 | + * |
|
145 | + * @param string $post_id theID of the cpt that was untrashed |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + abstract public function restore_cpt_item($post_id); |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
154 | + * from the db |
|
155 | + * |
|
156 | + * @param string $post_id the ID of the cpt that was deleted |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + abstract public function delete_cpt_item($post_id); |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
165 | + * |
|
166 | + * @access protected |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + protected function _before_page_setup() |
|
170 | + { |
|
171 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
172 | + $this->_cpt_routes = array_merge(array( |
|
173 | + 'create_new' => $this->page_slug, |
|
174 | + 'edit' => $this->page_slug, |
|
175 | + 'trash' => $this->page_slug, |
|
176 | + ), $this->_cpt_routes); |
|
177 | + //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
178 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
179 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
180 | + : get_post_type_object($page); |
|
181 | + //tweak pagenow for page loading. |
|
182 | + if ( ! $this->_pagenow_map) { |
|
183 | + $this->_pagenow_map = array( |
|
184 | + 'create_new' => 'post-new.php', |
|
185 | + 'edit' => 'post.php', |
|
186 | + 'trash' => 'post.php', |
|
187 | + ); |
|
188 | + } |
|
189 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
190 | + //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
191 | + //get current page from autosave |
|
192 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
193 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
194 | + : null; |
|
195 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
196 | + ? $this->_req_data['current_page'] |
|
197 | + : $current_page; |
|
198 | + //autosave... make sure its only for the correct page |
|
199 | + //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
200 | + //setup autosave ajax hook |
|
201 | + //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
202 | + //} |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
209 | + * |
|
210 | + * @param WP_Screen $current_screen |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function modify_pagenow($current_screen) |
|
214 | + { |
|
215 | + global $pagenow, $hook_suffix; |
|
216 | + //possibly reset pagenow. |
|
217 | + if ( ! empty($this->_req_data['page']) |
|
218 | + && $this->_req_data['page'] == $this->page_slug |
|
219 | + && ! empty($this->_req_data['action']) |
|
220 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
221 | + ) { |
|
222 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
223 | + $hook_suffix = $pagenow; |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
231 | + * |
|
232 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
233 | + * automatically register the id for the post metabox as a container. |
|
234 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
235 | + * you would send along the id of a metabox container. |
|
236 | + * @return void |
|
237 | + */ |
|
238 | + protected function _register_autosave_containers($ids) |
|
239 | + { |
|
240 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
247 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
248 | + */ |
|
249 | + protected function _set_autosave_containers() |
|
250 | + { |
|
251 | + global $wp_meta_boxes; |
|
252 | + $containers = array(); |
|
253 | + if (empty($wp_meta_boxes)) { |
|
254 | + return; |
|
255 | + } |
|
256 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
257 | + foreach ($current_metaboxes as $box_context) { |
|
258 | + foreach ($box_context as $box_details) { |
|
259 | + foreach ($box_details as $box) { |
|
260 | + if ( |
|
261 | + is_array($box['callback']) |
|
262 | + && ( |
|
263 | + $box['callback'][0] instanceof EE_Admin_Page |
|
264 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $containers[] = $box['id']; |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
273 | + //add hidden inputs container |
|
274 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + protected function _load_autosave_scripts_styles() |
|
280 | + { |
|
281 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
282 | 282 | wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2 |
283 | 283 | |
284 | - //filter _autosave_containers |
|
285 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
286 | - $this->_autosave_containers, $this); |
|
287 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
288 | - $containers, $this); |
|
289 | - |
|
290 | - wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
291 | - $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
292 | - |
|
293 | - $unsaved_data_msg = array( |
|
294 | - 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | - 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
296 | - 'inputChanged' => 0, |
|
297 | - ); |
|
298 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - public function load_page_dependencies() |
|
304 | - { |
|
305 | - try { |
|
306 | - $this->_load_page_dependencies(); |
|
307 | - } catch (EE_Error $e) { |
|
308 | - $e->get_error(); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
316 | - * |
|
317 | - * @access protected |
|
318 | - * @return void |
|
319 | - */ |
|
320 | - protected function _load_page_dependencies() |
|
321 | - { |
|
322 | - //we only add stuff if this is a cpt_route! |
|
323 | - if ( ! $this->_cpt_route) { |
|
324 | - parent::_load_page_dependencies(); |
|
325 | - return; |
|
326 | - } |
|
327 | - // now let's do some automatic filters into the wp_system |
|
328 | - // and we'll check to make sure the CHILD class |
|
329 | - // automatically has the required methods in place. |
|
330 | - // the following filters are for setting all the redirects |
|
331 | - // on DEFAULT WP custom post type actions |
|
332 | - // let's add a hidden input to the post-edit form |
|
333 | - // so we know when we have to trigger our custom redirects! |
|
334 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
335 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
336 | - // inject our Admin page nav tabs... |
|
337 | - // let's make sure the nav tabs are set if they aren't already |
|
338 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
339 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
340 | - // modify the post_updated messages array |
|
341 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
342 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
343 | - // cpts use the same format for shortlinks as posts! |
|
344 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
345 | - // This basically allows us to change the title of the "publish" metabox area |
|
346 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
347 | - if ( ! empty($this->_labels['publishbox'])) { |
|
348 | - $box_label = is_array($this->_labels['publishbox']) |
|
349 | - && isset($this->_labels['publishbox'][$this->_req_action]) |
|
350 | - ? $this->_labels['publishbox'][$this->_req_action] |
|
351 | - : $this->_labels['publishbox']; |
|
352 | - add_meta_box( |
|
353 | - 'submitdiv', |
|
354 | - $box_label, |
|
355 | - 'post_submit_meta_box', |
|
356 | - $this->_cpt_routes[$this->_req_action], |
|
357 | - 'side', |
|
358 | - 'core' |
|
359 | - ); |
|
360 | - } |
|
361 | - //let's add page_templates metabox if this cpt added support for it. |
|
362 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
363 | - add_meta_box( |
|
364 | - 'page_templates', |
|
365 | - __('Page Template', 'event_espresso'), |
|
366 | - array($this, 'page_template_meta_box'), |
|
367 | - $this->_cpt_routes[$this->_req_action], |
|
368 | - 'side', |
|
369 | - 'default' |
|
370 | - ); |
|
371 | - } |
|
372 | - //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
373 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
374 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
375 | - } |
|
376 | - //add preview button |
|
377 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
378 | - //insert our own post_stati dropdown |
|
379 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
380 | - //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
381 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
382 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
383 | - } |
|
384 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
385 | - // This is also before the wp_editor for post description field. |
|
386 | - if (method_exists($this, 'edit_form_after_title')) { |
|
387 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
388 | - } |
|
389 | - /** |
|
390 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
391 | - */ |
|
392 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
393 | - parent::_load_page_dependencies(); |
|
394 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
395 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
396 | - // This is for any plugins that are doing things properly |
|
397 | - // and hooking into the load page hook for core wp cpt routes. |
|
398 | - global $pagenow; |
|
399 | - do_action('load-' . $pagenow); |
|
400 | - $this->modify_current_screen(); |
|
401 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
402 | - //we route REALLY early. |
|
403 | - try { |
|
404 | - $this->_route_admin_request(); |
|
405 | - } catch (EE_Error $e) { |
|
406 | - $e->get_error(); |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | - * route instead. |
|
416 | - * |
|
417 | - * @param string $good_protocol_url The escaped url. |
|
418 | - * @param string $original_url The original url. |
|
419 | - * @param string $_context The context sent to the esc_url method. |
|
420 | - * @return string possibly a new url for our route. |
|
421 | - */ |
|
422 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | - { |
|
424 | - $routes_to_match = array( |
|
425 | - 0 => array( |
|
426 | - 'edit.php?post_type=espresso_attendees', |
|
427 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | - ), |
|
429 | - 1 => array( |
|
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | - ), |
|
433 | - ); |
|
434 | - foreach ($routes_to_match as $route_matches) { |
|
435 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | - } |
|
438 | - } |
|
439 | - return $good_protocol_url; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Determine whether the current cpt supports page templates or not. |
|
446 | - * |
|
447 | - * @since %VER% |
|
448 | - * @param string $cpt_name The cpt slug we're checking on. |
|
449 | - * @return bool True supported, false not. |
|
450 | - */ |
|
451 | - private function _supports_page_templates($cpt_name) |
|
452 | - { |
|
453 | - |
|
454 | - $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
455 | - $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
456 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
457 | - |
|
458 | - //if the installed version of WP is > 4.7 we do some additional checks. |
|
459 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
460 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
461 | - //if there are $post_templates for this cpt, then we return false for this method because |
|
462 | - //that means we aren't going to load our page template manager and leave that up to the native |
|
463 | - //cpt template manager. |
|
464 | - $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
465 | - } |
|
466 | - |
|
467 | - return $cpt_has_support; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * Callback for the page_templates metabox selector. |
|
473 | - * |
|
474 | - * @since %VER% |
|
475 | - * @return void |
|
476 | - */ |
|
477 | - public function page_template_meta_box() |
|
478 | - { |
|
479 | - global $post; |
|
480 | - $template = ''; |
|
481 | - |
|
482 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
483 | - $page_template_count = count(get_page_templates()); |
|
484 | - } else { |
|
485 | - $page_template_count = count(get_page_templates($post)); |
|
486 | - }; |
|
487 | - |
|
488 | - if ($page_template_count) { |
|
489 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
490 | - $template = ! empty($page_template) ? $page_template : ''; |
|
491 | - } |
|
492 | - ?> |
|
284 | + //filter _autosave_containers |
|
285 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
286 | + $this->_autosave_containers, $this); |
|
287 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
288 | + $containers, $this); |
|
289 | + |
|
290 | + wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
291 | + $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
292 | + |
|
293 | + $unsaved_data_msg = array( |
|
294 | + 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | + 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
296 | + 'inputChanged' => 0, |
|
297 | + ); |
|
298 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + public function load_page_dependencies() |
|
304 | + { |
|
305 | + try { |
|
306 | + $this->_load_page_dependencies(); |
|
307 | + } catch (EE_Error $e) { |
|
308 | + $e->get_error(); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
316 | + * |
|
317 | + * @access protected |
|
318 | + * @return void |
|
319 | + */ |
|
320 | + protected function _load_page_dependencies() |
|
321 | + { |
|
322 | + //we only add stuff if this is a cpt_route! |
|
323 | + if ( ! $this->_cpt_route) { |
|
324 | + parent::_load_page_dependencies(); |
|
325 | + return; |
|
326 | + } |
|
327 | + // now let's do some automatic filters into the wp_system |
|
328 | + // and we'll check to make sure the CHILD class |
|
329 | + // automatically has the required methods in place. |
|
330 | + // the following filters are for setting all the redirects |
|
331 | + // on DEFAULT WP custom post type actions |
|
332 | + // let's add a hidden input to the post-edit form |
|
333 | + // so we know when we have to trigger our custom redirects! |
|
334 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
335 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
336 | + // inject our Admin page nav tabs... |
|
337 | + // let's make sure the nav tabs are set if they aren't already |
|
338 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
339 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
340 | + // modify the post_updated messages array |
|
341 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
342 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
343 | + // cpts use the same format for shortlinks as posts! |
|
344 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
345 | + // This basically allows us to change the title of the "publish" metabox area |
|
346 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
347 | + if ( ! empty($this->_labels['publishbox'])) { |
|
348 | + $box_label = is_array($this->_labels['publishbox']) |
|
349 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
350 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
351 | + : $this->_labels['publishbox']; |
|
352 | + add_meta_box( |
|
353 | + 'submitdiv', |
|
354 | + $box_label, |
|
355 | + 'post_submit_meta_box', |
|
356 | + $this->_cpt_routes[$this->_req_action], |
|
357 | + 'side', |
|
358 | + 'core' |
|
359 | + ); |
|
360 | + } |
|
361 | + //let's add page_templates metabox if this cpt added support for it. |
|
362 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
363 | + add_meta_box( |
|
364 | + 'page_templates', |
|
365 | + __('Page Template', 'event_espresso'), |
|
366 | + array($this, 'page_template_meta_box'), |
|
367 | + $this->_cpt_routes[$this->_req_action], |
|
368 | + 'side', |
|
369 | + 'default' |
|
370 | + ); |
|
371 | + } |
|
372 | + //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
373 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
374 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
375 | + } |
|
376 | + //add preview button |
|
377 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
378 | + //insert our own post_stati dropdown |
|
379 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
380 | + //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
381 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
382 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
383 | + } |
|
384 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
385 | + // This is also before the wp_editor for post description field. |
|
386 | + if (method_exists($this, 'edit_form_after_title')) { |
|
387 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
388 | + } |
|
389 | + /** |
|
390 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
391 | + */ |
|
392 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
393 | + parent::_load_page_dependencies(); |
|
394 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
395 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
396 | + // This is for any plugins that are doing things properly |
|
397 | + // and hooking into the load page hook for core wp cpt routes. |
|
398 | + global $pagenow; |
|
399 | + do_action('load-' . $pagenow); |
|
400 | + $this->modify_current_screen(); |
|
401 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
402 | + //we route REALLY early. |
|
403 | + try { |
|
404 | + $this->_route_admin_request(); |
|
405 | + } catch (EE_Error $e) { |
|
406 | + $e->get_error(); |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | + * route instead. |
|
416 | + * |
|
417 | + * @param string $good_protocol_url The escaped url. |
|
418 | + * @param string $original_url The original url. |
|
419 | + * @param string $_context The context sent to the esc_url method. |
|
420 | + * @return string possibly a new url for our route. |
|
421 | + */ |
|
422 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | + { |
|
424 | + $routes_to_match = array( |
|
425 | + 0 => array( |
|
426 | + 'edit.php?post_type=espresso_attendees', |
|
427 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | + ), |
|
429 | + 1 => array( |
|
430 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | + ), |
|
433 | + ); |
|
434 | + foreach ($routes_to_match as $route_matches) { |
|
435 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | + } |
|
438 | + } |
|
439 | + return $good_protocol_url; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Determine whether the current cpt supports page templates or not. |
|
446 | + * |
|
447 | + * @since %VER% |
|
448 | + * @param string $cpt_name The cpt slug we're checking on. |
|
449 | + * @return bool True supported, false not. |
|
450 | + */ |
|
451 | + private function _supports_page_templates($cpt_name) |
|
452 | + { |
|
453 | + |
|
454 | + $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
455 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
456 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
457 | + |
|
458 | + //if the installed version of WP is > 4.7 we do some additional checks. |
|
459 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
460 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
461 | + //if there are $post_templates for this cpt, then we return false for this method because |
|
462 | + //that means we aren't going to load our page template manager and leave that up to the native |
|
463 | + //cpt template manager. |
|
464 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
465 | + } |
|
466 | + |
|
467 | + return $cpt_has_support; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * Callback for the page_templates metabox selector. |
|
473 | + * |
|
474 | + * @since %VER% |
|
475 | + * @return void |
|
476 | + */ |
|
477 | + public function page_template_meta_box() |
|
478 | + { |
|
479 | + global $post; |
|
480 | + $template = ''; |
|
481 | + |
|
482 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
483 | + $page_template_count = count(get_page_templates()); |
|
484 | + } else { |
|
485 | + $page_template_count = count(get_page_templates($post)); |
|
486 | + }; |
|
487 | + |
|
488 | + if ($page_template_count) { |
|
489 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
490 | + $template = ! empty($page_template) ? $page_template : ''; |
|
491 | + } |
|
492 | + ?> |
|
493 | 493 | <p><strong><?php _e('Template') ?></strong></p> |
494 | 494 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select |
495 | 495 | name="page_template" id="page_template"> |
@@ -497,450 +497,450 @@ discard block |
||
497 | 497 | <?php page_template_dropdown($template); ?> |
498 | 498 | </select> |
499 | 499 | <?php |
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
506 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
507 | - * |
|
508 | - * @param string $return the current html |
|
509 | - * @param int $id the post id for the page |
|
510 | - * @param string $new_title What the title is |
|
511 | - * @param string $new_slug what the slug is |
|
512 | - * @return string The new html string for the permalink area |
|
513 | - */ |
|
514 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
515 | - { |
|
516 | - $post = get_post($id); |
|
517 | - if ('publish' !== get_post_status($post)) { |
|
518 | - //include shims for the `get_preview_post_link` function |
|
519 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
520 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
521 | - . get_preview_post_link($id) |
|
522 | - . '" class="button button-small">' |
|
523 | - . __('Preview', 'event_espresso') |
|
524 | - . '</a></span>' |
|
525 | - . "\n"; |
|
526 | - } |
|
527 | - return $return; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
534 | - * |
|
535 | - * @return void |
|
536 | - */ |
|
537 | - public function custom_post_stati_dropdown() |
|
538 | - { |
|
539 | - |
|
540 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
541 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
542 | - ? $statuses[$this->_cpt_model_obj->status()] |
|
543 | - : ''; |
|
544 | - $template_args = array( |
|
545 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
546 | - 'statuses' => $statuses, |
|
547 | - 'cur_status_label' => $cur_status_label, |
|
548 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
549 | - ); |
|
550 | - //we'll add a trash post status (WP doesn't add one for some reason) |
|
551 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
552 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
553 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
554 | - $template_args['statuses'] = $statuses; |
|
555 | - } |
|
556 | - |
|
557 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
558 | - EEH_Template::display_template($template, $template_args); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - public function setup_autosave_hooks() |
|
564 | - { |
|
565 | - $this->_set_autosave_containers(); |
|
566 | - $this->_load_autosave_scripts_styles(); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
573 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
574 | - * for the nonce in here, but then this method looks for two things: |
|
575 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
576 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
577 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
578 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
579 | - * template args. |
|
580 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
581 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
582 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
583 | - * $this->_template_args['data']['items'] = array( |
|
584 | - * 'event-datetime-ids' => '1,2,3'; |
|
585 | - * ); |
|
586 | - * Keep in mind the following things: |
|
587 | - * - "where" index is for the input with the id as that string. |
|
588 | - * - "what" index is what will be used for the value of that input. |
|
589 | - * |
|
590 | - * @return void |
|
591 | - */ |
|
592 | - public function do_extra_autosave_stuff() |
|
593 | - { |
|
594 | - //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
595 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
596 | - ? $this->_req_data['autosavenonce'] |
|
597 | - : null; |
|
598 | - $this->_verify_nonce($nonce, 'autosave'); |
|
599 | - //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
600 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
601 | - define('DOING_AUTOSAVE', true); |
|
602 | - } |
|
603 | - //if we made it here then the nonce checked out. Let's run our methods and actions |
|
604 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
605 | - if (method_exists($this, $autosave)) { |
|
606 | - $this->$autosave(); |
|
607 | - } else { |
|
608 | - $this->_template_args['success'] = true; |
|
609 | - } |
|
610 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
611 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
612 | - //now let's return json |
|
613 | - $this->_return_json(); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
620 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
621 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
622 | - * |
|
623 | - * @access protected |
|
624 | - * @throws EE_Error |
|
625 | - * @return void |
|
626 | - */ |
|
627 | - protected function _extend_page_config_for_cpt() |
|
628 | - { |
|
629 | - //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
630 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
631 | - return; |
|
632 | - } |
|
633 | - //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
634 | - if ( ! empty($this->_cpt_object)) { |
|
635 | - $this->_page_routes = array_merge(array( |
|
636 | - 'create_new' => '_create_new_cpt_item', |
|
637 | - 'edit' => '_edit_cpt_item', |
|
638 | - ), $this->_page_routes); |
|
639 | - $this->_page_config = array_merge(array( |
|
640 | - 'create_new' => array( |
|
641 | - 'nav' => array( |
|
642 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
643 | - 'order' => 5, |
|
644 | - ), |
|
645 | - 'require_nonce' => false, |
|
646 | - ), |
|
647 | - 'edit' => array( |
|
648 | - 'nav' => array( |
|
649 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
650 | - 'order' => 5, |
|
651 | - 'persistent' => false, |
|
652 | - 'url' => '', |
|
653 | - ), |
|
654 | - 'require_nonce' => false, |
|
655 | - ), |
|
656 | - ), |
|
657 | - $this->_page_config |
|
658 | - ); |
|
659 | - } |
|
660 | - //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
661 | - if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
662 | - return; |
|
663 | - } |
|
664 | - $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
665 | - //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
666 | - if (empty($this->_cpt_object)) { |
|
667 | - $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
668 | - $this->page_slug, $this->_req_action, get_class($this)); |
|
669 | - throw new EE_Error($msg); |
|
670 | - } |
|
671 | - if ($this->_cpt_route) { |
|
672 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
673 | - $this->_set_model_object($id); |
|
674 | - } |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
681 | - * |
|
682 | - * @access protected |
|
683 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
684 | - * @param bool $ignore_route_check |
|
685 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
689 | - { |
|
690 | - $model = null; |
|
691 | - if ( |
|
692 | - empty($this->_cpt_model_names) |
|
693 | - || ( |
|
694 | - ! $ignore_route_check |
|
695 | - && ! isset($this->_cpt_routes[$this->_req_action]) |
|
696 | - ) || ( |
|
697 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
698 | - && $this->_cpt_model_obj->ID() === $id |
|
699 | - ) |
|
700 | - ) { |
|
701 | - //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
702 | - return; |
|
703 | - } |
|
704 | - //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
705 | - if ($ignore_route_check) { |
|
706 | - $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
707 | - $post_type = get_post_type($id); |
|
708 | - if (isset($model_names[$post_type])) { |
|
709 | - $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
710 | - } |
|
711 | - } else { |
|
712 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
713 | - } |
|
714 | - if ($model instanceof EEM_Base) { |
|
715 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
716 | - } |
|
717 | - do_action( |
|
718 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
719 | - $this->_cpt_model_obj, |
|
720 | - $req_type |
|
721 | - ); |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * admin_init_global |
|
728 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
729 | - * This method executes for ALL EE Admin pages. |
|
730 | - * |
|
731 | - * @access public |
|
732 | - * @return void |
|
733 | - */ |
|
734 | - public function admin_init_global() |
|
735 | - { |
|
736 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
737 | - //its possible this is a new save so let's catch that instead |
|
738 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
739 | - $post_type = $post ? $post->post_type : false; |
|
740 | - $current_route = isset($this->_req_data['current_route']) |
|
741 | - ? $this->_req_data['current_route'] |
|
742 | - : 'shouldneverwork'; |
|
743 | - $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
744 | - ? $this->_cpt_routes[$current_route] |
|
745 | - : ''; |
|
746 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
747 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
748 | - if ($post_type === $route_to_check) { |
|
749 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
750 | - } |
|
751 | - //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
752 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
753 | - if ( ! empty($revision)) { |
|
754 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
755 | - //doing a restore? |
|
756 | - if ( ! empty($action) && $action === 'restore') { |
|
757 | - //get post for revision |
|
758 | - $rev_post = get_post($revision); |
|
759 | - $rev_parent = get_post($rev_post->post_parent); |
|
760 | - //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
761 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
762 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
763 | - //restores of revisions |
|
764 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
769 | - if ($post_type && $post_type === $route_to_check) { |
|
770 | - //$post_id, $post |
|
771 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
772 | - //$post_id |
|
773 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
774 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
775 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
776 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
777 | - } |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * Callback for the WordPress trashed_post hook. |
|
784 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
785 | - * |
|
786 | - * @param int $post_id |
|
787 | - * @throws \EE_Error |
|
788 | - */ |
|
789 | - public function before_trash_cpt_item($post_id) |
|
790 | - { |
|
791 | - $this->_set_model_object($post_id, true, 'trash'); |
|
792 | - //if our cpt object isn't existent then get out immediately. |
|
793 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
794 | - return; |
|
795 | - } |
|
796 | - $this->trash_cpt_item($post_id); |
|
797 | - } |
|
798 | - |
|
799 | - |
|
800 | - |
|
801 | - /** |
|
802 | - * Callback for the WordPress untrashed_post hook. |
|
803 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
804 | - * |
|
805 | - * @param $post_id |
|
806 | - * @throws \EE_Error |
|
807 | - */ |
|
808 | - public function before_restore_cpt_item($post_id) |
|
809 | - { |
|
810 | - $this->_set_model_object($post_id, true, 'restore'); |
|
811 | - //if our cpt object isn't existent then get out immediately. |
|
812 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
813 | - return; |
|
814 | - } |
|
815 | - $this->restore_cpt_item($post_id); |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * Callback for the WordPress after_delete_post hook. |
|
822 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
823 | - * |
|
824 | - * @param $post_id |
|
825 | - * @throws \EE_Error |
|
826 | - */ |
|
827 | - public function before_delete_cpt_item($post_id) |
|
828 | - { |
|
829 | - $this->_set_model_object($post_id, true, 'delete'); |
|
830 | - //if our cpt object isn't existent then get out immediately. |
|
831 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
832 | - return; |
|
833 | - } |
|
834 | - $this->delete_cpt_item($post_id); |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
841 | - * accordingly. |
|
842 | - * |
|
843 | - * @access public |
|
844 | - * @throws EE_Error |
|
845 | - * @return void |
|
846 | - */ |
|
847 | - public function verify_cpt_object() |
|
848 | - { |
|
849 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
850 | - // verify event object |
|
851 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
852 | - throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
853 | - 'event_espresso'), $label)); |
|
854 | - } |
|
855 | - //if auto-draft then throw an error |
|
856 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
857 | - EE_Error::overwrite_errors(); |
|
858 | - EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
859 | - $label), __FILE__, __FUNCTION__, __LINE__); |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * admin_footer_scripts_global |
|
867 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
868 | - * will apply on ALL EE_Admin pages. |
|
869 | - * |
|
870 | - * @access public |
|
871 | - * @return void |
|
872 | - */ |
|
873 | - public function admin_footer_scripts_global() |
|
874 | - { |
|
875 | - $this->_add_admin_page_ajax_loading_img(); |
|
876 | - $this->_add_admin_page_overlay(); |
|
877 | - } |
|
878 | - |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * add in any global scripts for cpt routes |
|
883 | - * |
|
884 | - * @return void |
|
885 | - */ |
|
886 | - public function load_global_scripts_styles() |
|
887 | - { |
|
888 | - parent::load_global_scripts_styles(); |
|
889 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
890 | - //setup custom post status object for localize script but only if we've got a cpt object |
|
891 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
892 | - if ( ! empty($statuses)) { |
|
893 | - //get ALL statuses! |
|
894 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
895 | - //setup object |
|
896 | - $ee_cpt_statuses = array(); |
|
897 | - foreach ($statuses as $status => $label) { |
|
898 | - $ee_cpt_statuses[$status] = array( |
|
899 | - 'label' => $label, |
|
900 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
901 | - ); |
|
902 | - } |
|
903 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
912 | - * insert/updates |
|
913 | - * |
|
914 | - * @param int $post_id ID of post being updated |
|
915 | - * @param WP_Post $post Post object from WP |
|
916 | - * @param bool $update Whether this is an update or a new save. |
|
917 | - * @return void |
|
918 | - * @throws \EE_Error |
|
919 | - */ |
|
920 | - public function insert_update($post_id, $post, $update) |
|
921 | - { |
|
922 | - //make sure that if this is a revision OR trash action that we don't do any updates! |
|
923 | - if ( |
|
924 | - isset($this->_req_data['action']) |
|
925 | - && ( |
|
926 | - $this->_req_data['action'] === 'restore' |
|
927 | - || $this->_req_data['action'] === 'trash' |
|
928 | - ) |
|
929 | - ) { |
|
930 | - return; |
|
931 | - } |
|
932 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
933 | - //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
934 | - if ($update |
|
935 | - && ( |
|
936 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
937 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
938 | - ) |
|
939 | - ) { |
|
940 | - return; |
|
941 | - } |
|
942 | - //check for autosave and update our req_data property accordingly. |
|
943 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
506 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
507 | + * |
|
508 | + * @param string $return the current html |
|
509 | + * @param int $id the post id for the page |
|
510 | + * @param string $new_title What the title is |
|
511 | + * @param string $new_slug what the slug is |
|
512 | + * @return string The new html string for the permalink area |
|
513 | + */ |
|
514 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
515 | + { |
|
516 | + $post = get_post($id); |
|
517 | + if ('publish' !== get_post_status($post)) { |
|
518 | + //include shims for the `get_preview_post_link` function |
|
519 | + require_once( EE_CORE . 'wordpress-shims.php' ); |
|
520 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
521 | + . get_preview_post_link($id) |
|
522 | + . '" class="button button-small">' |
|
523 | + . __('Preview', 'event_espresso') |
|
524 | + . '</a></span>' |
|
525 | + . "\n"; |
|
526 | + } |
|
527 | + return $return; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
534 | + * |
|
535 | + * @return void |
|
536 | + */ |
|
537 | + public function custom_post_stati_dropdown() |
|
538 | + { |
|
539 | + |
|
540 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
541 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
542 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
543 | + : ''; |
|
544 | + $template_args = array( |
|
545 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
546 | + 'statuses' => $statuses, |
|
547 | + 'cur_status_label' => $cur_status_label, |
|
548 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
549 | + ); |
|
550 | + //we'll add a trash post status (WP doesn't add one for some reason) |
|
551 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
552 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
553 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
554 | + $template_args['statuses'] = $statuses; |
|
555 | + } |
|
556 | + |
|
557 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
558 | + EEH_Template::display_template($template, $template_args); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + public function setup_autosave_hooks() |
|
564 | + { |
|
565 | + $this->_set_autosave_containers(); |
|
566 | + $this->_load_autosave_scripts_styles(); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
573 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
574 | + * for the nonce in here, but then this method looks for two things: |
|
575 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
576 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
577 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
578 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
579 | + * template args. |
|
580 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
581 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
582 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
583 | + * $this->_template_args['data']['items'] = array( |
|
584 | + * 'event-datetime-ids' => '1,2,3'; |
|
585 | + * ); |
|
586 | + * Keep in mind the following things: |
|
587 | + * - "where" index is for the input with the id as that string. |
|
588 | + * - "what" index is what will be used for the value of that input. |
|
589 | + * |
|
590 | + * @return void |
|
591 | + */ |
|
592 | + public function do_extra_autosave_stuff() |
|
593 | + { |
|
594 | + //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
595 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
596 | + ? $this->_req_data['autosavenonce'] |
|
597 | + : null; |
|
598 | + $this->_verify_nonce($nonce, 'autosave'); |
|
599 | + //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
600 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
601 | + define('DOING_AUTOSAVE', true); |
|
602 | + } |
|
603 | + //if we made it here then the nonce checked out. Let's run our methods and actions |
|
604 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
605 | + if (method_exists($this, $autosave)) { |
|
606 | + $this->$autosave(); |
|
607 | + } else { |
|
608 | + $this->_template_args['success'] = true; |
|
609 | + } |
|
610 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
611 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
612 | + //now let's return json |
|
613 | + $this->_return_json(); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
620 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
621 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
622 | + * |
|
623 | + * @access protected |
|
624 | + * @throws EE_Error |
|
625 | + * @return void |
|
626 | + */ |
|
627 | + protected function _extend_page_config_for_cpt() |
|
628 | + { |
|
629 | + //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
630 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
631 | + return; |
|
632 | + } |
|
633 | + //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
634 | + if ( ! empty($this->_cpt_object)) { |
|
635 | + $this->_page_routes = array_merge(array( |
|
636 | + 'create_new' => '_create_new_cpt_item', |
|
637 | + 'edit' => '_edit_cpt_item', |
|
638 | + ), $this->_page_routes); |
|
639 | + $this->_page_config = array_merge(array( |
|
640 | + 'create_new' => array( |
|
641 | + 'nav' => array( |
|
642 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
643 | + 'order' => 5, |
|
644 | + ), |
|
645 | + 'require_nonce' => false, |
|
646 | + ), |
|
647 | + 'edit' => array( |
|
648 | + 'nav' => array( |
|
649 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
650 | + 'order' => 5, |
|
651 | + 'persistent' => false, |
|
652 | + 'url' => '', |
|
653 | + ), |
|
654 | + 'require_nonce' => false, |
|
655 | + ), |
|
656 | + ), |
|
657 | + $this->_page_config |
|
658 | + ); |
|
659 | + } |
|
660 | + //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
661 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
662 | + return; |
|
663 | + } |
|
664 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
665 | + //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
666 | + if (empty($this->_cpt_object)) { |
|
667 | + $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
668 | + $this->page_slug, $this->_req_action, get_class($this)); |
|
669 | + throw new EE_Error($msg); |
|
670 | + } |
|
671 | + if ($this->_cpt_route) { |
|
672 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
673 | + $this->_set_model_object($id); |
|
674 | + } |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
681 | + * |
|
682 | + * @access protected |
|
683 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
684 | + * @param bool $ignore_route_check |
|
685 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
689 | + { |
|
690 | + $model = null; |
|
691 | + if ( |
|
692 | + empty($this->_cpt_model_names) |
|
693 | + || ( |
|
694 | + ! $ignore_route_check |
|
695 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
696 | + ) || ( |
|
697 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
698 | + && $this->_cpt_model_obj->ID() === $id |
|
699 | + ) |
|
700 | + ) { |
|
701 | + //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
702 | + return; |
|
703 | + } |
|
704 | + //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
705 | + if ($ignore_route_check) { |
|
706 | + $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
707 | + $post_type = get_post_type($id); |
|
708 | + if (isset($model_names[$post_type])) { |
|
709 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
710 | + } |
|
711 | + } else { |
|
712 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
713 | + } |
|
714 | + if ($model instanceof EEM_Base) { |
|
715 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
716 | + } |
|
717 | + do_action( |
|
718 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
719 | + $this->_cpt_model_obj, |
|
720 | + $req_type |
|
721 | + ); |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * admin_init_global |
|
728 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
729 | + * This method executes for ALL EE Admin pages. |
|
730 | + * |
|
731 | + * @access public |
|
732 | + * @return void |
|
733 | + */ |
|
734 | + public function admin_init_global() |
|
735 | + { |
|
736 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
737 | + //its possible this is a new save so let's catch that instead |
|
738 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
739 | + $post_type = $post ? $post->post_type : false; |
|
740 | + $current_route = isset($this->_req_data['current_route']) |
|
741 | + ? $this->_req_data['current_route'] |
|
742 | + : 'shouldneverwork'; |
|
743 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
744 | + ? $this->_cpt_routes[$current_route] |
|
745 | + : ''; |
|
746 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
747 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
748 | + if ($post_type === $route_to_check) { |
|
749 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
750 | + } |
|
751 | + //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
752 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
753 | + if ( ! empty($revision)) { |
|
754 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
755 | + //doing a restore? |
|
756 | + if ( ! empty($action) && $action === 'restore') { |
|
757 | + //get post for revision |
|
758 | + $rev_post = get_post($revision); |
|
759 | + $rev_parent = get_post($rev_post->post_parent); |
|
760 | + //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
761 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
762 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
763 | + //restores of revisions |
|
764 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
769 | + if ($post_type && $post_type === $route_to_check) { |
|
770 | + //$post_id, $post |
|
771 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
772 | + //$post_id |
|
773 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
774 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
775 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
776 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
777 | + } |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * Callback for the WordPress trashed_post hook. |
|
784 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
785 | + * |
|
786 | + * @param int $post_id |
|
787 | + * @throws \EE_Error |
|
788 | + */ |
|
789 | + public function before_trash_cpt_item($post_id) |
|
790 | + { |
|
791 | + $this->_set_model_object($post_id, true, 'trash'); |
|
792 | + //if our cpt object isn't existent then get out immediately. |
|
793 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
794 | + return; |
|
795 | + } |
|
796 | + $this->trash_cpt_item($post_id); |
|
797 | + } |
|
798 | + |
|
799 | + |
|
800 | + |
|
801 | + /** |
|
802 | + * Callback for the WordPress untrashed_post hook. |
|
803 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
804 | + * |
|
805 | + * @param $post_id |
|
806 | + * @throws \EE_Error |
|
807 | + */ |
|
808 | + public function before_restore_cpt_item($post_id) |
|
809 | + { |
|
810 | + $this->_set_model_object($post_id, true, 'restore'); |
|
811 | + //if our cpt object isn't existent then get out immediately. |
|
812 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
813 | + return; |
|
814 | + } |
|
815 | + $this->restore_cpt_item($post_id); |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * Callback for the WordPress after_delete_post hook. |
|
822 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
823 | + * |
|
824 | + * @param $post_id |
|
825 | + * @throws \EE_Error |
|
826 | + */ |
|
827 | + public function before_delete_cpt_item($post_id) |
|
828 | + { |
|
829 | + $this->_set_model_object($post_id, true, 'delete'); |
|
830 | + //if our cpt object isn't existent then get out immediately. |
|
831 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
832 | + return; |
|
833 | + } |
|
834 | + $this->delete_cpt_item($post_id); |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
841 | + * accordingly. |
|
842 | + * |
|
843 | + * @access public |
|
844 | + * @throws EE_Error |
|
845 | + * @return void |
|
846 | + */ |
|
847 | + public function verify_cpt_object() |
|
848 | + { |
|
849 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
850 | + // verify event object |
|
851 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
852 | + throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
853 | + 'event_espresso'), $label)); |
|
854 | + } |
|
855 | + //if auto-draft then throw an error |
|
856 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
857 | + EE_Error::overwrite_errors(); |
|
858 | + EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
859 | + $label), __FILE__, __FUNCTION__, __LINE__); |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * admin_footer_scripts_global |
|
867 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
868 | + * will apply on ALL EE_Admin pages. |
|
869 | + * |
|
870 | + * @access public |
|
871 | + * @return void |
|
872 | + */ |
|
873 | + public function admin_footer_scripts_global() |
|
874 | + { |
|
875 | + $this->_add_admin_page_ajax_loading_img(); |
|
876 | + $this->_add_admin_page_overlay(); |
|
877 | + } |
|
878 | + |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * add in any global scripts for cpt routes |
|
883 | + * |
|
884 | + * @return void |
|
885 | + */ |
|
886 | + public function load_global_scripts_styles() |
|
887 | + { |
|
888 | + parent::load_global_scripts_styles(); |
|
889 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
890 | + //setup custom post status object for localize script but only if we've got a cpt object |
|
891 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
892 | + if ( ! empty($statuses)) { |
|
893 | + //get ALL statuses! |
|
894 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
895 | + //setup object |
|
896 | + $ee_cpt_statuses = array(); |
|
897 | + foreach ($statuses as $status => $label) { |
|
898 | + $ee_cpt_statuses[$status] = array( |
|
899 | + 'label' => $label, |
|
900 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
901 | + ); |
|
902 | + } |
|
903 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
912 | + * insert/updates |
|
913 | + * |
|
914 | + * @param int $post_id ID of post being updated |
|
915 | + * @param WP_Post $post Post object from WP |
|
916 | + * @param bool $update Whether this is an update or a new save. |
|
917 | + * @return void |
|
918 | + * @throws \EE_Error |
|
919 | + */ |
|
920 | + public function insert_update($post_id, $post, $update) |
|
921 | + { |
|
922 | + //make sure that if this is a revision OR trash action that we don't do any updates! |
|
923 | + if ( |
|
924 | + isset($this->_req_data['action']) |
|
925 | + && ( |
|
926 | + $this->_req_data['action'] === 'restore' |
|
927 | + || $this->_req_data['action'] === 'trash' |
|
928 | + ) |
|
929 | + ) { |
|
930 | + return; |
|
931 | + } |
|
932 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
933 | + //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
934 | + if ($update |
|
935 | + && ( |
|
936 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
937 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
938 | + ) |
|
939 | + ) { |
|
940 | + return; |
|
941 | + } |
|
942 | + //check for autosave and update our req_data property accordingly. |
|
943 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
944 | 944 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
945 | 945 | |
946 | 946 | foreach ( (array) $values as $key => $value ) { |
@@ -950,527 +950,527 @@ discard block |
||
950 | 950 | |
951 | 951 | }/**/ //TODO reactivate after autosave is implemented in 4.2 |
952 | 952 | |
953 | - //take care of updating any selected page_template IF this cpt supports it. |
|
954 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
955 | - //wp version aware. |
|
956 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
957 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
958 | - } else { |
|
959 | - $post->page_template = $this->_req_data['page_template']; |
|
960 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
961 | - } |
|
962 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
963 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
964 | - } else { |
|
965 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
966 | - } |
|
967 | - } |
|
968 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
969 | - return; |
|
970 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
971 | - $this->_insert_update_cpt_item($post_id, $post); |
|
972 | - } |
|
973 | - |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
978 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
979 | - * so we don't have to check for our CPT. |
|
980 | - * |
|
981 | - * @param int $post_id ID of the post |
|
982 | - * @return void |
|
983 | - */ |
|
984 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
985 | - { |
|
986 | - //only do this if we're actually processing one of our CPTs |
|
987 | - //if our cpt object isn't existent then get out immediately. |
|
988 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
989 | - return; |
|
990 | - } |
|
991 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
992 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
993 | - //our cpts may have comments so let's take care of that too |
|
994 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1001 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1002 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1003 | - * |
|
1004 | - * @param int $post_id ID of cpt item |
|
1005 | - * @param int $revision_id ID of revision being restored |
|
1006 | - * @return void |
|
1007 | - */ |
|
1008 | - public function restore_revision($post_id, $revision_id) |
|
1009 | - { |
|
1010 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1011 | - //global action |
|
1012 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1013 | - //class specific action so you can limit hooking into a specific page. |
|
1014 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1015 | - } |
|
1016 | - |
|
1017 | - |
|
1018 | - |
|
1019 | - /** |
|
1020 | - * @see restore_revision() for details |
|
1021 | - * @param int $post_id ID of cpt item |
|
1022 | - * @param int $revision_id ID of revision for item |
|
1023 | - * @return void |
|
1024 | - */ |
|
1025 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1026 | - |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1031 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1032 | - * To fix we have to reset the current_screen using the page_slug |
|
1033 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1034 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1035 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1036 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1037 | - * |
|
1038 | - * @return void |
|
1039 | - */ |
|
1040 | - public function modify_current_screen() |
|
1041 | - { |
|
1042 | - //ONLY do this if the current page_route IS a cpt route |
|
1043 | - if ( ! $this->_cpt_route) { |
|
1044 | - return; |
|
1045 | - } |
|
1046 | - //routing things REALLY early b/c this is a cpt admin page |
|
1047 | - set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1048 | - $this->_current_screen = get_current_screen(); |
|
1049 | - $this->_current_screen->base = 'event-espresso'; |
|
1050 | - $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1051 | - /*try { |
|
953 | + //take care of updating any selected page_template IF this cpt supports it. |
|
954 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
955 | + //wp version aware. |
|
956 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
957 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
958 | + } else { |
|
959 | + $post->page_template = $this->_req_data['page_template']; |
|
960 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
961 | + } |
|
962 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
963 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
964 | + } else { |
|
965 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
966 | + } |
|
967 | + } |
|
968 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
969 | + return; |
|
970 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
971 | + $this->_insert_update_cpt_item($post_id, $post); |
|
972 | + } |
|
973 | + |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
978 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
979 | + * so we don't have to check for our CPT. |
|
980 | + * |
|
981 | + * @param int $post_id ID of the post |
|
982 | + * @return void |
|
983 | + */ |
|
984 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
985 | + { |
|
986 | + //only do this if we're actually processing one of our CPTs |
|
987 | + //if our cpt object isn't existent then get out immediately. |
|
988 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
989 | + return; |
|
990 | + } |
|
991 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
992 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
993 | + //our cpts may have comments so let's take care of that too |
|
994 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1001 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1002 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1003 | + * |
|
1004 | + * @param int $post_id ID of cpt item |
|
1005 | + * @param int $revision_id ID of revision being restored |
|
1006 | + * @return void |
|
1007 | + */ |
|
1008 | + public function restore_revision($post_id, $revision_id) |
|
1009 | + { |
|
1010 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1011 | + //global action |
|
1012 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1013 | + //class specific action so you can limit hooking into a specific page. |
|
1014 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1015 | + } |
|
1016 | + |
|
1017 | + |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * @see restore_revision() for details |
|
1021 | + * @param int $post_id ID of cpt item |
|
1022 | + * @param int $revision_id ID of revision for item |
|
1023 | + * @return void |
|
1024 | + */ |
|
1025 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1026 | + |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1031 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1032 | + * To fix we have to reset the current_screen using the page_slug |
|
1033 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1034 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1035 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1036 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1037 | + * |
|
1038 | + * @return void |
|
1039 | + */ |
|
1040 | + public function modify_current_screen() |
|
1041 | + { |
|
1042 | + //ONLY do this if the current page_route IS a cpt route |
|
1043 | + if ( ! $this->_cpt_route) { |
|
1044 | + return; |
|
1045 | + } |
|
1046 | + //routing things REALLY early b/c this is a cpt admin page |
|
1047 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1048 | + $this->_current_screen = get_current_screen(); |
|
1049 | + $this->_current_screen->base = 'event-espresso'; |
|
1050 | + $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1051 | + /*try { |
|
1052 | 1052 | $this->_route_admin_request(); |
1053 | 1053 | } catch ( EE_Error $e ) { |
1054 | 1054 | $e->get_error(); |
1055 | 1055 | }/**/ |
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1062 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1063 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1064 | - * default to be. |
|
1065 | - * |
|
1066 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1067 | - * @return string |
|
1068 | - */ |
|
1069 | - public function add_custom_editor_default_title($title) |
|
1070 | - { |
|
1071 | - return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1072 | - ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1073 | - : $title; |
|
1074 | - } |
|
1075 | - |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1080 | - * |
|
1081 | - * @param string $shortlink The already generated shortlink |
|
1082 | - * @param int $id Post ID for this item |
|
1083 | - * @param string $context The context for the link |
|
1084 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1085 | - * @return string |
|
1086 | - */ |
|
1087 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1088 | - { |
|
1089 | - if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1090 | - $post = get_post($id); |
|
1091 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1092 | - $shortlink = home_url('?p=' . $post->ID); |
|
1093 | - } |
|
1094 | - } |
|
1095 | - return $shortlink; |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1102 | - * already run in modify_current_screen()) |
|
1103 | - * |
|
1104 | - * @return void |
|
1105 | - */ |
|
1106 | - public function route_admin_request() |
|
1107 | - { |
|
1108 | - if ($this->_cpt_route) { |
|
1109 | - return; |
|
1110 | - } |
|
1111 | - try { |
|
1112 | - $this->_route_admin_request(); |
|
1113 | - } catch (EE_Error $e) { |
|
1114 | - $e->get_error(); |
|
1115 | - } |
|
1116 | - } |
|
1117 | - |
|
1118 | - |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1122 | - * |
|
1123 | - * @return void |
|
1124 | - */ |
|
1125 | - public function cpt_post_form_hidden_input() |
|
1126 | - { |
|
1127 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1128 | - //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1129 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1130 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1131 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1132 | - echo '</div>'; |
|
1133 | - } |
|
1134 | - |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1139 | - * |
|
1140 | - * @param string $location Original location url |
|
1141 | - * @param int $status Status for http header |
|
1142 | - * @return string new (or original) url to redirect to. |
|
1143 | - */ |
|
1144 | - public function revision_redirect($location, $status) |
|
1145 | - { |
|
1146 | - //get revision |
|
1147 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1148 | - //can't do anything without revision so let's get out if not present |
|
1149 | - if (empty($rev_id)) { |
|
1150 | - return $location; |
|
1151 | - } |
|
1152 | - //get rev_post_data |
|
1153 | - $rev = get_post($rev_id); |
|
1154 | - $admin_url = $this->_admin_base_url; |
|
1155 | - $query_args = array( |
|
1156 | - 'action' => 'edit', |
|
1157 | - 'post' => $rev->post_parent, |
|
1158 | - 'revision' => $rev_id, |
|
1159 | - 'message' => 5, |
|
1160 | - ); |
|
1161 | - $this->_process_notices($query_args, true); |
|
1162 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1169 | - * |
|
1170 | - * @param string $link the original generated link |
|
1171 | - * @param int $id post id |
|
1172 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1173 | - * @return string the link |
|
1174 | - */ |
|
1175 | - public function modify_edit_post_link($link, $id, $context) |
|
1176 | - { |
|
1177 | - $post = get_post($id); |
|
1178 | - if ( ! isset($this->_req_data['action']) |
|
1179 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1180 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1181 | - ) { |
|
1182 | - return $link; |
|
1183 | - } |
|
1184 | - $query_args = array( |
|
1185 | - 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1186 | - ? $this->_cpt_edit_routes[$post->post_type] |
|
1187 | - : 'edit', |
|
1188 | - 'post' => $id, |
|
1189 | - ); |
|
1190 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1191 | - } |
|
1192 | - |
|
1193 | - |
|
1194 | - /** |
|
1195 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1196 | - * our routes. |
|
1197 | - * |
|
1198 | - * @param string $delete_link original delete link |
|
1199 | - * @param int $post_id id of cpt object |
|
1200 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1201 | - * @return string new delete link |
|
1202 | - * @throws EE_Error |
|
1203 | - */ |
|
1204 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1205 | - { |
|
1206 | - $post = get_post($post_id); |
|
1207 | - |
|
1208 | - if (empty($this->_req_data['action']) |
|
1209 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1210 | - || ! $post instanceof WP_Post |
|
1211 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1212 | - ) { |
|
1213 | - return $delete_link; |
|
1214 | - } |
|
1215 | - $this->_set_model_object($post->ID, true); |
|
1216 | - |
|
1217 | - //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1218 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1219 | - |
|
1220 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1221 | - array( |
|
1222 | - 'page' => $this->_req_data['page'], |
|
1223 | - 'action' => $action, |
|
1224 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1225 | - => $post->ID |
|
1226 | - ), |
|
1227 | - admin_url() |
|
1228 | - ); |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1235 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1236 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1237 | - * |
|
1238 | - * @param string $location This is the incoming currently set redirect location |
|
1239 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1240 | - * @return string the new location to redirect to |
|
1241 | - */ |
|
1242 | - public function cpt_post_location_redirect($location, $post_id) |
|
1243 | - { |
|
1244 | - //we DO have a match so let's setup the url |
|
1245 | - //we have to get the post to determine our route |
|
1246 | - $post = get_post($post_id); |
|
1247 | - $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1248 | - //shared query_args |
|
1249 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1250 | - $admin_url = $this->_admin_base_url; |
|
1251 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1252 | - $status = get_post_status($post_id); |
|
1253 | - if (isset($this->_req_data['publish'])) { |
|
1254 | - switch ($status) { |
|
1255 | - case 'pending': |
|
1256 | - $message = 8; |
|
1257 | - break; |
|
1258 | - case 'future': |
|
1259 | - $message = 9; |
|
1260 | - break; |
|
1261 | - default: |
|
1262 | - $message = 6; |
|
1263 | - } |
|
1264 | - } else { |
|
1265 | - $message = 'draft' === $status ? 10 : 1; |
|
1266 | - } |
|
1267 | - } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1268 | - $message = 2; |
|
1269 | - // $append = '#postcustom'; |
|
1270 | - } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1271 | - $message = 3; |
|
1272 | - // $append = '#postcustom'; |
|
1273 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1274 | - $message = 7; |
|
1275 | - } else { |
|
1276 | - $message = 4; |
|
1277 | - } |
|
1278 | - //change the message if the post type is not viewable on the frontend |
|
1279 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1280 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1281 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1282 | - $this->_process_notices($query_args, true); |
|
1283 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1284 | - } |
|
1285 | - |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1290 | - * |
|
1291 | - * @access public |
|
1292 | - * @return void |
|
1293 | - */ |
|
1294 | - public function inject_nav_tabs() |
|
1295 | - { |
|
1296 | - //can we hijack and insert the nav_tabs? |
|
1297 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1298 | - //first close off existing form tag |
|
1299 | - $html = '>'; |
|
1300 | - $html .= $nav_tabs; |
|
1301 | - //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1302 | - $html .= '<span></span'; |
|
1303 | - echo $html; |
|
1304 | - } |
|
1305 | - |
|
1306 | - |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * This just sets up the post update messages when an update form is loaded |
|
1310 | - * |
|
1311 | - * @access public |
|
1312 | - * @param array $messages the original messages array |
|
1313 | - * @return array the new messages array |
|
1314 | - */ |
|
1315 | - public function post_update_messages($messages) |
|
1316 | - { |
|
1317 | - global $post; |
|
1318 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1319 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1320 | - // $post_type = $post ? $post->post_type : false; |
|
1321 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1062 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1063 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1064 | + * default to be. |
|
1065 | + * |
|
1066 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1067 | + * @return string |
|
1068 | + */ |
|
1069 | + public function add_custom_editor_default_title($title) |
|
1070 | + { |
|
1071 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1072 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1073 | + : $title; |
|
1074 | + } |
|
1075 | + |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1080 | + * |
|
1081 | + * @param string $shortlink The already generated shortlink |
|
1082 | + * @param int $id Post ID for this item |
|
1083 | + * @param string $context The context for the link |
|
1084 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1085 | + * @return string |
|
1086 | + */ |
|
1087 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1088 | + { |
|
1089 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1090 | + $post = get_post($id); |
|
1091 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1092 | + $shortlink = home_url('?p=' . $post->ID); |
|
1093 | + } |
|
1094 | + } |
|
1095 | + return $shortlink; |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1102 | + * already run in modify_current_screen()) |
|
1103 | + * |
|
1104 | + * @return void |
|
1105 | + */ |
|
1106 | + public function route_admin_request() |
|
1107 | + { |
|
1108 | + if ($this->_cpt_route) { |
|
1109 | + return; |
|
1110 | + } |
|
1111 | + try { |
|
1112 | + $this->_route_admin_request(); |
|
1113 | + } catch (EE_Error $e) { |
|
1114 | + $e->get_error(); |
|
1115 | + } |
|
1116 | + } |
|
1117 | + |
|
1118 | + |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1122 | + * |
|
1123 | + * @return void |
|
1124 | + */ |
|
1125 | + public function cpt_post_form_hidden_input() |
|
1126 | + { |
|
1127 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1128 | + //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1129 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1130 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1131 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1132 | + echo '</div>'; |
|
1133 | + } |
|
1134 | + |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1139 | + * |
|
1140 | + * @param string $location Original location url |
|
1141 | + * @param int $status Status for http header |
|
1142 | + * @return string new (or original) url to redirect to. |
|
1143 | + */ |
|
1144 | + public function revision_redirect($location, $status) |
|
1145 | + { |
|
1146 | + //get revision |
|
1147 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1148 | + //can't do anything without revision so let's get out if not present |
|
1149 | + if (empty($rev_id)) { |
|
1150 | + return $location; |
|
1151 | + } |
|
1152 | + //get rev_post_data |
|
1153 | + $rev = get_post($rev_id); |
|
1154 | + $admin_url = $this->_admin_base_url; |
|
1155 | + $query_args = array( |
|
1156 | + 'action' => 'edit', |
|
1157 | + 'post' => $rev->post_parent, |
|
1158 | + 'revision' => $rev_id, |
|
1159 | + 'message' => 5, |
|
1160 | + ); |
|
1161 | + $this->_process_notices($query_args, true); |
|
1162 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1169 | + * |
|
1170 | + * @param string $link the original generated link |
|
1171 | + * @param int $id post id |
|
1172 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1173 | + * @return string the link |
|
1174 | + */ |
|
1175 | + public function modify_edit_post_link($link, $id, $context) |
|
1176 | + { |
|
1177 | + $post = get_post($id); |
|
1178 | + if ( ! isset($this->_req_data['action']) |
|
1179 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1180 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1181 | + ) { |
|
1182 | + return $link; |
|
1183 | + } |
|
1184 | + $query_args = array( |
|
1185 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1186 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1187 | + : 'edit', |
|
1188 | + 'post' => $id, |
|
1189 | + ); |
|
1190 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1191 | + } |
|
1192 | + |
|
1193 | + |
|
1194 | + /** |
|
1195 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1196 | + * our routes. |
|
1197 | + * |
|
1198 | + * @param string $delete_link original delete link |
|
1199 | + * @param int $post_id id of cpt object |
|
1200 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1201 | + * @return string new delete link |
|
1202 | + * @throws EE_Error |
|
1203 | + */ |
|
1204 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1205 | + { |
|
1206 | + $post = get_post($post_id); |
|
1207 | + |
|
1208 | + if (empty($this->_req_data['action']) |
|
1209 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1210 | + || ! $post instanceof WP_Post |
|
1211 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1212 | + ) { |
|
1213 | + return $delete_link; |
|
1214 | + } |
|
1215 | + $this->_set_model_object($post->ID, true); |
|
1216 | + |
|
1217 | + //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1218 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1219 | + |
|
1220 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1221 | + array( |
|
1222 | + 'page' => $this->_req_data['page'], |
|
1223 | + 'action' => $action, |
|
1224 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1225 | + => $post->ID |
|
1226 | + ), |
|
1227 | + admin_url() |
|
1228 | + ); |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1235 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1236 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1237 | + * |
|
1238 | + * @param string $location This is the incoming currently set redirect location |
|
1239 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1240 | + * @return string the new location to redirect to |
|
1241 | + */ |
|
1242 | + public function cpt_post_location_redirect($location, $post_id) |
|
1243 | + { |
|
1244 | + //we DO have a match so let's setup the url |
|
1245 | + //we have to get the post to determine our route |
|
1246 | + $post = get_post($post_id); |
|
1247 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1248 | + //shared query_args |
|
1249 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1250 | + $admin_url = $this->_admin_base_url; |
|
1251 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1252 | + $status = get_post_status($post_id); |
|
1253 | + if (isset($this->_req_data['publish'])) { |
|
1254 | + switch ($status) { |
|
1255 | + case 'pending': |
|
1256 | + $message = 8; |
|
1257 | + break; |
|
1258 | + case 'future': |
|
1259 | + $message = 9; |
|
1260 | + break; |
|
1261 | + default: |
|
1262 | + $message = 6; |
|
1263 | + } |
|
1264 | + } else { |
|
1265 | + $message = 'draft' === $status ? 10 : 1; |
|
1266 | + } |
|
1267 | + } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1268 | + $message = 2; |
|
1269 | + // $append = '#postcustom'; |
|
1270 | + } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1271 | + $message = 3; |
|
1272 | + // $append = '#postcustom'; |
|
1273 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1274 | + $message = 7; |
|
1275 | + } else { |
|
1276 | + $message = 4; |
|
1277 | + } |
|
1278 | + //change the message if the post type is not viewable on the frontend |
|
1279 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1280 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1281 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1282 | + $this->_process_notices($query_args, true); |
|
1283 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1284 | + } |
|
1285 | + |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1290 | + * |
|
1291 | + * @access public |
|
1292 | + * @return void |
|
1293 | + */ |
|
1294 | + public function inject_nav_tabs() |
|
1295 | + { |
|
1296 | + //can we hijack and insert the nav_tabs? |
|
1297 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1298 | + //first close off existing form tag |
|
1299 | + $html = '>'; |
|
1300 | + $html .= $nav_tabs; |
|
1301 | + //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1302 | + $html .= '<span></span'; |
|
1303 | + echo $html; |
|
1304 | + } |
|
1305 | + |
|
1306 | + |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * This just sets up the post update messages when an update form is loaded |
|
1310 | + * |
|
1311 | + * @access public |
|
1312 | + * @param array $messages the original messages array |
|
1313 | + * @return array the new messages array |
|
1314 | + */ |
|
1315 | + public function post_update_messages($messages) |
|
1316 | + { |
|
1317 | + global $post; |
|
1318 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1319 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1320 | + // $post_type = $post ? $post->post_type : false; |
|
1321 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1322 | 1322 | |
1323 | 1323 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1324 | - $messages[$post->post_type] = array( |
|
1325 | - 0 => '', //Unused. Messages start at index 1. |
|
1326 | - 1 => sprintf( |
|
1327 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1328 | - $this->_cpt_object->labels->singular_name, |
|
1329 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1330 | - '</a>' |
|
1331 | - ), |
|
1332 | - 2 => __('Custom field updated'), |
|
1333 | - 3 => __('Custom field deleted.'), |
|
1334 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1335 | - 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1336 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1337 | - : false, |
|
1338 | - 6 => sprintf( |
|
1339 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1340 | - $this->_cpt_object->labels->singular_name, |
|
1341 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1342 | - '</a>' |
|
1343 | - ), |
|
1344 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1345 | - 8 => sprintf( |
|
1346 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1347 | - $this->_cpt_object->labels->singular_name, |
|
1348 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1349 | - '</a>' |
|
1350 | - ), |
|
1351 | - 9 => sprintf( |
|
1352 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1353 | - $this->_cpt_object->labels->singular_name, |
|
1354 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1355 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1356 | - '</a>' |
|
1357 | - ), |
|
1358 | - 10 => sprintf( |
|
1359 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1360 | - $this->_cpt_object->labels->singular_name, |
|
1361 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1362 | - '</a>' |
|
1363 | - ), |
|
1364 | - ); |
|
1365 | - return $messages; |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * default method for the 'create_new' route for cpt admin pages. |
|
1372 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1373 | - * |
|
1374 | - * @access protected |
|
1375 | - * @return void |
|
1376 | - */ |
|
1377 | - protected function _create_new_cpt_item() |
|
1378 | - { |
|
1379 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1380 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1381 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1382 | - $post_type_object = $this->_cpt_object; |
|
1383 | - $title = $post_type_object->labels->add_new_item; |
|
1384 | - $editing = true; |
|
1385 | - wp_enqueue_script('autosave'); |
|
1386 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1387 | - $post_ID = $post->ID; |
|
1388 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1389 | - //modify the default editor title field with default title. |
|
1390 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1391 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1392 | - } |
|
1393 | - |
|
1394 | - |
|
1395 | - |
|
1396 | - public function add_new_admin_page_global() |
|
1397 | - { |
|
1398 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1399 | - ?> |
|
1324 | + $messages[$post->post_type] = array( |
|
1325 | + 0 => '', //Unused. Messages start at index 1. |
|
1326 | + 1 => sprintf( |
|
1327 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1328 | + $this->_cpt_object->labels->singular_name, |
|
1329 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1330 | + '</a>' |
|
1331 | + ), |
|
1332 | + 2 => __('Custom field updated'), |
|
1333 | + 3 => __('Custom field deleted.'), |
|
1334 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1335 | + 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1336 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1337 | + : false, |
|
1338 | + 6 => sprintf( |
|
1339 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1340 | + $this->_cpt_object->labels->singular_name, |
|
1341 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1342 | + '</a>' |
|
1343 | + ), |
|
1344 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1345 | + 8 => sprintf( |
|
1346 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1347 | + $this->_cpt_object->labels->singular_name, |
|
1348 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1349 | + '</a>' |
|
1350 | + ), |
|
1351 | + 9 => sprintf( |
|
1352 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1353 | + $this->_cpt_object->labels->singular_name, |
|
1354 | + '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1355 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1356 | + '</a>' |
|
1357 | + ), |
|
1358 | + 10 => sprintf( |
|
1359 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1360 | + $this->_cpt_object->labels->singular_name, |
|
1361 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1362 | + '</a>' |
|
1363 | + ), |
|
1364 | + ); |
|
1365 | + return $messages; |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * default method for the 'create_new' route for cpt admin pages. |
|
1372 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1373 | + * |
|
1374 | + * @access protected |
|
1375 | + * @return void |
|
1376 | + */ |
|
1377 | + protected function _create_new_cpt_item() |
|
1378 | + { |
|
1379 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1380 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1381 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1382 | + $post_type_object = $this->_cpt_object; |
|
1383 | + $title = $post_type_object->labels->add_new_item; |
|
1384 | + $editing = true; |
|
1385 | + wp_enqueue_script('autosave'); |
|
1386 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1387 | + $post_ID = $post->ID; |
|
1388 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1389 | + //modify the default editor title field with default title. |
|
1390 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1391 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1392 | + } |
|
1393 | + |
|
1394 | + |
|
1395 | + |
|
1396 | + public function add_new_admin_page_global() |
|
1397 | + { |
|
1398 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1399 | + ?> |
|
1400 | 1400 | <script type="text/javascript"> |
1401 | 1401 | adminpage = '<?php echo $admin_page; ?>'; |
1402 | 1402 | </script> |
1403 | 1403 | <?php |
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - |
|
1408 | - /** |
|
1409 | - * default method for the 'edit' route for cpt admin pages |
|
1410 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1411 | - * |
|
1412 | - * @access protected |
|
1413 | - * @return string template for edit cpt form |
|
1414 | - */ |
|
1415 | - protected function _edit_cpt_item() |
|
1416 | - { |
|
1417 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1418 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1419 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1420 | - if (empty ($post)) { |
|
1421 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1422 | - } |
|
1423 | - if ( ! empty($_GET['get-post-lock'])) { |
|
1424 | - wp_set_post_lock($post_id); |
|
1425 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1426 | - exit(); |
|
1427 | - } |
|
1428 | - |
|
1429 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1430 | - $editing = true; |
|
1431 | - $post_ID = $post_id; |
|
1432 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1433 | - $post_type_object = $this->_cpt_object; |
|
1434 | - |
|
1435 | - if ( ! wp_check_post_lock($post->ID)) { |
|
1436 | - $active_post_lock = wp_set_post_lock($post->ID); |
|
1437 | - //wp_enqueue_script('autosave'); |
|
1438 | - } |
|
1439 | - $title = $this->_cpt_object->labels->edit_item; |
|
1440 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1441 | - if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1442 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1443 | - ) { |
|
1444 | - $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1445 | - 'create_new', $this); |
|
1446 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1447 | - 'action' => $create_new_action, |
|
1448 | - 'page' => $this->page_slug, |
|
1449 | - ), 'admin.php'); |
|
1450 | - } |
|
1451 | - if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1452 | - wp_enqueue_script('admin-comments'); |
|
1453 | - enqueue_comment_hotkeys_js(); |
|
1454 | - } |
|
1455 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1456 | - //modify the default editor title field with default title. |
|
1457 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1458 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1459 | - } |
|
1460 | - |
|
1461 | - |
|
1462 | - |
|
1463 | - /** |
|
1464 | - * some getters |
|
1465 | - */ |
|
1466 | - /** |
|
1467 | - * This returns the protected _cpt_model_obj property |
|
1468 | - * |
|
1469 | - * @return EE_CPT_Base |
|
1470 | - */ |
|
1471 | - public function get_cpt_model_obj() |
|
1472 | - { |
|
1473 | - return $this->_cpt_model_obj; |
|
1474 | - } |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + |
|
1408 | + /** |
|
1409 | + * default method for the 'edit' route for cpt admin pages |
|
1410 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1411 | + * |
|
1412 | + * @access protected |
|
1413 | + * @return string template for edit cpt form |
|
1414 | + */ |
|
1415 | + protected function _edit_cpt_item() |
|
1416 | + { |
|
1417 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1418 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1419 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1420 | + if (empty ($post)) { |
|
1421 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1422 | + } |
|
1423 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1424 | + wp_set_post_lock($post_id); |
|
1425 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1426 | + exit(); |
|
1427 | + } |
|
1428 | + |
|
1429 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1430 | + $editing = true; |
|
1431 | + $post_ID = $post_id; |
|
1432 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1433 | + $post_type_object = $this->_cpt_object; |
|
1434 | + |
|
1435 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1436 | + $active_post_lock = wp_set_post_lock($post->ID); |
|
1437 | + //wp_enqueue_script('autosave'); |
|
1438 | + } |
|
1439 | + $title = $this->_cpt_object->labels->edit_item; |
|
1440 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1441 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1442 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1443 | + ) { |
|
1444 | + $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1445 | + 'create_new', $this); |
|
1446 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1447 | + 'action' => $create_new_action, |
|
1448 | + 'page' => $this->page_slug, |
|
1449 | + ), 'admin.php'); |
|
1450 | + } |
|
1451 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1452 | + wp_enqueue_script('admin-comments'); |
|
1453 | + enqueue_comment_hotkeys_js(); |
|
1454 | + } |
|
1455 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1456 | + //modify the default editor title field with default title. |
|
1457 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1458 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1459 | + } |
|
1460 | + |
|
1461 | + |
|
1462 | + |
|
1463 | + /** |
|
1464 | + * some getters |
|
1465 | + */ |
|
1466 | + /** |
|
1467 | + * This returns the protected _cpt_model_obj property |
|
1468 | + * |
|
1469 | + * @return EE_CPT_Base |
|
1470 | + */ |
|
1471 | + public function get_cpt_model_obj() |
|
1472 | + { |
|
1473 | + return $this->_cpt_model_obj; |
|
1474 | + } |
|
1475 | 1475 | |
1476 | 1476 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | protected function _register_autosave_containers($ids) |
239 | 239 | { |
240 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
240 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | //filter _autosave_containers |
285 | 285 | $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
286 | 286 | $this->_autosave_containers, $this); |
287 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
287 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
288 | 288 | $containers, $this); |
289 | 289 | |
290 | 290 | wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | // This is for any plugins that are doing things properly |
397 | 397 | // and hooking into the load page hook for core wp cpt routes. |
398 | 398 | global $pagenow; |
399 | - do_action('load-' . $pagenow); |
|
399 | + do_action('load-'.$pagenow); |
|
400 | 400 | $this->modify_current_screen(); |
401 | 401 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
402 | 402 | //we route REALLY early. |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | 'admin.php?page=espresso_registrations&action=contact_list', |
428 | 428 | ), |
429 | 429 | 1 => array( |
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
430 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
431 | + 'admin.php?page='.$this->_cpt_object->name, |
|
432 | 432 | ), |
433 | 433 | ); |
434 | 434 | foreach ($routes_to_match as $route_matches) { |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
457 | 457 | |
458 | 458 | //if the installed version of WP is > 4.7 we do some additional checks. |
459 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
459 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
460 | 460 | $post_templates = wp_get_theme()->get_post_templates(); |
461 | 461 | //if there are $post_templates for this cpt, then we return false for this method because |
462 | 462 | //that means we aren't going to load our page template manager and leave that up to the native |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | global $post; |
480 | 480 | $template = ''; |
481 | 481 | |
482 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
482 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
483 | 483 | $page_template_count = count(get_page_templates()); |
484 | 484 | } else { |
485 | 485 | $page_template_count = count(get_page_templates($post)); |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | $post = get_post($id); |
517 | 517 | if ('publish' !== get_post_status($post)) { |
518 | 518 | //include shims for the `get_preview_post_link` function |
519 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
519 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
520 | 520 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
521 | 521 | . get_preview_post_link($id) |
522 | 522 | . '" class="button button-small">' |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $template_args['statuses'] = $statuses; |
555 | 555 | } |
556 | 556 | |
557 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
557 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
558 | 558 | EEH_Template::display_template($template, $template_args); |
559 | 559 | } |
560 | 560 | |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | $this->_template_args['success'] = true; |
609 | 609 | } |
610 | 610 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
611 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
611 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
612 | 612 | //now let's return json |
613 | 613 | $this->_return_json(); |
614 | 614 | } |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | //global action |
1012 | 1012 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1013 | 1013 | //class specific action so you can limit hooking into a specific page. |
1014 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1014 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | |
@@ -1089,7 +1089,7 @@ discard block |
||
1089 | 1089 | if ( ! empty($id) && get_option('permalink_structure') !== '') { |
1090 | 1090 | $post = get_post($id); |
1091 | 1091 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1092 | - $shortlink = home_url('?p=' . $post->ID); |
|
1092 | + $shortlink = home_url('?p='.$post->ID); |
|
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | return $shortlink; |
@@ -1124,11 +1124,11 @@ discard block |
||
1124 | 1124 | */ |
1125 | 1125 | public function cpt_post_form_hidden_input() |
1126 | 1126 | { |
1127 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1127 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1128 | 1128 | //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1129 | 1129 | echo '<div id="ee-cpt-hidden-inputs">'; |
1130 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1131 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1130 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1131 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1132 | 1132 | echo '</div>'; |
1133 | 1133 | } |
1134 | 1134 | |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | $this->_set_model_object($post->ID, true); |
1216 | 1216 | |
1217 | 1217 | //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1218 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1218 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1219 | 1219 | |
1220 | 1220 | return EE_Admin_Page::add_query_args_and_nonce( |
1221 | 1221 | array( |
@@ -1326,39 +1326,39 @@ discard block |
||
1326 | 1326 | 1 => sprintf( |
1327 | 1327 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1328 | 1328 | $this->_cpt_object->labels->singular_name, |
1329 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1329 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1330 | 1330 | '</a>' |
1331 | 1331 | ), |
1332 | 1332 | 2 => __('Custom field updated'), |
1333 | 1333 | 3 => __('Custom field deleted.'), |
1334 | 1334 | 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1335 | 1335 | 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
1336 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1336 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false)) |
|
1337 | 1337 | : false, |
1338 | 1338 | 6 => sprintf( |
1339 | 1339 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1340 | 1340 | $this->_cpt_object->labels->singular_name, |
1341 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1341 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1342 | 1342 | '</a>' |
1343 | 1343 | ), |
1344 | 1344 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1345 | 1345 | 8 => sprintf( |
1346 | 1346 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1347 | 1347 | $this->_cpt_object->labels->singular_name, |
1348 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1348 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1349 | 1349 | '</a>' |
1350 | 1350 | ), |
1351 | 1351 | 9 => sprintf( |
1352 | 1352 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1353 | 1353 | $this->_cpt_object->labels->singular_name, |
1354 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1355 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1354 | + '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>', |
|
1355 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1356 | 1356 | '</a>' |
1357 | 1357 | ), |
1358 | 1358 | 10 => sprintf( |
1359 | 1359 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1360 | 1360 | $this->_cpt_object->labels->singular_name, |
1361 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1361 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1362 | 1362 | '</a>' |
1363 | 1363 | ), |
1364 | 1364 | ); |
@@ -1388,7 +1388,7 @@ discard block |
||
1388 | 1388 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1389 | 1389 | //modify the default editor title field with default title. |
1390 | 1390 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
1391 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1391 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1392 | 1392 | } |
1393 | 1393 | |
1394 | 1394 | |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1456 | 1456 | //modify the default editor title field with default title. |
1457 | 1457 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
1458 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1458 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 |
@@ -23,142 +23,142 @@ |
||
23 | 23 | class RecommendedVersions extends Middleware |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * converts a Request to a Response |
|
28 | - * |
|
29 | - * @param EE_Request $request |
|
30 | - * @param EE_Response $response |
|
31 | - * @return EE_Response |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - */ |
|
34 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
35 | - { |
|
36 | - $this->request = $request; |
|
37 | - $this->response = $response; |
|
38 | - // check required WP version |
|
39 | - if (! $this->minimumWordPressVersionRequired()) { |
|
40 | - $this->request->un_set('activate', true); |
|
41 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
42 | - $this->response->terminate_request(); |
|
43 | - $this->response->deactivate_plugin(); |
|
44 | - } |
|
45 | - // check recommended PHP version |
|
46 | - if (! $this->minimumPhpVersionRecommended()) { |
|
47 | - $this->displayMinimumRecommendedPhpVersionNotice(); |
|
48 | - } |
|
49 | - $this->response = $this->process_request_stack($this->request, $this->response); |
|
50 | - return $this->response; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Helper method to assess installed wp version against given values. |
|
56 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
57 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
58 | - * against) so consider that when sending in your values. |
|
59 | - * |
|
60 | - * @param string $version_to_check |
|
61 | - * @param string $operator |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
65 | - { |
|
66 | - global $wp_version; |
|
67 | - return version_compare( |
|
68 | - // first account for wp_version being pre-release |
|
69 | - // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
70 | - strpos($wp_version, '-') > 0 |
|
71 | - ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
72 | - : $wp_version, |
|
73 | - $version_to_check, |
|
74 | - $operator |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return boolean |
|
82 | - */ |
|
83 | - private function minimumWordPressVersionRequired() |
|
84 | - { |
|
85 | - return RecommendedVersions::compareWordPressVersion(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $min_version |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
95 | - { |
|
96 | - return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return boolean |
|
103 | - */ |
|
104 | - private function minimumPhpVersionRecommended() |
|
105 | - { |
|
106 | - return $this->checkPhpVersion(); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function minimumWpVersionError() |
|
115 | - { |
|
116 | - global $wp_version; |
|
117 | - ?> |
|
26 | + /** |
|
27 | + * converts a Request to a Response |
|
28 | + * |
|
29 | + * @param EE_Request $request |
|
30 | + * @param EE_Response $response |
|
31 | + * @return EE_Response |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + */ |
|
34 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
35 | + { |
|
36 | + $this->request = $request; |
|
37 | + $this->response = $response; |
|
38 | + // check required WP version |
|
39 | + if (! $this->minimumWordPressVersionRequired()) { |
|
40 | + $this->request->un_set('activate', true); |
|
41 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
42 | + $this->response->terminate_request(); |
|
43 | + $this->response->deactivate_plugin(); |
|
44 | + } |
|
45 | + // check recommended PHP version |
|
46 | + if (! $this->minimumPhpVersionRecommended()) { |
|
47 | + $this->displayMinimumRecommendedPhpVersionNotice(); |
|
48 | + } |
|
49 | + $this->response = $this->process_request_stack($this->request, $this->response); |
|
50 | + return $this->response; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Helper method to assess installed wp version against given values. |
|
56 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
57 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
58 | + * against) so consider that when sending in your values. |
|
59 | + * |
|
60 | + * @param string $version_to_check |
|
61 | + * @param string $operator |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
65 | + { |
|
66 | + global $wp_version; |
|
67 | + return version_compare( |
|
68 | + // first account for wp_version being pre-release |
|
69 | + // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
70 | + strpos($wp_version, '-') > 0 |
|
71 | + ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
72 | + : $wp_version, |
|
73 | + $version_to_check, |
|
74 | + $operator |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return boolean |
|
82 | + */ |
|
83 | + private function minimumWordPressVersionRequired() |
|
84 | + { |
|
85 | + return RecommendedVersions::compareWordPressVersion(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $min_version |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
95 | + { |
|
96 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return boolean |
|
103 | + */ |
|
104 | + private function minimumPhpVersionRecommended() |
|
105 | + { |
|
106 | + return $this->checkPhpVersion(); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function minimumWpVersionError() |
|
115 | + { |
|
116 | + global $wp_version; |
|
117 | + ?> |
|
118 | 118 | <div class="error"> |
119 | 119 | <p> |
120 | 120 | <?php |
121 | - printf( |
|
122 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
123 | - 'event_espresso'), |
|
124 | - EE_MIN_WP_VER_REQUIRED, |
|
125 | - $wp_version, |
|
126 | - '<br/>', |
|
127 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
128 | - ); |
|
129 | - ?> |
|
121 | + printf( |
|
122 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
123 | + 'event_espresso'), |
|
124 | + EE_MIN_WP_VER_REQUIRED, |
|
125 | + $wp_version, |
|
126 | + '<br/>', |
|
127 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
128 | + ); |
|
129 | + ?> |
|
130 | 130 | </p> |
131 | 131 | </div> |
132 | 132 | <?php |
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * _display_minimum_recommended_php_version_notice |
|
139 | - * |
|
140 | - * @access private |
|
141 | - * @return void |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - */ |
|
144 | - private function displayMinimumRecommendedPhpVersionNotice() |
|
145 | - { |
|
146 | - if ($this->request->isAdmin()) { |
|
147 | - new PersistentAdminNotice( |
|
148 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
149 | - sprintf( |
|
150 | - esc_html__( |
|
151 | - 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
|
152 | - 'event_espresso' |
|
153 | - ), |
|
154 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
155 | - PHP_VERSION, |
|
156 | - '<br/>', |
|
157 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
158 | - ) |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * _display_minimum_recommended_php_version_notice |
|
139 | + * |
|
140 | + * @access private |
|
141 | + * @return void |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + */ |
|
144 | + private function displayMinimumRecommendedPhpVersionNotice() |
|
145 | + { |
|
146 | + if ($this->request->isAdmin()) { |
|
147 | + new PersistentAdminNotice( |
|
148 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
149 | + sprintf( |
|
150 | + esc_html__( |
|
151 | + 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
|
152 | + 'event_espresso' |
|
153 | + ), |
|
154 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
155 | + PHP_VERSION, |
|
156 | + '<br/>', |
|
157 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
158 | + ) |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | // Location: RecommendedVersions.php |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | $this->request = $request; |
37 | 37 | $this->response = $response; |
38 | 38 | // check required WP version |
39 | - if (! $this->minimumWordPressVersionRequired()) { |
|
39 | + if ( ! $this->minimumWordPressVersionRequired()) { |
|
40 | 40 | $this->request->un_set('activate', true); |
41 | 41 | add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
42 | 42 | $this->response->terminate_request(); |
43 | 43 | $this->response->deactivate_plugin(); |
44 | 44 | } |
45 | 45 | // check recommended PHP version |
46 | - if (! $this->minimumPhpVersionRecommended()) { |
|
46 | + if ( ! $this->minimumPhpVersionRecommended()) { |
|
47 | 47 | $this->displayMinimumRecommendedPhpVersionNotice(); |
48 | 48 | } |
49 | 49 | $this->response = $this->process_request_stack($this->request, $this->response); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | if ($this->request->isAdmin()) { |
147 | 147 | new PersistentAdminNotice( |
148 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
148 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
149 | 149 | sprintf( |
150 | 150 | esc_html__( |
151 | 151 | 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
@@ -21,24 +21,24 @@ |
||
21 | 21 | class BotDetector extends Middleware |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * converts a Request to a Response |
|
26 | - * |
|
27 | - * @param EE_Request $request |
|
28 | - * @param EE_Response $response |
|
29 | - * @return EE_Response |
|
30 | - */ |
|
31 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
32 | - { |
|
33 | - $this->request = $request; |
|
34 | - $this->response = $response; |
|
35 | - $CrawlerDetect = new CrawlerDetect; |
|
36 | - // Check and record the user agent of the current 'visitor' |
|
37 | - $this->request->setIsBot($CrawlerDetect->isCrawler()); |
|
38 | - $this->request->setUserAgent($CrawlerDetect->userAgent()); |
|
39 | - $this->response = $this->process_request_stack($this->request, $this->response); |
|
40 | - return $this->response; |
|
41 | - } |
|
24 | + /** |
|
25 | + * converts a Request to a Response |
|
26 | + * |
|
27 | + * @param EE_Request $request |
|
28 | + * @param EE_Response $response |
|
29 | + * @return EE_Response |
|
30 | + */ |
|
31 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
32 | + { |
|
33 | + $this->request = $request; |
|
34 | + $this->response = $response; |
|
35 | + $CrawlerDetect = new CrawlerDetect; |
|
36 | + // Check and record the user agent of the current 'visitor' |
|
37 | + $this->request->setIsBot($CrawlerDetect->isCrawler()); |
|
38 | + $this->request->setUserAgent($CrawlerDetect->userAgent()); |
|
39 | + $this->response = $this->process_request_stack($this->request, $this->response); |
|
40 | + return $this->response; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | // Location: BotDetector.php |
@@ -28,49 +28,49 @@ |
||
28 | 28 | abstract class Middleware implements EEI_Request_Decorator |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @type EEI_Request_Decorator $request_stack |
|
33 | - */ |
|
34 | - protected $request_stack; |
|
35 | - |
|
36 | - /** |
|
37 | - * @type EE_Request $request |
|
38 | - */ |
|
39 | - protected $request; |
|
40 | - |
|
41 | - /** |
|
42 | - * @type EE_Response $response |
|
43 | - */ |
|
44 | - protected $response; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param \EEI_Request_Decorator $request_stack |
|
50 | - */ |
|
51 | - public function __construct(EEI_Request_Decorator $request_stack) |
|
52 | - { |
|
53 | - $this->request_stack = $request_stack; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * process_request_stack |
|
60 | - * |
|
61 | - * @param EE_Request $request |
|
62 | - * @param EE_Response $response |
|
63 | - * @return EE_Response |
|
64 | - */ |
|
65 | - protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
66 | - { |
|
67 | - $this->request = $request; |
|
68 | - $this->response = $response; |
|
69 | - if (! $this->response->request_terminated()) { |
|
70 | - $this->response = $this->request_stack->handle_request($this->request, $this->response); |
|
71 | - } |
|
72 | - return $this->response; |
|
73 | - } |
|
31 | + /** |
|
32 | + * @type EEI_Request_Decorator $request_stack |
|
33 | + */ |
|
34 | + protected $request_stack; |
|
35 | + |
|
36 | + /** |
|
37 | + * @type EE_Request $request |
|
38 | + */ |
|
39 | + protected $request; |
|
40 | + |
|
41 | + /** |
|
42 | + * @type EE_Response $response |
|
43 | + */ |
|
44 | + protected $response; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param \EEI_Request_Decorator $request_stack |
|
50 | + */ |
|
51 | + public function __construct(EEI_Request_Decorator $request_stack) |
|
52 | + { |
|
53 | + $this->request_stack = $request_stack; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * process_request_stack |
|
60 | + * |
|
61 | + * @param EE_Request $request |
|
62 | + * @param EE_Response $response |
|
63 | + * @return EE_Response |
|
64 | + */ |
|
65 | + protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
66 | + { |
|
67 | + $this->request = $request; |
|
68 | + $this->response = $response; |
|
69 | + if (! $this->response->request_terminated()) { |
|
70 | + $this->response = $this->request_stack->handle_request($this->request, $this->response); |
|
71 | + } |
|
72 | + return $this->response; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | 76 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | { |
67 | 67 | $this->request = $request; |
68 | 68 | $this->response = $response; |
69 | - if (! $this->response->request_terminated()) { |
|
69 | + if ( ! $this->response->request_terminated()) { |
|
70 | 70 | $this->response = $this->request_stack->handle_request($this->request, $this->response); |
71 | 71 | } |
72 | 72 | return $this->response; |