@@ -19,4167 +19,4167 @@ |
||
19 | 19 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var LoaderInterface |
|
24 | - */ |
|
25 | - protected $loader; |
|
22 | + /** |
|
23 | + * @var LoaderInterface |
|
24 | + */ |
|
25 | + protected $loader; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var RequestInterface |
|
29 | - */ |
|
30 | - protected $request; |
|
27 | + /** |
|
28 | + * @var RequestInterface |
|
29 | + */ |
|
30 | + protected $request; |
|
31 | 31 | |
32 | - // set in _init_page_props() |
|
33 | - public $page_slug; |
|
32 | + // set in _init_page_props() |
|
33 | + public $page_slug; |
|
34 | 34 | |
35 | - public $page_label; |
|
35 | + public $page_label; |
|
36 | 36 | |
37 | - public $page_folder; |
|
37 | + public $page_folder; |
|
38 | 38 | |
39 | - // set in define_page_props() |
|
40 | - protected $_admin_base_url; |
|
39 | + // set in define_page_props() |
|
40 | + protected $_admin_base_url; |
|
41 | 41 | |
42 | - protected $_admin_base_path; |
|
42 | + protected $_admin_base_path; |
|
43 | 43 | |
44 | - protected $_admin_page_title; |
|
44 | + protected $_admin_page_title; |
|
45 | 45 | |
46 | - protected $_labels; |
|
46 | + protected $_labels; |
|
47 | 47 | |
48 | 48 | |
49 | - // set early within EE_Admin_Init |
|
50 | - protected $_wp_page_slug; |
|
49 | + // set early within EE_Admin_Init |
|
50 | + protected $_wp_page_slug; |
|
51 | 51 | |
52 | - // navtabs |
|
53 | - protected $_nav_tabs; |
|
52 | + // navtabs |
|
53 | + protected $_nav_tabs; |
|
54 | 54 | |
55 | - protected $_default_nav_tab_name; |
|
55 | + protected $_default_nav_tab_name; |
|
56 | 56 | |
57 | 57 | |
58 | - // template variables (used by templates) |
|
59 | - protected $_template_path; |
|
58 | + // template variables (used by templates) |
|
59 | + protected $_template_path; |
|
60 | 60 | |
61 | - protected $_column_template_path; |
|
61 | + protected $_column_template_path; |
|
62 | 62 | |
63 | - /** |
|
64 | - * @var array $_template_args |
|
65 | - */ |
|
66 | - protected $_template_args = []; |
|
63 | + /** |
|
64 | + * @var array $_template_args |
|
65 | + */ |
|
66 | + protected $_template_args = []; |
|
67 | 67 | |
68 | - /** |
|
69 | - * this will hold the list table object for a given view. |
|
70 | - * |
|
71 | - * @var EE_Admin_List_Table $_list_table_object |
|
72 | - */ |
|
73 | - protected $_list_table_object; |
|
68 | + /** |
|
69 | + * this will hold the list table object for a given view. |
|
70 | + * |
|
71 | + * @var EE_Admin_List_Table $_list_table_object |
|
72 | + */ |
|
73 | + protected $_list_table_object; |
|
74 | 74 | |
75 | - // bools |
|
76 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
75 | + // bools |
|
76 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
77 | 77 | |
78 | - protected $_routing; |
|
78 | + protected $_routing; |
|
79 | 79 | |
80 | - // list table args |
|
81 | - protected $_view; |
|
80 | + // list table args |
|
81 | + protected $_view; |
|
82 | 82 | |
83 | - protected $_views; |
|
83 | + protected $_views; |
|
84 | 84 | |
85 | 85 | |
86 | - // action => method pairs used for routing incoming requests |
|
87 | - protected $_page_routes; |
|
86 | + // action => method pairs used for routing incoming requests |
|
87 | + protected $_page_routes; |
|
88 | 88 | |
89 | - /** |
|
90 | - * @var array $_page_config |
|
91 | - */ |
|
92 | - protected $_page_config; |
|
89 | + /** |
|
90 | + * @var array $_page_config |
|
91 | + */ |
|
92 | + protected $_page_config; |
|
93 | 93 | |
94 | - /** |
|
95 | - * the current page route and route config |
|
96 | - * |
|
97 | - * @var string $_route |
|
98 | - */ |
|
99 | - protected $_route; |
|
94 | + /** |
|
95 | + * the current page route and route config |
|
96 | + * |
|
97 | + * @var string $_route |
|
98 | + */ |
|
99 | + protected $_route; |
|
100 | 100 | |
101 | - /** |
|
102 | - * @var string $_cpt_route |
|
103 | - */ |
|
104 | - protected $_cpt_route; |
|
101 | + /** |
|
102 | + * @var string $_cpt_route |
|
103 | + */ |
|
104 | + protected $_cpt_route; |
|
105 | 105 | |
106 | - /** |
|
107 | - * @var array $_route_config |
|
108 | - */ |
|
109 | - protected $_route_config; |
|
106 | + /** |
|
107 | + * @var array $_route_config |
|
108 | + */ |
|
109 | + protected $_route_config; |
|
110 | 110 | |
111 | - /** |
|
112 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
113 | - * actions. |
|
114 | - * |
|
115 | - * @since 4.6.x |
|
116 | - * @var array. |
|
117 | - */ |
|
118 | - protected $_default_route_query_args; |
|
119 | - |
|
120 | - // set via request page and action args. |
|
121 | - protected $_current_page; |
|
122 | - |
|
123 | - protected $_current_view; |
|
124 | - |
|
125 | - protected $_current_page_view_url; |
|
126 | - |
|
127 | - /** |
|
128 | - * unprocessed value for the 'action' request param (default '') |
|
129 | - * |
|
130 | - * @var string |
|
131 | - */ |
|
132 | - protected $raw_req_action = ''; |
|
133 | - |
|
134 | - /** |
|
135 | - * unprocessed value for the 'page' request param (default '') |
|
136 | - * |
|
137 | - * @var string |
|
138 | - */ |
|
139 | - protected $raw_req_page = ''; |
|
140 | - |
|
141 | - /** |
|
142 | - * sanitized request action (and nonce) |
|
143 | - * |
|
144 | - * @var string |
|
145 | - */ |
|
146 | - protected $_req_action = ''; |
|
147 | - |
|
148 | - /** |
|
149 | - * sanitized request action nonce |
|
150 | - * |
|
151 | - * @var string |
|
152 | - */ |
|
153 | - protected $_req_nonce = ''; |
|
154 | - |
|
155 | - /** |
|
156 | - * @var string |
|
157 | - */ |
|
158 | - protected $_search_btn_label = ''; |
|
159 | - |
|
160 | - /** |
|
161 | - * @var string |
|
162 | - */ |
|
163 | - protected $_search_box_callback = ''; |
|
164 | - |
|
165 | - /** |
|
166 | - * @var WP_Screen |
|
167 | - */ |
|
168 | - protected $_current_screen; |
|
169 | - |
|
170 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
171 | - protected $_hook_obj; |
|
172 | - |
|
173 | - // for holding incoming request data |
|
174 | - protected $_req_data = []; |
|
175 | - |
|
176 | - // yes / no array for admin form fields |
|
177 | - protected $_yes_no_values = []; |
|
178 | - |
|
179 | - // some default things shared by all child classes |
|
180 | - protected $_default_espresso_metaboxes; |
|
181 | - |
|
182 | - /** |
|
183 | - * @var EE_Registry |
|
184 | - */ |
|
185 | - protected $EE = null; |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
190 | - * |
|
191 | - * @var boolean |
|
192 | - */ |
|
193 | - protected $_is_caf = false; |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @Constructor |
|
198 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
199 | - * @throws EE_Error |
|
200 | - * @throws InvalidArgumentException |
|
201 | - * @throws ReflectionException |
|
202 | - * @throws InvalidDataTypeException |
|
203 | - * @throws InvalidInterfaceException |
|
204 | - */ |
|
205 | - public function __construct($routing = true) |
|
206 | - { |
|
207 | - $this->loader = LoaderFactory::getLoader(); |
|
208 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
209 | - $this->_routing = $routing; |
|
210 | - |
|
211 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
212 | - $this->_is_caf = true; |
|
213 | - } |
|
214 | - $this->_yes_no_values = [ |
|
215 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
216 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
217 | - ]; |
|
218 | - // set the _req_data property. |
|
219 | - $this->_req_data = $this->request->requestParams(); |
|
220 | - // set initial page props (child method) |
|
221 | - $this->_init_page_props(); |
|
222 | - // set global defaults |
|
223 | - $this->_set_defaults(); |
|
224 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
225 | - $this->_global_ajax_hooks(); |
|
226 | - $this->_ajax_hooks(); |
|
227 | - // other_page_hooks have to be early too. |
|
228 | - $this->_do_other_page_hooks(); |
|
229 | - // set up page dependencies |
|
230 | - $this->_before_page_setup(); |
|
231 | - $this->_page_setup(); |
|
232 | - // die(); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * _init_page_props |
|
238 | - * Child classes use to set at least the following properties: |
|
239 | - * $page_slug. |
|
240 | - * $page_label. |
|
241 | - * |
|
242 | - * @abstract |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - abstract protected function _init_page_props(); |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * _ajax_hooks |
|
250 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
251 | - * Note: within the ajax callback methods. |
|
252 | - * |
|
253 | - * @abstract |
|
254 | - * @return void |
|
255 | - */ |
|
256 | - abstract protected function _ajax_hooks(); |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * _define_page_props |
|
261 | - * child classes define page properties in here. Must include at least: |
|
262 | - * $_admin_base_url = base_url for all admin pages |
|
263 | - * $_admin_page_title = default admin_page_title for admin pages |
|
264 | - * $_labels = array of default labels for various automatically generated elements: |
|
265 | - * array( |
|
266 | - * 'buttons' => array( |
|
267 | - * 'add' => esc_html__('label for add new button'), |
|
268 | - * 'edit' => esc_html__('label for edit button'), |
|
269 | - * 'delete' => esc_html__('label for delete button') |
|
270 | - * ) |
|
271 | - * ) |
|
272 | - * |
|
273 | - * @abstract |
|
274 | - * @return void |
|
275 | - */ |
|
276 | - abstract protected function _define_page_props(); |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * _set_page_routes |
|
281 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
282 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
283 | - * have a 'default' route. Here's the format |
|
284 | - * $this->_page_routes = array( |
|
285 | - * 'default' => array( |
|
286 | - * 'func' => '_default_method_handling_route', |
|
287 | - * 'args' => array('array','of','args'), |
|
288 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
289 | - * ajax request, backend processing) |
|
290 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
291 | - * headers route after. The string you enter here should match the defined route reference for a |
|
292 | - * headers sent route. |
|
293 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
294 | - * this route. |
|
295 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
296 | - * checks). |
|
297 | - * ), |
|
298 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
299 | - * handling method. |
|
300 | - * ) |
|
301 | - * ) |
|
302 | - * |
|
303 | - * @abstract |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - abstract protected function _set_page_routes(); |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * _set_page_config |
|
311 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
312 | - * array corresponds to the page_route for the loaded page. Format: |
|
313 | - * $this->_page_config = array( |
|
314 | - * 'default' => array( |
|
315 | - * 'labels' => array( |
|
316 | - * 'buttons' => array( |
|
317 | - * 'add' => esc_html__('label for adding item'), |
|
318 | - * 'edit' => esc_html__('label for editing item'), |
|
319 | - * 'delete' => esc_html__('label for deleting item') |
|
320 | - * ), |
|
321 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
322 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
323 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
324 | - * _define_page_props() method |
|
325 | - * 'nav' => array( |
|
326 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
327 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
328 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
329 | - * 'order' => 10, //required to indicate tab position. |
|
330 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
331 | - * displayed then add this parameter. |
|
332 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
333 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
334 | - * metaboxes set for eventespresso admin pages. |
|
335 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
336 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
337 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
338 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
339 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
340 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
341 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
342 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
343 | - * want to display. |
|
344 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
345 | - * 'tab_id' => array( |
|
346 | - * 'title' => 'tab_title', |
|
347 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
348 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
349 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
350 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
351 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
352 | - * attempt to use the callback which should match the name of a method in the class |
|
353 | - * ), |
|
354 | - * 'tab2_id' => array( |
|
355 | - * 'title' => 'tab2 title', |
|
356 | - * 'filename' => 'file_name_2' |
|
357 | - * 'callback' => 'callback_method_for_content', |
|
358 | - * ), |
|
359 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
360 | - * help tab area on an admin page. @return void |
|
361 | - * |
|
362 | - * @abstract |
|
363 | - */ |
|
364 | - abstract protected function _set_page_config(); |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * _add_screen_options |
|
369 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
370 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
371 | - * to a particular view. |
|
372 | - * |
|
373 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
374 | - * see also WP_Screen object documents... |
|
375 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
376 | - * @abstract |
|
377 | - * @return void |
|
378 | - */ |
|
379 | - abstract protected function _add_screen_options(); |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _add_feature_pointers |
|
384 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
385 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
386 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
387 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
388 | - * extended) also see: |
|
389 | - * |
|
390 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
391 | - * @abstract |
|
392 | - * @return void |
|
393 | - */ |
|
394 | - abstract protected function _add_feature_pointers(); |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * load_scripts_styles |
|
399 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
400 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
401 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
402 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
403 | - * |
|
404 | - * @abstract |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - abstract public function load_scripts_styles(); |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * admin_init |
|
412 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
413 | - * all pages/views loaded by child class. |
|
414 | - * |
|
415 | - * @abstract |
|
416 | - * @return void |
|
417 | - */ |
|
418 | - abstract public function admin_init(); |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * admin_notices |
|
423 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
424 | - * all pages/views loaded by child class. |
|
425 | - * |
|
426 | - * @abstract |
|
427 | - * @return void |
|
428 | - */ |
|
429 | - abstract public function admin_notices(); |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * admin_footer_scripts |
|
434 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
435 | - * will apply to all pages/views loaded by child class. |
|
436 | - * |
|
437 | - * @return void |
|
438 | - */ |
|
439 | - abstract public function admin_footer_scripts(); |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * admin_footer |
|
444 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
445 | - * apply to all pages/views loaded by child class. |
|
446 | - * |
|
447 | - * @return void |
|
448 | - */ |
|
449 | - public function admin_footer() |
|
450 | - { |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * _global_ajax_hooks |
|
456 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
457 | - * Note: within the ajax callback methods. |
|
458 | - * |
|
459 | - * @abstract |
|
460 | - * @return void |
|
461 | - */ |
|
462 | - protected function _global_ajax_hooks() |
|
463 | - { |
|
464 | - // for lazy loading of metabox content |
|
465 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - public function ajax_metabox_content() |
|
470 | - { |
|
471 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
472 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
473 | - self::cached_rss_display($content_id, $content_url); |
|
474 | - wp_die(); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
480 | - * |
|
481 | - * @return void |
|
482 | - */ |
|
483 | - protected function _before_page_setup() |
|
484 | - { |
|
485 | - // default is to do nothing |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Makes sure any things that need to be loaded early get handled. |
|
491 | - * We also escape early here if the page requested doesn't match the object. |
|
492 | - * |
|
493 | - * @final |
|
494 | - * @return void |
|
495 | - * @throws EE_Error |
|
496 | - * @throws InvalidArgumentException |
|
497 | - * @throws ReflectionException |
|
498 | - * @throws InvalidDataTypeException |
|
499 | - * @throws InvalidInterfaceException |
|
500 | - */ |
|
501 | - final protected function _page_setup() |
|
502 | - { |
|
503 | - // requires? |
|
504 | - // admin_init stuff - global - we're setting this REALLY early |
|
505 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
506 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
507 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
508 | - // next verify if we need to load anything... |
|
509 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
510 | - $this->page_folder = strtolower( |
|
511 | - str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
512 | - ); |
|
513 | - global $ee_menu_slugs; |
|
514 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
515 | - if ( |
|
516 | - ! $this->request->isAjax() |
|
517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
518 | - ) { |
|
519 | - return; |
|
520 | - } |
|
521 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
522 | - // we need to copy the action from the second to the first |
|
523 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
524 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
525 | - $action = $action !== '-1' ? $action : $action2; |
|
526 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
527 | - |
|
528 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
529 | - // then let's use the route as the action. |
|
530 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
531 | - $route = $this->request->getRequestParam('route'); |
|
532 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
533 | - ? $route |
|
534 | - : $req_action; |
|
535 | - |
|
536 | - $this->_current_view = $this->_req_action; |
|
537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
538 | - $this->_define_page_props(); |
|
539 | - $this->_current_page_view_url = add_query_arg( |
|
540 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
541 | - $this->_admin_base_url |
|
542 | - ); |
|
543 | - // default things |
|
544 | - $this->_default_espresso_metaboxes = [ |
|
545 | - '_espresso_news_post_box', |
|
546 | - '_espresso_links_post_box', |
|
547 | - '_espresso_ratings_request', |
|
548 | - '_espresso_sponsors_post_box', |
|
549 | - ]; |
|
550 | - // set page configs |
|
551 | - $this->_set_page_routes(); |
|
552 | - $this->_set_page_config(); |
|
553 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
554 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
555 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
556 | - if ($wp_referer) { |
|
557 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
558 | - } |
|
559 | - } |
|
560 | - // for caffeinated and other extended functionality. |
|
561 | - // If there is a _extend_page_config method |
|
562 | - // then let's run that to modify the all the various page configuration arrays |
|
563 | - if (method_exists($this, '_extend_page_config')) { |
|
564 | - $this->_extend_page_config(); |
|
565 | - } |
|
566 | - // for CPT and other extended functionality. |
|
567 | - // If there is an _extend_page_config_for_cpt |
|
568 | - // then let's run that to modify all the various page configuration arrays. |
|
569 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
570 | - $this->_extend_page_config_for_cpt(); |
|
571 | - } |
|
572 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
573 | - $this->_page_routes = apply_filters( |
|
574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
575 | - $this->_page_routes, |
|
576 | - $this |
|
577 | - ); |
|
578 | - $this->_page_config = apply_filters( |
|
579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
580 | - $this->_page_config, |
|
581 | - $this |
|
582 | - ); |
|
583 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
584 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
586 | - add_action( |
|
587 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
589 | - 10, |
|
590 | - 2 |
|
591 | - ); |
|
592 | - } |
|
593 | - // next route only if routing enabled |
|
594 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
595 | - $this->_verify_routes(); |
|
596 | - // next let's just check user_access and kill if no access |
|
597 | - $this->check_user_access(); |
|
598 | - if ($this->_is_UI_request) { |
|
599 | - // admin_init stuff - global, all views for this page class, specific view |
|
600 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
603 | - } |
|
604 | - } else { |
|
605 | - // hijack regular WP loading and route admin request immediately |
|
606 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
607 | - $this->route_admin_request(); |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
615 | - * |
|
616 | - * @return void |
|
617 | - * @throws EE_Error |
|
618 | - */ |
|
619 | - private function _do_other_page_hooks() |
|
620 | - { |
|
621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
622 | - foreach ($registered_pages as $page) { |
|
623 | - // now let's setup the file name and class that should be present |
|
624 | - $classname = str_replace('.class.php', '', $page); |
|
625 | - // autoloaders should take care of loading file |
|
626 | - if (! class_exists($classname)) { |
|
627 | - $error_msg[] = sprintf( |
|
628 | - esc_html__( |
|
629 | - 'Something went wrong with loading the %s admin hooks page.', |
|
630 | - 'event_espresso' |
|
631 | - ), |
|
632 | - $page |
|
633 | - ); |
|
634 | - $error_msg[] = $error_msg[0] |
|
635 | - . "\r\n" |
|
636 | - . sprintf( |
|
637 | - esc_html__( |
|
638 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
639 | - 'event_espresso' |
|
640 | - ), |
|
641 | - $page, |
|
642 | - '<br />', |
|
643 | - '<strong>' . $classname . '</strong>' |
|
644 | - ); |
|
645 | - throw new EE_Error(implode('||', $error_msg)); |
|
646 | - } |
|
647 | - // notice we are passing the instance of this class to the hook object. |
|
648 | - $this->loader->getShared($classname, [$this]); |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * @throws ReflectionException |
|
655 | - * @throws EE_Error |
|
656 | - */ |
|
657 | - public function load_page_dependencies() |
|
658 | - { |
|
659 | - try { |
|
660 | - $this->_load_page_dependencies(); |
|
661 | - } catch (EE_Error $e) { |
|
662 | - $e->get_error(); |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * load_page_dependencies |
|
669 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
670 | - * |
|
671 | - * @return void |
|
672 | - * @throws DomainException |
|
673 | - * @throws EE_Error |
|
674 | - * @throws InvalidArgumentException |
|
675 | - * @throws InvalidDataTypeException |
|
676 | - * @throws InvalidInterfaceException |
|
677 | - */ |
|
678 | - protected function _load_page_dependencies() |
|
679 | - { |
|
680 | - // let's set the current_screen and screen options to override what WP set |
|
681 | - $this->_current_screen = get_current_screen(); |
|
682 | - // load admin_notices - global, page class, and view specific |
|
683 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
684 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
687 | - } |
|
688 | - // load network admin_notices - global, page class, and view specific |
|
689 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
692 | - } |
|
693 | - // this will save any per_page screen options if they are present |
|
694 | - $this->_set_per_page_screen_options(); |
|
695 | - // setup list table properties |
|
696 | - $this->_set_list_table(); |
|
697 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
698 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
699 | - $this->_add_registered_meta_boxes(); |
|
700 | - $this->_add_screen_columns(); |
|
701 | - // add screen options - global, page child class, and view specific |
|
702 | - $this->_add_global_screen_options(); |
|
703 | - $this->_add_screen_options(); |
|
704 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
705 | - if (method_exists($this, $add_screen_options)) { |
|
706 | - $this->{$add_screen_options}(); |
|
707 | - } |
|
708 | - // add help tab(s) - set via page_config and qtips. |
|
709 | - $this->_add_help_tabs(); |
|
710 | - $this->_add_qtips(); |
|
711 | - // add feature_pointers - global, page child class, and view specific |
|
712 | - $this->_add_feature_pointers(); |
|
713 | - $this->_add_global_feature_pointers(); |
|
714 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
715 | - if (method_exists($this, $add_feature_pointer)) { |
|
716 | - $this->{$add_feature_pointer}(); |
|
717 | - } |
|
718 | - // enqueue scripts/styles - global, page class, and view specific |
|
719 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
720 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
721 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
722 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
723 | - } |
|
724 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
725 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
726 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
727 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
728 | - // is a good use case. Notice the late priority we're giving these |
|
729 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
730 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
731 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
732 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
733 | - } |
|
734 | - // admin footer scripts |
|
735 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
736 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
737 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
738 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
739 | - } |
|
740 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
741 | - // targeted hook |
|
742 | - do_action( |
|
743 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
744 | - ); |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * _set_defaults |
|
750 | - * This sets some global defaults for class properties. |
|
751 | - */ |
|
752 | - private function _set_defaults() |
|
753 | - { |
|
754 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
755 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
756 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
757 | - $this->_page_config = $this->_default_route_query_args = []; |
|
758 | - $this->_default_nav_tab_name = 'overview'; |
|
759 | - // init template args |
|
760 | - $this->_template_args = [ |
|
761 | - 'admin_page_header' => '', |
|
762 | - 'admin_page_content' => '', |
|
763 | - 'post_body_content' => '', |
|
764 | - 'before_list_table' => '', |
|
765 | - 'after_list_table' => '', |
|
766 | - ]; |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * route_admin_request |
|
772 | - * |
|
773 | - * @return void |
|
774 | - * @throws InvalidArgumentException |
|
775 | - * @throws InvalidInterfaceException |
|
776 | - * @throws InvalidDataTypeException |
|
777 | - * @throws EE_Error |
|
778 | - * @throws ReflectionException |
|
779 | - * @see _route_admin_request() |
|
780 | - */ |
|
781 | - public function route_admin_request() |
|
782 | - { |
|
783 | - try { |
|
784 | - $this->_route_admin_request(); |
|
785 | - } catch (EE_Error $e) { |
|
786 | - $e->get_error(); |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - public function set_wp_page_slug($wp_page_slug) |
|
792 | - { |
|
793 | - $this->_wp_page_slug = $wp_page_slug; |
|
794 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
795 | - if (is_network_admin()) { |
|
796 | - $this->_wp_page_slug .= '-network'; |
|
797 | - } |
|
798 | - } |
|
799 | - |
|
800 | - |
|
801 | - /** |
|
802 | - * _verify_routes |
|
803 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
804 | - * we know if we need to drop out. |
|
805 | - * |
|
806 | - * @return bool |
|
807 | - * @throws EE_Error |
|
808 | - */ |
|
809 | - protected function _verify_routes() |
|
810 | - { |
|
811 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
813 | - return false; |
|
814 | - } |
|
815 | - $this->_route = false; |
|
816 | - // check that the page_routes array is not empty |
|
817 | - if (empty($this->_page_routes)) { |
|
818 | - // user error msg |
|
819 | - $error_msg = sprintf( |
|
820 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
821 | - $this->_admin_page_title |
|
822 | - ); |
|
823 | - // developer error msg |
|
824 | - $error_msg .= '||' . $error_msg |
|
825 | - . esc_html__( |
|
826 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
827 | - 'event_espresso' |
|
828 | - ); |
|
829 | - throw new EE_Error($error_msg); |
|
830 | - } |
|
831 | - // and that the requested page route exists |
|
832 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
835 | - ? $this->_page_config[ $this->_req_action ] |
|
836 | - : []; |
|
837 | - } else { |
|
838 | - // user error msg |
|
839 | - $error_msg = sprintf( |
|
840 | - esc_html__( |
|
841 | - 'The requested page route does not exist for the %s admin page.', |
|
842 | - 'event_espresso' |
|
843 | - ), |
|
844 | - $this->_admin_page_title |
|
845 | - ); |
|
846 | - // developer error msg |
|
847 | - $error_msg .= '||' . $error_msg |
|
848 | - . sprintf( |
|
849 | - esc_html__( |
|
850 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
851 | - 'event_espresso' |
|
852 | - ), |
|
853 | - $this->_req_action |
|
854 | - ); |
|
855 | - throw new EE_Error($error_msg); |
|
856 | - } |
|
857 | - // and that a default route exists |
|
858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
859 | - // user error msg |
|
860 | - $error_msg = sprintf( |
|
861 | - esc_html__( |
|
862 | - 'A default page route has not been set for the % admin page.', |
|
863 | - 'event_espresso' |
|
864 | - ), |
|
865 | - $this->_admin_page_title |
|
866 | - ); |
|
867 | - // developer error msg |
|
868 | - $error_msg .= '||' . $error_msg |
|
869 | - . esc_html__( |
|
870 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
871 | - 'event_espresso' |
|
872 | - ); |
|
873 | - throw new EE_Error($error_msg); |
|
874 | - } |
|
875 | - // first lets' catch if the UI request has EVER been set. |
|
876 | - if ($this->_is_UI_request === null) { |
|
877 | - // lets set if this is a UI request or not. |
|
878 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
879 | - // wait a minute... we might have a noheader in the route array |
|
880 | - $this->_is_UI_request = ! ( |
|
881 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
882 | - ) |
|
883 | - ? $this->_is_UI_request |
|
884 | - : false; |
|
885 | - } |
|
886 | - $this->_set_current_labels(); |
|
887 | - return true; |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
893 | - * |
|
894 | - * @param string $route the route name we're verifying |
|
895 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
896 | - * @throws EE_Error |
|
897 | - */ |
|
898 | - protected function _verify_route($route) |
|
899 | - { |
|
900 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
901 | - return true; |
|
902 | - } |
|
903 | - // user error msg |
|
904 | - $error_msg = sprintf( |
|
905 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
906 | - $this->_admin_page_title |
|
907 | - ); |
|
908 | - // developer error msg |
|
909 | - $error_msg .= '||' . $error_msg |
|
910 | - . sprintf( |
|
911 | - esc_html__( |
|
912 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
913 | - 'event_espresso' |
|
914 | - ), |
|
915 | - $route |
|
916 | - ); |
|
917 | - throw new EE_Error($error_msg); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * perform nonce verification |
|
923 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
924 | - * using this method (and save retyping!) |
|
925 | - * |
|
926 | - * @param string $nonce The nonce sent |
|
927 | - * @param string $nonce_ref The nonce reference string (name0) |
|
928 | - * @return void |
|
929 | - * @throws EE_Error |
|
930 | - */ |
|
931 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
932 | - { |
|
933 | - // verify nonce against expected value |
|
934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
935 | - // these are not the droids you are looking for !!! |
|
936 | - $msg = sprintf( |
|
937 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
938 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
939 | - '</a>' |
|
940 | - ); |
|
941 | - if (WP_DEBUG) { |
|
942 | - $msg .= "\n "; |
|
943 | - $msg .= sprintf( |
|
944 | - esc_html__( |
|
945 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
946 | - 'event_espresso' |
|
947 | - ), |
|
948 | - __CLASS__ |
|
949 | - ); |
|
950 | - } |
|
951 | - if (! $this->request->isAjax()) { |
|
952 | - wp_die($msg); |
|
953 | - } |
|
954 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
955 | - $this->_return_json(); |
|
956 | - } |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - /** |
|
961 | - * _route_admin_request() |
|
962 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
963 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
964 | - * in the page routes and then will try to load the corresponding method. |
|
965 | - * |
|
966 | - * @return void |
|
967 | - * @throws EE_Error |
|
968 | - * @throws InvalidArgumentException |
|
969 | - * @throws InvalidDataTypeException |
|
970 | - * @throws InvalidInterfaceException |
|
971 | - * @throws ReflectionException |
|
972 | - */ |
|
973 | - protected function _route_admin_request() |
|
974 | - { |
|
975 | - if (! $this->_is_UI_request) { |
|
976 | - $this->_verify_routes(); |
|
977 | - } |
|
978 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
979 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
980 | - // set nonce from post data |
|
981 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
982 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
983 | - } |
|
984 | - // set the nav_tabs array but ONLY if this is UI_request |
|
985 | - if ($this->_is_UI_request) { |
|
986 | - $this->_set_nav_tabs(); |
|
987 | - } |
|
988 | - // grab callback function |
|
989 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
990 | - // check if callback has args |
|
991 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
992 | - $error_msg = ''; |
|
993 | - // action right before calling route |
|
994 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
996 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
997 | - } |
|
998 | - // right before calling the route, let's clean the _wp_http_referer |
|
999 | - $this->request->unSetRequestParam('_wp_http_referer'); |
|
1000 | - $this->request->unSetServerParam('_wp_http_referer'); |
|
1001 | - $cleaner_request_uri = remove_query_arg( |
|
1002 | - '_wp_http_referer', |
|
1003 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
1004 | - ); |
|
1005 | - $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri); |
|
1006 | - $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri); |
|
1007 | - if (! empty($func)) { |
|
1008 | - if (is_array($func)) { |
|
1009 | - [$class, $method] = $func; |
|
1010 | - } elseif (strpos($func, '::') !== false) { |
|
1011 | - [$class, $method] = explode('::', $func); |
|
1012 | - } else { |
|
1013 | - $class = $this; |
|
1014 | - $method = $func; |
|
1015 | - } |
|
1016 | - if (! (is_object($class) && $class === $this)) { |
|
1017 | - // send along this admin page object for access by addons. |
|
1018 | - $args['admin_page_object'] = $this; |
|
1019 | - } |
|
1020 | - if ( |
|
1021 | - // is it a method on a class that doesn't work? |
|
1022 | - ( |
|
1023 | - ( |
|
1024 | - method_exists($class, $method) |
|
1025 | - && call_user_func_array([$class, $method], $args) === false |
|
1026 | - ) |
|
1027 | - && ( |
|
1028 | - // is it a standalone function that doesn't work? |
|
1029 | - function_exists($method) |
|
1030 | - && call_user_func_array( |
|
1031 | - $func, |
|
1032 | - array_merge(['admin_page_object' => $this], $args) |
|
1033 | - ) === false |
|
1034 | - ) |
|
1035 | - ) |
|
1036 | - || ( |
|
1037 | - // is it neither a class method NOR a standalone function? |
|
1038 | - ! method_exists($class, $method) |
|
1039 | - && ! function_exists($method) |
|
1040 | - ) |
|
1041 | - ) { |
|
1042 | - // user error msg |
|
1043 | - $error_msg = esc_html__( |
|
1044 | - 'An error occurred. The requested page route could not be found.', |
|
1045 | - 'event_espresso' |
|
1046 | - ); |
|
1047 | - // developer error msg |
|
1048 | - $error_msg .= '||'; |
|
1049 | - $error_msg .= sprintf( |
|
1050 | - esc_html__( |
|
1051 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
1052 | - 'event_espresso' |
|
1053 | - ), |
|
1054 | - $method |
|
1055 | - ); |
|
1056 | - } |
|
1057 | - if (! empty($error_msg)) { |
|
1058 | - throw new EE_Error($error_msg); |
|
1059 | - } |
|
1060 | - } |
|
1061 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
1062 | - // then we need to reset the routing properties to the new route. |
|
1063 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
1064 | - if ( |
|
1065 | - $this->_is_UI_request === false |
|
1066 | - && is_array($this->_route) |
|
1067 | - && ! empty($this->_route['headers_sent_route']) |
|
1068 | - ) { |
|
1069 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
1070 | - } |
|
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * This method just allows the resetting of page properties in the case where a no headers |
|
1076 | - * route redirects to a headers route in its route config. |
|
1077 | - * |
|
1078 | - * @param string $new_route New (non header) route to redirect to. |
|
1079 | - * @return void |
|
1080 | - * @throws ReflectionException |
|
1081 | - * @throws InvalidArgumentException |
|
1082 | - * @throws InvalidInterfaceException |
|
1083 | - * @throws InvalidDataTypeException |
|
1084 | - * @throws EE_Error |
|
1085 | - * @since 4.3.0 |
|
1086 | - */ |
|
1087 | - protected function _reset_routing_properties($new_route) |
|
1088 | - { |
|
1089 | - $this->_is_UI_request = true; |
|
1090 | - // now we set the current route to whatever the headers_sent_route is set at |
|
1091 | - $this->request->setRequestParam('action', $new_route); |
|
1092 | - // rerun page setup |
|
1093 | - $this->_page_setup(); |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * _add_query_arg |
|
1099 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
1100 | - *(internally just uses EEH_URL's function with the same name) |
|
1101 | - * |
|
1102 | - * @param array $args |
|
1103 | - * @param string $url |
|
1104 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
1105 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
1106 | - * Example usage: If the current page is: |
|
1107 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
1108 | - * &action=default&event_id=20&month_range=March%202015 |
|
1109 | - * &_wpnonce=5467821 |
|
1110 | - * and you call: |
|
1111 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
1112 | - * array( |
|
1113 | - * 'action' => 'resend_something', |
|
1114 | - * 'page=>espresso_registrations' |
|
1115 | - * ), |
|
1116 | - * $some_url, |
|
1117 | - * true |
|
1118 | - * ); |
|
1119 | - * It will produce a url in this structure: |
|
1120 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
1121 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
1122 | - * month_range]=March%202015 |
|
1123 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
1124 | - * @return string |
|
1125 | - */ |
|
1126 | - public static function add_query_args_and_nonce( |
|
1127 | - $args = [], |
|
1128 | - $url = false, |
|
1129 | - $sticky = false, |
|
1130 | - $exclude_nonce = false |
|
1131 | - ) { |
|
1132 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
1133 | - if ($sticky) { |
|
1134 | - /** @var RequestInterface $request */ |
|
1135 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1136 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
1137 | - foreach ($request->requestParams() as $key => $value) { |
|
1138 | - // do not add nonces |
|
1139 | - if (strpos($key, 'nonce') !== false) { |
|
1140 | - continue; |
|
1141 | - } |
|
1142 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
1146 | - } |
|
1147 | - |
|
1148 | - |
|
1149 | - /** |
|
1150 | - * This returns a generated link that will load the related help tab. |
|
1151 | - * |
|
1152 | - * @param string $help_tab_id the id for the connected help tab |
|
1153 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
1154 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
1155 | - * @return string generated link |
|
1156 | - * @uses EEH_Template::get_help_tab_link() |
|
1157 | - */ |
|
1158 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
1159 | - { |
|
1160 | - return EEH_Template::get_help_tab_link( |
|
1161 | - $help_tab_id, |
|
1162 | - $this->page_slug, |
|
1163 | - $this->_req_action, |
|
1164 | - $icon_style, |
|
1165 | - $help_text |
|
1166 | - ); |
|
1167 | - } |
|
1168 | - |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * _add_help_tabs |
|
1172 | - * Note child classes define their help tabs within the page_config array. |
|
1173 | - * |
|
1174 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
1175 | - * @return void |
|
1176 | - * @throws DomainException |
|
1177 | - * @throws EE_Error |
|
1178 | - */ |
|
1179 | - protected function _add_help_tabs() |
|
1180 | - { |
|
1181 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
1182 | - $config = $this->_page_config[ $this->_req_action ]; |
|
1183 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
1184 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
1185 | - // check that the callback given is valid |
|
1186 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
1187 | - throw new EE_Error( |
|
1188 | - sprintf( |
|
1189 | - esc_html__( |
|
1190 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
1191 | - 'event_espresso' |
|
1192 | - ), |
|
1193 | - $config['help_sidebar'], |
|
1194 | - get_class($this) |
|
1195 | - ) |
|
1196 | - ); |
|
1197 | - } |
|
1198 | - $content = apply_filters( |
|
1199 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1200 | - $this->{$config['help_sidebar']}() |
|
1201 | - ); |
|
1202 | - $this->_current_screen->set_help_sidebar($content); |
|
1203 | - } |
|
1204 | - if (! isset($config['help_tabs'])) { |
|
1205 | - return; |
|
1206 | - } //no help tabs for this route |
|
1207 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
1208 | - // we're here so there ARE help tabs! |
|
1209 | - // make sure we've got what we need |
|
1210 | - if (! isset($cfg['title'])) { |
|
1211 | - throw new EE_Error( |
|
1212 | - esc_html__( |
|
1213 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
1214 | - 'event_espresso' |
|
1215 | - ) |
|
1216 | - ); |
|
1217 | - } |
|
1218 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1219 | - throw new EE_Error( |
|
1220 | - esc_html__( |
|
1221 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
1222 | - 'event_espresso' |
|
1223 | - ) |
|
1224 | - ); |
|
1225 | - } |
|
1226 | - // first priority goes to content. |
|
1227 | - if (! empty($cfg['content'])) { |
|
1228 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
1229 | - // second priority goes to filename |
|
1230 | - } elseif (! empty($cfg['filename'])) { |
|
1231 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1232 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
1233 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1234 | - . basename($this->_get_dir()) |
|
1235 | - . '/help_tabs/' |
|
1236 | - . $cfg['filename'] |
|
1237 | - . '.help_tab.php' : $file_path; |
|
1238 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1239 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1240 | - EE_Error::add_error( |
|
1241 | - sprintf( |
|
1242 | - esc_html__( |
|
1243 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
1244 | - 'event_espresso' |
|
1245 | - ), |
|
1246 | - $tab_id, |
|
1247 | - key($config), |
|
1248 | - $file_path |
|
1249 | - ), |
|
1250 | - __FILE__, |
|
1251 | - __FUNCTION__, |
|
1252 | - __LINE__ |
|
1253 | - ); |
|
1254 | - return; |
|
1255 | - } |
|
1256 | - $template_args['admin_page_obj'] = $this; |
|
1257 | - $content = EEH_Template::display_template( |
|
1258 | - $file_path, |
|
1259 | - $template_args, |
|
1260 | - true |
|
1261 | - ); |
|
1262 | - } else { |
|
1263 | - $content = ''; |
|
1264 | - } |
|
1265 | - // check if callback is valid |
|
1266 | - if ( |
|
1267 | - empty($content) |
|
1268 | - && ( |
|
1269 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
1270 | - ) |
|
1271 | - ) { |
|
1272 | - EE_Error::add_error( |
|
1273 | - sprintf( |
|
1274 | - esc_html__( |
|
1275 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
1276 | - 'event_espresso' |
|
1277 | - ), |
|
1278 | - $cfg['title'] |
|
1279 | - ), |
|
1280 | - __FILE__, |
|
1281 | - __FUNCTION__, |
|
1282 | - __LINE__ |
|
1283 | - ); |
|
1284 | - return; |
|
1285 | - } |
|
1286 | - // setup config array for help tab method |
|
1287 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1288 | - $_ht = [ |
|
1289 | - 'id' => $id, |
|
1290 | - 'title' => $cfg['title'], |
|
1291 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
1292 | - 'content' => $content, |
|
1293 | - ]; |
|
1294 | - $this->_current_screen->add_help_tab($_ht); |
|
1295 | - } |
|
1296 | - } |
|
1297 | - } |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * This simply sets up any qtips that have been defined in the page config |
|
1302 | - * |
|
1303 | - * @return void |
|
1304 | - */ |
|
1305 | - protected function _add_qtips() |
|
1306 | - { |
|
1307 | - if (isset($this->_route_config['qtips'])) { |
|
1308 | - $qtips = (array) $this->_route_config['qtips']; |
|
1309 | - // load qtip loader |
|
1310 | - $path = [ |
|
1311 | - $this->_get_dir() . '/qtips/', |
|
1312 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1313 | - ]; |
|
1314 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
1315 | - } |
|
1316 | - } |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * _set_nav_tabs |
|
1321 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
1322 | - * wish to add additional tabs or modify accordingly. |
|
1323 | - * |
|
1324 | - * @return void |
|
1325 | - * @throws InvalidArgumentException |
|
1326 | - * @throws InvalidInterfaceException |
|
1327 | - * @throws InvalidDataTypeException |
|
1328 | - */ |
|
1329 | - protected function _set_nav_tabs() |
|
1330 | - { |
|
1331 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1332 | - $i = 0; |
|
1333 | - foreach ($this->_page_config as $slug => $config) { |
|
1334 | - if (! is_array($config) || empty($config['nav'])) { |
|
1335 | - continue; |
|
1336 | - } |
|
1337 | - // no nav tab for this config |
|
1338 | - // check for persistent flag |
|
1339 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
1340 | - // nav tab is only to appear when route requested. |
|
1341 | - continue; |
|
1342 | - } |
|
1343 | - if (! $this->check_user_access($slug, true)) { |
|
1344 | - // no nav tab because current user does not have access. |
|
1345 | - continue; |
|
1346 | - } |
|
1347 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1348 | - $this->_nav_tabs[ $slug ] = [ |
|
1349 | - 'url' => isset($config['nav']['url']) |
|
1350 | - ? $config['nav']['url'] |
|
1351 | - : self::add_query_args_and_nonce( |
|
1352 | - ['action' => $slug], |
|
1353 | - $this->_admin_base_url |
|
1354 | - ), |
|
1355 | - 'link_text' => isset($config['nav']['label']) |
|
1356 | - ? $config['nav']['label'] |
|
1357 | - : ucwords( |
|
1358 | - str_replace('_', ' ', $slug) |
|
1359 | - ), |
|
1360 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1361 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
1362 | - ]; |
|
1363 | - $i++; |
|
1364 | - } |
|
1365 | - // if $this->_nav_tabs is empty then lets set the default |
|
1366 | - if (empty($this->_nav_tabs)) { |
|
1367 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
1368 | - 'url' => $this->_admin_base_url, |
|
1369 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
1370 | - 'css_class' => 'nav-tab-active', |
|
1371 | - 'order' => 10, |
|
1372 | - ]; |
|
1373 | - } |
|
1374 | - // now let's sort the tabs according to order |
|
1375 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * _set_current_labels |
|
1381 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
1382 | - * property array |
|
1383 | - * |
|
1384 | - * @return void |
|
1385 | - */ |
|
1386 | - private function _set_current_labels() |
|
1387 | - { |
|
1388 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
1389 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
1390 | - if (is_array($text)) { |
|
1391 | - foreach ($text as $sublabel => $subtext) { |
|
1392 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1393 | - } |
|
1394 | - } else { |
|
1395 | - $this->_labels[ $label ] = $text; |
|
1396 | - } |
|
1397 | - } |
|
1398 | - } |
|
1399 | - } |
|
1400 | - |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * verifies user access for this admin page |
|
1404 | - * |
|
1405 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
1406 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
1407 | - * return false if verify fail. |
|
1408 | - * @return bool |
|
1409 | - * @throws InvalidArgumentException |
|
1410 | - * @throws InvalidDataTypeException |
|
1411 | - * @throws InvalidInterfaceException |
|
1412 | - */ |
|
1413 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
1414 | - { |
|
1415 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1416 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
1417 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1418 | - && is_array( |
|
1419 | - $this->_page_routes[ $route_to_check ] |
|
1420 | - ) |
|
1421 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1422 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1423 | - if (empty($capability) && empty($route_to_check)) { |
|
1424 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
1425 | - : $this->_route['capability']; |
|
1426 | - } else { |
|
1427 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
1428 | - } |
|
1429 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
1430 | - if ( |
|
1431 | - ! $this->request->isAjax() |
|
1432 | - && ( |
|
1433 | - ! function_exists('is_admin') |
|
1434 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
1435 | - $capability, |
|
1436 | - $this->page_slug |
|
1437 | - . '_' |
|
1438 | - . $route_to_check, |
|
1439 | - $id |
|
1440 | - ) |
|
1441 | - ) |
|
1442 | - ) { |
|
1443 | - if ($verify_only) { |
|
1444 | - return false; |
|
1445 | - } |
|
1446 | - if (is_user_logged_in()) { |
|
1447 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
1448 | - } else { |
|
1449 | - return false; |
|
1450 | - } |
|
1451 | - } |
|
1452 | - return true; |
|
1453 | - } |
|
1454 | - |
|
1455 | - |
|
1456 | - /** |
|
1457 | - * admin_init_global |
|
1458 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
1459 | - * This method executes for ALL EE Admin pages. |
|
1460 | - * |
|
1461 | - * @return void |
|
1462 | - */ |
|
1463 | - public function admin_init_global() |
|
1464 | - { |
|
1465 | - } |
|
1466 | - |
|
1467 | - |
|
1468 | - /** |
|
1469 | - * wp_loaded_global |
|
1470 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
1471 | - * EE_Admin page and will execute on every EE Admin Page load |
|
1472 | - * |
|
1473 | - * @return void |
|
1474 | - */ |
|
1475 | - public function wp_loaded() |
|
1476 | - { |
|
1477 | - } |
|
1478 | - |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * admin_notices |
|
1482 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
1483 | - * ALL EE_Admin pages. |
|
1484 | - * |
|
1485 | - * @return void |
|
1486 | - */ |
|
1487 | - public function admin_notices_global() |
|
1488 | - { |
|
1489 | - $this->_display_no_javascript_warning(); |
|
1490 | - $this->_display_espresso_notices(); |
|
1491 | - } |
|
1492 | - |
|
1493 | - |
|
1494 | - public function network_admin_notices_global() |
|
1495 | - { |
|
1496 | - $this->_display_no_javascript_warning(); |
|
1497 | - $this->_display_espresso_notices(); |
|
1498 | - } |
|
1499 | - |
|
1500 | - |
|
1501 | - /** |
|
1502 | - * admin_footer_scripts_global |
|
1503 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
1504 | - * will apply on ALL EE_Admin pages. |
|
1505 | - * |
|
1506 | - * @return void |
|
1507 | - */ |
|
1508 | - public function admin_footer_scripts_global() |
|
1509 | - { |
|
1510 | - $this->_add_admin_page_ajax_loading_img(); |
|
1511 | - $this->_add_admin_page_overlay(); |
|
1512 | - // if metaboxes are present we need to add the nonce field |
|
1513 | - if ( |
|
1514 | - isset($this->_route_config['metaboxes']) |
|
1515 | - || isset($this->_route_config['list_table']) |
|
1516 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
1517 | - ) { |
|
1518 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
1519 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
1520 | - } |
|
1521 | - } |
|
1522 | - |
|
1523 | - |
|
1524 | - /** |
|
1525 | - * admin_footer_global |
|
1526 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
1527 | - * ALL EE_Admin Pages. |
|
1528 | - * |
|
1529 | - * @return void |
|
1530 | - */ |
|
1531 | - public function admin_footer_global() |
|
1532 | - { |
|
1533 | - // dialog container for dialog helper |
|
1534 | - echo ' |
|
111 | + /** |
|
112 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
113 | + * actions. |
|
114 | + * |
|
115 | + * @since 4.6.x |
|
116 | + * @var array. |
|
117 | + */ |
|
118 | + protected $_default_route_query_args; |
|
119 | + |
|
120 | + // set via request page and action args. |
|
121 | + protected $_current_page; |
|
122 | + |
|
123 | + protected $_current_view; |
|
124 | + |
|
125 | + protected $_current_page_view_url; |
|
126 | + |
|
127 | + /** |
|
128 | + * unprocessed value for the 'action' request param (default '') |
|
129 | + * |
|
130 | + * @var string |
|
131 | + */ |
|
132 | + protected $raw_req_action = ''; |
|
133 | + |
|
134 | + /** |
|
135 | + * unprocessed value for the 'page' request param (default '') |
|
136 | + * |
|
137 | + * @var string |
|
138 | + */ |
|
139 | + protected $raw_req_page = ''; |
|
140 | + |
|
141 | + /** |
|
142 | + * sanitized request action (and nonce) |
|
143 | + * |
|
144 | + * @var string |
|
145 | + */ |
|
146 | + protected $_req_action = ''; |
|
147 | + |
|
148 | + /** |
|
149 | + * sanitized request action nonce |
|
150 | + * |
|
151 | + * @var string |
|
152 | + */ |
|
153 | + protected $_req_nonce = ''; |
|
154 | + |
|
155 | + /** |
|
156 | + * @var string |
|
157 | + */ |
|
158 | + protected $_search_btn_label = ''; |
|
159 | + |
|
160 | + /** |
|
161 | + * @var string |
|
162 | + */ |
|
163 | + protected $_search_box_callback = ''; |
|
164 | + |
|
165 | + /** |
|
166 | + * @var WP_Screen |
|
167 | + */ |
|
168 | + protected $_current_screen; |
|
169 | + |
|
170 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
171 | + protected $_hook_obj; |
|
172 | + |
|
173 | + // for holding incoming request data |
|
174 | + protected $_req_data = []; |
|
175 | + |
|
176 | + // yes / no array for admin form fields |
|
177 | + protected $_yes_no_values = []; |
|
178 | + |
|
179 | + // some default things shared by all child classes |
|
180 | + protected $_default_espresso_metaboxes; |
|
181 | + |
|
182 | + /** |
|
183 | + * @var EE_Registry |
|
184 | + */ |
|
185 | + protected $EE = null; |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
190 | + * |
|
191 | + * @var boolean |
|
192 | + */ |
|
193 | + protected $_is_caf = false; |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @Constructor |
|
198 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
199 | + * @throws EE_Error |
|
200 | + * @throws InvalidArgumentException |
|
201 | + * @throws ReflectionException |
|
202 | + * @throws InvalidDataTypeException |
|
203 | + * @throws InvalidInterfaceException |
|
204 | + */ |
|
205 | + public function __construct($routing = true) |
|
206 | + { |
|
207 | + $this->loader = LoaderFactory::getLoader(); |
|
208 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
209 | + $this->_routing = $routing; |
|
210 | + |
|
211 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
212 | + $this->_is_caf = true; |
|
213 | + } |
|
214 | + $this->_yes_no_values = [ |
|
215 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
216 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
217 | + ]; |
|
218 | + // set the _req_data property. |
|
219 | + $this->_req_data = $this->request->requestParams(); |
|
220 | + // set initial page props (child method) |
|
221 | + $this->_init_page_props(); |
|
222 | + // set global defaults |
|
223 | + $this->_set_defaults(); |
|
224 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
225 | + $this->_global_ajax_hooks(); |
|
226 | + $this->_ajax_hooks(); |
|
227 | + // other_page_hooks have to be early too. |
|
228 | + $this->_do_other_page_hooks(); |
|
229 | + // set up page dependencies |
|
230 | + $this->_before_page_setup(); |
|
231 | + $this->_page_setup(); |
|
232 | + // die(); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * _init_page_props |
|
238 | + * Child classes use to set at least the following properties: |
|
239 | + * $page_slug. |
|
240 | + * $page_label. |
|
241 | + * |
|
242 | + * @abstract |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + abstract protected function _init_page_props(); |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * _ajax_hooks |
|
250 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
251 | + * Note: within the ajax callback methods. |
|
252 | + * |
|
253 | + * @abstract |
|
254 | + * @return void |
|
255 | + */ |
|
256 | + abstract protected function _ajax_hooks(); |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * _define_page_props |
|
261 | + * child classes define page properties in here. Must include at least: |
|
262 | + * $_admin_base_url = base_url for all admin pages |
|
263 | + * $_admin_page_title = default admin_page_title for admin pages |
|
264 | + * $_labels = array of default labels for various automatically generated elements: |
|
265 | + * array( |
|
266 | + * 'buttons' => array( |
|
267 | + * 'add' => esc_html__('label for add new button'), |
|
268 | + * 'edit' => esc_html__('label for edit button'), |
|
269 | + * 'delete' => esc_html__('label for delete button') |
|
270 | + * ) |
|
271 | + * ) |
|
272 | + * |
|
273 | + * @abstract |
|
274 | + * @return void |
|
275 | + */ |
|
276 | + abstract protected function _define_page_props(); |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * _set_page_routes |
|
281 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
282 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
283 | + * have a 'default' route. Here's the format |
|
284 | + * $this->_page_routes = array( |
|
285 | + * 'default' => array( |
|
286 | + * 'func' => '_default_method_handling_route', |
|
287 | + * 'args' => array('array','of','args'), |
|
288 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
289 | + * ajax request, backend processing) |
|
290 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
291 | + * headers route after. The string you enter here should match the defined route reference for a |
|
292 | + * headers sent route. |
|
293 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
294 | + * this route. |
|
295 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
296 | + * checks). |
|
297 | + * ), |
|
298 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
299 | + * handling method. |
|
300 | + * ) |
|
301 | + * ) |
|
302 | + * |
|
303 | + * @abstract |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + abstract protected function _set_page_routes(); |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * _set_page_config |
|
311 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
312 | + * array corresponds to the page_route for the loaded page. Format: |
|
313 | + * $this->_page_config = array( |
|
314 | + * 'default' => array( |
|
315 | + * 'labels' => array( |
|
316 | + * 'buttons' => array( |
|
317 | + * 'add' => esc_html__('label for adding item'), |
|
318 | + * 'edit' => esc_html__('label for editing item'), |
|
319 | + * 'delete' => esc_html__('label for deleting item') |
|
320 | + * ), |
|
321 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
322 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
323 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
324 | + * _define_page_props() method |
|
325 | + * 'nav' => array( |
|
326 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
327 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
328 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
329 | + * 'order' => 10, //required to indicate tab position. |
|
330 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
331 | + * displayed then add this parameter. |
|
332 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
333 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
334 | + * metaboxes set for eventespresso admin pages. |
|
335 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
336 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
337 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
338 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
339 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
340 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
341 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
342 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
343 | + * want to display. |
|
344 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
345 | + * 'tab_id' => array( |
|
346 | + * 'title' => 'tab_title', |
|
347 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
348 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
349 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
350 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
351 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
352 | + * attempt to use the callback which should match the name of a method in the class |
|
353 | + * ), |
|
354 | + * 'tab2_id' => array( |
|
355 | + * 'title' => 'tab2 title', |
|
356 | + * 'filename' => 'file_name_2' |
|
357 | + * 'callback' => 'callback_method_for_content', |
|
358 | + * ), |
|
359 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
360 | + * help tab area on an admin page. @return void |
|
361 | + * |
|
362 | + * @abstract |
|
363 | + */ |
|
364 | + abstract protected function _set_page_config(); |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * _add_screen_options |
|
369 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
370 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
371 | + * to a particular view. |
|
372 | + * |
|
373 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
374 | + * see also WP_Screen object documents... |
|
375 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
376 | + * @abstract |
|
377 | + * @return void |
|
378 | + */ |
|
379 | + abstract protected function _add_screen_options(); |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _add_feature_pointers |
|
384 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
385 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
386 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
387 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
388 | + * extended) also see: |
|
389 | + * |
|
390 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
391 | + * @abstract |
|
392 | + * @return void |
|
393 | + */ |
|
394 | + abstract protected function _add_feature_pointers(); |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * load_scripts_styles |
|
399 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
400 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
401 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
402 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
403 | + * |
|
404 | + * @abstract |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + abstract public function load_scripts_styles(); |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * admin_init |
|
412 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
413 | + * all pages/views loaded by child class. |
|
414 | + * |
|
415 | + * @abstract |
|
416 | + * @return void |
|
417 | + */ |
|
418 | + abstract public function admin_init(); |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * admin_notices |
|
423 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
424 | + * all pages/views loaded by child class. |
|
425 | + * |
|
426 | + * @abstract |
|
427 | + * @return void |
|
428 | + */ |
|
429 | + abstract public function admin_notices(); |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * admin_footer_scripts |
|
434 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
435 | + * will apply to all pages/views loaded by child class. |
|
436 | + * |
|
437 | + * @return void |
|
438 | + */ |
|
439 | + abstract public function admin_footer_scripts(); |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * admin_footer |
|
444 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
445 | + * apply to all pages/views loaded by child class. |
|
446 | + * |
|
447 | + * @return void |
|
448 | + */ |
|
449 | + public function admin_footer() |
|
450 | + { |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * _global_ajax_hooks |
|
456 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
457 | + * Note: within the ajax callback methods. |
|
458 | + * |
|
459 | + * @abstract |
|
460 | + * @return void |
|
461 | + */ |
|
462 | + protected function _global_ajax_hooks() |
|
463 | + { |
|
464 | + // for lazy loading of metabox content |
|
465 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + public function ajax_metabox_content() |
|
470 | + { |
|
471 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
472 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
473 | + self::cached_rss_display($content_id, $content_url); |
|
474 | + wp_die(); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
480 | + * |
|
481 | + * @return void |
|
482 | + */ |
|
483 | + protected function _before_page_setup() |
|
484 | + { |
|
485 | + // default is to do nothing |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Makes sure any things that need to be loaded early get handled. |
|
491 | + * We also escape early here if the page requested doesn't match the object. |
|
492 | + * |
|
493 | + * @final |
|
494 | + * @return void |
|
495 | + * @throws EE_Error |
|
496 | + * @throws InvalidArgumentException |
|
497 | + * @throws ReflectionException |
|
498 | + * @throws InvalidDataTypeException |
|
499 | + * @throws InvalidInterfaceException |
|
500 | + */ |
|
501 | + final protected function _page_setup() |
|
502 | + { |
|
503 | + // requires? |
|
504 | + // admin_init stuff - global - we're setting this REALLY early |
|
505 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
506 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
507 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
508 | + // next verify if we need to load anything... |
|
509 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
510 | + $this->page_folder = strtolower( |
|
511 | + str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
512 | + ); |
|
513 | + global $ee_menu_slugs; |
|
514 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
515 | + if ( |
|
516 | + ! $this->request->isAjax() |
|
517 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
518 | + ) { |
|
519 | + return; |
|
520 | + } |
|
521 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
522 | + // we need to copy the action from the second to the first |
|
523 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
524 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
525 | + $action = $action !== '-1' ? $action : $action2; |
|
526 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
527 | + |
|
528 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
529 | + // then let's use the route as the action. |
|
530 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
531 | + $route = $this->request->getRequestParam('route'); |
|
532 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
533 | + ? $route |
|
534 | + : $req_action; |
|
535 | + |
|
536 | + $this->_current_view = $this->_req_action; |
|
537 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
538 | + $this->_define_page_props(); |
|
539 | + $this->_current_page_view_url = add_query_arg( |
|
540 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
541 | + $this->_admin_base_url |
|
542 | + ); |
|
543 | + // default things |
|
544 | + $this->_default_espresso_metaboxes = [ |
|
545 | + '_espresso_news_post_box', |
|
546 | + '_espresso_links_post_box', |
|
547 | + '_espresso_ratings_request', |
|
548 | + '_espresso_sponsors_post_box', |
|
549 | + ]; |
|
550 | + // set page configs |
|
551 | + $this->_set_page_routes(); |
|
552 | + $this->_set_page_config(); |
|
553 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
554 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
555 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
556 | + if ($wp_referer) { |
|
557 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
558 | + } |
|
559 | + } |
|
560 | + // for caffeinated and other extended functionality. |
|
561 | + // If there is a _extend_page_config method |
|
562 | + // then let's run that to modify the all the various page configuration arrays |
|
563 | + if (method_exists($this, '_extend_page_config')) { |
|
564 | + $this->_extend_page_config(); |
|
565 | + } |
|
566 | + // for CPT and other extended functionality. |
|
567 | + // If there is an _extend_page_config_for_cpt |
|
568 | + // then let's run that to modify all the various page configuration arrays. |
|
569 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
570 | + $this->_extend_page_config_for_cpt(); |
|
571 | + } |
|
572 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
573 | + $this->_page_routes = apply_filters( |
|
574 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
575 | + $this->_page_routes, |
|
576 | + $this |
|
577 | + ); |
|
578 | + $this->_page_config = apply_filters( |
|
579 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
580 | + $this->_page_config, |
|
581 | + $this |
|
582 | + ); |
|
583 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
584 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
586 | + add_action( |
|
587 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
589 | + 10, |
|
590 | + 2 |
|
591 | + ); |
|
592 | + } |
|
593 | + // next route only if routing enabled |
|
594 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
595 | + $this->_verify_routes(); |
|
596 | + // next let's just check user_access and kill if no access |
|
597 | + $this->check_user_access(); |
|
598 | + if ($this->_is_UI_request) { |
|
599 | + // admin_init stuff - global, all views for this page class, specific view |
|
600 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
601 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
602 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
603 | + } |
|
604 | + } else { |
|
605 | + // hijack regular WP loading and route admin request immediately |
|
606 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
607 | + $this->route_admin_request(); |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
615 | + * |
|
616 | + * @return void |
|
617 | + * @throws EE_Error |
|
618 | + */ |
|
619 | + private function _do_other_page_hooks() |
|
620 | + { |
|
621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
622 | + foreach ($registered_pages as $page) { |
|
623 | + // now let's setup the file name and class that should be present |
|
624 | + $classname = str_replace('.class.php', '', $page); |
|
625 | + // autoloaders should take care of loading file |
|
626 | + if (! class_exists($classname)) { |
|
627 | + $error_msg[] = sprintf( |
|
628 | + esc_html__( |
|
629 | + 'Something went wrong with loading the %s admin hooks page.', |
|
630 | + 'event_espresso' |
|
631 | + ), |
|
632 | + $page |
|
633 | + ); |
|
634 | + $error_msg[] = $error_msg[0] |
|
635 | + . "\r\n" |
|
636 | + . sprintf( |
|
637 | + esc_html__( |
|
638 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
639 | + 'event_espresso' |
|
640 | + ), |
|
641 | + $page, |
|
642 | + '<br />', |
|
643 | + '<strong>' . $classname . '</strong>' |
|
644 | + ); |
|
645 | + throw new EE_Error(implode('||', $error_msg)); |
|
646 | + } |
|
647 | + // notice we are passing the instance of this class to the hook object. |
|
648 | + $this->loader->getShared($classname, [$this]); |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * @throws ReflectionException |
|
655 | + * @throws EE_Error |
|
656 | + */ |
|
657 | + public function load_page_dependencies() |
|
658 | + { |
|
659 | + try { |
|
660 | + $this->_load_page_dependencies(); |
|
661 | + } catch (EE_Error $e) { |
|
662 | + $e->get_error(); |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * load_page_dependencies |
|
669 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
670 | + * |
|
671 | + * @return void |
|
672 | + * @throws DomainException |
|
673 | + * @throws EE_Error |
|
674 | + * @throws InvalidArgumentException |
|
675 | + * @throws InvalidDataTypeException |
|
676 | + * @throws InvalidInterfaceException |
|
677 | + */ |
|
678 | + protected function _load_page_dependencies() |
|
679 | + { |
|
680 | + // let's set the current_screen and screen options to override what WP set |
|
681 | + $this->_current_screen = get_current_screen(); |
|
682 | + // load admin_notices - global, page class, and view specific |
|
683 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
684 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
685 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
686 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
687 | + } |
|
688 | + // load network admin_notices - global, page class, and view specific |
|
689 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
690 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
692 | + } |
|
693 | + // this will save any per_page screen options if they are present |
|
694 | + $this->_set_per_page_screen_options(); |
|
695 | + // setup list table properties |
|
696 | + $this->_set_list_table(); |
|
697 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
698 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
699 | + $this->_add_registered_meta_boxes(); |
|
700 | + $this->_add_screen_columns(); |
|
701 | + // add screen options - global, page child class, and view specific |
|
702 | + $this->_add_global_screen_options(); |
|
703 | + $this->_add_screen_options(); |
|
704 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
705 | + if (method_exists($this, $add_screen_options)) { |
|
706 | + $this->{$add_screen_options}(); |
|
707 | + } |
|
708 | + // add help tab(s) - set via page_config and qtips. |
|
709 | + $this->_add_help_tabs(); |
|
710 | + $this->_add_qtips(); |
|
711 | + // add feature_pointers - global, page child class, and view specific |
|
712 | + $this->_add_feature_pointers(); |
|
713 | + $this->_add_global_feature_pointers(); |
|
714 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
715 | + if (method_exists($this, $add_feature_pointer)) { |
|
716 | + $this->{$add_feature_pointer}(); |
|
717 | + } |
|
718 | + // enqueue scripts/styles - global, page class, and view specific |
|
719 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
720 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
721 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
722 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
723 | + } |
|
724 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
725 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
726 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
727 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
728 | + // is a good use case. Notice the late priority we're giving these |
|
729 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
730 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
731 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
732 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
733 | + } |
|
734 | + // admin footer scripts |
|
735 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
736 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
737 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
738 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
739 | + } |
|
740 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
741 | + // targeted hook |
|
742 | + do_action( |
|
743 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
744 | + ); |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * _set_defaults |
|
750 | + * This sets some global defaults for class properties. |
|
751 | + */ |
|
752 | + private function _set_defaults() |
|
753 | + { |
|
754 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
755 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
756 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
757 | + $this->_page_config = $this->_default_route_query_args = []; |
|
758 | + $this->_default_nav_tab_name = 'overview'; |
|
759 | + // init template args |
|
760 | + $this->_template_args = [ |
|
761 | + 'admin_page_header' => '', |
|
762 | + 'admin_page_content' => '', |
|
763 | + 'post_body_content' => '', |
|
764 | + 'before_list_table' => '', |
|
765 | + 'after_list_table' => '', |
|
766 | + ]; |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * route_admin_request |
|
772 | + * |
|
773 | + * @return void |
|
774 | + * @throws InvalidArgumentException |
|
775 | + * @throws InvalidInterfaceException |
|
776 | + * @throws InvalidDataTypeException |
|
777 | + * @throws EE_Error |
|
778 | + * @throws ReflectionException |
|
779 | + * @see _route_admin_request() |
|
780 | + */ |
|
781 | + public function route_admin_request() |
|
782 | + { |
|
783 | + try { |
|
784 | + $this->_route_admin_request(); |
|
785 | + } catch (EE_Error $e) { |
|
786 | + $e->get_error(); |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + public function set_wp_page_slug($wp_page_slug) |
|
792 | + { |
|
793 | + $this->_wp_page_slug = $wp_page_slug; |
|
794 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
795 | + if (is_network_admin()) { |
|
796 | + $this->_wp_page_slug .= '-network'; |
|
797 | + } |
|
798 | + } |
|
799 | + |
|
800 | + |
|
801 | + /** |
|
802 | + * _verify_routes |
|
803 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
804 | + * we know if we need to drop out. |
|
805 | + * |
|
806 | + * @return bool |
|
807 | + * @throws EE_Error |
|
808 | + */ |
|
809 | + protected function _verify_routes() |
|
810 | + { |
|
811 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
812 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
813 | + return false; |
|
814 | + } |
|
815 | + $this->_route = false; |
|
816 | + // check that the page_routes array is not empty |
|
817 | + if (empty($this->_page_routes)) { |
|
818 | + // user error msg |
|
819 | + $error_msg = sprintf( |
|
820 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
821 | + $this->_admin_page_title |
|
822 | + ); |
|
823 | + // developer error msg |
|
824 | + $error_msg .= '||' . $error_msg |
|
825 | + . esc_html__( |
|
826 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
827 | + 'event_espresso' |
|
828 | + ); |
|
829 | + throw new EE_Error($error_msg); |
|
830 | + } |
|
831 | + // and that the requested page route exists |
|
832 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
833 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
834 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
835 | + ? $this->_page_config[ $this->_req_action ] |
|
836 | + : []; |
|
837 | + } else { |
|
838 | + // user error msg |
|
839 | + $error_msg = sprintf( |
|
840 | + esc_html__( |
|
841 | + 'The requested page route does not exist for the %s admin page.', |
|
842 | + 'event_espresso' |
|
843 | + ), |
|
844 | + $this->_admin_page_title |
|
845 | + ); |
|
846 | + // developer error msg |
|
847 | + $error_msg .= '||' . $error_msg |
|
848 | + . sprintf( |
|
849 | + esc_html__( |
|
850 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
851 | + 'event_espresso' |
|
852 | + ), |
|
853 | + $this->_req_action |
|
854 | + ); |
|
855 | + throw new EE_Error($error_msg); |
|
856 | + } |
|
857 | + // and that a default route exists |
|
858 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
859 | + // user error msg |
|
860 | + $error_msg = sprintf( |
|
861 | + esc_html__( |
|
862 | + 'A default page route has not been set for the % admin page.', |
|
863 | + 'event_espresso' |
|
864 | + ), |
|
865 | + $this->_admin_page_title |
|
866 | + ); |
|
867 | + // developer error msg |
|
868 | + $error_msg .= '||' . $error_msg |
|
869 | + . esc_html__( |
|
870 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
871 | + 'event_espresso' |
|
872 | + ); |
|
873 | + throw new EE_Error($error_msg); |
|
874 | + } |
|
875 | + // first lets' catch if the UI request has EVER been set. |
|
876 | + if ($this->_is_UI_request === null) { |
|
877 | + // lets set if this is a UI request or not. |
|
878 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
879 | + // wait a minute... we might have a noheader in the route array |
|
880 | + $this->_is_UI_request = ! ( |
|
881 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
882 | + ) |
|
883 | + ? $this->_is_UI_request |
|
884 | + : false; |
|
885 | + } |
|
886 | + $this->_set_current_labels(); |
|
887 | + return true; |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
893 | + * |
|
894 | + * @param string $route the route name we're verifying |
|
895 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
896 | + * @throws EE_Error |
|
897 | + */ |
|
898 | + protected function _verify_route($route) |
|
899 | + { |
|
900 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
901 | + return true; |
|
902 | + } |
|
903 | + // user error msg |
|
904 | + $error_msg = sprintf( |
|
905 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
906 | + $this->_admin_page_title |
|
907 | + ); |
|
908 | + // developer error msg |
|
909 | + $error_msg .= '||' . $error_msg |
|
910 | + . sprintf( |
|
911 | + esc_html__( |
|
912 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
913 | + 'event_espresso' |
|
914 | + ), |
|
915 | + $route |
|
916 | + ); |
|
917 | + throw new EE_Error($error_msg); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * perform nonce verification |
|
923 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
924 | + * using this method (and save retyping!) |
|
925 | + * |
|
926 | + * @param string $nonce The nonce sent |
|
927 | + * @param string $nonce_ref The nonce reference string (name0) |
|
928 | + * @return void |
|
929 | + * @throws EE_Error |
|
930 | + */ |
|
931 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
932 | + { |
|
933 | + // verify nonce against expected value |
|
934 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
935 | + // these are not the droids you are looking for !!! |
|
936 | + $msg = sprintf( |
|
937 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
938 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
939 | + '</a>' |
|
940 | + ); |
|
941 | + if (WP_DEBUG) { |
|
942 | + $msg .= "\n "; |
|
943 | + $msg .= sprintf( |
|
944 | + esc_html__( |
|
945 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
946 | + 'event_espresso' |
|
947 | + ), |
|
948 | + __CLASS__ |
|
949 | + ); |
|
950 | + } |
|
951 | + if (! $this->request->isAjax()) { |
|
952 | + wp_die($msg); |
|
953 | + } |
|
954 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
955 | + $this->_return_json(); |
|
956 | + } |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + /** |
|
961 | + * _route_admin_request() |
|
962 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
963 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
964 | + * in the page routes and then will try to load the corresponding method. |
|
965 | + * |
|
966 | + * @return void |
|
967 | + * @throws EE_Error |
|
968 | + * @throws InvalidArgumentException |
|
969 | + * @throws InvalidDataTypeException |
|
970 | + * @throws InvalidInterfaceException |
|
971 | + * @throws ReflectionException |
|
972 | + */ |
|
973 | + protected function _route_admin_request() |
|
974 | + { |
|
975 | + if (! $this->_is_UI_request) { |
|
976 | + $this->_verify_routes(); |
|
977 | + } |
|
978 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
979 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
980 | + // set nonce from post data |
|
981 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
982 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
983 | + } |
|
984 | + // set the nav_tabs array but ONLY if this is UI_request |
|
985 | + if ($this->_is_UI_request) { |
|
986 | + $this->_set_nav_tabs(); |
|
987 | + } |
|
988 | + // grab callback function |
|
989 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
990 | + // check if callback has args |
|
991 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
992 | + $error_msg = ''; |
|
993 | + // action right before calling route |
|
994 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
995 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
996 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
997 | + } |
|
998 | + // right before calling the route, let's clean the _wp_http_referer |
|
999 | + $this->request->unSetRequestParam('_wp_http_referer'); |
|
1000 | + $this->request->unSetServerParam('_wp_http_referer'); |
|
1001 | + $cleaner_request_uri = remove_query_arg( |
|
1002 | + '_wp_http_referer', |
|
1003 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
1004 | + ); |
|
1005 | + $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri); |
|
1006 | + $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri); |
|
1007 | + if (! empty($func)) { |
|
1008 | + if (is_array($func)) { |
|
1009 | + [$class, $method] = $func; |
|
1010 | + } elseif (strpos($func, '::') !== false) { |
|
1011 | + [$class, $method] = explode('::', $func); |
|
1012 | + } else { |
|
1013 | + $class = $this; |
|
1014 | + $method = $func; |
|
1015 | + } |
|
1016 | + if (! (is_object($class) && $class === $this)) { |
|
1017 | + // send along this admin page object for access by addons. |
|
1018 | + $args['admin_page_object'] = $this; |
|
1019 | + } |
|
1020 | + if ( |
|
1021 | + // is it a method on a class that doesn't work? |
|
1022 | + ( |
|
1023 | + ( |
|
1024 | + method_exists($class, $method) |
|
1025 | + && call_user_func_array([$class, $method], $args) === false |
|
1026 | + ) |
|
1027 | + && ( |
|
1028 | + // is it a standalone function that doesn't work? |
|
1029 | + function_exists($method) |
|
1030 | + && call_user_func_array( |
|
1031 | + $func, |
|
1032 | + array_merge(['admin_page_object' => $this], $args) |
|
1033 | + ) === false |
|
1034 | + ) |
|
1035 | + ) |
|
1036 | + || ( |
|
1037 | + // is it neither a class method NOR a standalone function? |
|
1038 | + ! method_exists($class, $method) |
|
1039 | + && ! function_exists($method) |
|
1040 | + ) |
|
1041 | + ) { |
|
1042 | + // user error msg |
|
1043 | + $error_msg = esc_html__( |
|
1044 | + 'An error occurred. The requested page route could not be found.', |
|
1045 | + 'event_espresso' |
|
1046 | + ); |
|
1047 | + // developer error msg |
|
1048 | + $error_msg .= '||'; |
|
1049 | + $error_msg .= sprintf( |
|
1050 | + esc_html__( |
|
1051 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
1052 | + 'event_espresso' |
|
1053 | + ), |
|
1054 | + $method |
|
1055 | + ); |
|
1056 | + } |
|
1057 | + if (! empty($error_msg)) { |
|
1058 | + throw new EE_Error($error_msg); |
|
1059 | + } |
|
1060 | + } |
|
1061 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
1062 | + // then we need to reset the routing properties to the new route. |
|
1063 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
1064 | + if ( |
|
1065 | + $this->_is_UI_request === false |
|
1066 | + && is_array($this->_route) |
|
1067 | + && ! empty($this->_route['headers_sent_route']) |
|
1068 | + ) { |
|
1069 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
1070 | + } |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * This method just allows the resetting of page properties in the case where a no headers |
|
1076 | + * route redirects to a headers route in its route config. |
|
1077 | + * |
|
1078 | + * @param string $new_route New (non header) route to redirect to. |
|
1079 | + * @return void |
|
1080 | + * @throws ReflectionException |
|
1081 | + * @throws InvalidArgumentException |
|
1082 | + * @throws InvalidInterfaceException |
|
1083 | + * @throws InvalidDataTypeException |
|
1084 | + * @throws EE_Error |
|
1085 | + * @since 4.3.0 |
|
1086 | + */ |
|
1087 | + protected function _reset_routing_properties($new_route) |
|
1088 | + { |
|
1089 | + $this->_is_UI_request = true; |
|
1090 | + // now we set the current route to whatever the headers_sent_route is set at |
|
1091 | + $this->request->setRequestParam('action', $new_route); |
|
1092 | + // rerun page setup |
|
1093 | + $this->_page_setup(); |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * _add_query_arg |
|
1099 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
1100 | + *(internally just uses EEH_URL's function with the same name) |
|
1101 | + * |
|
1102 | + * @param array $args |
|
1103 | + * @param string $url |
|
1104 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
1105 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
1106 | + * Example usage: If the current page is: |
|
1107 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
1108 | + * &action=default&event_id=20&month_range=March%202015 |
|
1109 | + * &_wpnonce=5467821 |
|
1110 | + * and you call: |
|
1111 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
1112 | + * array( |
|
1113 | + * 'action' => 'resend_something', |
|
1114 | + * 'page=>espresso_registrations' |
|
1115 | + * ), |
|
1116 | + * $some_url, |
|
1117 | + * true |
|
1118 | + * ); |
|
1119 | + * It will produce a url in this structure: |
|
1120 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
1121 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
1122 | + * month_range]=March%202015 |
|
1123 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
1124 | + * @return string |
|
1125 | + */ |
|
1126 | + public static function add_query_args_and_nonce( |
|
1127 | + $args = [], |
|
1128 | + $url = false, |
|
1129 | + $sticky = false, |
|
1130 | + $exclude_nonce = false |
|
1131 | + ) { |
|
1132 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
1133 | + if ($sticky) { |
|
1134 | + /** @var RequestInterface $request */ |
|
1135 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1136 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
1137 | + foreach ($request->requestParams() as $key => $value) { |
|
1138 | + // do not add nonces |
|
1139 | + if (strpos($key, 'nonce') !== false) { |
|
1140 | + continue; |
|
1141 | + } |
|
1142 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
1146 | + } |
|
1147 | + |
|
1148 | + |
|
1149 | + /** |
|
1150 | + * This returns a generated link that will load the related help tab. |
|
1151 | + * |
|
1152 | + * @param string $help_tab_id the id for the connected help tab |
|
1153 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
1154 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
1155 | + * @return string generated link |
|
1156 | + * @uses EEH_Template::get_help_tab_link() |
|
1157 | + */ |
|
1158 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
1159 | + { |
|
1160 | + return EEH_Template::get_help_tab_link( |
|
1161 | + $help_tab_id, |
|
1162 | + $this->page_slug, |
|
1163 | + $this->_req_action, |
|
1164 | + $icon_style, |
|
1165 | + $help_text |
|
1166 | + ); |
|
1167 | + } |
|
1168 | + |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * _add_help_tabs |
|
1172 | + * Note child classes define their help tabs within the page_config array. |
|
1173 | + * |
|
1174 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
1175 | + * @return void |
|
1176 | + * @throws DomainException |
|
1177 | + * @throws EE_Error |
|
1178 | + */ |
|
1179 | + protected function _add_help_tabs() |
|
1180 | + { |
|
1181 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
1182 | + $config = $this->_page_config[ $this->_req_action ]; |
|
1183 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
1184 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
1185 | + // check that the callback given is valid |
|
1186 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
1187 | + throw new EE_Error( |
|
1188 | + sprintf( |
|
1189 | + esc_html__( |
|
1190 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
1191 | + 'event_espresso' |
|
1192 | + ), |
|
1193 | + $config['help_sidebar'], |
|
1194 | + get_class($this) |
|
1195 | + ) |
|
1196 | + ); |
|
1197 | + } |
|
1198 | + $content = apply_filters( |
|
1199 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1200 | + $this->{$config['help_sidebar']}() |
|
1201 | + ); |
|
1202 | + $this->_current_screen->set_help_sidebar($content); |
|
1203 | + } |
|
1204 | + if (! isset($config['help_tabs'])) { |
|
1205 | + return; |
|
1206 | + } //no help tabs for this route |
|
1207 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
1208 | + // we're here so there ARE help tabs! |
|
1209 | + // make sure we've got what we need |
|
1210 | + if (! isset($cfg['title'])) { |
|
1211 | + throw new EE_Error( |
|
1212 | + esc_html__( |
|
1213 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
1214 | + 'event_espresso' |
|
1215 | + ) |
|
1216 | + ); |
|
1217 | + } |
|
1218 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1219 | + throw new EE_Error( |
|
1220 | + esc_html__( |
|
1221 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
1222 | + 'event_espresso' |
|
1223 | + ) |
|
1224 | + ); |
|
1225 | + } |
|
1226 | + // first priority goes to content. |
|
1227 | + if (! empty($cfg['content'])) { |
|
1228 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
1229 | + // second priority goes to filename |
|
1230 | + } elseif (! empty($cfg['filename'])) { |
|
1231 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1232 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
1233 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1234 | + . basename($this->_get_dir()) |
|
1235 | + . '/help_tabs/' |
|
1236 | + . $cfg['filename'] |
|
1237 | + . '.help_tab.php' : $file_path; |
|
1238 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1239 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1240 | + EE_Error::add_error( |
|
1241 | + sprintf( |
|
1242 | + esc_html__( |
|
1243 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
1244 | + 'event_espresso' |
|
1245 | + ), |
|
1246 | + $tab_id, |
|
1247 | + key($config), |
|
1248 | + $file_path |
|
1249 | + ), |
|
1250 | + __FILE__, |
|
1251 | + __FUNCTION__, |
|
1252 | + __LINE__ |
|
1253 | + ); |
|
1254 | + return; |
|
1255 | + } |
|
1256 | + $template_args['admin_page_obj'] = $this; |
|
1257 | + $content = EEH_Template::display_template( |
|
1258 | + $file_path, |
|
1259 | + $template_args, |
|
1260 | + true |
|
1261 | + ); |
|
1262 | + } else { |
|
1263 | + $content = ''; |
|
1264 | + } |
|
1265 | + // check if callback is valid |
|
1266 | + if ( |
|
1267 | + empty($content) |
|
1268 | + && ( |
|
1269 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
1270 | + ) |
|
1271 | + ) { |
|
1272 | + EE_Error::add_error( |
|
1273 | + sprintf( |
|
1274 | + esc_html__( |
|
1275 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
1276 | + 'event_espresso' |
|
1277 | + ), |
|
1278 | + $cfg['title'] |
|
1279 | + ), |
|
1280 | + __FILE__, |
|
1281 | + __FUNCTION__, |
|
1282 | + __LINE__ |
|
1283 | + ); |
|
1284 | + return; |
|
1285 | + } |
|
1286 | + // setup config array for help tab method |
|
1287 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1288 | + $_ht = [ |
|
1289 | + 'id' => $id, |
|
1290 | + 'title' => $cfg['title'], |
|
1291 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
1292 | + 'content' => $content, |
|
1293 | + ]; |
|
1294 | + $this->_current_screen->add_help_tab($_ht); |
|
1295 | + } |
|
1296 | + } |
|
1297 | + } |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * This simply sets up any qtips that have been defined in the page config |
|
1302 | + * |
|
1303 | + * @return void |
|
1304 | + */ |
|
1305 | + protected function _add_qtips() |
|
1306 | + { |
|
1307 | + if (isset($this->_route_config['qtips'])) { |
|
1308 | + $qtips = (array) $this->_route_config['qtips']; |
|
1309 | + // load qtip loader |
|
1310 | + $path = [ |
|
1311 | + $this->_get_dir() . '/qtips/', |
|
1312 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1313 | + ]; |
|
1314 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
1315 | + } |
|
1316 | + } |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * _set_nav_tabs |
|
1321 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
1322 | + * wish to add additional tabs or modify accordingly. |
|
1323 | + * |
|
1324 | + * @return void |
|
1325 | + * @throws InvalidArgumentException |
|
1326 | + * @throws InvalidInterfaceException |
|
1327 | + * @throws InvalidDataTypeException |
|
1328 | + */ |
|
1329 | + protected function _set_nav_tabs() |
|
1330 | + { |
|
1331 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1332 | + $i = 0; |
|
1333 | + foreach ($this->_page_config as $slug => $config) { |
|
1334 | + if (! is_array($config) || empty($config['nav'])) { |
|
1335 | + continue; |
|
1336 | + } |
|
1337 | + // no nav tab for this config |
|
1338 | + // check for persistent flag |
|
1339 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
1340 | + // nav tab is only to appear when route requested. |
|
1341 | + continue; |
|
1342 | + } |
|
1343 | + if (! $this->check_user_access($slug, true)) { |
|
1344 | + // no nav tab because current user does not have access. |
|
1345 | + continue; |
|
1346 | + } |
|
1347 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1348 | + $this->_nav_tabs[ $slug ] = [ |
|
1349 | + 'url' => isset($config['nav']['url']) |
|
1350 | + ? $config['nav']['url'] |
|
1351 | + : self::add_query_args_and_nonce( |
|
1352 | + ['action' => $slug], |
|
1353 | + $this->_admin_base_url |
|
1354 | + ), |
|
1355 | + 'link_text' => isset($config['nav']['label']) |
|
1356 | + ? $config['nav']['label'] |
|
1357 | + : ucwords( |
|
1358 | + str_replace('_', ' ', $slug) |
|
1359 | + ), |
|
1360 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1361 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
1362 | + ]; |
|
1363 | + $i++; |
|
1364 | + } |
|
1365 | + // if $this->_nav_tabs is empty then lets set the default |
|
1366 | + if (empty($this->_nav_tabs)) { |
|
1367 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
1368 | + 'url' => $this->_admin_base_url, |
|
1369 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
1370 | + 'css_class' => 'nav-tab-active', |
|
1371 | + 'order' => 10, |
|
1372 | + ]; |
|
1373 | + } |
|
1374 | + // now let's sort the tabs according to order |
|
1375 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * _set_current_labels |
|
1381 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
1382 | + * property array |
|
1383 | + * |
|
1384 | + * @return void |
|
1385 | + */ |
|
1386 | + private function _set_current_labels() |
|
1387 | + { |
|
1388 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
1389 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
1390 | + if (is_array($text)) { |
|
1391 | + foreach ($text as $sublabel => $subtext) { |
|
1392 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1393 | + } |
|
1394 | + } else { |
|
1395 | + $this->_labels[ $label ] = $text; |
|
1396 | + } |
|
1397 | + } |
|
1398 | + } |
|
1399 | + } |
|
1400 | + |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * verifies user access for this admin page |
|
1404 | + * |
|
1405 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
1406 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
1407 | + * return false if verify fail. |
|
1408 | + * @return bool |
|
1409 | + * @throws InvalidArgumentException |
|
1410 | + * @throws InvalidDataTypeException |
|
1411 | + * @throws InvalidInterfaceException |
|
1412 | + */ |
|
1413 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
1414 | + { |
|
1415 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1416 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
1417 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1418 | + && is_array( |
|
1419 | + $this->_page_routes[ $route_to_check ] |
|
1420 | + ) |
|
1421 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1422 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1423 | + if (empty($capability) && empty($route_to_check)) { |
|
1424 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
1425 | + : $this->_route['capability']; |
|
1426 | + } else { |
|
1427 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
1428 | + } |
|
1429 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
1430 | + if ( |
|
1431 | + ! $this->request->isAjax() |
|
1432 | + && ( |
|
1433 | + ! function_exists('is_admin') |
|
1434 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
1435 | + $capability, |
|
1436 | + $this->page_slug |
|
1437 | + . '_' |
|
1438 | + . $route_to_check, |
|
1439 | + $id |
|
1440 | + ) |
|
1441 | + ) |
|
1442 | + ) { |
|
1443 | + if ($verify_only) { |
|
1444 | + return false; |
|
1445 | + } |
|
1446 | + if (is_user_logged_in()) { |
|
1447 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
1448 | + } else { |
|
1449 | + return false; |
|
1450 | + } |
|
1451 | + } |
|
1452 | + return true; |
|
1453 | + } |
|
1454 | + |
|
1455 | + |
|
1456 | + /** |
|
1457 | + * admin_init_global |
|
1458 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
1459 | + * This method executes for ALL EE Admin pages. |
|
1460 | + * |
|
1461 | + * @return void |
|
1462 | + */ |
|
1463 | + public function admin_init_global() |
|
1464 | + { |
|
1465 | + } |
|
1466 | + |
|
1467 | + |
|
1468 | + /** |
|
1469 | + * wp_loaded_global |
|
1470 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
1471 | + * EE_Admin page and will execute on every EE Admin Page load |
|
1472 | + * |
|
1473 | + * @return void |
|
1474 | + */ |
|
1475 | + public function wp_loaded() |
|
1476 | + { |
|
1477 | + } |
|
1478 | + |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * admin_notices |
|
1482 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
1483 | + * ALL EE_Admin pages. |
|
1484 | + * |
|
1485 | + * @return void |
|
1486 | + */ |
|
1487 | + public function admin_notices_global() |
|
1488 | + { |
|
1489 | + $this->_display_no_javascript_warning(); |
|
1490 | + $this->_display_espresso_notices(); |
|
1491 | + } |
|
1492 | + |
|
1493 | + |
|
1494 | + public function network_admin_notices_global() |
|
1495 | + { |
|
1496 | + $this->_display_no_javascript_warning(); |
|
1497 | + $this->_display_espresso_notices(); |
|
1498 | + } |
|
1499 | + |
|
1500 | + |
|
1501 | + /** |
|
1502 | + * admin_footer_scripts_global |
|
1503 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
1504 | + * will apply on ALL EE_Admin pages. |
|
1505 | + * |
|
1506 | + * @return void |
|
1507 | + */ |
|
1508 | + public function admin_footer_scripts_global() |
|
1509 | + { |
|
1510 | + $this->_add_admin_page_ajax_loading_img(); |
|
1511 | + $this->_add_admin_page_overlay(); |
|
1512 | + // if metaboxes are present we need to add the nonce field |
|
1513 | + if ( |
|
1514 | + isset($this->_route_config['metaboxes']) |
|
1515 | + || isset($this->_route_config['list_table']) |
|
1516 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
1517 | + ) { |
|
1518 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
1519 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
1520 | + } |
|
1521 | + } |
|
1522 | + |
|
1523 | + |
|
1524 | + /** |
|
1525 | + * admin_footer_global |
|
1526 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
1527 | + * ALL EE_Admin Pages. |
|
1528 | + * |
|
1529 | + * @return void |
|
1530 | + */ |
|
1531 | + public function admin_footer_global() |
|
1532 | + { |
|
1533 | + // dialog container for dialog helper |
|
1534 | + echo ' |
|
1535 | 1535 | <div class="ee-admin-dialog-container auto-hide hidden"> |
1536 | 1536 | <div class="ee-notices"></div> |
1537 | 1537 | <div class="ee-admin-dialog-container-inner-content"></div> |
1538 | 1538 | </div> |
1539 | 1539 | '; |
1540 | 1540 | |
1541 | - // current set timezone for timezone js |
|
1542 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
1543 | - } |
|
1544 | - |
|
1545 | - |
|
1546 | - /** |
|
1547 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
1548 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
1549 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
1550 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
1551 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
1552 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
1553 | - * for the |
|
1554 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
1555 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
1556 | - * 'help_trigger_id' => array( |
|
1557 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
1558 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
1559 | - * ) |
|
1560 | - * ); |
|
1561 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
1562 | - * |
|
1563 | - * @param array $help_array |
|
1564 | - * @param bool $display |
|
1565 | - * @return string content |
|
1566 | - * @throws DomainException |
|
1567 | - * @throws EE_Error |
|
1568 | - */ |
|
1569 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
1570 | - { |
|
1571 | - $content = ''; |
|
1572 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
1573 | - // loop through the array and setup content |
|
1574 | - foreach ($help_array as $trigger => $help) { |
|
1575 | - // make sure the array is setup properly |
|
1576 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
1577 | - throw new EE_Error( |
|
1578 | - esc_html__( |
|
1579 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
1580 | - 'event_espresso' |
|
1581 | - ) |
|
1582 | - ); |
|
1583 | - } |
|
1584 | - // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
1585 | - $template_args = [ |
|
1586 | - 'help_popup_id' => $trigger, |
|
1587 | - 'help_popup_title' => $help['title'], |
|
1588 | - 'help_popup_content' => $help['content'], |
|
1589 | - ]; |
|
1590 | - $content .= EEH_Template::display_template( |
|
1591 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1592 | - $template_args, |
|
1593 | - true |
|
1594 | - ); |
|
1595 | - } |
|
1596 | - if ($display) { |
|
1597 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
1598 | - return ''; |
|
1599 | - } |
|
1600 | - return $content; |
|
1601 | - } |
|
1602 | - |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
1606 | - * |
|
1607 | - * @return array properly formatted array for help popup content |
|
1608 | - * @throws EE_Error |
|
1609 | - */ |
|
1610 | - private function _get_help_content() |
|
1611 | - { |
|
1612 | - // what is the method we're looking for? |
|
1613 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
1614 | - // if method doesn't exist let's get out. |
|
1615 | - if (! method_exists($this, $method_name)) { |
|
1616 | - return []; |
|
1617 | - } |
|
1618 | - // k we're good to go let's retrieve the help array |
|
1619 | - $help_array = call_user_func([$this, $method_name]); |
|
1620 | - // make sure we've got an array! |
|
1621 | - if (! is_array($help_array)) { |
|
1622 | - throw new EE_Error( |
|
1623 | - esc_html__( |
|
1624 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
1625 | - 'event_espresso' |
|
1626 | - ) |
|
1627 | - ); |
|
1628 | - } |
|
1629 | - return $help_array; |
|
1630 | - } |
|
1631 | - |
|
1632 | - |
|
1633 | - /** |
|
1634 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
1635 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
1636 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
1637 | - * |
|
1638 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
1639 | - * @param boolean $display if false then we return the trigger string |
|
1640 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
1641 | - * @return string |
|
1642 | - * @throws DomainException |
|
1643 | - * @throws EE_Error |
|
1644 | - */ |
|
1645 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
1646 | - { |
|
1647 | - if ($this->request->isAjax()) { |
|
1648 | - return ''; |
|
1649 | - } |
|
1650 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
1651 | - $help_array = $this->_get_help_content(); |
|
1652 | - $help_content = ''; |
|
1653 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1654 | - $help_array[ $trigger_id ] = [ |
|
1655 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
1656 | - 'content' => esc_html__( |
|
1657 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
1658 | - 'event_espresso' |
|
1659 | - ), |
|
1660 | - ]; |
|
1661 | - $help_content = $this->_set_help_popup_content($help_array); |
|
1662 | - } |
|
1663 | - // let's setup the trigger |
|
1664 | - $content = '<a class="ee-dialog" href="?height=' |
|
1665 | - . esc_attr($dimensions[0]) |
|
1666 | - . '&width=' |
|
1667 | - . esc_attr($dimensions[1]) |
|
1668 | - . '&inlineId=' |
|
1669 | - . esc_attr($trigger_id) |
|
1670 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
1671 | - $content .= $help_content; |
|
1672 | - if ($display) { |
|
1673 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
1674 | - return ''; |
|
1675 | - } |
|
1676 | - return $content; |
|
1677 | - } |
|
1678 | - |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * _add_global_screen_options |
|
1682 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
1683 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
1684 | - * |
|
1685 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
1686 | - * see also WP_Screen object documents... |
|
1687 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
1688 | - * @abstract |
|
1689 | - * @return void |
|
1690 | - */ |
|
1691 | - private function _add_global_screen_options() |
|
1692 | - { |
|
1693 | - } |
|
1694 | - |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * _add_global_feature_pointers |
|
1698 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
1699 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
1700 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
1701 | - * |
|
1702 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
1703 | - * extended) also see: |
|
1704 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
1705 | - * @abstract |
|
1706 | - * @return void |
|
1707 | - */ |
|
1708 | - private function _add_global_feature_pointers() |
|
1709 | - { |
|
1710 | - } |
|
1711 | - |
|
1712 | - |
|
1713 | - /** |
|
1714 | - * load_global_scripts_styles |
|
1715 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
1716 | - * |
|
1717 | - * @return void |
|
1718 | - */ |
|
1719 | - public function load_global_scripts_styles() |
|
1720 | - { |
|
1721 | - /** STYLES **/ |
|
1722 | - // add debugging styles |
|
1723 | - if (WP_DEBUG) { |
|
1724 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
1725 | - } |
|
1726 | - // register all styles |
|
1727 | - wp_register_style( |
|
1728 | - 'espresso-ui-theme', |
|
1729 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1730 | - [], |
|
1731 | - EVENT_ESPRESSO_VERSION |
|
1732 | - ); |
|
1733 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
1734 | - // helpers styles |
|
1735 | - wp_register_style( |
|
1736 | - 'ee-text-links', |
|
1737 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1738 | - [], |
|
1739 | - EVENT_ESPRESSO_VERSION |
|
1740 | - ); |
|
1741 | - /** SCRIPTS **/ |
|
1742 | - // register all scripts |
|
1743 | - wp_register_script( |
|
1744 | - 'ee-dialog', |
|
1745 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1746 | - ['jquery', 'jquery-ui-draggable'], |
|
1747 | - EVENT_ESPRESSO_VERSION, |
|
1748 | - true |
|
1749 | - ); |
|
1750 | - wp_register_script( |
|
1751 | - 'ee_admin_js', |
|
1752 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1753 | - ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
1754 | - EVENT_ESPRESSO_VERSION, |
|
1755 | - true |
|
1756 | - ); |
|
1757 | - wp_register_script( |
|
1758 | - 'jquery-ui-timepicker-addon', |
|
1759 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1760 | - ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
1761 | - EVENT_ESPRESSO_VERSION, |
|
1762 | - true |
|
1763 | - ); |
|
1764 | - // script for sorting tables |
|
1765 | - wp_register_script( |
|
1766 | - 'espresso_ajax_table_sorting', |
|
1767 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1768 | - ['ee_admin_js', 'jquery-ui-sortable'], |
|
1769 | - EVENT_ESPRESSO_VERSION, |
|
1770 | - true |
|
1771 | - ); |
|
1772 | - // script for parsing uri's |
|
1773 | - wp_register_script( |
|
1774 | - 'ee-parse-uri', |
|
1775 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1776 | - [], |
|
1777 | - EVENT_ESPRESSO_VERSION, |
|
1778 | - true |
|
1779 | - ); |
|
1780 | - // and parsing associative serialized form elements |
|
1781 | - wp_register_script( |
|
1782 | - 'ee-serialize-full-array', |
|
1783 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1784 | - ['jquery'], |
|
1785 | - EVENT_ESPRESSO_VERSION, |
|
1786 | - true |
|
1787 | - ); |
|
1788 | - // helpers scripts |
|
1789 | - wp_register_script( |
|
1790 | - 'ee-text-links', |
|
1791 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1792 | - ['jquery'], |
|
1793 | - EVENT_ESPRESSO_VERSION, |
|
1794 | - true |
|
1795 | - ); |
|
1796 | - wp_register_script( |
|
1797 | - 'ee-moment-core', |
|
1798 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1799 | - [], |
|
1800 | - EVENT_ESPRESSO_VERSION, |
|
1801 | - true |
|
1802 | - ); |
|
1803 | - wp_register_script( |
|
1804 | - 'ee-moment', |
|
1805 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1806 | - ['ee-moment-core'], |
|
1807 | - EVENT_ESPRESSO_VERSION, |
|
1808 | - true |
|
1809 | - ); |
|
1810 | - wp_register_script( |
|
1811 | - 'ee-datepicker', |
|
1812 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1813 | - ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
1814 | - EVENT_ESPRESSO_VERSION, |
|
1815 | - true |
|
1816 | - ); |
|
1817 | - // google charts |
|
1818 | - wp_register_script( |
|
1819 | - 'google-charts', |
|
1820 | - 'https://www.gstatic.com/charts/loader.js', |
|
1821 | - [], |
|
1822 | - EVENT_ESPRESSO_VERSION |
|
1823 | - ); |
|
1824 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
1825 | - wp_enqueue_style('ee-admin-css'); |
|
1826 | - wp_enqueue_script('ee_admin_js'); |
|
1827 | - wp_enqueue_script('ee-accounting'); |
|
1828 | - wp_enqueue_script('jquery-validate'); |
|
1829 | - // taking care of metaboxes |
|
1830 | - if ( |
|
1831 | - empty($this->_cpt_route) |
|
1832 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
1833 | - ) { |
|
1834 | - wp_enqueue_script('dashboard'); |
|
1835 | - } |
|
1836 | - // LOCALIZED DATA |
|
1837 | - // localize script for ajax lazy loading |
|
1838 | - $lazy_loader_container_ids = apply_filters( |
|
1839 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
1840 | - ['espresso_news_post_box_content'] |
|
1841 | - ); |
|
1842 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
1843 | - add_filter( |
|
1844 | - 'admin_body_class', |
|
1845 | - function ($classes) { |
|
1846 | - if (strpos($classes, 'espresso-admin') === false) { |
|
1847 | - $classes .= ' espresso-admin'; |
|
1848 | - } |
|
1849 | - return $classes; |
|
1850 | - } |
|
1851 | - ); |
|
1852 | - } |
|
1853 | - |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * admin_footer_scripts_eei18n_js_strings |
|
1857 | - * |
|
1858 | - * @return void |
|
1859 | - */ |
|
1860 | - public function admin_footer_scripts_eei18n_js_strings() |
|
1861 | - { |
|
1862 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
1863 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
1864 | - __( |
|
1865 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
1866 | - 'event_espresso' |
|
1867 | - ) |
|
1868 | - ); |
|
1869 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
1870 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
1871 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
1872 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
1873 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
1874 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
1875 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
1876 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
1877 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
1878 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
1879 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
1880 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
1881 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
1882 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
1883 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
1884 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
1885 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
1886 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
1887 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
1888 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
1889 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
1890 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
1891 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
1892 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
1893 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
1894 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
1895 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
1896 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
1897 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
1898 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
1899 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
1900 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
1901 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
1902 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
1903 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
1904 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
1905 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
1906 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
1907 | - } |
|
1908 | - |
|
1909 | - |
|
1910 | - /** |
|
1911 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
1912 | - * |
|
1913 | - * @return void |
|
1914 | - */ |
|
1915 | - public function add_xdebug_style() |
|
1916 | - { |
|
1917 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
1918 | - } |
|
1919 | - |
|
1920 | - |
|
1921 | - /************************/ |
|
1922 | - /** LIST TABLE METHODS **/ |
|
1923 | - /************************/ |
|
1924 | - /** |
|
1925 | - * this sets up the list table if the current view requires it. |
|
1926 | - * |
|
1927 | - * @return void |
|
1928 | - * @throws EE_Error |
|
1929 | - */ |
|
1930 | - protected function _set_list_table() |
|
1931 | - { |
|
1932 | - // first is this a list_table view? |
|
1933 | - if (! isset($this->_route_config['list_table'])) { |
|
1934 | - return; |
|
1935 | - } //not a list_table view so get out. |
|
1936 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
1937 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
1938 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
1939 | - // user error msg |
|
1940 | - $error_msg = esc_html__( |
|
1941 | - 'An error occurred. The requested list table views could not be found.', |
|
1942 | - 'event_espresso' |
|
1943 | - ); |
|
1944 | - // developer error msg |
|
1945 | - $error_msg .= '||' |
|
1946 | - . sprintf( |
|
1947 | - esc_html__( |
|
1948 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
1949 | - 'event_espresso' |
|
1950 | - ), |
|
1951 | - $this->_req_action, |
|
1952 | - $list_table_view |
|
1953 | - ); |
|
1954 | - throw new EE_Error($error_msg); |
|
1955 | - } |
|
1956 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
1957 | - $this->_views = apply_filters( |
|
1958 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
1959 | - $this->_views |
|
1960 | - ); |
|
1961 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
1962 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
1963 | - $this->_set_list_table_view(); |
|
1964 | - $this->_set_list_table_object(); |
|
1965 | - } |
|
1966 | - |
|
1967 | - |
|
1968 | - /** |
|
1969 | - * set current view for List Table |
|
1970 | - * |
|
1971 | - * @return void |
|
1972 | - */ |
|
1973 | - protected function _set_list_table_view() |
|
1974 | - { |
|
1975 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
1976 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
1977 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
1978 | - ? $status |
|
1979 | - : $this->_view; |
|
1980 | - } |
|
1981 | - |
|
1982 | - |
|
1983 | - /** |
|
1984 | - * _set_list_table_object |
|
1985 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
1986 | - * |
|
1987 | - * @throws InvalidInterfaceException |
|
1988 | - * @throws InvalidArgumentException |
|
1989 | - * @throws InvalidDataTypeException |
|
1990 | - * @throws EE_Error |
|
1991 | - * @throws InvalidInterfaceException |
|
1992 | - */ |
|
1993 | - protected function _set_list_table_object() |
|
1994 | - { |
|
1995 | - if (isset($this->_route_config['list_table'])) { |
|
1996 | - if (! class_exists($this->_route_config['list_table'])) { |
|
1997 | - throw new EE_Error( |
|
1998 | - sprintf( |
|
1999 | - esc_html__( |
|
2000 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
2001 | - 'event_espresso' |
|
2002 | - ), |
|
2003 | - $this->_route_config['list_table'], |
|
2004 | - get_class($this) |
|
2005 | - ) |
|
2006 | - ); |
|
2007 | - } |
|
2008 | - $this->_list_table_object = $this->loader->getShared( |
|
2009 | - $this->_route_config['list_table'], |
|
2010 | - [$this] |
|
2011 | - ); |
|
2012 | - } |
|
2013 | - } |
|
2014 | - |
|
2015 | - |
|
2016 | - /** |
|
2017 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
2018 | - * |
|
2019 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
2020 | - * urls. The array should be indexed by the view it is being |
|
2021 | - * added to. |
|
2022 | - * @return array |
|
2023 | - */ |
|
2024 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
2025 | - { |
|
2026 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2027 | - if (empty($this->_views)) { |
|
2028 | - $this->_views = []; |
|
2029 | - } |
|
2030 | - // cycle thru views |
|
2031 | - foreach ($this->_views as $key => $view) { |
|
2032 | - $query_args = []; |
|
2033 | - // check for current view |
|
2034 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2035 | - $query_args['action'] = $this->_req_action; |
|
2036 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2037 | - $query_args['status'] = $view['slug']; |
|
2038 | - // merge any other arguments sent in. |
|
2039 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
2040 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2041 | - } |
|
2042 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2043 | - } |
|
2044 | - return $this->_views; |
|
2045 | - } |
|
2046 | - |
|
2047 | - |
|
2048 | - /** |
|
2049 | - * _entries_per_page_dropdown |
|
2050 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
2051 | - * |
|
2052 | - * @param int $max_entries total number of rows in the table |
|
2053 | - * @return string |
|
2054 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
2055 | - * WP does it. |
|
2056 | - */ |
|
2057 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
2058 | - { |
|
2059 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2060 | - $values = [10, 25, 50, 100]; |
|
2061 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
2062 | - if ($max_entries) { |
|
2063 | - $values[] = $max_entries; |
|
2064 | - sort($values); |
|
2065 | - } |
|
2066 | - $entries_per_page_dropdown = ' |
|
1541 | + // current set timezone for timezone js |
|
1542 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
1543 | + } |
|
1544 | + |
|
1545 | + |
|
1546 | + /** |
|
1547 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
1548 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
1549 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
1550 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
1551 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
1552 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
1553 | + * for the |
|
1554 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
1555 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
1556 | + * 'help_trigger_id' => array( |
|
1557 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
1558 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
1559 | + * ) |
|
1560 | + * ); |
|
1561 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
1562 | + * |
|
1563 | + * @param array $help_array |
|
1564 | + * @param bool $display |
|
1565 | + * @return string content |
|
1566 | + * @throws DomainException |
|
1567 | + * @throws EE_Error |
|
1568 | + */ |
|
1569 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
1570 | + { |
|
1571 | + $content = ''; |
|
1572 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
1573 | + // loop through the array and setup content |
|
1574 | + foreach ($help_array as $trigger => $help) { |
|
1575 | + // make sure the array is setup properly |
|
1576 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
1577 | + throw new EE_Error( |
|
1578 | + esc_html__( |
|
1579 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
1580 | + 'event_espresso' |
|
1581 | + ) |
|
1582 | + ); |
|
1583 | + } |
|
1584 | + // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
1585 | + $template_args = [ |
|
1586 | + 'help_popup_id' => $trigger, |
|
1587 | + 'help_popup_title' => $help['title'], |
|
1588 | + 'help_popup_content' => $help['content'], |
|
1589 | + ]; |
|
1590 | + $content .= EEH_Template::display_template( |
|
1591 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1592 | + $template_args, |
|
1593 | + true |
|
1594 | + ); |
|
1595 | + } |
|
1596 | + if ($display) { |
|
1597 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
1598 | + return ''; |
|
1599 | + } |
|
1600 | + return $content; |
|
1601 | + } |
|
1602 | + |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
1606 | + * |
|
1607 | + * @return array properly formatted array for help popup content |
|
1608 | + * @throws EE_Error |
|
1609 | + */ |
|
1610 | + private function _get_help_content() |
|
1611 | + { |
|
1612 | + // what is the method we're looking for? |
|
1613 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
1614 | + // if method doesn't exist let's get out. |
|
1615 | + if (! method_exists($this, $method_name)) { |
|
1616 | + return []; |
|
1617 | + } |
|
1618 | + // k we're good to go let's retrieve the help array |
|
1619 | + $help_array = call_user_func([$this, $method_name]); |
|
1620 | + // make sure we've got an array! |
|
1621 | + if (! is_array($help_array)) { |
|
1622 | + throw new EE_Error( |
|
1623 | + esc_html__( |
|
1624 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
1625 | + 'event_espresso' |
|
1626 | + ) |
|
1627 | + ); |
|
1628 | + } |
|
1629 | + return $help_array; |
|
1630 | + } |
|
1631 | + |
|
1632 | + |
|
1633 | + /** |
|
1634 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
1635 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
1636 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
1637 | + * |
|
1638 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
1639 | + * @param boolean $display if false then we return the trigger string |
|
1640 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
1641 | + * @return string |
|
1642 | + * @throws DomainException |
|
1643 | + * @throws EE_Error |
|
1644 | + */ |
|
1645 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
1646 | + { |
|
1647 | + if ($this->request->isAjax()) { |
|
1648 | + return ''; |
|
1649 | + } |
|
1650 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
1651 | + $help_array = $this->_get_help_content(); |
|
1652 | + $help_content = ''; |
|
1653 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1654 | + $help_array[ $trigger_id ] = [ |
|
1655 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
1656 | + 'content' => esc_html__( |
|
1657 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
1658 | + 'event_espresso' |
|
1659 | + ), |
|
1660 | + ]; |
|
1661 | + $help_content = $this->_set_help_popup_content($help_array); |
|
1662 | + } |
|
1663 | + // let's setup the trigger |
|
1664 | + $content = '<a class="ee-dialog" href="?height=' |
|
1665 | + . esc_attr($dimensions[0]) |
|
1666 | + . '&width=' |
|
1667 | + . esc_attr($dimensions[1]) |
|
1668 | + . '&inlineId=' |
|
1669 | + . esc_attr($trigger_id) |
|
1670 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
1671 | + $content .= $help_content; |
|
1672 | + if ($display) { |
|
1673 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
1674 | + return ''; |
|
1675 | + } |
|
1676 | + return $content; |
|
1677 | + } |
|
1678 | + |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * _add_global_screen_options |
|
1682 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
1683 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
1684 | + * |
|
1685 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
1686 | + * see also WP_Screen object documents... |
|
1687 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
1688 | + * @abstract |
|
1689 | + * @return void |
|
1690 | + */ |
|
1691 | + private function _add_global_screen_options() |
|
1692 | + { |
|
1693 | + } |
|
1694 | + |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * _add_global_feature_pointers |
|
1698 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
1699 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
1700 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
1701 | + * |
|
1702 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
1703 | + * extended) also see: |
|
1704 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
1705 | + * @abstract |
|
1706 | + * @return void |
|
1707 | + */ |
|
1708 | + private function _add_global_feature_pointers() |
|
1709 | + { |
|
1710 | + } |
|
1711 | + |
|
1712 | + |
|
1713 | + /** |
|
1714 | + * load_global_scripts_styles |
|
1715 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
1716 | + * |
|
1717 | + * @return void |
|
1718 | + */ |
|
1719 | + public function load_global_scripts_styles() |
|
1720 | + { |
|
1721 | + /** STYLES **/ |
|
1722 | + // add debugging styles |
|
1723 | + if (WP_DEBUG) { |
|
1724 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
1725 | + } |
|
1726 | + // register all styles |
|
1727 | + wp_register_style( |
|
1728 | + 'espresso-ui-theme', |
|
1729 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1730 | + [], |
|
1731 | + EVENT_ESPRESSO_VERSION |
|
1732 | + ); |
|
1733 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
1734 | + // helpers styles |
|
1735 | + wp_register_style( |
|
1736 | + 'ee-text-links', |
|
1737 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1738 | + [], |
|
1739 | + EVENT_ESPRESSO_VERSION |
|
1740 | + ); |
|
1741 | + /** SCRIPTS **/ |
|
1742 | + // register all scripts |
|
1743 | + wp_register_script( |
|
1744 | + 'ee-dialog', |
|
1745 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1746 | + ['jquery', 'jquery-ui-draggable'], |
|
1747 | + EVENT_ESPRESSO_VERSION, |
|
1748 | + true |
|
1749 | + ); |
|
1750 | + wp_register_script( |
|
1751 | + 'ee_admin_js', |
|
1752 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1753 | + ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
1754 | + EVENT_ESPRESSO_VERSION, |
|
1755 | + true |
|
1756 | + ); |
|
1757 | + wp_register_script( |
|
1758 | + 'jquery-ui-timepicker-addon', |
|
1759 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1760 | + ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
1761 | + EVENT_ESPRESSO_VERSION, |
|
1762 | + true |
|
1763 | + ); |
|
1764 | + // script for sorting tables |
|
1765 | + wp_register_script( |
|
1766 | + 'espresso_ajax_table_sorting', |
|
1767 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1768 | + ['ee_admin_js', 'jquery-ui-sortable'], |
|
1769 | + EVENT_ESPRESSO_VERSION, |
|
1770 | + true |
|
1771 | + ); |
|
1772 | + // script for parsing uri's |
|
1773 | + wp_register_script( |
|
1774 | + 'ee-parse-uri', |
|
1775 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1776 | + [], |
|
1777 | + EVENT_ESPRESSO_VERSION, |
|
1778 | + true |
|
1779 | + ); |
|
1780 | + // and parsing associative serialized form elements |
|
1781 | + wp_register_script( |
|
1782 | + 'ee-serialize-full-array', |
|
1783 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1784 | + ['jquery'], |
|
1785 | + EVENT_ESPRESSO_VERSION, |
|
1786 | + true |
|
1787 | + ); |
|
1788 | + // helpers scripts |
|
1789 | + wp_register_script( |
|
1790 | + 'ee-text-links', |
|
1791 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1792 | + ['jquery'], |
|
1793 | + EVENT_ESPRESSO_VERSION, |
|
1794 | + true |
|
1795 | + ); |
|
1796 | + wp_register_script( |
|
1797 | + 'ee-moment-core', |
|
1798 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1799 | + [], |
|
1800 | + EVENT_ESPRESSO_VERSION, |
|
1801 | + true |
|
1802 | + ); |
|
1803 | + wp_register_script( |
|
1804 | + 'ee-moment', |
|
1805 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1806 | + ['ee-moment-core'], |
|
1807 | + EVENT_ESPRESSO_VERSION, |
|
1808 | + true |
|
1809 | + ); |
|
1810 | + wp_register_script( |
|
1811 | + 'ee-datepicker', |
|
1812 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1813 | + ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
1814 | + EVENT_ESPRESSO_VERSION, |
|
1815 | + true |
|
1816 | + ); |
|
1817 | + // google charts |
|
1818 | + wp_register_script( |
|
1819 | + 'google-charts', |
|
1820 | + 'https://www.gstatic.com/charts/loader.js', |
|
1821 | + [], |
|
1822 | + EVENT_ESPRESSO_VERSION |
|
1823 | + ); |
|
1824 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
1825 | + wp_enqueue_style('ee-admin-css'); |
|
1826 | + wp_enqueue_script('ee_admin_js'); |
|
1827 | + wp_enqueue_script('ee-accounting'); |
|
1828 | + wp_enqueue_script('jquery-validate'); |
|
1829 | + // taking care of metaboxes |
|
1830 | + if ( |
|
1831 | + empty($this->_cpt_route) |
|
1832 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
1833 | + ) { |
|
1834 | + wp_enqueue_script('dashboard'); |
|
1835 | + } |
|
1836 | + // LOCALIZED DATA |
|
1837 | + // localize script for ajax lazy loading |
|
1838 | + $lazy_loader_container_ids = apply_filters( |
|
1839 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
1840 | + ['espresso_news_post_box_content'] |
|
1841 | + ); |
|
1842 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
1843 | + add_filter( |
|
1844 | + 'admin_body_class', |
|
1845 | + function ($classes) { |
|
1846 | + if (strpos($classes, 'espresso-admin') === false) { |
|
1847 | + $classes .= ' espresso-admin'; |
|
1848 | + } |
|
1849 | + return $classes; |
|
1850 | + } |
|
1851 | + ); |
|
1852 | + } |
|
1853 | + |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * admin_footer_scripts_eei18n_js_strings |
|
1857 | + * |
|
1858 | + * @return void |
|
1859 | + */ |
|
1860 | + public function admin_footer_scripts_eei18n_js_strings() |
|
1861 | + { |
|
1862 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
1863 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
1864 | + __( |
|
1865 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
1866 | + 'event_espresso' |
|
1867 | + ) |
|
1868 | + ); |
|
1869 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
1870 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
1871 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
1872 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
1873 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
1874 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
1875 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
1876 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
1877 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
1878 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
1879 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
1880 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
1881 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
1882 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
1883 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
1884 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
1885 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
1886 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
1887 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
1888 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
1889 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
1890 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
1891 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
1892 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
1893 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
1894 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
1895 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
1896 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
1897 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
1898 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
1899 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
1900 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
1901 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
1902 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
1903 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
1904 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
1905 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
1906 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
1907 | + } |
|
1908 | + |
|
1909 | + |
|
1910 | + /** |
|
1911 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
1912 | + * |
|
1913 | + * @return void |
|
1914 | + */ |
|
1915 | + public function add_xdebug_style() |
|
1916 | + { |
|
1917 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
1918 | + } |
|
1919 | + |
|
1920 | + |
|
1921 | + /************************/ |
|
1922 | + /** LIST TABLE METHODS **/ |
|
1923 | + /************************/ |
|
1924 | + /** |
|
1925 | + * this sets up the list table if the current view requires it. |
|
1926 | + * |
|
1927 | + * @return void |
|
1928 | + * @throws EE_Error |
|
1929 | + */ |
|
1930 | + protected function _set_list_table() |
|
1931 | + { |
|
1932 | + // first is this a list_table view? |
|
1933 | + if (! isset($this->_route_config['list_table'])) { |
|
1934 | + return; |
|
1935 | + } //not a list_table view so get out. |
|
1936 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
1937 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
1938 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
1939 | + // user error msg |
|
1940 | + $error_msg = esc_html__( |
|
1941 | + 'An error occurred. The requested list table views could not be found.', |
|
1942 | + 'event_espresso' |
|
1943 | + ); |
|
1944 | + // developer error msg |
|
1945 | + $error_msg .= '||' |
|
1946 | + . sprintf( |
|
1947 | + esc_html__( |
|
1948 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
1949 | + 'event_espresso' |
|
1950 | + ), |
|
1951 | + $this->_req_action, |
|
1952 | + $list_table_view |
|
1953 | + ); |
|
1954 | + throw new EE_Error($error_msg); |
|
1955 | + } |
|
1956 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
1957 | + $this->_views = apply_filters( |
|
1958 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
1959 | + $this->_views |
|
1960 | + ); |
|
1961 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
1962 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
1963 | + $this->_set_list_table_view(); |
|
1964 | + $this->_set_list_table_object(); |
|
1965 | + } |
|
1966 | + |
|
1967 | + |
|
1968 | + /** |
|
1969 | + * set current view for List Table |
|
1970 | + * |
|
1971 | + * @return void |
|
1972 | + */ |
|
1973 | + protected function _set_list_table_view() |
|
1974 | + { |
|
1975 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
1976 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
1977 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
1978 | + ? $status |
|
1979 | + : $this->_view; |
|
1980 | + } |
|
1981 | + |
|
1982 | + |
|
1983 | + /** |
|
1984 | + * _set_list_table_object |
|
1985 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
1986 | + * |
|
1987 | + * @throws InvalidInterfaceException |
|
1988 | + * @throws InvalidArgumentException |
|
1989 | + * @throws InvalidDataTypeException |
|
1990 | + * @throws EE_Error |
|
1991 | + * @throws InvalidInterfaceException |
|
1992 | + */ |
|
1993 | + protected function _set_list_table_object() |
|
1994 | + { |
|
1995 | + if (isset($this->_route_config['list_table'])) { |
|
1996 | + if (! class_exists($this->_route_config['list_table'])) { |
|
1997 | + throw new EE_Error( |
|
1998 | + sprintf( |
|
1999 | + esc_html__( |
|
2000 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
2001 | + 'event_espresso' |
|
2002 | + ), |
|
2003 | + $this->_route_config['list_table'], |
|
2004 | + get_class($this) |
|
2005 | + ) |
|
2006 | + ); |
|
2007 | + } |
|
2008 | + $this->_list_table_object = $this->loader->getShared( |
|
2009 | + $this->_route_config['list_table'], |
|
2010 | + [$this] |
|
2011 | + ); |
|
2012 | + } |
|
2013 | + } |
|
2014 | + |
|
2015 | + |
|
2016 | + /** |
|
2017 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
2018 | + * |
|
2019 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
2020 | + * urls. The array should be indexed by the view it is being |
|
2021 | + * added to. |
|
2022 | + * @return array |
|
2023 | + */ |
|
2024 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
2025 | + { |
|
2026 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2027 | + if (empty($this->_views)) { |
|
2028 | + $this->_views = []; |
|
2029 | + } |
|
2030 | + // cycle thru views |
|
2031 | + foreach ($this->_views as $key => $view) { |
|
2032 | + $query_args = []; |
|
2033 | + // check for current view |
|
2034 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2035 | + $query_args['action'] = $this->_req_action; |
|
2036 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2037 | + $query_args['status'] = $view['slug']; |
|
2038 | + // merge any other arguments sent in. |
|
2039 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
2040 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2041 | + } |
|
2042 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2043 | + } |
|
2044 | + return $this->_views; |
|
2045 | + } |
|
2046 | + |
|
2047 | + |
|
2048 | + /** |
|
2049 | + * _entries_per_page_dropdown |
|
2050 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
2051 | + * |
|
2052 | + * @param int $max_entries total number of rows in the table |
|
2053 | + * @return string |
|
2054 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
2055 | + * WP does it. |
|
2056 | + */ |
|
2057 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
2058 | + { |
|
2059 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2060 | + $values = [10, 25, 50, 100]; |
|
2061 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
2062 | + if ($max_entries) { |
|
2063 | + $values[] = $max_entries; |
|
2064 | + sort($values); |
|
2065 | + } |
|
2066 | + $entries_per_page_dropdown = ' |
|
2067 | 2067 | <div id="entries-per-page-dv" class="alignleft actions"> |
2068 | 2068 | <label class="hide-if-no-js"> |
2069 | 2069 | Show |
2070 | 2070 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
2071 | - foreach ($values as $value) { |
|
2072 | - if ($value < $max_entries) { |
|
2073 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2074 | - $entries_per_page_dropdown .= ' |
|
2071 | + foreach ($values as $value) { |
|
2072 | + if ($value < $max_entries) { |
|
2073 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2074 | + $entries_per_page_dropdown .= ' |
|
2075 | 2075 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
2076 | - } |
|
2077 | - } |
|
2078 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2079 | - $entries_per_page_dropdown .= ' |
|
2076 | + } |
|
2077 | + } |
|
2078 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2079 | + $entries_per_page_dropdown .= ' |
|
2080 | 2080 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
2081 | - $entries_per_page_dropdown .= ' |
|
2081 | + $entries_per_page_dropdown .= ' |
|
2082 | 2082 | </select> |
2083 | 2083 | entries |
2084 | 2084 | </label> |
2085 | 2085 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
2086 | 2086 | </div> |
2087 | 2087 | '; |
2088 | - return $entries_per_page_dropdown; |
|
2089 | - } |
|
2090 | - |
|
2091 | - |
|
2092 | - /** |
|
2093 | - * _set_search_attributes |
|
2094 | - * |
|
2095 | - * @return void |
|
2096 | - */ |
|
2097 | - public function _set_search_attributes() |
|
2098 | - { |
|
2099 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
2100 | - esc_html__('Search %s', 'event_espresso'), |
|
2101 | - empty($this->_search_btn_label) ? $this->page_label |
|
2102 | - : $this->_search_btn_label |
|
2103 | - ); |
|
2104 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2105 | - } |
|
2106 | - |
|
2107 | - |
|
2108 | - |
|
2109 | - /*** END LIST TABLE METHODS **/ |
|
2110 | - |
|
2111 | - |
|
2112 | - /** |
|
2113 | - * _add_registered_metaboxes |
|
2114 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
2115 | - * |
|
2116 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
2117 | - * @return void |
|
2118 | - * @throws EE_Error |
|
2119 | - */ |
|
2120 | - private function _add_registered_meta_boxes() |
|
2121 | - { |
|
2122 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2123 | - // we only add meta boxes if the page_route calls for it |
|
2124 | - if ( |
|
2125 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
2126 | - && is_array( |
|
2127 | - $this->_route_config['metaboxes'] |
|
2128 | - ) |
|
2129 | - ) { |
|
2130 | - // this simply loops through the callbacks provided |
|
2131 | - // and checks if there is a corresponding callback registered by the child |
|
2132 | - // if there is then we go ahead and process the metabox loader. |
|
2133 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
2134 | - // first check for Closures |
|
2135 | - if ($metabox_callback instanceof Closure) { |
|
2136 | - $result = $metabox_callback(); |
|
2137 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
2138 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
2139 | - } else { |
|
2140 | - $result = call_user_func([$this, &$metabox_callback]); |
|
2141 | - } |
|
2142 | - if ($result === false) { |
|
2143 | - // user error msg |
|
2144 | - $error_msg = esc_html__( |
|
2145 | - 'An error occurred. The requested metabox could not be found.', |
|
2146 | - 'event_espresso' |
|
2147 | - ); |
|
2148 | - // developer error msg |
|
2149 | - $error_msg .= '||' |
|
2150 | - . sprintf( |
|
2151 | - esc_html__( |
|
2152 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
2153 | - 'event_espresso' |
|
2154 | - ), |
|
2155 | - $metabox_callback |
|
2156 | - ); |
|
2157 | - throw new EE_Error($error_msg); |
|
2158 | - } |
|
2159 | - } |
|
2160 | - } |
|
2161 | - } |
|
2162 | - |
|
2163 | - |
|
2164 | - /** |
|
2165 | - * _add_screen_columns |
|
2166 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
2167 | - * the dynamic column template and we'll setup the column options for the page. |
|
2168 | - * |
|
2169 | - * @return void |
|
2170 | - */ |
|
2171 | - private function _add_screen_columns() |
|
2172 | - { |
|
2173 | - if ( |
|
2174 | - is_array($this->_route_config) |
|
2175 | - && isset($this->_route_config['columns']) |
|
2176 | - && is_array($this->_route_config['columns']) |
|
2177 | - && count($this->_route_config['columns']) === 2 |
|
2178 | - ) { |
|
2179 | - add_screen_option( |
|
2180 | - 'layout_columns', |
|
2181 | - [ |
|
2182 | - 'max' => (int) $this->_route_config['columns'][0], |
|
2183 | - 'default' => (int) $this->_route_config['columns'][1], |
|
2184 | - ] |
|
2185 | - ); |
|
2186 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
2187 | - $screen_id = $this->_current_screen->id; |
|
2188 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
2189 | - $total_columns = ! empty($screen_columns) |
|
2190 | - ? $screen_columns |
|
2191 | - : $this->_route_config['columns'][1]; |
|
2192 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2193 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2194 | - $this->_template_args['screen'] = $this->_current_screen; |
|
2195 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
2196 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
2197 | - // finally if we don't have has_metaboxes set in the route config |
|
2198 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
2199 | - $this->_route_config['has_metaboxes'] = true; |
|
2200 | - } |
|
2201 | - } |
|
2202 | - |
|
2203 | - |
|
2204 | - |
|
2205 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
2206 | - |
|
2207 | - |
|
2208 | - /** |
|
2209 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
2210 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
2211 | - * these get loaded on. |
|
2212 | - */ |
|
2213 | - private function _espresso_news_post_box() |
|
2214 | - { |
|
2215 | - $news_box_title = apply_filters( |
|
2216 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2217 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
2218 | - ); |
|
2219 | - add_meta_box( |
|
2220 | - 'espresso_news_post_box', |
|
2221 | - $news_box_title, |
|
2222 | - [ |
|
2223 | - $this, |
|
2224 | - 'espresso_news_post_box', |
|
2225 | - ], |
|
2226 | - $this->_wp_page_slug, |
|
2227 | - 'side' |
|
2228 | - ); |
|
2229 | - } |
|
2230 | - |
|
2231 | - |
|
2232 | - /** |
|
2233 | - * Code for setting up espresso ratings request metabox. |
|
2234 | - */ |
|
2235 | - protected function _espresso_ratings_request() |
|
2236 | - { |
|
2237 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2238 | - return; |
|
2239 | - } |
|
2240 | - $ratings_box_title = apply_filters( |
|
2241 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2242 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
2243 | - ); |
|
2244 | - add_meta_box( |
|
2245 | - 'espresso_ratings_request', |
|
2246 | - $ratings_box_title, |
|
2247 | - [ |
|
2248 | - $this, |
|
2249 | - 'espresso_ratings_request', |
|
2250 | - ], |
|
2251 | - $this->_wp_page_slug, |
|
2252 | - 'side' |
|
2253 | - ); |
|
2254 | - } |
|
2255 | - |
|
2256 | - |
|
2257 | - /** |
|
2258 | - * Code for setting up espresso ratings request metabox content. |
|
2259 | - * |
|
2260 | - * @throws DomainException |
|
2261 | - */ |
|
2262 | - public function espresso_ratings_request() |
|
2263 | - { |
|
2264 | - EEH_Template::display_template( |
|
2265 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2266 | - [] |
|
2267 | - ); |
|
2268 | - } |
|
2269 | - |
|
2270 | - |
|
2271 | - public static function cached_rss_display($rss_id, $url) |
|
2272 | - { |
|
2273 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
2274 | - . esc_html__('Loading…', 'event_espresso') |
|
2275 | - . '</p><p class="hide-if-js">' |
|
2276 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
2277 | - . '</p>'; |
|
2278 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2279 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
2280 | - $post = '</div>' . "\n"; |
|
2281 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
2282 | - $output = get_transient($cache_key); |
|
2283 | - if ($output !== false) { |
|
2284 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
2285 | - return true; |
|
2286 | - } |
|
2287 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2288 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
2289 | - return false; |
|
2290 | - } |
|
2291 | - ob_start(); |
|
2292 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
2293 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
2294 | - return true; |
|
2295 | - } |
|
2296 | - |
|
2297 | - |
|
2298 | - public function espresso_news_post_box() |
|
2299 | - { |
|
2300 | - ?> |
|
2088 | + return $entries_per_page_dropdown; |
|
2089 | + } |
|
2090 | + |
|
2091 | + |
|
2092 | + /** |
|
2093 | + * _set_search_attributes |
|
2094 | + * |
|
2095 | + * @return void |
|
2096 | + */ |
|
2097 | + public function _set_search_attributes() |
|
2098 | + { |
|
2099 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
2100 | + esc_html__('Search %s', 'event_espresso'), |
|
2101 | + empty($this->_search_btn_label) ? $this->page_label |
|
2102 | + : $this->_search_btn_label |
|
2103 | + ); |
|
2104 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2105 | + } |
|
2106 | + |
|
2107 | + |
|
2108 | + |
|
2109 | + /*** END LIST TABLE METHODS **/ |
|
2110 | + |
|
2111 | + |
|
2112 | + /** |
|
2113 | + * _add_registered_metaboxes |
|
2114 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
2115 | + * |
|
2116 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
2117 | + * @return void |
|
2118 | + * @throws EE_Error |
|
2119 | + */ |
|
2120 | + private function _add_registered_meta_boxes() |
|
2121 | + { |
|
2122 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2123 | + // we only add meta boxes if the page_route calls for it |
|
2124 | + if ( |
|
2125 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
2126 | + && is_array( |
|
2127 | + $this->_route_config['metaboxes'] |
|
2128 | + ) |
|
2129 | + ) { |
|
2130 | + // this simply loops through the callbacks provided |
|
2131 | + // and checks if there is a corresponding callback registered by the child |
|
2132 | + // if there is then we go ahead and process the metabox loader. |
|
2133 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
2134 | + // first check for Closures |
|
2135 | + if ($metabox_callback instanceof Closure) { |
|
2136 | + $result = $metabox_callback(); |
|
2137 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
2138 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
2139 | + } else { |
|
2140 | + $result = call_user_func([$this, &$metabox_callback]); |
|
2141 | + } |
|
2142 | + if ($result === false) { |
|
2143 | + // user error msg |
|
2144 | + $error_msg = esc_html__( |
|
2145 | + 'An error occurred. The requested metabox could not be found.', |
|
2146 | + 'event_espresso' |
|
2147 | + ); |
|
2148 | + // developer error msg |
|
2149 | + $error_msg .= '||' |
|
2150 | + . sprintf( |
|
2151 | + esc_html__( |
|
2152 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
2153 | + 'event_espresso' |
|
2154 | + ), |
|
2155 | + $metabox_callback |
|
2156 | + ); |
|
2157 | + throw new EE_Error($error_msg); |
|
2158 | + } |
|
2159 | + } |
|
2160 | + } |
|
2161 | + } |
|
2162 | + |
|
2163 | + |
|
2164 | + /** |
|
2165 | + * _add_screen_columns |
|
2166 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
2167 | + * the dynamic column template and we'll setup the column options for the page. |
|
2168 | + * |
|
2169 | + * @return void |
|
2170 | + */ |
|
2171 | + private function _add_screen_columns() |
|
2172 | + { |
|
2173 | + if ( |
|
2174 | + is_array($this->_route_config) |
|
2175 | + && isset($this->_route_config['columns']) |
|
2176 | + && is_array($this->_route_config['columns']) |
|
2177 | + && count($this->_route_config['columns']) === 2 |
|
2178 | + ) { |
|
2179 | + add_screen_option( |
|
2180 | + 'layout_columns', |
|
2181 | + [ |
|
2182 | + 'max' => (int) $this->_route_config['columns'][0], |
|
2183 | + 'default' => (int) $this->_route_config['columns'][1], |
|
2184 | + ] |
|
2185 | + ); |
|
2186 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
2187 | + $screen_id = $this->_current_screen->id; |
|
2188 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
2189 | + $total_columns = ! empty($screen_columns) |
|
2190 | + ? $screen_columns |
|
2191 | + : $this->_route_config['columns'][1]; |
|
2192 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2193 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2194 | + $this->_template_args['screen'] = $this->_current_screen; |
|
2195 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
2196 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
2197 | + // finally if we don't have has_metaboxes set in the route config |
|
2198 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
2199 | + $this->_route_config['has_metaboxes'] = true; |
|
2200 | + } |
|
2201 | + } |
|
2202 | + |
|
2203 | + |
|
2204 | + |
|
2205 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
2206 | + |
|
2207 | + |
|
2208 | + /** |
|
2209 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
2210 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
2211 | + * these get loaded on. |
|
2212 | + */ |
|
2213 | + private function _espresso_news_post_box() |
|
2214 | + { |
|
2215 | + $news_box_title = apply_filters( |
|
2216 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2217 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
2218 | + ); |
|
2219 | + add_meta_box( |
|
2220 | + 'espresso_news_post_box', |
|
2221 | + $news_box_title, |
|
2222 | + [ |
|
2223 | + $this, |
|
2224 | + 'espresso_news_post_box', |
|
2225 | + ], |
|
2226 | + $this->_wp_page_slug, |
|
2227 | + 'side' |
|
2228 | + ); |
|
2229 | + } |
|
2230 | + |
|
2231 | + |
|
2232 | + /** |
|
2233 | + * Code for setting up espresso ratings request metabox. |
|
2234 | + */ |
|
2235 | + protected function _espresso_ratings_request() |
|
2236 | + { |
|
2237 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2238 | + return; |
|
2239 | + } |
|
2240 | + $ratings_box_title = apply_filters( |
|
2241 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2242 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
2243 | + ); |
|
2244 | + add_meta_box( |
|
2245 | + 'espresso_ratings_request', |
|
2246 | + $ratings_box_title, |
|
2247 | + [ |
|
2248 | + $this, |
|
2249 | + 'espresso_ratings_request', |
|
2250 | + ], |
|
2251 | + $this->_wp_page_slug, |
|
2252 | + 'side' |
|
2253 | + ); |
|
2254 | + } |
|
2255 | + |
|
2256 | + |
|
2257 | + /** |
|
2258 | + * Code for setting up espresso ratings request metabox content. |
|
2259 | + * |
|
2260 | + * @throws DomainException |
|
2261 | + */ |
|
2262 | + public function espresso_ratings_request() |
|
2263 | + { |
|
2264 | + EEH_Template::display_template( |
|
2265 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2266 | + [] |
|
2267 | + ); |
|
2268 | + } |
|
2269 | + |
|
2270 | + |
|
2271 | + public static function cached_rss_display($rss_id, $url) |
|
2272 | + { |
|
2273 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
2274 | + . esc_html__('Loading…', 'event_espresso') |
|
2275 | + . '</p><p class="hide-if-js">' |
|
2276 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
2277 | + . '</p>'; |
|
2278 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2279 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
2280 | + $post = '</div>' . "\n"; |
|
2281 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
2282 | + $output = get_transient($cache_key); |
|
2283 | + if ($output !== false) { |
|
2284 | + echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
2285 | + return true; |
|
2286 | + } |
|
2287 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2288 | + echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
2289 | + return false; |
|
2290 | + } |
|
2291 | + ob_start(); |
|
2292 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
2293 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
2294 | + return true; |
|
2295 | + } |
|
2296 | + |
|
2297 | + |
|
2298 | + public function espresso_news_post_box() |
|
2299 | + { |
|
2300 | + ?> |
|
2301 | 2301 | <div class="padding"> |
2302 | 2302 | <div id="espresso_news_post_box_content" class="infolinks"> |
2303 | 2303 | <?php |
2304 | - // Get RSS Feed(s) |
|
2305 | - self::cached_rss_display( |
|
2306 | - 'espresso_news_post_box_content', |
|
2307 | - esc_url_raw( |
|
2308 | - apply_filters( |
|
2309 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
2310 | - 'https://eventespresso.com/feed/' |
|
2311 | - ) |
|
2312 | - ) |
|
2313 | - ); |
|
2314 | - ?> |
|
2304 | + // Get RSS Feed(s) |
|
2305 | + self::cached_rss_display( |
|
2306 | + 'espresso_news_post_box_content', |
|
2307 | + esc_url_raw( |
|
2308 | + apply_filters( |
|
2309 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
2310 | + 'https://eventespresso.com/feed/' |
|
2311 | + ) |
|
2312 | + ) |
|
2313 | + ); |
|
2314 | + ?> |
|
2315 | 2315 | </div> |
2316 | 2316 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
2317 | 2317 | </div> |
2318 | 2318 | <?php |
2319 | - } |
|
2320 | - |
|
2321 | - |
|
2322 | - private function _espresso_links_post_box() |
|
2323 | - { |
|
2324 | - // Hiding until we actually have content to put in here... |
|
2325 | - // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
2326 | - } |
|
2327 | - |
|
2328 | - |
|
2329 | - public function espresso_links_post_box() |
|
2330 | - { |
|
2331 | - // Hiding until we actually have content to put in here... |
|
2332 | - // EEH_Template::display_template( |
|
2333 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
2334 | - // ); |
|
2335 | - } |
|
2336 | - |
|
2337 | - |
|
2338 | - protected function _espresso_sponsors_post_box() |
|
2339 | - { |
|
2340 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
2341 | - add_meta_box( |
|
2342 | - 'espresso_sponsors_post_box', |
|
2343 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
2344 | - [$this, 'espresso_sponsors_post_box'], |
|
2345 | - $this->_wp_page_slug, |
|
2346 | - 'side' |
|
2347 | - ); |
|
2348 | - } |
|
2349 | - } |
|
2350 | - |
|
2351 | - |
|
2352 | - public function espresso_sponsors_post_box() |
|
2353 | - { |
|
2354 | - EEH_Template::display_template( |
|
2355 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2356 | - ); |
|
2357 | - } |
|
2358 | - |
|
2359 | - |
|
2360 | - private function _publish_post_box() |
|
2361 | - { |
|
2362 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2363 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
2364 | - // then we'll use that for the metabox label. |
|
2365 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
2366 | - if (! empty($this->_labels['publishbox'])) { |
|
2367 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2368 | - : $this->_labels['publishbox']; |
|
2369 | - } else { |
|
2370 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
2371 | - } |
|
2372 | - $box_label = apply_filters( |
|
2373 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
2374 | - $box_label, |
|
2375 | - $this->_req_action, |
|
2376 | - $this |
|
2377 | - ); |
|
2378 | - add_meta_box( |
|
2379 | - $meta_box_ref, |
|
2380 | - $box_label, |
|
2381 | - [$this, 'editor_overview'], |
|
2382 | - $this->_current_screen->id, |
|
2383 | - 'side', |
|
2384 | - 'high' |
|
2385 | - ); |
|
2386 | - } |
|
2387 | - |
|
2388 | - |
|
2389 | - public function editor_overview() |
|
2390 | - { |
|
2391 | - // if we have extra content set let's add it in if not make sure its empty |
|
2392 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2393 | - ? $this->_template_args['publish_box_extra_content'] |
|
2394 | - : ''; |
|
2395 | - echo EEH_Template::display_template( |
|
2396 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2397 | - $this->_template_args, |
|
2398 | - true |
|
2399 | - ); |
|
2400 | - } |
|
2401 | - |
|
2402 | - |
|
2403 | - /** end of globally available metaboxes section **/ |
|
2404 | - |
|
2405 | - |
|
2406 | - /** |
|
2407 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
2408 | - * protected method. |
|
2409 | - * |
|
2410 | - * @param string $name |
|
2411 | - * @param int $id |
|
2412 | - * @param bool $delete |
|
2413 | - * @param string $save_close_redirect_URL |
|
2414 | - * @param bool $both_btns |
|
2415 | - * @throws EE_Error |
|
2416 | - * @throws InvalidArgumentException |
|
2417 | - * @throws InvalidDataTypeException |
|
2418 | - * @throws InvalidInterfaceException |
|
2419 | - * @see $this->_set_publish_post_box_vars for param details |
|
2420 | - * @since 4.6.0 |
|
2421 | - */ |
|
2422 | - public function set_publish_post_box_vars( |
|
2423 | - $name = '', |
|
2424 | - $id = 0, |
|
2425 | - $delete = false, |
|
2426 | - $save_close_redirect_URL = '', |
|
2427 | - $both_btns = true |
|
2428 | - ) { |
|
2429 | - $this->_set_publish_post_box_vars( |
|
2430 | - $name, |
|
2431 | - $id, |
|
2432 | - $delete, |
|
2433 | - $save_close_redirect_URL, |
|
2434 | - $both_btns |
|
2435 | - ); |
|
2436 | - } |
|
2437 | - |
|
2438 | - |
|
2439 | - /** |
|
2440 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
2441 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
2442 | - * save, and save and close buttons to work properly, then you will want to include a |
|
2443 | - * values for the name and id arguments. |
|
2444 | - * |
|
2445 | - * @param string $name key used for the action ID (i.e. event_id) |
|
2446 | - * @param int $id id attached to the item published |
|
2447 | - * @param string $delete page route callback for the delete action |
|
2448 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
2449 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
2450 | - * the Save button |
|
2451 | - * @throws EE_Error |
|
2452 | - * @throws InvalidArgumentException |
|
2453 | - * @throws InvalidDataTypeException |
|
2454 | - * @throws InvalidInterfaceException |
|
2455 | - * @todo Add in validation for name/id arguments. |
|
2456 | - */ |
|
2457 | - protected function _set_publish_post_box_vars( |
|
2458 | - $name = '', |
|
2459 | - $id = 0, |
|
2460 | - $delete = '', |
|
2461 | - $save_close_redirect_URL = '', |
|
2462 | - $both_btns = true |
|
2463 | - ) { |
|
2464 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
2465 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
2466 | - ? $save_close_redirect_URL |
|
2467 | - : $this->_admin_base_url; |
|
2468 | - // create the Save & Close and Save buttons |
|
2469 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
2470 | - // if we have extra content set let's add it in if not make sure its empty |
|
2471 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2472 | - ? $this->_template_args['publish_box_extra_content'] |
|
2473 | - : ''; |
|
2474 | - if ($delete && ! empty($id)) { |
|
2475 | - // make sure we have a default if just true is sent. |
|
2476 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
2477 | - $delete_link_args = [$name => $id]; |
|
2478 | - $delete = $this->get_action_link_or_button( |
|
2479 | - $delete, |
|
2480 | - $delete, |
|
2481 | - $delete_link_args, |
|
2482 | - 'submitdelete deletion', |
|
2483 | - '', |
|
2484 | - false |
|
2485 | - ); |
|
2486 | - } |
|
2487 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
2488 | - if (! empty($name) && ! empty($id)) { |
|
2489 | - $hidden_field_arr[ $name ] = [ |
|
2490 | - 'type' => 'hidden', |
|
2491 | - 'value' => $id, |
|
2492 | - ]; |
|
2493 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2494 | - } else { |
|
2495 | - $hf = ''; |
|
2496 | - } |
|
2497 | - // add hidden field |
|
2498 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
2499 | - ? $hf[ $name ]['field'] |
|
2500 | - : $hf; |
|
2501 | - } |
|
2502 | - |
|
2503 | - |
|
2504 | - /** |
|
2505 | - * displays an error message to ppl who have javascript disabled |
|
2506 | - * |
|
2507 | - * @return void |
|
2508 | - */ |
|
2509 | - private function _display_no_javascript_warning() |
|
2510 | - { |
|
2511 | - ?> |
|
2319 | + } |
|
2320 | + |
|
2321 | + |
|
2322 | + private function _espresso_links_post_box() |
|
2323 | + { |
|
2324 | + // Hiding until we actually have content to put in here... |
|
2325 | + // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
2326 | + } |
|
2327 | + |
|
2328 | + |
|
2329 | + public function espresso_links_post_box() |
|
2330 | + { |
|
2331 | + // Hiding until we actually have content to put in here... |
|
2332 | + // EEH_Template::display_template( |
|
2333 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
2334 | + // ); |
|
2335 | + } |
|
2336 | + |
|
2337 | + |
|
2338 | + protected function _espresso_sponsors_post_box() |
|
2339 | + { |
|
2340 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
2341 | + add_meta_box( |
|
2342 | + 'espresso_sponsors_post_box', |
|
2343 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
2344 | + [$this, 'espresso_sponsors_post_box'], |
|
2345 | + $this->_wp_page_slug, |
|
2346 | + 'side' |
|
2347 | + ); |
|
2348 | + } |
|
2349 | + } |
|
2350 | + |
|
2351 | + |
|
2352 | + public function espresso_sponsors_post_box() |
|
2353 | + { |
|
2354 | + EEH_Template::display_template( |
|
2355 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2356 | + ); |
|
2357 | + } |
|
2358 | + |
|
2359 | + |
|
2360 | + private function _publish_post_box() |
|
2361 | + { |
|
2362 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2363 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
2364 | + // then we'll use that for the metabox label. |
|
2365 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
2366 | + if (! empty($this->_labels['publishbox'])) { |
|
2367 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2368 | + : $this->_labels['publishbox']; |
|
2369 | + } else { |
|
2370 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
2371 | + } |
|
2372 | + $box_label = apply_filters( |
|
2373 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
2374 | + $box_label, |
|
2375 | + $this->_req_action, |
|
2376 | + $this |
|
2377 | + ); |
|
2378 | + add_meta_box( |
|
2379 | + $meta_box_ref, |
|
2380 | + $box_label, |
|
2381 | + [$this, 'editor_overview'], |
|
2382 | + $this->_current_screen->id, |
|
2383 | + 'side', |
|
2384 | + 'high' |
|
2385 | + ); |
|
2386 | + } |
|
2387 | + |
|
2388 | + |
|
2389 | + public function editor_overview() |
|
2390 | + { |
|
2391 | + // if we have extra content set let's add it in if not make sure its empty |
|
2392 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2393 | + ? $this->_template_args['publish_box_extra_content'] |
|
2394 | + : ''; |
|
2395 | + echo EEH_Template::display_template( |
|
2396 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2397 | + $this->_template_args, |
|
2398 | + true |
|
2399 | + ); |
|
2400 | + } |
|
2401 | + |
|
2402 | + |
|
2403 | + /** end of globally available metaboxes section **/ |
|
2404 | + |
|
2405 | + |
|
2406 | + /** |
|
2407 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
2408 | + * protected method. |
|
2409 | + * |
|
2410 | + * @param string $name |
|
2411 | + * @param int $id |
|
2412 | + * @param bool $delete |
|
2413 | + * @param string $save_close_redirect_URL |
|
2414 | + * @param bool $both_btns |
|
2415 | + * @throws EE_Error |
|
2416 | + * @throws InvalidArgumentException |
|
2417 | + * @throws InvalidDataTypeException |
|
2418 | + * @throws InvalidInterfaceException |
|
2419 | + * @see $this->_set_publish_post_box_vars for param details |
|
2420 | + * @since 4.6.0 |
|
2421 | + */ |
|
2422 | + public function set_publish_post_box_vars( |
|
2423 | + $name = '', |
|
2424 | + $id = 0, |
|
2425 | + $delete = false, |
|
2426 | + $save_close_redirect_URL = '', |
|
2427 | + $both_btns = true |
|
2428 | + ) { |
|
2429 | + $this->_set_publish_post_box_vars( |
|
2430 | + $name, |
|
2431 | + $id, |
|
2432 | + $delete, |
|
2433 | + $save_close_redirect_URL, |
|
2434 | + $both_btns |
|
2435 | + ); |
|
2436 | + } |
|
2437 | + |
|
2438 | + |
|
2439 | + /** |
|
2440 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
2441 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
2442 | + * save, and save and close buttons to work properly, then you will want to include a |
|
2443 | + * values for the name and id arguments. |
|
2444 | + * |
|
2445 | + * @param string $name key used for the action ID (i.e. event_id) |
|
2446 | + * @param int $id id attached to the item published |
|
2447 | + * @param string $delete page route callback for the delete action |
|
2448 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
2449 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
2450 | + * the Save button |
|
2451 | + * @throws EE_Error |
|
2452 | + * @throws InvalidArgumentException |
|
2453 | + * @throws InvalidDataTypeException |
|
2454 | + * @throws InvalidInterfaceException |
|
2455 | + * @todo Add in validation for name/id arguments. |
|
2456 | + */ |
|
2457 | + protected function _set_publish_post_box_vars( |
|
2458 | + $name = '', |
|
2459 | + $id = 0, |
|
2460 | + $delete = '', |
|
2461 | + $save_close_redirect_URL = '', |
|
2462 | + $both_btns = true |
|
2463 | + ) { |
|
2464 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
2465 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
2466 | + ? $save_close_redirect_URL |
|
2467 | + : $this->_admin_base_url; |
|
2468 | + // create the Save & Close and Save buttons |
|
2469 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
2470 | + // if we have extra content set let's add it in if not make sure its empty |
|
2471 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2472 | + ? $this->_template_args['publish_box_extra_content'] |
|
2473 | + : ''; |
|
2474 | + if ($delete && ! empty($id)) { |
|
2475 | + // make sure we have a default if just true is sent. |
|
2476 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
2477 | + $delete_link_args = [$name => $id]; |
|
2478 | + $delete = $this->get_action_link_or_button( |
|
2479 | + $delete, |
|
2480 | + $delete, |
|
2481 | + $delete_link_args, |
|
2482 | + 'submitdelete deletion', |
|
2483 | + '', |
|
2484 | + false |
|
2485 | + ); |
|
2486 | + } |
|
2487 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
2488 | + if (! empty($name) && ! empty($id)) { |
|
2489 | + $hidden_field_arr[ $name ] = [ |
|
2490 | + 'type' => 'hidden', |
|
2491 | + 'value' => $id, |
|
2492 | + ]; |
|
2493 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2494 | + } else { |
|
2495 | + $hf = ''; |
|
2496 | + } |
|
2497 | + // add hidden field |
|
2498 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
2499 | + ? $hf[ $name ]['field'] |
|
2500 | + : $hf; |
|
2501 | + } |
|
2502 | + |
|
2503 | + |
|
2504 | + /** |
|
2505 | + * displays an error message to ppl who have javascript disabled |
|
2506 | + * |
|
2507 | + * @return void |
|
2508 | + */ |
|
2509 | + private function _display_no_javascript_warning() |
|
2510 | + { |
|
2511 | + ?> |
|
2512 | 2512 | <noscript> |
2513 | 2513 | <div id="no-js-message" class="error"> |
2514 | 2514 | <p style="font-size:1.3em;"> |
2515 | 2515 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
2516 | 2516 | <?php esc_html_e( |
2517 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
2518 | - 'event_espresso' |
|
2519 | - ); ?> |
|
2517 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
2518 | + 'event_espresso' |
|
2519 | + ); ?> |
|
2520 | 2520 | </p> |
2521 | 2521 | </div> |
2522 | 2522 | </noscript> |
2523 | 2523 | <?php |
2524 | - } |
|
2525 | - |
|
2526 | - |
|
2527 | - /** |
|
2528 | - * displays espresso success and/or error notices |
|
2529 | - * |
|
2530 | - * @return void |
|
2531 | - */ |
|
2532 | - protected function _display_espresso_notices() |
|
2533 | - { |
|
2534 | - $notices = $this->_get_transient(true); |
|
2535 | - echo stripslashes($notices); |
|
2536 | - } |
|
2537 | - |
|
2538 | - |
|
2539 | - /** |
|
2540 | - * spinny things pacify the masses |
|
2541 | - * |
|
2542 | - * @return void |
|
2543 | - */ |
|
2544 | - protected function _add_admin_page_ajax_loading_img() |
|
2545 | - { |
|
2546 | - ?> |
|
2524 | + } |
|
2525 | + |
|
2526 | + |
|
2527 | + /** |
|
2528 | + * displays espresso success and/or error notices |
|
2529 | + * |
|
2530 | + * @return void |
|
2531 | + */ |
|
2532 | + protected function _display_espresso_notices() |
|
2533 | + { |
|
2534 | + $notices = $this->_get_transient(true); |
|
2535 | + echo stripslashes($notices); |
|
2536 | + } |
|
2537 | + |
|
2538 | + |
|
2539 | + /** |
|
2540 | + * spinny things pacify the masses |
|
2541 | + * |
|
2542 | + * @return void |
|
2543 | + */ |
|
2544 | + protected function _add_admin_page_ajax_loading_img() |
|
2545 | + { |
|
2546 | + ?> |
|
2547 | 2547 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
2548 | 2548 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
2549 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
2549 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
2550 | 2550 | </div> |
2551 | 2551 | <?php |
2552 | - } |
|
2552 | + } |
|
2553 | 2553 | |
2554 | 2554 | |
2555 | - /** |
|
2556 | - * add admin page overlay for modal boxes |
|
2557 | - * |
|
2558 | - * @return void |
|
2559 | - */ |
|
2560 | - protected function _add_admin_page_overlay() |
|
2561 | - { |
|
2562 | - ?> |
|
2555 | + /** |
|
2556 | + * add admin page overlay for modal boxes |
|
2557 | + * |
|
2558 | + * @return void |
|
2559 | + */ |
|
2560 | + protected function _add_admin_page_overlay() |
|
2561 | + { |
|
2562 | + ?> |
|
2563 | 2563 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
2564 | 2564 | <?php |
2565 | - } |
|
2566 | - |
|
2567 | - |
|
2568 | - /** |
|
2569 | - * facade for add_meta_box |
|
2570 | - * |
|
2571 | - * @param string $action where the metabox gets displayed |
|
2572 | - * @param string $title Title of Metabox (output in metabox header) |
|
2573 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
2574 | - * instead of the one created in here. |
|
2575 | - * @param array $callback_args an array of args supplied for the metabox |
|
2576 | - * @param string $column what metabox column |
|
2577 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
2578 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
2579 | - * created but just set our own callback for wp's add_meta_box. |
|
2580 | - * @throws DomainException |
|
2581 | - */ |
|
2582 | - public function _add_admin_page_meta_box( |
|
2583 | - $action, |
|
2584 | - $title, |
|
2585 | - $callback, |
|
2586 | - $callback_args, |
|
2587 | - $column = 'normal', |
|
2588 | - $priority = 'high', |
|
2589 | - $create_func = true |
|
2590 | - ) { |
|
2591 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
2592 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
2593 | - if (empty($callback_args) && $create_func) { |
|
2594 | - $callback_args = [ |
|
2595 | - 'template_path' => $this->_template_path, |
|
2596 | - 'template_args' => $this->_template_args, |
|
2597 | - ]; |
|
2598 | - } |
|
2599 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
2600 | - $call_back_func = $create_func |
|
2601 | - ? function ($post, $metabox) { |
|
2602 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2603 | - echo EEH_Template::display_template( |
|
2604 | - $metabox['args']['template_path'], |
|
2605 | - $metabox['args']['template_args'], |
|
2606 | - true |
|
2607 | - ); |
|
2608 | - } |
|
2609 | - : $callback; |
|
2610 | - add_meta_box( |
|
2611 | - str_replace('_', '-', $action) . '-mbox', |
|
2612 | - $title, |
|
2613 | - $call_back_func, |
|
2614 | - $this->_wp_page_slug, |
|
2615 | - $column, |
|
2616 | - $priority, |
|
2617 | - $callback_args |
|
2618 | - ); |
|
2619 | - } |
|
2620 | - |
|
2621 | - |
|
2622 | - /** |
|
2623 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
2624 | - * |
|
2625 | - * @throws DomainException |
|
2626 | - * @throws EE_Error |
|
2627 | - */ |
|
2628 | - public function display_admin_page_with_metabox_columns() |
|
2629 | - { |
|
2630 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
2631 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2632 | - $this->_column_template_path, |
|
2633 | - $this->_template_args, |
|
2634 | - true |
|
2635 | - ); |
|
2636 | - // the final wrapper |
|
2637 | - $this->admin_page_wrapper(); |
|
2638 | - } |
|
2639 | - |
|
2640 | - |
|
2641 | - /** |
|
2642 | - * generates HTML wrapper for an admin details page |
|
2643 | - * |
|
2644 | - * @return void |
|
2645 | - * @throws EE_Error |
|
2646 | - * @throws DomainException |
|
2647 | - */ |
|
2648 | - public function display_admin_page_with_sidebar() |
|
2649 | - { |
|
2650 | - $this->_display_admin_page(true); |
|
2651 | - } |
|
2652 | - |
|
2653 | - |
|
2654 | - /** |
|
2655 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
2656 | - * |
|
2657 | - * @return void |
|
2658 | - * @throws EE_Error |
|
2659 | - * @throws DomainException |
|
2660 | - */ |
|
2661 | - public function display_admin_page_with_no_sidebar() |
|
2662 | - { |
|
2663 | - $this->_display_admin_page(); |
|
2664 | - } |
|
2665 | - |
|
2666 | - |
|
2667 | - /** |
|
2668 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
2669 | - * |
|
2670 | - * @return void |
|
2671 | - * @throws EE_Error |
|
2672 | - * @throws DomainException |
|
2673 | - */ |
|
2674 | - public function display_about_admin_page() |
|
2675 | - { |
|
2676 | - $this->_display_admin_page(false, true); |
|
2677 | - } |
|
2678 | - |
|
2679 | - |
|
2680 | - /** |
|
2681 | - * display_admin_page |
|
2682 | - * contains the code for actually displaying an admin page |
|
2683 | - * |
|
2684 | - * @param boolean $sidebar true with sidebar, false without |
|
2685 | - * @param boolean $about use the about_admin_wrapper instead of the default. |
|
2686 | - * @return void |
|
2687 | - * @throws DomainException |
|
2688 | - * @throws EE_Error |
|
2689 | - */ |
|
2690 | - private function _display_admin_page($sidebar = false, $about = false) |
|
2691 | - { |
|
2692 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2693 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
2694 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
2695 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
2696 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
2697 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2698 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
2699 | - ? 'poststuff' |
|
2700 | - : 'espresso-default-admin'; |
|
2701 | - $template_path = $sidebar |
|
2702 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
2703 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2704 | - if ($this->request->isAjax()) { |
|
2705 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2706 | - } |
|
2707 | - $template_path = ! empty($this->_column_template_path) |
|
2708 | - ? $this->_column_template_path : $template_path; |
|
2709 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
2710 | - ? $this->_template_args['admin_page_content'] |
|
2711 | - : ''; |
|
2712 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
2713 | - ? $this->_template_args['before_admin_page_content'] |
|
2714 | - : ''; |
|
2715 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
2716 | - ? $this->_template_args['after_admin_page_content'] |
|
2717 | - : ''; |
|
2718 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2719 | - $template_path, |
|
2720 | - $this->_template_args, |
|
2721 | - true |
|
2722 | - ); |
|
2723 | - // the final template wrapper |
|
2724 | - $this->admin_page_wrapper($about); |
|
2725 | - } |
|
2726 | - |
|
2727 | - |
|
2728 | - /** |
|
2729 | - * This is used to display caf preview pages. |
|
2730 | - * |
|
2731 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
2732 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
2733 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
2734 | - * @return void |
|
2735 | - * @throws DomainException |
|
2736 | - * @throws EE_Error |
|
2737 | - * @throws InvalidArgumentException |
|
2738 | - * @throws InvalidDataTypeException |
|
2739 | - * @throws InvalidInterfaceException |
|
2740 | - * @since 4.3.2 |
|
2741 | - */ |
|
2742 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
2743 | - { |
|
2744 | - // let's generate a default preview action button if there isn't one already present. |
|
2745 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2746 | - 'Upgrade to Event Espresso 4 Right Now', |
|
2747 | - 'event_espresso' |
|
2748 | - ); |
|
2749 | - $buy_now_url = add_query_arg( |
|
2750 | - [ |
|
2751 | - 'ee_ver' => 'ee4', |
|
2752 | - 'utm_source' => 'ee4_plugin_admin', |
|
2753 | - 'utm_medium' => 'link', |
|
2754 | - 'utm_campaign' => $utm_campaign_source, |
|
2755 | - 'utm_content' => 'buy_now_button', |
|
2756 | - ], |
|
2757 | - 'https://eventespresso.com/pricing/' |
|
2758 | - ); |
|
2759 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
2760 | - ? $this->get_action_link_or_button( |
|
2761 | - '', |
|
2762 | - 'buy_now', |
|
2763 | - [], |
|
2764 | - 'button-primary button-large', |
|
2765 | - esc_url_raw($buy_now_url), |
|
2766 | - true |
|
2767 | - ) |
|
2768 | - : $this->_template_args['preview_action_button']; |
|
2769 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2771 | - $this->_template_args, |
|
2772 | - true |
|
2773 | - ); |
|
2774 | - $this->_display_admin_page($display_sidebar); |
|
2775 | - } |
|
2776 | - |
|
2777 | - |
|
2778 | - /** |
|
2779 | - * display_admin_list_table_page_with_sidebar |
|
2780 | - * generates HTML wrapper for an admin_page with list_table |
|
2781 | - * |
|
2782 | - * @return void |
|
2783 | - * @throws EE_Error |
|
2784 | - * @throws DomainException |
|
2785 | - */ |
|
2786 | - public function display_admin_list_table_page_with_sidebar() |
|
2787 | - { |
|
2788 | - $this->_display_admin_list_table_page(true); |
|
2789 | - } |
|
2790 | - |
|
2791 | - |
|
2792 | - /** |
|
2793 | - * display_admin_list_table_page_with_no_sidebar |
|
2794 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
2795 | - * |
|
2796 | - * @return void |
|
2797 | - * @throws EE_Error |
|
2798 | - * @throws DomainException |
|
2799 | - */ |
|
2800 | - public function display_admin_list_table_page_with_no_sidebar() |
|
2801 | - { |
|
2802 | - $this->_display_admin_list_table_page(); |
|
2803 | - } |
|
2804 | - |
|
2805 | - |
|
2806 | - /** |
|
2807 | - * generates html wrapper for an admin_list_table page |
|
2808 | - * |
|
2809 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
2810 | - * @return void |
|
2811 | - * @throws DomainException |
|
2812 | - * @throws EE_Error |
|
2813 | - */ |
|
2814 | - private function _display_admin_list_table_page($sidebar = false) |
|
2815 | - { |
|
2816 | - // setup search attributes |
|
2817 | - $this->_set_search_attributes(); |
|
2818 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2819 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2820 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
2821 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
2822 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
2823 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
2824 | - $this->_template_args['current_route'] = $this->_req_action; |
|
2825 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
2826 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
2827 | - if (! empty($ajax_sorting_callback)) { |
|
2828 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
2829 | - $ajax_sorting_callback . '_nonce', |
|
2830 | - $ajax_sorting_callback . '_nonce', |
|
2831 | - false, |
|
2832 | - false |
|
2833 | - ); |
|
2834 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
2835 | - . $this->page_slug |
|
2836 | - . '" />'; |
|
2837 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
2838 | - . $ajax_sorting_callback |
|
2839 | - . '" />'; |
|
2840 | - } else { |
|
2841 | - $sortable_list_table_form_fields = ''; |
|
2842 | - } |
|
2843 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
2844 | - $hidden_form_fields = |
|
2845 | - isset($this->_template_args['list_table_hidden_fields']) |
|
2846 | - ? $this->_template_args['list_table_hidden_fields'] |
|
2847 | - : ''; |
|
2848 | - |
|
2849 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
2850 | - $hidden_form_fields .= ' |
|
2565 | + } |
|
2566 | + |
|
2567 | + |
|
2568 | + /** |
|
2569 | + * facade for add_meta_box |
|
2570 | + * |
|
2571 | + * @param string $action where the metabox gets displayed |
|
2572 | + * @param string $title Title of Metabox (output in metabox header) |
|
2573 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
2574 | + * instead of the one created in here. |
|
2575 | + * @param array $callback_args an array of args supplied for the metabox |
|
2576 | + * @param string $column what metabox column |
|
2577 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
2578 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
2579 | + * created but just set our own callback for wp's add_meta_box. |
|
2580 | + * @throws DomainException |
|
2581 | + */ |
|
2582 | + public function _add_admin_page_meta_box( |
|
2583 | + $action, |
|
2584 | + $title, |
|
2585 | + $callback, |
|
2586 | + $callback_args, |
|
2587 | + $column = 'normal', |
|
2588 | + $priority = 'high', |
|
2589 | + $create_func = true |
|
2590 | + ) { |
|
2591 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
2592 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
2593 | + if (empty($callback_args) && $create_func) { |
|
2594 | + $callback_args = [ |
|
2595 | + 'template_path' => $this->_template_path, |
|
2596 | + 'template_args' => $this->_template_args, |
|
2597 | + ]; |
|
2598 | + } |
|
2599 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
2600 | + $call_back_func = $create_func |
|
2601 | + ? function ($post, $metabox) { |
|
2602 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2603 | + echo EEH_Template::display_template( |
|
2604 | + $metabox['args']['template_path'], |
|
2605 | + $metabox['args']['template_args'], |
|
2606 | + true |
|
2607 | + ); |
|
2608 | + } |
|
2609 | + : $callback; |
|
2610 | + add_meta_box( |
|
2611 | + str_replace('_', '-', $action) . '-mbox', |
|
2612 | + $title, |
|
2613 | + $call_back_func, |
|
2614 | + $this->_wp_page_slug, |
|
2615 | + $column, |
|
2616 | + $priority, |
|
2617 | + $callback_args |
|
2618 | + ); |
|
2619 | + } |
|
2620 | + |
|
2621 | + |
|
2622 | + /** |
|
2623 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
2624 | + * |
|
2625 | + * @throws DomainException |
|
2626 | + * @throws EE_Error |
|
2627 | + */ |
|
2628 | + public function display_admin_page_with_metabox_columns() |
|
2629 | + { |
|
2630 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
2631 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2632 | + $this->_column_template_path, |
|
2633 | + $this->_template_args, |
|
2634 | + true |
|
2635 | + ); |
|
2636 | + // the final wrapper |
|
2637 | + $this->admin_page_wrapper(); |
|
2638 | + } |
|
2639 | + |
|
2640 | + |
|
2641 | + /** |
|
2642 | + * generates HTML wrapper for an admin details page |
|
2643 | + * |
|
2644 | + * @return void |
|
2645 | + * @throws EE_Error |
|
2646 | + * @throws DomainException |
|
2647 | + */ |
|
2648 | + public function display_admin_page_with_sidebar() |
|
2649 | + { |
|
2650 | + $this->_display_admin_page(true); |
|
2651 | + } |
|
2652 | + |
|
2653 | + |
|
2654 | + /** |
|
2655 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
2656 | + * |
|
2657 | + * @return void |
|
2658 | + * @throws EE_Error |
|
2659 | + * @throws DomainException |
|
2660 | + */ |
|
2661 | + public function display_admin_page_with_no_sidebar() |
|
2662 | + { |
|
2663 | + $this->_display_admin_page(); |
|
2664 | + } |
|
2665 | + |
|
2666 | + |
|
2667 | + /** |
|
2668 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
2669 | + * |
|
2670 | + * @return void |
|
2671 | + * @throws EE_Error |
|
2672 | + * @throws DomainException |
|
2673 | + */ |
|
2674 | + public function display_about_admin_page() |
|
2675 | + { |
|
2676 | + $this->_display_admin_page(false, true); |
|
2677 | + } |
|
2678 | + |
|
2679 | + |
|
2680 | + /** |
|
2681 | + * display_admin_page |
|
2682 | + * contains the code for actually displaying an admin page |
|
2683 | + * |
|
2684 | + * @param boolean $sidebar true with sidebar, false without |
|
2685 | + * @param boolean $about use the about_admin_wrapper instead of the default. |
|
2686 | + * @return void |
|
2687 | + * @throws DomainException |
|
2688 | + * @throws EE_Error |
|
2689 | + */ |
|
2690 | + private function _display_admin_page($sidebar = false, $about = false) |
|
2691 | + { |
|
2692 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2693 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
2694 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
2695 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
2696 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
2697 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2698 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
2699 | + ? 'poststuff' |
|
2700 | + : 'espresso-default-admin'; |
|
2701 | + $template_path = $sidebar |
|
2702 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
2703 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2704 | + if ($this->request->isAjax()) { |
|
2705 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2706 | + } |
|
2707 | + $template_path = ! empty($this->_column_template_path) |
|
2708 | + ? $this->_column_template_path : $template_path; |
|
2709 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
2710 | + ? $this->_template_args['admin_page_content'] |
|
2711 | + : ''; |
|
2712 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
2713 | + ? $this->_template_args['before_admin_page_content'] |
|
2714 | + : ''; |
|
2715 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
2716 | + ? $this->_template_args['after_admin_page_content'] |
|
2717 | + : ''; |
|
2718 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2719 | + $template_path, |
|
2720 | + $this->_template_args, |
|
2721 | + true |
|
2722 | + ); |
|
2723 | + // the final template wrapper |
|
2724 | + $this->admin_page_wrapper($about); |
|
2725 | + } |
|
2726 | + |
|
2727 | + |
|
2728 | + /** |
|
2729 | + * This is used to display caf preview pages. |
|
2730 | + * |
|
2731 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
2732 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
2733 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
2734 | + * @return void |
|
2735 | + * @throws DomainException |
|
2736 | + * @throws EE_Error |
|
2737 | + * @throws InvalidArgumentException |
|
2738 | + * @throws InvalidDataTypeException |
|
2739 | + * @throws InvalidInterfaceException |
|
2740 | + * @since 4.3.2 |
|
2741 | + */ |
|
2742 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
2743 | + { |
|
2744 | + // let's generate a default preview action button if there isn't one already present. |
|
2745 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2746 | + 'Upgrade to Event Espresso 4 Right Now', |
|
2747 | + 'event_espresso' |
|
2748 | + ); |
|
2749 | + $buy_now_url = add_query_arg( |
|
2750 | + [ |
|
2751 | + 'ee_ver' => 'ee4', |
|
2752 | + 'utm_source' => 'ee4_plugin_admin', |
|
2753 | + 'utm_medium' => 'link', |
|
2754 | + 'utm_campaign' => $utm_campaign_source, |
|
2755 | + 'utm_content' => 'buy_now_button', |
|
2756 | + ], |
|
2757 | + 'https://eventespresso.com/pricing/' |
|
2758 | + ); |
|
2759 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
2760 | + ? $this->get_action_link_or_button( |
|
2761 | + '', |
|
2762 | + 'buy_now', |
|
2763 | + [], |
|
2764 | + 'button-primary button-large', |
|
2765 | + esc_url_raw($buy_now_url), |
|
2766 | + true |
|
2767 | + ) |
|
2768 | + : $this->_template_args['preview_action_button']; |
|
2769 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2771 | + $this->_template_args, |
|
2772 | + true |
|
2773 | + ); |
|
2774 | + $this->_display_admin_page($display_sidebar); |
|
2775 | + } |
|
2776 | + |
|
2777 | + |
|
2778 | + /** |
|
2779 | + * display_admin_list_table_page_with_sidebar |
|
2780 | + * generates HTML wrapper for an admin_page with list_table |
|
2781 | + * |
|
2782 | + * @return void |
|
2783 | + * @throws EE_Error |
|
2784 | + * @throws DomainException |
|
2785 | + */ |
|
2786 | + public function display_admin_list_table_page_with_sidebar() |
|
2787 | + { |
|
2788 | + $this->_display_admin_list_table_page(true); |
|
2789 | + } |
|
2790 | + |
|
2791 | + |
|
2792 | + /** |
|
2793 | + * display_admin_list_table_page_with_no_sidebar |
|
2794 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
2795 | + * |
|
2796 | + * @return void |
|
2797 | + * @throws EE_Error |
|
2798 | + * @throws DomainException |
|
2799 | + */ |
|
2800 | + public function display_admin_list_table_page_with_no_sidebar() |
|
2801 | + { |
|
2802 | + $this->_display_admin_list_table_page(); |
|
2803 | + } |
|
2804 | + |
|
2805 | + |
|
2806 | + /** |
|
2807 | + * generates html wrapper for an admin_list_table page |
|
2808 | + * |
|
2809 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
2810 | + * @return void |
|
2811 | + * @throws DomainException |
|
2812 | + * @throws EE_Error |
|
2813 | + */ |
|
2814 | + private function _display_admin_list_table_page($sidebar = false) |
|
2815 | + { |
|
2816 | + // setup search attributes |
|
2817 | + $this->_set_search_attributes(); |
|
2818 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2819 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2820 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
2821 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
2822 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
2823 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
2824 | + $this->_template_args['current_route'] = $this->_req_action; |
|
2825 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
2826 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
2827 | + if (! empty($ajax_sorting_callback)) { |
|
2828 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
2829 | + $ajax_sorting_callback . '_nonce', |
|
2830 | + $ajax_sorting_callback . '_nonce', |
|
2831 | + false, |
|
2832 | + false |
|
2833 | + ); |
|
2834 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
2835 | + . $this->page_slug |
|
2836 | + . '" />'; |
|
2837 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
2838 | + . $ajax_sorting_callback |
|
2839 | + . '" />'; |
|
2840 | + } else { |
|
2841 | + $sortable_list_table_form_fields = ''; |
|
2842 | + } |
|
2843 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
2844 | + $hidden_form_fields = |
|
2845 | + isset($this->_template_args['list_table_hidden_fields']) |
|
2846 | + ? $this->_template_args['list_table_hidden_fields'] |
|
2847 | + : ''; |
|
2848 | + |
|
2849 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
2850 | + $hidden_form_fields .= ' |
|
2851 | 2851 | <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
2852 | 2852 | |
2853 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2854 | - // display message about search results? |
|
2855 | - $search = $this->request->getRequestParam('s'); |
|
2856 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
2857 | - ? '<p class="ee-search-results">' . sprintf( |
|
2858 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
2859 | - trim($search, '%') |
|
2860 | - ) . '</p>' |
|
2861 | - : ''; |
|
2862 | - // filter before_list_table template arg |
|
2863 | - $this->_template_args['before_list_table'] = apply_filters( |
|
2864 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
2865 | - $this->_template_args['before_list_table'], |
|
2866 | - $this->page_slug, |
|
2867 | - $this->request->requestParams(), |
|
2868 | - $this->_req_action |
|
2869 | - ); |
|
2870 | - // convert to array and filter again |
|
2871 | - // arrays are easier to inject new items in a specific location, |
|
2872 | - // but would not be backwards compatible, so we have to add a new filter |
|
2873 | - $this->_template_args['before_list_table'] = implode( |
|
2874 | - " \n", |
|
2875 | - (array) apply_filters( |
|
2876 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
2877 | - (array) $this->_template_args['before_list_table'], |
|
2878 | - $this->page_slug, |
|
2879 | - $this->request->requestParams(), |
|
2880 | - $this->_req_action |
|
2881 | - ) |
|
2882 | - ); |
|
2883 | - // filter after_list_table template arg |
|
2884 | - $this->_template_args['after_list_table'] = apply_filters( |
|
2885 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
2886 | - $this->_template_args['after_list_table'], |
|
2887 | - $this->page_slug, |
|
2888 | - $this->request->requestParams(), |
|
2889 | - $this->_req_action |
|
2890 | - ); |
|
2891 | - // convert to array and filter again |
|
2892 | - // arrays are easier to inject new items in a specific location, |
|
2893 | - // but would not be backwards compatible, so we have to add a new filter |
|
2894 | - $this->_template_args['after_list_table'] = implode( |
|
2895 | - " \n", |
|
2896 | - (array) apply_filters( |
|
2897 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
2898 | - (array) $this->_template_args['after_list_table'], |
|
2899 | - $this->page_slug, |
|
2900 | - $this->request->requestParams(), |
|
2901 | - $this->_req_action |
|
2902 | - ) |
|
2903 | - ); |
|
2904 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2905 | - $template_path, |
|
2906 | - $this->_template_args, |
|
2907 | - true |
|
2908 | - ); |
|
2909 | - // the final template wrapper |
|
2910 | - if ($sidebar) { |
|
2911 | - $this->display_admin_page_with_sidebar(); |
|
2912 | - } else { |
|
2913 | - $this->display_admin_page_with_no_sidebar(); |
|
2914 | - } |
|
2915 | - } |
|
2916 | - |
|
2917 | - |
|
2918 | - /** |
|
2919 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
2920 | - * html string for the legend. |
|
2921 | - * $items are expected in an array in the following format: |
|
2922 | - * $legend_items = array( |
|
2923 | - * 'item_id' => array( |
|
2924 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
2925 | - * 'desc' => esc_html__('localized description of item'); |
|
2926 | - * ) |
|
2927 | - * ); |
|
2928 | - * |
|
2929 | - * @param array $items see above for format of array |
|
2930 | - * @return string html string of legend |
|
2931 | - * @throws DomainException |
|
2932 | - */ |
|
2933 | - protected function _display_legend($items) |
|
2934 | - { |
|
2935 | - $this->_template_args['items'] = apply_filters( |
|
2936 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
2937 | - (array) $items, |
|
2938 | - $this |
|
2939 | - ); |
|
2940 | - return EEH_Template::display_template( |
|
2941 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
2942 | - $this->_template_args, |
|
2943 | - true |
|
2944 | - ); |
|
2945 | - } |
|
2946 | - |
|
2947 | - |
|
2948 | - /** |
|
2949 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
2950 | - * The returned json object is created from an array in the following format: |
|
2951 | - * array( |
|
2952 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
2953 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
2954 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
2955 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
2956 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
2957 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
2958 | - * that might be included in here) |
|
2959 | - * ) |
|
2960 | - * The json object is populated by whatever is set in the $_template_args property. |
|
2961 | - * |
|
2962 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
2963 | - * instead of displayed. |
|
2964 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
2965 | - * @return void |
|
2966 | - * @throws EE_Error |
|
2967 | - */ |
|
2968 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
2969 | - { |
|
2970 | - // make sure any EE_Error notices have been handled. |
|
2971 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
2972 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
2973 | - unset($this->_template_args['data']); |
|
2974 | - $json = [ |
|
2975 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
2976 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
2977 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
2978 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
2979 | - 'notices' => EE_Error::get_notices(), |
|
2980 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
2981 | - ? $this->_template_args['admin_page_content'] : '', |
|
2982 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
2983 | - 'isEEajax' => true |
|
2984 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
2985 | - ]; |
|
2986 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
2987 | - if (null === error_get_last() || ! headers_sent()) { |
|
2988 | - header('Content-Type: application/json; charset=UTF-8'); |
|
2989 | - } |
|
2990 | - echo wp_json_encode($json); |
|
2991 | - exit(); |
|
2992 | - } |
|
2993 | - |
|
2994 | - |
|
2995 | - /** |
|
2996 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
2997 | - * |
|
2998 | - * @return void |
|
2999 | - * @throws EE_Error |
|
3000 | - */ |
|
3001 | - public function return_json() |
|
3002 | - { |
|
3003 | - if ($this->request->isAjax()) { |
|
3004 | - $this->_return_json(); |
|
3005 | - } else { |
|
3006 | - throw new EE_Error( |
|
3007 | - sprintf( |
|
3008 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
3009 | - __FUNCTION__ |
|
3010 | - ) |
|
3011 | - ); |
|
3012 | - } |
|
3013 | - } |
|
3014 | - |
|
3015 | - |
|
3016 | - /** |
|
3017 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
3018 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
3019 | - * |
|
3020 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
3021 | - */ |
|
3022 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
3023 | - { |
|
3024 | - $this->_hook_obj = $hook_obj; |
|
3025 | - } |
|
3026 | - |
|
3027 | - |
|
3028 | - /** |
|
3029 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
3030 | - * |
|
3031 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
3032 | - * @return void |
|
3033 | - * @throws DomainException |
|
3034 | - * @throws EE_Error |
|
3035 | - */ |
|
3036 | - public function admin_page_wrapper($about = false) |
|
3037 | - { |
|
3038 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3039 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
3040 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
3041 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
3042 | - |
|
3043 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
3044 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3045 | - isset($this->_template_args['before_admin_page_content']) |
|
3046 | - ? $this->_template_args['before_admin_page_content'] |
|
3047 | - : '' |
|
3048 | - ); |
|
3049 | - |
|
3050 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3051 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3052 | - isset($this->_template_args['after_admin_page_content']) |
|
3053 | - ? $this->_template_args['after_admin_page_content'] |
|
3054 | - : '' |
|
3055 | - ); |
|
3056 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3057 | - |
|
3058 | - if ($this->request->isAjax()) { |
|
3059 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3060 | - // $template_path, |
|
3061 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
3062 | - $this->_template_args, |
|
3063 | - true |
|
3064 | - ); |
|
3065 | - $this->_return_json(); |
|
3066 | - } |
|
3067 | - // load settings page wrapper template |
|
3068 | - $template_path = $about |
|
3069 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
3070 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
3071 | - |
|
3072 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
3073 | - } |
|
3074 | - |
|
3075 | - |
|
3076 | - /** |
|
3077 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
3078 | - * |
|
3079 | - * @return string html |
|
3080 | - * @throws EE_Error |
|
3081 | - */ |
|
3082 | - protected function _get_main_nav_tabs() |
|
3083 | - { |
|
3084 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
3085 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
3086 | - // (rather than setting in the page_routes array) |
|
3087 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
3088 | - } |
|
3089 | - |
|
3090 | - |
|
3091 | - /** |
|
3092 | - * sort nav tabs |
|
3093 | - * |
|
3094 | - * @param $a |
|
3095 | - * @param $b |
|
3096 | - * @return int |
|
3097 | - */ |
|
3098 | - private function _sort_nav_tabs($a, $b) |
|
3099 | - { |
|
3100 | - if ($a['order'] === $b['order']) { |
|
3101 | - return 0; |
|
3102 | - } |
|
3103 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
3104 | - } |
|
3105 | - |
|
3106 | - |
|
3107 | - /** |
|
3108 | - * generates HTML for the forms used on admin pages |
|
3109 | - * |
|
3110 | - * @param array $input_vars - array of input field details |
|
3111 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
3112 | - * use) |
|
3113 | - * @param bool $id |
|
3114 | - * @return array|string |
|
3115 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
3116 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
3117 | - */ |
|
3118 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
3119 | - { |
|
3120 | - return $generator === 'string' |
|
3121 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
3122 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
3123 | - } |
|
3124 | - |
|
3125 | - |
|
3126 | - /** |
|
3127 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
3128 | - * |
|
3129 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
3130 | - * Close" button. |
|
3131 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
3132 | - * 'Save', [1] => 'save & close') |
|
3133 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
3134 | - * via the "name" value in the button). We can also use this to just dump |
|
3135 | - * default actions by submitting some other value. |
|
3136 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
3137 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
3138 | - * close (normal form handling). |
|
3139 | - */ |
|
3140 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
3141 | - { |
|
3142 | - // make sure $text and $actions are in an array |
|
3143 | - $text = (array) $text; |
|
3144 | - $actions = (array) $actions; |
|
3145 | - $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
3146 | - $button_text = ! empty($text) |
|
3147 | - ? $text |
|
3148 | - : [ |
|
3149 | - esc_html__('Save', 'event_espresso'), |
|
3150 | - esc_html__('Save and Close', 'event_espresso'), |
|
3151 | - ]; |
|
3152 | - $default_names = ['save', 'save_and_close']; |
|
3153 | - $buttons = ''; |
|
3154 | - foreach ($button_text as $key => $button) { |
|
3155 | - $ref = $default_names[ $key ]; |
|
3156 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
3157 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
3158 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
3159 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
3160 | - if (! $both) { |
|
3161 | - break; |
|
3162 | - } |
|
3163 | - } |
|
3164 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
3165 | - $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3166 | - . $referrer_url |
|
3167 | - . '" />'; |
|
3168 | - $this->_template_args['save_buttons'] = $buttons; |
|
3169 | - } |
|
3170 | - |
|
3171 | - |
|
3172 | - /** |
|
3173 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
3174 | - * |
|
3175 | - * @param string $route |
|
3176 | - * @param array $additional_hidden_fields |
|
3177 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
3178 | - * @since 4.6.0 |
|
3179 | - */ |
|
3180 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
3181 | - { |
|
3182 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
3183 | - } |
|
3184 | - |
|
3185 | - |
|
3186 | - /** |
|
3187 | - * set form open and close tags on add/edit pages. |
|
3188 | - * |
|
3189 | - * @param string $route the route you want the form to direct to |
|
3190 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
3191 | - * @return void |
|
3192 | - */ |
|
3193 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
3194 | - { |
|
3195 | - if (empty($route)) { |
|
3196 | - $user_msg = esc_html__( |
|
3197 | - 'An error occurred. No action was set for this page\'s form.', |
|
3198 | - 'event_espresso' |
|
3199 | - ); |
|
3200 | - $dev_msg = $user_msg . "\n" |
|
3201 | - . sprintf( |
|
3202 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
3203 | - __FUNCTION__, |
|
3204 | - __CLASS__ |
|
3205 | - ); |
|
3206 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3207 | - } |
|
3208 | - // open form |
|
3209 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
3210 | - . $this->_admin_base_url |
|
3211 | - . '" id="' |
|
3212 | - . $route |
|
3213 | - . '_event_form" >'; |
|
3214 | - // add nonce |
|
3215 | - $nonce = |
|
3216 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3217 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3218 | - // add REQUIRED form action |
|
3219 | - $hidden_fields = [ |
|
3220 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
3221 | - ]; |
|
3222 | - // merge arrays |
|
3223 | - $hidden_fields = is_array($additional_hidden_fields) |
|
3224 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
3225 | - : $hidden_fields; |
|
3226 | - // generate form fields |
|
3227 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
3228 | - // add fields to form |
|
3229 | - foreach ((array) $form_fields as $form_field) { |
|
3230 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3231 | - } |
|
3232 | - // close form |
|
3233 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
3234 | - } |
|
3235 | - |
|
3236 | - |
|
3237 | - /** |
|
3238 | - * Public Wrapper for _redirect_after_action() method since its |
|
3239 | - * discovered it would be useful for external code to have access. |
|
3240 | - * |
|
3241 | - * @param bool $success |
|
3242 | - * @param string $what |
|
3243 | - * @param string $action_desc |
|
3244 | - * @param array $query_args |
|
3245 | - * @param bool $override_overwrite |
|
3246 | - * @throws EE_Error |
|
3247 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
3248 | - * @since 4.5.0 |
|
3249 | - */ |
|
3250 | - public function redirect_after_action( |
|
3251 | - $success = false, |
|
3252 | - $what = 'item', |
|
3253 | - $action_desc = 'processed', |
|
3254 | - $query_args = [], |
|
3255 | - $override_overwrite = false |
|
3256 | - ) { |
|
3257 | - $this->_redirect_after_action( |
|
3258 | - $success, |
|
3259 | - $what, |
|
3260 | - $action_desc, |
|
3261 | - $query_args, |
|
3262 | - $override_overwrite |
|
3263 | - ); |
|
3264 | - } |
|
3265 | - |
|
3266 | - |
|
3267 | - /** |
|
3268 | - * Helper method for merging existing request data with the returned redirect url. |
|
3269 | - * |
|
3270 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
3271 | - * filters are still applied. |
|
3272 | - * |
|
3273 | - * @param array $new_route_data |
|
3274 | - * @return array |
|
3275 | - */ |
|
3276 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
3277 | - { |
|
3278 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
3279 | - // unset nonces |
|
3280 | - if (strpos($ref, 'nonce') !== false) { |
|
3281 | - $this->request->unSetRequestParam($ref); |
|
3282 | - continue; |
|
3283 | - } |
|
3284 | - // urlencode values. |
|
3285 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
3286 | - $this->request->setRequestParam($ref, $value); |
|
3287 | - } |
|
3288 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
3289 | - } |
|
3290 | - |
|
3291 | - |
|
3292 | - /** |
|
3293 | - * _redirect_after_action |
|
3294 | - * |
|
3295 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
3296 | - * @param string $what - what the action was performed on |
|
3297 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
3298 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
3299 | - * action is completed |
|
3300 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
3301 | - * override this so that they show. |
|
3302 | - * @return void |
|
3303 | - * @throws EE_Error |
|
3304 | - */ |
|
3305 | - protected function _redirect_after_action( |
|
3306 | - $success = 0, |
|
3307 | - $what = 'item', |
|
3308 | - $action_desc = 'processed', |
|
3309 | - $query_args = [], |
|
3310 | - $override_overwrite = false |
|
3311 | - ) { |
|
3312 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3313 | - // class name for actions/filters. |
|
3314 | - $classname = get_class($this); |
|
3315 | - // set redirect url. |
|
3316 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
3317 | - // otherwise we go with whatever is set as the _admin_base_url |
|
3318 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
3319 | - $notices = EE_Error::get_notices(false); |
|
3320 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
3321 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3322 | - EE_Error::overwrite_success(); |
|
3323 | - } |
|
3324 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3325 | - // how many records affected ? more than one record ? or just one ? |
|
3326 | - if ($success > 1) { |
|
3327 | - // set plural msg |
|
3328 | - EE_Error::add_success( |
|
3329 | - sprintf( |
|
3330 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
3331 | - $what, |
|
3332 | - $action_desc |
|
3333 | - ), |
|
3334 | - __FILE__, |
|
3335 | - __FUNCTION__, |
|
3336 | - __LINE__ |
|
3337 | - ); |
|
3338 | - } elseif ($success === 1) { |
|
3339 | - // set singular msg |
|
3340 | - EE_Error::add_success( |
|
3341 | - sprintf( |
|
3342 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
3343 | - $what, |
|
3344 | - $action_desc |
|
3345 | - ), |
|
3346 | - __FILE__, |
|
3347 | - __FUNCTION__, |
|
3348 | - __LINE__ |
|
3349 | - ); |
|
3350 | - } |
|
3351 | - } |
|
3352 | - // check that $query_args isn't something crazy |
|
3353 | - if (! is_array($query_args)) { |
|
3354 | - $query_args = []; |
|
3355 | - } |
|
3356 | - /** |
|
3357 | - * Allow injecting actions before the query_args are modified for possible different |
|
3358 | - * redirections on save and close actions |
|
3359 | - * |
|
3360 | - * @param array $query_args The original query_args array coming into the |
|
3361 | - * method. |
|
3362 | - * @since 4.2.0 |
|
3363 | - */ |
|
3364 | - do_action( |
|
3365 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
3366 | - $query_args |
|
3367 | - ); |
|
3368 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
3369 | - |
|
3370 | - if ( |
|
3371 | - $this->request->requestParamIsSet('save_and_close') |
|
3372 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
3373 | - ) { |
|
3374 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
3375 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
3376 | - // regenerate query args array from referrer URL |
|
3377 | - parse_str($parsed_url['query'], $query_args); |
|
3378 | - // correct page and action will be in the query args now |
|
3379 | - $redirect_url = admin_url('admin.php'); |
|
3380 | - } |
|
3381 | - // merge any default query_args set in _default_route_query_args property |
|
3382 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3383 | - $args_to_merge = []; |
|
3384 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
3385 | - // is there a wp_referer array in our _default_route_query_args property? |
|
3386 | - if ($query_param === 'wp_referer') { |
|
3387 | - $query_value = (array) $query_value; |
|
3388 | - foreach ($query_value as $reference => $value) { |
|
3389 | - if (strpos($reference, 'nonce') !== false) { |
|
3390 | - continue; |
|
3391 | - } |
|
3392 | - // finally we will override any arguments in the referer with |
|
3393 | - // what might be set on the _default_route_query_args array. |
|
3394 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
3395 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3396 | - } else { |
|
3397 | - $args_to_merge[ $reference ] = urlencode($value); |
|
3398 | - } |
|
3399 | - } |
|
3400 | - continue; |
|
3401 | - } |
|
3402 | - $args_to_merge[ $query_param ] = $query_value; |
|
3403 | - } |
|
3404 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
3405 | - // redirect. |
|
3406 | - $query_args = array_merge($args_to_merge, $query_args); |
|
3407 | - } |
|
3408 | - $this->_process_notices($query_args); |
|
3409 | - // generate redirect url |
|
3410 | - // if redirecting to anything other than the main page, add a nonce |
|
3411 | - if (isset($query_args['action'])) { |
|
3412 | - // manually generate wp_nonce and merge that with the query vars |
|
3413 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
3414 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3415 | - } |
|
3416 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
3417 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
3418 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3419 | - $redirect_url = apply_filters( |
|
3420 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3421 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
3422 | - $query_args |
|
3423 | - ); |
|
3424 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
3425 | - if ($this->request->isAjax()) { |
|
3426 | - $default_data = [ |
|
3427 | - 'close' => true, |
|
3428 | - 'redirect_url' => $redirect_url, |
|
3429 | - 'where' => 'main', |
|
3430 | - 'what' => 'append', |
|
3431 | - ]; |
|
3432 | - $this->_template_args['success'] = $success; |
|
3433 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
3434 | - $default_data, |
|
3435 | - $this->_template_args['data'] |
|
3436 | - ) : $default_data; |
|
3437 | - $this->_return_json(); |
|
3438 | - } |
|
3439 | - wp_safe_redirect($redirect_url); |
|
3440 | - exit(); |
|
3441 | - } |
|
3442 | - |
|
3443 | - |
|
3444 | - /** |
|
3445 | - * process any notices before redirecting (or returning ajax request) |
|
3446 | - * This method sets the $this->_template_args['notices'] attribute; |
|
3447 | - * |
|
3448 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
3449 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
3450 | - * page_routes haven't been defined yet. |
|
3451 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
3452 | - * still save a transient for the notice. |
|
3453 | - * @return void |
|
3454 | - * @throws EE_Error |
|
3455 | - */ |
|
3456 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
3457 | - { |
|
3458 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
3459 | - if ($this->request->isAjax()) { |
|
3460 | - $notices = EE_Error::get_notices(false); |
|
3461 | - if (empty($this->_template_args['success'])) { |
|
3462 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
3463 | - } |
|
3464 | - if (empty($this->_template_args['errors'])) { |
|
3465 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
3466 | - } |
|
3467 | - if (empty($this->_template_args['attention'])) { |
|
3468 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
3469 | - } |
|
3470 | - } |
|
3471 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
3472 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
3473 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
3474 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
3475 | - $this->_add_transient( |
|
3476 | - $route, |
|
3477 | - $this->_template_args['notices'], |
|
3478 | - true, |
|
3479 | - $skip_route_verify |
|
3480 | - ); |
|
3481 | - } |
|
3482 | - } |
|
3483 | - |
|
3484 | - |
|
3485 | - /** |
|
3486 | - * get_action_link_or_button |
|
3487 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
3488 | - * |
|
3489 | - * @param string $action use this to indicate which action the url is generated with. |
|
3490 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
3491 | - * property. |
|
3492 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
3493 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
3494 | - * @param string $base_url If this is not provided |
|
3495 | - * the _admin_base_url will be used as the default for the button base_url. |
|
3496 | - * Otherwise this value will be used. |
|
3497 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
3498 | - * @return string |
|
3499 | - * @throws InvalidArgumentException |
|
3500 | - * @throws InvalidInterfaceException |
|
3501 | - * @throws InvalidDataTypeException |
|
3502 | - * @throws EE_Error |
|
3503 | - */ |
|
3504 | - public function get_action_link_or_button( |
|
3505 | - $action, |
|
3506 | - $type = 'add', |
|
3507 | - $extra_request = [], |
|
3508 | - $class = 'button button--primary', |
|
3509 | - $base_url = '', |
|
3510 | - $exclude_nonce = false |
|
3511 | - ) { |
|
3512 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
3513 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3514 | - throw new EE_Error( |
|
3515 | - sprintf( |
|
3516 | - esc_html__( |
|
3517 | - 'There is no page route for given action for the button. This action was given: %s', |
|
3518 | - 'event_espresso' |
|
3519 | - ), |
|
3520 | - $action |
|
3521 | - ) |
|
3522 | - ); |
|
3523 | - } |
|
3524 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
3525 | - throw new EE_Error( |
|
3526 | - sprintf( |
|
3527 | - esc_html__( |
|
3528 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
3529 | - 'event_espresso' |
|
3530 | - ), |
|
3531 | - $type |
|
3532 | - ) |
|
3533 | - ); |
|
3534 | - } |
|
3535 | - // finally check user access for this button. |
|
3536 | - $has_access = $this->check_user_access($action, true); |
|
3537 | - if (! $has_access) { |
|
3538 | - return ''; |
|
3539 | - } |
|
3540 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
3541 | - $query_args = [ |
|
3542 | - 'action' => $action, |
|
3543 | - ]; |
|
3544 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
3545 | - if (! empty($extra_request)) { |
|
3546 | - $query_args = array_merge($extra_request, $query_args); |
|
3547 | - } |
|
3548 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
3549 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3550 | - } |
|
3551 | - |
|
3552 | - |
|
3553 | - /** |
|
3554 | - * _per_page_screen_option |
|
3555 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
3556 | - * |
|
3557 | - * @return void |
|
3558 | - * @throws InvalidArgumentException |
|
3559 | - * @throws InvalidInterfaceException |
|
3560 | - * @throws InvalidDataTypeException |
|
3561 | - */ |
|
3562 | - protected function _per_page_screen_option() |
|
3563 | - { |
|
3564 | - $option = 'per_page'; |
|
3565 | - $args = [ |
|
3566 | - 'label' => apply_filters( |
|
3567 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
3568 | - $this->_admin_page_title, |
|
3569 | - $this |
|
3570 | - ), |
|
3571 | - 'default' => (int) apply_filters( |
|
3572 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
3573 | - 20 |
|
3574 | - ), |
|
3575 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3576 | - ]; |
|
3577 | - // ONLY add the screen option if the user has access to it. |
|
3578 | - if ($this->check_user_access($this->_current_view, true)) { |
|
3579 | - add_screen_option($option, $args); |
|
3580 | - } |
|
3581 | - } |
|
3582 | - |
|
3583 | - |
|
3584 | - /** |
|
3585 | - * set_per_page_screen_option |
|
3586 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
3587 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
3588 | - * admin_menu. |
|
3589 | - * |
|
3590 | - * @return void |
|
3591 | - */ |
|
3592 | - private function _set_per_page_screen_options() |
|
3593 | - { |
|
3594 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
3595 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
3596 | - if (! $user = wp_get_current_user()) { |
|
3597 | - return; |
|
3598 | - } |
|
3599 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
3600 | - if (! $option) { |
|
3601 | - return; |
|
3602 | - } |
|
3603 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
3604 | - $map_option = $option; |
|
3605 | - $option = str_replace('-', '_', $option); |
|
3606 | - switch ($map_option) { |
|
3607 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3608 | - $max_value = apply_filters( |
|
3609 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
3610 | - 999, |
|
3611 | - $this->_current_page, |
|
3612 | - $this->_current_view |
|
3613 | - ); |
|
3614 | - if ($value < 1) { |
|
3615 | - return; |
|
3616 | - } |
|
3617 | - $value = min($value, $max_value); |
|
3618 | - break; |
|
3619 | - default: |
|
3620 | - $value = apply_filters( |
|
3621 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
3622 | - false, |
|
3623 | - $option, |
|
3624 | - $value |
|
3625 | - ); |
|
3626 | - if (false === $value) { |
|
3627 | - return; |
|
3628 | - } |
|
3629 | - break; |
|
3630 | - } |
|
3631 | - update_user_meta($user->ID, $option, $value); |
|
3632 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
3633 | - exit; |
|
3634 | - } |
|
3635 | - } |
|
3636 | - |
|
3637 | - |
|
3638 | - /** |
|
3639 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
3640 | - * |
|
3641 | - * @param array $data array that will be assigned to template args. |
|
3642 | - */ |
|
3643 | - public function set_template_args($data) |
|
3644 | - { |
|
3645 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
3646 | - } |
|
3647 | - |
|
3648 | - |
|
3649 | - /** |
|
3650 | - * This makes available the WP transient system for temporarily moving data between routes |
|
3651 | - * |
|
3652 | - * @param string $route the route that should receive the transient |
|
3653 | - * @param array $data the data that gets sent |
|
3654 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
3655 | - * normal route transient. |
|
3656 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
3657 | - * when we are adding a transient before page_routes have been defined. |
|
3658 | - * @return void |
|
3659 | - * @throws EE_Error |
|
3660 | - */ |
|
3661 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
3662 | - { |
|
3663 | - $user_id = get_current_user_id(); |
|
3664 | - if (! $skip_route_verify) { |
|
3665 | - $this->_verify_route($route); |
|
3666 | - } |
|
3667 | - // now let's set the string for what kind of transient we're setting |
|
3668 | - $transient = $notices |
|
3669 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3670 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3671 | - $data = $notices ? ['notices' => $data] : $data; |
|
3672 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
3673 | - $existing = is_multisite() && is_network_admin() |
|
3674 | - ? get_site_transient($transient) |
|
3675 | - : get_transient($transient); |
|
3676 | - if ($existing) { |
|
3677 | - $data = array_merge((array) $data, (array) $existing); |
|
3678 | - } |
|
3679 | - if (is_multisite() && is_network_admin()) { |
|
3680 | - set_site_transient($transient, $data, 8); |
|
3681 | - } else { |
|
3682 | - set_transient($transient, $data, 8); |
|
3683 | - } |
|
3684 | - } |
|
3685 | - |
|
3686 | - |
|
3687 | - /** |
|
3688 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
3689 | - * |
|
3690 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
3691 | - * @param string $route |
|
3692 | - * @return mixed data |
|
3693 | - */ |
|
3694 | - protected function _get_transient($notices = false, $route = '') |
|
3695 | - { |
|
3696 | - $user_id = get_current_user_id(); |
|
3697 | - $route = ! $route ? $this->_req_action : $route; |
|
3698 | - $transient = $notices |
|
3699 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3700 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3701 | - $data = is_multisite() && is_network_admin() |
|
3702 | - ? get_site_transient($transient) |
|
3703 | - : get_transient($transient); |
|
3704 | - // delete transient after retrieval (just in case it hasn't expired); |
|
3705 | - if (is_multisite() && is_network_admin()) { |
|
3706 | - delete_site_transient($transient); |
|
3707 | - } else { |
|
3708 | - delete_transient($transient); |
|
3709 | - } |
|
3710 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
3711 | - } |
|
3712 | - |
|
3713 | - |
|
3714 | - /** |
|
3715 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
3716 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
3717 | - * default route callback on the EE_Admin page you want it run.) |
|
3718 | - * |
|
3719 | - * @return void |
|
3720 | - */ |
|
3721 | - protected function _transient_garbage_collection() |
|
3722 | - { |
|
3723 | - global $wpdb; |
|
3724 | - // retrieve all existing transients |
|
3725 | - $query = |
|
3726 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
3727 | - if ($results = $wpdb->get_results($query)) { |
|
3728 | - foreach ($results as $result) { |
|
3729 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
3730 | - get_transient($transient); |
|
3731 | - if (is_multisite() && is_network_admin()) { |
|
3732 | - get_site_transient($transient); |
|
3733 | - } |
|
3734 | - } |
|
3735 | - } |
|
3736 | - } |
|
3737 | - |
|
3738 | - |
|
3739 | - /** |
|
3740 | - * get_view |
|
3741 | - * |
|
3742 | - * @return string content of _view property |
|
3743 | - */ |
|
3744 | - public function get_view() |
|
3745 | - { |
|
3746 | - return $this->_view; |
|
3747 | - } |
|
3748 | - |
|
3749 | - |
|
3750 | - /** |
|
3751 | - * getter for the protected $_views property |
|
3752 | - * |
|
3753 | - * @return array |
|
3754 | - */ |
|
3755 | - public function get_views() |
|
3756 | - { |
|
3757 | - return $this->_views; |
|
3758 | - } |
|
3759 | - |
|
3760 | - |
|
3761 | - /** |
|
3762 | - * get_current_page |
|
3763 | - * |
|
3764 | - * @return string _current_page property value |
|
3765 | - */ |
|
3766 | - public function get_current_page() |
|
3767 | - { |
|
3768 | - return $this->_current_page; |
|
3769 | - } |
|
3770 | - |
|
3771 | - |
|
3772 | - /** |
|
3773 | - * get_current_view |
|
3774 | - * |
|
3775 | - * @return string _current_view property value |
|
3776 | - */ |
|
3777 | - public function get_current_view() |
|
3778 | - { |
|
3779 | - return $this->_current_view; |
|
3780 | - } |
|
3781 | - |
|
3782 | - |
|
3783 | - /** |
|
3784 | - * get_current_screen |
|
3785 | - * |
|
3786 | - * @return object The current WP_Screen object |
|
3787 | - */ |
|
3788 | - public function get_current_screen() |
|
3789 | - { |
|
3790 | - return $this->_current_screen; |
|
3791 | - } |
|
3792 | - |
|
3793 | - |
|
3794 | - /** |
|
3795 | - * get_current_page_view_url |
|
3796 | - * |
|
3797 | - * @return string This returns the url for the current_page_view. |
|
3798 | - */ |
|
3799 | - public function get_current_page_view_url() |
|
3800 | - { |
|
3801 | - return $this->_current_page_view_url; |
|
3802 | - } |
|
3803 | - |
|
3804 | - |
|
3805 | - /** |
|
3806 | - * just returns the Request |
|
3807 | - * |
|
3808 | - * @return RequestInterface |
|
3809 | - */ |
|
3810 | - public function get_request() |
|
3811 | - { |
|
3812 | - return $this->request; |
|
3813 | - } |
|
3814 | - |
|
3815 | - |
|
3816 | - /** |
|
3817 | - * just returns the _req_data property |
|
3818 | - * |
|
3819 | - * @return array |
|
3820 | - */ |
|
3821 | - public function get_request_data() |
|
3822 | - { |
|
3823 | - return $this->request->requestParams(); |
|
3824 | - } |
|
3825 | - |
|
3826 | - |
|
3827 | - /** |
|
3828 | - * returns the _req_data protected property |
|
3829 | - * |
|
3830 | - * @return string |
|
3831 | - */ |
|
3832 | - public function get_req_action() |
|
3833 | - { |
|
3834 | - return $this->_req_action; |
|
3835 | - } |
|
3836 | - |
|
3837 | - |
|
3838 | - /** |
|
3839 | - * @return bool value of $_is_caf property |
|
3840 | - */ |
|
3841 | - public function is_caf() |
|
3842 | - { |
|
3843 | - return $this->_is_caf; |
|
3844 | - } |
|
3845 | - |
|
3846 | - |
|
3847 | - /** |
|
3848 | - * @return mixed |
|
3849 | - */ |
|
3850 | - public function default_espresso_metaboxes() |
|
3851 | - { |
|
3852 | - return $this->_default_espresso_metaboxes; |
|
3853 | - } |
|
3854 | - |
|
3855 | - |
|
3856 | - /** |
|
3857 | - * @return mixed |
|
3858 | - */ |
|
3859 | - public function admin_base_url() |
|
3860 | - { |
|
3861 | - return $this->_admin_base_url; |
|
3862 | - } |
|
3863 | - |
|
3864 | - |
|
3865 | - /** |
|
3866 | - * @return mixed |
|
3867 | - */ |
|
3868 | - public function wp_page_slug() |
|
3869 | - { |
|
3870 | - return $this->_wp_page_slug; |
|
3871 | - } |
|
3872 | - |
|
3873 | - |
|
3874 | - /** |
|
3875 | - * updates espresso configuration settings |
|
3876 | - * |
|
3877 | - * @param string $tab |
|
3878 | - * @param EE_Config_Base|EE_Config $config |
|
3879 | - * @param string $file file where error occurred |
|
3880 | - * @param string $func function where error occurred |
|
3881 | - * @param string $line line no where error occurred |
|
3882 | - * @return boolean |
|
3883 | - */ |
|
3884 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
3885 | - { |
|
3886 | - // remove any options that are NOT going to be saved with the config settings. |
|
3887 | - if (isset($config->core->ee_ueip_optin)) { |
|
3888 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
3889 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
3890 | - update_option('ee_ueip_has_notified', true); |
|
3891 | - } |
|
3892 | - // and save it (note we're also doing the network save here) |
|
3893 | - $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
3894 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
3895 | - if ($config_saved && $net_saved) { |
|
3896 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
3897 | - return true; |
|
3898 | - } |
|
3899 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
3900 | - return false; |
|
3901 | - } |
|
3902 | - |
|
3903 | - |
|
3904 | - /** |
|
3905 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
3906 | - * |
|
3907 | - * @return array |
|
3908 | - */ |
|
3909 | - public function get_yes_no_values() |
|
3910 | - { |
|
3911 | - return $this->_yes_no_values; |
|
3912 | - } |
|
3913 | - |
|
3914 | - |
|
3915 | - protected function _get_dir() |
|
3916 | - { |
|
3917 | - $reflector = new ReflectionClass(get_class($this)); |
|
3918 | - return dirname($reflector->getFileName()); |
|
3919 | - } |
|
3920 | - |
|
3921 | - |
|
3922 | - /** |
|
3923 | - * A helper for getting a "next link". |
|
3924 | - * |
|
3925 | - * @param string $url The url to link to |
|
3926 | - * @param string $class The class to use. |
|
3927 | - * @return string |
|
3928 | - */ |
|
3929 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
3930 | - { |
|
3931 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3932 | - } |
|
3933 | - |
|
3934 | - |
|
3935 | - /** |
|
3936 | - * A helper for getting a "previous link". |
|
3937 | - * |
|
3938 | - * @param string $url The url to link to |
|
3939 | - * @param string $class The class to use. |
|
3940 | - * @return string |
|
3941 | - */ |
|
3942 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
3943 | - { |
|
3944 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3945 | - } |
|
3946 | - |
|
3947 | - |
|
3948 | - |
|
3949 | - |
|
3950 | - |
|
3951 | - |
|
3952 | - |
|
3953 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
3954 | - |
|
3955 | - |
|
3956 | - /** |
|
3957 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
3958 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
3959 | - * _req_data array. |
|
3960 | - * |
|
3961 | - * @return bool success/fail |
|
3962 | - * @throws EE_Error |
|
3963 | - * @throws InvalidArgumentException |
|
3964 | - * @throws ReflectionException |
|
3965 | - * @throws InvalidDataTypeException |
|
3966 | - * @throws InvalidInterfaceException |
|
3967 | - */ |
|
3968 | - protected function _process_resend_registration() |
|
3969 | - { |
|
3970 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
3971 | - do_action( |
|
3972 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
3973 | - $this->_template_args['success'], |
|
3974 | - $this->request->requestParams() |
|
3975 | - ); |
|
3976 | - return $this->_template_args['success']; |
|
3977 | - } |
|
3978 | - |
|
3979 | - |
|
3980 | - /** |
|
3981 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
3982 | - * |
|
3983 | - * @param EE_Payment $payment |
|
3984 | - * @return bool success/fail |
|
3985 | - */ |
|
3986 | - protected function _process_payment_notification(EE_Payment $payment) |
|
3987 | - { |
|
3988 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
3989 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
3990 | - $this->_template_args['success'] = apply_filters( |
|
3991 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
3992 | - false, |
|
3993 | - $payment |
|
3994 | - ); |
|
3995 | - return $this->_template_args['success']; |
|
3996 | - } |
|
3997 | - |
|
3998 | - |
|
3999 | - /** |
|
4000 | - * @param EEM_Base $entity_model |
|
4001 | - * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
4002 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
4003 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
4004 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
4005 | - * @return int|float |
|
4006 | - * @throws EE_Error |
|
4007 | - */ |
|
4008 | - protected function trashRestoreDeleteEntities( |
|
4009 | - EEM_Base $entity_model, |
|
4010 | - string $entity_PK_name, |
|
4011 | - string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
4012 | - string $delete_column = '', |
|
4013 | - callable $callback = null |
|
4014 | - ) { |
|
4015 | - $entity_PK = $entity_model->get_primary_key_field(); |
|
4016 | - $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
4017 | - $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
4018 | - // grab ID if deleting a single entity |
|
4019 | - if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
4020 | - $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
4021 | - return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
4022 | - } |
|
4023 | - // or grab checkbox array if bulk deleting |
|
4024 | - $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
4025 | - if (empty($checkboxes)) { |
|
4026 | - return 0; |
|
4027 | - } |
|
4028 | - $success = 0; |
|
4029 | - $IDs = array_keys($checkboxes); |
|
4030 | - // cycle thru bulk action checkboxes |
|
4031 | - foreach ($IDs as $ID) { |
|
4032 | - // increment $success |
|
4033 | - if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
4034 | - $success++; |
|
4035 | - } |
|
4036 | - } |
|
4037 | - $count = (int) count($checkboxes); |
|
4038 | - // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
4039 | - // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
4040 | - return $success === $count ? $count : $success / $count; |
|
4041 | - } |
|
4042 | - |
|
4043 | - |
|
4044 | - /** |
|
4045 | - * @param EE_Primary_Key_Field_Base $entity_PK |
|
4046 | - * @return string |
|
4047 | - * @throws EE_Error |
|
4048 | - * @since 4.10.30.p |
|
4049 | - */ |
|
4050 | - private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
4051 | - { |
|
4052 | - $entity_PK_type = $entity_PK->getSchemaType(); |
|
4053 | - switch ($entity_PK_type) { |
|
4054 | - case 'boolean': |
|
4055 | - return 'bool'; |
|
4056 | - case 'integer': |
|
4057 | - return 'int'; |
|
4058 | - case 'number': |
|
4059 | - return 'float'; |
|
4060 | - case 'string': |
|
4061 | - return 'string'; |
|
4062 | - } |
|
4063 | - throw new RuntimeException( |
|
4064 | - sprintf( |
|
4065 | - esc_html__( |
|
4066 | - '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
4067 | - 'event_espresso' |
|
4068 | - ), |
|
4069 | - $entity_PK_type, |
|
4070 | - $entity_PK->get_name() |
|
4071 | - ) |
|
4072 | - ); |
|
4073 | - } |
|
4074 | - |
|
4075 | - |
|
4076 | - /** |
|
4077 | - * @param EEM_Base $entity_model |
|
4078 | - * @param int|string $entity_ID |
|
4079 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
4080 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
4081 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
4082 | - * @return bool |
|
4083 | - */ |
|
4084 | - protected function trashRestoreDeleteEntity( |
|
4085 | - EEM_Base $entity_model, |
|
4086 | - $entity_ID, |
|
4087 | - string $action, |
|
4088 | - string $delete_column, |
|
4089 | - callable $callback = null |
|
4090 | - ) { |
|
4091 | - $entity_ID = absint($entity_ID); |
|
4092 | - if (! $entity_ID) { |
|
4093 | - $this->trashRestoreDeleteError($action, $entity_model); |
|
4094 | - } |
|
4095 | - $result = 0; |
|
4096 | - try { |
|
4097 | - switch ($action) { |
|
4098 | - case EE_Admin_List_Table::ACTION_DELETE: |
|
4099 | - $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
4100 | - break; |
|
4101 | - case EE_Admin_List_Table::ACTION_RESTORE: |
|
4102 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
4103 | - $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
4104 | - break; |
|
4105 | - case EE_Admin_List_Table::ACTION_TRASH: |
|
4106 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
4107 | - $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
4108 | - break; |
|
4109 | - } |
|
4110 | - } catch (Exception $exception) { |
|
4111 | - $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
4112 | - } |
|
4113 | - if (is_callable($callback)) { |
|
4114 | - call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
4115 | - } |
|
4116 | - return $result; |
|
4117 | - } |
|
4118 | - |
|
4119 | - |
|
4120 | - /** |
|
4121 | - * @param EEM_Base $entity_model |
|
4122 | - * @param string $delete_column |
|
4123 | - * @since 4.10.30.p |
|
4124 | - */ |
|
4125 | - private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
4126 | - { |
|
4127 | - if (empty($delete_column)) { |
|
4128 | - throw new DomainException( |
|
4129 | - sprintf( |
|
4130 | - esc_html__( |
|
4131 | - 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
4132 | - 'event_espresso' |
|
4133 | - ), |
|
4134 | - $entity_model->get_this_model_name() |
|
4135 | - ) |
|
4136 | - ); |
|
4137 | - } |
|
4138 | - if (! $entity_model->has_field($delete_column)) { |
|
4139 | - throw new DomainException( |
|
4140 | - sprintf( |
|
4141 | - esc_html__( |
|
4142 | - 'The %1$s field does not exist on the %2$s model.', |
|
4143 | - 'event_espresso' |
|
4144 | - ), |
|
4145 | - $delete_column, |
|
4146 | - $entity_model->get_this_model_name() |
|
4147 | - ) |
|
4148 | - ); |
|
4149 | - } |
|
4150 | - } |
|
4151 | - |
|
4152 | - |
|
4153 | - /** |
|
4154 | - * @param EEM_Base $entity_model |
|
4155 | - * @param Exception|null $exception |
|
4156 | - * @param string $action |
|
4157 | - * @since 4.10.30.p |
|
4158 | - */ |
|
4159 | - private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
4160 | - { |
|
4161 | - if ($exception instanceof Exception) { |
|
4162 | - throw new RuntimeException( |
|
4163 | - sprintf( |
|
4164 | - esc_html__( |
|
4165 | - 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
4166 | - 'event_espresso' |
|
4167 | - ), |
|
4168 | - $action, |
|
4169 | - $entity_model->get_this_model_name(), |
|
4170 | - $exception->getMessage() |
|
4171 | - ) |
|
4172 | - ); |
|
4173 | - } |
|
4174 | - throw new RuntimeException( |
|
4175 | - sprintf( |
|
4176 | - esc_html__( |
|
4177 | - 'Could not %1$s the %2$s because an invalid ID was received.', |
|
4178 | - 'event_espresso' |
|
4179 | - ), |
|
4180 | - $action, |
|
4181 | - $entity_model->get_this_model_name() |
|
4182 | - ) |
|
4183 | - ); |
|
4184 | - } |
|
2853 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2854 | + // display message about search results? |
|
2855 | + $search = $this->request->getRequestParam('s'); |
|
2856 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
2857 | + ? '<p class="ee-search-results">' . sprintf( |
|
2858 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
2859 | + trim($search, '%') |
|
2860 | + ) . '</p>' |
|
2861 | + : ''; |
|
2862 | + // filter before_list_table template arg |
|
2863 | + $this->_template_args['before_list_table'] = apply_filters( |
|
2864 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
2865 | + $this->_template_args['before_list_table'], |
|
2866 | + $this->page_slug, |
|
2867 | + $this->request->requestParams(), |
|
2868 | + $this->_req_action |
|
2869 | + ); |
|
2870 | + // convert to array and filter again |
|
2871 | + // arrays are easier to inject new items in a specific location, |
|
2872 | + // but would not be backwards compatible, so we have to add a new filter |
|
2873 | + $this->_template_args['before_list_table'] = implode( |
|
2874 | + " \n", |
|
2875 | + (array) apply_filters( |
|
2876 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
2877 | + (array) $this->_template_args['before_list_table'], |
|
2878 | + $this->page_slug, |
|
2879 | + $this->request->requestParams(), |
|
2880 | + $this->_req_action |
|
2881 | + ) |
|
2882 | + ); |
|
2883 | + // filter after_list_table template arg |
|
2884 | + $this->_template_args['after_list_table'] = apply_filters( |
|
2885 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
2886 | + $this->_template_args['after_list_table'], |
|
2887 | + $this->page_slug, |
|
2888 | + $this->request->requestParams(), |
|
2889 | + $this->_req_action |
|
2890 | + ); |
|
2891 | + // convert to array and filter again |
|
2892 | + // arrays are easier to inject new items in a specific location, |
|
2893 | + // but would not be backwards compatible, so we have to add a new filter |
|
2894 | + $this->_template_args['after_list_table'] = implode( |
|
2895 | + " \n", |
|
2896 | + (array) apply_filters( |
|
2897 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
2898 | + (array) $this->_template_args['after_list_table'], |
|
2899 | + $this->page_slug, |
|
2900 | + $this->request->requestParams(), |
|
2901 | + $this->_req_action |
|
2902 | + ) |
|
2903 | + ); |
|
2904 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2905 | + $template_path, |
|
2906 | + $this->_template_args, |
|
2907 | + true |
|
2908 | + ); |
|
2909 | + // the final template wrapper |
|
2910 | + if ($sidebar) { |
|
2911 | + $this->display_admin_page_with_sidebar(); |
|
2912 | + } else { |
|
2913 | + $this->display_admin_page_with_no_sidebar(); |
|
2914 | + } |
|
2915 | + } |
|
2916 | + |
|
2917 | + |
|
2918 | + /** |
|
2919 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
2920 | + * html string for the legend. |
|
2921 | + * $items are expected in an array in the following format: |
|
2922 | + * $legend_items = array( |
|
2923 | + * 'item_id' => array( |
|
2924 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
2925 | + * 'desc' => esc_html__('localized description of item'); |
|
2926 | + * ) |
|
2927 | + * ); |
|
2928 | + * |
|
2929 | + * @param array $items see above for format of array |
|
2930 | + * @return string html string of legend |
|
2931 | + * @throws DomainException |
|
2932 | + */ |
|
2933 | + protected function _display_legend($items) |
|
2934 | + { |
|
2935 | + $this->_template_args['items'] = apply_filters( |
|
2936 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
2937 | + (array) $items, |
|
2938 | + $this |
|
2939 | + ); |
|
2940 | + return EEH_Template::display_template( |
|
2941 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
2942 | + $this->_template_args, |
|
2943 | + true |
|
2944 | + ); |
|
2945 | + } |
|
2946 | + |
|
2947 | + |
|
2948 | + /** |
|
2949 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
2950 | + * The returned json object is created from an array in the following format: |
|
2951 | + * array( |
|
2952 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
2953 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
2954 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
2955 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
2956 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
2957 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
2958 | + * that might be included in here) |
|
2959 | + * ) |
|
2960 | + * The json object is populated by whatever is set in the $_template_args property. |
|
2961 | + * |
|
2962 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
2963 | + * instead of displayed. |
|
2964 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
2965 | + * @return void |
|
2966 | + * @throws EE_Error |
|
2967 | + */ |
|
2968 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
2969 | + { |
|
2970 | + // make sure any EE_Error notices have been handled. |
|
2971 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
2972 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
2973 | + unset($this->_template_args['data']); |
|
2974 | + $json = [ |
|
2975 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
2976 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
2977 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
2978 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
2979 | + 'notices' => EE_Error::get_notices(), |
|
2980 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
2981 | + ? $this->_template_args['admin_page_content'] : '', |
|
2982 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
2983 | + 'isEEajax' => true |
|
2984 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
2985 | + ]; |
|
2986 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
2987 | + if (null === error_get_last() || ! headers_sent()) { |
|
2988 | + header('Content-Type: application/json; charset=UTF-8'); |
|
2989 | + } |
|
2990 | + echo wp_json_encode($json); |
|
2991 | + exit(); |
|
2992 | + } |
|
2993 | + |
|
2994 | + |
|
2995 | + /** |
|
2996 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
2997 | + * |
|
2998 | + * @return void |
|
2999 | + * @throws EE_Error |
|
3000 | + */ |
|
3001 | + public function return_json() |
|
3002 | + { |
|
3003 | + if ($this->request->isAjax()) { |
|
3004 | + $this->_return_json(); |
|
3005 | + } else { |
|
3006 | + throw new EE_Error( |
|
3007 | + sprintf( |
|
3008 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
3009 | + __FUNCTION__ |
|
3010 | + ) |
|
3011 | + ); |
|
3012 | + } |
|
3013 | + } |
|
3014 | + |
|
3015 | + |
|
3016 | + /** |
|
3017 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
3018 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
3019 | + * |
|
3020 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
3021 | + */ |
|
3022 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
3023 | + { |
|
3024 | + $this->_hook_obj = $hook_obj; |
|
3025 | + } |
|
3026 | + |
|
3027 | + |
|
3028 | + /** |
|
3029 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
3030 | + * |
|
3031 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
3032 | + * @return void |
|
3033 | + * @throws DomainException |
|
3034 | + * @throws EE_Error |
|
3035 | + */ |
|
3036 | + public function admin_page_wrapper($about = false) |
|
3037 | + { |
|
3038 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3039 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
3040 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
3041 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
3042 | + |
|
3043 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
3044 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3045 | + isset($this->_template_args['before_admin_page_content']) |
|
3046 | + ? $this->_template_args['before_admin_page_content'] |
|
3047 | + : '' |
|
3048 | + ); |
|
3049 | + |
|
3050 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3051 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3052 | + isset($this->_template_args['after_admin_page_content']) |
|
3053 | + ? $this->_template_args['after_admin_page_content'] |
|
3054 | + : '' |
|
3055 | + ); |
|
3056 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3057 | + |
|
3058 | + if ($this->request->isAjax()) { |
|
3059 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3060 | + // $template_path, |
|
3061 | + EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
3062 | + $this->_template_args, |
|
3063 | + true |
|
3064 | + ); |
|
3065 | + $this->_return_json(); |
|
3066 | + } |
|
3067 | + // load settings page wrapper template |
|
3068 | + $template_path = $about |
|
3069 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
3070 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
3071 | + |
|
3072 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
3073 | + } |
|
3074 | + |
|
3075 | + |
|
3076 | + /** |
|
3077 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
3078 | + * |
|
3079 | + * @return string html |
|
3080 | + * @throws EE_Error |
|
3081 | + */ |
|
3082 | + protected function _get_main_nav_tabs() |
|
3083 | + { |
|
3084 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
3085 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
3086 | + // (rather than setting in the page_routes array) |
|
3087 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
3088 | + } |
|
3089 | + |
|
3090 | + |
|
3091 | + /** |
|
3092 | + * sort nav tabs |
|
3093 | + * |
|
3094 | + * @param $a |
|
3095 | + * @param $b |
|
3096 | + * @return int |
|
3097 | + */ |
|
3098 | + private function _sort_nav_tabs($a, $b) |
|
3099 | + { |
|
3100 | + if ($a['order'] === $b['order']) { |
|
3101 | + return 0; |
|
3102 | + } |
|
3103 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
3104 | + } |
|
3105 | + |
|
3106 | + |
|
3107 | + /** |
|
3108 | + * generates HTML for the forms used on admin pages |
|
3109 | + * |
|
3110 | + * @param array $input_vars - array of input field details |
|
3111 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
3112 | + * use) |
|
3113 | + * @param bool $id |
|
3114 | + * @return array|string |
|
3115 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
3116 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
3117 | + */ |
|
3118 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
3119 | + { |
|
3120 | + return $generator === 'string' |
|
3121 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
3122 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
3123 | + } |
|
3124 | + |
|
3125 | + |
|
3126 | + /** |
|
3127 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
3128 | + * |
|
3129 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
3130 | + * Close" button. |
|
3131 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
3132 | + * 'Save', [1] => 'save & close') |
|
3133 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
3134 | + * via the "name" value in the button). We can also use this to just dump |
|
3135 | + * default actions by submitting some other value. |
|
3136 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
3137 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
3138 | + * close (normal form handling). |
|
3139 | + */ |
|
3140 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
3141 | + { |
|
3142 | + // make sure $text and $actions are in an array |
|
3143 | + $text = (array) $text; |
|
3144 | + $actions = (array) $actions; |
|
3145 | + $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
3146 | + $button_text = ! empty($text) |
|
3147 | + ? $text |
|
3148 | + : [ |
|
3149 | + esc_html__('Save', 'event_espresso'), |
|
3150 | + esc_html__('Save and Close', 'event_espresso'), |
|
3151 | + ]; |
|
3152 | + $default_names = ['save', 'save_and_close']; |
|
3153 | + $buttons = ''; |
|
3154 | + foreach ($button_text as $key => $button) { |
|
3155 | + $ref = $default_names[ $key ]; |
|
3156 | + $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
3157 | + $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
3158 | + . 'value="' . $button . '" name="' . $name . '" ' |
|
3159 | + . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
3160 | + if (! $both) { |
|
3161 | + break; |
|
3162 | + } |
|
3163 | + } |
|
3164 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
3165 | + $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3166 | + . $referrer_url |
|
3167 | + . '" />'; |
|
3168 | + $this->_template_args['save_buttons'] = $buttons; |
|
3169 | + } |
|
3170 | + |
|
3171 | + |
|
3172 | + /** |
|
3173 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
3174 | + * |
|
3175 | + * @param string $route |
|
3176 | + * @param array $additional_hidden_fields |
|
3177 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
3178 | + * @since 4.6.0 |
|
3179 | + */ |
|
3180 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
3181 | + { |
|
3182 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
3183 | + } |
|
3184 | + |
|
3185 | + |
|
3186 | + /** |
|
3187 | + * set form open and close tags on add/edit pages. |
|
3188 | + * |
|
3189 | + * @param string $route the route you want the form to direct to |
|
3190 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
3191 | + * @return void |
|
3192 | + */ |
|
3193 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
3194 | + { |
|
3195 | + if (empty($route)) { |
|
3196 | + $user_msg = esc_html__( |
|
3197 | + 'An error occurred. No action was set for this page\'s form.', |
|
3198 | + 'event_espresso' |
|
3199 | + ); |
|
3200 | + $dev_msg = $user_msg . "\n" |
|
3201 | + . sprintf( |
|
3202 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
3203 | + __FUNCTION__, |
|
3204 | + __CLASS__ |
|
3205 | + ); |
|
3206 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3207 | + } |
|
3208 | + // open form |
|
3209 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
3210 | + . $this->_admin_base_url |
|
3211 | + . '" id="' |
|
3212 | + . $route |
|
3213 | + . '_event_form" >'; |
|
3214 | + // add nonce |
|
3215 | + $nonce = |
|
3216 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3217 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3218 | + // add REQUIRED form action |
|
3219 | + $hidden_fields = [ |
|
3220 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
3221 | + ]; |
|
3222 | + // merge arrays |
|
3223 | + $hidden_fields = is_array($additional_hidden_fields) |
|
3224 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
3225 | + : $hidden_fields; |
|
3226 | + // generate form fields |
|
3227 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
3228 | + // add fields to form |
|
3229 | + foreach ((array) $form_fields as $form_field) { |
|
3230 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3231 | + } |
|
3232 | + // close form |
|
3233 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
3234 | + } |
|
3235 | + |
|
3236 | + |
|
3237 | + /** |
|
3238 | + * Public Wrapper for _redirect_after_action() method since its |
|
3239 | + * discovered it would be useful for external code to have access. |
|
3240 | + * |
|
3241 | + * @param bool $success |
|
3242 | + * @param string $what |
|
3243 | + * @param string $action_desc |
|
3244 | + * @param array $query_args |
|
3245 | + * @param bool $override_overwrite |
|
3246 | + * @throws EE_Error |
|
3247 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
3248 | + * @since 4.5.0 |
|
3249 | + */ |
|
3250 | + public function redirect_after_action( |
|
3251 | + $success = false, |
|
3252 | + $what = 'item', |
|
3253 | + $action_desc = 'processed', |
|
3254 | + $query_args = [], |
|
3255 | + $override_overwrite = false |
|
3256 | + ) { |
|
3257 | + $this->_redirect_after_action( |
|
3258 | + $success, |
|
3259 | + $what, |
|
3260 | + $action_desc, |
|
3261 | + $query_args, |
|
3262 | + $override_overwrite |
|
3263 | + ); |
|
3264 | + } |
|
3265 | + |
|
3266 | + |
|
3267 | + /** |
|
3268 | + * Helper method for merging existing request data with the returned redirect url. |
|
3269 | + * |
|
3270 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
3271 | + * filters are still applied. |
|
3272 | + * |
|
3273 | + * @param array $new_route_data |
|
3274 | + * @return array |
|
3275 | + */ |
|
3276 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
3277 | + { |
|
3278 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
3279 | + // unset nonces |
|
3280 | + if (strpos($ref, 'nonce') !== false) { |
|
3281 | + $this->request->unSetRequestParam($ref); |
|
3282 | + continue; |
|
3283 | + } |
|
3284 | + // urlencode values. |
|
3285 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
3286 | + $this->request->setRequestParam($ref, $value); |
|
3287 | + } |
|
3288 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
3289 | + } |
|
3290 | + |
|
3291 | + |
|
3292 | + /** |
|
3293 | + * _redirect_after_action |
|
3294 | + * |
|
3295 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
3296 | + * @param string $what - what the action was performed on |
|
3297 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
3298 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
3299 | + * action is completed |
|
3300 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
3301 | + * override this so that they show. |
|
3302 | + * @return void |
|
3303 | + * @throws EE_Error |
|
3304 | + */ |
|
3305 | + protected function _redirect_after_action( |
|
3306 | + $success = 0, |
|
3307 | + $what = 'item', |
|
3308 | + $action_desc = 'processed', |
|
3309 | + $query_args = [], |
|
3310 | + $override_overwrite = false |
|
3311 | + ) { |
|
3312 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3313 | + // class name for actions/filters. |
|
3314 | + $classname = get_class($this); |
|
3315 | + // set redirect url. |
|
3316 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
3317 | + // otherwise we go with whatever is set as the _admin_base_url |
|
3318 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
3319 | + $notices = EE_Error::get_notices(false); |
|
3320 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
3321 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3322 | + EE_Error::overwrite_success(); |
|
3323 | + } |
|
3324 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3325 | + // how many records affected ? more than one record ? or just one ? |
|
3326 | + if ($success > 1) { |
|
3327 | + // set plural msg |
|
3328 | + EE_Error::add_success( |
|
3329 | + sprintf( |
|
3330 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
3331 | + $what, |
|
3332 | + $action_desc |
|
3333 | + ), |
|
3334 | + __FILE__, |
|
3335 | + __FUNCTION__, |
|
3336 | + __LINE__ |
|
3337 | + ); |
|
3338 | + } elseif ($success === 1) { |
|
3339 | + // set singular msg |
|
3340 | + EE_Error::add_success( |
|
3341 | + sprintf( |
|
3342 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
3343 | + $what, |
|
3344 | + $action_desc |
|
3345 | + ), |
|
3346 | + __FILE__, |
|
3347 | + __FUNCTION__, |
|
3348 | + __LINE__ |
|
3349 | + ); |
|
3350 | + } |
|
3351 | + } |
|
3352 | + // check that $query_args isn't something crazy |
|
3353 | + if (! is_array($query_args)) { |
|
3354 | + $query_args = []; |
|
3355 | + } |
|
3356 | + /** |
|
3357 | + * Allow injecting actions before the query_args are modified for possible different |
|
3358 | + * redirections on save and close actions |
|
3359 | + * |
|
3360 | + * @param array $query_args The original query_args array coming into the |
|
3361 | + * method. |
|
3362 | + * @since 4.2.0 |
|
3363 | + */ |
|
3364 | + do_action( |
|
3365 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
3366 | + $query_args |
|
3367 | + ); |
|
3368 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
3369 | + |
|
3370 | + if ( |
|
3371 | + $this->request->requestParamIsSet('save_and_close') |
|
3372 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
3373 | + ) { |
|
3374 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
3375 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
3376 | + // regenerate query args array from referrer URL |
|
3377 | + parse_str($parsed_url['query'], $query_args); |
|
3378 | + // correct page and action will be in the query args now |
|
3379 | + $redirect_url = admin_url('admin.php'); |
|
3380 | + } |
|
3381 | + // merge any default query_args set in _default_route_query_args property |
|
3382 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3383 | + $args_to_merge = []; |
|
3384 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
3385 | + // is there a wp_referer array in our _default_route_query_args property? |
|
3386 | + if ($query_param === 'wp_referer') { |
|
3387 | + $query_value = (array) $query_value; |
|
3388 | + foreach ($query_value as $reference => $value) { |
|
3389 | + if (strpos($reference, 'nonce') !== false) { |
|
3390 | + continue; |
|
3391 | + } |
|
3392 | + // finally we will override any arguments in the referer with |
|
3393 | + // what might be set on the _default_route_query_args array. |
|
3394 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
3395 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3396 | + } else { |
|
3397 | + $args_to_merge[ $reference ] = urlencode($value); |
|
3398 | + } |
|
3399 | + } |
|
3400 | + continue; |
|
3401 | + } |
|
3402 | + $args_to_merge[ $query_param ] = $query_value; |
|
3403 | + } |
|
3404 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
3405 | + // redirect. |
|
3406 | + $query_args = array_merge($args_to_merge, $query_args); |
|
3407 | + } |
|
3408 | + $this->_process_notices($query_args); |
|
3409 | + // generate redirect url |
|
3410 | + // if redirecting to anything other than the main page, add a nonce |
|
3411 | + if (isset($query_args['action'])) { |
|
3412 | + // manually generate wp_nonce and merge that with the query vars |
|
3413 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
3414 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3415 | + } |
|
3416 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
3417 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
3418 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3419 | + $redirect_url = apply_filters( |
|
3420 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3421 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
3422 | + $query_args |
|
3423 | + ); |
|
3424 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
3425 | + if ($this->request->isAjax()) { |
|
3426 | + $default_data = [ |
|
3427 | + 'close' => true, |
|
3428 | + 'redirect_url' => $redirect_url, |
|
3429 | + 'where' => 'main', |
|
3430 | + 'what' => 'append', |
|
3431 | + ]; |
|
3432 | + $this->_template_args['success'] = $success; |
|
3433 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
3434 | + $default_data, |
|
3435 | + $this->_template_args['data'] |
|
3436 | + ) : $default_data; |
|
3437 | + $this->_return_json(); |
|
3438 | + } |
|
3439 | + wp_safe_redirect($redirect_url); |
|
3440 | + exit(); |
|
3441 | + } |
|
3442 | + |
|
3443 | + |
|
3444 | + /** |
|
3445 | + * process any notices before redirecting (or returning ajax request) |
|
3446 | + * This method sets the $this->_template_args['notices'] attribute; |
|
3447 | + * |
|
3448 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
3449 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
3450 | + * page_routes haven't been defined yet. |
|
3451 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
3452 | + * still save a transient for the notice. |
|
3453 | + * @return void |
|
3454 | + * @throws EE_Error |
|
3455 | + */ |
|
3456 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
3457 | + { |
|
3458 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
3459 | + if ($this->request->isAjax()) { |
|
3460 | + $notices = EE_Error::get_notices(false); |
|
3461 | + if (empty($this->_template_args['success'])) { |
|
3462 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
3463 | + } |
|
3464 | + if (empty($this->_template_args['errors'])) { |
|
3465 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
3466 | + } |
|
3467 | + if (empty($this->_template_args['attention'])) { |
|
3468 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
3469 | + } |
|
3470 | + } |
|
3471 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
3472 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
3473 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
3474 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
3475 | + $this->_add_transient( |
|
3476 | + $route, |
|
3477 | + $this->_template_args['notices'], |
|
3478 | + true, |
|
3479 | + $skip_route_verify |
|
3480 | + ); |
|
3481 | + } |
|
3482 | + } |
|
3483 | + |
|
3484 | + |
|
3485 | + /** |
|
3486 | + * get_action_link_or_button |
|
3487 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
3488 | + * |
|
3489 | + * @param string $action use this to indicate which action the url is generated with. |
|
3490 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
3491 | + * property. |
|
3492 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
3493 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
3494 | + * @param string $base_url If this is not provided |
|
3495 | + * the _admin_base_url will be used as the default for the button base_url. |
|
3496 | + * Otherwise this value will be used. |
|
3497 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
3498 | + * @return string |
|
3499 | + * @throws InvalidArgumentException |
|
3500 | + * @throws InvalidInterfaceException |
|
3501 | + * @throws InvalidDataTypeException |
|
3502 | + * @throws EE_Error |
|
3503 | + */ |
|
3504 | + public function get_action_link_or_button( |
|
3505 | + $action, |
|
3506 | + $type = 'add', |
|
3507 | + $extra_request = [], |
|
3508 | + $class = 'button button--primary', |
|
3509 | + $base_url = '', |
|
3510 | + $exclude_nonce = false |
|
3511 | + ) { |
|
3512 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
3513 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3514 | + throw new EE_Error( |
|
3515 | + sprintf( |
|
3516 | + esc_html__( |
|
3517 | + 'There is no page route for given action for the button. This action was given: %s', |
|
3518 | + 'event_espresso' |
|
3519 | + ), |
|
3520 | + $action |
|
3521 | + ) |
|
3522 | + ); |
|
3523 | + } |
|
3524 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
3525 | + throw new EE_Error( |
|
3526 | + sprintf( |
|
3527 | + esc_html__( |
|
3528 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
3529 | + 'event_espresso' |
|
3530 | + ), |
|
3531 | + $type |
|
3532 | + ) |
|
3533 | + ); |
|
3534 | + } |
|
3535 | + // finally check user access for this button. |
|
3536 | + $has_access = $this->check_user_access($action, true); |
|
3537 | + if (! $has_access) { |
|
3538 | + return ''; |
|
3539 | + } |
|
3540 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
3541 | + $query_args = [ |
|
3542 | + 'action' => $action, |
|
3543 | + ]; |
|
3544 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
3545 | + if (! empty($extra_request)) { |
|
3546 | + $query_args = array_merge($extra_request, $query_args); |
|
3547 | + } |
|
3548 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
3549 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3550 | + } |
|
3551 | + |
|
3552 | + |
|
3553 | + /** |
|
3554 | + * _per_page_screen_option |
|
3555 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
3556 | + * |
|
3557 | + * @return void |
|
3558 | + * @throws InvalidArgumentException |
|
3559 | + * @throws InvalidInterfaceException |
|
3560 | + * @throws InvalidDataTypeException |
|
3561 | + */ |
|
3562 | + protected function _per_page_screen_option() |
|
3563 | + { |
|
3564 | + $option = 'per_page'; |
|
3565 | + $args = [ |
|
3566 | + 'label' => apply_filters( |
|
3567 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
3568 | + $this->_admin_page_title, |
|
3569 | + $this |
|
3570 | + ), |
|
3571 | + 'default' => (int) apply_filters( |
|
3572 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
3573 | + 20 |
|
3574 | + ), |
|
3575 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3576 | + ]; |
|
3577 | + // ONLY add the screen option if the user has access to it. |
|
3578 | + if ($this->check_user_access($this->_current_view, true)) { |
|
3579 | + add_screen_option($option, $args); |
|
3580 | + } |
|
3581 | + } |
|
3582 | + |
|
3583 | + |
|
3584 | + /** |
|
3585 | + * set_per_page_screen_option |
|
3586 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
3587 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
3588 | + * admin_menu. |
|
3589 | + * |
|
3590 | + * @return void |
|
3591 | + */ |
|
3592 | + private function _set_per_page_screen_options() |
|
3593 | + { |
|
3594 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
3595 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
3596 | + if (! $user = wp_get_current_user()) { |
|
3597 | + return; |
|
3598 | + } |
|
3599 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
3600 | + if (! $option) { |
|
3601 | + return; |
|
3602 | + } |
|
3603 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
3604 | + $map_option = $option; |
|
3605 | + $option = str_replace('-', '_', $option); |
|
3606 | + switch ($map_option) { |
|
3607 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3608 | + $max_value = apply_filters( |
|
3609 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
3610 | + 999, |
|
3611 | + $this->_current_page, |
|
3612 | + $this->_current_view |
|
3613 | + ); |
|
3614 | + if ($value < 1) { |
|
3615 | + return; |
|
3616 | + } |
|
3617 | + $value = min($value, $max_value); |
|
3618 | + break; |
|
3619 | + default: |
|
3620 | + $value = apply_filters( |
|
3621 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
3622 | + false, |
|
3623 | + $option, |
|
3624 | + $value |
|
3625 | + ); |
|
3626 | + if (false === $value) { |
|
3627 | + return; |
|
3628 | + } |
|
3629 | + break; |
|
3630 | + } |
|
3631 | + update_user_meta($user->ID, $option, $value); |
|
3632 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
3633 | + exit; |
|
3634 | + } |
|
3635 | + } |
|
3636 | + |
|
3637 | + |
|
3638 | + /** |
|
3639 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
3640 | + * |
|
3641 | + * @param array $data array that will be assigned to template args. |
|
3642 | + */ |
|
3643 | + public function set_template_args($data) |
|
3644 | + { |
|
3645 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
3646 | + } |
|
3647 | + |
|
3648 | + |
|
3649 | + /** |
|
3650 | + * This makes available the WP transient system for temporarily moving data between routes |
|
3651 | + * |
|
3652 | + * @param string $route the route that should receive the transient |
|
3653 | + * @param array $data the data that gets sent |
|
3654 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
3655 | + * normal route transient. |
|
3656 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
3657 | + * when we are adding a transient before page_routes have been defined. |
|
3658 | + * @return void |
|
3659 | + * @throws EE_Error |
|
3660 | + */ |
|
3661 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
3662 | + { |
|
3663 | + $user_id = get_current_user_id(); |
|
3664 | + if (! $skip_route_verify) { |
|
3665 | + $this->_verify_route($route); |
|
3666 | + } |
|
3667 | + // now let's set the string for what kind of transient we're setting |
|
3668 | + $transient = $notices |
|
3669 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3670 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
3671 | + $data = $notices ? ['notices' => $data] : $data; |
|
3672 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
3673 | + $existing = is_multisite() && is_network_admin() |
|
3674 | + ? get_site_transient($transient) |
|
3675 | + : get_transient($transient); |
|
3676 | + if ($existing) { |
|
3677 | + $data = array_merge((array) $data, (array) $existing); |
|
3678 | + } |
|
3679 | + if (is_multisite() && is_network_admin()) { |
|
3680 | + set_site_transient($transient, $data, 8); |
|
3681 | + } else { |
|
3682 | + set_transient($transient, $data, 8); |
|
3683 | + } |
|
3684 | + } |
|
3685 | + |
|
3686 | + |
|
3687 | + /** |
|
3688 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
3689 | + * |
|
3690 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
3691 | + * @param string $route |
|
3692 | + * @return mixed data |
|
3693 | + */ |
|
3694 | + protected function _get_transient($notices = false, $route = '') |
|
3695 | + { |
|
3696 | + $user_id = get_current_user_id(); |
|
3697 | + $route = ! $route ? $this->_req_action : $route; |
|
3698 | + $transient = $notices |
|
3699 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3700 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
3701 | + $data = is_multisite() && is_network_admin() |
|
3702 | + ? get_site_transient($transient) |
|
3703 | + : get_transient($transient); |
|
3704 | + // delete transient after retrieval (just in case it hasn't expired); |
|
3705 | + if (is_multisite() && is_network_admin()) { |
|
3706 | + delete_site_transient($transient); |
|
3707 | + } else { |
|
3708 | + delete_transient($transient); |
|
3709 | + } |
|
3710 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
3711 | + } |
|
3712 | + |
|
3713 | + |
|
3714 | + /** |
|
3715 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
3716 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
3717 | + * default route callback on the EE_Admin page you want it run.) |
|
3718 | + * |
|
3719 | + * @return void |
|
3720 | + */ |
|
3721 | + protected function _transient_garbage_collection() |
|
3722 | + { |
|
3723 | + global $wpdb; |
|
3724 | + // retrieve all existing transients |
|
3725 | + $query = |
|
3726 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
3727 | + if ($results = $wpdb->get_results($query)) { |
|
3728 | + foreach ($results as $result) { |
|
3729 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
3730 | + get_transient($transient); |
|
3731 | + if (is_multisite() && is_network_admin()) { |
|
3732 | + get_site_transient($transient); |
|
3733 | + } |
|
3734 | + } |
|
3735 | + } |
|
3736 | + } |
|
3737 | + |
|
3738 | + |
|
3739 | + /** |
|
3740 | + * get_view |
|
3741 | + * |
|
3742 | + * @return string content of _view property |
|
3743 | + */ |
|
3744 | + public function get_view() |
|
3745 | + { |
|
3746 | + return $this->_view; |
|
3747 | + } |
|
3748 | + |
|
3749 | + |
|
3750 | + /** |
|
3751 | + * getter for the protected $_views property |
|
3752 | + * |
|
3753 | + * @return array |
|
3754 | + */ |
|
3755 | + public function get_views() |
|
3756 | + { |
|
3757 | + return $this->_views; |
|
3758 | + } |
|
3759 | + |
|
3760 | + |
|
3761 | + /** |
|
3762 | + * get_current_page |
|
3763 | + * |
|
3764 | + * @return string _current_page property value |
|
3765 | + */ |
|
3766 | + public function get_current_page() |
|
3767 | + { |
|
3768 | + return $this->_current_page; |
|
3769 | + } |
|
3770 | + |
|
3771 | + |
|
3772 | + /** |
|
3773 | + * get_current_view |
|
3774 | + * |
|
3775 | + * @return string _current_view property value |
|
3776 | + */ |
|
3777 | + public function get_current_view() |
|
3778 | + { |
|
3779 | + return $this->_current_view; |
|
3780 | + } |
|
3781 | + |
|
3782 | + |
|
3783 | + /** |
|
3784 | + * get_current_screen |
|
3785 | + * |
|
3786 | + * @return object The current WP_Screen object |
|
3787 | + */ |
|
3788 | + public function get_current_screen() |
|
3789 | + { |
|
3790 | + return $this->_current_screen; |
|
3791 | + } |
|
3792 | + |
|
3793 | + |
|
3794 | + /** |
|
3795 | + * get_current_page_view_url |
|
3796 | + * |
|
3797 | + * @return string This returns the url for the current_page_view. |
|
3798 | + */ |
|
3799 | + public function get_current_page_view_url() |
|
3800 | + { |
|
3801 | + return $this->_current_page_view_url; |
|
3802 | + } |
|
3803 | + |
|
3804 | + |
|
3805 | + /** |
|
3806 | + * just returns the Request |
|
3807 | + * |
|
3808 | + * @return RequestInterface |
|
3809 | + */ |
|
3810 | + public function get_request() |
|
3811 | + { |
|
3812 | + return $this->request; |
|
3813 | + } |
|
3814 | + |
|
3815 | + |
|
3816 | + /** |
|
3817 | + * just returns the _req_data property |
|
3818 | + * |
|
3819 | + * @return array |
|
3820 | + */ |
|
3821 | + public function get_request_data() |
|
3822 | + { |
|
3823 | + return $this->request->requestParams(); |
|
3824 | + } |
|
3825 | + |
|
3826 | + |
|
3827 | + /** |
|
3828 | + * returns the _req_data protected property |
|
3829 | + * |
|
3830 | + * @return string |
|
3831 | + */ |
|
3832 | + public function get_req_action() |
|
3833 | + { |
|
3834 | + return $this->_req_action; |
|
3835 | + } |
|
3836 | + |
|
3837 | + |
|
3838 | + /** |
|
3839 | + * @return bool value of $_is_caf property |
|
3840 | + */ |
|
3841 | + public function is_caf() |
|
3842 | + { |
|
3843 | + return $this->_is_caf; |
|
3844 | + } |
|
3845 | + |
|
3846 | + |
|
3847 | + /** |
|
3848 | + * @return mixed |
|
3849 | + */ |
|
3850 | + public function default_espresso_metaboxes() |
|
3851 | + { |
|
3852 | + return $this->_default_espresso_metaboxes; |
|
3853 | + } |
|
3854 | + |
|
3855 | + |
|
3856 | + /** |
|
3857 | + * @return mixed |
|
3858 | + */ |
|
3859 | + public function admin_base_url() |
|
3860 | + { |
|
3861 | + return $this->_admin_base_url; |
|
3862 | + } |
|
3863 | + |
|
3864 | + |
|
3865 | + /** |
|
3866 | + * @return mixed |
|
3867 | + */ |
|
3868 | + public function wp_page_slug() |
|
3869 | + { |
|
3870 | + return $this->_wp_page_slug; |
|
3871 | + } |
|
3872 | + |
|
3873 | + |
|
3874 | + /** |
|
3875 | + * updates espresso configuration settings |
|
3876 | + * |
|
3877 | + * @param string $tab |
|
3878 | + * @param EE_Config_Base|EE_Config $config |
|
3879 | + * @param string $file file where error occurred |
|
3880 | + * @param string $func function where error occurred |
|
3881 | + * @param string $line line no where error occurred |
|
3882 | + * @return boolean |
|
3883 | + */ |
|
3884 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
3885 | + { |
|
3886 | + // remove any options that are NOT going to be saved with the config settings. |
|
3887 | + if (isset($config->core->ee_ueip_optin)) { |
|
3888 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
3889 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
3890 | + update_option('ee_ueip_has_notified', true); |
|
3891 | + } |
|
3892 | + // and save it (note we're also doing the network save here) |
|
3893 | + $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
3894 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
3895 | + if ($config_saved && $net_saved) { |
|
3896 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
3897 | + return true; |
|
3898 | + } |
|
3899 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
3900 | + return false; |
|
3901 | + } |
|
3902 | + |
|
3903 | + |
|
3904 | + /** |
|
3905 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
3906 | + * |
|
3907 | + * @return array |
|
3908 | + */ |
|
3909 | + public function get_yes_no_values() |
|
3910 | + { |
|
3911 | + return $this->_yes_no_values; |
|
3912 | + } |
|
3913 | + |
|
3914 | + |
|
3915 | + protected function _get_dir() |
|
3916 | + { |
|
3917 | + $reflector = new ReflectionClass(get_class($this)); |
|
3918 | + return dirname($reflector->getFileName()); |
|
3919 | + } |
|
3920 | + |
|
3921 | + |
|
3922 | + /** |
|
3923 | + * A helper for getting a "next link". |
|
3924 | + * |
|
3925 | + * @param string $url The url to link to |
|
3926 | + * @param string $class The class to use. |
|
3927 | + * @return string |
|
3928 | + */ |
|
3929 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
3930 | + { |
|
3931 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3932 | + } |
|
3933 | + |
|
3934 | + |
|
3935 | + /** |
|
3936 | + * A helper for getting a "previous link". |
|
3937 | + * |
|
3938 | + * @param string $url The url to link to |
|
3939 | + * @param string $class The class to use. |
|
3940 | + * @return string |
|
3941 | + */ |
|
3942 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
3943 | + { |
|
3944 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3945 | + } |
|
3946 | + |
|
3947 | + |
|
3948 | + |
|
3949 | + |
|
3950 | + |
|
3951 | + |
|
3952 | + |
|
3953 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
3954 | + |
|
3955 | + |
|
3956 | + /** |
|
3957 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
3958 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
3959 | + * _req_data array. |
|
3960 | + * |
|
3961 | + * @return bool success/fail |
|
3962 | + * @throws EE_Error |
|
3963 | + * @throws InvalidArgumentException |
|
3964 | + * @throws ReflectionException |
|
3965 | + * @throws InvalidDataTypeException |
|
3966 | + * @throws InvalidInterfaceException |
|
3967 | + */ |
|
3968 | + protected function _process_resend_registration() |
|
3969 | + { |
|
3970 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
3971 | + do_action( |
|
3972 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
3973 | + $this->_template_args['success'], |
|
3974 | + $this->request->requestParams() |
|
3975 | + ); |
|
3976 | + return $this->_template_args['success']; |
|
3977 | + } |
|
3978 | + |
|
3979 | + |
|
3980 | + /** |
|
3981 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
3982 | + * |
|
3983 | + * @param EE_Payment $payment |
|
3984 | + * @return bool success/fail |
|
3985 | + */ |
|
3986 | + protected function _process_payment_notification(EE_Payment $payment) |
|
3987 | + { |
|
3988 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
3989 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
3990 | + $this->_template_args['success'] = apply_filters( |
|
3991 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
3992 | + false, |
|
3993 | + $payment |
|
3994 | + ); |
|
3995 | + return $this->_template_args['success']; |
|
3996 | + } |
|
3997 | + |
|
3998 | + |
|
3999 | + /** |
|
4000 | + * @param EEM_Base $entity_model |
|
4001 | + * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
4002 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
4003 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
4004 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
4005 | + * @return int|float |
|
4006 | + * @throws EE_Error |
|
4007 | + */ |
|
4008 | + protected function trashRestoreDeleteEntities( |
|
4009 | + EEM_Base $entity_model, |
|
4010 | + string $entity_PK_name, |
|
4011 | + string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
4012 | + string $delete_column = '', |
|
4013 | + callable $callback = null |
|
4014 | + ) { |
|
4015 | + $entity_PK = $entity_model->get_primary_key_field(); |
|
4016 | + $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
4017 | + $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
4018 | + // grab ID if deleting a single entity |
|
4019 | + if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
4020 | + $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
4021 | + return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
4022 | + } |
|
4023 | + // or grab checkbox array if bulk deleting |
|
4024 | + $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
4025 | + if (empty($checkboxes)) { |
|
4026 | + return 0; |
|
4027 | + } |
|
4028 | + $success = 0; |
|
4029 | + $IDs = array_keys($checkboxes); |
|
4030 | + // cycle thru bulk action checkboxes |
|
4031 | + foreach ($IDs as $ID) { |
|
4032 | + // increment $success |
|
4033 | + if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
4034 | + $success++; |
|
4035 | + } |
|
4036 | + } |
|
4037 | + $count = (int) count($checkboxes); |
|
4038 | + // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
4039 | + // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
4040 | + return $success === $count ? $count : $success / $count; |
|
4041 | + } |
|
4042 | + |
|
4043 | + |
|
4044 | + /** |
|
4045 | + * @param EE_Primary_Key_Field_Base $entity_PK |
|
4046 | + * @return string |
|
4047 | + * @throws EE_Error |
|
4048 | + * @since 4.10.30.p |
|
4049 | + */ |
|
4050 | + private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
4051 | + { |
|
4052 | + $entity_PK_type = $entity_PK->getSchemaType(); |
|
4053 | + switch ($entity_PK_type) { |
|
4054 | + case 'boolean': |
|
4055 | + return 'bool'; |
|
4056 | + case 'integer': |
|
4057 | + return 'int'; |
|
4058 | + case 'number': |
|
4059 | + return 'float'; |
|
4060 | + case 'string': |
|
4061 | + return 'string'; |
|
4062 | + } |
|
4063 | + throw new RuntimeException( |
|
4064 | + sprintf( |
|
4065 | + esc_html__( |
|
4066 | + '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
4067 | + 'event_espresso' |
|
4068 | + ), |
|
4069 | + $entity_PK_type, |
|
4070 | + $entity_PK->get_name() |
|
4071 | + ) |
|
4072 | + ); |
|
4073 | + } |
|
4074 | + |
|
4075 | + |
|
4076 | + /** |
|
4077 | + * @param EEM_Base $entity_model |
|
4078 | + * @param int|string $entity_ID |
|
4079 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
4080 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
4081 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
4082 | + * @return bool |
|
4083 | + */ |
|
4084 | + protected function trashRestoreDeleteEntity( |
|
4085 | + EEM_Base $entity_model, |
|
4086 | + $entity_ID, |
|
4087 | + string $action, |
|
4088 | + string $delete_column, |
|
4089 | + callable $callback = null |
|
4090 | + ) { |
|
4091 | + $entity_ID = absint($entity_ID); |
|
4092 | + if (! $entity_ID) { |
|
4093 | + $this->trashRestoreDeleteError($action, $entity_model); |
|
4094 | + } |
|
4095 | + $result = 0; |
|
4096 | + try { |
|
4097 | + switch ($action) { |
|
4098 | + case EE_Admin_List_Table::ACTION_DELETE: |
|
4099 | + $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
4100 | + break; |
|
4101 | + case EE_Admin_List_Table::ACTION_RESTORE: |
|
4102 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
4103 | + $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
4104 | + break; |
|
4105 | + case EE_Admin_List_Table::ACTION_TRASH: |
|
4106 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
4107 | + $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
4108 | + break; |
|
4109 | + } |
|
4110 | + } catch (Exception $exception) { |
|
4111 | + $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
4112 | + } |
|
4113 | + if (is_callable($callback)) { |
|
4114 | + call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
4115 | + } |
|
4116 | + return $result; |
|
4117 | + } |
|
4118 | + |
|
4119 | + |
|
4120 | + /** |
|
4121 | + * @param EEM_Base $entity_model |
|
4122 | + * @param string $delete_column |
|
4123 | + * @since 4.10.30.p |
|
4124 | + */ |
|
4125 | + private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
4126 | + { |
|
4127 | + if (empty($delete_column)) { |
|
4128 | + throw new DomainException( |
|
4129 | + sprintf( |
|
4130 | + esc_html__( |
|
4131 | + 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
4132 | + 'event_espresso' |
|
4133 | + ), |
|
4134 | + $entity_model->get_this_model_name() |
|
4135 | + ) |
|
4136 | + ); |
|
4137 | + } |
|
4138 | + if (! $entity_model->has_field($delete_column)) { |
|
4139 | + throw new DomainException( |
|
4140 | + sprintf( |
|
4141 | + esc_html__( |
|
4142 | + 'The %1$s field does not exist on the %2$s model.', |
|
4143 | + 'event_espresso' |
|
4144 | + ), |
|
4145 | + $delete_column, |
|
4146 | + $entity_model->get_this_model_name() |
|
4147 | + ) |
|
4148 | + ); |
|
4149 | + } |
|
4150 | + } |
|
4151 | + |
|
4152 | + |
|
4153 | + /** |
|
4154 | + * @param EEM_Base $entity_model |
|
4155 | + * @param Exception|null $exception |
|
4156 | + * @param string $action |
|
4157 | + * @since 4.10.30.p |
|
4158 | + */ |
|
4159 | + private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
4160 | + { |
|
4161 | + if ($exception instanceof Exception) { |
|
4162 | + throw new RuntimeException( |
|
4163 | + sprintf( |
|
4164 | + esc_html__( |
|
4165 | + 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
4166 | + 'event_espresso' |
|
4167 | + ), |
|
4168 | + $action, |
|
4169 | + $entity_model->get_this_model_name(), |
|
4170 | + $exception->getMessage() |
|
4171 | + ) |
|
4172 | + ); |
|
4173 | + } |
|
4174 | + throw new RuntimeException( |
|
4175 | + sprintf( |
|
4176 | + esc_html__( |
|
4177 | + 'Could not %1$s the %2$s because an invalid ID was received.', |
|
4178 | + 'event_espresso' |
|
4179 | + ), |
|
4180 | + $action, |
|
4181 | + $entity_model->get_this_model_name() |
|
4182 | + ) |
|
4183 | + ); |
|
4184 | + } |
|
4185 | 4185 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | $ee_menu_slugs = (array) $ee_menu_slugs; |
515 | 515 | if ( |
516 | 516 | ! $this->request->isAjax() |
517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
517 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
518 | 518 | ) { |
519 | 519 | return; |
520 | 520 | } |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | : $req_action; |
535 | 535 | |
536 | 536 | $this->_current_view = $this->_req_action; |
537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
537 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
538 | 538 | $this->_define_page_props(); |
539 | 539 | $this->_current_page_view_url = add_query_arg( |
540 | 540 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -571,21 +571,21 @@ discard block |
||
571 | 571 | } |
572 | 572 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
573 | 573 | $this->_page_routes = apply_filters( |
574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
574 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
575 | 575 | $this->_page_routes, |
576 | 576 | $this |
577 | 577 | ); |
578 | 578 | $this->_page_config = apply_filters( |
579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
579 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
580 | 580 | $this->_page_config, |
581 | 581 | $this |
582 | 582 | ); |
583 | 583 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
584 | 584 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
586 | 586 | add_action( |
587 | 587 | 'AHEE__EE_Admin_Page__route_admin_request', |
588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
589 | 589 | 10, |
590 | 590 | 2 |
591 | 591 | ); |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | if ($this->_is_UI_request) { |
599 | 599 | // admin_init stuff - global, all views for this page class, specific view |
600 | 600 | add_action('admin_init', [$this, 'admin_init'], 10); |
601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
601 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
602 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
603 | 603 | } |
604 | 604 | } else { |
605 | 605 | // hijack regular WP loading and route admin request immediately |
@@ -618,12 +618,12 @@ discard block |
||
618 | 618 | */ |
619 | 619 | private function _do_other_page_hooks() |
620 | 620 | { |
621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
622 | 622 | foreach ($registered_pages as $page) { |
623 | 623 | // now let's setup the file name and class that should be present |
624 | 624 | $classname = str_replace('.class.php', '', $page); |
625 | 625 | // autoloaders should take care of loading file |
626 | - if (! class_exists($classname)) { |
|
626 | + if ( ! class_exists($classname)) { |
|
627 | 627 | $error_msg[] = sprintf( |
628 | 628 | esc_html__( |
629 | 629 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | ), |
641 | 641 | $page, |
642 | 642 | '<br />', |
643 | - '<strong>' . $classname . '</strong>' |
|
643 | + '<strong>'.$classname.'</strong>' |
|
644 | 644 | ); |
645 | 645 | throw new EE_Error(implode('||', $error_msg)); |
646 | 646 | } |
@@ -682,13 +682,13 @@ discard block |
||
682 | 682 | // load admin_notices - global, page class, and view specific |
683 | 683 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
684 | 684 | add_action('admin_notices', [$this, 'admin_notices'], 10); |
685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
685 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
686 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
687 | 687 | } |
688 | 688 | // load network admin_notices - global, page class, and view specific |
689 | 689 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
690 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
692 | 692 | } |
693 | 693 | // this will save any per_page screen options if they are present |
694 | 694 | $this->_set_per_page_screen_options(); |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | protected function _verify_routes() |
810 | 810 | { |
811 | 811 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
812 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
813 | 813 | return false; |
814 | 814 | } |
815 | 815 | $this->_route = false; |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | $this->_admin_page_title |
822 | 822 | ); |
823 | 823 | // developer error msg |
824 | - $error_msg .= '||' . $error_msg |
|
824 | + $error_msg .= '||'.$error_msg |
|
825 | 825 | . esc_html__( |
826 | 826 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
827 | 827 | 'event_espresso' |
@@ -830,9 +830,9 @@ discard block |
||
830 | 830 | } |
831 | 831 | // and that the requested page route exists |
832 | 832 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
835 | - ? $this->_page_config[ $this->_req_action ] |
|
833 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
834 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
835 | + ? $this->_page_config[$this->_req_action] |
|
836 | 836 | : []; |
837 | 837 | } else { |
838 | 838 | // user error msg |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | $this->_admin_page_title |
845 | 845 | ); |
846 | 846 | // developer error msg |
847 | - $error_msg .= '||' . $error_msg |
|
847 | + $error_msg .= '||'.$error_msg |
|
848 | 848 | . sprintf( |
849 | 849 | esc_html__( |
850 | 850 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | throw new EE_Error($error_msg); |
856 | 856 | } |
857 | 857 | // and that a default route exists |
858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
858 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
859 | 859 | // user error msg |
860 | 860 | $error_msg = sprintf( |
861 | 861 | esc_html__( |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | $this->_admin_page_title |
866 | 866 | ); |
867 | 867 | // developer error msg |
868 | - $error_msg .= '||' . $error_msg |
|
868 | + $error_msg .= '||'.$error_msg |
|
869 | 869 | . esc_html__( |
870 | 870 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
871 | 871 | 'event_espresso' |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | $this->_admin_page_title |
907 | 907 | ); |
908 | 908 | // developer error msg |
909 | - $error_msg .= '||' . $error_msg |
|
909 | + $error_msg .= '||'.$error_msg |
|
910 | 910 | . sprintf( |
911 | 911 | esc_html__( |
912 | 912 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -931,7 +931,7 @@ discard block |
||
931 | 931 | protected function _verify_nonce($nonce, $nonce_ref) |
932 | 932 | { |
933 | 933 | // verify nonce against expected value |
934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
934 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
935 | 935 | // these are not the droids you are looking for !!! |
936 | 936 | $msg = sprintf( |
937 | 937 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | __CLASS__ |
949 | 949 | ); |
950 | 950 | } |
951 | - if (! $this->request->isAjax()) { |
|
951 | + if ( ! $this->request->isAjax()) { |
|
952 | 952 | wp_die($msg); |
953 | 953 | } |
954 | 954 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | */ |
973 | 973 | protected function _route_admin_request() |
974 | 974 | { |
975 | - if (! $this->_is_UI_request) { |
|
975 | + if ( ! $this->_is_UI_request) { |
|
976 | 976 | $this->_verify_routes(); |
977 | 977 | } |
978 | 978 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | $error_msg = ''; |
993 | 993 | // action right before calling route |
994 | 994 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
995 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
996 | 996 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
997 | 997 | } |
998 | 998 | // right before calling the route, let's clean the _wp_http_referer |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | ); |
1005 | 1005 | $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri); |
1006 | 1006 | $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri); |
1007 | - if (! empty($func)) { |
|
1007 | + if ( ! empty($func)) { |
|
1008 | 1008 | if (is_array($func)) { |
1009 | 1009 | [$class, $method] = $func; |
1010 | 1010 | } elseif (strpos($func, '::') !== false) { |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | $class = $this; |
1014 | 1014 | $method = $func; |
1015 | 1015 | } |
1016 | - if (! (is_object($class) && $class === $this)) { |
|
1016 | + if ( ! (is_object($class) && $class === $this)) { |
|
1017 | 1017 | // send along this admin page object for access by addons. |
1018 | 1018 | $args['admin_page_object'] = $this; |
1019 | 1019 | } |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | $method |
1055 | 1055 | ); |
1056 | 1056 | } |
1057 | - if (! empty($error_msg)) { |
|
1057 | + if ( ! empty($error_msg)) { |
|
1058 | 1058 | throw new EE_Error($error_msg); |
1059 | 1059 | } |
1060 | 1060 | } |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | if (strpos($key, 'nonce') !== false) { |
1140 | 1140 | continue; |
1141 | 1141 | } |
1142 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
1142 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
1143 | 1143 | } |
1144 | 1144 | } |
1145 | 1145 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1178,12 +1178,12 @@ discard block |
||
1178 | 1178 | */ |
1179 | 1179 | protected function _add_help_tabs() |
1180 | 1180 | { |
1181 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
1182 | - $config = $this->_page_config[ $this->_req_action ]; |
|
1181 | + if (isset($this->_page_config[$this->_req_action])) { |
|
1182 | + $config = $this->_page_config[$this->_req_action]; |
|
1183 | 1183 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
1184 | 1184 | if (is_array($config) && isset($config['help_sidebar'])) { |
1185 | 1185 | // check that the callback given is valid |
1186 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
1186 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
1187 | 1187 | throw new EE_Error( |
1188 | 1188 | sprintf( |
1189 | 1189 | esc_html__( |
@@ -1196,18 +1196,18 @@ discard block |
||
1196 | 1196 | ); |
1197 | 1197 | } |
1198 | 1198 | $content = apply_filters( |
1199 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1199 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
1200 | 1200 | $this->{$config['help_sidebar']}() |
1201 | 1201 | ); |
1202 | 1202 | $this->_current_screen->set_help_sidebar($content); |
1203 | 1203 | } |
1204 | - if (! isset($config['help_tabs'])) { |
|
1204 | + if ( ! isset($config['help_tabs'])) { |
|
1205 | 1205 | return; |
1206 | 1206 | } //no help tabs for this route |
1207 | 1207 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
1208 | 1208 | // we're here so there ARE help tabs! |
1209 | 1209 | // make sure we've got what we need |
1210 | - if (! isset($cfg['title'])) { |
|
1210 | + if ( ! isset($cfg['title'])) { |
|
1211 | 1211 | throw new EE_Error( |
1212 | 1212 | esc_html__( |
1213 | 1213 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | ) |
1216 | 1216 | ); |
1217 | 1217 | } |
1218 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1218 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1219 | 1219 | throw new EE_Error( |
1220 | 1220 | esc_html__( |
1221 | 1221 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1224,11 +1224,11 @@ discard block |
||
1224 | 1224 | ); |
1225 | 1225 | } |
1226 | 1226 | // first priority goes to content. |
1227 | - if (! empty($cfg['content'])) { |
|
1227 | + if ( ! empty($cfg['content'])) { |
|
1228 | 1228 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
1229 | 1229 | // second priority goes to filename |
1230 | - } elseif (! empty($cfg['filename'])) { |
|
1231 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1230 | + } elseif ( ! empty($cfg['filename'])) { |
|
1231 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
1232 | 1232 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
1233 | 1233 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
1234 | 1234 | . basename($this->_get_dir()) |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | . $cfg['filename'] |
1237 | 1237 | . '.help_tab.php' : $file_path; |
1238 | 1238 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
1239 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1239 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1240 | 1240 | EE_Error::add_error( |
1241 | 1241 | sprintf( |
1242 | 1242 | esc_html__( |
@@ -1284,7 +1284,7 @@ discard block |
||
1284 | 1284 | return; |
1285 | 1285 | } |
1286 | 1286 | // setup config array for help tab method |
1287 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1287 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
1288 | 1288 | $_ht = [ |
1289 | 1289 | 'id' => $id, |
1290 | 1290 | 'title' => $cfg['title'], |
@@ -1308,8 +1308,8 @@ discard block |
||
1308 | 1308 | $qtips = (array) $this->_route_config['qtips']; |
1309 | 1309 | // load qtip loader |
1310 | 1310 | $path = [ |
1311 | - $this->_get_dir() . '/qtips/', |
|
1312 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1311 | + $this->_get_dir().'/qtips/', |
|
1312 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
1313 | 1313 | ]; |
1314 | 1314 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
1315 | 1315 | } |
@@ -1331,7 +1331,7 @@ discard block |
||
1331 | 1331 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1332 | 1332 | $i = 0; |
1333 | 1333 | foreach ($this->_page_config as $slug => $config) { |
1334 | - if (! is_array($config) || empty($config['nav'])) { |
|
1334 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
1335 | 1335 | continue; |
1336 | 1336 | } |
1337 | 1337 | // no nav tab for this config |
@@ -1340,12 +1340,12 @@ discard block |
||
1340 | 1340 | // nav tab is only to appear when route requested. |
1341 | 1341 | continue; |
1342 | 1342 | } |
1343 | - if (! $this->check_user_access($slug, true)) { |
|
1343 | + if ( ! $this->check_user_access($slug, true)) { |
|
1344 | 1344 | // no nav tab because current user does not have access. |
1345 | 1345 | continue; |
1346 | 1346 | } |
1347 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1348 | - $this->_nav_tabs[ $slug ] = [ |
|
1347 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
1348 | + $this->_nav_tabs[$slug] = [ |
|
1349 | 1349 | 'url' => isset($config['nav']['url']) |
1350 | 1350 | ? $config['nav']['url'] |
1351 | 1351 | : self::add_query_args_and_nonce( |
@@ -1357,14 +1357,14 @@ discard block |
||
1357 | 1357 | : ucwords( |
1358 | 1358 | str_replace('_', ' ', $slug) |
1359 | 1359 | ), |
1360 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1360 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
1361 | 1361 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
1362 | 1362 | ]; |
1363 | 1363 | $i++; |
1364 | 1364 | } |
1365 | 1365 | // if $this->_nav_tabs is empty then lets set the default |
1366 | 1366 | if (empty($this->_nav_tabs)) { |
1367 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
1367 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
1368 | 1368 | 'url' => $this->_admin_base_url, |
1369 | 1369 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
1370 | 1370 | 'css_class' => 'nav-tab-active', |
@@ -1389,10 +1389,10 @@ discard block |
||
1389 | 1389 | foreach ($this->_route_config['labels'] as $label => $text) { |
1390 | 1390 | if (is_array($text)) { |
1391 | 1391 | foreach ($text as $sublabel => $subtext) { |
1392 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1392 | + $this->_labels[$label][$sublabel] = $subtext; |
|
1393 | 1393 | } |
1394 | 1394 | } else { |
1395 | - $this->_labels[ $label ] = $text; |
|
1395 | + $this->_labels[$label] = $text; |
|
1396 | 1396 | } |
1397 | 1397 | } |
1398 | 1398 | } |
@@ -1414,12 +1414,12 @@ discard block |
||
1414 | 1414 | { |
1415 | 1415 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1416 | 1416 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
1417 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1417 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
1418 | 1418 | && is_array( |
1419 | - $this->_page_routes[ $route_to_check ] |
|
1419 | + $this->_page_routes[$route_to_check] |
|
1420 | 1420 | ) |
1421 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1422 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1421 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
1422 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
1423 | 1423 | if (empty($capability) && empty($route_to_check)) { |
1424 | 1424 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
1425 | 1425 | : $this->_route['capability']; |
@@ -1539,7 +1539,7 @@ discard block |
||
1539 | 1539 | '; |
1540 | 1540 | |
1541 | 1541 | // current set timezone for timezone js |
1542 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
1542 | + echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>'; |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | |
@@ -1573,7 +1573,7 @@ discard block |
||
1573 | 1573 | // loop through the array and setup content |
1574 | 1574 | foreach ($help_array as $trigger => $help) { |
1575 | 1575 | // make sure the array is setup properly |
1576 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
1576 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
1577 | 1577 | throw new EE_Error( |
1578 | 1578 | esc_html__( |
1579 | 1579 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1587,8 +1587,8 @@ discard block |
||
1587 | 1587 | 'help_popup_title' => $help['title'], |
1588 | 1588 | 'help_popup_content' => $help['content'], |
1589 | 1589 | ]; |
1590 | - $content .= EEH_Template::display_template( |
|
1591 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1590 | + $content .= EEH_Template::display_template( |
|
1591 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
1592 | 1592 | $template_args, |
1593 | 1593 | true |
1594 | 1594 | ); |
@@ -1610,15 +1610,15 @@ discard block |
||
1610 | 1610 | private function _get_help_content() |
1611 | 1611 | { |
1612 | 1612 | // what is the method we're looking for? |
1613 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
1613 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
1614 | 1614 | // if method doesn't exist let's get out. |
1615 | - if (! method_exists($this, $method_name)) { |
|
1615 | + if ( ! method_exists($this, $method_name)) { |
|
1616 | 1616 | return []; |
1617 | 1617 | } |
1618 | 1618 | // k we're good to go let's retrieve the help array |
1619 | 1619 | $help_array = call_user_func([$this, $method_name]); |
1620 | 1620 | // make sure we've got an array! |
1621 | - if (! is_array($help_array)) { |
|
1621 | + if ( ! is_array($help_array)) { |
|
1622 | 1622 | throw new EE_Error( |
1623 | 1623 | esc_html__( |
1624 | 1624 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1650,15 +1650,15 @@ discard block |
||
1650 | 1650 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
1651 | 1651 | $help_array = $this->_get_help_content(); |
1652 | 1652 | $help_content = ''; |
1653 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1654 | - $help_array[ $trigger_id ] = [ |
|
1653 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
1654 | + $help_array[$trigger_id] = [ |
|
1655 | 1655 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
1656 | 1656 | 'content' => esc_html__( |
1657 | 1657 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
1658 | 1658 | 'event_espresso' |
1659 | 1659 | ), |
1660 | 1660 | ]; |
1661 | - $help_content = $this->_set_help_popup_content($help_array); |
|
1661 | + $help_content = $this->_set_help_popup_content($help_array); |
|
1662 | 1662 | } |
1663 | 1663 | // let's setup the trigger |
1664 | 1664 | $content = '<a class="ee-dialog" href="?height=' |
@@ -1726,15 +1726,15 @@ discard block |
||
1726 | 1726 | // register all styles |
1727 | 1727 | wp_register_style( |
1728 | 1728 | 'espresso-ui-theme', |
1729 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1729 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1730 | 1730 | [], |
1731 | 1731 | EVENT_ESPRESSO_VERSION |
1732 | 1732 | ); |
1733 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
1733 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
1734 | 1734 | // helpers styles |
1735 | 1735 | wp_register_style( |
1736 | 1736 | 'ee-text-links', |
1737 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1737 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
1738 | 1738 | [], |
1739 | 1739 | EVENT_ESPRESSO_VERSION |
1740 | 1740 | ); |
@@ -1742,21 +1742,21 @@ discard block |
||
1742 | 1742 | // register all scripts |
1743 | 1743 | wp_register_script( |
1744 | 1744 | 'ee-dialog', |
1745 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1745 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
1746 | 1746 | ['jquery', 'jquery-ui-draggable'], |
1747 | 1747 | EVENT_ESPRESSO_VERSION, |
1748 | 1748 | true |
1749 | 1749 | ); |
1750 | 1750 | wp_register_script( |
1751 | 1751 | 'ee_admin_js', |
1752 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1752 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
1753 | 1753 | ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
1754 | 1754 | EVENT_ESPRESSO_VERSION, |
1755 | 1755 | true |
1756 | 1756 | ); |
1757 | 1757 | wp_register_script( |
1758 | 1758 | 'jquery-ui-timepicker-addon', |
1759 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1759 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
1760 | 1760 | ['jquery-ui-datepicker', 'jquery-ui-slider'], |
1761 | 1761 | EVENT_ESPRESSO_VERSION, |
1762 | 1762 | true |
@@ -1764,7 +1764,7 @@ discard block |
||
1764 | 1764 | // script for sorting tables |
1765 | 1765 | wp_register_script( |
1766 | 1766 | 'espresso_ajax_table_sorting', |
1767 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1767 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
1768 | 1768 | ['ee_admin_js', 'jquery-ui-sortable'], |
1769 | 1769 | EVENT_ESPRESSO_VERSION, |
1770 | 1770 | true |
@@ -1772,7 +1772,7 @@ discard block |
||
1772 | 1772 | // script for parsing uri's |
1773 | 1773 | wp_register_script( |
1774 | 1774 | 'ee-parse-uri', |
1775 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1775 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
1776 | 1776 | [], |
1777 | 1777 | EVENT_ESPRESSO_VERSION, |
1778 | 1778 | true |
@@ -1780,7 +1780,7 @@ discard block |
||
1780 | 1780 | // and parsing associative serialized form elements |
1781 | 1781 | wp_register_script( |
1782 | 1782 | 'ee-serialize-full-array', |
1783 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1783 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
1784 | 1784 | ['jquery'], |
1785 | 1785 | EVENT_ESPRESSO_VERSION, |
1786 | 1786 | true |
@@ -1788,28 +1788,28 @@ discard block |
||
1788 | 1788 | // helpers scripts |
1789 | 1789 | wp_register_script( |
1790 | 1790 | 'ee-text-links', |
1791 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1791 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
1792 | 1792 | ['jquery'], |
1793 | 1793 | EVENT_ESPRESSO_VERSION, |
1794 | 1794 | true |
1795 | 1795 | ); |
1796 | 1796 | wp_register_script( |
1797 | 1797 | 'ee-moment-core', |
1798 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1798 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
1799 | 1799 | [], |
1800 | 1800 | EVENT_ESPRESSO_VERSION, |
1801 | 1801 | true |
1802 | 1802 | ); |
1803 | 1803 | wp_register_script( |
1804 | 1804 | 'ee-moment', |
1805 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1805 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
1806 | 1806 | ['ee-moment-core'], |
1807 | 1807 | EVENT_ESPRESSO_VERSION, |
1808 | 1808 | true |
1809 | 1809 | ); |
1810 | 1810 | wp_register_script( |
1811 | 1811 | 'ee-datepicker', |
1812 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1812 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
1813 | 1813 | ['jquery-ui-timepicker-addon', 'ee-moment'], |
1814 | 1814 | EVENT_ESPRESSO_VERSION, |
1815 | 1815 | true |
@@ -1842,7 +1842,7 @@ discard block |
||
1842 | 1842 | wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
1843 | 1843 | add_filter( |
1844 | 1844 | 'admin_body_class', |
1845 | - function ($classes) { |
|
1845 | + function($classes) { |
|
1846 | 1846 | if (strpos($classes, 'espresso-admin') === false) { |
1847 | 1847 | $classes .= ' espresso-admin'; |
1848 | 1848 | } |
@@ -1930,12 +1930,12 @@ discard block |
||
1930 | 1930 | protected function _set_list_table() |
1931 | 1931 | { |
1932 | 1932 | // first is this a list_table view? |
1933 | - if (! isset($this->_route_config['list_table'])) { |
|
1933 | + if ( ! isset($this->_route_config['list_table'])) { |
|
1934 | 1934 | return; |
1935 | 1935 | } //not a list_table view so get out. |
1936 | 1936 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
1937 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
1938 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
1937 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
1938 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
1939 | 1939 | // user error msg |
1940 | 1940 | $error_msg = esc_html__( |
1941 | 1941 | 'An error occurred. The requested list table views could not be found.', |
@@ -1955,10 +1955,10 @@ discard block |
||
1955 | 1955 | } |
1956 | 1956 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
1957 | 1957 | $this->_views = apply_filters( |
1958 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
1958 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
1959 | 1959 | $this->_views |
1960 | 1960 | ); |
1961 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
1961 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
1962 | 1962 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
1963 | 1963 | $this->_set_list_table_view(); |
1964 | 1964 | $this->_set_list_table_object(); |
@@ -1993,7 +1993,7 @@ discard block |
||
1993 | 1993 | protected function _set_list_table_object() |
1994 | 1994 | { |
1995 | 1995 | if (isset($this->_route_config['list_table'])) { |
1996 | - if (! class_exists($this->_route_config['list_table'])) { |
|
1996 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
1997 | 1997 | throw new EE_Error( |
1998 | 1998 | sprintf( |
1999 | 1999 | esc_html__( |
@@ -2031,15 +2031,15 @@ discard block |
||
2031 | 2031 | foreach ($this->_views as $key => $view) { |
2032 | 2032 | $query_args = []; |
2033 | 2033 | // check for current view |
2034 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2034 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2035 | 2035 | $query_args['action'] = $this->_req_action; |
2036 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2036 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
2037 | 2037 | $query_args['status'] = $view['slug']; |
2038 | 2038 | // merge any other arguments sent in. |
2039 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
2040 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2039 | + if (isset($extra_query_args[$view['slug']])) { |
|
2040 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
2041 | 2041 | } |
2042 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2042 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2043 | 2043 | } |
2044 | 2044 | return $this->_views; |
2045 | 2045 | } |
@@ -2070,14 +2070,14 @@ discard block |
||
2070 | 2070 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
2071 | 2071 | foreach ($values as $value) { |
2072 | 2072 | if ($value < $max_entries) { |
2073 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2073 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
2074 | 2074 | $entries_per_page_dropdown .= ' |
2075 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
2075 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
2076 | 2076 | } |
2077 | 2077 | } |
2078 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2078 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
2079 | 2079 | $entries_per_page_dropdown .= ' |
2080 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
2080 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
2081 | 2081 | $entries_per_page_dropdown .= ' |
2082 | 2082 | </select> |
2083 | 2083 | entries |
@@ -2101,7 +2101,7 @@ discard block |
||
2101 | 2101 | empty($this->_search_btn_label) ? $this->page_label |
2102 | 2102 | : $this->_search_btn_label |
2103 | 2103 | ); |
2104 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2104 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
2105 | 2105 | } |
2106 | 2106 | |
2107 | 2107 | |
@@ -2189,7 +2189,7 @@ discard block |
||
2189 | 2189 | $total_columns = ! empty($screen_columns) |
2190 | 2190 | ? $screen_columns |
2191 | 2191 | : $this->_route_config['columns'][1]; |
2192 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2192 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
2193 | 2193 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
2194 | 2194 | $this->_template_args['screen'] = $this->_current_screen; |
2195 | 2195 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2234,7 +2234,7 @@ discard block |
||
2234 | 2234 | */ |
2235 | 2235 | protected function _espresso_ratings_request() |
2236 | 2236 | { |
2237 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2237 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2238 | 2238 | return; |
2239 | 2239 | } |
2240 | 2240 | $ratings_box_title = apply_filters( |
@@ -2262,7 +2262,7 @@ discard block |
||
2262 | 2262 | public function espresso_ratings_request() |
2263 | 2263 | { |
2264 | 2264 | EEH_Template::display_template( |
2265 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2265 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
2266 | 2266 | [] |
2267 | 2267 | ); |
2268 | 2268 | } |
@@ -2270,22 +2270,22 @@ discard block |
||
2270 | 2270 | |
2271 | 2271 | public static function cached_rss_display($rss_id, $url) |
2272 | 2272 | { |
2273 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
2273 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
2274 | 2274 | . esc_html__('Loading…', 'event_espresso') |
2275 | 2275 | . '</p><p class="hide-if-js">' |
2276 | 2276 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
2277 | 2277 | . '</p>'; |
2278 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2279 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
2280 | - $post = '</div>' . "\n"; |
|
2281 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
2278 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
2279 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
2280 | + $post = '</div>'."\n"; |
|
2281 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
2282 | 2282 | $output = get_transient($cache_key); |
2283 | 2283 | if ($output !== false) { |
2284 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
2284 | + echo wp_kses($pre.$output.$post, AllowedTags::getWithFormTags()); |
|
2285 | 2285 | return true; |
2286 | 2286 | } |
2287 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2288 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
2287 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2288 | + echo wp_kses($pre.$loading.$post, AllowedTags::getWithFormTags()); |
|
2289 | 2289 | return false; |
2290 | 2290 | } |
2291 | 2291 | ob_start(); |
@@ -2352,19 +2352,19 @@ discard block |
||
2352 | 2352 | public function espresso_sponsors_post_box() |
2353 | 2353 | { |
2354 | 2354 | EEH_Template::display_template( |
2355 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2355 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2356 | 2356 | ); |
2357 | 2357 | } |
2358 | 2358 | |
2359 | 2359 | |
2360 | 2360 | private function _publish_post_box() |
2361 | 2361 | { |
2362 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2362 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
2363 | 2363 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
2364 | 2364 | // then we'll use that for the metabox label. |
2365 | 2365 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
2366 | - if (! empty($this->_labels['publishbox'])) { |
|
2367 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2366 | + if ( ! empty($this->_labels['publishbox'])) { |
|
2367 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
2368 | 2368 | : $this->_labels['publishbox']; |
2369 | 2369 | } else { |
2370 | 2370 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2393,7 +2393,7 @@ discard block |
||
2393 | 2393 | ? $this->_template_args['publish_box_extra_content'] |
2394 | 2394 | : ''; |
2395 | 2395 | echo EEH_Template::display_template( |
2396 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2396 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
2397 | 2397 | $this->_template_args, |
2398 | 2398 | true |
2399 | 2399 | ); |
@@ -2485,18 +2485,18 @@ discard block |
||
2485 | 2485 | ); |
2486 | 2486 | } |
2487 | 2487 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
2488 | - if (! empty($name) && ! empty($id)) { |
|
2489 | - $hidden_field_arr[ $name ] = [ |
|
2488 | + if ( ! empty($name) && ! empty($id)) { |
|
2489 | + $hidden_field_arr[$name] = [ |
|
2490 | 2490 | 'type' => 'hidden', |
2491 | 2491 | 'value' => $id, |
2492 | 2492 | ]; |
2493 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2493 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2494 | 2494 | } else { |
2495 | 2495 | $hf = ''; |
2496 | 2496 | } |
2497 | 2497 | // add hidden field |
2498 | 2498 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
2499 | - ? $hf[ $name ]['field'] |
|
2499 | + ? $hf[$name]['field'] |
|
2500 | 2500 | : $hf; |
2501 | 2501 | } |
2502 | 2502 | |
@@ -2598,7 +2598,7 @@ discard block |
||
2598 | 2598 | } |
2599 | 2599 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
2600 | 2600 | $call_back_func = $create_func |
2601 | - ? function ($post, $metabox) { |
|
2601 | + ? function($post, $metabox) { |
|
2602 | 2602 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2603 | 2603 | echo EEH_Template::display_template( |
2604 | 2604 | $metabox['args']['template_path'], |
@@ -2608,7 +2608,7 @@ discard block |
||
2608 | 2608 | } |
2609 | 2609 | : $callback; |
2610 | 2610 | add_meta_box( |
2611 | - str_replace('_', '-', $action) . '-mbox', |
|
2611 | + str_replace('_', '-', $action).'-mbox', |
|
2612 | 2612 | $title, |
2613 | 2613 | $call_back_func, |
2614 | 2614 | $this->_wp_page_slug, |
@@ -2700,9 +2700,9 @@ discard block |
||
2700 | 2700 | : 'espresso-default-admin'; |
2701 | 2701 | $template_path = $sidebar |
2702 | 2702 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
2703 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2703 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
2704 | 2704 | if ($this->request->isAjax()) { |
2705 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2705 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2706 | 2706 | } |
2707 | 2707 | $template_path = ! empty($this->_column_template_path) |
2708 | 2708 | ? $this->_column_template_path : $template_path; |
@@ -2742,11 +2742,11 @@ discard block |
||
2742 | 2742 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
2743 | 2743 | { |
2744 | 2744 | // let's generate a default preview action button if there isn't one already present. |
2745 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2745 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2746 | 2746 | 'Upgrade to Event Espresso 4 Right Now', |
2747 | 2747 | 'event_espresso' |
2748 | 2748 | ); |
2749 | - $buy_now_url = add_query_arg( |
|
2749 | + $buy_now_url = add_query_arg( |
|
2750 | 2750 | [ |
2751 | 2751 | 'ee_ver' => 'ee4', |
2752 | 2752 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2766,8 +2766,8 @@ discard block |
||
2766 | 2766 | true |
2767 | 2767 | ) |
2768 | 2768 | : $this->_template_args['preview_action_button']; |
2769 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2769 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
2771 | 2771 | $this->_template_args, |
2772 | 2772 | true |
2773 | 2773 | ); |
@@ -2816,7 +2816,7 @@ discard block |
||
2816 | 2816 | // setup search attributes |
2817 | 2817 | $this->_set_search_attributes(); |
2818 | 2818 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
2819 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2819 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
2820 | 2820 | $this->_template_args['table_url'] = $this->request->isAjax() |
2821 | 2821 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
2822 | 2822 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -2824,10 +2824,10 @@ discard block |
||
2824 | 2824 | $this->_template_args['current_route'] = $this->_req_action; |
2825 | 2825 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
2826 | 2826 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
2827 | - if (! empty($ajax_sorting_callback)) { |
|
2827 | + if ( ! empty($ajax_sorting_callback)) { |
|
2828 | 2828 | $sortable_list_table_form_fields = wp_nonce_field( |
2829 | - $ajax_sorting_callback . '_nonce', |
|
2830 | - $ajax_sorting_callback . '_nonce', |
|
2829 | + $ajax_sorting_callback.'_nonce', |
|
2830 | + $ajax_sorting_callback.'_nonce', |
|
2831 | 2831 | false, |
2832 | 2832 | false |
2833 | 2833 | ); |
@@ -2846,18 +2846,18 @@ discard block |
||
2846 | 2846 | ? $this->_template_args['list_table_hidden_fields'] |
2847 | 2847 | : ''; |
2848 | 2848 | |
2849 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
2849 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
2850 | 2850 | $hidden_form_fields .= ' |
2851 | - <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
2851 | + <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
2852 | 2852 | |
2853 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2853 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2854 | 2854 | // display message about search results? |
2855 | 2855 | $search = $this->request->getRequestParam('s'); |
2856 | 2856 | $this->_template_args['before_list_table'] .= ! empty($search) |
2857 | - ? '<p class="ee-search-results">' . sprintf( |
|
2857 | + ? '<p class="ee-search-results">'.sprintf( |
|
2858 | 2858 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
2859 | 2859 | trim($search, '%') |
2860 | - ) . '</p>' |
|
2860 | + ).'</p>' |
|
2861 | 2861 | : ''; |
2862 | 2862 | // filter before_list_table template arg |
2863 | 2863 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -2891,7 +2891,7 @@ discard block |
||
2891 | 2891 | // convert to array and filter again |
2892 | 2892 | // arrays are easier to inject new items in a specific location, |
2893 | 2893 | // but would not be backwards compatible, so we have to add a new filter |
2894 | - $this->_template_args['after_list_table'] = implode( |
|
2894 | + $this->_template_args['after_list_table'] = implode( |
|
2895 | 2895 | " \n", |
2896 | 2896 | (array) apply_filters( |
2897 | 2897 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -2938,7 +2938,7 @@ discard block |
||
2938 | 2938 | $this |
2939 | 2939 | ); |
2940 | 2940 | return EEH_Template::display_template( |
2941 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
2941 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
2942 | 2942 | $this->_template_args, |
2943 | 2943 | true |
2944 | 2944 | ); |
@@ -3047,18 +3047,18 @@ discard block |
||
3047 | 3047 | : '' |
3048 | 3048 | ); |
3049 | 3049 | |
3050 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3050 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3051 | 3051 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
3052 | 3052 | isset($this->_template_args['after_admin_page_content']) |
3053 | 3053 | ? $this->_template_args['after_admin_page_content'] |
3054 | 3054 | : '' |
3055 | 3055 | ); |
3056 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3056 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3057 | 3057 | |
3058 | 3058 | if ($this->request->isAjax()) { |
3059 | 3059 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
3060 | 3060 | // $template_path, |
3061 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
3061 | + EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php', |
|
3062 | 3062 | $this->_template_args, |
3063 | 3063 | true |
3064 | 3064 | ); |
@@ -3067,7 +3067,7 @@ discard block |
||
3067 | 3067 | // load settings page wrapper template |
3068 | 3068 | $template_path = $about |
3069 | 3069 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
3070 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
3070 | + : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php'; |
|
3071 | 3071 | |
3072 | 3072 | EEH_Template::display_template($template_path, $this->_template_args); |
3073 | 3073 | } |
@@ -3152,12 +3152,12 @@ discard block |
||
3152 | 3152 | $default_names = ['save', 'save_and_close']; |
3153 | 3153 | $buttons = ''; |
3154 | 3154 | foreach ($button_text as $key => $button) { |
3155 | - $ref = $default_names[ $key ]; |
|
3156 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
3157 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
3158 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
3159 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
3160 | - if (! $both) { |
|
3155 | + $ref = $default_names[$key]; |
|
3156 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
3157 | + $buttons .= '<input type="submit" class="button-primary '.$ref.'" ' |
|
3158 | + . 'value="'.$button.'" name="'.$name.'" ' |
|
3159 | + . 'id="'.$this->_current_view.'_'.$ref.'" />'; |
|
3160 | + if ( ! $both) { |
|
3161 | 3161 | break; |
3162 | 3162 | } |
3163 | 3163 | } |
@@ -3197,13 +3197,13 @@ discard block |
||
3197 | 3197 | 'An error occurred. No action was set for this page\'s form.', |
3198 | 3198 | 'event_espresso' |
3199 | 3199 | ); |
3200 | - $dev_msg = $user_msg . "\n" |
|
3200 | + $dev_msg = $user_msg."\n" |
|
3201 | 3201 | . sprintf( |
3202 | 3202 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
3203 | 3203 | __FUNCTION__, |
3204 | 3204 | __CLASS__ |
3205 | 3205 | ); |
3206 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3206 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3207 | 3207 | } |
3208 | 3208 | // open form |
3209 | 3209 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3212,9 +3212,9 @@ discard block |
||
3212 | 3212 | . $route |
3213 | 3213 | . '_event_form" >'; |
3214 | 3214 | // add nonce |
3215 | - $nonce = |
|
3216 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3217 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3215 | + $nonce = |
|
3216 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
3217 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
3218 | 3218 | // add REQUIRED form action |
3219 | 3219 | $hidden_fields = [ |
3220 | 3220 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3227,7 +3227,7 @@ discard block |
||
3227 | 3227 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
3228 | 3228 | // add fields to form |
3229 | 3229 | foreach ((array) $form_fields as $form_field) { |
3230 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3230 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
3231 | 3231 | } |
3232 | 3232 | // close form |
3233 | 3233 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3318,10 +3318,10 @@ discard block |
||
3318 | 3318 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
3319 | 3319 | $notices = EE_Error::get_notices(false); |
3320 | 3320 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
3321 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3321 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
3322 | 3322 | EE_Error::overwrite_success(); |
3323 | 3323 | } |
3324 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3324 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3325 | 3325 | // how many records affected ? more than one record ? or just one ? |
3326 | 3326 | if ($success > 1) { |
3327 | 3327 | // set plural msg |
@@ -3350,7 +3350,7 @@ discard block |
||
3350 | 3350 | } |
3351 | 3351 | } |
3352 | 3352 | // check that $query_args isn't something crazy |
3353 | - if (! is_array($query_args)) { |
|
3353 | + if ( ! is_array($query_args)) { |
|
3354 | 3354 | $query_args = []; |
3355 | 3355 | } |
3356 | 3356 | /** |
@@ -3379,7 +3379,7 @@ discard block |
||
3379 | 3379 | $redirect_url = admin_url('admin.php'); |
3380 | 3380 | } |
3381 | 3381 | // merge any default query_args set in _default_route_query_args property |
3382 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3382 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3383 | 3383 | $args_to_merge = []; |
3384 | 3384 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
3385 | 3385 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3391,15 +3391,15 @@ discard block |
||
3391 | 3391 | } |
3392 | 3392 | // finally we will override any arguments in the referer with |
3393 | 3393 | // what might be set on the _default_route_query_args array. |
3394 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
3395 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3394 | + if (isset($this->_default_route_query_args[$reference])) { |
|
3395 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
3396 | 3396 | } else { |
3397 | - $args_to_merge[ $reference ] = urlencode($value); |
|
3397 | + $args_to_merge[$reference] = urlencode($value); |
|
3398 | 3398 | } |
3399 | 3399 | } |
3400 | 3400 | continue; |
3401 | 3401 | } |
3402 | - $args_to_merge[ $query_param ] = $query_value; |
|
3402 | + $args_to_merge[$query_param] = $query_value; |
|
3403 | 3403 | } |
3404 | 3404 | // now let's merge these arguments but override with what was specifically sent in to the |
3405 | 3405 | // redirect. |
@@ -3411,19 +3411,19 @@ discard block |
||
3411 | 3411 | if (isset($query_args['action'])) { |
3412 | 3412 | // manually generate wp_nonce and merge that with the query vars |
3413 | 3413 | // becuz the wp_nonce_url function wrecks havoc on some vars |
3414 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3414 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
3415 | 3415 | } |
3416 | 3416 | // we're adding some hooks and filters in here for processing any things just before redirects |
3417 | 3417 | // (example: an admin page has done an insert or update and we want to run something after that). |
3418 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3418 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
3419 | 3419 | $redirect_url = apply_filters( |
3420 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3420 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
3421 | 3421 | self::add_query_args_and_nonce($query_args, $redirect_url), |
3422 | 3422 | $query_args |
3423 | 3423 | ); |
3424 | 3424 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
3425 | 3425 | if ($this->request->isAjax()) { |
3426 | - $default_data = [ |
|
3426 | + $default_data = [ |
|
3427 | 3427 | 'close' => true, |
3428 | 3428 | 'redirect_url' => $redirect_url, |
3429 | 3429 | 'where' => 'main', |
@@ -3470,7 +3470,7 @@ discard block |
||
3470 | 3470 | } |
3471 | 3471 | $this->_template_args['notices'] = EE_Error::get_notices(); |
3472 | 3472 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
3473 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
3473 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
3474 | 3474 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
3475 | 3475 | $this->_add_transient( |
3476 | 3476 | $route, |
@@ -3510,7 +3510,7 @@ discard block |
||
3510 | 3510 | $exclude_nonce = false |
3511 | 3511 | ) { |
3512 | 3512 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
3513 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3513 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
3514 | 3514 | throw new EE_Error( |
3515 | 3515 | sprintf( |
3516 | 3516 | esc_html__( |
@@ -3521,7 +3521,7 @@ discard block |
||
3521 | 3521 | ) |
3522 | 3522 | ); |
3523 | 3523 | } |
3524 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
3524 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
3525 | 3525 | throw new EE_Error( |
3526 | 3526 | sprintf( |
3527 | 3527 | esc_html__( |
@@ -3534,7 +3534,7 @@ discard block |
||
3534 | 3534 | } |
3535 | 3535 | // finally check user access for this button. |
3536 | 3536 | $has_access = $this->check_user_access($action, true); |
3537 | - if (! $has_access) { |
|
3537 | + if ( ! $has_access) { |
|
3538 | 3538 | return ''; |
3539 | 3539 | } |
3540 | 3540 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3542,11 +3542,11 @@ discard block |
||
3542 | 3542 | 'action' => $action, |
3543 | 3543 | ]; |
3544 | 3544 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
3545 | - if (! empty($extra_request)) { |
|
3545 | + if ( ! empty($extra_request)) { |
|
3546 | 3546 | $query_args = array_merge($extra_request, $query_args); |
3547 | 3547 | } |
3548 | 3548 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
3549 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3549 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
3550 | 3550 | } |
3551 | 3551 | |
3552 | 3552 | |
@@ -3572,7 +3572,7 @@ discard block |
||
3572 | 3572 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
3573 | 3573 | 20 |
3574 | 3574 | ), |
3575 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3575 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
3576 | 3576 | ]; |
3577 | 3577 | // ONLY add the screen option if the user has access to it. |
3578 | 3578 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3593,18 +3593,18 @@ discard block |
||
3593 | 3593 | { |
3594 | 3594 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
3595 | 3595 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
3596 | - if (! $user = wp_get_current_user()) { |
|
3596 | + if ( ! $user = wp_get_current_user()) { |
|
3597 | 3597 | return; |
3598 | 3598 | } |
3599 | 3599 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
3600 | - if (! $option) { |
|
3600 | + if ( ! $option) { |
|
3601 | 3601 | return; |
3602 | 3602 | } |
3603 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
3603 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
3604 | 3604 | $map_option = $option; |
3605 | 3605 | $option = str_replace('-', '_', $option); |
3606 | 3606 | switch ($map_option) { |
3607 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3607 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
3608 | 3608 | $max_value = apply_filters( |
3609 | 3609 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
3610 | 3610 | 999, |
@@ -3661,13 +3661,13 @@ discard block |
||
3661 | 3661 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
3662 | 3662 | { |
3663 | 3663 | $user_id = get_current_user_id(); |
3664 | - if (! $skip_route_verify) { |
|
3664 | + if ( ! $skip_route_verify) { |
|
3665 | 3665 | $this->_verify_route($route); |
3666 | 3666 | } |
3667 | 3667 | // now let's set the string for what kind of transient we're setting |
3668 | 3668 | $transient = $notices |
3669 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3670 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3669 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
3670 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
3671 | 3671 | $data = $notices ? ['notices' => $data] : $data; |
3672 | 3672 | // is there already a transient for this route? If there is then let's ADD to that transient |
3673 | 3673 | $existing = is_multisite() && is_network_admin() |
@@ -3696,8 +3696,8 @@ discard block |
||
3696 | 3696 | $user_id = get_current_user_id(); |
3697 | 3697 | $route = ! $route ? $this->_req_action : $route; |
3698 | 3698 | $transient = $notices |
3699 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3700 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3699 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
3700 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
3701 | 3701 | $data = is_multisite() && is_network_admin() |
3702 | 3702 | ? get_site_transient($transient) |
3703 | 3703 | : get_transient($transient); |
@@ -3928,7 +3928,7 @@ discard block |
||
3928 | 3928 | */ |
3929 | 3929 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
3930 | 3930 | { |
3931 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3931 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
3932 | 3932 | } |
3933 | 3933 | |
3934 | 3934 | |
@@ -3941,7 +3941,7 @@ discard block |
||
3941 | 3941 | */ |
3942 | 3942 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
3943 | 3943 | { |
3944 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
3944 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
3945 | 3945 | } |
3946 | 3946 | |
3947 | 3947 | |
@@ -4089,7 +4089,7 @@ discard block |
||
4089 | 4089 | callable $callback = null |
4090 | 4090 | ) { |
4091 | 4091 | $entity_ID = absint($entity_ID); |
4092 | - if (! $entity_ID) { |
|
4092 | + if ( ! $entity_ID) { |
|
4093 | 4093 | $this->trashRestoreDeleteError($action, $entity_model); |
4094 | 4094 | } |
4095 | 4095 | $result = 0; |
@@ -4135,7 +4135,7 @@ discard block |
||
4135 | 4135 | ) |
4136 | 4136 | ); |
4137 | 4137 | } |
4138 | - if (! $entity_model->has_field($delete_column)) { |
|
4138 | + if ( ! $entity_model->has_field($delete_column)) { |
|
4139 | 4139 | throw new DomainException( |
4140 | 4140 | sprintf( |
4141 | 4141 | esc_html__( |
@@ -16,204 +16,204 @@ |
||
16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param RequestTypeContextCheckerInterface $type |
|
21 | - */ |
|
22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
19 | + /** |
|
20 | + * @param RequestTypeContextCheckerInterface $type |
|
21 | + */ |
|
22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function getParams(); |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function getParams(); |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function postParams(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function cookieParams(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function serverParams(); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param string $key |
|
51 | - * @param mixed|null $default |
|
52 | - * @return array|int|float|string |
|
53 | - */ |
|
54 | - public function getServerParam($key, $default = null); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $key |
|
59 | - * @param array|int|float|string $value |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function setServerParam($key, $value); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * remove param |
|
67 | - * |
|
68 | - * @param string $key |
|
69 | - * @param bool $unset_from_global_too |
|
70 | - */ |
|
71 | - public function unSetServerParam($key, $unset_from_global_too = false); |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $key |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function serverParamIsSet($key); |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function filesParams(); |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * returns sanitized contents of $_REQUEST |
|
89 | - * |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function requestParams(); |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $key |
|
97 | - * @param string $value |
|
98 | - * @param bool $override_ee |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function setRequestParam($key, $value, $override_ee = false); |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * returns the value for a request param if the given key exists |
|
106 | - * |
|
107 | - * @param string $key |
|
108 | - * @param mixed|null $default |
|
109 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
110 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
111 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
112 | - * @return array|bool|float|int|string |
|
113 | - */ |
|
114 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * check if param exists |
|
119 | - * |
|
120 | - * @param string $key |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function requestParamIsSet($key); |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
128 | - * and return the value for the first match found |
|
129 | - * wildcards can be either of the following: |
|
130 | - * ? to represent a single character of any type |
|
131 | - * * to represent one or more characters of any type |
|
132 | - * |
|
133 | - * @param string $pattern |
|
134 | - * @param mixed|null $default |
|
135 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
136 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
137 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
138 | - * @return array|bool|float|int|string |
|
139 | - */ |
|
140 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
145 | - * wildcards can be either of the following: |
|
146 | - * ? to represent a single character of any type |
|
147 | - * * to represent one or more characters of any type |
|
148 | - * returns true if a match is found or false if not |
|
149 | - * |
|
150 | - * @param string $pattern |
|
151 | - * @return false|int |
|
152 | - */ |
|
153 | - public function matches($pattern); |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * remove param |
|
158 | - * |
|
159 | - * @param string $key |
|
160 | - * @param bool $unset_from_global_too |
|
161 | - */ |
|
162 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * remove params |
|
167 | - * |
|
168 | - * @param array $keys |
|
169 | - * @param bool $unset_from_global_too |
|
170 | - */ |
|
171 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function ipAddress(); |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function requestUri($relativeToWpRoot = false); |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function userAgent(); |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param string $user_agent |
|
195 | - */ |
|
196 | - public function setUserAgent($user_agent = ''); |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function isBot(); |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @param bool $is_bot |
|
207 | - */ |
|
208 | - public function setIsBot($is_bot); |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * merges the incoming array of parameters into the existing request parameters |
|
213 | - * |
|
214 | - * @param array $request_params |
|
215 | - * @return mixed |
|
216 | - * @since 4.10.24.p |
|
217 | - */ |
|
218 | - public function mergeRequestParams(array $request_params); |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function postParams(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function cookieParams(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function serverParams(); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param string $key |
|
51 | + * @param mixed|null $default |
|
52 | + * @return array|int|float|string |
|
53 | + */ |
|
54 | + public function getServerParam($key, $default = null); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $key |
|
59 | + * @param array|int|float|string $value |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function setServerParam($key, $value); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * remove param |
|
67 | + * |
|
68 | + * @param string $key |
|
69 | + * @param bool $unset_from_global_too |
|
70 | + */ |
|
71 | + public function unSetServerParam($key, $unset_from_global_too = false); |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $key |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function serverParamIsSet($key); |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function filesParams(); |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * returns sanitized contents of $_REQUEST |
|
89 | + * |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function requestParams(); |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $key |
|
97 | + * @param string $value |
|
98 | + * @param bool $override_ee |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function setRequestParam($key, $value, $override_ee = false); |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * returns the value for a request param if the given key exists |
|
106 | + * |
|
107 | + * @param string $key |
|
108 | + * @param mixed|null $default |
|
109 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
110 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
111 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
112 | + * @return array|bool|float|int|string |
|
113 | + */ |
|
114 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * check if param exists |
|
119 | + * |
|
120 | + * @param string $key |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function requestParamIsSet($key); |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
128 | + * and return the value for the first match found |
|
129 | + * wildcards can be either of the following: |
|
130 | + * ? to represent a single character of any type |
|
131 | + * * to represent one or more characters of any type |
|
132 | + * |
|
133 | + * @param string $pattern |
|
134 | + * @param mixed|null $default |
|
135 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
136 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
137 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
138 | + * @return array|bool|float|int|string |
|
139 | + */ |
|
140 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
145 | + * wildcards can be either of the following: |
|
146 | + * ? to represent a single character of any type |
|
147 | + * * to represent one or more characters of any type |
|
148 | + * returns true if a match is found or false if not |
|
149 | + * |
|
150 | + * @param string $pattern |
|
151 | + * @return false|int |
|
152 | + */ |
|
153 | + public function matches($pattern); |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * remove param |
|
158 | + * |
|
159 | + * @param string $key |
|
160 | + * @param bool $unset_from_global_too |
|
161 | + */ |
|
162 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * remove params |
|
167 | + * |
|
168 | + * @param array $keys |
|
169 | + * @param bool $unset_from_global_too |
|
170 | + */ |
|
171 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function ipAddress(); |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function requestUri($relativeToWpRoot = false); |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public function userAgent(); |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param string $user_agent |
|
195 | + */ |
|
196 | + public function setUserAgent($user_agent = ''); |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function isBot(); |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @param bool $is_bot |
|
207 | + */ |
|
208 | + public function setIsBot($is_bot); |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * merges the incoming array of parameters into the existing request parameters |
|
213 | + * |
|
214 | + * @param array $request_params |
|
215 | + * @return mixed |
|
216 | + * @since 4.10.24.p |
|
217 | + */ |
|
218 | + public function mergeRequestParams(array $request_params); |
|
219 | 219 | } |
@@ -7,204 +7,204 @@ |
||
7 | 7 | class ServerParams |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * IP address for request |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $ip_address; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * @var ServerSanitizer |
|
20 | - */ |
|
21 | - protected $sanitizer; |
|
22 | - |
|
23 | - /** |
|
24 | - * sanitized $_SERVER parameters |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $server; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $request_uri; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $user_agent; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * ServerParams constructor. |
|
43 | - * |
|
44 | - * @param ServerSanitizer $sanitizer |
|
45 | - * @param array $server |
|
46 | - */ |
|
47 | - public function __construct(ServerSanitizer $sanitizer, array $server = []) |
|
48 | - { |
|
49 | - $this->sanitizer = $sanitizer; |
|
50 | - $this->server = $this->cleanServerParams($server); |
|
51 | - $this->ip_address = $this->setVisitorIp(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - private function cleanServerParams(array $server) |
|
59 | - { |
|
60 | - $cleaned = []; |
|
61 | - $server = ! empty($server) ? $server : $_SERVER; |
|
62 | - foreach ($server as $key => $value) { |
|
63 | - $cleaned[ $key ] = $this->sanitizer->clean($key, $value); |
|
64 | - } |
|
65 | - return $cleaned; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function getAllServerParams() |
|
73 | - { |
|
74 | - return $this->server; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $key |
|
80 | - * @param mixed|null $default |
|
81 | - * @return array|int|float|string |
|
82 | - */ |
|
83 | - public function getServerParam($key, $default = null) |
|
84 | - { |
|
85 | - return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @param string $key |
|
91 | - * @param array|int|float|string $value |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function setServerParam($key, $value) |
|
95 | - { |
|
96 | - $clean_value = $this->sanitizer->clean($key, $value); |
|
97 | - $this->server[ $key ] = $clean_value; |
|
98 | - // modify global too |
|
99 | - $_SERVER[ $key ] = $clean_value; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function serverParamIsSet($key) |
|
107 | - { |
|
108 | - return isset($this->server[ $key ]); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * remove param |
|
114 | - * |
|
115 | - * @param string $key |
|
116 | - * @param bool $unset_from_global_too |
|
117 | - */ |
|
118 | - public function unSetServerParam($key, $unset_from_global_too = false) |
|
119 | - { |
|
120 | - // because unset may not actually remove var |
|
121 | - $this->server[ $key ] = null; |
|
122 | - unset($this->server[ $key ]); |
|
123 | - if ($unset_from_global_too) { |
|
124 | - unset($_SERVER[ $key ]); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function ipAddress() |
|
133 | - { |
|
134 | - return $this->ip_address; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * attempt to get IP address of current visitor from server |
|
140 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
141 | - * |
|
142 | - * @access public |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function setVisitorIp() |
|
146 | - { |
|
147 | - $visitor_ip = '0.0.0.0'; |
|
148 | - $server_keys = [ |
|
149 | - 'HTTP_CLIENT_IP', |
|
150 | - 'HTTP_FORWARDED', |
|
151 | - 'HTTP_FORWARDED_FOR', |
|
152 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
153 | - 'HTTP_X_FORWARDED', |
|
154 | - 'HTTP_X_FORWARDED_FOR', |
|
155 | - 'REMOTE_ADDR', |
|
156 | - ]; |
|
157 | - foreach ($server_keys as $key) { |
|
158 | - if (isset($this->server[ $key ])) { |
|
159 | - $potential_ip = array_map('trim', explode(',', $this->server[ $key ])); |
|
160 | - foreach ($potential_ip as $ip) { |
|
161 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
162 | - $visitor_ip = $ip; |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - return $visitor_ip; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
173 | - * |
|
174 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
175 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
176 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function requestUri($relativeToWpRoot = false) |
|
180 | - { |
|
181 | - if ($relativeToWpRoot) { |
|
182 | - $home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
183 | - return str_replace($home_path, '', $this->server['REQUEST_URI']); |
|
184 | - } |
|
185 | - return $this->server['REQUEST_URI']; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public function userAgent() |
|
193 | - { |
|
194 | - if (empty($this->user_agent)) { |
|
195 | - $this->setUserAgent(); |
|
196 | - } |
|
197 | - return $this->user_agent; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $user_agent |
|
203 | - */ |
|
204 | - public function setUserAgent($user_agent = '') |
|
205 | - { |
|
206 | - $this->user_agent = $user_agent === '' || ! is_string($user_agent) |
|
207 | - ? $this->getServerParam('HTTP_USER_AGENT') |
|
208 | - : esc_attr($user_agent); |
|
209 | - } |
|
10 | + /** |
|
11 | + * IP address for request |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $ip_address; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * @var ServerSanitizer |
|
20 | + */ |
|
21 | + protected $sanitizer; |
|
22 | + |
|
23 | + /** |
|
24 | + * sanitized $_SERVER parameters |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $server; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $request_uri; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $user_agent; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * ServerParams constructor. |
|
43 | + * |
|
44 | + * @param ServerSanitizer $sanitizer |
|
45 | + * @param array $server |
|
46 | + */ |
|
47 | + public function __construct(ServerSanitizer $sanitizer, array $server = []) |
|
48 | + { |
|
49 | + $this->sanitizer = $sanitizer; |
|
50 | + $this->server = $this->cleanServerParams($server); |
|
51 | + $this->ip_address = $this->setVisitorIp(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + private function cleanServerParams(array $server) |
|
59 | + { |
|
60 | + $cleaned = []; |
|
61 | + $server = ! empty($server) ? $server : $_SERVER; |
|
62 | + foreach ($server as $key => $value) { |
|
63 | + $cleaned[ $key ] = $this->sanitizer->clean($key, $value); |
|
64 | + } |
|
65 | + return $cleaned; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function getAllServerParams() |
|
73 | + { |
|
74 | + return $this->server; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $key |
|
80 | + * @param mixed|null $default |
|
81 | + * @return array|int|float|string |
|
82 | + */ |
|
83 | + public function getServerParam($key, $default = null) |
|
84 | + { |
|
85 | + return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @param string $key |
|
91 | + * @param array|int|float|string $value |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function setServerParam($key, $value) |
|
95 | + { |
|
96 | + $clean_value = $this->sanitizer->clean($key, $value); |
|
97 | + $this->server[ $key ] = $clean_value; |
|
98 | + // modify global too |
|
99 | + $_SERVER[ $key ] = $clean_value; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function serverParamIsSet($key) |
|
107 | + { |
|
108 | + return isset($this->server[ $key ]); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * remove param |
|
114 | + * |
|
115 | + * @param string $key |
|
116 | + * @param bool $unset_from_global_too |
|
117 | + */ |
|
118 | + public function unSetServerParam($key, $unset_from_global_too = false) |
|
119 | + { |
|
120 | + // because unset may not actually remove var |
|
121 | + $this->server[ $key ] = null; |
|
122 | + unset($this->server[ $key ]); |
|
123 | + if ($unset_from_global_too) { |
|
124 | + unset($_SERVER[ $key ]); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function ipAddress() |
|
133 | + { |
|
134 | + return $this->ip_address; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * attempt to get IP address of current visitor from server |
|
140 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
141 | + * |
|
142 | + * @access public |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function setVisitorIp() |
|
146 | + { |
|
147 | + $visitor_ip = '0.0.0.0'; |
|
148 | + $server_keys = [ |
|
149 | + 'HTTP_CLIENT_IP', |
|
150 | + 'HTTP_FORWARDED', |
|
151 | + 'HTTP_FORWARDED_FOR', |
|
152 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
153 | + 'HTTP_X_FORWARDED', |
|
154 | + 'HTTP_X_FORWARDED_FOR', |
|
155 | + 'REMOTE_ADDR', |
|
156 | + ]; |
|
157 | + foreach ($server_keys as $key) { |
|
158 | + if (isset($this->server[ $key ])) { |
|
159 | + $potential_ip = array_map('trim', explode(',', $this->server[ $key ])); |
|
160 | + foreach ($potential_ip as $ip) { |
|
161 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
162 | + $visitor_ip = $ip; |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + return $visitor_ip; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
173 | + * |
|
174 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
175 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
176 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function requestUri($relativeToWpRoot = false) |
|
180 | + { |
|
181 | + if ($relativeToWpRoot) { |
|
182 | + $home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
183 | + return str_replace($home_path, '', $this->server['REQUEST_URI']); |
|
184 | + } |
|
185 | + return $this->server['REQUEST_URI']; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public function userAgent() |
|
193 | + { |
|
194 | + if (empty($this->user_agent)) { |
|
195 | + $this->setUserAgent(); |
|
196 | + } |
|
197 | + return $this->user_agent; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $user_agent |
|
203 | + */ |
|
204 | + public function setUserAgent($user_agent = '') |
|
205 | + { |
|
206 | + $this->user_agent = $user_agent === '' || ! is_string($user_agent) |
|
207 | + ? $this->getServerParam('HTTP_USER_AGENT') |
|
208 | + : esc_attr($user_agent); |
|
209 | + } |
|
210 | 210 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $cleaned = []; |
61 | 61 | $server = ! empty($server) ? $server : $_SERVER; |
62 | 62 | foreach ($server as $key => $value) { |
63 | - $cleaned[ $key ] = $this->sanitizer->clean($key, $value); |
|
63 | + $cleaned[$key] = $this->sanitizer->clean($key, $value); |
|
64 | 64 | } |
65 | 65 | return $cleaned; |
66 | 66 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getServerParam($key, $default = null) |
84 | 84 | { |
85 | - return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default; |
|
85 | + return $this->serverParamIsSet($key) ? $this->server[$key] : $default; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | public function setServerParam($key, $value) |
95 | 95 | { |
96 | 96 | $clean_value = $this->sanitizer->clean($key, $value); |
97 | - $this->server[ $key ] = $clean_value; |
|
97 | + $this->server[$key] = $clean_value; |
|
98 | 98 | // modify global too |
99 | - $_SERVER[ $key ] = $clean_value; |
|
99 | + $_SERVER[$key] = $clean_value; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function serverParamIsSet($key) |
107 | 107 | { |
108 | - return isset($this->server[ $key ]); |
|
108 | + return isset($this->server[$key]); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | public function unSetServerParam($key, $unset_from_global_too = false) |
119 | 119 | { |
120 | 120 | // because unset may not actually remove var |
121 | - $this->server[ $key ] = null; |
|
122 | - unset($this->server[ $key ]); |
|
121 | + $this->server[$key] = null; |
|
122 | + unset($this->server[$key]); |
|
123 | 123 | if ($unset_from_global_too) { |
124 | - unset($_SERVER[ $key ]); |
|
124 | + unset($_SERVER[$key]); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | 'REMOTE_ADDR', |
156 | 156 | ]; |
157 | 157 | foreach ($server_keys as $key) { |
158 | - if (isset($this->server[ $key ])) { |
|
159 | - $potential_ip = array_map('trim', explode(',', $this->server[ $key ])); |
|
158 | + if (isset($this->server[$key])) { |
|
159 | + $potential_ip = array_map('trim', explode(',', $this->server[$key])); |
|
160 | 160 | foreach ($potential_ip as $ip) { |
161 | 161 | if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
162 | 162 | $visitor_ip = $ip; |
@@ -17,507 +17,507 @@ |
||
17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_COOKIE parameters |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $cookies; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_FILES parameters |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $files; |
|
33 | - |
|
34 | - /** |
|
35 | - * true if current user appears to be some kind of bot |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - protected $is_bot; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var RequestParams |
|
43 | - */ |
|
44 | - protected $request_params; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var RequestTypeContextCheckerInterface |
|
48 | - */ |
|
49 | - protected $request_type; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var ServerParams |
|
53 | - */ |
|
54 | - protected $server_params; |
|
55 | - |
|
56 | - |
|
57 | - public function __construct( |
|
58 | - RequestParams $request_params, |
|
59 | - ServerParams $server_params, |
|
60 | - array $cookies = [], |
|
61 | - array $files = [] |
|
62 | - ) { |
|
63 | - $this->cookies = ! empty($cookies) |
|
64 | - ? $cookies |
|
65 | - : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
66 | - $this->files = ! empty($files) ? $files : $_FILES; |
|
67 | - $this->request_params = $request_params; |
|
68 | - $this->server_params = $server_params; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param RequestTypeContextCheckerInterface $type |
|
74 | - */ |
|
75 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
76 | - { |
|
77 | - $this->request_type = $type; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getParams() |
|
85 | - { |
|
86 | - return $this->request_params->getParams(); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function postParams() |
|
94 | - { |
|
95 | - return $this->request_params->postParams(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function cookieParams() |
|
103 | - { |
|
104 | - return $this->cookies; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function serverParams() |
|
112 | - { |
|
113 | - return $this->server_params->getAllServerParams(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $key |
|
119 | - * @param mixed|null $default |
|
120 | - * @return array|int|float|string |
|
121 | - */ |
|
122 | - public function getServerParam($key, $default = null) |
|
123 | - { |
|
124 | - return $this->server_params->getServerParam($key, $default); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $key |
|
130 | - * @param array|int|float|string $value |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function setServerParam($key, $value) |
|
134 | - { |
|
135 | - $this->server_params->setServerParam($key, $value); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function serverParamIsSet($key) |
|
144 | - { |
|
145 | - return $this->server_params->serverParamIsSet($key); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function filesParams() |
|
153 | - { |
|
154 | - return $this->files; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * returns sanitized contents of $_REQUEST |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function requestParams() |
|
164 | - { |
|
165 | - return $this->request_params->requestParams(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $key |
|
171 | - * @param mixed|null $value |
|
172 | - * @param bool $override_ee |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function setRequestParam($key, $value, $override_ee = false) |
|
176 | - { |
|
177 | - $this->request_params->setRequestParam($key, $value, $override_ee); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * merges the incoming array of parameters into the existing request parameters |
|
183 | - * |
|
184 | - * @param array $request_params |
|
185 | - * @return void |
|
186 | - * @since 4.10.24.p |
|
187 | - */ |
|
188 | - public function mergeRequestParams(array $request_params) |
|
189 | - { |
|
190 | - $this->request_params->mergeRequestParams($request_params); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * returns sanitized value for a request param if the given key exists |
|
196 | - * |
|
197 | - * @param string $key |
|
198 | - * @param mixed|null $default |
|
199 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
200 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
201 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
202 | - * @return array|bool|float|int|string |
|
203 | - */ |
|
204 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
205 | - { |
|
206 | - return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * check if param exists |
|
212 | - * |
|
213 | - * @param string $key |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function requestParamIsSet($key) |
|
217 | - { |
|
218 | - return $this->request_params->requestParamIsSet($key); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
224 | - * and return the sanitized value for the first match found |
|
225 | - * wildcards can be either of the following: |
|
226 | - * ? to represent a single character of any type |
|
227 | - * * to represent one or more characters of any type |
|
228 | - * |
|
229 | - * @param string $pattern |
|
230 | - * @param mixed|null $default |
|
231 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
232 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
233 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
234 | - * @return array|bool|float|int|string |
|
235 | - */ |
|
236 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
237 | - { |
|
238 | - return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
244 | - * wildcards can be either of the following: |
|
245 | - * ? to represent a single character of any type |
|
246 | - * * to represent one or more characters of any type |
|
247 | - * returns true if a match is found or false if not |
|
248 | - * |
|
249 | - * @param string $pattern |
|
250 | - * @return bool |
|
251 | - */ |
|
252 | - public function matches($pattern) |
|
253 | - { |
|
254 | - return $this->request_params->matches($pattern); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * remove param |
|
260 | - * |
|
261 | - * @param $key |
|
262 | - * @param bool $unset_from_global_too |
|
263 | - */ |
|
264 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
265 | - { |
|
266 | - $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * remove param |
|
272 | - * |
|
273 | - * @param $key |
|
274 | - * @param bool $unset_from_global_too |
|
275 | - */ |
|
276 | - public function unSetServerParam($key, $unset_from_global_too = false) |
|
277 | - { |
|
278 | - $this->server_params->unSetServerParam($key, $unset_from_global_too); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * remove params |
|
284 | - * |
|
285 | - * @param array $keys |
|
286 | - * @param bool $unset_from_global_too |
|
287 | - */ |
|
288 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
289 | - { |
|
290 | - $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function ipAddress() |
|
298 | - { |
|
299 | - return $this->server_params->ipAddress(); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
305 | - * |
|
306 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
307 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
308 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
309 | - * @return string |
|
310 | - */ |
|
311 | - public function requestUri($relativeToWpRoot = false) |
|
312 | - { |
|
313 | - return $this->server_params->requestUri($relativeToWpRoot); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function userAgent() |
|
321 | - { |
|
322 | - return $this->server_params->userAgent(); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string $user_agent |
|
328 | - */ |
|
329 | - public function setUserAgent($user_agent = '') |
|
330 | - { |
|
331 | - $this->server_params->setUserAgent($user_agent); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - public function isBot() |
|
339 | - { |
|
340 | - return $this->is_bot; |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @param bool $is_bot |
|
346 | - */ |
|
347 | - public function setIsBot($is_bot) |
|
348 | - { |
|
349 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @return bool |
|
355 | - */ |
|
356 | - public function isActivation() |
|
357 | - { |
|
358 | - return $this->request_type->isActivation(); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @param $is_activation |
|
364 | - * @return bool |
|
365 | - */ |
|
366 | - public function setIsActivation($is_activation) |
|
367 | - { |
|
368 | - return $this->request_type->setIsActivation($is_activation); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function isAdmin() |
|
376 | - { |
|
377 | - return $this->request_type->isAdmin(); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @return bool |
|
383 | - */ |
|
384 | - public function isAdminAjax() |
|
385 | - { |
|
386 | - return $this->request_type->isAdminAjax(); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * @return bool |
|
392 | - */ |
|
393 | - public function isAjax() |
|
394 | - { |
|
395 | - return $this->request_type->isAjax(); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * @return bool |
|
401 | - */ |
|
402 | - public function isEeAjax() |
|
403 | - { |
|
404 | - return $this->request_type->isEeAjax(); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @return bool |
|
410 | - */ |
|
411 | - public function isOtherAjax() |
|
412 | - { |
|
413 | - return $this->request_type->isOtherAjax(); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * @return bool |
|
419 | - */ |
|
420 | - public function isApi() |
|
421 | - { |
|
422 | - return $this->request_type->isApi(); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * @return bool |
|
428 | - */ |
|
429 | - public function isCli() |
|
430 | - { |
|
431 | - return $this->request_type->isCli(); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @return bool |
|
437 | - */ |
|
438 | - public function isCron() |
|
439 | - { |
|
440 | - return $this->request_type->isCron(); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * @return bool |
|
446 | - */ |
|
447 | - public function isFeed() |
|
448 | - { |
|
449 | - return $this->request_type->isFeed(); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * @return bool |
|
455 | - */ |
|
456 | - public function isFrontend() |
|
457 | - { |
|
458 | - return $this->request_type->isFrontend(); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @return bool |
|
464 | - */ |
|
465 | - public function isFrontAjax() |
|
466 | - { |
|
467 | - return $this->request_type->isFrontAjax(); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * @return bool |
|
473 | - */ |
|
474 | - public function isIframe() |
|
475 | - { |
|
476 | - return $this->request_type->isIframe(); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * @return bool |
|
482 | - */ |
|
483 | - public function isWordPressApi() |
|
484 | - { |
|
485 | - return $this->request_type->isWordPressApi(); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return bool |
|
491 | - */ |
|
492 | - public function isWordPressHeartbeat() |
|
493 | - { |
|
494 | - return $this->request_type->isWordPressHeartbeat(); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * @return bool |
|
500 | - */ |
|
501 | - public function isWordPressScrape() |
|
502 | - { |
|
503 | - return $this->request_type->isWordPressScrape(); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * @return string |
|
509 | - */ |
|
510 | - public function slug() |
|
511 | - { |
|
512 | - return $this->request_type->slug(); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * @return RequestTypeContextCheckerInterface |
|
518 | - */ |
|
519 | - public function getRequestType() |
|
520 | - { |
|
521 | - return $this->request_type; |
|
522 | - } |
|
20 | + /** |
|
21 | + * $_COOKIE parameters |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $cookies; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_FILES parameters |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $files; |
|
33 | + |
|
34 | + /** |
|
35 | + * true if current user appears to be some kind of bot |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + protected $is_bot; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var RequestParams |
|
43 | + */ |
|
44 | + protected $request_params; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var RequestTypeContextCheckerInterface |
|
48 | + */ |
|
49 | + protected $request_type; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var ServerParams |
|
53 | + */ |
|
54 | + protected $server_params; |
|
55 | + |
|
56 | + |
|
57 | + public function __construct( |
|
58 | + RequestParams $request_params, |
|
59 | + ServerParams $server_params, |
|
60 | + array $cookies = [], |
|
61 | + array $files = [] |
|
62 | + ) { |
|
63 | + $this->cookies = ! empty($cookies) |
|
64 | + ? $cookies |
|
65 | + : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
66 | + $this->files = ! empty($files) ? $files : $_FILES; |
|
67 | + $this->request_params = $request_params; |
|
68 | + $this->server_params = $server_params; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param RequestTypeContextCheckerInterface $type |
|
74 | + */ |
|
75 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
76 | + { |
|
77 | + $this->request_type = $type; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getParams() |
|
85 | + { |
|
86 | + return $this->request_params->getParams(); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function postParams() |
|
94 | + { |
|
95 | + return $this->request_params->postParams(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function cookieParams() |
|
103 | + { |
|
104 | + return $this->cookies; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function serverParams() |
|
112 | + { |
|
113 | + return $this->server_params->getAllServerParams(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $key |
|
119 | + * @param mixed|null $default |
|
120 | + * @return array|int|float|string |
|
121 | + */ |
|
122 | + public function getServerParam($key, $default = null) |
|
123 | + { |
|
124 | + return $this->server_params->getServerParam($key, $default); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $key |
|
130 | + * @param array|int|float|string $value |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function setServerParam($key, $value) |
|
134 | + { |
|
135 | + $this->server_params->setServerParam($key, $value); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function serverParamIsSet($key) |
|
144 | + { |
|
145 | + return $this->server_params->serverParamIsSet($key); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function filesParams() |
|
153 | + { |
|
154 | + return $this->files; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * returns sanitized contents of $_REQUEST |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function requestParams() |
|
164 | + { |
|
165 | + return $this->request_params->requestParams(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $key |
|
171 | + * @param mixed|null $value |
|
172 | + * @param bool $override_ee |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function setRequestParam($key, $value, $override_ee = false) |
|
176 | + { |
|
177 | + $this->request_params->setRequestParam($key, $value, $override_ee); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * merges the incoming array of parameters into the existing request parameters |
|
183 | + * |
|
184 | + * @param array $request_params |
|
185 | + * @return void |
|
186 | + * @since 4.10.24.p |
|
187 | + */ |
|
188 | + public function mergeRequestParams(array $request_params) |
|
189 | + { |
|
190 | + $this->request_params->mergeRequestParams($request_params); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * returns sanitized value for a request param if the given key exists |
|
196 | + * |
|
197 | + * @param string $key |
|
198 | + * @param mixed|null $default |
|
199 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
200 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
201 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
202 | + * @return array|bool|float|int|string |
|
203 | + */ |
|
204 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
205 | + { |
|
206 | + return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * check if param exists |
|
212 | + * |
|
213 | + * @param string $key |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function requestParamIsSet($key) |
|
217 | + { |
|
218 | + return $this->request_params->requestParamIsSet($key); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
224 | + * and return the sanitized value for the first match found |
|
225 | + * wildcards can be either of the following: |
|
226 | + * ? to represent a single character of any type |
|
227 | + * * to represent one or more characters of any type |
|
228 | + * |
|
229 | + * @param string $pattern |
|
230 | + * @param mixed|null $default |
|
231 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
232 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
233 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
234 | + * @return array|bool|float|int|string |
|
235 | + */ |
|
236 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
237 | + { |
|
238 | + return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
244 | + * wildcards can be either of the following: |
|
245 | + * ? to represent a single character of any type |
|
246 | + * * to represent one or more characters of any type |
|
247 | + * returns true if a match is found or false if not |
|
248 | + * |
|
249 | + * @param string $pattern |
|
250 | + * @return bool |
|
251 | + */ |
|
252 | + public function matches($pattern) |
|
253 | + { |
|
254 | + return $this->request_params->matches($pattern); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * remove param |
|
260 | + * |
|
261 | + * @param $key |
|
262 | + * @param bool $unset_from_global_too |
|
263 | + */ |
|
264 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
265 | + { |
|
266 | + $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * remove param |
|
272 | + * |
|
273 | + * @param $key |
|
274 | + * @param bool $unset_from_global_too |
|
275 | + */ |
|
276 | + public function unSetServerParam($key, $unset_from_global_too = false) |
|
277 | + { |
|
278 | + $this->server_params->unSetServerParam($key, $unset_from_global_too); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * remove params |
|
284 | + * |
|
285 | + * @param array $keys |
|
286 | + * @param bool $unset_from_global_too |
|
287 | + */ |
|
288 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
289 | + { |
|
290 | + $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function ipAddress() |
|
298 | + { |
|
299 | + return $this->server_params->ipAddress(); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
305 | + * |
|
306 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
307 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
308 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
309 | + * @return string |
|
310 | + */ |
|
311 | + public function requestUri($relativeToWpRoot = false) |
|
312 | + { |
|
313 | + return $this->server_params->requestUri($relativeToWpRoot); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function userAgent() |
|
321 | + { |
|
322 | + return $this->server_params->userAgent(); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string $user_agent |
|
328 | + */ |
|
329 | + public function setUserAgent($user_agent = '') |
|
330 | + { |
|
331 | + $this->server_params->setUserAgent($user_agent); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + public function isBot() |
|
339 | + { |
|
340 | + return $this->is_bot; |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @param bool $is_bot |
|
346 | + */ |
|
347 | + public function setIsBot($is_bot) |
|
348 | + { |
|
349 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @return bool |
|
355 | + */ |
|
356 | + public function isActivation() |
|
357 | + { |
|
358 | + return $this->request_type->isActivation(); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @param $is_activation |
|
364 | + * @return bool |
|
365 | + */ |
|
366 | + public function setIsActivation($is_activation) |
|
367 | + { |
|
368 | + return $this->request_type->setIsActivation($is_activation); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function isAdmin() |
|
376 | + { |
|
377 | + return $this->request_type->isAdmin(); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @return bool |
|
383 | + */ |
|
384 | + public function isAdminAjax() |
|
385 | + { |
|
386 | + return $this->request_type->isAdminAjax(); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * @return bool |
|
392 | + */ |
|
393 | + public function isAjax() |
|
394 | + { |
|
395 | + return $this->request_type->isAjax(); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * @return bool |
|
401 | + */ |
|
402 | + public function isEeAjax() |
|
403 | + { |
|
404 | + return $this->request_type->isEeAjax(); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @return bool |
|
410 | + */ |
|
411 | + public function isOtherAjax() |
|
412 | + { |
|
413 | + return $this->request_type->isOtherAjax(); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * @return bool |
|
419 | + */ |
|
420 | + public function isApi() |
|
421 | + { |
|
422 | + return $this->request_type->isApi(); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * @return bool |
|
428 | + */ |
|
429 | + public function isCli() |
|
430 | + { |
|
431 | + return $this->request_type->isCli(); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @return bool |
|
437 | + */ |
|
438 | + public function isCron() |
|
439 | + { |
|
440 | + return $this->request_type->isCron(); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * @return bool |
|
446 | + */ |
|
447 | + public function isFeed() |
|
448 | + { |
|
449 | + return $this->request_type->isFeed(); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * @return bool |
|
455 | + */ |
|
456 | + public function isFrontend() |
|
457 | + { |
|
458 | + return $this->request_type->isFrontend(); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @return bool |
|
464 | + */ |
|
465 | + public function isFrontAjax() |
|
466 | + { |
|
467 | + return $this->request_type->isFrontAjax(); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * @return bool |
|
473 | + */ |
|
474 | + public function isIframe() |
|
475 | + { |
|
476 | + return $this->request_type->isIframe(); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * @return bool |
|
482 | + */ |
|
483 | + public function isWordPressApi() |
|
484 | + { |
|
485 | + return $this->request_type->isWordPressApi(); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return bool |
|
491 | + */ |
|
492 | + public function isWordPressHeartbeat() |
|
493 | + { |
|
494 | + return $this->request_type->isWordPressHeartbeat(); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * @return bool |
|
500 | + */ |
|
501 | + public function isWordPressScrape() |
|
502 | + { |
|
503 | + return $this->request_type->isWordPressScrape(); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * @return string |
|
509 | + */ |
|
510 | + public function slug() |
|
511 | + { |
|
512 | + return $this->request_type->slug(); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * @return RequestTypeContextCheckerInterface |
|
518 | + */ |
|
519 | + public function getRequestType() |
|
520 | + { |
|
521 | + return $this->request_type; |
|
522 | + } |
|
523 | 523 | } |
@@ -14,69 +14,69 @@ |
||
14 | 14 | */ |
15 | 15 | class RegistrationsCsvReportParams |
16 | 16 | { |
17 | - /** |
|
18 | - * @param string $return_url |
|
19 | - * @param array $request_params |
|
20 | - * @param int $EVT_ID |
|
21 | - * @param int $DTT_ID |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public static function getRequestParams( |
|
25 | - $return_url, |
|
26 | - $request_params = [], |
|
27 | - $EVT_ID = 0, |
|
28 | - $DTT_ID = 0 |
|
29 | - ) { |
|
30 | - if ( |
|
31 | - ! EE_Capabilities::instance()->current_user_can( |
|
32 | - 'ee_read_registrations', |
|
33 | - 'espresso_registrations_registrations_reports', |
|
34 | - $EVT_ID |
|
35 | - ) |
|
36 | - ) { |
|
37 | - return []; |
|
38 | - } |
|
39 | - unset($request_params['_wp_http_referer']); |
|
40 | - add_action( |
|
41 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
42 | - [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
43 | - ); |
|
17 | + /** |
|
18 | + * @param string $return_url |
|
19 | + * @param array $request_params |
|
20 | + * @param int $EVT_ID |
|
21 | + * @param int $DTT_ID |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public static function getRequestParams( |
|
25 | + $return_url, |
|
26 | + $request_params = [], |
|
27 | + $EVT_ID = 0, |
|
28 | + $DTT_ID = 0 |
|
29 | + ) { |
|
30 | + if ( |
|
31 | + ! EE_Capabilities::instance()->current_user_can( |
|
32 | + 'ee_read_registrations', |
|
33 | + 'espresso_registrations_registrations_reports', |
|
34 | + $EVT_ID |
|
35 | + ) |
|
36 | + ) { |
|
37 | + return []; |
|
38 | + } |
|
39 | + unset($request_params['_wp_http_referer']); |
|
40 | + add_action( |
|
41 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
42 | + [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
43 | + ); |
|
44 | 44 | |
45 | - $route_details = [ |
|
46 | - 'route' => 'registrations_report', |
|
47 | - 'extra_request' => [ 'return_url' => $return_url ], |
|
48 | - ]; |
|
49 | - if (! empty($EVT_ID)) { |
|
50 | - $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
51 | - } |
|
52 | - if ($DTT_ID) { |
|
53 | - $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
54 | - } |
|
55 | - if ( |
|
56 | - isset($request_params['use_filters']) |
|
57 | - && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
58 | - ) { |
|
59 | - $route_details['extra_request']['filters'] = array_diff_key( |
|
60 | - $request_params, |
|
61 | - [ |
|
62 | - 'page' => '', |
|
63 | - 'action' => '', |
|
64 | - 'default_nonce' => '', |
|
65 | - ] |
|
66 | - ); |
|
67 | - } |
|
68 | - return $route_details; |
|
69 | - } |
|
45 | + $route_details = [ |
|
46 | + 'route' => 'registrations_report', |
|
47 | + 'extra_request' => [ 'return_url' => $return_url ], |
|
48 | + ]; |
|
49 | + if (! empty($EVT_ID)) { |
|
50 | + $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
51 | + } |
|
52 | + if ($DTT_ID) { |
|
53 | + $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
54 | + } |
|
55 | + if ( |
|
56 | + isset($request_params['use_filters']) |
|
57 | + && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
58 | + ) { |
|
59 | + $route_details['extra_request']['filters'] = array_diff_key( |
|
60 | + $request_params, |
|
61 | + [ |
|
62 | + 'page' => '', |
|
63 | + 'action' => '', |
|
64 | + 'default_nonce' => '', |
|
65 | + ] |
|
66 | + ); |
|
67 | + } |
|
68 | + return $route_details; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - public static function csvReportNotice() |
|
73 | - { |
|
74 | - echo ' |
|
72 | + public static function csvReportNotice() |
|
73 | + { |
|
74 | + echo ' |
|
75 | 75 | <span class="csv-report-notice__wrapper"> |
76 | 76 | <span class="dashicons dashicons-info"></span> |
77 | 77 | <span class="csv-report-notice__text"> |
78 | 78 | ' . esc_html('All Registration CSV Reports are now triggered by the preceding button') . ' |
79 | 79 | </span> |
80 | 80 | </span>'; |
81 | - } |
|
81 | + } |
|
82 | 82 | } |