@@ -222,7 +222,7 @@ |
||
222 | 222 | /** |
223 | 223 | * constructor |
224 | 224 | * |
225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
225 | + * @param EE_Admin_Page $adminpage the calling admin_page_object |
|
226 | 226 | */ |
227 | 227 | public function __construct(EE_Admin_Page $adminpage) |
228 | 228 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -28,729 +28,729 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $caller; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
42 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
43 | - * used later to make sure we require the needed files. |
|
44 | - * |
|
45 | - * @var bool |
|
46 | - */ |
|
47 | - protected $_extend; |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_name; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
62 | - * array( |
|
63 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
64 | - * ) |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_ajax_func; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
73 | - * array( |
|
74 | - * 'page_route' => 'executing_method' //must be public |
|
75 | - * ) |
|
76 | - * |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - protected $_init_func; |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
85 | - * array( |
|
86 | - * 0 => array( |
|
87 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
88 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
89 | - * will be added to each route. |
|
90 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
91 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
92 | - * method arguments. |
|
93 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
94 | - * automatically) |
|
95 | - * 'priority' => 'default', //default 'default' (optional) |
|
96 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
97 | - * 'context' => 'advanced' //advanced is default (optional), |
|
98 | - * 'callback_args' => array() //any callback args to include (optional) |
|
99 | - * ) |
|
100 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
101 | - * |
|
102 | - * @var array |
|
103 | - */ |
|
104 | - protected $_metaboxes; |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
110 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
111 | - * array: array( |
|
112 | - * 0 => array( |
|
113 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
114 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
115 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
116 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
117 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
118 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
119 | - * id for the screen the metabox is on. |
|
120 | - * ) |
|
121 | - * ) |
|
122 | - * |
|
123 | - * @var array |
|
124 | - */ |
|
125 | - protected $_remove_metaboxes; |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
131 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
132 | - * second array index is for indicating what routes each script/style loads on. array( |
|
133 | - * 'registers' => array( |
|
134 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
135 | - * argument to link scripts together. |
|
136 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
137 | - * 'url' => 'http://urltoscript.css.js', |
|
138 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
139 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
140 | - * gets loaded before the one you are setting here. |
|
141 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
142 | - * ), |
|
143 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
144 | - * the script gets enqueued on. |
|
145 | - * 'script_ref' => array('route_one', 'route_two') |
|
146 | - * ), |
|
147 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
148 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
149 | - * the object. |
|
150 | - * 'scrip_ref' => array( |
|
151 | - * 'NAME_OF_JS_OBJECT' => array( |
|
152 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
153 | - * 'some_data' => 5 |
|
154 | - * ) |
|
155 | - * ) |
|
156 | - * ) |
|
157 | - * ) |
|
158 | - * |
|
159 | - * @var array |
|
160 | - */ |
|
161 | - protected $_scripts_styles; |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * This is a property that will contain the current route. |
|
166 | - * |
|
167 | - * @var string; |
|
168 | - */ |
|
169 | - protected $_current_route; |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
175 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
176 | - * 'wp_hook_reference' => 1 |
|
177 | - * ) |
|
178 | - * ) |
|
179 | - * |
|
180 | - * @var array |
|
181 | - */ |
|
182 | - protected $_wp_action_filters_priority; |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
188 | - * |
|
189 | - * @var array |
|
190 | - */ |
|
191 | - protected $_req_data; |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This just holds an instance of the page object for this hook |
|
197 | - * |
|
198 | - * @var EE_Admin_Page |
|
199 | - */ |
|
200 | - protected $_page_object; |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
206 | - * |
|
207 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
208 | - */ |
|
209 | - protected $_adminpage_obj; |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Holds EE_Registry object |
|
215 | - * |
|
216 | - * @var EE_Registry |
|
217 | - */ |
|
218 | - protected $EE = null; |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * constructor |
|
224 | - * |
|
225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
226 | - */ |
|
227 | - public function __construct(EE_Admin_Page $adminpage) |
|
228 | - { |
|
229 | - |
|
230 | - $this->_adminpage_obj = $adminpage; |
|
231 | - $this->_req_data = array_merge($_GET, $_POST); |
|
232 | - $this->_set_defaults(); |
|
233 | - $this->_set_hooks_properties(); |
|
234 | - //first let's verify we're on the right page |
|
235 | - if (! isset($this->_req_data['page']) |
|
236 | - || (isset($this->_req_data['page']) |
|
237 | - && $this->_adminpage_obj->page_slug |
|
238 | - != $this->_req_data['page'])) { |
|
239 | - return; |
|
240 | - } //get out nothing more to be done here. |
|
241 | - //allow for extends to modify properties |
|
242 | - if (method_exists($this, '_extend_properties')) { |
|
243 | - $this->_extend_properties(); |
|
244 | - } |
|
245 | - $this->_set_page_object(); |
|
246 | - $this->_init_hooks(); |
|
247 | - $this->_load_custom_methods(); |
|
248 | - $this->_load_routed_hooks(); |
|
249 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
250 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
251 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
252 | - $this->_ajax_hooks(); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * used by child classes to set the following properties: |
|
259 | - * $_ajax_func (optional) |
|
260 | - * $_init_func (optional) |
|
261 | - * $_metaboxes (optional) |
|
262 | - * $_scripts (optional) |
|
263 | - * $_styles (optional) |
|
264 | - * $_name (required) |
|
265 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
266 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
267 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
268 | - * |
|
269 | - * @access protected |
|
270 | - * @abstract |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - abstract protected function _set_hooks_properties(); |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
279 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
280 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
281 | - * |
|
282 | - * @access public |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - public function enqueue_scripts_styles() |
|
286 | - { |
|
287 | - |
|
288 | - if (! empty($this->_scripts_styles)) { |
|
289 | - //first let's do all the registrations |
|
290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
291 | - $msg[] = __( |
|
292 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
293 | - 'event_espresso' |
|
294 | - ); |
|
295 | - $msg[] = sprintf( |
|
296 | - __( |
|
297 | - 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - '<strong>' . $this->caller . '</strong>' |
|
301 | - ); |
|
302 | - throw new EE_Error(implode('||', $msg)); |
|
303 | - } |
|
304 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
305 | - $defaults = array( |
|
306 | - 'type' => 'js', |
|
307 | - 'url' => '', |
|
308 | - 'depends' => array(), |
|
309 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
310 | - 'footer' => true, |
|
311 | - ); |
|
312 | - $details = wp_parse_args($details, $defaults); |
|
313 | - extract($details); |
|
314 | - //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
315 | - $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
316 | - //let's make sure we're not missing any REQUIRED parameters |
|
317 | - if (empty($url)) { |
|
318 | - $msg[] = sprintf( |
|
319 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
320 | - $type == 'js' ? 'script' : 'stylesheet' |
|
321 | - ); |
|
322 | - $msg[] = sprintf( |
|
323 | - __( |
|
324 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
325 | - 'event_espresso' |
|
326 | - ), |
|
327 | - '<strong>' . $this->caller . '</strong>', |
|
328 | - $ref |
|
329 | - ); |
|
330 | - throw new EE_Error(implode('||', $msg)); |
|
331 | - } |
|
332 | - //made it here so let's do the appropriate registration |
|
333 | - $type == 'js' |
|
334 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
335 | - : wp_register_style( |
|
336 | - $ref, |
|
337 | - $url, |
|
338 | - $depends, |
|
339 | - $version |
|
340 | - ); |
|
341 | - } |
|
342 | - //k now lets do the enqueues |
|
343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
344 | - return; |
|
345 | - } //not sure if we should throw an error here or not. |
|
346 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
347 | - //make sure $routes is an array |
|
348 | - $routes = (array)$routes; |
|
349 | - if (in_array($this->_current_route, $routes)) { |
|
350 | - $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
351 | - : wp_enqueue_style($ref); |
|
352 | - //if we have a localization for the script let's do that too. |
|
353 | - if (isset($this->_scripts_styles['localize'][$ref])) { |
|
354 | - foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
355 | - wp_localize_script( |
|
356 | - $ref, |
|
357 | - $object_name, |
|
358 | - $this->_scripts_styles['localize'][$ref][$object_name] |
|
359 | - ); |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - //let's do the deregisters |
|
365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
366 | - return; |
|
367 | - } |
|
368 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
369 | - $defaults = array( |
|
370 | - 'type' => 'js', |
|
371 | - ); |
|
372 | - $details = wp_parse_args($details, $defaults); |
|
373 | - extract($details); |
|
374 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
375 | - } |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * just set the defaults for the hooks properties. |
|
383 | - * |
|
384 | - * @access private |
|
385 | - * @return void |
|
386 | - */ |
|
387 | - private function _set_defaults() |
|
388 | - { |
|
389 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
390 | - $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
391 | - $this->caller = get_class($this); |
|
392 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * this sets the _page_object property |
|
399 | - * |
|
400 | - * @access protected |
|
401 | - * @return void |
|
402 | - */ |
|
403 | - protected function _set_page_object() |
|
404 | - { |
|
405 | - //first make sure $this->_name is set |
|
406 | - if (empty($this->_name)) { |
|
407 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
408 | - $msg[] = sprintf( |
|
409 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
410 | - $this->caller |
|
411 | - ); |
|
412 | - throw new EE_Error(implode('||', $msg)); |
|
413 | - } |
|
414 | - $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
416 | - //first default file (if exists) |
|
417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
418 | - if (is_readable($decaf_file)) { |
|
419 | - require_once($decaf_file); |
|
420 | - } |
|
421 | - //now we have to do require for extended file (if needed) |
|
422 | - if ($this->_extend) { |
|
423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
424 | - } |
|
425 | - //if we've got an extended class we use that! |
|
426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
427 | - //let's make sure the class exists |
|
428 | - if (! class_exists($ref)) { |
|
429 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
430 | - $msg[] = sprintf( |
|
431 | - __( |
|
432 | - 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
433 | - 'event_espresso' |
|
434 | - ), |
|
435 | - $ref |
|
436 | - ); |
|
437 | - throw new EE_Error(implode('||', $msg)); |
|
438 | - } |
|
439 | - $a = new ReflectionClass($ref); |
|
440 | - $this->_page_object = $a->newInstance(false); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
446 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
447 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
448 | - * |
|
449 | - * @access private |
|
450 | - * @return void |
|
451 | - */ |
|
452 | - private function _load_custom_methods() |
|
453 | - { |
|
454 | - /** |
|
455 | - * method cannot be named 'default' (@see http://us3.php |
|
456 | - * .net/manual/en/reserved.keywords.php) so need to |
|
457 | - * handle routes that are "default" |
|
458 | - * |
|
459 | - * @since 4.3.0 |
|
460 | - */ |
|
461 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
462 | - //these run before the Admin_Page route executes. |
|
463 | - if (method_exists($this, $method_callback)) { |
|
464 | - call_user_func(array($this, $method_callback)); |
|
465 | - } |
|
466 | - //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
467 | - //first the actions |
|
468 | - //note that these action hooks will have the $query_args value available. |
|
469 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
471 | - add_action( |
|
472 | - 'AHEE__' |
|
473 | - . $admin_class_name |
|
474 | - . '___redirect_after_action__before_redirect_modification_' |
|
475 | - . $this->_current_route, |
|
476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
477 | - 10 |
|
478 | - ); |
|
479 | - } |
|
480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
481 | - add_action( |
|
482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
484 | - 10 |
|
485 | - ); |
|
486 | - } |
|
487 | - //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
489 | - add_filter( |
|
490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
492 | - 10, |
|
493 | - 2 |
|
494 | - ); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
502 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
503 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
504 | - * |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - private function _load_routed_hooks() |
|
508 | - { |
|
509 | - |
|
510 | - //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
511 | - $hook_filter_array = array( |
|
512 | - 'admin_footer' => array( |
|
513 | - 'type' => 'action', |
|
514 | - 'argnum' => 1, |
|
515 | - 'priority' => 10, |
|
516 | - ), |
|
517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
518 | - 'type' => 'filter', |
|
519 | - 'argnum' => 1, |
|
520 | - 'priority' => 10, |
|
521 | - ), |
|
522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
523 | - 'type' => 'filter', |
|
524 | - 'argnum' => 1, |
|
525 | - 'priority' => 10, |
|
526 | - ), |
|
527 | - 'FHEE_list_table_views' => array( |
|
528 | - 'type' => 'filter', |
|
529 | - 'argnum' => 1, |
|
530 | - 'priority' => 10, |
|
531 | - ), |
|
532 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
533 | - 'type' => 'action', |
|
534 | - 'argnum' => 1, |
|
535 | - 'priority' => 10, |
|
536 | - ), |
|
537 | - ); |
|
538 | - foreach ($hook_filter_array as $hook => $args) { |
|
539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
540 | - if (isset($this->_wp_action_filters_priority[$hook])) { |
|
541 | - $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
542 | - } |
|
543 | - if ($args['type'] == 'action') { |
|
544 | - add_action( |
|
545 | - $hook, |
|
546 | - array($this, $this->_current_route . '_' . $hook), |
|
547 | - $args['priority'], |
|
548 | - $args['argnum'] |
|
549 | - ); |
|
550 | - } else { |
|
551 | - add_filter( |
|
552 | - $hook, |
|
553 | - array($this, $this->_current_route . '_' . $hook), |
|
554 | - $args['priority'], |
|
555 | - $args['argnum'] |
|
556 | - ); |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
565 | - * |
|
566 | - * @return void |
|
567 | - */ |
|
568 | - private function _ajax_hooks() |
|
569 | - { |
|
570 | - |
|
571 | - if (empty($this->_ajax_func)) { |
|
572 | - return; |
|
573 | - } //get out there's nothing to take care of. |
|
574 | - foreach ($this->_ajax_func as $action => $method) { |
|
575 | - //make sure method exists |
|
576 | - if (! method_exists($this, $method)) { |
|
577 | - $msg[] = __( |
|
578 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
579 | - 'event_espresso' |
|
580 | - ) . '<br />'; |
|
581 | - $msg[] = sprintf( |
|
582 | - __( |
|
583 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
584 | - 'event_espresso' |
|
585 | - ), |
|
586 | - $method, |
|
587 | - $this->caller |
|
588 | - ); |
|
589 | - throw new EE_Error(implode('||', $msg)); |
|
590 | - } |
|
591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Loop throught the $_init_func array and add_actions for the array. |
|
599 | - * |
|
600 | - * @return void |
|
601 | - */ |
|
602 | - protected function _init_hooks() |
|
603 | - { |
|
604 | - if (empty($this->_init_func)) { |
|
605 | - return; |
|
606 | - } //get out there's nothing to take care of. |
|
607 | - //We need to determine what page_route we are on! |
|
608 | - $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
609 | - foreach ($this->_init_func as $route => $method) { |
|
610 | - //make sure method exists |
|
611 | - if (! method_exists($this, $method)) { |
|
612 | - $msg[] = __( |
|
613 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
614 | - 'event_espresso' |
|
615 | - ) . '<br />'; |
|
616 | - $msg[] = sprintf( |
|
617 | - __( |
|
618 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
619 | - 'event_espresso' |
|
620 | - ), |
|
621 | - $method, |
|
622 | - $this->caller |
|
623 | - ); |
|
624 | - throw new EE_Error(implode('||', $msg)); |
|
625 | - } |
|
626 | - if ($route == $this->_current_route) { |
|
627 | - add_action('admin_init', array($this, $method)); |
|
628 | - } |
|
629 | - } |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
636 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
637 | - * |
|
638 | - * @access public |
|
639 | - * @return void |
|
640 | - */ |
|
641 | - public function add_metaboxes() |
|
642 | - { |
|
643 | - if (empty($this->_metaboxes)) { |
|
644 | - return; |
|
645 | - } //get out we don't have any metaboxes to set for this connection |
|
646 | - $this->_handle_metabox_array($this->_metaboxes); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - private function _handle_metabox_array($boxes, $add = true) |
|
652 | - { |
|
653 | - |
|
654 | - foreach ($boxes as $box) { |
|
655 | - if (! isset($box['page_route'])) { |
|
656 | - continue; |
|
657 | - } //we dont' have a valid array |
|
658 | - //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
659 | - $box['page_route'] = (array)$box['page_route']; |
|
660 | - foreach ($box['page_route'] as $route) { |
|
661 | - if ($route != $this->_current_route) { |
|
662 | - continue; |
|
663 | - } //get out we only add metaboxes for set route. |
|
664 | - if ($add) { |
|
665 | - $this->_add_metabox($box); |
|
666 | - } else { |
|
667 | - $this->_remove_metabox($box); |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
677 | - * |
|
678 | - * @access public |
|
679 | - * @return void |
|
680 | - */ |
|
681 | - public function remove_metaboxes() |
|
682 | - { |
|
683 | - |
|
684 | - if (empty($this->_remove_metaboxes)) { |
|
685 | - return; |
|
686 | - } //get out there are no metaboxes to remove |
|
687 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * This just handles adding a metabox |
|
693 | - * |
|
694 | - * @access private |
|
695 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
696 | - */ |
|
697 | - private function _add_metabox($args) |
|
698 | - { |
|
699 | - $current_screen = get_current_screen(); |
|
700 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
701 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
702 | - //set defaults |
|
703 | - $defaults = array( |
|
704 | - 'func' => $func, |
|
705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
706 | - 'priority' => 'default', |
|
707 | - 'label' => $this->caller, |
|
708 | - 'context' => 'advanced', |
|
709 | - 'callback_args' => array(), |
|
710 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
711 | - ); |
|
712 | - $args = wp_parse_args($args, $defaults); |
|
713 | - extract($args); |
|
714 | - //make sure method exists |
|
715 | - if (! method_exists($this, $func)) { |
|
716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
717 | - $msg[] = sprintf( |
|
718 | - __( |
|
719 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
720 | - 'event_espresso' |
|
721 | - ), |
|
722 | - $func, |
|
723 | - $this->caller |
|
724 | - ); |
|
725 | - throw new EE_Error(implode('||', $msg)); |
|
726 | - } |
|
727 | - //everything checks out so lets add the metabox |
|
728 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - |
|
733 | - private function _remove_metabox($args) |
|
734 | - { |
|
735 | - $current_screen = get_current_screen(); |
|
736 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
737 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
738 | - //set defaults |
|
739 | - $defaults = array( |
|
740 | - 'id' => isset($args['id']) |
|
741 | - ? $args['id'] |
|
742 | - : $this->_current_route |
|
743 | - . '_' |
|
744 | - . $this->caller |
|
745 | - . '_' |
|
746 | - . $func |
|
747 | - . '_metabox', |
|
748 | - 'context' => 'default', |
|
749 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
750 | - ); |
|
751 | - $args = wp_parse_args($args, $defaults); |
|
752 | - extract($args); |
|
753 | - //everything checks out so lets remove the box! |
|
754 | - remove_meta_box($id, $screen, $context); |
|
755 | - } |
|
31 | + /** |
|
32 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $caller; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
42 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
43 | + * used later to make sure we require the needed files. |
|
44 | + * |
|
45 | + * @var bool |
|
46 | + */ |
|
47 | + protected $_extend; |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_name; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
62 | + * array( |
|
63 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
64 | + * ) |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_ajax_func; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
73 | + * array( |
|
74 | + * 'page_route' => 'executing_method' //must be public |
|
75 | + * ) |
|
76 | + * |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + protected $_init_func; |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
85 | + * array( |
|
86 | + * 0 => array( |
|
87 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
88 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
89 | + * will be added to each route. |
|
90 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
91 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
92 | + * method arguments. |
|
93 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
94 | + * automatically) |
|
95 | + * 'priority' => 'default', //default 'default' (optional) |
|
96 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
97 | + * 'context' => 'advanced' //advanced is default (optional), |
|
98 | + * 'callback_args' => array() //any callback args to include (optional) |
|
99 | + * ) |
|
100 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
101 | + * |
|
102 | + * @var array |
|
103 | + */ |
|
104 | + protected $_metaboxes; |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
110 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
111 | + * array: array( |
|
112 | + * 0 => array( |
|
113 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
114 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
115 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
116 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
117 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
118 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
119 | + * id for the screen the metabox is on. |
|
120 | + * ) |
|
121 | + * ) |
|
122 | + * |
|
123 | + * @var array |
|
124 | + */ |
|
125 | + protected $_remove_metaboxes; |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
131 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
132 | + * second array index is for indicating what routes each script/style loads on. array( |
|
133 | + * 'registers' => array( |
|
134 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
135 | + * argument to link scripts together. |
|
136 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
137 | + * 'url' => 'http://urltoscript.css.js', |
|
138 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
139 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
140 | + * gets loaded before the one you are setting here. |
|
141 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
142 | + * ), |
|
143 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
144 | + * the script gets enqueued on. |
|
145 | + * 'script_ref' => array('route_one', 'route_two') |
|
146 | + * ), |
|
147 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
148 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
149 | + * the object. |
|
150 | + * 'scrip_ref' => array( |
|
151 | + * 'NAME_OF_JS_OBJECT' => array( |
|
152 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
153 | + * 'some_data' => 5 |
|
154 | + * ) |
|
155 | + * ) |
|
156 | + * ) |
|
157 | + * ) |
|
158 | + * |
|
159 | + * @var array |
|
160 | + */ |
|
161 | + protected $_scripts_styles; |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * This is a property that will contain the current route. |
|
166 | + * |
|
167 | + * @var string; |
|
168 | + */ |
|
169 | + protected $_current_route; |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
175 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
176 | + * 'wp_hook_reference' => 1 |
|
177 | + * ) |
|
178 | + * ) |
|
179 | + * |
|
180 | + * @var array |
|
181 | + */ |
|
182 | + protected $_wp_action_filters_priority; |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
188 | + * |
|
189 | + * @var array |
|
190 | + */ |
|
191 | + protected $_req_data; |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This just holds an instance of the page object for this hook |
|
197 | + * |
|
198 | + * @var EE_Admin_Page |
|
199 | + */ |
|
200 | + protected $_page_object; |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
206 | + * |
|
207 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
208 | + */ |
|
209 | + protected $_adminpage_obj; |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Holds EE_Registry object |
|
215 | + * |
|
216 | + * @var EE_Registry |
|
217 | + */ |
|
218 | + protected $EE = null; |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * constructor |
|
224 | + * |
|
225 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
226 | + */ |
|
227 | + public function __construct(EE_Admin_Page $adminpage) |
|
228 | + { |
|
229 | + |
|
230 | + $this->_adminpage_obj = $adminpage; |
|
231 | + $this->_req_data = array_merge($_GET, $_POST); |
|
232 | + $this->_set_defaults(); |
|
233 | + $this->_set_hooks_properties(); |
|
234 | + //first let's verify we're on the right page |
|
235 | + if (! isset($this->_req_data['page']) |
|
236 | + || (isset($this->_req_data['page']) |
|
237 | + && $this->_adminpage_obj->page_slug |
|
238 | + != $this->_req_data['page'])) { |
|
239 | + return; |
|
240 | + } //get out nothing more to be done here. |
|
241 | + //allow for extends to modify properties |
|
242 | + if (method_exists($this, '_extend_properties')) { |
|
243 | + $this->_extend_properties(); |
|
244 | + } |
|
245 | + $this->_set_page_object(); |
|
246 | + $this->_init_hooks(); |
|
247 | + $this->_load_custom_methods(); |
|
248 | + $this->_load_routed_hooks(); |
|
249 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
250 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
251 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
252 | + $this->_ajax_hooks(); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * used by child classes to set the following properties: |
|
259 | + * $_ajax_func (optional) |
|
260 | + * $_init_func (optional) |
|
261 | + * $_metaboxes (optional) |
|
262 | + * $_scripts (optional) |
|
263 | + * $_styles (optional) |
|
264 | + * $_name (required) |
|
265 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
266 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
267 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
268 | + * |
|
269 | + * @access protected |
|
270 | + * @abstract |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + abstract protected function _set_hooks_properties(); |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
279 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
280 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
281 | + * |
|
282 | + * @access public |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + public function enqueue_scripts_styles() |
|
286 | + { |
|
287 | + |
|
288 | + if (! empty($this->_scripts_styles)) { |
|
289 | + //first let's do all the registrations |
|
290 | + if (! isset($this->_scripts_styles['registers'])) { |
|
291 | + $msg[] = __( |
|
292 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
293 | + 'event_espresso' |
|
294 | + ); |
|
295 | + $msg[] = sprintf( |
|
296 | + __( |
|
297 | + 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + '<strong>' . $this->caller . '</strong>' |
|
301 | + ); |
|
302 | + throw new EE_Error(implode('||', $msg)); |
|
303 | + } |
|
304 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
305 | + $defaults = array( |
|
306 | + 'type' => 'js', |
|
307 | + 'url' => '', |
|
308 | + 'depends' => array(), |
|
309 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
310 | + 'footer' => true, |
|
311 | + ); |
|
312 | + $details = wp_parse_args($details, $defaults); |
|
313 | + extract($details); |
|
314 | + //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
315 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
316 | + //let's make sure we're not missing any REQUIRED parameters |
|
317 | + if (empty($url)) { |
|
318 | + $msg[] = sprintf( |
|
319 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
320 | + $type == 'js' ? 'script' : 'stylesheet' |
|
321 | + ); |
|
322 | + $msg[] = sprintf( |
|
323 | + __( |
|
324 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
325 | + 'event_espresso' |
|
326 | + ), |
|
327 | + '<strong>' . $this->caller . '</strong>', |
|
328 | + $ref |
|
329 | + ); |
|
330 | + throw new EE_Error(implode('||', $msg)); |
|
331 | + } |
|
332 | + //made it here so let's do the appropriate registration |
|
333 | + $type == 'js' |
|
334 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
335 | + : wp_register_style( |
|
336 | + $ref, |
|
337 | + $url, |
|
338 | + $depends, |
|
339 | + $version |
|
340 | + ); |
|
341 | + } |
|
342 | + //k now lets do the enqueues |
|
343 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
344 | + return; |
|
345 | + } //not sure if we should throw an error here or not. |
|
346 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
347 | + //make sure $routes is an array |
|
348 | + $routes = (array)$routes; |
|
349 | + if (in_array($this->_current_route, $routes)) { |
|
350 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
351 | + : wp_enqueue_style($ref); |
|
352 | + //if we have a localization for the script let's do that too. |
|
353 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
354 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
355 | + wp_localize_script( |
|
356 | + $ref, |
|
357 | + $object_name, |
|
358 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
359 | + ); |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + //let's do the deregisters |
|
365 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
366 | + return; |
|
367 | + } |
|
368 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
369 | + $defaults = array( |
|
370 | + 'type' => 'js', |
|
371 | + ); |
|
372 | + $details = wp_parse_args($details, $defaults); |
|
373 | + extract($details); |
|
374 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
375 | + } |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * just set the defaults for the hooks properties. |
|
383 | + * |
|
384 | + * @access private |
|
385 | + * @return void |
|
386 | + */ |
|
387 | + private function _set_defaults() |
|
388 | + { |
|
389 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
390 | + $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
391 | + $this->caller = get_class($this); |
|
392 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * this sets the _page_object property |
|
399 | + * |
|
400 | + * @access protected |
|
401 | + * @return void |
|
402 | + */ |
|
403 | + protected function _set_page_object() |
|
404 | + { |
|
405 | + //first make sure $this->_name is set |
|
406 | + if (empty($this->_name)) { |
|
407 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
408 | + $msg[] = sprintf( |
|
409 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
410 | + $this->caller |
|
411 | + ); |
|
412 | + throw new EE_Error(implode('||', $msg)); |
|
413 | + } |
|
414 | + $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
415 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
416 | + //first default file (if exists) |
|
417 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
418 | + if (is_readable($decaf_file)) { |
|
419 | + require_once($decaf_file); |
|
420 | + } |
|
421 | + //now we have to do require for extended file (if needed) |
|
422 | + if ($this->_extend) { |
|
423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
424 | + } |
|
425 | + //if we've got an extended class we use that! |
|
426 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
427 | + //let's make sure the class exists |
|
428 | + if (! class_exists($ref)) { |
|
429 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
430 | + $msg[] = sprintf( |
|
431 | + __( |
|
432 | + 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
433 | + 'event_espresso' |
|
434 | + ), |
|
435 | + $ref |
|
436 | + ); |
|
437 | + throw new EE_Error(implode('||', $msg)); |
|
438 | + } |
|
439 | + $a = new ReflectionClass($ref); |
|
440 | + $this->_page_object = $a->newInstance(false); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
446 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
447 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
448 | + * |
|
449 | + * @access private |
|
450 | + * @return void |
|
451 | + */ |
|
452 | + private function _load_custom_methods() |
|
453 | + { |
|
454 | + /** |
|
455 | + * method cannot be named 'default' (@see http://us3.php |
|
456 | + * .net/manual/en/reserved.keywords.php) so need to |
|
457 | + * handle routes that are "default" |
|
458 | + * |
|
459 | + * @since 4.3.0 |
|
460 | + */ |
|
461 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
462 | + //these run before the Admin_Page route executes. |
|
463 | + if (method_exists($this, $method_callback)) { |
|
464 | + call_user_func(array($this, $method_callback)); |
|
465 | + } |
|
466 | + //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
467 | + //first the actions |
|
468 | + //note that these action hooks will have the $query_args value available. |
|
469 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
470 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
471 | + add_action( |
|
472 | + 'AHEE__' |
|
473 | + . $admin_class_name |
|
474 | + . '___redirect_after_action__before_redirect_modification_' |
|
475 | + . $this->_current_route, |
|
476 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
477 | + 10 |
|
478 | + ); |
|
479 | + } |
|
480 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
481 | + add_action( |
|
482 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | + array($this, '_redirect_action_' . $this->_current_route), |
|
484 | + 10 |
|
485 | + ); |
|
486 | + } |
|
487 | + //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
488 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
489 | + add_filter( |
|
490 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
492 | + 10, |
|
493 | + 2 |
|
494 | + ); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
502 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
503 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
504 | + * |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + private function _load_routed_hooks() |
|
508 | + { |
|
509 | + |
|
510 | + //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
511 | + $hook_filter_array = array( |
|
512 | + 'admin_footer' => array( |
|
513 | + 'type' => 'action', |
|
514 | + 'argnum' => 1, |
|
515 | + 'priority' => 10, |
|
516 | + ), |
|
517 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
518 | + 'type' => 'filter', |
|
519 | + 'argnum' => 1, |
|
520 | + 'priority' => 10, |
|
521 | + ), |
|
522 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
523 | + 'type' => 'filter', |
|
524 | + 'argnum' => 1, |
|
525 | + 'priority' => 10, |
|
526 | + ), |
|
527 | + 'FHEE_list_table_views' => array( |
|
528 | + 'type' => 'filter', |
|
529 | + 'argnum' => 1, |
|
530 | + 'priority' => 10, |
|
531 | + ), |
|
532 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
533 | + 'type' => 'action', |
|
534 | + 'argnum' => 1, |
|
535 | + 'priority' => 10, |
|
536 | + ), |
|
537 | + ); |
|
538 | + foreach ($hook_filter_array as $hook => $args) { |
|
539 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
540 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
541 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
542 | + } |
|
543 | + if ($args['type'] == 'action') { |
|
544 | + add_action( |
|
545 | + $hook, |
|
546 | + array($this, $this->_current_route . '_' . $hook), |
|
547 | + $args['priority'], |
|
548 | + $args['argnum'] |
|
549 | + ); |
|
550 | + } else { |
|
551 | + add_filter( |
|
552 | + $hook, |
|
553 | + array($this, $this->_current_route . '_' . $hook), |
|
554 | + $args['priority'], |
|
555 | + $args['argnum'] |
|
556 | + ); |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
565 | + * |
|
566 | + * @return void |
|
567 | + */ |
|
568 | + private function _ajax_hooks() |
|
569 | + { |
|
570 | + |
|
571 | + if (empty($this->_ajax_func)) { |
|
572 | + return; |
|
573 | + } //get out there's nothing to take care of. |
|
574 | + foreach ($this->_ajax_func as $action => $method) { |
|
575 | + //make sure method exists |
|
576 | + if (! method_exists($this, $method)) { |
|
577 | + $msg[] = __( |
|
578 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
579 | + 'event_espresso' |
|
580 | + ) . '<br />'; |
|
581 | + $msg[] = sprintf( |
|
582 | + __( |
|
583 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
584 | + 'event_espresso' |
|
585 | + ), |
|
586 | + $method, |
|
587 | + $this->caller |
|
588 | + ); |
|
589 | + throw new EE_Error(implode('||', $msg)); |
|
590 | + } |
|
591 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Loop throught the $_init_func array and add_actions for the array. |
|
599 | + * |
|
600 | + * @return void |
|
601 | + */ |
|
602 | + protected function _init_hooks() |
|
603 | + { |
|
604 | + if (empty($this->_init_func)) { |
|
605 | + return; |
|
606 | + } //get out there's nothing to take care of. |
|
607 | + //We need to determine what page_route we are on! |
|
608 | + $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
609 | + foreach ($this->_init_func as $route => $method) { |
|
610 | + //make sure method exists |
|
611 | + if (! method_exists($this, $method)) { |
|
612 | + $msg[] = __( |
|
613 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
614 | + 'event_espresso' |
|
615 | + ) . '<br />'; |
|
616 | + $msg[] = sprintf( |
|
617 | + __( |
|
618 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
619 | + 'event_espresso' |
|
620 | + ), |
|
621 | + $method, |
|
622 | + $this->caller |
|
623 | + ); |
|
624 | + throw new EE_Error(implode('||', $msg)); |
|
625 | + } |
|
626 | + if ($route == $this->_current_route) { |
|
627 | + add_action('admin_init', array($this, $method)); |
|
628 | + } |
|
629 | + } |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
636 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
637 | + * |
|
638 | + * @access public |
|
639 | + * @return void |
|
640 | + */ |
|
641 | + public function add_metaboxes() |
|
642 | + { |
|
643 | + if (empty($this->_metaboxes)) { |
|
644 | + return; |
|
645 | + } //get out we don't have any metaboxes to set for this connection |
|
646 | + $this->_handle_metabox_array($this->_metaboxes); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + private function _handle_metabox_array($boxes, $add = true) |
|
652 | + { |
|
653 | + |
|
654 | + foreach ($boxes as $box) { |
|
655 | + if (! isset($box['page_route'])) { |
|
656 | + continue; |
|
657 | + } //we dont' have a valid array |
|
658 | + //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
659 | + $box['page_route'] = (array)$box['page_route']; |
|
660 | + foreach ($box['page_route'] as $route) { |
|
661 | + if ($route != $this->_current_route) { |
|
662 | + continue; |
|
663 | + } //get out we only add metaboxes for set route. |
|
664 | + if ($add) { |
|
665 | + $this->_add_metabox($box); |
|
666 | + } else { |
|
667 | + $this->_remove_metabox($box); |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
677 | + * |
|
678 | + * @access public |
|
679 | + * @return void |
|
680 | + */ |
|
681 | + public function remove_metaboxes() |
|
682 | + { |
|
683 | + |
|
684 | + if (empty($this->_remove_metaboxes)) { |
|
685 | + return; |
|
686 | + } //get out there are no metaboxes to remove |
|
687 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * This just handles adding a metabox |
|
693 | + * |
|
694 | + * @access private |
|
695 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
696 | + */ |
|
697 | + private function _add_metabox($args) |
|
698 | + { |
|
699 | + $current_screen = get_current_screen(); |
|
700 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
701 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
702 | + //set defaults |
|
703 | + $defaults = array( |
|
704 | + 'func' => $func, |
|
705 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
706 | + 'priority' => 'default', |
|
707 | + 'label' => $this->caller, |
|
708 | + 'context' => 'advanced', |
|
709 | + 'callback_args' => array(), |
|
710 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
711 | + ); |
|
712 | + $args = wp_parse_args($args, $defaults); |
|
713 | + extract($args); |
|
714 | + //make sure method exists |
|
715 | + if (! method_exists($this, $func)) { |
|
716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
717 | + $msg[] = sprintf( |
|
718 | + __( |
|
719 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
720 | + 'event_espresso' |
|
721 | + ), |
|
722 | + $func, |
|
723 | + $this->caller |
|
724 | + ); |
|
725 | + throw new EE_Error(implode('||', $msg)); |
|
726 | + } |
|
727 | + //everything checks out so lets add the metabox |
|
728 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + |
|
733 | + private function _remove_metabox($args) |
|
734 | + { |
|
735 | + $current_screen = get_current_screen(); |
|
736 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
737 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
738 | + //set defaults |
|
739 | + $defaults = array( |
|
740 | + 'id' => isset($args['id']) |
|
741 | + ? $args['id'] |
|
742 | + : $this->_current_route |
|
743 | + . '_' |
|
744 | + . $this->caller |
|
745 | + . '_' |
|
746 | + . $func |
|
747 | + . '_metabox', |
|
748 | + 'context' => 'default', |
|
749 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
750 | + ); |
|
751 | + $args = wp_parse_args($args, $defaults); |
|
752 | + extract($args); |
|
753 | + //everything checks out so lets remove the box! |
|
754 | + remove_meta_box($id, $screen, $context); |
|
755 | + } |
|
756 | 756 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $this->_set_defaults(); |
233 | 233 | $this->_set_hooks_properties(); |
234 | 234 | //first let's verify we're on the right page |
235 | - if (! isset($this->_req_data['page']) |
|
235 | + if ( ! isset($this->_req_data['page']) |
|
236 | 236 | || (isset($this->_req_data['page']) |
237 | 237 | && $this->_adminpage_obj->page_slug |
238 | 238 | != $this->_req_data['page'])) { |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | public function enqueue_scripts_styles() |
286 | 286 | { |
287 | 287 | |
288 | - if (! empty($this->_scripts_styles)) { |
|
288 | + if ( ! empty($this->_scripts_styles)) { |
|
289 | 289 | //first let's do all the registrations |
290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
290 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
291 | 291 | $msg[] = __( |
292 | 292 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
293 | 293 | 'event_espresso' |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
298 | 298 | 'event_espresso' |
299 | 299 | ), |
300 | - '<strong>' . $this->caller . '</strong>' |
|
300 | + '<strong>'.$this->caller.'</strong>' |
|
301 | 301 | ); |
302 | 302 | throw new EE_Error(implode('||', $msg)); |
303 | 303 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | 'version' => EVENT_ESPRESSO_VERSION, |
310 | 310 | 'footer' => true, |
311 | 311 | ); |
312 | - $details = wp_parse_args($details, $defaults); |
|
312 | + $details = wp_parse_args($details, $defaults); |
|
313 | 313 | extract($details); |
314 | 314 | //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
315 | 315 | $this->_scripts_styles['registers'][$ref]['type'] = $type; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
325 | 325 | 'event_espresso' |
326 | 326 | ), |
327 | - '<strong>' . $this->caller . '</strong>', |
|
327 | + '<strong>'.$this->caller.'</strong>', |
|
328 | 328 | $ref |
329 | 329 | ); |
330 | 330 | throw new EE_Error(implode('||', $msg)); |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | ); |
341 | 341 | } |
342 | 342 | //k now lets do the enqueues |
343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
343 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
344 | 344 | return; |
345 | 345 | } //not sure if we should throw an error here or not. |
346 | 346 | foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
347 | 347 | //make sure $routes is an array |
348 | - $routes = (array)$routes; |
|
348 | + $routes = (array) $routes; |
|
349 | 349 | if (in_array($this->_current_route, $routes)) { |
350 | 350 | $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
351 | 351 | : wp_enqueue_style($ref); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | } |
363 | 363 | } |
364 | 364 | //let's do the deregisters |
365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
365 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -412,20 +412,20 @@ discard block |
||
412 | 412 | throw new EE_Error(implode('||', $msg)); |
413 | 413 | } |
414 | 414 | $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
415 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; //take the message -> The_Message |
|
416 | 416 | //first default file (if exists) |
417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
417 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php'; |
|
418 | 418 | if (is_readable($decaf_file)) { |
419 | 419 | require_once($decaf_file); |
420 | 420 | } |
421 | 421 | //now we have to do require for extended file (if needed) |
422 | 422 | if ($this->_extend) { |
423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php'); |
|
424 | 424 | } |
425 | 425 | //if we've got an extended class we use that! |
426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
426 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
427 | 427 | //let's make sure the class exists |
428 | - if (! class_exists($ref)) { |
|
428 | + if ( ! class_exists($ref)) { |
|
429 | 429 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
430 | 430 | $msg[] = sprintf( |
431 | 431 | __( |
@@ -467,28 +467,28 @@ discard block |
||
467 | 467 | //first the actions |
468 | 468 | //note that these action hooks will have the $query_args value available. |
469 | 469 | $admin_class_name = get_class($this->_adminpage_obj); |
470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
470 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
471 | 471 | add_action( |
472 | 472 | 'AHEE__' |
473 | 473 | . $admin_class_name |
474 | 474 | . '___redirect_after_action__before_redirect_modification_' |
475 | 475 | . $this->_current_route, |
476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
476 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
477 | 477 | 10 |
478 | 478 | ); |
479 | 479 | } |
480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
480 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
481 | 481 | add_action( |
482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
482 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
483 | + array($this, '_redirect_action_'.$this->_current_route), |
|
484 | 484 | 10 |
485 | 485 | ); |
486 | 486 | } |
487 | 487 | //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
488 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
489 | 489 | add_filter( |
490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
490 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
491 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
492 | 492 | 10, |
493 | 493 | 2 |
494 | 494 | ); |
@@ -514,12 +514,12 @@ discard block |
||
514 | 514 | 'argnum' => 1, |
515 | 515 | 'priority' => 10, |
516 | 516 | ), |
517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
517 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
518 | 518 | 'type' => 'filter', |
519 | 519 | 'argnum' => 1, |
520 | 520 | 'priority' => 10, |
521 | 521 | ), |
522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
522 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
523 | 523 | 'type' => 'filter', |
524 | 524 | 'argnum' => 1, |
525 | 525 | 'priority' => 10, |
@@ -536,21 +536,21 @@ discard block |
||
536 | 536 | ), |
537 | 537 | ); |
538 | 538 | foreach ($hook_filter_array as $hook => $args) { |
539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
539 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
540 | 540 | if (isset($this->_wp_action_filters_priority[$hook])) { |
541 | 541 | $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
542 | 542 | } |
543 | 543 | if ($args['type'] == 'action') { |
544 | 544 | add_action( |
545 | 545 | $hook, |
546 | - array($this, $this->_current_route . '_' . $hook), |
|
546 | + array($this, $this->_current_route.'_'.$hook), |
|
547 | 547 | $args['priority'], |
548 | 548 | $args['argnum'] |
549 | 549 | ); |
550 | 550 | } else { |
551 | 551 | add_filter( |
552 | 552 | $hook, |
553 | - array($this, $this->_current_route . '_' . $hook), |
|
553 | + array($this, $this->_current_route.'_'.$hook), |
|
554 | 554 | $args['priority'], |
555 | 555 | $args['argnum'] |
556 | 556 | ); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | } //get out there's nothing to take care of. |
574 | 574 | foreach ($this->_ajax_func as $action => $method) { |
575 | 575 | //make sure method exists |
576 | - if (! method_exists($this, $method)) { |
|
576 | + if ( ! method_exists($this, $method)) { |
|
577 | 577 | $msg[] = __( |
578 | 578 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
579 | 579 | 'event_espresso' |
580 | - ) . '<br />'; |
|
580 | + ).'<br />'; |
|
581 | 581 | $msg[] = sprintf( |
582 | 582 | __( |
583 | 583 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | ); |
589 | 589 | throw new EE_Error(implode('||', $msg)); |
590 | 590 | } |
591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
591 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
609 | 609 | foreach ($this->_init_func as $route => $method) { |
610 | 610 | //make sure method exists |
611 | - if (! method_exists($this, $method)) { |
|
611 | + if ( ! method_exists($this, $method)) { |
|
612 | 612 | $msg[] = __( |
613 | 613 | 'There is no corresponding method for the hook labeled in the _init_func array', |
614 | 614 | 'event_espresso' |
615 | - ) . '<br />'; |
|
615 | + ).'<br />'; |
|
616 | 616 | $msg[] = sprintf( |
617 | 617 | __( |
618 | 618 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -652,11 +652,11 @@ discard block |
||
652 | 652 | { |
653 | 653 | |
654 | 654 | foreach ($boxes as $box) { |
655 | - if (! isset($box['page_route'])) { |
|
655 | + if ( ! isset($box['page_route'])) { |
|
656 | 656 | continue; |
657 | 657 | } //we dont' have a valid array |
658 | 658 | //let's make sure $box['page_route'] is an array so the "foreach" will work. |
659 | - $box['page_route'] = (array)$box['page_route']; |
|
659 | + $box['page_route'] = (array) $box['page_route']; |
|
660 | 660 | foreach ($box['page_route'] as $route) { |
661 | 661 | if ($route != $this->_current_route) { |
662 | 662 | continue; |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | //set defaults |
703 | 703 | $defaults = array( |
704 | 704 | 'func' => $func, |
705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
705 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
706 | 706 | 'priority' => 'default', |
707 | 707 | 'label' => $this->caller, |
708 | 708 | 'context' => 'advanced', |
@@ -712,8 +712,8 @@ discard block |
||
712 | 712 | $args = wp_parse_args($args, $defaults); |
713 | 713 | extract($args); |
714 | 714 | //make sure method exists |
715 | - if (! method_exists($this, $func)) { |
|
716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
715 | + if ( ! method_exists($this, $func)) { |
|
716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
717 | 717 | $msg[] = sprintf( |
718 | 718 | __( |
719 | 719 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -205,7 +205,6 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @access public |
207 | 207 | * @uses _initialize_admin_page() |
208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | 208 | * @return void |
210 | 209 | */ |
211 | 210 | public function initialize_admin_page() |
@@ -221,6 +220,9 @@ discard block |
||
221 | 220 | |
222 | 221 | |
223 | 222 | |
223 | + /** |
|
224 | + * @param string $wp_page_slug |
|
225 | + */ |
|
224 | 226 | public function set_page_dependencies($wp_page_slug) |
225 | 227 | { |
226 | 228 | if (! $this->_load_page) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -28,443 +28,443 @@ discard block |
||
28 | 28 | abstract class EE_Admin_Page_Init extends EE_Base |
29 | 29 | { |
30 | 30 | |
31 | - //identity properties (set in _set_defaults and _set_init_properties) |
|
32 | - public $label; |
|
33 | - |
|
34 | - /** |
|
35 | - * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
36 | - * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $capability; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This holds the menu map object for this admin page. |
|
45 | - * |
|
46 | - * @var EE_Admin_Page_Menu_Map |
|
47 | - */ |
|
48 | - protected $_menu_map; |
|
49 | - |
|
50 | - /** |
|
51 | - * deprecated |
|
52 | - */ |
|
53 | - public $menu_label; |
|
54 | - public $menu_slug; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - //set in _set_defaults |
|
59 | - protected $_folder_name; |
|
60 | - protected $_folder_path; |
|
61 | - protected $_file_name; |
|
62 | - public $hook_file; |
|
63 | - protected $_wp_page_slug; |
|
64 | - protected $_routing; |
|
65 | - |
|
66 | - |
|
67 | - //will hold page object. |
|
68 | - protected $_loaded_page_object; |
|
69 | - |
|
70 | - |
|
71 | - //for caf |
|
72 | - protected $_files_hooked; |
|
73 | - protected $_hook_paths; |
|
74 | - |
|
75 | - //load_page? |
|
76 | - private $_load_page; |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @Constructor |
|
82 | - * @access public |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - public function __construct() |
|
86 | - { |
|
87 | - //set global defaults |
|
88 | - $this->_set_defaults(); |
|
89 | - //set properties that are always available with objects. |
|
90 | - $this->_set_init_properties(); |
|
91 | - //global styles/scripts across all wp admin pages |
|
92 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
93 | - //load initial stuff. |
|
94 | - $this->_set_file_and_folder_name(); |
|
95 | - $this->_set_menu_map(); |
|
96 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
97 | - EE_Error::doing_it_wrong( |
|
98 | - get_class($this) . '::$_menu_map', |
|
99 | - sprintf( |
|
100 | - __( |
|
101 | - 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - get_class($this) |
|
105 | - ), |
|
106 | - '4.4.0' |
|
107 | - ); |
|
108 | - return; |
|
109 | - } |
|
110 | - //set default capability |
|
111 | - $this->_set_capability(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * _set_init_properties |
|
118 | - * Child classes use to set the following properties: |
|
119 | - * $label |
|
120 | - * |
|
121 | - * @abstract |
|
122 | - * @access protected |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - abstract protected function _set_init_properties(); |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
131 | - * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
132 | - * |
|
133 | - * @since 4.4.0 |
|
134 | - * @ return void. |
|
135 | - */ |
|
136 | - protected function _set_menu_map() |
|
137 | - { |
|
138 | - return array(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * returns the menu map for this admin page |
|
145 | - * |
|
146 | - * @since 4.4.0 |
|
147 | - * @return EE_Admin_Page_Menu_Map |
|
148 | - */ |
|
149 | - public function get_menu_map() |
|
150 | - { |
|
151 | - return $this->_menu_map; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * This loads scripts and styles for the EE_Admin system |
|
158 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
159 | - * |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function load_wp_global_scripts_styles() |
|
163 | - { |
|
164 | - wp_register_style( |
|
165 | - 'espresso_menu', |
|
166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
167 | - array('dashicons'), |
|
168 | - EVENT_ESPRESSO_VERSION |
|
169 | - ); |
|
170 | - wp_enqueue_style('espresso_menu'); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * this sets default properties (might be overridden in _set_init_properties); |
|
177 | - * |
|
178 | - * @access private |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function _set_defaults() |
|
182 | - { |
|
183 | - $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
184 | - $this->_routing = true; |
|
185 | - $this->_load_page = false; |
|
186 | - $this->_files_hooked = $this->_hook_paths = array(); |
|
187 | - //menu_map |
|
188 | - $this->_menu_map = $this->get_menu_map(); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - protected function _set_capability() |
|
194 | - { |
|
195 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * initialize_admin_page |
|
203 | - * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
204 | - * EE_Admin_Init class. |
|
205 | - * |
|
206 | - * @access public |
|
207 | - * @uses _initialize_admin_page() |
|
208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function initialize_admin_page() |
|
212 | - { |
|
213 | - //let's check user access first |
|
214 | - $this->_check_user_access(); |
|
215 | - if (! is_object($this->_loaded_page_object)) { |
|
216 | - return; |
|
217 | - } |
|
218 | - $this->_loaded_page_object->route_admin_request(); |
|
219 | - return; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - public function set_page_dependencies($wp_page_slug) |
|
225 | - { |
|
226 | - if (! $this->_load_page) { |
|
227 | - return; |
|
228 | - } |
|
229 | - if (! is_object($this->_loaded_page_object)) { |
|
230 | - $msg[] = __( |
|
231 | - 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
232 | - 'event_espresso' |
|
233 | - ); |
|
234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
235 | - __( |
|
236 | - 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - $this->_file_name, |
|
240 | - $this->_file_name, |
|
241 | - $this->_folder_path . $this->_file_name, |
|
242 | - $this->_menu_map->menu_slug |
|
243 | - ); |
|
244 | - throw new EE_Error(implode('||', $msg)); |
|
245 | - } |
|
246 | - $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
247 | - $page_hook = 'load-' . $wp_page_slug; |
|
248 | - //hook into page load hook so all page specific stuff get's loaded. |
|
249 | - if (! empty($wp_page_slug)) { |
|
250 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
257 | - * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
258 | - * |
|
259 | - * @return void |
|
260 | - */ |
|
261 | - public function do_initial_loads() |
|
262 | - { |
|
263 | - //no loading or initializing if menu map is setup incorrectly. |
|
264 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
265 | - return; |
|
266 | - } |
|
267 | - $this->_initialize_admin_page(); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * all we're doing here is setting the $_file_name property for later use. |
|
273 | - * |
|
274 | - * @access private |
|
275 | - * @return void |
|
276 | - */ |
|
277 | - private function _set_file_and_folder_name() |
|
278 | - { |
|
279 | - $bt = debug_backtrace(); |
|
280 | - //for more reliable determination of folder name |
|
281 | - //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
282 | - $class = get_class($this); |
|
283 | - foreach ($bt as $index => $values) { |
|
284 | - if (isset($values['class']) && $values['class'] == $class) { |
|
285 | - $file_index = $index - 1; |
|
286 | - $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
287 | - if (! empty($this->_folder_name)) { |
|
288 | - break; |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
293 | - $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
294 | - $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
295 | - $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
301 | - * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
302 | - * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
303 | - * events_Messages_Hooks.class.php |
|
304 | - * |
|
305 | - * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
306 | - * files/classes |
|
307 | - * @return array |
|
308 | - */ |
|
309 | - public function register_hooks($extend = false) |
|
310 | - { |
|
311 | - |
|
312 | - //get a list of files in the directory that have the "Hook" in their name an |
|
313 | - //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
314 | - if ($extend) { |
|
315 | - $hook_files_glob_path = apply_filters( |
|
316 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
317 | - EE_CORE_CAF_ADMIN_EXTEND |
|
318 | - . $this->_folder_name |
|
319 | - . DS |
|
320 | - . '*' |
|
321 | - . $this->_file_name |
|
322 | - . '_Hooks_Extend.class.php' |
|
323 | - ); |
|
324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | - } |
|
326 | - //loop through decaf folders |
|
327 | - $hook_files_glob_path = apply_filters( |
|
328 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
330 | - ); |
|
331 | - $this->_hook_paths = array_merge( |
|
332 | - $this->_register_hook_files($hook_files_glob_path), |
|
333 | - $this->_hook_paths |
|
334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | - return $this->_hook_paths; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
341 | - { |
|
342 | - $hook_paths = array(); |
|
343 | - if ($hook_files = glob($hook_files_glob_path)) { |
|
344 | - if (empty($hook_files)) { |
|
345 | - return array(); |
|
346 | - } |
|
347 | - foreach ($hook_files as $file) { |
|
348 | - //lets get the linked admin. |
|
349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
350 | - : str_replace($this->_folder_path, '', $file); |
|
351 | - $replace = $extend |
|
352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
353 | - : '_' |
|
354 | - . $this->_file_name |
|
355 | - . '_Hooks.class.php'; |
|
356 | - $rel_admin = str_replace($replace, '', $hook_file); |
|
357 | - $rel_admin = strtolower($rel_admin); |
|
358 | - $hook_paths[] = $file; |
|
359 | - //make sure we haven't already got a hook setup for this page path |
|
360 | - if (in_array($rel_admin, $this->_files_hooked)) { |
|
361 | - continue; |
|
362 | - } |
|
363 | - $this->hook_file = $hook_file; |
|
364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
365 | - $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
366 | - $this->_files_hooked[] = $rel_admin; |
|
367 | - } |
|
368 | - } |
|
369 | - return $hook_paths; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - public function load_admin_hook($registered_pages) |
|
375 | - { |
|
376 | - $this->hook_file; |
|
377 | - $hook_file = (array)$this->hook_file; |
|
378 | - return array_merge($hook_file, $registered_pages); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _initialize_admin_page |
|
384 | - * |
|
385 | - * @see initialize_admin_page() for info |
|
386 | - */ |
|
387 | - protected function _initialize_admin_page() |
|
388 | - { |
|
389 | - |
|
390 | - //JUST CHECK WE'RE ON RIGHT PAGE. |
|
391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | - return; |
|
393 | - } //not on the right page so let's get out. |
|
394 | - $this->_load_page = true; |
|
395 | - //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
396 | - // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
397 | - //we don't need to do a page_request check here because it's only called via WP menu system. |
|
398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
400 | - $admin_page = apply_filters( |
|
401 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
402 | - $admin_page |
|
403 | - ); |
|
404 | - // define requested admin page class name then load the file and instantiate |
|
405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
406 | - $path_to_file = apply_filters( |
|
407 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
408 | - $path_to_file |
|
409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | - if (is_readable($path_to_file)) { |
|
411 | - // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
412 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
413 | - do_action( |
|
414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
415 | - ); |
|
416 | - require_once($path_to_file); |
|
417 | - $a = new ReflectionClass($admin_page); |
|
418 | - $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
419 | - } |
|
420 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - public function get_admin_page_name() |
|
427 | - { |
|
428 | - return $this->_file_name . '_Admin_Page'; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @return mixed |
|
435 | - */ |
|
436 | - public function loaded_page_object() |
|
437 | - { |
|
438 | - return $this->_loaded_page_object; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - // public function set_autoloaders( $className ) { |
|
446 | - // $dir_ref = array( |
|
447 | - // $this->_folder_path => array('core','class') |
|
448 | - // ); |
|
449 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
450 | - // } |
|
451 | - /** |
|
452 | - * _check_user_access |
|
453 | - * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
454 | - * WordPress die message. |
|
455 | - * |
|
456 | - * @return bool|die true if pass (or admin) wp_die if fail |
|
457 | - */ |
|
458 | - private function _check_user_access() |
|
459 | - { |
|
460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
461 | - $this->_menu_map->capability, |
|
462 | - $this->_menu_map->menu_slug |
|
463 | - )) { |
|
464 | - wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
465 | - } |
|
466 | - return true; |
|
467 | - } |
|
31 | + //identity properties (set in _set_defaults and _set_init_properties) |
|
32 | + public $label; |
|
33 | + |
|
34 | + /** |
|
35 | + * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
36 | + * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $capability; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This holds the menu map object for this admin page. |
|
45 | + * |
|
46 | + * @var EE_Admin_Page_Menu_Map |
|
47 | + */ |
|
48 | + protected $_menu_map; |
|
49 | + |
|
50 | + /** |
|
51 | + * deprecated |
|
52 | + */ |
|
53 | + public $menu_label; |
|
54 | + public $menu_slug; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + //set in _set_defaults |
|
59 | + protected $_folder_name; |
|
60 | + protected $_folder_path; |
|
61 | + protected $_file_name; |
|
62 | + public $hook_file; |
|
63 | + protected $_wp_page_slug; |
|
64 | + protected $_routing; |
|
65 | + |
|
66 | + |
|
67 | + //will hold page object. |
|
68 | + protected $_loaded_page_object; |
|
69 | + |
|
70 | + |
|
71 | + //for caf |
|
72 | + protected $_files_hooked; |
|
73 | + protected $_hook_paths; |
|
74 | + |
|
75 | + //load_page? |
|
76 | + private $_load_page; |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @Constructor |
|
82 | + * @access public |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + public function __construct() |
|
86 | + { |
|
87 | + //set global defaults |
|
88 | + $this->_set_defaults(); |
|
89 | + //set properties that are always available with objects. |
|
90 | + $this->_set_init_properties(); |
|
91 | + //global styles/scripts across all wp admin pages |
|
92 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
93 | + //load initial stuff. |
|
94 | + $this->_set_file_and_folder_name(); |
|
95 | + $this->_set_menu_map(); |
|
96 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
97 | + EE_Error::doing_it_wrong( |
|
98 | + get_class($this) . '::$_menu_map', |
|
99 | + sprintf( |
|
100 | + __( |
|
101 | + 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + get_class($this) |
|
105 | + ), |
|
106 | + '4.4.0' |
|
107 | + ); |
|
108 | + return; |
|
109 | + } |
|
110 | + //set default capability |
|
111 | + $this->_set_capability(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * _set_init_properties |
|
118 | + * Child classes use to set the following properties: |
|
119 | + * $label |
|
120 | + * |
|
121 | + * @abstract |
|
122 | + * @access protected |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + abstract protected function _set_init_properties(); |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
131 | + * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
132 | + * |
|
133 | + * @since 4.4.0 |
|
134 | + * @ return void. |
|
135 | + */ |
|
136 | + protected function _set_menu_map() |
|
137 | + { |
|
138 | + return array(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * returns the menu map for this admin page |
|
145 | + * |
|
146 | + * @since 4.4.0 |
|
147 | + * @return EE_Admin_Page_Menu_Map |
|
148 | + */ |
|
149 | + public function get_menu_map() |
|
150 | + { |
|
151 | + return $this->_menu_map; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * This loads scripts and styles for the EE_Admin system |
|
158 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
159 | + * |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function load_wp_global_scripts_styles() |
|
163 | + { |
|
164 | + wp_register_style( |
|
165 | + 'espresso_menu', |
|
166 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
167 | + array('dashicons'), |
|
168 | + EVENT_ESPRESSO_VERSION |
|
169 | + ); |
|
170 | + wp_enqueue_style('espresso_menu'); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * this sets default properties (might be overridden in _set_init_properties); |
|
177 | + * |
|
178 | + * @access private |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function _set_defaults() |
|
182 | + { |
|
183 | + $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
184 | + $this->_routing = true; |
|
185 | + $this->_load_page = false; |
|
186 | + $this->_files_hooked = $this->_hook_paths = array(); |
|
187 | + //menu_map |
|
188 | + $this->_menu_map = $this->get_menu_map(); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + protected function _set_capability() |
|
194 | + { |
|
195 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
196 | + $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * initialize_admin_page |
|
203 | + * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
204 | + * EE_Admin_Init class. |
|
205 | + * |
|
206 | + * @access public |
|
207 | + * @uses _initialize_admin_page() |
|
208 | + * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function initialize_admin_page() |
|
212 | + { |
|
213 | + //let's check user access first |
|
214 | + $this->_check_user_access(); |
|
215 | + if (! is_object($this->_loaded_page_object)) { |
|
216 | + return; |
|
217 | + } |
|
218 | + $this->_loaded_page_object->route_admin_request(); |
|
219 | + return; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + public function set_page_dependencies($wp_page_slug) |
|
225 | + { |
|
226 | + if (! $this->_load_page) { |
|
227 | + return; |
|
228 | + } |
|
229 | + if (! is_object($this->_loaded_page_object)) { |
|
230 | + $msg[] = __( |
|
231 | + 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
232 | + 'event_espresso' |
|
233 | + ); |
|
234 | + $msg[] = $msg[0] . "\r\n" . sprintf( |
|
235 | + __( |
|
236 | + 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + $this->_file_name, |
|
240 | + $this->_file_name, |
|
241 | + $this->_folder_path . $this->_file_name, |
|
242 | + $this->_menu_map->menu_slug |
|
243 | + ); |
|
244 | + throw new EE_Error(implode('||', $msg)); |
|
245 | + } |
|
246 | + $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
247 | + $page_hook = 'load-' . $wp_page_slug; |
|
248 | + //hook into page load hook so all page specific stuff get's loaded. |
|
249 | + if (! empty($wp_page_slug)) { |
|
250 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
257 | + * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
258 | + * |
|
259 | + * @return void |
|
260 | + */ |
|
261 | + public function do_initial_loads() |
|
262 | + { |
|
263 | + //no loading or initializing if menu map is setup incorrectly. |
|
264 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
265 | + return; |
|
266 | + } |
|
267 | + $this->_initialize_admin_page(); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * all we're doing here is setting the $_file_name property for later use. |
|
273 | + * |
|
274 | + * @access private |
|
275 | + * @return void |
|
276 | + */ |
|
277 | + private function _set_file_and_folder_name() |
|
278 | + { |
|
279 | + $bt = debug_backtrace(); |
|
280 | + //for more reliable determination of folder name |
|
281 | + //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
282 | + $class = get_class($this); |
|
283 | + foreach ($bt as $index => $values) { |
|
284 | + if (isset($values['class']) && $values['class'] == $class) { |
|
285 | + $file_index = $index - 1; |
|
286 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
287 | + if (! empty($this->_folder_name)) { |
|
288 | + break; |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
293 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
294 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
295 | + $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
301 | + * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
302 | + * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
303 | + * events_Messages_Hooks.class.php |
|
304 | + * |
|
305 | + * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
306 | + * files/classes |
|
307 | + * @return array |
|
308 | + */ |
|
309 | + public function register_hooks($extend = false) |
|
310 | + { |
|
311 | + |
|
312 | + //get a list of files in the directory that have the "Hook" in their name an |
|
313 | + //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
314 | + if ($extend) { |
|
315 | + $hook_files_glob_path = apply_filters( |
|
316 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
317 | + EE_CORE_CAF_ADMIN_EXTEND |
|
318 | + . $this->_folder_name |
|
319 | + . DS |
|
320 | + . '*' |
|
321 | + . $this->_file_name |
|
322 | + . '_Hooks_Extend.class.php' |
|
323 | + ); |
|
324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | + } |
|
326 | + //loop through decaf folders |
|
327 | + $hook_files_glob_path = apply_filters( |
|
328 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
329 | + $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
330 | + ); |
|
331 | + $this->_hook_paths = array_merge( |
|
332 | + $this->_register_hook_files($hook_files_glob_path), |
|
333 | + $this->_hook_paths |
|
334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | + return $this->_hook_paths; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
341 | + { |
|
342 | + $hook_paths = array(); |
|
343 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
344 | + if (empty($hook_files)) { |
|
345 | + return array(); |
|
346 | + } |
|
347 | + foreach ($hook_files as $file) { |
|
348 | + //lets get the linked admin. |
|
349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
350 | + : str_replace($this->_folder_path, '', $file); |
|
351 | + $replace = $extend |
|
352 | + ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
353 | + : '_' |
|
354 | + . $this->_file_name |
|
355 | + . '_Hooks.class.php'; |
|
356 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
357 | + $rel_admin = strtolower($rel_admin); |
|
358 | + $hook_paths[] = $file; |
|
359 | + //make sure we haven't already got a hook setup for this page path |
|
360 | + if (in_array($rel_admin, $this->_files_hooked)) { |
|
361 | + continue; |
|
362 | + } |
|
363 | + $this->hook_file = $hook_file; |
|
364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
365 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
366 | + $this->_files_hooked[] = $rel_admin; |
|
367 | + } |
|
368 | + } |
|
369 | + return $hook_paths; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + public function load_admin_hook($registered_pages) |
|
375 | + { |
|
376 | + $this->hook_file; |
|
377 | + $hook_file = (array)$this->hook_file; |
|
378 | + return array_merge($hook_file, $registered_pages); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _initialize_admin_page |
|
384 | + * |
|
385 | + * @see initialize_admin_page() for info |
|
386 | + */ |
|
387 | + protected function _initialize_admin_page() |
|
388 | + { |
|
389 | + |
|
390 | + //JUST CHECK WE'RE ON RIGHT PAGE. |
|
391 | + if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | + return; |
|
393 | + } //not on the right page so let's get out. |
|
394 | + $this->_load_page = true; |
|
395 | + //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
396 | + // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
397 | + //we don't need to do a page_request check here because it's only called via WP menu system. |
|
398 | + $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | + $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
400 | + $admin_page = apply_filters( |
|
401 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
402 | + $admin_page |
|
403 | + ); |
|
404 | + // define requested admin page class name then load the file and instantiate |
|
405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
406 | + $path_to_file = apply_filters( |
|
407 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
408 | + $path_to_file |
|
409 | + );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | + if (is_readable($path_to_file)) { |
|
411 | + // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
412 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
413 | + do_action( |
|
414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
415 | + ); |
|
416 | + require_once($path_to_file); |
|
417 | + $a = new ReflectionClass($admin_page); |
|
418 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
419 | + } |
|
420 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + public function get_admin_page_name() |
|
427 | + { |
|
428 | + return $this->_file_name . '_Admin_Page'; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @return mixed |
|
435 | + */ |
|
436 | + public function loaded_page_object() |
|
437 | + { |
|
438 | + return $this->_loaded_page_object; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + // public function set_autoloaders( $className ) { |
|
446 | + // $dir_ref = array( |
|
447 | + // $this->_folder_path => array('core','class') |
|
448 | + // ); |
|
449 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
450 | + // } |
|
451 | + /** |
|
452 | + * _check_user_access |
|
453 | + * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
454 | + * WordPress die message. |
|
455 | + * |
|
456 | + * @return bool|die true if pass (or admin) wp_die if fail |
|
457 | + */ |
|
458 | + private function _check_user_access() |
|
459 | + { |
|
460 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
461 | + $this->_menu_map->capability, |
|
462 | + $this->_menu_map->menu_slug |
|
463 | + )) { |
|
464 | + wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
465 | + } |
|
466 | + return true; |
|
467 | + } |
|
468 | 468 | |
469 | 469 | } |
470 | 470 | // end of file: includes/core/admin/EE_Admin_Page_Init.core.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->_set_menu_map(); |
96 | 96 | if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
97 | 97 | EE_Error::doing_it_wrong( |
98 | - get_class($this) . '::$_menu_map', |
|
98 | + get_class($this).'::$_menu_map', |
|
99 | 99 | sprintf( |
100 | 100 | __( |
101 | 101 | 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | { |
164 | 164 | wp_register_style( |
165 | 165 | 'espresso_menu', |
166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
166 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
167 | 167 | array('dashicons'), |
168 | 168 | EVENT_ESPRESSO_VERSION |
169 | 169 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | protected function _set_capability() |
194 | 194 | { |
195 | 195 | $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
196 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | //let's check user access first |
214 | 214 | $this->_check_user_access(); |
215 | - if (! is_object($this->_loaded_page_object)) { |
|
215 | + if ( ! is_object($this->_loaded_page_object)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | $this->_loaded_page_object->route_admin_request(); |
@@ -223,30 +223,30 @@ discard block |
||
223 | 223 | |
224 | 224 | public function set_page_dependencies($wp_page_slug) |
225 | 225 | { |
226 | - if (! $this->_load_page) { |
|
226 | + if ( ! $this->_load_page) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - if (! is_object($this->_loaded_page_object)) { |
|
229 | + if ( ! is_object($this->_loaded_page_object)) { |
|
230 | 230 | $msg[] = __( |
231 | 231 | 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
232 | 232 | 'event_espresso' |
233 | 233 | ); |
234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
234 | + $msg[] = $msg[0]."\r\n".sprintf( |
|
235 | 235 | __( |
236 | 236 | 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
237 | 237 | 'event_espresso' |
238 | 238 | ), |
239 | 239 | $this->_file_name, |
240 | 240 | $this->_file_name, |
241 | - $this->_folder_path . $this->_file_name, |
|
241 | + $this->_folder_path.$this->_file_name, |
|
242 | 242 | $this->_menu_map->menu_slug |
243 | 243 | ); |
244 | 244 | throw new EE_Error(implode('||', $msg)); |
245 | 245 | } |
246 | 246 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
247 | - $page_hook = 'load-' . $wp_page_slug; |
|
247 | + $page_hook = 'load-'.$wp_page_slug; |
|
248 | 248 | //hook into page load hook so all page specific stuff get's loaded. |
249 | - if (! empty($wp_page_slug)) { |
|
249 | + if ( ! empty($wp_page_slug)) { |
|
250 | 250 | add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
251 | 251 | } |
252 | 252 | } |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | if (isset($values['class']) && $values['class'] == $class) { |
285 | 285 | $file_index = $index - 1; |
286 | 286 | $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
287 | - if (! empty($this->_folder_name)) { |
|
287 | + if ( ! empty($this->_folder_name)) { |
|
288 | 288 | break; |
289 | 289 | } |
290 | 290 | } |
291 | 291 | } |
292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
292 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS; |
|
293 | 293 | $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
294 | 294 | $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
295 | 295 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
@@ -321,17 +321,17 @@ discard block |
||
321 | 321 | . $this->_file_name |
322 | 322 | . '_Hooks_Extend.class.php' |
323 | 323 | ); |
324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | 325 | } |
326 | 326 | //loop through decaf folders |
327 | 327 | $hook_files_glob_path = apply_filters( |
328 | 328 | 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
329 | + $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php' |
|
330 | 330 | ); |
331 | - $this->_hook_paths = array_merge( |
|
331 | + $this->_hook_paths = array_merge( |
|
332 | 332 | $this->_register_hook_files($hook_files_glob_path), |
333 | 333 | $this->_hook_paths |
334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | 335 | return $this->_hook_paths; |
336 | 336 | } |
337 | 337 | |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | } |
347 | 347 | foreach ($hook_files as $file) { |
348 | 348 | //lets get the linked admin. |
349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file) |
|
350 | 350 | : str_replace($this->_folder_path, '', $file); |
351 | 351 | $replace = $extend |
352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
352 | + ? '_'.$this->_file_name.'_Hooks_Extend.class.php' |
|
353 | 353 | : '_' |
354 | 354 | . $this->_file_name |
355 | 355 | . '_Hooks.class.php'; |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | continue; |
362 | 362 | } |
363 | 363 | $this->hook_file = $hook_file; |
364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
365 | 365 | $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
366 | 366 | $this->_files_hooked[] = $rel_admin; |
367 | 367 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | public function load_admin_hook($registered_pages) |
375 | 375 | { |
376 | 376 | $this->hook_file; |
377 | - $hook_file = (array)$this->hook_file; |
|
377 | + $hook_file = (array) $this->hook_file; |
|
378 | 378 | return array_merge($hook_file, $registered_pages); |
379 | 379 | } |
380 | 380 | |
@@ -388,44 +388,44 @@ discard block |
||
388 | 388 | { |
389 | 389 | |
390 | 390 | //JUST CHECK WE'RE ON RIGHT PAGE. |
391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
391 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | 392 | return; |
393 | 393 | } //not on the right page so let's get out. |
394 | 394 | $this->_load_page = true; |
395 | 395 | //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
396 | 396 | // spl_autoload_register(array( $this, 'set_autoloaders') ); |
397 | 397 | //we don't need to do a page_request check here because it's only called via WP menu system. |
398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
398 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
399 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
400 | 400 | $admin_page = apply_filters( |
401 | 401 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
402 | 402 | $admin_page |
403 | 403 | ); |
404 | 404 | // define requested admin page class name then load the file and instantiate |
405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php'); |
|
406 | 406 | $path_to_file = apply_filters( |
407 | 407 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
408 | 408 | $path_to_file |
409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
409 | + ); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | 410 | if (is_readable($path_to_file)) { |
411 | 411 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
412 | 412 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
413 | 413 | do_action( |
414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug |
|
415 | 415 | ); |
416 | 416 | require_once($path_to_file); |
417 | 417 | $a = new ReflectionClass($admin_page); |
418 | 418 | $this->_loaded_page_object = $a->newInstance($this->_routing); |
419 | 419 | } |
420 | 420 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
425 | 425 | |
426 | 426 | public function get_admin_page_name() |
427 | 427 | { |
428 | - return $this->_file_name . '_Admin_Page'; |
|
428 | + return $this->_file_name.'_Admin_Page'; |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function _check_user_access() |
459 | 459 | { |
460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
460 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
461 | 461 | $this->_menu_map->capability, |
462 | 462 | $this->_menu_map->menu_slug |
463 | 463 | )) { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -26,750 +26,750 @@ discard block |
||
26 | 26 | class EE_Admin_Page_Loader |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * _installed_pages |
|
31 | - * objects for page_init objects detected and loaded |
|
32 | - * |
|
33 | - * @access private |
|
34 | - * @var \EE_Admin_Page_Init[] |
|
35 | - */ |
|
36 | - private $_installed_pages = array(); |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private $_menu_slugs = array(); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * _caffeinated_extends |
|
50 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
51 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - private $_caffeinated_extends = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * _current_caf_extend_slug |
|
61 | - * This property is used for holding the page slug that is required for referencing the correct |
|
62 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
63 | - * |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private $_current_caf_extend_slug; |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * _caf_autoloader |
|
72 | - * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
73 | - * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
74 | - * classes. |
|
75 | - * |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - // private $_caf_autoloader = array(); |
|
79 | - /** |
|
80 | - * _prepped_menu_maps |
|
81 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
82 | - * |
|
83 | - * @since 4.4.0 |
|
84 | - * @var EE_Admin_Page_Menu_Map[] |
|
85 | - */ |
|
86 | - private $_prepped_menu_maps = array(); |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * _admin_menu_groups |
|
92 | - * array that holds the group headings and details for |
|
93 | - * |
|
94 | - * @access private |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - private $_admin_menu_groups = array(); |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
103 | - * pages. |
|
104 | - * |
|
105 | - * @var string |
|
106 | - */ |
|
107 | - public $hook_file; |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * constructor |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @return \EE_Admin_Page_Loader |
|
116 | - */ |
|
117 | - public function __construct() |
|
118 | - { |
|
119 | - //load menu_map classes |
|
120 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
121 | - //define the default "groups" for the admin_pages |
|
122 | - $this->_set_menu_groups(); |
|
123 | - //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
124 | - // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
125 | - //let's do a scan and see what installed pages we have |
|
126 | - $this->_get_installed_pages(); |
|
127 | - //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
128 | - add_action('admin_menu', array($this, 'set_menus')); |
|
129 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
136 | - * files in the caffeinated folder. |
|
137 | - * |
|
138 | - * @access private |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function _define_caffeinated_constants() |
|
142 | - { |
|
143 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * _set_menu_groups |
|
157 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
158 | - * |
|
159 | - * @access private |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - private function _set_menu_groups() |
|
163 | - { |
|
164 | - |
|
165 | - //set array of EE_Admin_Page_Menu_Group objects |
|
166 | - $groups = array( |
|
167 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
168 | - array( |
|
169 | - 'menu_label' => __('Main', 'event_espresso'), |
|
170 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
171 | - 'menu_slug' => 'main', |
|
172 | - 'capability' => 'ee_read_ee', |
|
173 | - 'menu_order' => 0, |
|
174 | - 'parent_slug' => 'espresso_events', |
|
175 | - ) |
|
176 | - ), |
|
177 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
178 | - array( |
|
179 | - 'menu_label' => __('Management', 'event_espresso'), |
|
180 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | - 'menu_slug' => 'management', |
|
182 | - 'capability' => 'ee_read_ee', |
|
183 | - 'menu_order' => 10, |
|
184 | - 'parent_slug' => 'espresso_events', |
|
185 | - ) |
|
186 | - ), |
|
187 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
188 | - array( |
|
189 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
190 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
191 | - 'menu_slug' => 'settings', |
|
192 | - 'capability' => 'ee_read_ee', |
|
193 | - 'menu_order' => 30, |
|
194 | - 'parent_slug' => 'espresso_events', |
|
195 | - ) |
|
196 | - ), |
|
197 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
198 | - array( |
|
199 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
200 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | - 'menu_slug' => 'templates', |
|
202 | - 'capability' => 'ee_read_ee', |
|
203 | - 'menu_order' => 40, |
|
204 | - 'parent_slug' => 'espresso_events', |
|
205 | - ) |
|
206 | - ), |
|
207 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
208 | - array( |
|
209 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
210 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | - 'menu_slug' => 'extras', |
|
212 | - 'capability' => 'ee_read_ee', |
|
213 | - 'menu_order' => 50, |
|
214 | - 'parent_slug' => 'espresso_events', |
|
215 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
216 | - ) |
|
217 | - ), |
|
218 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
219 | - array( |
|
220 | - 'menu_label' => __("Tools", "event_espresso"), |
|
221 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
222 | - 'menu_slug' => 'tools', |
|
223 | - 'capability' => 'ee_read_ee', |
|
224 | - 'menu_order' => 60, |
|
225 | - 'parent_slug' => 'espresso_events', |
|
226 | - ) |
|
227 | - ), |
|
228 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
229 | - array( |
|
230 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
231 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
232 | - 'menu_slug' => 'addons', |
|
233 | - 'capability' => 'ee_read_ee', |
|
234 | - 'menu_order' => 20, |
|
235 | - 'parent_slug' => 'espresso_events', |
|
236 | - ) |
|
237 | - ), |
|
238 | - ); |
|
239 | - $this->_admin_menu_groups = apply_filters( |
|
240 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
241 | - $groups |
|
242 | - ); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
249 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
250 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
251 | - * |
|
252 | - * @since 4.4.0 |
|
253 | - * @throws \EE_Error |
|
254 | - * @return EE_Admin_Page_Menu_Group[] |
|
255 | - */ |
|
256 | - private function _rearrange_menu_groups() |
|
257 | - { |
|
258 | - $groups = array(); |
|
259 | - //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
260 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
261 | - foreach ($this->_admin_menu_groups as $group) { |
|
262 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | - throw new EE_Error( |
|
264 | - sprintf( |
|
265 | - __( |
|
266 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
267 | - 'event_espresso' |
|
268 | - ), |
|
269 | - print_r($group, true) |
|
270 | - ) |
|
271 | - ); |
|
272 | - } |
|
273 | - $groups[$group->menu_slug] = $group; |
|
274 | - } |
|
275 | - return $groups; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * _get_installed_pages |
|
282 | - * This just gets the list of installed EE_Admin_pages. |
|
283 | - * |
|
284 | - * @access private |
|
285 | - * @throws EE_Error |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - private function _get_installed_pages() |
|
289 | - { |
|
290 | - $installed_refs = array(); |
|
291 | - $exclude = array('assets', 'templates'); |
|
292 | - // grab everything in the admin core directory |
|
293 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
294 | - if ($admin_screens) { |
|
295 | - foreach ($admin_screens as $admin_screen) { |
|
296 | - // files and anything in the exclude array need not apply |
|
297 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
298 | - // these folders represent the different EE admin pages |
|
299 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
300 | - } |
|
301 | - } |
|
302 | - } |
|
303 | - if (empty($installed_refs)) { |
|
304 | - $error_msg[] = __( |
|
305 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
306 | - 'event_espresso' |
|
307 | - ); |
|
308 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
309 | - __( |
|
310 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
311 | - 'event_espresso' |
|
312 | - ), |
|
313 | - EE_ADMIN_PAGES |
|
314 | - ); |
|
315 | - throw new EE_Error(implode('||', $error_msg)); |
|
316 | - } |
|
317 | - //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
318 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
319 | - //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
320 | - $installed_refs = apply_filters( |
|
321 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
322 | - $installed_refs |
|
323 | - ); |
|
324 | - $this->_caffeinated_extends = apply_filters( |
|
325 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
326 | - $this->_caffeinated_extends |
|
327 | - ); |
|
328 | - //loop through admin pages and setup the $_installed_pages array. |
|
329 | - $hooks_ref = array(); |
|
330 | - foreach ($installed_refs as $page => $path) { |
|
331 | - // set autoloaders for our admin page classes based on included path information |
|
332 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
333 | - // build list of installed pages |
|
334 | - $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
335 | - // verify returned object |
|
336 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
337 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | - continue; |
|
339 | - } |
|
340 | - //skip if in full maintenance mode and maintenance_mode_parent is set |
|
341 | - $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
342 | - if (empty($maintenance_mode_parent) |
|
343 | - && EE_Maintenance_Mode::instance()->level() |
|
344 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
345 | - unset($installed_refs[$page]); |
|
346 | - continue; |
|
347 | - } |
|
348 | - $this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page; |
|
349 | - //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
350 | - $extend = false; |
|
351 | - //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
352 | - if (isset($this->_caffeinated_extends[$page])) { |
|
353 | - $this->_current_caf_extend_slug = $page; |
|
354 | - $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__' |
|
355 | - . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
356 | - . '_' |
|
357 | - . $this->_installed_pages[$page]->get_admin_page_name(); |
|
358 | - $path_runtime = 'return "' |
|
359 | - . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"] |
|
360 | - . '";'; |
|
361 | - $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__' |
|
362 | - . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
363 | - . '_' |
|
364 | - . $this->_installed_pages[$page]->get_admin_page_name(); |
|
365 | - $page_runtime = 'return "' |
|
366 | - . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
|
367 | - . '";'; |
|
368 | - $hook_function_path = create_function('$path_to_file', $path_runtime); |
|
369 | - $hook_function_page = create_function('$admin_page', $page_runtime); |
|
370 | - add_filter($path_hook, $hook_function_path); |
|
371 | - add_filter($page_hook, $hook_function_page); |
|
372 | - $extend = true; |
|
373 | - } |
|
374 | - //let's do the registered hooks |
|
375 | - $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
376 | - $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
377 | - } |
|
378 | - } |
|
379 | - //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
380 | - //first make sure we've got unique values |
|
381 | - $hooks_ref = array_unique($hooks_ref); |
|
382 | - //now let's loop and require! |
|
383 | - foreach ($hooks_ref as $path) { |
|
384 | - require_once($path); |
|
385 | - } |
|
386 | - //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
387 | - global $ee_menu_slugs; |
|
388 | - $ee_menu_slugs = $this->_menu_slugs; |
|
389 | - //we need to loop again to run any early code |
|
390 | - foreach ($installed_refs as $page => $path) { |
|
391 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
392 | - $this->_installed_pages[$page]->do_initial_loads(); |
|
393 | - } |
|
394 | - } |
|
395 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * get_admin_page_object |
|
402 | - * |
|
403 | - * @param string $page_slug |
|
404 | - * @return EE_Admin_Page |
|
405 | - */ |
|
406 | - public function get_admin_page_object($page_slug = '') |
|
407 | - { |
|
408 | - if (isset($this->_installed_pages[$page_slug])) { |
|
409 | - return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
410 | - } |
|
411 | - return null; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * _get_classname_for_admin_page |
|
418 | - * generates an "Admin Page" class based on the directory name |
|
419 | - * |
|
420 | - * @param $dir_name |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - private function _get_classname_for_admin_page($dir_name = '') |
|
424 | - { |
|
425 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
426 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * _get_classname_for_admin_init_page |
|
433 | - * generates an "Admin Page Init" class based on the directory name |
|
434 | - * |
|
435 | - * @param $dir_name |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
439 | - { |
|
440 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
441 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * _load_admin_page |
|
448 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
449 | - * |
|
450 | - * @param string $page page_reference |
|
451 | - * @param string $path |
|
452 | - * @throws EE_Error |
|
453 | - * @return object|bool return page object if valid, bool false if not. |
|
454 | - */ |
|
455 | - private function _load_admin_page($page = '', $path = '') |
|
456 | - { |
|
457 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
458 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
459 | - if (! class_exists($class_name)) { |
|
460 | - $inner_error_msg = '<br />' . sprintf( |
|
461 | - esc_html__( |
|
462 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
463 | - 'event_espresso' |
|
464 | - ), |
|
465 | - '<strong>' . $class_name . '</strong>' |
|
466 | - ); |
|
467 | - $error_msg[] = sprintf( |
|
468 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
469 | - $page |
|
470 | - ); |
|
471 | - $error_msg[] = $error_msg[0] |
|
472 | - . "\r\n" |
|
473 | - . sprintf( |
|
474 | - esc_html__( |
|
475 | - 'There is no Init class in place for the %s admin page.', |
|
476 | - 'event_espresso' |
|
477 | - ), |
|
478 | - $page |
|
479 | - ) |
|
480 | - . $inner_error_msg; |
|
481 | - throw new EE_Error(implode('||', $error_msg)); |
|
482 | - } |
|
483 | - $a = new ReflectionClass($class_name); |
|
484 | - return $a->newInstance(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * set_menus |
|
491 | - * This method sets up the menus for EE Admin Pages |
|
492 | - * |
|
493 | - * @access private |
|
494 | - * @return void |
|
495 | - */ |
|
496 | - public function set_menus() |
|
497 | - { |
|
498 | - //prep the menu pages (sort, group.) |
|
499 | - $this->_prep_pages(); |
|
500 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
501 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
502 | - $menu_map->add_menu_page(false); |
|
503 | - } |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * set_network_menus |
|
510 | - * This method sets up the menus for network EE Admin Pages. |
|
511 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
512 | - * are only added to the menu map if they are intended for the admin menu |
|
513 | - * |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function set_network_menus() |
|
517 | - { |
|
518 | - $this->_prep_pages(); |
|
519 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
520 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
521 | - $menu_map->add_menu_page(true); |
|
522 | - } |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * _prep_pages |
|
530 | - * sets the _prepped_menu_maps property |
|
531 | - * |
|
532 | - * @access private |
|
533 | - * @throws EE_Error |
|
534 | - * @return void |
|
535 | - */ |
|
536 | - private function _prep_pages() |
|
537 | - { |
|
538 | - $pages_array = array(); |
|
539 | - //rearrange _admin_menu_groups to be indexed by group slug. |
|
540 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
541 | - foreach ($this->_installed_pages as $page) { |
|
542 | - if ($page instanceof EE_Admin_page_Init) { |
|
543 | - $page_map = $page->get_menu_map(); |
|
544 | - //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
545 | - if (is_array($page_map) || empty($page_map)) { |
|
546 | - EE_Error::add_persistent_admin_notice( |
|
547 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
548 | - sprintf( |
|
549 | - __( |
|
550 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
551 | - 'event_espresso' |
|
552 | - ), |
|
553 | - $page->label |
|
554 | - ) |
|
555 | - ); |
|
556 | - continue; |
|
557 | - } |
|
558 | - //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
559 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | - throw new EE_Error( |
|
561 | - sprintf( |
|
562 | - __( |
|
563 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
564 | - 'event_espresso' |
|
565 | - ), |
|
566 | - $page->label, |
|
567 | - $page_map |
|
568 | - ) |
|
569 | - ); |
|
570 | - } |
|
571 | - //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
572 | - if (empty($page_map->maintenance_mode_parent) |
|
573 | - && EE_Maintenance_Mode::instance()->level() |
|
574 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
575 | - continue; |
|
576 | - } |
|
577 | - //assign to group (remember $page_map has the admin page stored in it). |
|
578 | - $pages_array[$page_map->menu_group][] = $page_map; |
|
579 | - } |
|
580 | - } |
|
581 | - if (empty($pages_array)) { |
|
582 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
583 | - } |
|
584 | - //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
585 | - foreach ($pages_array as $group => $menu_maps) { |
|
586 | - //valid_group? |
|
587 | - if (! array_key_exists($group, $menu_groups)) { |
|
588 | - continue; |
|
589 | - } |
|
590 | - //sort pages. |
|
591 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
592 | - //prepend header |
|
593 | - array_unshift($menu_maps, $menu_groups[$group]); |
|
594 | - //reset $pages_array with prepped data |
|
595 | - $pages_array[$group] = $menu_maps; |
|
596 | - } |
|
597 | - //now let's setup the _prepped_menu_maps property |
|
598 | - foreach ($menu_groups as $group => $group_objs) { |
|
599 | - if (isset($pages_array[$group])) { |
|
600 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
601 | - } |
|
602 | - }/**/ |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
609 | - * In this method there are three checks being done: |
|
610 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
611 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
612 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
613 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
614 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
615 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
616 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
617 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
618 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
619 | - * admin_pages) |
|
620 | - * |
|
621 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
622 | - * loaded. |
|
623 | - * @return array |
|
624 | - */ |
|
625 | - private function _set_caffeinated($installed_refs) |
|
626 | - { |
|
627 | - |
|
628 | - //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | - return $installed_refs; |
|
631 | - } |
|
632 | - $this->_define_caffeinated_constants(); |
|
633 | - $exclude = array('tickets'); |
|
634 | - //okay let's setup an "New" pages first (we'll return installed refs later) |
|
635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
636 | - if ($new_admin_screens) { |
|
637 | - foreach ($new_admin_screens as $admin_screen) { |
|
638 | - // files and anything in the exclude array need not apply |
|
639 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
640 | - // these folders represent the different NEW EE admin pages |
|
641 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
642 | - // set autoloaders for our admin page classes based on included path information |
|
643 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
644 | - // $this->_caf_autoloader[] = array( |
|
645 | - // 'dir' => 'new', |
|
646 | - // 'folder' => basename( $admin_screen ) |
|
647 | - // ); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
653 | - if ($extends) { |
|
654 | - foreach ($extends as $extend) { |
|
655 | - if (is_dir($extend)) { |
|
656 | - $extend_ref = basename($extend); |
|
657 | - //now let's make sure there is a file that matches the expected format |
|
658 | - $filename = str_replace( |
|
659 | - ' ', |
|
660 | - '_', |
|
661 | - ucwords( |
|
662 | - str_replace( |
|
663 | - '_', |
|
664 | - ' ', |
|
665 | - $extend_ref |
|
666 | - ) |
|
667 | - ) |
|
668 | - ); |
|
669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
670 | - $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
671 | - array('\\', '/'), |
|
672 | - DS, |
|
673 | - EE_CORE_CAF_ADMIN |
|
674 | - . 'extend' |
|
675 | - . DS |
|
676 | - . $extend_ref |
|
677 | - . DS |
|
678 | - . $filename |
|
679 | - . '.core.php' |
|
680 | - ); |
|
681 | - $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
682 | - // set autoloaders for our admin page classes based on included path information |
|
683 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
684 | - // $this->_caf_autoloader[] = array( |
|
685 | - // 'dir' => 'extend', |
|
686 | - // 'folder' => $extend_ref |
|
687 | - // ); |
|
688 | - } |
|
689 | - } |
|
690 | - } |
|
691 | - //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
692 | - $ee_admin_hooks = array(); |
|
693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
694 | - if ($hooks) { |
|
695 | - foreach ($hooks as $hook) { |
|
696 | - if (is_readable($hook)) { |
|
697 | - require_once $hook; |
|
698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
699 | - $classname = str_replace('.class.php', '', $classname); |
|
700 | - if (class_exists($classname)) { |
|
701 | - $a = new ReflectionClass($classname); |
|
702 | - $ee_admin_hooks[] = $a->newInstance(); |
|
703 | - } |
|
704 | - } |
|
705 | - } |
|
706 | - }/**/ |
|
707 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
708 | - return $installed_refs; |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * Initial autoloader registration |
|
717 | - * This just sets up the autoloader for the root admin files |
|
718 | - * |
|
719 | - * @param string $className incoming classname to check for autoload |
|
720 | - * @return void |
|
721 | - */ |
|
722 | - // public function init_autoloaders( $className ) { |
|
723 | - // $dir_ref = array( |
|
724 | - // EE_ADMIN => array('core', 'class') |
|
725 | - // ); |
|
726 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
727 | - // } |
|
728 | - /** |
|
729 | - * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
730 | - * caffeinated folders. |
|
731 | - * |
|
732 | - * @access public |
|
733 | - * @param string $className in coming classname being called |
|
734 | - * @return void |
|
735 | - */ |
|
736 | - // public function caffeinated_autoloaders( $className ) { |
|
737 | - // //let's setup an array of paths to check (for each subsystem) |
|
738 | - // $dir_ref = array(); |
|
739 | - // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
740 | - // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
741 | - // } |
|
742 | - // |
|
743 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
744 | - // } |
|
745 | - /** |
|
746 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
747 | - * |
|
748 | - * @since 4.4.0 |
|
749 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
750 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
751 | - * @return int sort order |
|
752 | - */ |
|
753 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
754 | - { |
|
755 | - if ($a->menu_order == $b->menu_order) { |
|
756 | - return 0; |
|
757 | - } |
|
758 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * _default_header_link |
|
765 | - * This is just a dummy method to use with header submenu items |
|
766 | - * |
|
767 | - * @return bool false |
|
768 | - */ |
|
769 | - public function _default_header_link() |
|
770 | - { |
|
771 | - return false; |
|
772 | - } |
|
29 | + /** |
|
30 | + * _installed_pages |
|
31 | + * objects for page_init objects detected and loaded |
|
32 | + * |
|
33 | + * @access private |
|
34 | + * @var \EE_Admin_Page_Init[] |
|
35 | + */ |
|
36 | + private $_installed_pages = array(); |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private $_menu_slugs = array(); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * _caffeinated_extends |
|
50 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
51 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + private $_caffeinated_extends = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * _current_caf_extend_slug |
|
61 | + * This property is used for holding the page slug that is required for referencing the correct |
|
62 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
63 | + * |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private $_current_caf_extend_slug; |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * _caf_autoloader |
|
72 | + * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
73 | + * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
74 | + * classes. |
|
75 | + * |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + // private $_caf_autoloader = array(); |
|
79 | + /** |
|
80 | + * _prepped_menu_maps |
|
81 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
82 | + * |
|
83 | + * @since 4.4.0 |
|
84 | + * @var EE_Admin_Page_Menu_Map[] |
|
85 | + */ |
|
86 | + private $_prepped_menu_maps = array(); |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * _admin_menu_groups |
|
92 | + * array that holds the group headings and details for |
|
93 | + * |
|
94 | + * @access private |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + private $_admin_menu_groups = array(); |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
103 | + * pages. |
|
104 | + * |
|
105 | + * @var string |
|
106 | + */ |
|
107 | + public $hook_file; |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * constructor |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @return \EE_Admin_Page_Loader |
|
116 | + */ |
|
117 | + public function __construct() |
|
118 | + { |
|
119 | + //load menu_map classes |
|
120 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
121 | + //define the default "groups" for the admin_pages |
|
122 | + $this->_set_menu_groups(); |
|
123 | + //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
124 | + // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
125 | + //let's do a scan and see what installed pages we have |
|
126 | + $this->_get_installed_pages(); |
|
127 | + //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
128 | + add_action('admin_menu', array($this, 'set_menus')); |
|
129 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
136 | + * files in the caffeinated folder. |
|
137 | + * |
|
138 | + * @access private |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function _define_caffeinated_constants() |
|
142 | + { |
|
143 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * _set_menu_groups |
|
157 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
158 | + * |
|
159 | + * @access private |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + private function _set_menu_groups() |
|
163 | + { |
|
164 | + |
|
165 | + //set array of EE_Admin_Page_Menu_Group objects |
|
166 | + $groups = array( |
|
167 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
168 | + array( |
|
169 | + 'menu_label' => __('Main', 'event_espresso'), |
|
170 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
171 | + 'menu_slug' => 'main', |
|
172 | + 'capability' => 'ee_read_ee', |
|
173 | + 'menu_order' => 0, |
|
174 | + 'parent_slug' => 'espresso_events', |
|
175 | + ) |
|
176 | + ), |
|
177 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
178 | + array( |
|
179 | + 'menu_label' => __('Management', 'event_espresso'), |
|
180 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | + 'menu_slug' => 'management', |
|
182 | + 'capability' => 'ee_read_ee', |
|
183 | + 'menu_order' => 10, |
|
184 | + 'parent_slug' => 'espresso_events', |
|
185 | + ) |
|
186 | + ), |
|
187 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
188 | + array( |
|
189 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
190 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
191 | + 'menu_slug' => 'settings', |
|
192 | + 'capability' => 'ee_read_ee', |
|
193 | + 'menu_order' => 30, |
|
194 | + 'parent_slug' => 'espresso_events', |
|
195 | + ) |
|
196 | + ), |
|
197 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
198 | + array( |
|
199 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
200 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | + 'menu_slug' => 'templates', |
|
202 | + 'capability' => 'ee_read_ee', |
|
203 | + 'menu_order' => 40, |
|
204 | + 'parent_slug' => 'espresso_events', |
|
205 | + ) |
|
206 | + ), |
|
207 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
208 | + array( |
|
209 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
210 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | + 'menu_slug' => 'extras', |
|
212 | + 'capability' => 'ee_read_ee', |
|
213 | + 'menu_order' => 50, |
|
214 | + 'parent_slug' => 'espresso_events', |
|
215 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
216 | + ) |
|
217 | + ), |
|
218 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
219 | + array( |
|
220 | + 'menu_label' => __("Tools", "event_espresso"), |
|
221 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
222 | + 'menu_slug' => 'tools', |
|
223 | + 'capability' => 'ee_read_ee', |
|
224 | + 'menu_order' => 60, |
|
225 | + 'parent_slug' => 'espresso_events', |
|
226 | + ) |
|
227 | + ), |
|
228 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
229 | + array( |
|
230 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
231 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
232 | + 'menu_slug' => 'addons', |
|
233 | + 'capability' => 'ee_read_ee', |
|
234 | + 'menu_order' => 20, |
|
235 | + 'parent_slug' => 'espresso_events', |
|
236 | + ) |
|
237 | + ), |
|
238 | + ); |
|
239 | + $this->_admin_menu_groups = apply_filters( |
|
240 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
241 | + $groups |
|
242 | + ); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
249 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
250 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
251 | + * |
|
252 | + * @since 4.4.0 |
|
253 | + * @throws \EE_Error |
|
254 | + * @return EE_Admin_Page_Menu_Group[] |
|
255 | + */ |
|
256 | + private function _rearrange_menu_groups() |
|
257 | + { |
|
258 | + $groups = array(); |
|
259 | + //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
260 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
261 | + foreach ($this->_admin_menu_groups as $group) { |
|
262 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | + throw new EE_Error( |
|
264 | + sprintf( |
|
265 | + __( |
|
266 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
267 | + 'event_espresso' |
|
268 | + ), |
|
269 | + print_r($group, true) |
|
270 | + ) |
|
271 | + ); |
|
272 | + } |
|
273 | + $groups[$group->menu_slug] = $group; |
|
274 | + } |
|
275 | + return $groups; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * _get_installed_pages |
|
282 | + * This just gets the list of installed EE_Admin_pages. |
|
283 | + * |
|
284 | + * @access private |
|
285 | + * @throws EE_Error |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + private function _get_installed_pages() |
|
289 | + { |
|
290 | + $installed_refs = array(); |
|
291 | + $exclude = array('assets', 'templates'); |
|
292 | + // grab everything in the admin core directory |
|
293 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
294 | + if ($admin_screens) { |
|
295 | + foreach ($admin_screens as $admin_screen) { |
|
296 | + // files and anything in the exclude array need not apply |
|
297 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
298 | + // these folders represent the different EE admin pages |
|
299 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
300 | + } |
|
301 | + } |
|
302 | + } |
|
303 | + if (empty($installed_refs)) { |
|
304 | + $error_msg[] = __( |
|
305 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
306 | + 'event_espresso' |
|
307 | + ); |
|
308 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
309 | + __( |
|
310 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
311 | + 'event_espresso' |
|
312 | + ), |
|
313 | + EE_ADMIN_PAGES |
|
314 | + ); |
|
315 | + throw new EE_Error(implode('||', $error_msg)); |
|
316 | + } |
|
317 | + //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
318 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
319 | + //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
320 | + $installed_refs = apply_filters( |
|
321 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
322 | + $installed_refs |
|
323 | + ); |
|
324 | + $this->_caffeinated_extends = apply_filters( |
|
325 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
326 | + $this->_caffeinated_extends |
|
327 | + ); |
|
328 | + //loop through admin pages and setup the $_installed_pages array. |
|
329 | + $hooks_ref = array(); |
|
330 | + foreach ($installed_refs as $page => $path) { |
|
331 | + // set autoloaders for our admin page classes based on included path information |
|
332 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
333 | + // build list of installed pages |
|
334 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
335 | + // verify returned object |
|
336 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
337 | + if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | + continue; |
|
339 | + } |
|
340 | + //skip if in full maintenance mode and maintenance_mode_parent is set |
|
341 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
342 | + if (empty($maintenance_mode_parent) |
|
343 | + && EE_Maintenance_Mode::instance()->level() |
|
344 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
345 | + unset($installed_refs[$page]); |
|
346 | + continue; |
|
347 | + } |
|
348 | + $this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page; |
|
349 | + //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
350 | + $extend = false; |
|
351 | + //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
352 | + if (isset($this->_caffeinated_extends[$page])) { |
|
353 | + $this->_current_caf_extend_slug = $page; |
|
354 | + $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__' |
|
355 | + . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
356 | + . '_' |
|
357 | + . $this->_installed_pages[$page]->get_admin_page_name(); |
|
358 | + $path_runtime = 'return "' |
|
359 | + . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"] |
|
360 | + . '";'; |
|
361 | + $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__' |
|
362 | + . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
363 | + . '_' |
|
364 | + . $this->_installed_pages[$page]->get_admin_page_name(); |
|
365 | + $page_runtime = 'return "' |
|
366 | + . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
|
367 | + . '";'; |
|
368 | + $hook_function_path = create_function('$path_to_file', $path_runtime); |
|
369 | + $hook_function_page = create_function('$admin_page', $page_runtime); |
|
370 | + add_filter($path_hook, $hook_function_path); |
|
371 | + add_filter($page_hook, $hook_function_page); |
|
372 | + $extend = true; |
|
373 | + } |
|
374 | + //let's do the registered hooks |
|
375 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
376 | + $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
377 | + } |
|
378 | + } |
|
379 | + //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
380 | + //first make sure we've got unique values |
|
381 | + $hooks_ref = array_unique($hooks_ref); |
|
382 | + //now let's loop and require! |
|
383 | + foreach ($hooks_ref as $path) { |
|
384 | + require_once($path); |
|
385 | + } |
|
386 | + //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
387 | + global $ee_menu_slugs; |
|
388 | + $ee_menu_slugs = $this->_menu_slugs; |
|
389 | + //we need to loop again to run any early code |
|
390 | + foreach ($installed_refs as $page => $path) { |
|
391 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
392 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
393 | + } |
|
394 | + } |
|
395 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * get_admin_page_object |
|
402 | + * |
|
403 | + * @param string $page_slug |
|
404 | + * @return EE_Admin_Page |
|
405 | + */ |
|
406 | + public function get_admin_page_object($page_slug = '') |
|
407 | + { |
|
408 | + if (isset($this->_installed_pages[$page_slug])) { |
|
409 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
410 | + } |
|
411 | + return null; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * _get_classname_for_admin_page |
|
418 | + * generates an "Admin Page" class based on the directory name |
|
419 | + * |
|
420 | + * @param $dir_name |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + private function _get_classname_for_admin_page($dir_name = '') |
|
424 | + { |
|
425 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
426 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * _get_classname_for_admin_init_page |
|
433 | + * generates an "Admin Page Init" class based on the directory name |
|
434 | + * |
|
435 | + * @param $dir_name |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
439 | + { |
|
440 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
441 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * _load_admin_page |
|
448 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
449 | + * |
|
450 | + * @param string $page page_reference |
|
451 | + * @param string $path |
|
452 | + * @throws EE_Error |
|
453 | + * @return object|bool return page object if valid, bool false if not. |
|
454 | + */ |
|
455 | + private function _load_admin_page($page = '', $path = '') |
|
456 | + { |
|
457 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
458 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
459 | + if (! class_exists($class_name)) { |
|
460 | + $inner_error_msg = '<br />' . sprintf( |
|
461 | + esc_html__( |
|
462 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
463 | + 'event_espresso' |
|
464 | + ), |
|
465 | + '<strong>' . $class_name . '</strong>' |
|
466 | + ); |
|
467 | + $error_msg[] = sprintf( |
|
468 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
469 | + $page |
|
470 | + ); |
|
471 | + $error_msg[] = $error_msg[0] |
|
472 | + . "\r\n" |
|
473 | + . sprintf( |
|
474 | + esc_html__( |
|
475 | + 'There is no Init class in place for the %s admin page.', |
|
476 | + 'event_espresso' |
|
477 | + ), |
|
478 | + $page |
|
479 | + ) |
|
480 | + . $inner_error_msg; |
|
481 | + throw new EE_Error(implode('||', $error_msg)); |
|
482 | + } |
|
483 | + $a = new ReflectionClass($class_name); |
|
484 | + return $a->newInstance(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * set_menus |
|
491 | + * This method sets up the menus for EE Admin Pages |
|
492 | + * |
|
493 | + * @access private |
|
494 | + * @return void |
|
495 | + */ |
|
496 | + public function set_menus() |
|
497 | + { |
|
498 | + //prep the menu pages (sort, group.) |
|
499 | + $this->_prep_pages(); |
|
500 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
501 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
502 | + $menu_map->add_menu_page(false); |
|
503 | + } |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * set_network_menus |
|
510 | + * This method sets up the menus for network EE Admin Pages. |
|
511 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
512 | + * are only added to the menu map if they are intended for the admin menu |
|
513 | + * |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function set_network_menus() |
|
517 | + { |
|
518 | + $this->_prep_pages(); |
|
519 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
520 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
521 | + $menu_map->add_menu_page(true); |
|
522 | + } |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * _prep_pages |
|
530 | + * sets the _prepped_menu_maps property |
|
531 | + * |
|
532 | + * @access private |
|
533 | + * @throws EE_Error |
|
534 | + * @return void |
|
535 | + */ |
|
536 | + private function _prep_pages() |
|
537 | + { |
|
538 | + $pages_array = array(); |
|
539 | + //rearrange _admin_menu_groups to be indexed by group slug. |
|
540 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
541 | + foreach ($this->_installed_pages as $page) { |
|
542 | + if ($page instanceof EE_Admin_page_Init) { |
|
543 | + $page_map = $page->get_menu_map(); |
|
544 | + //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
545 | + if (is_array($page_map) || empty($page_map)) { |
|
546 | + EE_Error::add_persistent_admin_notice( |
|
547 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
548 | + sprintf( |
|
549 | + __( |
|
550 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
551 | + 'event_espresso' |
|
552 | + ), |
|
553 | + $page->label |
|
554 | + ) |
|
555 | + ); |
|
556 | + continue; |
|
557 | + } |
|
558 | + //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
559 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | + throw new EE_Error( |
|
561 | + sprintf( |
|
562 | + __( |
|
563 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
564 | + 'event_espresso' |
|
565 | + ), |
|
566 | + $page->label, |
|
567 | + $page_map |
|
568 | + ) |
|
569 | + ); |
|
570 | + } |
|
571 | + //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
572 | + if (empty($page_map->maintenance_mode_parent) |
|
573 | + && EE_Maintenance_Mode::instance()->level() |
|
574 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
575 | + continue; |
|
576 | + } |
|
577 | + //assign to group (remember $page_map has the admin page stored in it). |
|
578 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
579 | + } |
|
580 | + } |
|
581 | + if (empty($pages_array)) { |
|
582 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
583 | + } |
|
584 | + //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
585 | + foreach ($pages_array as $group => $menu_maps) { |
|
586 | + //valid_group? |
|
587 | + if (! array_key_exists($group, $menu_groups)) { |
|
588 | + continue; |
|
589 | + } |
|
590 | + //sort pages. |
|
591 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
592 | + //prepend header |
|
593 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
594 | + //reset $pages_array with prepped data |
|
595 | + $pages_array[$group] = $menu_maps; |
|
596 | + } |
|
597 | + //now let's setup the _prepped_menu_maps property |
|
598 | + foreach ($menu_groups as $group => $group_objs) { |
|
599 | + if (isset($pages_array[$group])) { |
|
600 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
601 | + } |
|
602 | + }/**/ |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
609 | + * In this method there are three checks being done: |
|
610 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
611 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
612 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
613 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
614 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
615 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
616 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
617 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
618 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
619 | + * admin_pages) |
|
620 | + * |
|
621 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
622 | + * loaded. |
|
623 | + * @return array |
|
624 | + */ |
|
625 | + private function _set_caffeinated($installed_refs) |
|
626 | + { |
|
627 | + |
|
628 | + //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
629 | + if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | + return $installed_refs; |
|
631 | + } |
|
632 | + $this->_define_caffeinated_constants(); |
|
633 | + $exclude = array('tickets'); |
|
634 | + //okay let's setup an "New" pages first (we'll return installed refs later) |
|
635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
636 | + if ($new_admin_screens) { |
|
637 | + foreach ($new_admin_screens as $admin_screen) { |
|
638 | + // files and anything in the exclude array need not apply |
|
639 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
640 | + // these folders represent the different NEW EE admin pages |
|
641 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
642 | + // set autoloaders for our admin page classes based on included path information |
|
643 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
644 | + // $this->_caf_autoloader[] = array( |
|
645 | + // 'dir' => 'new', |
|
646 | + // 'folder' => basename( $admin_screen ) |
|
647 | + // ); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
652 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
653 | + if ($extends) { |
|
654 | + foreach ($extends as $extend) { |
|
655 | + if (is_dir($extend)) { |
|
656 | + $extend_ref = basename($extend); |
|
657 | + //now let's make sure there is a file that matches the expected format |
|
658 | + $filename = str_replace( |
|
659 | + ' ', |
|
660 | + '_', |
|
661 | + ucwords( |
|
662 | + str_replace( |
|
663 | + '_', |
|
664 | + ' ', |
|
665 | + $extend_ref |
|
666 | + ) |
|
667 | + ) |
|
668 | + ); |
|
669 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
670 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
671 | + array('\\', '/'), |
|
672 | + DS, |
|
673 | + EE_CORE_CAF_ADMIN |
|
674 | + . 'extend' |
|
675 | + . DS |
|
676 | + . $extend_ref |
|
677 | + . DS |
|
678 | + . $filename |
|
679 | + . '.core.php' |
|
680 | + ); |
|
681 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
682 | + // set autoloaders for our admin page classes based on included path information |
|
683 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
684 | + // $this->_caf_autoloader[] = array( |
|
685 | + // 'dir' => 'extend', |
|
686 | + // 'folder' => $extend_ref |
|
687 | + // ); |
|
688 | + } |
|
689 | + } |
|
690 | + } |
|
691 | + //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
692 | + $ee_admin_hooks = array(); |
|
693 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
694 | + if ($hooks) { |
|
695 | + foreach ($hooks as $hook) { |
|
696 | + if (is_readable($hook)) { |
|
697 | + require_once $hook; |
|
698 | + $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
699 | + $classname = str_replace('.class.php', '', $classname); |
|
700 | + if (class_exists($classname)) { |
|
701 | + $a = new ReflectionClass($classname); |
|
702 | + $ee_admin_hooks[] = $a->newInstance(); |
|
703 | + } |
|
704 | + } |
|
705 | + } |
|
706 | + }/**/ |
|
707 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
708 | + return $installed_refs; |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * Initial autoloader registration |
|
717 | + * This just sets up the autoloader for the root admin files |
|
718 | + * |
|
719 | + * @param string $className incoming classname to check for autoload |
|
720 | + * @return void |
|
721 | + */ |
|
722 | + // public function init_autoloaders( $className ) { |
|
723 | + // $dir_ref = array( |
|
724 | + // EE_ADMIN => array('core', 'class') |
|
725 | + // ); |
|
726 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
727 | + // } |
|
728 | + /** |
|
729 | + * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
730 | + * caffeinated folders. |
|
731 | + * |
|
732 | + * @access public |
|
733 | + * @param string $className in coming classname being called |
|
734 | + * @return void |
|
735 | + */ |
|
736 | + // public function caffeinated_autoloaders( $className ) { |
|
737 | + // //let's setup an array of paths to check (for each subsystem) |
|
738 | + // $dir_ref = array(); |
|
739 | + // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
740 | + // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
741 | + // } |
|
742 | + // |
|
743 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
744 | + // } |
|
745 | + /** |
|
746 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
747 | + * |
|
748 | + * @since 4.4.0 |
|
749 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
750 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
751 | + * @return int sort order |
|
752 | + */ |
|
753 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
754 | + { |
|
755 | + if ($a->menu_order == $b->menu_order) { |
|
756 | + return 0; |
|
757 | + } |
|
758 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * _default_header_link |
|
765 | + * This is just a dummy method to use with header submenu items |
|
766 | + * |
|
767 | + * @return bool false |
|
768 | + */ |
|
769 | + public function _default_header_link() |
|
770 | + { |
|
771 | + return false; |
|
772 | + } |
|
773 | 773 | |
774 | 774 | |
775 | 775 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function _define_caffeinated_constants() |
142 | 142 | { |
143 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
143 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
145 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
146 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
147 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
148 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
149 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
260 | 260 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
261 | 261 | foreach ($this->_admin_menu_groups as $group) { |
262 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
262 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | 263 | throw new EE_Error( |
264 | 264 | sprintf( |
265 | 265 | __( |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | $installed_refs = array(); |
291 | 291 | $exclude = array('assets', 'templates'); |
292 | 292 | // grab everything in the admin core directory |
293 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
293 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
294 | 294 | if ($admin_screens) { |
295 | 295 | foreach ($admin_screens as $admin_screen) { |
296 | 296 | // files and anything in the exclude array need not apply |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
306 | 306 | 'event_espresso' |
307 | 307 | ); |
308 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
308 | + $error_msg[] = $error_msg[0]."\r\n".sprintf( |
|
309 | 309 | __( |
310 | 310 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
311 | 311 | 'event_espresso' |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
318 | 318 | $installed_refs = $this->_set_caffeinated($installed_refs); |
319 | 319 | //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
320 | - $installed_refs = apply_filters( |
|
320 | + $installed_refs = apply_filters( |
|
321 | 321 | 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
322 | 322 | $installed_refs |
323 | 323 | ); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
335 | 335 | // verify returned object |
336 | 336 | if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
337 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
337 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | 338 | continue; |
339 | 339 | } |
340 | 340 | //skip if in full maintenance mode and maintenance_mode_parent is set |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
363 | 363 | . '_' |
364 | 364 | . $this->_installed_pages[$page]->get_admin_page_name(); |
365 | - $page_runtime = 'return "' |
|
365 | + $page_runtime = 'return "' |
|
366 | 366 | . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
367 | 367 | . '";'; |
368 | 368 | $hook_function_path = create_function('$path_to_file', $path_runtime); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | private function _get_classname_for_admin_page($dir_name = '') |
424 | 424 | { |
425 | 425 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
426 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
426 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | private function _get_classname_for_admin_init_page($dir_name = '') |
439 | 439 | { |
440 | 440 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
441 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
441 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | |
@@ -456,19 +456,19 @@ discard block |
||
456 | 456 | { |
457 | 457 | $class_name = $this->_get_classname_for_admin_init_page($page); |
458 | 458 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
459 | - if (! class_exists($class_name)) { |
|
460 | - $inner_error_msg = '<br />' . sprintf( |
|
459 | + if ( ! class_exists($class_name)) { |
|
460 | + $inner_error_msg = '<br />'.sprintf( |
|
461 | 461 | esc_html__( |
462 | 462 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
463 | 463 | 'event_espresso' |
464 | 464 | ), |
465 | - '<strong>' . $class_name . '</strong>' |
|
465 | + '<strong>'.$class_name.'</strong>' |
|
466 | 466 | ); |
467 | - $error_msg[] = sprintf( |
|
467 | + $error_msg[] = sprintf( |
|
468 | 468 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
469 | 469 | $page |
470 | 470 | ); |
471 | - $error_msg[] = $error_msg[0] |
|
471 | + $error_msg[] = $error_msg[0] |
|
472 | 472 | . "\r\n" |
473 | 473 | . sprintf( |
474 | 474 | esc_html__( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
545 | 545 | if (is_array($page_map) || empty($page_map)) { |
546 | 546 | EE_Error::add_persistent_admin_notice( |
547 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
547 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
548 | 548 | sprintf( |
549 | 549 | __( |
550 | 550 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | continue; |
557 | 557 | } |
558 | 558 | //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
559 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
559 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | 560 | throw new EE_Error( |
561 | 561 | sprintf( |
562 | 562 | __( |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | //let's sort the groups, make sure it's a valid group, add header (if to show). |
585 | 585 | foreach ($pages_array as $group => $menu_maps) { |
586 | 586 | //valid_group? |
587 | - if (! array_key_exists($group, $menu_groups)) { |
|
587 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
588 | 588 | continue; |
589 | 589 | } |
590 | 590 | //sort pages. |
@@ -626,13 +626,13 @@ discard block |
||
626 | 626 | { |
627 | 627 | |
628 | 628 | //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
629 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | 630 | return $installed_refs; |
631 | 631 | } |
632 | 632 | $this->_define_caffeinated_constants(); |
633 | 633 | $exclude = array('tickets'); |
634 | 634 | //okay let's setup an "New" pages first (we'll return installed refs later) |
635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
636 | 636 | if ($new_admin_screens) { |
637 | 637 | foreach ($new_admin_screens as $admin_screen) { |
638 | 638 | // files and anything in the exclude array need not apply |
@@ -649,13 +649,13 @@ discard block |
||
649 | 649 | } |
650 | 650 | } |
651 | 651 | //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
652 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
653 | 653 | if ($extends) { |
654 | 654 | foreach ($extends as $extend) { |
655 | 655 | if (is_dir($extend)) { |
656 | 656 | $extend_ref = basename($extend); |
657 | 657 | //now let's make sure there is a file that matches the expected format |
658 | - $filename = str_replace( |
|
658 | + $filename = str_replace( |
|
659 | 659 | ' ', |
660 | 660 | '_', |
661 | 661 | ucwords( |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | ) |
667 | 667 | ) |
668 | 668 | ); |
669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
669 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
670 | 670 | $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
671 | 671 | array('\\', '/'), |
672 | 672 | DS, |
@@ -690,12 +690,12 @@ discard block |
||
690 | 690 | } |
691 | 691 | //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
692 | 692 | $ee_admin_hooks = array(); |
693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
693 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
694 | 694 | if ($hooks) { |
695 | 695 | foreach ($hooks as $hook) { |
696 | 696 | if (is_readable($hook)) { |
697 | 697 | require_once $hook; |
698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
698 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
699 | 699 | $classname = str_replace('.class.php', '', $classname); |
700 | 700 | if (class_exists($classname)) { |
701 | 701 | $a = new ReflectionClass($classname); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -12,869 +12,869 @@ discard block |
||
12 | 12 | class EE_Message extends EE_Base_Class implements EEI_Admin_Links |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
17 | - * @type null |
|
18 | - */ |
|
19 | - public $template_pack; |
|
20 | - |
|
21 | - /** |
|
22 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
23 | - * @type null |
|
24 | - */ |
|
25 | - public $template_variation; |
|
26 | - |
|
27 | - /** |
|
28 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
29 | - * @type string |
|
30 | - */ |
|
31 | - public $content = ''; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @type EE_messenger $_messenger |
|
36 | - */ |
|
37 | - protected $_messenger = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_message_type $_message_type |
|
41 | - */ |
|
42 | - protected $_message_type = null; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $props_n_values |
|
47 | - * @param string $timezone |
|
48 | - * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
49 | - * format. |
|
50 | - * @return EE_Message |
|
51 | - */ |
|
52 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
53 | - { |
|
54 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
55 | - //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
56 | - if ( ! $has_object) { |
|
57 | - EE_Registry::instance()->load_helper('URL'); |
|
58 | - $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
59 | - } |
|
60 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @param array $props_n_values |
|
66 | - * @param string $timezone |
|
67 | - * @return EE_Message |
|
68 | - */ |
|
69 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
70 | - { |
|
71 | - return new self($props_n_values, true, $timezone); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Gets MSG_token |
|
77 | - * |
|
78 | - * @return int |
|
79 | - */ |
|
80 | - public function MSG_token() |
|
81 | - { |
|
82 | - return $this->get('MSG_token'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Sets MSG_token |
|
88 | - * |
|
89 | - * @param int $MSG_token |
|
90 | - */ |
|
91 | - public function set_MSG_token($MSG_token) |
|
92 | - { |
|
93 | - $this->set('MSG_token', $MSG_token); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets GRP_ID |
|
99 | - * |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function GRP_ID() |
|
103 | - { |
|
104 | - return $this->get('GRP_ID'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets GRP_ID |
|
110 | - * |
|
111 | - * @param int $GRP_ID |
|
112 | - */ |
|
113 | - public function set_GRP_ID($GRP_ID) |
|
114 | - { |
|
115 | - $this->set('GRP_ID', $GRP_ID); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Gets TXN_ID |
|
121 | - * |
|
122 | - * @return int |
|
123 | - */ |
|
124 | - public function TXN_ID() |
|
125 | - { |
|
126 | - return $this->get('TXN_ID'); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Sets TXN_ID |
|
132 | - * |
|
133 | - * @param int $TXN_ID |
|
134 | - */ |
|
135 | - public function set_TXN_ID($TXN_ID) |
|
136 | - { |
|
137 | - $this->set('TXN_ID', $TXN_ID); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Gets messenger |
|
143 | - * |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function messenger() |
|
147 | - { |
|
148 | - return $this->get('MSG_messenger'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets messenger |
|
154 | - * |
|
155 | - * @param string $messenger |
|
156 | - */ |
|
157 | - public function set_messenger($messenger) |
|
158 | - { |
|
159 | - $this->set('MSG_messenger', $messenger); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns corresponding messenger object for the set messenger on this message |
|
165 | - * |
|
166 | - * @return EE_messenger | null |
|
167 | - */ |
|
168 | - public function messenger_object() |
|
169 | - { |
|
170 | - return $this->_messenger; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets messenger |
|
176 | - * |
|
177 | - * @param EE_messenger $messenger |
|
178 | - */ |
|
179 | - public function set_messenger_object(EE_messenger $messenger) |
|
180 | - { |
|
181 | - $this->_messenger = $messenger; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * validates messenger |
|
187 | - * |
|
188 | - * @param bool $throw_exceptions |
|
189 | - * @return bool |
|
190 | - * @throws \EE_Error |
|
191 | - */ |
|
192 | - public function valid_messenger($throw_exceptions = false) |
|
193 | - { |
|
194 | - if ($this->_messenger instanceof EE_messenger) { |
|
195 | - return true; |
|
196 | - } |
|
197 | - if ($throw_exceptions) { |
|
198 | - throw new EE_Error( |
|
199 | - sprintf( |
|
200 | - __( |
|
201 | - 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - $this->messenger() |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * This returns the set localized label for the messenger on this message. |
|
214 | - * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
215 | - * with this message. |
|
216 | - * |
|
217 | - * @param bool $plural whether to return the plural label or not. |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function messenger_label($plural = false) |
|
221 | - { |
|
222 | - $label_type = $plural ? 'plural' : 'singular'; |
|
223 | - $messenger = $this->messenger_object(); |
|
224 | - return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Gets message_type |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function message_type() |
|
234 | - { |
|
235 | - return $this->get('MSG_message_type'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Sets message_type |
|
241 | - * |
|
242 | - * @param string $message_type |
|
243 | - */ |
|
244 | - public function set_message_type($message_type) |
|
245 | - { |
|
246 | - $this->set('MSG_message_type', $message_type); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns the message type object for the set message type on this message |
|
252 | - * |
|
253 | - * @return EE_message_type | null |
|
254 | - */ |
|
255 | - public function message_type_object() |
|
256 | - { |
|
257 | - return $this->_message_type; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * Sets message_type |
|
263 | - * |
|
264 | - * @param EE_message_type $message_type |
|
265 | - * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
266 | - * the message type or not. |
|
267 | - */ |
|
268 | - public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
269 | - { |
|
270 | - $this->_message_type = $message_type; |
|
271 | - if ($set_priority) { |
|
272 | - $this->set_priority($this->_message_type->get_priority()); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * validates message_type |
|
279 | - * |
|
280 | - * @param bool $throw_exceptions |
|
281 | - * @return bool |
|
282 | - * @throws \EE_Error |
|
283 | - */ |
|
284 | - public function valid_message_type($throw_exceptions = false) |
|
285 | - { |
|
286 | - if ($this->_message_type instanceof EE_message_type) { |
|
287 | - return true; |
|
288 | - } |
|
289 | - if ($throw_exceptions) { |
|
290 | - throw new EE_Error( |
|
291 | - sprintf( |
|
292 | - __( |
|
293 | - 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
294 | - 'event_espresso' |
|
295 | - ), |
|
296 | - $this->message_type() |
|
297 | - ) |
|
298 | - ); |
|
299 | - } |
|
300 | - return false; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
306 | - * |
|
307 | - * @param bool $throw_exceptions |
|
308 | - * @return bool |
|
309 | - * @throws \EE_Error |
|
310 | - */ |
|
311 | - public function is_valid($throw_exceptions = false) |
|
312 | - { |
|
313 | - if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
314 | - return true; |
|
315 | - } |
|
316 | - return false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * This validates whether the internal messenger and message type objects are valid for sending. |
|
322 | - * Three checks are done: |
|
323 | - * 1. There is a valid messenger object. |
|
324 | - * 2. There is a valid message type object. |
|
325 | - * 3. The message type object is active for the messenger. |
|
326 | - * |
|
327 | - * @throws EE_Error But only if $throw_exceptions is set to true. |
|
328 | - * @param bool $throw_exceptions |
|
329 | - * @return bool |
|
330 | - */ |
|
331 | - public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
332 | - { |
|
333 | - $valid = false; |
|
334 | - if ($this->is_valid($throw_exceptions)) { |
|
335 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
336 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
337 | - $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
338 | - $this->message_type()); |
|
339 | - if ( ! $valid && $throw_exceptions) { |
|
340 | - throw new EE_Error( |
|
341 | - sprintf( |
|
342 | - __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
343 | - 'event_espresso'), |
|
344 | - $this->message_type(), |
|
345 | - $this->messenger() |
|
346 | - ) |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
350 | - return $valid; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * This returns the set localized label for the message type on this message. |
|
356 | - * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
357 | - * with this message. |
|
358 | - * |
|
359 | - * @param bool $plural whether to return the plural label or not. |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function message_type_label($plural = false) |
|
363 | - { |
|
364 | - $label_type = $plural ? 'plural' : 'singular'; |
|
365 | - $message_type = $this->message_type_object(); |
|
366 | - return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
367 | - '_', |
|
368 | - ' ', |
|
369 | - $this->message_type() |
|
370 | - ); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Gets context |
|
376 | - * |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function context() |
|
380 | - { |
|
381 | - return $this->get('MSG_context'); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
387 | - * types. Otherwise, this will just return the set context slug on this object. |
|
388 | - * |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function context_label() |
|
392 | - { |
|
393 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
394 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
395 | - $contexts = $message_resource_manager->get_all_contexts(); |
|
396 | - return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Sets context |
|
402 | - * |
|
403 | - * @param string $context |
|
404 | - */ |
|
405 | - public function set_context($context) |
|
406 | - { |
|
407 | - $this->set('MSG_context', $context); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Gets recipient_ID |
|
413 | - * |
|
414 | - * @return int |
|
415 | - */ |
|
416 | - public function recipient_ID() |
|
417 | - { |
|
418 | - return $this->get('MSG_recipient_ID'); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Sets recipient_ID |
|
424 | - * |
|
425 | - * @param string $recipient_ID |
|
426 | - */ |
|
427 | - public function set_recipient_ID($recipient_ID) |
|
428 | - { |
|
429 | - $this->set('MSG_recipient_ID', $recipient_ID); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Gets recipient_type |
|
435 | - * |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function recipient_type() |
|
439 | - { |
|
440 | - return $this->get('MSG_recipient_type'); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Return the related object matching the recipient type and ID. |
|
446 | - * |
|
447 | - * @return EE_Base_Class | null |
|
448 | - */ |
|
449 | - public function recipient_object() |
|
450 | - { |
|
451 | - if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
452 | - return null; |
|
453 | - } |
|
454 | - |
|
455 | - return $this->get_first_related($this->recipient_type()); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Sets recipient_type |
|
461 | - * |
|
462 | - * @param string $recipient_type |
|
463 | - */ |
|
464 | - public function set_recipient_type($recipient_type) |
|
465 | - { |
|
466 | - $this->set('MSG_recipient_type', $recipient_type); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Gets content |
|
472 | - * |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - public function content() |
|
476 | - { |
|
477 | - return $this->get('MSG_content'); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Sets content |
|
483 | - * |
|
484 | - * @param string $content |
|
485 | - */ |
|
486 | - public function set_content($content) |
|
487 | - { |
|
488 | - $this->set('MSG_content', $content); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Gets subject |
|
494 | - * |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function subject() |
|
498 | - { |
|
499 | - return $this->get('MSG_subject'); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Sets subject |
|
505 | - * |
|
506 | - * @param string $subject |
|
507 | - */ |
|
508 | - public function set_subject($subject) |
|
509 | - { |
|
510 | - $this->set('MSG_subject', $subject); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Gets to |
|
516 | - * |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function to() |
|
520 | - { |
|
521 | - $to = $this->get('MSG_to'); |
|
522 | - return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * Sets to |
|
528 | - * |
|
529 | - * @param string $to |
|
530 | - */ |
|
531 | - public function set_to($to) |
|
532 | - { |
|
533 | - $this->set('MSG_to', $to); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Gets from |
|
539 | - * |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - public function from() |
|
543 | - { |
|
544 | - return $this->get('MSG_from'); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * Sets from |
|
550 | - * |
|
551 | - * @param string $from |
|
552 | - */ |
|
553 | - public function set_from($from) |
|
554 | - { |
|
555 | - $this->set('MSG_from', $from); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Gets priority |
|
561 | - * |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function priority() |
|
565 | - { |
|
566 | - return $this->get('MSG_priority'); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Sets priority |
|
572 | - * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
573 | - * this method calls the send_now method to verify that. |
|
574 | - * |
|
575 | - * @param int $priority |
|
576 | - */ |
|
577 | - public function set_priority($priority) |
|
578 | - { |
|
579 | - $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
580 | - parent::set('MSG_priority', $priority); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Overrides parent::set method so we can capture any sets for priority. |
|
586 | - * |
|
587 | - * @see parent::set() for phpdocs |
|
588 | - * @param string $field_name |
|
589 | - * @param mixed $field_value |
|
590 | - * @param bool $use_default |
|
591 | - * @throws EE_Error |
|
592 | - */ |
|
593 | - public function set($field_name, $field_value, $use_default = false) |
|
594 | - { |
|
595 | - if ($field_name === 'MSG_priority') { |
|
596 | - $this->set_priority($field_value); |
|
597 | - } |
|
598 | - parent::set($field_name, $field_value, $use_default); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @return bool |
|
604 | - * @throws \EE_Error |
|
605 | - */ |
|
606 | - public function send_now() |
|
607 | - { |
|
608 | - $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
609 | - return $send_now === EEM_Message::priority_high ? true : false; |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Gets STS_ID |
|
615 | - * |
|
616 | - * @return string |
|
617 | - */ |
|
618 | - public function STS_ID() |
|
619 | - { |
|
620 | - return $this->get('STS_ID'); |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Sets STS_ID |
|
626 | - * |
|
627 | - * @param string $STS_ID |
|
628 | - */ |
|
629 | - public function set_STS_ID($STS_ID) |
|
630 | - { |
|
631 | - $this->set('STS_ID', $STS_ID); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * Gets created |
|
637 | - * |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - public function created() |
|
641 | - { |
|
642 | - return $this->get('MSG_created'); |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Sets created |
|
648 | - * |
|
649 | - * @param string $created |
|
650 | - */ |
|
651 | - public function set_created($created) |
|
652 | - { |
|
653 | - $this->set('MSG_created', $created); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * Gets modified |
|
659 | - * |
|
660 | - * @return string |
|
661 | - */ |
|
662 | - public function modified() |
|
663 | - { |
|
664 | - return $this->get('MSG_modified'); |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * Sets modified |
|
670 | - * |
|
671 | - * @param string $modified |
|
672 | - */ |
|
673 | - public function set_modified($modified) |
|
674 | - { |
|
675 | - $this->set('MSG_modified', $modified); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Sets generation data for this message. |
|
681 | - * |
|
682 | - * @param mixed $data |
|
683 | - */ |
|
684 | - public function set_generation_data($data) |
|
685 | - { |
|
686 | - $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * Returns any set generation data for this message. |
|
692 | - * |
|
693 | - * @return mixed|null |
|
694 | - */ |
|
695 | - public function get_generation_data() |
|
696 | - { |
|
697 | - return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * Gets any error message. |
|
703 | - * |
|
704 | - * @return mixed|null |
|
705 | - */ |
|
706 | - public function error_message() |
|
707 | - { |
|
708 | - return $this->get_field_or_extra_meta('MSG_error'); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * Sets an error message. |
|
714 | - * |
|
715 | - * @param $message |
|
716 | - * @return bool|int |
|
717 | - */ |
|
718 | - public function set_error_message($message) |
|
719 | - { |
|
720 | - return $this->set_field_or_extra_meta('MSG_error', $message); |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * This retrieves the associated template pack with this message. |
|
726 | - * |
|
727 | - * @return EE_Messages_Template_Pack | null |
|
728 | - */ |
|
729 | - public function get_template_pack() |
|
730 | - { |
|
731 | - /** |
|
732 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
733 | - */ |
|
734 | - if ( ! empty($this->template_pack)) { |
|
735 | - return $this->template_pack; |
|
736 | - } |
|
737 | - /** @type EE_Message_Template_Group $grp */ |
|
738 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
739 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
740 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
741 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
742 | - array( |
|
743 | - array( |
|
744 | - 'MTP_messenger' => $this->messenger(), |
|
745 | - 'MTP_message_type' => $this->message_type(), |
|
746 | - 'MTP_is_global' => true, |
|
747 | - ), |
|
748 | - ) |
|
749 | - ); |
|
750 | - } |
|
751 | - |
|
752 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * Retrieves the variation used for generating this message. |
|
758 | - * |
|
759 | - * @return string |
|
760 | - */ |
|
761 | - public function get_template_pack_variation() |
|
762 | - { |
|
763 | - /** |
|
764 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
765 | - */ |
|
766 | - if ( ! empty($this->template_variation)) { |
|
767 | - return $this->template_variation; |
|
768 | - } |
|
769 | - |
|
770 | - /** @type EE_Message_Template_Group $grp */ |
|
771 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
772 | - |
|
773 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
774 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
775 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
776 | - array( |
|
777 | - array( |
|
778 | - 'MTP_messenger' => $this->messenger(), |
|
779 | - 'MTP_message_type' => $this->message_type(), |
|
780 | - 'MTP_is_global' => true, |
|
781 | - ), |
|
782 | - ) |
|
783 | - ); |
|
784 | - } |
|
785 | - |
|
786 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Return the link to the admin details for the object. |
|
791 | - * |
|
792 | - * @return string |
|
793 | - */ |
|
794 | - public function get_admin_details_link() |
|
795 | - { |
|
796 | - EE_Registry::instance()->load_helper('URL'); |
|
797 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
798 | - switch ($this->STS_ID()) { |
|
799 | - case EEM_Message::status_failed : |
|
800 | - case EEM_Message::status_debug_only : |
|
801 | - return EEH_MSG_Template::generate_error_display_trigger($this); |
|
802 | - break; |
|
803 | - |
|
804 | - case EEM_Message::status_sent : |
|
805 | - return EEH_MSG_Template::generate_browser_trigger($this); |
|
806 | - break; |
|
807 | - |
|
808 | - default : |
|
809 | - return ''; |
|
810 | - } |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
815 | - * |
|
816 | - * @return string |
|
817 | - */ |
|
818 | - public function get_admin_edit_link() |
|
819 | - { |
|
820 | - return $this->get_admin_details_link(); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Returns the link to a settings page for the object. |
|
825 | - * |
|
826 | - * @return string |
|
827 | - */ |
|
828 | - public function get_admin_settings_link() |
|
829 | - { |
|
830 | - EE_Registry::instance()->load_helper('URL'); |
|
831 | - return EEH_URL::add_query_args_and_nonce( |
|
832 | - array( |
|
833 | - 'page' => 'espresso_messages', |
|
834 | - 'action' => 'settings', |
|
835 | - ), |
|
836 | - admin_url('admin.php') |
|
837 | - ); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
842 | - * |
|
843 | - * @return string |
|
844 | - */ |
|
845 | - public function get_admin_overview_link() |
|
846 | - { |
|
847 | - EE_Registry::instance()->load_helper('URL'); |
|
848 | - return EEH_URL::add_query_args_and_nonce( |
|
849 | - array( |
|
850 | - 'page' => 'espresso_messages', |
|
851 | - 'action' => 'default', |
|
852 | - ), |
|
853 | - admin_url('admin.php') |
|
854 | - ); |
|
855 | - } |
|
856 | - |
|
857 | - |
|
858 | - /** |
|
859 | - * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
860 | - * it. |
|
861 | - * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
862 | - * |
|
863 | - */ |
|
864 | - public function set_messenger_is_executing() |
|
865 | - { |
|
866 | - $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
867 | - $this->set_error_message( |
|
868 | - esc_html__( |
|
869 | - 'A message with this status indicates that there was a problem that occurred while the message was being |
|
15 | + /** |
|
16 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
17 | + * @type null |
|
18 | + */ |
|
19 | + public $template_pack; |
|
20 | + |
|
21 | + /** |
|
22 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
23 | + * @type null |
|
24 | + */ |
|
25 | + public $template_variation; |
|
26 | + |
|
27 | + /** |
|
28 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
29 | + * @type string |
|
30 | + */ |
|
31 | + public $content = ''; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @type EE_messenger $_messenger |
|
36 | + */ |
|
37 | + protected $_messenger = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_message_type $_message_type |
|
41 | + */ |
|
42 | + protected $_message_type = null; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $props_n_values |
|
47 | + * @param string $timezone |
|
48 | + * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
49 | + * format. |
|
50 | + * @return EE_Message |
|
51 | + */ |
|
52 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
53 | + { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
55 | + //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
56 | + if ( ! $has_object) { |
|
57 | + EE_Registry::instance()->load_helper('URL'); |
|
58 | + $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
59 | + } |
|
60 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @param array $props_n_values |
|
66 | + * @param string $timezone |
|
67 | + * @return EE_Message |
|
68 | + */ |
|
69 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
70 | + { |
|
71 | + return new self($props_n_values, true, $timezone); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Gets MSG_token |
|
77 | + * |
|
78 | + * @return int |
|
79 | + */ |
|
80 | + public function MSG_token() |
|
81 | + { |
|
82 | + return $this->get('MSG_token'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Sets MSG_token |
|
88 | + * |
|
89 | + * @param int $MSG_token |
|
90 | + */ |
|
91 | + public function set_MSG_token($MSG_token) |
|
92 | + { |
|
93 | + $this->set('MSG_token', $MSG_token); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets GRP_ID |
|
99 | + * |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function GRP_ID() |
|
103 | + { |
|
104 | + return $this->get('GRP_ID'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets GRP_ID |
|
110 | + * |
|
111 | + * @param int $GRP_ID |
|
112 | + */ |
|
113 | + public function set_GRP_ID($GRP_ID) |
|
114 | + { |
|
115 | + $this->set('GRP_ID', $GRP_ID); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Gets TXN_ID |
|
121 | + * |
|
122 | + * @return int |
|
123 | + */ |
|
124 | + public function TXN_ID() |
|
125 | + { |
|
126 | + return $this->get('TXN_ID'); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Sets TXN_ID |
|
132 | + * |
|
133 | + * @param int $TXN_ID |
|
134 | + */ |
|
135 | + public function set_TXN_ID($TXN_ID) |
|
136 | + { |
|
137 | + $this->set('TXN_ID', $TXN_ID); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Gets messenger |
|
143 | + * |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function messenger() |
|
147 | + { |
|
148 | + return $this->get('MSG_messenger'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets messenger |
|
154 | + * |
|
155 | + * @param string $messenger |
|
156 | + */ |
|
157 | + public function set_messenger($messenger) |
|
158 | + { |
|
159 | + $this->set('MSG_messenger', $messenger); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns corresponding messenger object for the set messenger on this message |
|
165 | + * |
|
166 | + * @return EE_messenger | null |
|
167 | + */ |
|
168 | + public function messenger_object() |
|
169 | + { |
|
170 | + return $this->_messenger; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets messenger |
|
176 | + * |
|
177 | + * @param EE_messenger $messenger |
|
178 | + */ |
|
179 | + public function set_messenger_object(EE_messenger $messenger) |
|
180 | + { |
|
181 | + $this->_messenger = $messenger; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * validates messenger |
|
187 | + * |
|
188 | + * @param bool $throw_exceptions |
|
189 | + * @return bool |
|
190 | + * @throws \EE_Error |
|
191 | + */ |
|
192 | + public function valid_messenger($throw_exceptions = false) |
|
193 | + { |
|
194 | + if ($this->_messenger instanceof EE_messenger) { |
|
195 | + return true; |
|
196 | + } |
|
197 | + if ($throw_exceptions) { |
|
198 | + throw new EE_Error( |
|
199 | + sprintf( |
|
200 | + __( |
|
201 | + 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + $this->messenger() |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * This returns the set localized label for the messenger on this message. |
|
214 | + * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
215 | + * with this message. |
|
216 | + * |
|
217 | + * @param bool $plural whether to return the plural label or not. |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function messenger_label($plural = false) |
|
221 | + { |
|
222 | + $label_type = $plural ? 'plural' : 'singular'; |
|
223 | + $messenger = $this->messenger_object(); |
|
224 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Gets message_type |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function message_type() |
|
234 | + { |
|
235 | + return $this->get('MSG_message_type'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Sets message_type |
|
241 | + * |
|
242 | + * @param string $message_type |
|
243 | + */ |
|
244 | + public function set_message_type($message_type) |
|
245 | + { |
|
246 | + $this->set('MSG_message_type', $message_type); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns the message type object for the set message type on this message |
|
252 | + * |
|
253 | + * @return EE_message_type | null |
|
254 | + */ |
|
255 | + public function message_type_object() |
|
256 | + { |
|
257 | + return $this->_message_type; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * Sets message_type |
|
263 | + * |
|
264 | + * @param EE_message_type $message_type |
|
265 | + * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
266 | + * the message type or not. |
|
267 | + */ |
|
268 | + public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
269 | + { |
|
270 | + $this->_message_type = $message_type; |
|
271 | + if ($set_priority) { |
|
272 | + $this->set_priority($this->_message_type->get_priority()); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * validates message_type |
|
279 | + * |
|
280 | + * @param bool $throw_exceptions |
|
281 | + * @return bool |
|
282 | + * @throws \EE_Error |
|
283 | + */ |
|
284 | + public function valid_message_type($throw_exceptions = false) |
|
285 | + { |
|
286 | + if ($this->_message_type instanceof EE_message_type) { |
|
287 | + return true; |
|
288 | + } |
|
289 | + if ($throw_exceptions) { |
|
290 | + throw new EE_Error( |
|
291 | + sprintf( |
|
292 | + __( |
|
293 | + 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
294 | + 'event_espresso' |
|
295 | + ), |
|
296 | + $this->message_type() |
|
297 | + ) |
|
298 | + ); |
|
299 | + } |
|
300 | + return false; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
306 | + * |
|
307 | + * @param bool $throw_exceptions |
|
308 | + * @return bool |
|
309 | + * @throws \EE_Error |
|
310 | + */ |
|
311 | + public function is_valid($throw_exceptions = false) |
|
312 | + { |
|
313 | + if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
314 | + return true; |
|
315 | + } |
|
316 | + return false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * This validates whether the internal messenger and message type objects are valid for sending. |
|
322 | + * Three checks are done: |
|
323 | + * 1. There is a valid messenger object. |
|
324 | + * 2. There is a valid message type object. |
|
325 | + * 3. The message type object is active for the messenger. |
|
326 | + * |
|
327 | + * @throws EE_Error But only if $throw_exceptions is set to true. |
|
328 | + * @param bool $throw_exceptions |
|
329 | + * @return bool |
|
330 | + */ |
|
331 | + public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
332 | + { |
|
333 | + $valid = false; |
|
334 | + if ($this->is_valid($throw_exceptions)) { |
|
335 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
336 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
337 | + $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
338 | + $this->message_type()); |
|
339 | + if ( ! $valid && $throw_exceptions) { |
|
340 | + throw new EE_Error( |
|
341 | + sprintf( |
|
342 | + __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
343 | + 'event_espresso'), |
|
344 | + $this->message_type(), |
|
345 | + $this->messenger() |
|
346 | + ) |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | + return $valid; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * This returns the set localized label for the message type on this message. |
|
356 | + * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
357 | + * with this message. |
|
358 | + * |
|
359 | + * @param bool $plural whether to return the plural label or not. |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function message_type_label($plural = false) |
|
363 | + { |
|
364 | + $label_type = $plural ? 'plural' : 'singular'; |
|
365 | + $message_type = $this->message_type_object(); |
|
366 | + return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
367 | + '_', |
|
368 | + ' ', |
|
369 | + $this->message_type() |
|
370 | + ); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Gets context |
|
376 | + * |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function context() |
|
380 | + { |
|
381 | + return $this->get('MSG_context'); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
387 | + * types. Otherwise, this will just return the set context slug on this object. |
|
388 | + * |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function context_label() |
|
392 | + { |
|
393 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
394 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
395 | + $contexts = $message_resource_manager->get_all_contexts(); |
|
396 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Sets context |
|
402 | + * |
|
403 | + * @param string $context |
|
404 | + */ |
|
405 | + public function set_context($context) |
|
406 | + { |
|
407 | + $this->set('MSG_context', $context); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Gets recipient_ID |
|
413 | + * |
|
414 | + * @return int |
|
415 | + */ |
|
416 | + public function recipient_ID() |
|
417 | + { |
|
418 | + return $this->get('MSG_recipient_ID'); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Sets recipient_ID |
|
424 | + * |
|
425 | + * @param string $recipient_ID |
|
426 | + */ |
|
427 | + public function set_recipient_ID($recipient_ID) |
|
428 | + { |
|
429 | + $this->set('MSG_recipient_ID', $recipient_ID); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Gets recipient_type |
|
435 | + * |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function recipient_type() |
|
439 | + { |
|
440 | + return $this->get('MSG_recipient_type'); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Return the related object matching the recipient type and ID. |
|
446 | + * |
|
447 | + * @return EE_Base_Class | null |
|
448 | + */ |
|
449 | + public function recipient_object() |
|
450 | + { |
|
451 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
452 | + return null; |
|
453 | + } |
|
454 | + |
|
455 | + return $this->get_first_related($this->recipient_type()); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Sets recipient_type |
|
461 | + * |
|
462 | + * @param string $recipient_type |
|
463 | + */ |
|
464 | + public function set_recipient_type($recipient_type) |
|
465 | + { |
|
466 | + $this->set('MSG_recipient_type', $recipient_type); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Gets content |
|
472 | + * |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + public function content() |
|
476 | + { |
|
477 | + return $this->get('MSG_content'); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Sets content |
|
483 | + * |
|
484 | + * @param string $content |
|
485 | + */ |
|
486 | + public function set_content($content) |
|
487 | + { |
|
488 | + $this->set('MSG_content', $content); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Gets subject |
|
494 | + * |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function subject() |
|
498 | + { |
|
499 | + return $this->get('MSG_subject'); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Sets subject |
|
505 | + * |
|
506 | + * @param string $subject |
|
507 | + */ |
|
508 | + public function set_subject($subject) |
|
509 | + { |
|
510 | + $this->set('MSG_subject', $subject); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Gets to |
|
516 | + * |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function to() |
|
520 | + { |
|
521 | + $to = $this->get('MSG_to'); |
|
522 | + return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * Sets to |
|
528 | + * |
|
529 | + * @param string $to |
|
530 | + */ |
|
531 | + public function set_to($to) |
|
532 | + { |
|
533 | + $this->set('MSG_to', $to); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Gets from |
|
539 | + * |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + public function from() |
|
543 | + { |
|
544 | + return $this->get('MSG_from'); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * Sets from |
|
550 | + * |
|
551 | + * @param string $from |
|
552 | + */ |
|
553 | + public function set_from($from) |
|
554 | + { |
|
555 | + $this->set('MSG_from', $from); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Gets priority |
|
561 | + * |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function priority() |
|
565 | + { |
|
566 | + return $this->get('MSG_priority'); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Sets priority |
|
572 | + * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
573 | + * this method calls the send_now method to verify that. |
|
574 | + * |
|
575 | + * @param int $priority |
|
576 | + */ |
|
577 | + public function set_priority($priority) |
|
578 | + { |
|
579 | + $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
580 | + parent::set('MSG_priority', $priority); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Overrides parent::set method so we can capture any sets for priority. |
|
586 | + * |
|
587 | + * @see parent::set() for phpdocs |
|
588 | + * @param string $field_name |
|
589 | + * @param mixed $field_value |
|
590 | + * @param bool $use_default |
|
591 | + * @throws EE_Error |
|
592 | + */ |
|
593 | + public function set($field_name, $field_value, $use_default = false) |
|
594 | + { |
|
595 | + if ($field_name === 'MSG_priority') { |
|
596 | + $this->set_priority($field_value); |
|
597 | + } |
|
598 | + parent::set($field_name, $field_value, $use_default); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @return bool |
|
604 | + * @throws \EE_Error |
|
605 | + */ |
|
606 | + public function send_now() |
|
607 | + { |
|
608 | + $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
609 | + return $send_now === EEM_Message::priority_high ? true : false; |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Gets STS_ID |
|
615 | + * |
|
616 | + * @return string |
|
617 | + */ |
|
618 | + public function STS_ID() |
|
619 | + { |
|
620 | + return $this->get('STS_ID'); |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Sets STS_ID |
|
626 | + * |
|
627 | + * @param string $STS_ID |
|
628 | + */ |
|
629 | + public function set_STS_ID($STS_ID) |
|
630 | + { |
|
631 | + $this->set('STS_ID', $STS_ID); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * Gets created |
|
637 | + * |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + public function created() |
|
641 | + { |
|
642 | + return $this->get('MSG_created'); |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Sets created |
|
648 | + * |
|
649 | + * @param string $created |
|
650 | + */ |
|
651 | + public function set_created($created) |
|
652 | + { |
|
653 | + $this->set('MSG_created', $created); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * Gets modified |
|
659 | + * |
|
660 | + * @return string |
|
661 | + */ |
|
662 | + public function modified() |
|
663 | + { |
|
664 | + return $this->get('MSG_modified'); |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * Sets modified |
|
670 | + * |
|
671 | + * @param string $modified |
|
672 | + */ |
|
673 | + public function set_modified($modified) |
|
674 | + { |
|
675 | + $this->set('MSG_modified', $modified); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Sets generation data for this message. |
|
681 | + * |
|
682 | + * @param mixed $data |
|
683 | + */ |
|
684 | + public function set_generation_data($data) |
|
685 | + { |
|
686 | + $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * Returns any set generation data for this message. |
|
692 | + * |
|
693 | + * @return mixed|null |
|
694 | + */ |
|
695 | + public function get_generation_data() |
|
696 | + { |
|
697 | + return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * Gets any error message. |
|
703 | + * |
|
704 | + * @return mixed|null |
|
705 | + */ |
|
706 | + public function error_message() |
|
707 | + { |
|
708 | + return $this->get_field_or_extra_meta('MSG_error'); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * Sets an error message. |
|
714 | + * |
|
715 | + * @param $message |
|
716 | + * @return bool|int |
|
717 | + */ |
|
718 | + public function set_error_message($message) |
|
719 | + { |
|
720 | + return $this->set_field_or_extra_meta('MSG_error', $message); |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * This retrieves the associated template pack with this message. |
|
726 | + * |
|
727 | + * @return EE_Messages_Template_Pack | null |
|
728 | + */ |
|
729 | + public function get_template_pack() |
|
730 | + { |
|
731 | + /** |
|
732 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
733 | + */ |
|
734 | + if ( ! empty($this->template_pack)) { |
|
735 | + return $this->template_pack; |
|
736 | + } |
|
737 | + /** @type EE_Message_Template_Group $grp */ |
|
738 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
739 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
740 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
741 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
742 | + array( |
|
743 | + array( |
|
744 | + 'MTP_messenger' => $this->messenger(), |
|
745 | + 'MTP_message_type' => $this->message_type(), |
|
746 | + 'MTP_is_global' => true, |
|
747 | + ), |
|
748 | + ) |
|
749 | + ); |
|
750 | + } |
|
751 | + |
|
752 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * Retrieves the variation used for generating this message. |
|
758 | + * |
|
759 | + * @return string |
|
760 | + */ |
|
761 | + public function get_template_pack_variation() |
|
762 | + { |
|
763 | + /** |
|
764 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
765 | + */ |
|
766 | + if ( ! empty($this->template_variation)) { |
|
767 | + return $this->template_variation; |
|
768 | + } |
|
769 | + |
|
770 | + /** @type EE_Message_Template_Group $grp */ |
|
771 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
772 | + |
|
773 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
774 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
775 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
776 | + array( |
|
777 | + array( |
|
778 | + 'MTP_messenger' => $this->messenger(), |
|
779 | + 'MTP_message_type' => $this->message_type(), |
|
780 | + 'MTP_is_global' => true, |
|
781 | + ), |
|
782 | + ) |
|
783 | + ); |
|
784 | + } |
|
785 | + |
|
786 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Return the link to the admin details for the object. |
|
791 | + * |
|
792 | + * @return string |
|
793 | + */ |
|
794 | + public function get_admin_details_link() |
|
795 | + { |
|
796 | + EE_Registry::instance()->load_helper('URL'); |
|
797 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
798 | + switch ($this->STS_ID()) { |
|
799 | + case EEM_Message::status_failed : |
|
800 | + case EEM_Message::status_debug_only : |
|
801 | + return EEH_MSG_Template::generate_error_display_trigger($this); |
|
802 | + break; |
|
803 | + |
|
804 | + case EEM_Message::status_sent : |
|
805 | + return EEH_MSG_Template::generate_browser_trigger($this); |
|
806 | + break; |
|
807 | + |
|
808 | + default : |
|
809 | + return ''; |
|
810 | + } |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
815 | + * |
|
816 | + * @return string |
|
817 | + */ |
|
818 | + public function get_admin_edit_link() |
|
819 | + { |
|
820 | + return $this->get_admin_details_link(); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Returns the link to a settings page for the object. |
|
825 | + * |
|
826 | + * @return string |
|
827 | + */ |
|
828 | + public function get_admin_settings_link() |
|
829 | + { |
|
830 | + EE_Registry::instance()->load_helper('URL'); |
|
831 | + return EEH_URL::add_query_args_and_nonce( |
|
832 | + array( |
|
833 | + 'page' => 'espresso_messages', |
|
834 | + 'action' => 'settings', |
|
835 | + ), |
|
836 | + admin_url('admin.php') |
|
837 | + ); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
842 | + * |
|
843 | + * @return string |
|
844 | + */ |
|
845 | + public function get_admin_overview_link() |
|
846 | + { |
|
847 | + EE_Registry::instance()->load_helper('URL'); |
|
848 | + return EEH_URL::add_query_args_and_nonce( |
|
849 | + array( |
|
850 | + 'page' => 'espresso_messages', |
|
851 | + 'action' => 'default', |
|
852 | + ), |
|
853 | + admin_url('admin.php') |
|
854 | + ); |
|
855 | + } |
|
856 | + |
|
857 | + |
|
858 | + /** |
|
859 | + * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
860 | + * it. |
|
861 | + * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
862 | + * |
|
863 | + */ |
|
864 | + public function set_messenger_is_executing() |
|
865 | + { |
|
866 | + $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
867 | + $this->set_error_message( |
|
868 | + esc_html__( |
|
869 | + 'A message with this status indicates that there was a problem that occurred while the message was being |
|
870 | 870 | processed by the messenger. It is still possible that the message was sent successfully, but at some |
871 | 871 | point during the processing there was a failure. This usually is indicative of a timeout issue with PHP |
872 | 872 | or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory |
873 | 873 | available to PHP on your server.', |
874 | - 'event_espresso' |
|
875 | - ) |
|
876 | - ); |
|
877 | - } |
|
874 | + 'event_espresso' |
|
875 | + ) |
|
876 | + ); |
|
877 | + } |
|
878 | 878 | } |
879 | 879 | /* End of file EE_Message.class.php */ |
880 | 880 | /* Location: /core/db_classes/EE_Message.class.php */ |
881 | 881 | \ No newline at end of file |
@@ -13,72 +13,72 @@ |
||
13 | 13 | trait BaseCoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Core method for going to an Event Espresso Admin page. |
|
18 | - * @param string $page |
|
19 | - * @param string $action |
|
20 | - * @param string $additional_params |
|
21 | - */ |
|
22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | - { |
|
24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Core method for going to an Event Espresso Admin page. |
|
18 | + * @param string $page |
|
19 | + * @param string $action |
|
20 | + * @param string $additional_params |
|
21 | + */ |
|
22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | + { |
|
24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | - * @return \EventEspressoAcceptanceTester; |
|
31 | - */ |
|
32 | - protected function actor() |
|
33 | - { |
|
34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | - return $this; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | + * @return \EventEspressoAcceptanceTester; |
|
31 | + */ |
|
32 | + protected function actor() |
|
33 | + { |
|
34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Use this to set the per page option for a list table page. |
|
41 | - * Assumes you are on a page that has this field exposed. |
|
42 | - * |
|
43 | - * @param int|string $per_page_value |
|
44 | - * @throws \Codeception\Exception\TestRuntimeException |
|
45 | - */ |
|
46 | - public function setPerPageOptionForScreen($per_page_value) |
|
47 | - { |
|
48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | - $this->actor()->wait(8); |
|
52 | - } |
|
39 | + /** |
|
40 | + * Use this to set the per page option for a list table page. |
|
41 | + * Assumes you are on a page that has this field exposed. |
|
42 | + * |
|
43 | + * @param int|string $per_page_value |
|
44 | + * @throws \Codeception\Exception\TestRuntimeException |
|
45 | + */ |
|
46 | + public function setPerPageOptionForScreen($per_page_value) |
|
47 | + { |
|
48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | + $this->actor()->wait(8); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Use this to append a given value to a wpEditor instance. |
|
58 | - * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | - * the value is added to the text area. |
|
60 | - * |
|
61 | - * @param $field_reference |
|
62 | - * @param $value |
|
63 | - * @throws \Codeception\Exception\ElementNotFound |
|
64 | - */ |
|
65 | - public function appendToWPEditorField($field_reference, $value) |
|
66 | - { |
|
67 | - $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | - $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | - } |
|
56 | + /** |
|
57 | + * Use this to append a given value to a wpEditor instance. |
|
58 | + * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | + * the value is added to the text area. |
|
60 | + * |
|
61 | + * @param $field_reference |
|
62 | + * @param $value |
|
63 | + * @throws \Codeception\Exception\ElementNotFound |
|
64 | + */ |
|
65 | + public function appendToWPEditorField($field_reference, $value) |
|
66 | + { |
|
67 | + $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | + $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Use to select and submit the given bulk action. |
|
74 | - * @param string $bulk_action_option |
|
75 | - */ |
|
76 | - public function submitBulkActionOnListTable($bulk_action_option) |
|
77 | - { |
|
78 | - $this->actor()->selectOption( |
|
79 | - CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
80 | - $bulk_action_option |
|
81 | - ); |
|
82 | - $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
83 | - } |
|
72 | + /** |
|
73 | + * Use to select and submit the given bulk action. |
|
74 | + * @param string $bulk_action_option |
|
75 | + */ |
|
76 | + public function submitBulkActionOnListTable($bulk_action_option) |
|
77 | + { |
|
78 | + $this->actor()->selectOption( |
|
79 | + CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
80 | + $bulk_action_option |
|
81 | + ); |
|
82 | + $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
83 | + } |
|
84 | 84 | } |
@@ -13,30 +13,30 @@ |
||
13 | 13 | trait RegistrationsAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * This will select all checkboxes on a registration list table for the given array of |
|
18 | - * registration ids. |
|
19 | - * Assumes the actor is on a list table page for registrations. |
|
20 | - * @param $registration_ids |
|
21 | - */ |
|
22 | - public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
23 | - { |
|
24 | - foreach ($registration_ids as $registration_id) { |
|
25 | - $this->actor()->checkOption( |
|
26 | - RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
27 | - ); |
|
28 | - } |
|
29 | - } |
|
16 | + /** |
|
17 | + * This will select all checkboxes on a registration list table for the given array of |
|
18 | + * registration ids. |
|
19 | + * Assumes the actor is on a list table page for registrations. |
|
20 | + * @param $registration_ids |
|
21 | + */ |
|
22 | + public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
23 | + { |
|
24 | + foreach ($registration_ids as $registration_id) { |
|
25 | + $this->actor()->checkOption( |
|
26 | + RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
27 | + ); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Navigates the actor to the default registration list table page. |
|
34 | - * @param string $additional_params |
|
35 | - */ |
|
36 | - public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage( |
|
39 | - RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
40 | - ); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Navigates the actor to the default registration list table page. |
|
34 | + * @param string $additional_params |
|
35 | + */ |
|
36 | + public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage( |
|
39 | + RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -13,70 +13,70 @@ |
||
13 | 13 | */ |
14 | 14 | trait Checkout |
15 | 15 | { |
16 | - /** |
|
17 | - * @param $value |
|
18 | - * @param int $attendee_number |
|
19 | - */ |
|
20 | - public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | - { |
|
22 | - $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @param $value |
|
18 | + * @param int $attendee_number |
|
19 | + */ |
|
20 | + public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | + { |
|
22 | + $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param $value |
|
27 | - * @param int $attendee_number |
|
28 | - */ |
|
29 | - public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | - { |
|
31 | - $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | - } |
|
25 | + /** |
|
26 | + * @param $value |
|
27 | + * @param int $attendee_number |
|
28 | + */ |
|
29 | + public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | + { |
|
31 | + $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $value |
|
36 | - * @param int $attendee_number |
|
37 | - */ |
|
38 | - public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | - { |
|
40 | - $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param $value |
|
36 | + * @param int $attendee_number |
|
37 | + */ |
|
38 | + public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | + { |
|
40 | + $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Clicks the next registration step button. |
|
46 | - */ |
|
47 | - public function goToNextRegistrationStep() |
|
48 | - { |
|
49 | - $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | - } |
|
44 | + /** |
|
45 | + * Clicks the next registration step button. |
|
46 | + */ |
|
47 | + public function goToNextRegistrationStep() |
|
48 | + { |
|
49 | + $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Selects the payment option for the given payment method slug. |
|
55 | - * |
|
56 | - * @param string $payment_method_slug |
|
57 | - * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
58 | - * payment option select box is complete. Otherwise its up to calling code to |
|
59 | - * wait for whatever is needed after selecting the payment method. |
|
60 | - */ |
|
61 | - public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
62 | - { |
|
63 | - $this->actor()->selectOption( |
|
64 | - CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
65 | - $payment_method_slug |
|
66 | - ); |
|
67 | - if ($verify_selected) { |
|
68 | - $this->actor()->waitForText('Important information regarding your payment'); |
|
69 | - } |
|
70 | - } |
|
53 | + /** |
|
54 | + * Selects the payment option for the given payment method slug. |
|
55 | + * |
|
56 | + * @param string $payment_method_slug |
|
57 | + * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
58 | + * payment option select box is complete. Otherwise its up to calling code to |
|
59 | + * wait for whatever is needed after selecting the payment method. |
|
60 | + */ |
|
61 | + public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
62 | + { |
|
63 | + $this->actor()->selectOption( |
|
64 | + CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
65 | + $payment_method_slug |
|
66 | + ); |
|
67 | + if ($verify_selected) { |
|
68 | + $this->actor()->waitForText('Important information regarding your payment'); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * Submits the payment options step form. |
|
75 | - * Assumes the actor is in the context of the payment options SPCO step. |
|
76 | - */ |
|
77 | - public function submitPaymentOptionsRegistrationStepForm() |
|
78 | - { |
|
79 | - $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
80 | - } |
|
73 | + /** |
|
74 | + * Submits the payment options step form. |
|
75 | + * Assumes the actor is in the context of the payment options SPCO step. |
|
76 | + */ |
|
77 | + public function submitPaymentOptionsRegistrationStepForm() |
|
78 | + { |
|
79 | + $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | \ No newline at end of file |
@@ -10,288 +10,288 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | - * toggling. |
|
151 | - * |
|
152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | - * (false) |
|
155 | - */ |
|
156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | - { |
|
158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | - if ($expected_state_is_active) { |
|
160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | - } else { |
|
162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Triggers saving the message template. |
|
169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | - */ |
|
171 | - public function saveMessageTemplate($and_close = false) |
|
172 | - { |
|
173 | - if ($and_close) { |
|
174 | - $this->actor()->click('Save and Close'); |
|
175 | - } else { |
|
176 | - $this->actor()->click('Save'); |
|
177 | - } |
|
178 | - $this->actor()->waitForText('successfully updated'); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * This takes care of clicking the View Message icon for the given parameters. |
|
184 | - * Assumes you are already viewing the messages activity list table. |
|
185 | - * @param $message_type_label |
|
186 | - * @param $message_status |
|
187 | - * @param string $messenger |
|
188 | - * @param string $context |
|
189 | - * @param int $number_in_set |
|
190 | - */ |
|
191 | - public function viewMessageInMessagesListTableFor( |
|
192 | - $message_type_label, |
|
193 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
194 | - $messenger = 'Email', |
|
195 | - $context = 'Event Admin', |
|
196 | - $number_in_set = 1 |
|
197 | - ) { |
|
198 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
199 | - $message_type_label, |
|
200 | - $message_status, |
|
201 | - $messenger, |
|
202 | - $context, |
|
203 | - $number_in_set |
|
204 | - )); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
210 | - * Assumes you are already viewing the messages activity list table. |
|
211 | - * @param $message_type_label |
|
212 | - * @param $message_status |
|
213 | - * @param string $messenger |
|
214 | - * @param string $context |
|
215 | - * @param int $number_in_set |
|
216 | - */ |
|
217 | - public function deleteMessageInMessagesListTableFor( |
|
218 | - $message_type_label, |
|
219 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
220 | - $messenger = 'Email', |
|
221 | - $context = 'Event Admin', |
|
222 | - $number_in_set = 1 |
|
223 | - ) { |
|
224 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
225 | - $message_type_label, |
|
226 | - $message_status, |
|
227 | - $messenger, |
|
228 | - $context, |
|
229 | - $number_in_set |
|
230 | - ); |
|
231 | - $this->actor()->moveMouseOver( |
|
232 | - MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | - 'to', |
|
234 | - $message_type_label, |
|
235 | - $message_status, |
|
236 | - $messenger, |
|
237 | - $context, |
|
238 | - '', |
|
239 | - $number_in_set |
|
240 | - ), |
|
241 | - 5, |
|
242 | - 5 |
|
243 | - ); |
|
244 | - $this->actor()->waitForElementVisible( |
|
245 | - $delete_action_selector |
|
246 | - ); |
|
247 | - $this->actor()->click( |
|
248 | - $delete_action_selector |
|
249 | - ); |
|
250 | - $this->actor()->waitForText('successfully deleted'); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
256 | - * list table, this will take care of validating the given text is in that window. |
|
257 | - * @param string $text_to_view |
|
258 | - */ |
|
259 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
260 | - { |
|
261 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
262 | - $this->actor()->switchToIframe('message-view-window'); |
|
263 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
264 | - $this->actor()->switchToIframe(); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * This returns the value for the link at the given selector in the message modal. |
|
270 | - * @param string $selector (any selector string accepted by WebDriver) |
|
271 | - */ |
|
272 | - public function observeLinkAtInMessageModal($selector) |
|
273 | - { |
|
274 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
275 | - $this->actor()->switchToIframe('message-view-window'); |
|
276 | - return $this->actor()->observeLinkUrlAt($selector); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
282 | - * list table, this will take care of validating the given text is NOT that window. |
|
283 | - * @param string $text_to_view |
|
284 | - */ |
|
285 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
286 | - { |
|
287 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - public function dismissMessageModal() |
|
292 | - { |
|
293 | - $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
294 | - //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
295 | - $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
296 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | + * toggling. |
|
151 | + * |
|
152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | + * (false) |
|
155 | + */ |
|
156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | + { |
|
158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | + if ($expected_state_is_active) { |
|
160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | + } else { |
|
162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Triggers saving the message template. |
|
169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | + */ |
|
171 | + public function saveMessageTemplate($and_close = false) |
|
172 | + { |
|
173 | + if ($and_close) { |
|
174 | + $this->actor()->click('Save and Close'); |
|
175 | + } else { |
|
176 | + $this->actor()->click('Save'); |
|
177 | + } |
|
178 | + $this->actor()->waitForText('successfully updated'); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * This takes care of clicking the View Message icon for the given parameters. |
|
184 | + * Assumes you are already viewing the messages activity list table. |
|
185 | + * @param $message_type_label |
|
186 | + * @param $message_status |
|
187 | + * @param string $messenger |
|
188 | + * @param string $context |
|
189 | + * @param int $number_in_set |
|
190 | + */ |
|
191 | + public function viewMessageInMessagesListTableFor( |
|
192 | + $message_type_label, |
|
193 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
194 | + $messenger = 'Email', |
|
195 | + $context = 'Event Admin', |
|
196 | + $number_in_set = 1 |
|
197 | + ) { |
|
198 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
199 | + $message_type_label, |
|
200 | + $message_status, |
|
201 | + $messenger, |
|
202 | + $context, |
|
203 | + $number_in_set |
|
204 | + )); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
210 | + * Assumes you are already viewing the messages activity list table. |
|
211 | + * @param $message_type_label |
|
212 | + * @param $message_status |
|
213 | + * @param string $messenger |
|
214 | + * @param string $context |
|
215 | + * @param int $number_in_set |
|
216 | + */ |
|
217 | + public function deleteMessageInMessagesListTableFor( |
|
218 | + $message_type_label, |
|
219 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
220 | + $messenger = 'Email', |
|
221 | + $context = 'Event Admin', |
|
222 | + $number_in_set = 1 |
|
223 | + ) { |
|
224 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
225 | + $message_type_label, |
|
226 | + $message_status, |
|
227 | + $messenger, |
|
228 | + $context, |
|
229 | + $number_in_set |
|
230 | + ); |
|
231 | + $this->actor()->moveMouseOver( |
|
232 | + MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | + 'to', |
|
234 | + $message_type_label, |
|
235 | + $message_status, |
|
236 | + $messenger, |
|
237 | + $context, |
|
238 | + '', |
|
239 | + $number_in_set |
|
240 | + ), |
|
241 | + 5, |
|
242 | + 5 |
|
243 | + ); |
|
244 | + $this->actor()->waitForElementVisible( |
|
245 | + $delete_action_selector |
|
246 | + ); |
|
247 | + $this->actor()->click( |
|
248 | + $delete_action_selector |
|
249 | + ); |
|
250 | + $this->actor()->waitForText('successfully deleted'); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
256 | + * list table, this will take care of validating the given text is in that window. |
|
257 | + * @param string $text_to_view |
|
258 | + */ |
|
259 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
260 | + { |
|
261 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
262 | + $this->actor()->switchToIframe('message-view-window'); |
|
263 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
264 | + $this->actor()->switchToIframe(); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * This returns the value for the link at the given selector in the message modal. |
|
270 | + * @param string $selector (any selector string accepted by WebDriver) |
|
271 | + */ |
|
272 | + public function observeLinkAtInMessageModal($selector) |
|
273 | + { |
|
274 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
275 | + $this->actor()->switchToIframe('message-view-window'); |
|
276 | + return $this->actor()->observeLinkUrlAt($selector); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
282 | + * list table, this will take care of validating the given text is NOT that window. |
|
283 | + * @param string $text_to_view |
|
284 | + */ |
|
285 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
286 | + { |
|
287 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + public function dismissMessageModal() |
|
292 | + { |
|
293 | + $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
294 | + //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
295 | + $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
296 | + } |
|
297 | 297 | } |
@@ -13,96 +13,96 @@ |
||
13 | 13 | class CoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const URL_PREFIX = 'admin.php?page='; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * This is the selector for the next page button on list tables. |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * The selector for the search input submit button on list table pages |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Selector for the screen options dropdown. |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Selector for apply screen options settings. |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Selector for bulk action select field on list tables. |
|
59 | - */ |
|
60 | - const SELECTOR_LIST_TABLE_BULK_ACTION_FIELD = '#bulk-action-selector-'; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Selector for applying a bulk action. |
|
65 | - */ |
|
66 | - const SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY = '#doaction'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Get the EE admin url for the given properties. |
|
71 | - * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
72 | - * with `amOnAdminPage` action. |
|
73 | - * |
|
74 | - * @param string $page |
|
75 | - * @param string $action |
|
76 | - * @param string $additional_params |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
80 | - { |
|
81 | - $url = self::URL_PREFIX . $page; |
|
82 | - $url .= $action ? '&action=' . $action : ''; |
|
83 | - $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
84 | - return $url; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns the selector for the text tab switcher for a wp-editor instance. |
|
90 | - * @param $field_reference |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public static function wpEditorTextTabSelector($field_reference) |
|
94 | - { |
|
95 | - return '#content-' . $field_reference . '-content-html'; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
101 | - * @param $field_reference |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public static function wpEditorTextAreaSelector($field_reference) |
|
105 | - { |
|
106 | - return '#content-' . $field_reference . '-content'; |
|
107 | - } |
|
16 | + /** |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const URL_PREFIX = 'admin.php?page='; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * This is the selector for the next page button on list tables. |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * The selector for the search input submit button on list table pages |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Selector for the screen options dropdown. |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Selector for apply screen options settings. |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Selector for bulk action select field on list tables. |
|
59 | + */ |
|
60 | + const SELECTOR_LIST_TABLE_BULK_ACTION_FIELD = '#bulk-action-selector-'; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Selector for applying a bulk action. |
|
65 | + */ |
|
66 | + const SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY = '#doaction'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Get the EE admin url for the given properties. |
|
71 | + * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
72 | + * with `amOnAdminPage` action. |
|
73 | + * |
|
74 | + * @param string $page |
|
75 | + * @param string $action |
|
76 | + * @param string $additional_params |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
80 | + { |
|
81 | + $url = self::URL_PREFIX . $page; |
|
82 | + $url .= $action ? '&action=' . $action : ''; |
|
83 | + $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
84 | + return $url; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns the selector for the text tab switcher for a wp-editor instance. |
|
90 | + * @param $field_reference |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public static function wpEditorTextTabSelector($field_reference) |
|
94 | + { |
|
95 | + return '#content-' . $field_reference . '-content-html'; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
101 | + * @param $field_reference |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public static function wpEditorTextAreaSelector($field_reference) |
|
105 | + { |
|
106 | + return '#content-' . $field_reference . '-content'; |
|
107 | + } |
|
108 | 108 | } |