@@ -13,717 +13,717 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $caller; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
26 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
27 | - * used later to make sure we require the needed files. |
|
28 | - * |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - protected $_extend; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_name; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
44 | - * array( |
|
45 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
46 | - * ) |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $_ajax_func; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
55 | - * array( |
|
56 | - * 'page_route' => 'executing_method' //must be public |
|
57 | - * ) |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $_init_func; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
66 | - * array( |
|
67 | - * 0 => array( |
|
68 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
69 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
70 | - * will be added to each route. |
|
71 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
72 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
73 | - * method arguments. |
|
74 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
75 | - * automatically) |
|
76 | - * 'priority' => 'default', //default 'default' (optional) |
|
77 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
78 | - * 'context' => 'advanced' //advanced is default (optional), |
|
79 | - * 'callback_args' => array() //any callback args to include (optional) |
|
80 | - * ) |
|
81 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
82 | - * |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - protected $_metaboxes; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
90 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
91 | - * array: array( |
|
92 | - * 0 => array( |
|
93 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
94 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
95 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
96 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
97 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
98 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
99 | - * id for the screen the metabox is on. |
|
100 | - * ) |
|
101 | - * ) |
|
102 | - * |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - protected $_remove_metaboxes; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
110 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
111 | - * second array index is for indicating what routes each script/style loads on. array( |
|
112 | - * 'registers' => array( |
|
113 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
114 | - * argument to link scripts together. |
|
115 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
116 | - * 'url' => 'http://urltoscript.css.js', |
|
117 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
118 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
119 | - * gets loaded before the one you are setting here. |
|
120 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
121 | - * ), |
|
122 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
123 | - * the script gets enqueued on. |
|
124 | - * 'script_ref' => array('route_one', 'route_two') |
|
125 | - * ), |
|
126 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
127 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
128 | - * the object. |
|
129 | - * 'scrip_ref' => array( |
|
130 | - * 'NAME_OF_JS_OBJECT' => array( |
|
131 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
132 | - * 'some_data' => 5 |
|
133 | - * ) |
|
134 | - * ) |
|
135 | - * ) |
|
136 | - * ) |
|
137 | - * |
|
138 | - * @var array |
|
139 | - */ |
|
140 | - protected $_scripts_styles; |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * This is a property that will contain the current route. |
|
145 | - * |
|
146 | - * @var string; |
|
147 | - */ |
|
148 | - protected $_current_route; |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
153 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
154 | - * 'wp_hook_reference' => 1 |
|
155 | - * ) |
|
156 | - * ) |
|
157 | - * |
|
158 | - * @var array |
|
159 | - */ |
|
160 | - protected $_wp_action_filters_priority; |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
165 | - * |
|
166 | - * @var array |
|
167 | - */ |
|
168 | - protected $_req_data; |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * This just holds an instance of the page object for this hook |
|
173 | - * |
|
174 | - * @var EE_Admin_Page |
|
175 | - */ |
|
176 | - protected $_page_object; |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
181 | - * |
|
182 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
183 | - */ |
|
184 | - protected $_adminpage_obj; |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Holds EE_Registry object |
|
189 | - * |
|
190 | - * @var EE_Registry |
|
191 | - */ |
|
192 | - protected $EE = null; |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * constructor |
|
197 | - * |
|
198 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
199 | - */ |
|
200 | - public function __construct(EE_Admin_Page $adminpage) |
|
201 | - { |
|
202 | - $this->_adminpage_obj = $adminpage; |
|
203 | - $this->_req_data = array_merge($_GET, $_POST); |
|
204 | - $this->_set_defaults(); |
|
205 | - $this->_set_hooks_properties(); |
|
206 | - // first let's verify we're on the right page |
|
207 | - if (! isset($this->_req_data['page']) |
|
208 | - || (isset($this->_req_data['page']) |
|
209 | - && $this->_adminpage_obj->page_slug |
|
210 | - != $this->_req_data['page'])) { |
|
211 | - return; |
|
212 | - } //get out nothing more to be done here. |
|
213 | - // allow for extends to modify properties |
|
214 | - if (method_exists($this, '_extend_properties')) { |
|
215 | - $this->_extend_properties(); |
|
216 | - } |
|
217 | - $this->_set_page_object(); |
|
218 | - $this->_init_hooks(); |
|
219 | - $this->_load_custom_methods(); |
|
220 | - $this->_load_routed_hooks(); |
|
221 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
222 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
223 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
224 | - $this->_ajax_hooks(); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * used by child classes to set the following properties: |
|
230 | - * $_ajax_func (optional) |
|
231 | - * $_init_func (optional) |
|
232 | - * $_metaboxes (optional) |
|
233 | - * $_scripts (optional) |
|
234 | - * $_styles (optional) |
|
235 | - * $_name (required) |
|
236 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
237 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
238 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
239 | - * |
|
240 | - * @access protected |
|
241 | - * @abstract |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - abstract protected function _set_hooks_properties(); |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
249 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
250 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
251 | - * |
|
252 | - * @access public |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - public function enqueue_scripts_styles() |
|
256 | - { |
|
257 | - if (! empty($this->_scripts_styles)) { |
|
258 | - // first let's do all the registrations |
|
259 | - if (! isset($this->_scripts_styles['registers'])) { |
|
260 | - $msg[] = __( |
|
261 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
262 | - 'event_espresso' |
|
263 | - ); |
|
264 | - $msg[] = sprintf( |
|
265 | - __( |
|
266 | - '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', |
|
267 | - 'event_espresso' |
|
268 | - ), |
|
269 | - '<strong>' . $this->caller . '</strong>' |
|
270 | - ); |
|
271 | - throw new EE_Error(implode('||', $msg)); |
|
272 | - } |
|
273 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
274 | - $defaults = array( |
|
275 | - 'type' => 'js', |
|
276 | - 'url' => '', |
|
277 | - 'depends' => array(), |
|
278 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
279 | - 'footer' => true, |
|
280 | - ); |
|
281 | - $details = wp_parse_args($details, $defaults); |
|
282 | - extract($details); |
|
283 | - // 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 |
|
284 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
285 | - // let's make sure we're not missing any REQUIRED parameters |
|
286 | - if (empty($url)) { |
|
287 | - $msg[] = sprintf( |
|
288 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
289 | - $type == 'js' ? 'script' : 'stylesheet' |
|
290 | - ); |
|
291 | - $msg[] = sprintf( |
|
292 | - __( |
|
293 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
294 | - 'event_espresso' |
|
295 | - ), |
|
296 | - '<strong>' . $this->caller . '</strong>', |
|
297 | - $ref |
|
298 | - ); |
|
299 | - throw new EE_Error(implode('||', $msg)); |
|
300 | - } |
|
301 | - // made it here so let's do the appropriate registration |
|
302 | - $type == 'js' |
|
303 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
304 | - : wp_register_style( |
|
305 | - $ref, |
|
306 | - $url, |
|
307 | - $depends, |
|
308 | - $version |
|
309 | - ); |
|
310 | - } |
|
311 | - // k now lets do the enqueues |
|
312 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
313 | - return; |
|
314 | - } //not sure if we should throw an error here or not. |
|
315 | - |
|
316 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
317 | - // make sure $routes is an array |
|
318 | - $routes = (array) $routes; |
|
319 | - if (in_array($this->_current_route, $routes)) { |
|
320 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
321 | - : wp_enqueue_style($ref); |
|
322 | - // if we have a localization for the script let's do that too. |
|
323 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
324 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
325 | - wp_localize_script( |
|
326 | - $ref, |
|
327 | - $object_name, |
|
328 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
329 | - ); |
|
330 | - } |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
334 | - // let's do the deregisters |
|
335 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
336 | - return; |
|
337 | - } |
|
338 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
339 | - $defaults = array( |
|
340 | - 'type' => 'js', |
|
341 | - ); |
|
342 | - $details = wp_parse_args($details, $defaults); |
|
343 | - extract($details); |
|
344 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * just set the defaults for the hooks properties. |
|
352 | - * |
|
353 | - * @access private |
|
354 | - * @return void |
|
355 | - */ |
|
356 | - private function _set_defaults() |
|
357 | - { |
|
358 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
359 | - $this->_current_route = $this->getCurrentRoute(); |
|
360 | - $this->caller = get_class($this); |
|
361 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * A helper for determining the current route. |
|
367 | - * @return string |
|
368 | - */ |
|
369 | - private function getCurrentRoute() |
|
370 | - { |
|
371 | - // list tables do something else with 'action' for bulk actions. |
|
372 | - $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default'; |
|
373 | - // we set a 'route' variable in some cases where action is being used by something else. |
|
374 | - $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action; |
|
375 | - return sanitize_key($action); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * this sets the _page_object property |
|
381 | - * |
|
382 | - * @access protected |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - protected function _set_page_object() |
|
386 | - { |
|
387 | - // first make sure $this->_name is set |
|
388 | - if (empty($this->_name)) { |
|
389 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
390 | - $msg[] = sprintf( |
|
391 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
392 | - $this->caller |
|
393 | - ); |
|
394 | - throw new EE_Error(implode('||', $msg)); |
|
395 | - } |
|
396 | - $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
397 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
398 | - // first default file (if exists) |
|
399 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
400 | - if (is_readable($decaf_file)) { |
|
401 | - require_once($decaf_file); |
|
402 | - } |
|
403 | - // now we have to do require for extended file (if needed) |
|
404 | - if ($this->_extend) { |
|
405 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
406 | - } |
|
407 | - // if we've got an extended class we use that! |
|
408 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
409 | - // let's make sure the class exists |
|
410 | - if (! class_exists($ref)) { |
|
411 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
412 | - $msg[] = sprintf( |
|
413 | - __( |
|
414 | - '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', |
|
415 | - 'event_espresso' |
|
416 | - ), |
|
417 | - $ref |
|
418 | - ); |
|
419 | - throw new EE_Error(implode('||', $msg)); |
|
420 | - } |
|
421 | - $a = new ReflectionClass($ref); |
|
422 | - $this->_page_object = $a->newInstance(false); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
428 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
429 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
430 | - * |
|
431 | - * @access private |
|
432 | - * @return void |
|
433 | - */ |
|
434 | - private function _load_custom_methods() |
|
435 | - { |
|
436 | - /** |
|
437 | - * method cannot be named 'default' (@see http://us3.php |
|
438 | - * .net/manual/en/reserved.keywords.php) so need to |
|
439 | - * handle routes that are "default" |
|
440 | - * |
|
441 | - * @since 4.3.0 |
|
442 | - */ |
|
443 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
444 | - // these run before the Admin_Page route executes. |
|
445 | - if (method_exists($this, $method_callback)) { |
|
446 | - call_user_func(array($this, $method_callback)); |
|
447 | - } |
|
448 | - // 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. |
|
449 | - // first the actions |
|
450 | - // note that these action hooks will have the $query_args value available. |
|
451 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
452 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
453 | - add_action( |
|
454 | - 'AHEE__' |
|
455 | - . $admin_class_name |
|
456 | - . '___redirect_after_action__before_redirect_modification_' |
|
457 | - . $this->_current_route, |
|
458 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
459 | - 10 |
|
460 | - ); |
|
461 | - } |
|
462 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
463 | - add_action( |
|
464 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
465 | - array($this, '_redirect_action_' . $this->_current_route), |
|
466 | - 10 |
|
467 | - ); |
|
468 | - } |
|
469 | - // 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. |
|
470 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
471 | - add_filter( |
|
472 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
473 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
474 | - 10, |
|
475 | - 2 |
|
476 | - ); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
483 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
484 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
485 | - * |
|
486 | - * @return void |
|
487 | - */ |
|
488 | - private function _load_routed_hooks() |
|
489 | - { |
|
490 | - |
|
491 | - // 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. |
|
492 | - $hook_filter_array = array( |
|
493 | - 'admin_footer' => array( |
|
494 | - 'type' => 'action', |
|
495 | - 'argnum' => 1, |
|
496 | - 'priority' => 10, |
|
497 | - ), |
|
498 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
499 | - 'type' => 'filter', |
|
500 | - 'argnum' => 1, |
|
501 | - 'priority' => 10, |
|
502 | - ), |
|
503 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
504 | - 'type' => 'filter', |
|
505 | - 'argnum' => 1, |
|
506 | - 'priority' => 10, |
|
507 | - ), |
|
508 | - 'FHEE_list_table_views' => array( |
|
509 | - 'type' => 'filter', |
|
510 | - 'argnum' => 1, |
|
511 | - 'priority' => 10, |
|
512 | - ), |
|
513 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
514 | - 'type' => 'action', |
|
515 | - 'argnum' => 1, |
|
516 | - 'priority' => 10, |
|
517 | - ), |
|
518 | - ); |
|
519 | - foreach ($hook_filter_array as $hook => $args) { |
|
520 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
521 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
522 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
523 | - } |
|
524 | - if ($args['type'] == 'action') { |
|
525 | - add_action( |
|
526 | - $hook, |
|
527 | - array($this, $this->_current_route . '_' . $hook), |
|
528 | - $args['priority'], |
|
529 | - $args['argnum'] |
|
530 | - ); |
|
531 | - } else { |
|
532 | - add_filter( |
|
533 | - $hook, |
|
534 | - array($this, $this->_current_route . '_' . $hook), |
|
535 | - $args['priority'], |
|
536 | - $args['argnum'] |
|
537 | - ); |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
546 | - * |
|
547 | - * @return void |
|
548 | - */ |
|
549 | - private function _ajax_hooks() |
|
550 | - { |
|
551 | - if (empty($this->_ajax_func)) { |
|
552 | - return; |
|
553 | - } //get out there's nothing to take care of. |
|
554 | - foreach ($this->_ajax_func as $action => $method) { |
|
555 | - // make sure method exists |
|
556 | - if (! method_exists($this, $method)) { |
|
557 | - $msg[] = __( |
|
558 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
559 | - 'event_espresso' |
|
560 | - ) . '<br />'; |
|
561 | - $msg[] = sprintf( |
|
562 | - __( |
|
563 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
564 | - 'event_espresso' |
|
565 | - ), |
|
566 | - $method, |
|
567 | - $this->caller |
|
568 | - ); |
|
569 | - throw new EE_Error(implode('||', $msg)); |
|
570 | - } |
|
571 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
572 | - } |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * Loop throught the $_init_func array and add_actions for the array. |
|
578 | - * |
|
579 | - * @return void |
|
580 | - */ |
|
581 | - protected function _init_hooks() |
|
582 | - { |
|
583 | - if (empty($this->_init_func)) { |
|
584 | - return; |
|
585 | - } //get out there's nothing to take care of. |
|
586 | - // We need to determine what page_route we are on! |
|
587 | - $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
588 | - foreach ($this->_init_func as $route => $method) { |
|
589 | - // make sure method exists |
|
590 | - if (! method_exists($this, $method)) { |
|
591 | - $msg[] = __( |
|
592 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
593 | - 'event_espresso' |
|
594 | - ) . '<br />'; |
|
595 | - $msg[] = sprintf( |
|
596 | - __( |
|
597 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
598 | - 'event_espresso' |
|
599 | - ), |
|
600 | - $method, |
|
601 | - $this->caller |
|
602 | - ); |
|
603 | - throw new EE_Error(implode('||', $msg)); |
|
604 | - } |
|
605 | - if ($route == $this->_current_route) { |
|
606 | - add_action('admin_init', array($this, $method)); |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
614 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
615 | - * |
|
616 | - * @access public |
|
617 | - * @return void |
|
618 | - */ |
|
619 | - public function add_metaboxes() |
|
620 | - { |
|
621 | - if (empty($this->_metaboxes)) { |
|
622 | - return; |
|
623 | - } //get out we don't have any metaboxes to set for this connection |
|
624 | - $this->_handle_metabox_array($this->_metaboxes); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - private function _handle_metabox_array($boxes, $add = true) |
|
629 | - { |
|
630 | - foreach ($boxes as $box) { |
|
631 | - if (! isset($box['page_route'])) { |
|
632 | - continue; |
|
633 | - } //we dont' have a valid array |
|
634 | - // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
635 | - $box['page_route'] = (array) $box['page_route']; |
|
636 | - foreach ($box['page_route'] as $route) { |
|
637 | - if ($route != $this->_current_route) { |
|
638 | - continue; |
|
639 | - } //get out we only add metaboxes for set route. |
|
640 | - if ($add) { |
|
641 | - $this->_add_metabox($box); |
|
642 | - } else { |
|
643 | - $this->_remove_metabox($box); |
|
644 | - } |
|
645 | - } |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
652 | - * |
|
653 | - * @access public |
|
654 | - * @return void |
|
655 | - */ |
|
656 | - public function remove_metaboxes() |
|
657 | - { |
|
658 | - if (empty($this->_remove_metaboxes)) { |
|
659 | - return; |
|
660 | - } //get out there are no metaboxes to remove |
|
661 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * This just handles adding a metabox |
|
667 | - * |
|
668 | - * @access private |
|
669 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
670 | - */ |
|
671 | - private function _add_metabox($args) |
|
672 | - { |
|
673 | - $current_screen = get_current_screen(); |
|
674 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
675 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
676 | - // set defaults |
|
677 | - $defaults = array( |
|
678 | - 'func' => $func, |
|
679 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
680 | - 'priority' => 'default', |
|
681 | - 'label' => $this->caller, |
|
682 | - 'context' => 'advanced', |
|
683 | - 'callback_args' => array(), |
|
684 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
685 | - ); |
|
686 | - $args = wp_parse_args($args, $defaults); |
|
687 | - extract($args); |
|
688 | - // make sure method exists |
|
689 | - if (! method_exists($this, $func)) { |
|
690 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
691 | - $msg[] = sprintf( |
|
692 | - __( |
|
693 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
694 | - 'event_espresso' |
|
695 | - ), |
|
696 | - $func, |
|
697 | - $this->caller |
|
698 | - ); |
|
699 | - throw new EE_Error(implode('||', $msg)); |
|
700 | - } |
|
701 | - // everything checks out so lets add the metabox |
|
702 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - private function _remove_metabox($args) |
|
707 | - { |
|
708 | - $current_screen = get_current_screen(); |
|
709 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
710 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
711 | - // set defaults |
|
712 | - $defaults = array( |
|
713 | - 'id' => isset($args['id']) |
|
714 | - ? $args['id'] |
|
715 | - : $this->_current_route |
|
716 | - . '_' |
|
717 | - . $this->caller |
|
718 | - . '_' |
|
719 | - . $func |
|
720 | - . '_metabox', |
|
721 | - 'context' => 'default', |
|
722 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
723 | - ); |
|
724 | - $args = wp_parse_args($args, $defaults); |
|
725 | - extract($args); |
|
726 | - // everything checks out so lets remove the box! |
|
727 | - remove_meta_box($id, $screen, $context); |
|
728 | - } |
|
16 | + /** |
|
17 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $caller; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
26 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
27 | + * used later to make sure we require the needed files. |
|
28 | + * |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + protected $_extend; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_name; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
44 | + * array( |
|
45 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
46 | + * ) |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $_ajax_func; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
55 | + * array( |
|
56 | + * 'page_route' => 'executing_method' //must be public |
|
57 | + * ) |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $_init_func; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
66 | + * array( |
|
67 | + * 0 => array( |
|
68 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
69 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
70 | + * will be added to each route. |
|
71 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
72 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
73 | + * method arguments. |
|
74 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
75 | + * automatically) |
|
76 | + * 'priority' => 'default', //default 'default' (optional) |
|
77 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
78 | + * 'context' => 'advanced' //advanced is default (optional), |
|
79 | + * 'callback_args' => array() //any callback args to include (optional) |
|
80 | + * ) |
|
81 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
82 | + * |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + protected $_metaboxes; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
90 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
91 | + * array: array( |
|
92 | + * 0 => array( |
|
93 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
94 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
95 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
96 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
97 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
98 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
99 | + * id for the screen the metabox is on. |
|
100 | + * ) |
|
101 | + * ) |
|
102 | + * |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + protected $_remove_metaboxes; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
110 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
111 | + * second array index is for indicating what routes each script/style loads on. array( |
|
112 | + * 'registers' => array( |
|
113 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
114 | + * argument to link scripts together. |
|
115 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
116 | + * 'url' => 'http://urltoscript.css.js', |
|
117 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
118 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
119 | + * gets loaded before the one you are setting here. |
|
120 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
121 | + * ), |
|
122 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
123 | + * the script gets enqueued on. |
|
124 | + * 'script_ref' => array('route_one', 'route_two') |
|
125 | + * ), |
|
126 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
127 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
128 | + * the object. |
|
129 | + * 'scrip_ref' => array( |
|
130 | + * 'NAME_OF_JS_OBJECT' => array( |
|
131 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
132 | + * 'some_data' => 5 |
|
133 | + * ) |
|
134 | + * ) |
|
135 | + * ) |
|
136 | + * ) |
|
137 | + * |
|
138 | + * @var array |
|
139 | + */ |
|
140 | + protected $_scripts_styles; |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * This is a property that will contain the current route. |
|
145 | + * |
|
146 | + * @var string; |
|
147 | + */ |
|
148 | + protected $_current_route; |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
153 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
154 | + * 'wp_hook_reference' => 1 |
|
155 | + * ) |
|
156 | + * ) |
|
157 | + * |
|
158 | + * @var array |
|
159 | + */ |
|
160 | + protected $_wp_action_filters_priority; |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
165 | + * |
|
166 | + * @var array |
|
167 | + */ |
|
168 | + protected $_req_data; |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * This just holds an instance of the page object for this hook |
|
173 | + * |
|
174 | + * @var EE_Admin_Page |
|
175 | + */ |
|
176 | + protected $_page_object; |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
181 | + * |
|
182 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
183 | + */ |
|
184 | + protected $_adminpage_obj; |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Holds EE_Registry object |
|
189 | + * |
|
190 | + * @var EE_Registry |
|
191 | + */ |
|
192 | + protected $EE = null; |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * constructor |
|
197 | + * |
|
198 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
199 | + */ |
|
200 | + public function __construct(EE_Admin_Page $adminpage) |
|
201 | + { |
|
202 | + $this->_adminpage_obj = $adminpage; |
|
203 | + $this->_req_data = array_merge($_GET, $_POST); |
|
204 | + $this->_set_defaults(); |
|
205 | + $this->_set_hooks_properties(); |
|
206 | + // first let's verify we're on the right page |
|
207 | + if (! isset($this->_req_data['page']) |
|
208 | + || (isset($this->_req_data['page']) |
|
209 | + && $this->_adminpage_obj->page_slug |
|
210 | + != $this->_req_data['page'])) { |
|
211 | + return; |
|
212 | + } //get out nothing more to be done here. |
|
213 | + // allow for extends to modify properties |
|
214 | + if (method_exists($this, '_extend_properties')) { |
|
215 | + $this->_extend_properties(); |
|
216 | + } |
|
217 | + $this->_set_page_object(); |
|
218 | + $this->_init_hooks(); |
|
219 | + $this->_load_custom_methods(); |
|
220 | + $this->_load_routed_hooks(); |
|
221 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
222 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
223 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
224 | + $this->_ajax_hooks(); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * used by child classes to set the following properties: |
|
230 | + * $_ajax_func (optional) |
|
231 | + * $_init_func (optional) |
|
232 | + * $_metaboxes (optional) |
|
233 | + * $_scripts (optional) |
|
234 | + * $_styles (optional) |
|
235 | + * $_name (required) |
|
236 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
237 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
238 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
239 | + * |
|
240 | + * @access protected |
|
241 | + * @abstract |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + abstract protected function _set_hooks_properties(); |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
249 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
250 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
251 | + * |
|
252 | + * @access public |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + public function enqueue_scripts_styles() |
|
256 | + { |
|
257 | + if (! empty($this->_scripts_styles)) { |
|
258 | + // first let's do all the registrations |
|
259 | + if (! isset($this->_scripts_styles['registers'])) { |
|
260 | + $msg[] = __( |
|
261 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
262 | + 'event_espresso' |
|
263 | + ); |
|
264 | + $msg[] = sprintf( |
|
265 | + __( |
|
266 | + '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', |
|
267 | + 'event_espresso' |
|
268 | + ), |
|
269 | + '<strong>' . $this->caller . '</strong>' |
|
270 | + ); |
|
271 | + throw new EE_Error(implode('||', $msg)); |
|
272 | + } |
|
273 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
274 | + $defaults = array( |
|
275 | + 'type' => 'js', |
|
276 | + 'url' => '', |
|
277 | + 'depends' => array(), |
|
278 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
279 | + 'footer' => true, |
|
280 | + ); |
|
281 | + $details = wp_parse_args($details, $defaults); |
|
282 | + extract($details); |
|
283 | + // 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 |
|
284 | + $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
285 | + // let's make sure we're not missing any REQUIRED parameters |
|
286 | + if (empty($url)) { |
|
287 | + $msg[] = sprintf( |
|
288 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
289 | + $type == 'js' ? 'script' : 'stylesheet' |
|
290 | + ); |
|
291 | + $msg[] = sprintf( |
|
292 | + __( |
|
293 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
294 | + 'event_espresso' |
|
295 | + ), |
|
296 | + '<strong>' . $this->caller . '</strong>', |
|
297 | + $ref |
|
298 | + ); |
|
299 | + throw new EE_Error(implode('||', $msg)); |
|
300 | + } |
|
301 | + // made it here so let's do the appropriate registration |
|
302 | + $type == 'js' |
|
303 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
304 | + : wp_register_style( |
|
305 | + $ref, |
|
306 | + $url, |
|
307 | + $depends, |
|
308 | + $version |
|
309 | + ); |
|
310 | + } |
|
311 | + // k now lets do the enqueues |
|
312 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
313 | + return; |
|
314 | + } //not sure if we should throw an error here or not. |
|
315 | + |
|
316 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
317 | + // make sure $routes is an array |
|
318 | + $routes = (array) $routes; |
|
319 | + if (in_array($this->_current_route, $routes)) { |
|
320 | + $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
321 | + : wp_enqueue_style($ref); |
|
322 | + // if we have a localization for the script let's do that too. |
|
323 | + if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
324 | + foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
325 | + wp_localize_script( |
|
326 | + $ref, |
|
327 | + $object_name, |
|
328 | + $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
329 | + ); |
|
330 | + } |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | + // let's do the deregisters |
|
335 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
336 | + return; |
|
337 | + } |
|
338 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
339 | + $defaults = array( |
|
340 | + 'type' => 'js', |
|
341 | + ); |
|
342 | + $details = wp_parse_args($details, $defaults); |
|
343 | + extract($details); |
|
344 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * just set the defaults for the hooks properties. |
|
352 | + * |
|
353 | + * @access private |
|
354 | + * @return void |
|
355 | + */ |
|
356 | + private function _set_defaults() |
|
357 | + { |
|
358 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
359 | + $this->_current_route = $this->getCurrentRoute(); |
|
360 | + $this->caller = get_class($this); |
|
361 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * A helper for determining the current route. |
|
367 | + * @return string |
|
368 | + */ |
|
369 | + private function getCurrentRoute() |
|
370 | + { |
|
371 | + // list tables do something else with 'action' for bulk actions. |
|
372 | + $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default'; |
|
373 | + // we set a 'route' variable in some cases where action is being used by something else. |
|
374 | + $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action; |
|
375 | + return sanitize_key($action); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * this sets the _page_object property |
|
381 | + * |
|
382 | + * @access protected |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + protected function _set_page_object() |
|
386 | + { |
|
387 | + // first make sure $this->_name is set |
|
388 | + if (empty($this->_name)) { |
|
389 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
390 | + $msg[] = sprintf( |
|
391 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
392 | + $this->caller |
|
393 | + ); |
|
394 | + throw new EE_Error(implode('||', $msg)); |
|
395 | + } |
|
396 | + $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
397 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
398 | + // first default file (if exists) |
|
399 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
400 | + if (is_readable($decaf_file)) { |
|
401 | + require_once($decaf_file); |
|
402 | + } |
|
403 | + // now we have to do require for extended file (if needed) |
|
404 | + if ($this->_extend) { |
|
405 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
406 | + } |
|
407 | + // if we've got an extended class we use that! |
|
408 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
409 | + // let's make sure the class exists |
|
410 | + if (! class_exists($ref)) { |
|
411 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
412 | + $msg[] = sprintf( |
|
413 | + __( |
|
414 | + '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', |
|
415 | + 'event_espresso' |
|
416 | + ), |
|
417 | + $ref |
|
418 | + ); |
|
419 | + throw new EE_Error(implode('||', $msg)); |
|
420 | + } |
|
421 | + $a = new ReflectionClass($ref); |
|
422 | + $this->_page_object = $a->newInstance(false); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
428 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
429 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
430 | + * |
|
431 | + * @access private |
|
432 | + * @return void |
|
433 | + */ |
|
434 | + private function _load_custom_methods() |
|
435 | + { |
|
436 | + /** |
|
437 | + * method cannot be named 'default' (@see http://us3.php |
|
438 | + * .net/manual/en/reserved.keywords.php) so need to |
|
439 | + * handle routes that are "default" |
|
440 | + * |
|
441 | + * @since 4.3.0 |
|
442 | + */ |
|
443 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
444 | + // these run before the Admin_Page route executes. |
|
445 | + if (method_exists($this, $method_callback)) { |
|
446 | + call_user_func(array($this, $method_callback)); |
|
447 | + } |
|
448 | + // 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. |
|
449 | + // first the actions |
|
450 | + // note that these action hooks will have the $query_args value available. |
|
451 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
452 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
453 | + add_action( |
|
454 | + 'AHEE__' |
|
455 | + . $admin_class_name |
|
456 | + . '___redirect_after_action__before_redirect_modification_' |
|
457 | + . $this->_current_route, |
|
458 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
459 | + 10 |
|
460 | + ); |
|
461 | + } |
|
462 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
463 | + add_action( |
|
464 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
465 | + array($this, '_redirect_action_' . $this->_current_route), |
|
466 | + 10 |
|
467 | + ); |
|
468 | + } |
|
469 | + // 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. |
|
470 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
471 | + add_filter( |
|
472 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
473 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
474 | + 10, |
|
475 | + 2 |
|
476 | + ); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
483 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
484 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
485 | + * |
|
486 | + * @return void |
|
487 | + */ |
|
488 | + private function _load_routed_hooks() |
|
489 | + { |
|
490 | + |
|
491 | + // 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. |
|
492 | + $hook_filter_array = array( |
|
493 | + 'admin_footer' => array( |
|
494 | + 'type' => 'action', |
|
495 | + 'argnum' => 1, |
|
496 | + 'priority' => 10, |
|
497 | + ), |
|
498 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
499 | + 'type' => 'filter', |
|
500 | + 'argnum' => 1, |
|
501 | + 'priority' => 10, |
|
502 | + ), |
|
503 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
504 | + 'type' => 'filter', |
|
505 | + 'argnum' => 1, |
|
506 | + 'priority' => 10, |
|
507 | + ), |
|
508 | + 'FHEE_list_table_views' => array( |
|
509 | + 'type' => 'filter', |
|
510 | + 'argnum' => 1, |
|
511 | + 'priority' => 10, |
|
512 | + ), |
|
513 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
514 | + 'type' => 'action', |
|
515 | + 'argnum' => 1, |
|
516 | + 'priority' => 10, |
|
517 | + ), |
|
518 | + ); |
|
519 | + foreach ($hook_filter_array as $hook => $args) { |
|
520 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
521 | + if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
522 | + $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
523 | + } |
|
524 | + if ($args['type'] == 'action') { |
|
525 | + add_action( |
|
526 | + $hook, |
|
527 | + array($this, $this->_current_route . '_' . $hook), |
|
528 | + $args['priority'], |
|
529 | + $args['argnum'] |
|
530 | + ); |
|
531 | + } else { |
|
532 | + add_filter( |
|
533 | + $hook, |
|
534 | + array($this, $this->_current_route . '_' . $hook), |
|
535 | + $args['priority'], |
|
536 | + $args['argnum'] |
|
537 | + ); |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
546 | + * |
|
547 | + * @return void |
|
548 | + */ |
|
549 | + private function _ajax_hooks() |
|
550 | + { |
|
551 | + if (empty($this->_ajax_func)) { |
|
552 | + return; |
|
553 | + } //get out there's nothing to take care of. |
|
554 | + foreach ($this->_ajax_func as $action => $method) { |
|
555 | + // make sure method exists |
|
556 | + if (! method_exists($this, $method)) { |
|
557 | + $msg[] = __( |
|
558 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
559 | + 'event_espresso' |
|
560 | + ) . '<br />'; |
|
561 | + $msg[] = sprintf( |
|
562 | + __( |
|
563 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
564 | + 'event_espresso' |
|
565 | + ), |
|
566 | + $method, |
|
567 | + $this->caller |
|
568 | + ); |
|
569 | + throw new EE_Error(implode('||', $msg)); |
|
570 | + } |
|
571 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
572 | + } |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * Loop throught the $_init_func array and add_actions for the array. |
|
578 | + * |
|
579 | + * @return void |
|
580 | + */ |
|
581 | + protected function _init_hooks() |
|
582 | + { |
|
583 | + if (empty($this->_init_func)) { |
|
584 | + return; |
|
585 | + } //get out there's nothing to take care of. |
|
586 | + // We need to determine what page_route we are on! |
|
587 | + $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
588 | + foreach ($this->_init_func as $route => $method) { |
|
589 | + // make sure method exists |
|
590 | + if (! method_exists($this, $method)) { |
|
591 | + $msg[] = __( |
|
592 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
593 | + 'event_espresso' |
|
594 | + ) . '<br />'; |
|
595 | + $msg[] = sprintf( |
|
596 | + __( |
|
597 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
598 | + 'event_espresso' |
|
599 | + ), |
|
600 | + $method, |
|
601 | + $this->caller |
|
602 | + ); |
|
603 | + throw new EE_Error(implode('||', $msg)); |
|
604 | + } |
|
605 | + if ($route == $this->_current_route) { |
|
606 | + add_action('admin_init', array($this, $method)); |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
614 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
615 | + * |
|
616 | + * @access public |
|
617 | + * @return void |
|
618 | + */ |
|
619 | + public function add_metaboxes() |
|
620 | + { |
|
621 | + if (empty($this->_metaboxes)) { |
|
622 | + return; |
|
623 | + } //get out we don't have any metaboxes to set for this connection |
|
624 | + $this->_handle_metabox_array($this->_metaboxes); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + private function _handle_metabox_array($boxes, $add = true) |
|
629 | + { |
|
630 | + foreach ($boxes as $box) { |
|
631 | + if (! isset($box['page_route'])) { |
|
632 | + continue; |
|
633 | + } //we dont' have a valid array |
|
634 | + // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
635 | + $box['page_route'] = (array) $box['page_route']; |
|
636 | + foreach ($box['page_route'] as $route) { |
|
637 | + if ($route != $this->_current_route) { |
|
638 | + continue; |
|
639 | + } //get out we only add metaboxes for set route. |
|
640 | + if ($add) { |
|
641 | + $this->_add_metabox($box); |
|
642 | + } else { |
|
643 | + $this->_remove_metabox($box); |
|
644 | + } |
|
645 | + } |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
652 | + * |
|
653 | + * @access public |
|
654 | + * @return void |
|
655 | + */ |
|
656 | + public function remove_metaboxes() |
|
657 | + { |
|
658 | + if (empty($this->_remove_metaboxes)) { |
|
659 | + return; |
|
660 | + } //get out there are no metaboxes to remove |
|
661 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * This just handles adding a metabox |
|
667 | + * |
|
668 | + * @access private |
|
669 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
670 | + */ |
|
671 | + private function _add_metabox($args) |
|
672 | + { |
|
673 | + $current_screen = get_current_screen(); |
|
674 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
675 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
676 | + // set defaults |
|
677 | + $defaults = array( |
|
678 | + 'func' => $func, |
|
679 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
680 | + 'priority' => 'default', |
|
681 | + 'label' => $this->caller, |
|
682 | + 'context' => 'advanced', |
|
683 | + 'callback_args' => array(), |
|
684 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
685 | + ); |
|
686 | + $args = wp_parse_args($args, $defaults); |
|
687 | + extract($args); |
|
688 | + // make sure method exists |
|
689 | + if (! method_exists($this, $func)) { |
|
690 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
691 | + $msg[] = sprintf( |
|
692 | + __( |
|
693 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
694 | + 'event_espresso' |
|
695 | + ), |
|
696 | + $func, |
|
697 | + $this->caller |
|
698 | + ); |
|
699 | + throw new EE_Error(implode('||', $msg)); |
|
700 | + } |
|
701 | + // everything checks out so lets add the metabox |
|
702 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + private function _remove_metabox($args) |
|
707 | + { |
|
708 | + $current_screen = get_current_screen(); |
|
709 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
710 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
711 | + // set defaults |
|
712 | + $defaults = array( |
|
713 | + 'id' => isset($args['id']) |
|
714 | + ? $args['id'] |
|
715 | + : $this->_current_route |
|
716 | + . '_' |
|
717 | + . $this->caller |
|
718 | + . '_' |
|
719 | + . $func |
|
720 | + . '_metabox', |
|
721 | + 'context' => 'default', |
|
722 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
723 | + ); |
|
724 | + $args = wp_parse_args($args, $defaults); |
|
725 | + extract($args); |
|
726 | + // everything checks out so lets remove the box! |
|
727 | + remove_meta_box($id, $screen, $context); |
|
728 | + } |
|
729 | 729 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $this->_set_defaults(); |
205 | 205 | $this->_set_hooks_properties(); |
206 | 206 | // first let's verify we're on the right page |
207 | - if (! isset($this->_req_data['page']) |
|
207 | + if ( ! isset($this->_req_data['page']) |
|
208 | 208 | || (isset($this->_req_data['page']) |
209 | 209 | && $this->_adminpage_obj->page_slug |
210 | 210 | != $this->_req_data['page'])) { |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function enqueue_scripts_styles() |
256 | 256 | { |
257 | - if (! empty($this->_scripts_styles)) { |
|
257 | + if ( ! empty($this->_scripts_styles)) { |
|
258 | 258 | // first let's do all the registrations |
259 | - if (! isset($this->_scripts_styles['registers'])) { |
|
259 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
260 | 260 | $msg[] = __( |
261 | 261 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
262 | 262 | 'event_espresso' |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | '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', |
267 | 267 | 'event_espresso' |
268 | 268 | ), |
269 | - '<strong>' . $this->caller . '</strong>' |
|
269 | + '<strong>'.$this->caller.'</strong>' |
|
270 | 270 | ); |
271 | 271 | throw new EE_Error(implode('||', $msg)); |
272 | 272 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $details = wp_parse_args($details, $defaults); |
282 | 282 | extract($details); |
283 | 283 | // 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 |
284 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
284 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
285 | 285 | // let's make sure we're not missing any REQUIRED parameters |
286 | 286 | if (empty($url)) { |
287 | 287 | $msg[] = sprintf( |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
294 | 294 | 'event_espresso' |
295 | 295 | ), |
296 | - '<strong>' . $this->caller . '</strong>', |
|
296 | + '<strong>'.$this->caller.'</strong>', |
|
297 | 297 | $ref |
298 | 298 | ); |
299 | 299 | throw new EE_Error(implode('||', $msg)); |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ); |
310 | 310 | } |
311 | 311 | // k now lets do the enqueues |
312 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
312 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
313 | 313 | return; |
314 | 314 | } //not sure if we should throw an error here or not. |
315 | 315 | |
@@ -317,22 +317,22 @@ discard block |
||
317 | 317 | // make sure $routes is an array |
318 | 318 | $routes = (array) $routes; |
319 | 319 | if (in_array($this->_current_route, $routes)) { |
320 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
320 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
321 | 321 | : wp_enqueue_style($ref); |
322 | 322 | // if we have a localization for the script let's do that too. |
323 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
324 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
323 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
324 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
325 | 325 | wp_localize_script( |
326 | 326 | $ref, |
327 | 327 | $object_name, |
328 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
328 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
329 | 329 | ); |
330 | 330 | } |
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
334 | 334 | // let's do the deregisters |
335 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
335 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
336 | 336 | return; |
337 | 337 | } |
338 | 338 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -394,20 +394,20 @@ discard block |
||
394 | 394 | throw new EE_Error(implode('||', $msg)); |
395 | 395 | } |
396 | 396 | $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
397 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
397 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; // take the message -> The_Message |
|
398 | 398 | // first default file (if exists) |
399 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
399 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.'/'.$ref.'.core.php'; |
|
400 | 400 | if (is_readable($decaf_file)) { |
401 | 401 | require_once($decaf_file); |
402 | 402 | } |
403 | 403 | // now we have to do require for extended file (if needed) |
404 | 404 | if ($this->_extend) { |
405 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
405 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.'/Extend_'.$ref.'.core.php'); |
|
406 | 406 | } |
407 | 407 | // if we've got an extended class we use that! |
408 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
408 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
409 | 409 | // let's make sure the class exists |
410 | - if (! class_exists($ref)) { |
|
410 | + if ( ! class_exists($ref)) { |
|
411 | 411 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
412 | 412 | $msg[] = sprintf( |
413 | 413 | __( |
@@ -449,28 +449,28 @@ discard block |
||
449 | 449 | // first the actions |
450 | 450 | // note that these action hooks will have the $query_args value available. |
451 | 451 | $admin_class_name = get_class($this->_adminpage_obj); |
452 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
452 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
453 | 453 | add_action( |
454 | 454 | 'AHEE__' |
455 | 455 | . $admin_class_name |
456 | 456 | . '___redirect_after_action__before_redirect_modification_' |
457 | 457 | . $this->_current_route, |
458 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
458 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
459 | 459 | 10 |
460 | 460 | ); |
461 | 461 | } |
462 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
462 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
463 | 463 | add_action( |
464 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
465 | - array($this, '_redirect_action_' . $this->_current_route), |
|
464 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
465 | + array($this, '_redirect_action_'.$this->_current_route), |
|
466 | 466 | 10 |
467 | 467 | ); |
468 | 468 | } |
469 | 469 | // 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. |
470 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
470 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
471 | 471 | add_filter( |
472 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
473 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
472 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
473 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
474 | 474 | 10, |
475 | 475 | 2 |
476 | 476 | ); |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | 'argnum' => 1, |
496 | 496 | 'priority' => 10, |
497 | 497 | ), |
498 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
498 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
499 | 499 | 'type' => 'filter', |
500 | 500 | 'argnum' => 1, |
501 | 501 | 'priority' => 10, |
502 | 502 | ), |
503 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
503 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
504 | 504 | 'type' => 'filter', |
505 | 505 | 'argnum' => 1, |
506 | 506 | 'priority' => 10, |
@@ -517,21 +517,21 @@ discard block |
||
517 | 517 | ), |
518 | 518 | ); |
519 | 519 | foreach ($hook_filter_array as $hook => $args) { |
520 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
521 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
522 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
520 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
521 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
522 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
523 | 523 | } |
524 | 524 | if ($args['type'] == 'action') { |
525 | 525 | add_action( |
526 | 526 | $hook, |
527 | - array($this, $this->_current_route . '_' . $hook), |
|
527 | + array($this, $this->_current_route.'_'.$hook), |
|
528 | 528 | $args['priority'], |
529 | 529 | $args['argnum'] |
530 | 530 | ); |
531 | 531 | } else { |
532 | 532 | add_filter( |
533 | 533 | $hook, |
534 | - array($this, $this->_current_route . '_' . $hook), |
|
534 | + array($this, $this->_current_route.'_'.$hook), |
|
535 | 535 | $args['priority'], |
536 | 536 | $args['argnum'] |
537 | 537 | ); |
@@ -553,11 +553,11 @@ discard block |
||
553 | 553 | } //get out there's nothing to take care of. |
554 | 554 | foreach ($this->_ajax_func as $action => $method) { |
555 | 555 | // make sure method exists |
556 | - if (! method_exists($this, $method)) { |
|
556 | + if ( ! method_exists($this, $method)) { |
|
557 | 557 | $msg[] = __( |
558 | 558 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
559 | 559 | 'event_espresso' |
560 | - ) . '<br />'; |
|
560 | + ).'<br />'; |
|
561 | 561 | $msg[] = sprintf( |
562 | 562 | __( |
563 | 563 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | ); |
569 | 569 | throw new EE_Error(implode('||', $msg)); |
570 | 570 | } |
571 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
571 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
@@ -587,11 +587,11 @@ discard block |
||
587 | 587 | $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
588 | 588 | foreach ($this->_init_func as $route => $method) { |
589 | 589 | // make sure method exists |
590 | - if (! method_exists($this, $method)) { |
|
590 | + if ( ! method_exists($this, $method)) { |
|
591 | 591 | $msg[] = __( |
592 | 592 | 'There is no corresponding method for the hook labeled in the _init_func array', |
593 | 593 | 'event_espresso' |
594 | - ) . '<br />'; |
|
594 | + ).'<br />'; |
|
595 | 595 | $msg[] = sprintf( |
596 | 596 | __( |
597 | 597 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | private function _handle_metabox_array($boxes, $add = true) |
629 | 629 | { |
630 | 630 | foreach ($boxes as $box) { |
631 | - if (! isset($box['page_route'])) { |
|
631 | + if ( ! isset($box['page_route'])) { |
|
632 | 632 | continue; |
633 | 633 | } //we dont' have a valid array |
634 | 634 | // let's make sure $box['page_route'] is an array so the "foreach" will work. |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | // set defaults |
677 | 677 | $defaults = array( |
678 | 678 | 'func' => $func, |
679 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
679 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
680 | 680 | 'priority' => 'default', |
681 | 681 | 'label' => $this->caller, |
682 | 682 | 'context' => 'advanced', |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | $args = wp_parse_args($args, $defaults); |
687 | 687 | extract($args); |
688 | 688 | // make sure method exists |
689 | - if (! method_exists($this, $func)) { |
|
690 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
689 | + if ( ! method_exists($this, $func)) { |
|
690 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
691 | 691 | $msg[] = sprintf( |
692 | 692 | __( |
693 | 693 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -9,136 +9,136 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Question_Group extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - const system_personal = 1; |
|
12 | + const system_personal = 1; |
|
13 | 13 | |
14 | - const system_address = 2; |
|
14 | + const system_address = 2; |
|
15 | 15 | |
16 | - /** |
|
17 | - * private instance of the EEM_Question_Group object |
|
18 | - * |
|
19 | - * @var EEM_Question_Group |
|
20 | - */ |
|
21 | - protected static $_instance = null; |
|
16 | + /** |
|
17 | + * private instance of the EEM_Question_Group object |
|
18 | + * |
|
19 | + * @var EEM_Question_Group |
|
20 | + */ |
|
21 | + protected static $_instance = null; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EEM_Question_Group constructor. |
|
26 | - * |
|
27 | - * @param string|null $timezone |
|
28 | - */ |
|
29 | - protected function __construct($timezone = null) |
|
30 | - { |
|
31 | - $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
32 | - $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
24 | + /** |
|
25 | + * EEM_Question_Group constructor. |
|
26 | + * |
|
27 | + * @param string|null $timezone |
|
28 | + */ |
|
29 | + protected function __construct($timezone = null) |
|
30 | + { |
|
31 | + $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
32 | + $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
33 | 33 | |
34 | - $this->_tables = [ |
|
35 | - 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
36 | - ]; |
|
37 | - $this->_fields = [ |
|
38 | - 'Question_Group' => [ |
|
39 | - 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
40 | - 'QSG_ID', |
|
41 | - esc_html__('Question Group ID', 'event_espresso') |
|
42 | - ), |
|
43 | - 'QSG_name' => new EE_Plain_Text_Field( |
|
44 | - 'QSG_name', |
|
45 | - esc_html__('Question Group Name', 'event_espresso'), |
|
46 | - false, |
|
47 | - '' |
|
48 | - ), |
|
49 | - 'QSG_identifier' => new EE_Plain_Text_Field( |
|
50 | - 'QSG_identifier', |
|
51 | - esc_html__('Text ID for question Group', 'event_espresso'), |
|
52 | - false, |
|
53 | - '' |
|
54 | - ), |
|
55 | - 'QSG_desc' => new EE_Post_Content_Field( |
|
56 | - 'QSG_desc', |
|
57 | - esc_html__('Description of Question Group', 'event_espresso'), |
|
58 | - true, |
|
59 | - '' |
|
60 | - ), |
|
61 | - 'QSG_order' => new EE_Integer_Field( |
|
62 | - 'QSG_order', |
|
63 | - esc_html__('Order in which to show the question group', 'event_espresso'), |
|
64 | - true, |
|
65 | - 0 |
|
66 | - ), |
|
67 | - 'QSG_show_group_name' => new EE_Boolean_Field( |
|
68 | - 'QSG_show_group_name', |
|
69 | - esc_html__( |
|
70 | - 'Flag indicating whether to show the group\'s name on the registration page', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - false, |
|
74 | - true |
|
75 | - ), |
|
76 | - 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
77 | - 'QSG_show_group_desc', |
|
78 | - esc_html__( |
|
79 | - 'Flag indicating whether to show the group\s description on the registration page', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - false, |
|
83 | - false |
|
84 | - ), |
|
85 | - 'QSG_wp_user' => new EE_WP_User_Field( |
|
86 | - 'QSG_wp_user', |
|
87 | - esc_html__('Question Group Creator ID', 'event_espresso'), |
|
88 | - false |
|
89 | - ), |
|
90 | - 'QSG_system' => new EE_Integer_Field( |
|
91 | - 'QSG_system', |
|
92 | - esc_html__( |
|
93 | - 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - false, |
|
97 | - 0 |
|
98 | - ), |
|
99 | - 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
100 | - 'QSG_deleted', |
|
101 | - esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
102 | - false, |
|
103 | - false |
|
104 | - ), |
|
105 | - ], |
|
106 | - ]; |
|
107 | - $this->_model_relations = [ |
|
108 | - 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
109 | - 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
110 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
111 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
112 | - ]; |
|
113 | - // this model is generally available for reading |
|
114 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
115 | - new EE_Restriction_Generator_Public(); |
|
116 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
117 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
118 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
119 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
120 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
121 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
34 | + $this->_tables = [ |
|
35 | + 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
36 | + ]; |
|
37 | + $this->_fields = [ |
|
38 | + 'Question_Group' => [ |
|
39 | + 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
40 | + 'QSG_ID', |
|
41 | + esc_html__('Question Group ID', 'event_espresso') |
|
42 | + ), |
|
43 | + 'QSG_name' => new EE_Plain_Text_Field( |
|
44 | + 'QSG_name', |
|
45 | + esc_html__('Question Group Name', 'event_espresso'), |
|
46 | + false, |
|
47 | + '' |
|
48 | + ), |
|
49 | + 'QSG_identifier' => new EE_Plain_Text_Field( |
|
50 | + 'QSG_identifier', |
|
51 | + esc_html__('Text ID for question Group', 'event_espresso'), |
|
52 | + false, |
|
53 | + '' |
|
54 | + ), |
|
55 | + 'QSG_desc' => new EE_Post_Content_Field( |
|
56 | + 'QSG_desc', |
|
57 | + esc_html__('Description of Question Group', 'event_espresso'), |
|
58 | + true, |
|
59 | + '' |
|
60 | + ), |
|
61 | + 'QSG_order' => new EE_Integer_Field( |
|
62 | + 'QSG_order', |
|
63 | + esc_html__('Order in which to show the question group', 'event_espresso'), |
|
64 | + true, |
|
65 | + 0 |
|
66 | + ), |
|
67 | + 'QSG_show_group_name' => new EE_Boolean_Field( |
|
68 | + 'QSG_show_group_name', |
|
69 | + esc_html__( |
|
70 | + 'Flag indicating whether to show the group\'s name on the registration page', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + false, |
|
74 | + true |
|
75 | + ), |
|
76 | + 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
77 | + 'QSG_show_group_desc', |
|
78 | + esc_html__( |
|
79 | + 'Flag indicating whether to show the group\s description on the registration page', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + false, |
|
83 | + false |
|
84 | + ), |
|
85 | + 'QSG_wp_user' => new EE_WP_User_Field( |
|
86 | + 'QSG_wp_user', |
|
87 | + esc_html__('Question Group Creator ID', 'event_espresso'), |
|
88 | + false |
|
89 | + ), |
|
90 | + 'QSG_system' => new EE_Integer_Field( |
|
91 | + 'QSG_system', |
|
92 | + esc_html__( |
|
93 | + 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + false, |
|
97 | + 0 |
|
98 | + ), |
|
99 | + 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
100 | + 'QSG_deleted', |
|
101 | + esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
102 | + false, |
|
103 | + false |
|
104 | + ), |
|
105 | + ], |
|
106 | + ]; |
|
107 | + $this->_model_relations = [ |
|
108 | + 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
109 | + 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
110 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
111 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
112 | + ]; |
|
113 | + // this model is generally available for reading |
|
114 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
115 | + new EE_Restriction_Generator_Public(); |
|
116 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
117 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
118 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
119 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
120 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
121 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
122 | 122 | |
123 | - parent::__construct($timezone); |
|
124 | - } |
|
123 | + parent::__construct($timezone); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * searches the db for the question group with the latest question order and returns that value. |
|
129 | - * |
|
130 | - * @return int |
|
131 | - * @throws EE_Error |
|
132 | - */ |
|
133 | - public function get_latest_question_group_order() |
|
134 | - { |
|
135 | - $max = $this->_get_all_wpdb_results( |
|
136 | - [], |
|
137 | - ARRAY_A, |
|
138 | - [ |
|
139 | - 'max_order' => ["MAX(QSG_order)", "%d"], |
|
140 | - ] |
|
141 | - ); |
|
142 | - return $max[0]['max_order']; |
|
143 | - } |
|
127 | + /** |
|
128 | + * searches the db for the question group with the latest question order and returns that value. |
|
129 | + * |
|
130 | + * @return int |
|
131 | + * @throws EE_Error |
|
132 | + */ |
|
133 | + public function get_latest_question_group_order() |
|
134 | + { |
|
135 | + $max = $this->_get_all_wpdb_results( |
|
136 | + [], |
|
137 | + ARRAY_A, |
|
138 | + [ |
|
139 | + 'max_order' => ["MAX(QSG_order)", "%d"], |
|
140 | + ] |
|
141 | + ); |
|
142 | + return $max[0]['max_order']; |
|
143 | + } |
|
144 | 144 | } |