Completed
Branch TASK-9118-extensions-page (04eaec)
by
unknown
38:06 queued 23:39
created

EE_Admin_Page   F

Complexity

Total Complexity 440

Size/Duplication

Total Lines 3391
Duplicated Lines 1.03 %

Coupling/Cohesion

Components 1
Dependencies 15
Metric Value
wmc 440
lcom 1
cbo 15
dl 35
loc 3391
rs 0.6314

121 Methods

Rating   Name   Duplication   Size   Complexity  
_init_page_props() 0 1 ?
_ajax_hooks() 0 1 ?
_define_page_props() 0 1 ?
_set_page_routes() 0 1 ?
_set_page_config() 0 1 ?
_add_screen_options() 0 1 ?
_add_feature_pointers() 0 1 ?
load_scripts_styles() 0 1 ?
admin_init() 0 1 ?
admin_notices() 0 1 ?
admin_footer_scripts() 0 1 ?
A admin_footer() 0 1 1
A _global_ajax_hooks() 0 4 1
F _page_setup() 0 92 24
A _verify_nonce() 0 16 4
A add_query_args_and_nonce() 0 19 4
A _get_help_tab_link() 0 3 1
A admin_init_global() 0 2 1
A wp_loaded() 0 1 1
A admin_notices_global() 0 4 1
A network_admin_notices_global() 0 4 1
A _add_global_screen_options() 0 1 1
A _add_global_feature_pointers() 0 1 1
A add_xdebug_style() 0 3 1
A _set_list_table_view() 0 11 4
A _set_search_attributes() 0 4 2
A _espresso_links_post_box() 0 4 1
A espresso_sponsors_post_box() 0 4 1
A set_publish_post_box_vars() 0 3 1
A _display_espresso_notices() 0 4 1
A _add_admin_page_meta_box() 0 16 4
A display_admin_page_with_sidebar() 0 4 1
A display_admin_page_with_no_sidebar() 0 3 1
A display_about_admin_page() 0 3 1
A display_admin_list_table_page_with_sidebar() 0 3 1
A display_admin_list_table_page_with_no_sidebar() 0 3 1
A set_hook_object() 0 3 1
A set_add_edit_form_tags() 0 3 1
A redirect_after_action() 0 3 1
A _process_notices() 0 10 4
A set_template_args() 0 3 1
B _get_transient() 0 13 9
A get_view() 0 3 1
A get_views() 0 3 1
A get_current_page() 0 3 1
A get_current_view() 0 3 1
A get_current_screen() 0 3 1
A get_current_page_view_url() 0 3 1
A get_request_data() 0 3 1
A get_req_action() 0 3 1
A is_caf() 0 3 1
A get_yes_no_values() 0 3 1
A _get_dir() 0 4 1
A _next_link() 0 3 1
A _previous_link() 0 3 1
B __construct() 0 41 3
A ajax_metabox_content() 0 7 3
A _do_other_page_hooks() 5 21 3
A load_page_dependencies() 0 7 2
C _load_page_dependencies() 0 71 8
A _set_defaults() 0 16 1
A route_admin_request() 0 7 2
A set_wp_page_slug() 0 8 2
C _verify_routes() 7 53 13
A _verify_route() 7 11 2
F _route_admin_request() 5 60 23
A _reset_routing_properties() 0 7 1
F _add_help_tabs() 4 105 29
C _add_help_tour() 5 52 12
A _add_qtips() 0 12 2
D _set_nav_tabs() 0 38 17
B _set_current_labels() 0 13 6
F check_user_access() 0 22 17
B admin_footer_scripts_global() 0 10 5
A admin_footer_global() 0 17 2
B _set_help_popup_content() 0 29 6
A _get_help_content() 0 18 3
B _set_help_trigger() 0 25 5
D load_global_scripts_styles() 0 97 10
A admin_footer_scripts_eei18n_js_strings() 0 51 1
B _set_list_table() 0 25 3
A _set_list_table_object() 2 8 3
B get_list_table_view_RLs() 0 25 5
C _entries_per_page_dropdown() 0 38 7
B _add_registered_meta_boxes() 0 19 6
B _add_screen_columns() 0 17 6
A _espresso_news_post_box() 0 7 1
A _espresso_ratings_request() 0 10 2
A espresso_ratings_request() 0 5 1
B cached_rss_display() 0 24 4
A espresso_news_post_box() 0 16 1
A espresso_links_post_box() 0 5 1
A _espresso_sponsors_post_box() 0 6 2
A _publish_post_box() 0 15 3
A editor_overview() 0 6 2
D _set_publish_post_box_vars() 0 30 10
A _display_no_javascript_warning() 0 12 1
A _add_admin_page_ajax_loading_img() 0 7 1
A _add_admin_page_overlay() 0 5 1
A display_admin_page_with_metabox_columns() 0 7 1
C _display_admin_page() 0 26 7
A display_admin_caf_preview_page() 0 18 2
B _display_admin_list_table_page() 0 39 6
A _display_legend() 0 5 1
C _return_json() 0 28 8
A return_json() 0 8 3
B admin_page_wrapper() 0 32 6
A _get_main_nav_tabs() 0 5 1
A _sort_nav_tabs() 0 6 3
A _generate_admin_form_fields() 0 5 2
C _set_save_buttons() 0 22 7
B _set_add_edit_form_tags() 0 30 4
F _redirect_after_action() 0 115 21
C get_action_link_or_button() 0 29 7
A _per_page_screen_option() 0 12 2
D _set_per_page_screen_options() 0 34 9
C _add_transient() 0 22 9
B _transient_garbage_collection() 0 15 5
B _update_espresso_configuration() 0 20 5
A _process_resend_registration() 0 5 1
A _process_payment_notification() 0 6 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EE_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EE_Admin_Page, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * Event Espresso
4
 *
5
 * Event Registration and Management Plugin for WordPress
6
 *
7
 * @ package			Event Espresso
8
 * @ author				Seth Shoultes
9
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license			{@link http://eventespresso.com/support/terms-conditions/}   * see Plugin Licensing *
11
 * @ link				{@link http://www.eventespresso.com}
12
 * @ since		 		4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 */
16
17
18
19
/**
20
 * EE_Admin_Page class
21
 *
22
 * @package		Event Espresso
23
 * @subpackage		includes/core/admin/EE_Admin_Page.core.php
24
 * @abstract
25
 * @author		Brent Christensen, Darren Ethier
26
 *
27
 * ------------------------------------------------------------------------
28
 */
29
abstract class EE_Admin_Page extends EE_BASE {
30
31
32
	//set in _init_page_props()
33
	public $page_slug;
34
	public $page_label;
35
	public $page_folder;
36
37
	//set in define_page_props()
38
	protected $_admin_base_url;
39
	protected $_admin_base_path;
40
	protected $_admin_page_title;
41
	protected $_labels;
42
43
44
	//set early within EE_Admin_Init
45
	protected $_wp_page_slug;
46
47
	//navtabs
48
	protected $_nav_tabs;
49
	protected $_default_nav_tab_name;
50
51
	//helptourstops
52
	protected $_help_tour = array();
53
54
55
	//template variables (used by templates)
56
	protected $_template_path;
57
	protected $_column_template_path;
58
	protected $_template_args;
59
60
	//this will hold the list table object for a given view.
61
	protected $_list_table_object;
62
63
	//bools
64
	protected $_is_UI_request = NULL; //this starts at null so we can have no header routes progress through two states.
65
	protected $_routing;
66
67
	//list table args
68
	protected $_view;
69
	protected $_views;
70
71
72
	//action => method pairs used for routing incoming requests
73
	protected $_page_routes;
74
	protected $_page_config;
75
76
	//the current page route and route config
77
	protected $_route;
78
	protected $_route_config;
79
80
	/**
81
	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
82
	 * actions.
83
	 *
84
	 * @since 4.6.x
85
	 * @var array.
86
	 */
87
	protected $_default_route_query_args;
88
89
	//set via request page and action args.
90
	protected $_current_page;
91
	protected $_current_view;
92
	protected $_current_page_view_url;
93
94
	//sanitized request action (and nonce)
95
	protected $_req_action;
96
	protected $_req_nonce;
97
98
	//search related
99
	protected $_search_btn_label;
100
	protected $_search_box_callback;
101
102
	/**
103
	 * WP Current Screen object
104
	 *
105
	 * @var WP_Screen
106
	 */
107
	protected $_current_screen;
108
109
	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
110
	protected $_hook_obj;
111
112
	//for holding incoming request data
113
	protected $_req_data;
114
115
	// yes / no array for admin form fields
116
	protected $_yes_no_values = array();
117
118
	//some default things shared by all child classes
119
	protected $_default_espresso_metaboxes;
120
121
	/**
122
	 * 	EE_Registry Object
123
	 *	@var 	EE_Registry
124
	 * 	@access 	protected
125
	 */
126
	protected $EE = NULL;
127
128
129
130
	/**
131
	 * This is just a property that flags whether the given route is a caffeinated route or not.
132
	 * @var boolean
133
	 */
134
	protected $_is_caf = FALSE;
135
136
137
138
139
140
	/**
141
	 * 		@Constructor
142
	 *
143
	 * 		@param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
144
	 * 		@access public
145
	 * 		@return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
146
	 */
147
	public function __construct( $routing = TRUE ) {
148
149
		if ( strpos( $this->_get_dir(), 'caffeinated' ) !== false )
150
			$this->_is_caf = TRUE;
151
152
		$this->_yes_no_values = array(
153
			array('id' => TRUE, 'text' => __('Yes', 'event_espresso')),
154
			array('id' => FALSE, 'text' => __('No', 'event_espresso'))
155
		);
156
157
158
159
		//set the _req_data property.
160
		$this->_req_data = array_merge( $_GET, $_POST );
161
162
163
		//routing enabled?
164
		$this->_routing = $routing;
165
166
		//set initial page props (child method)
167
		$this->_init_page_props();
168
169
		//set global defaults
170
		$this->_set_defaults();
171
172
		//set early because incoming requests could be ajax related and we need to register those hooks.
173
		$this->_global_ajax_hooks();
174
		$this->_ajax_hooks();
175
176
177
		//other_page_hooks have to be early too.
178
		$this->_do_other_page_hooks();
179
180
		//This just allows us to have extending clases do something specific before the parent constructor runs _page_setup.
181
		if ( method_exists( $this, '_before_page_setup' ) )
182
			$this->_before_page_setup();
0 ignored issues
show
Bug introduced by
The method _before_page_setup() does not exist on EE_Admin_Page. Did you maybe mean _page_setup()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
183
184
		//set up page dependencies
185
		$this->_page_setup();
186
187
	}
188
189
190
191
192
	/**
193
	 * _init_page_props
194
	 * Child classes use to set at least the following properties:
195
	 * $page_slug.
196
	 * $page_label.
197
	 *
198
	 * @abstract
199
	 * @access protected
200
	 * @return void
201
	 */
202
	abstract protected function _init_page_props();
203
204
205
206
	/**
207
	 * _ajax_hooks
208
	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
209
	 * Note: within the ajax callback methods.
210
	 *
211
	 * @abstract
212
	 * @access protected
213
	 * @return void
214
	 */
215
	abstract protected function _ajax_hooks();
216
217
218
219
220
	/**
221
	 * _define_page_props
222
	 * child classes define page properties in here.  Must include at least:
223
	 * $_admin_base_url = base_url for all admin pages
224
	 * $_admin_page_title = default admin_page_title for admin pages
225
	 * $_labels = array of default labels for various automatically generated elements:
226
	 * 	array(
227
	 * 		'buttons' => array(
228
	 * 			'add' => __('label for add new button'),
229
	 * 	 		'edit' => __('label for edit button'),
230
	 * 	  		'delete' => __('label for delete button')
231
	 * 	  	 	)
232
	 * 	  	)
233
	 *
234
	 * @abstract
235
	 * @access protected
236
	 * @return void
237
	 */
238
	abstract protected function _define_page_props();
239
240
241
242
243
244
	/**
245
	 * _set_page_routes
246
	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default' route. Here's the format
247
	 * $this->_page_routes = array(
248
	 * 		'default' => array(
249
	 * 			'func' => '_default_method_handling_route',
250
	 * 			'args' => array('array','of','args'),
251
	 * 			'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
252
	 *			'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
253
	 *			'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
254
	 *			'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
255
	 * 		),
256
	 * 		'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
257
	 * 		)
258
	 *
259
	 * )
260
	 *
261
	 *
262
	 * @abstract
263
	 * @access protected
264
	 * @return void
265
	 */
266
	abstract protected function _set_page_routes();
267
268
269
270
271
272
273
	/**
274
	 * _set_page_config
275
	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
276
	 * Format:
277
	 * $this->_page_config = array(
278
	 * 		'default' => array(
279
	 * 			'labels' => array(
280
	 * 				'buttons' => array(
281
	 * 					'add' => __('label for adding item'),
282
	 * 				 	'edit' => __('label for editing item'),
283
	 * 				  	'delete' => __('label for deleting item')
284
	 * 			    ),
285
	 * 			    'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
286
	 * 			), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
287
	 * 			'nav' => array(
288
	 * 				'label' => __('Label for Tab', 'event_espresso').
289
	 *     			'url' => 'http://someurl', //automatically generated UNLESS you define
290
	 *     			'css_class' => 'css-class', //automatically generated UNLESS you define
291
	 *     			'order' => 10, //required to indicate tab position.
292
	 *     			'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
293
	 *     		'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
294
	 *     		'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
295
	 *     		'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use this flag to make sure the necessary js gets enqueued on page load.
296
	 *     		'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
297
	 *     		'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
298
	 *     		'help_tabs' => array( //this is used for adding help tabs to a page
299
	 *     			'tab_id' => array(
300
	 *     				'title' => 'tab_title',
301
	 *     				'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
302
	 *     				'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
303
	 *     				),
304
	 *     			'tab2_id' => array(
305
	 *     			 	'title' => 'tab2 title',
306
	 *     			 	'filename' => 'file_name_2'
307
	 *     			 	'callback' => 'callback_method_for_content',
308
	 *     			 ),
309
	 *     	   	'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
310
	 *     		'help_tour' => array(
311
	 *     			'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
312
	 *     		),
313
	 *     		'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set 'require_nonce' to FALSE
314
	 *     		)
315
	 *
316
	 * )
317
	 *
318
	 *
319
	 * @abstract
320
	 * @access protected
321
	 * @return void
322
	 */
323
	abstract protected function _set_page_config();
324
325
326
327
328
329
	/** end sample help_tour methods **/
330
331
332
	/**
333
	 * _add_screen_options
334
	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
335
	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
336
	 * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
337
	 * see also WP_Screen object documents...
338
	 * @link http://codex.wordpress.org/Class_Reference/WP_Screen
339
	 *
340
	 * @abstract
341
	 * @access protected
342
	 * @return void
343
	 */
344
	abstract protected function _add_screen_options();
345
346
347
348
349
350
351
352
	/**
353
	 * _add_feature_pointers
354
	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
355
	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
356
	 * Note: this is just a placeholder for now.  Implementation will come down the road
357
	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
358
	 * @link http://eamann.com/tech/wordpress-portland/
359
	 *
360
	 * @abstract
361
	 * @access protected
362
	 * @return void
363
	 */
364
	abstract protected function _add_feature_pointers();
365
366
367
368
369
370
	/**
371
	 * load_scripts_styles
372
	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
373
	 *
374
	 * @abstract
375
	 * @access public
376
	 * @return void
377
	 */
378
	abstract public function load_scripts_styles();
379
380
381
382
383
384
385
	/**
386
	 * admin_init
387
	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
	 *
389
	 * @abstract
390
	 * @access public
391
	 * @return void
392
	 */
393
	abstract public function admin_init();
394
395
396
397
398
399
400
	/**
401
	 * admin_notices
402
	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
403
	 *
404
	 * @abstract
405
	 * @access public
406
	 * @return void
407
	 */
408
	abstract public function admin_notices();
409
410
411
412
413
414
	/**
415
	 * admin_footer_scripts
416
	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
417
	 *
418
	 * @access public
419
	 * @return void
420
	 */
421
	abstract public function admin_footer_scripts();
422
423
424
425
426
427
428
	/**
429
	 * admin_footer
430
	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
431
	 *
432
	 * @access  public
433
	 * @return void
434
	 */
435
	public function admin_footer() {}
436
437
438
439
440
	/**
441
	 * _global_ajax_hooks
442
	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
443
	 * Note: within the ajax callback methods.
444
	 *
445
	 * @abstract
446
	 * @access protected
447
	 * @return void
448
	 */
449
	protected function _global_ajax_hooks() {
450
		//for lazy loading of metabox content
451
		add_action( 'wp_ajax_espresso-ajax-content', array( $this, 'ajax_metabox_content'), 10 );
452
	}
453
454
455
456
	public function ajax_metabox_content() {
457
		$contentid = isset( $this->_req_data['contentid'] ) ? $this->_req_data['contentid'] : '';
458
		$url = isset( $this->_req_data['contenturl'] ) ? $this->_req_data['contenturl'] : '';
459
460
		self::cached_rss_display( $contentid, $url );
461
		wp_die();
462
	}
463
464
465
466
	/**
467
	 * _page_setup
468
	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
469
	 *
470
	 * @final
471
	 * @access protected
472
	 * @return void
473
	 */
474
	final protected function _page_setup() {
475
476
		//requires?
477
		EE_Registry::instance()->load_helper('Template');
478
479
480
		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
481
		add_action( 'admin_init', array( $this, 'admin_init_global' ), 5 );
482
483
484
		//next verify if we need to load anything...
485
		$this->_current_page = !empty( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : FALSE;
486
		$this->page_folder = strtolower( str_replace( '_Admin_Page', '', str_replace( 'Extend_', '', get_class($this) ) ) );
487
488
		global $ee_menu_slugs;
489
		$ee_menu_slugs = (array) $ee_menu_slugs;
490
491
		if ( ( !$this->_current_page || ! isset( $ee_menu_slugs[$this->_current_page] ) ) && !defined( 'DOING_AJAX') ) return FALSE;
492
493
494
		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
495
		if ( isset( $this->_req_data['action2'] ) && $this->_req_data['action'] == -1 ) {
496
			$this->_req_data['action'] = ! empty( $this->_req_data['action2'] ) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
497
		}
498
		// then set blank or -1 action values to 'default'
499
		$this->_req_action = isset( $this->_req_data['action'] ) && ! empty( $this->_req_data['action'] ) && $this->_req_data['action'] != -1 ? sanitize_key( $this->_req_data['action'] ) : 'default';
500
501
		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
502
		$this->_req_action = $this->_req_action == 'default' && isset( $this->_req_data['route'] ) ? $this->_req_data['route'] : $this->_req_action;
503
504
		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
505
		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
506
507
		$this->_current_view = $this->_req_action;
508
		$this->_req_nonce = $this->_req_action . '_nonce';
509
		$this->_define_page_props();
510
511
		$this->_current_page_view_url = add_query_arg( array( 'page' => $this->_current_page, 'action' => $this->_current_view ),  $this->_admin_base_url );
512
513
		//default things
514
		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box' );
515
516
		//set page configs
517
		$this->_set_page_routes();
518
		$this->_set_page_config();
519
520
		//let's include any referrer data in our default_query_args for this route for "stickiness".
521
		if ( isset( $this->_req_data['wp_referer'] ) ) {
522
			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
523
		}
524
525
		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
526
		if ( method_exists( $this, '_extend_page_config' ) )
527
			$this->_extend_page_config();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class EE_Admin_Page as the method _extend_page_config() does only exist in the following sub-classes of EE_Admin_Page: Extend_About_Admin_Page, Extend_Events_Admin_Page, Extend_General_Settings_Admin_Page, Extend_Messages_Admin_Page, Extend_Registration_Form_Admin_Page, Extend_Registrations_Admin_Page, Extend_Support_Admin_Page, Extend_Transactions_Admin_Page. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
528
529
		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
530
		if ( method_exists( $this, '_extend_page_config_for_cpt' ) )
531
			$this->_extend_page_config_for_cpt();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class EE_Admin_Page as the method _extend_page_config_for_cpt() does only exist in the following sub-classes of EE_Admin_Page: EE_Admin_Page_CPT, Events_Admin_Page, Extend_Events_Admin_Page, Extend_Registrations_Admin_Page, Registrations_Admin_Page, Venues_Admin_Page. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
532
533
		//filter routes and page_config so addons can add their stuff. Filtering done per class
534
		$this->_page_routes = apply_filters( 'FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this );
535
		$this->_page_config = apply_filters( 'FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this );
536
537
538
		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
539
		if ( method_exists( $this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view ) ) {
540
			add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view ), 10, 2 );
541
		}
542
543
544
		//next route only if routing enabled
545
		if ( $this->_routing && !defined('DOING_AJAX') ) {
546
547
			$this->_verify_routes();
548
549
			//next let's just check user_access and kill if no access
550
			$this->check_user_access();
551
552
			if ( $this->_is_UI_request ) {
553
				//admin_init stuff - global, all views for this page class, specific view
554
				add_action( 'admin_init', array( $this, 'admin_init' ), 10 );
555
				if ( method_exists( $this, 'admin_init_' . $this->_current_view )) {
556
					add_action( 'admin_init', array( $this, 'admin_init_' . $this->_current_view ), 15 );
557
				}
558
559
			} else {
560
				//hijack regular WP loading and route admin request immediately
561
				@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
562
				$this->route_admin_request();
563
			}
564
		}
565
	}
566
567
568
569
570
571
	/**
572
	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
573
	 *
574
	 * @access private
575
	 * @return void
576
	 */
577
	private function _do_other_page_hooks() {
578
		$registered_pages = apply_filters( 'FHEE_do_other_page_hooks_' . $this->page_slug, array() );
579
580
		foreach ( $registered_pages as $page ) {
581
582
			//now let's setup the file name and class that should be present
583
			$classname = str_replace('.class.php', '', $page);
584
585
			//autoloaders should take care of loading file
586 View Code Duplication
			if ( !class_exists( $classname ) ) {
587
				$error_msg[] = sprintf( __('Something went wrong with loading the %s admin hooks page.', 'event_espresso' ), $page);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$error_msg was never initialized. Although not strictly required by PHP, it is generally a good practice to add $error_msg = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
588
				$error_msg[] = $error_msg[0] . "\r\n" . sprintf( __( 'There is no class in place for the %s admin hooks page.%sMake sure you have <strong>%s</strong> defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', 'event_espresso'), $page, '<br />', $classname );
589
				throw new EE_Error( implode( '||', $error_msg ));
590
			}
591
592
			$a = new ReflectionClass($classname);
593
594
			//notice we are passing the instance of this class to the hook object.
595
			$hookobj[] = $a->newInstance($this);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$hookobj was never initialized. Although not strictly required by PHP, it is generally a good practice to add $hookobj = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
596
		}
597
	}
598
599
600
601
	public function load_page_dependencies() {
602
		try {
603
			$this->_load_page_dependencies();
604
		} catch ( EE_Error $e ) {
605
			$e->get_error();
606
		}
607
	}
608
609
610
611
	/**
612
	 * load_page_dependencies
613
	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
614
	 * @access public
615
	 * @return void
616
	 */
617
	protected function _load_page_dependencies() {
618
		//let's set the current_screen and screen options to override what WP set
619
		$this->_current_screen = get_current_screen();
620
621
		//load admin_notices - global, page class, and view specific
622
		add_action( 'admin_notices', array( $this, 'admin_notices_global'), 5 );
623
		add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 );
624
		if ( method_exists( $this, 'admin_notices_' . $this->_current_view ) ) {
625
			add_action( 'admin_notices', array( $this, 'admin_notices_' . $this->_current_view ), 15 );
626
		}
627
628
		//load network admin_notices - global, page class, and view specific
629
		add_action( 'network_admin_notices', array( $this, 'network_admin_notices_global'), 5 );
630
		if ( method_exists( $this, 'network_admin_notices_' . $this->_current_view ) ) {
631
			add_action( 'network_admin_notices', array( $this, 'network_admin_notices_' . $this->_current_view ) );
632
		}
633
634
		//this will save any per_page screen options if they are present
635
		$this->_set_per_page_screen_options();
636
637
		//setup list table properties
638
		$this->_set_list_table();
639
640
		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
641
		$this->_add_registered_meta_boxes();
642
		$this->_add_screen_columns();
643
644
		//add screen options - global, page child class, and view specific
645
		$this->_add_global_screen_options();
0 ignored issues
show
Unused Code introduced by
The call to the method EE_Admin_Page::_add_global_screen_options() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
646
		$this->_add_screen_options();
647
		if ( method_exists( $this, '_add_screen_options_' . $this->_current_view ) )
648
			call_user_func( array( $this, '_add_screen_options_' . $this->_current_view ) );
649
650
651
		//add help tab(s) and tours- set via page_config and qtips.
652
		$this->_add_help_tour();
653
		$this->_add_help_tabs();
654
		$this->_add_qtips();
655
656
		//add feature_pointers - global, page child class, and view specific
657
		$this->_add_feature_pointers();
658
		$this->_add_global_feature_pointers();
0 ignored issues
show
Unused Code introduced by
The call to the method EE_Admin_Page::_add_global_feature_pointers() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
659
		if ( method_exists( $this, '_add_feature_pointer_' . $this->_current_view ) )
660
			call_user_func( array( $this, '_add_feature_pointer_' . $this->_current_view ) );
661
662
		//enqueue scripts/styles - global, page class, and view specific
663
		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5 );
664
		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10 );
665
		if ( method_exists( $this, 'load_scripts_styles_' . $this->_current_view ) )
666
			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view ), 15 );
667
668
		add_action('admin_enqueue_scripts', array( $this, 'admin_footer_scripts_eei18n_js_strings' ), 100 );
669
670
		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
671
		add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts_global' ), 99 );
672
		add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts' ), 100 );
673
		if ( method_exists( $this, 'admin_footer_scripts_' . $this->_current_view ) )
674
			add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts_' . $this->_current_view ), 101 );
675
676
		//admin footer scripts
677
		add_action('admin_footer', array( $this, 'admin_footer_global' ), 99 );
678
		add_action('admin_footer', array( $this, 'admin_footer'), 100 );
679
		if ( method_exists( $this, 'admin_footer_' . $this->_current_view ) )
680
			add_action('admin_footer', array( $this, 'admin_footer_' . $this->_current_view ), 101 );
681
682
683
		do_action( 'FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug );
684
		//targeted hook
685
		do_action( 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action );
686
687
	}
688
689
690
691
692
693
	/**
694
	 * _set_defaults
695
	 * This sets some global defaults for class properties.
696
	 */
697
	private function _set_defaults() {
698
		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = NULL;
0 ignored issues
show
Documentation introduced by
The property _event does not exist on object<EE_Admin_Page>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
699
700
		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config =  $this->_default_route_query_args = array();
0 ignored issues
show
Unused Code introduced by
$this_views is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
701
702
		$this->default_nav_tab_name = 'overview';
0 ignored issues
show
Bug introduced by
The property default_nav_tab_name does not seem to exist. Did you mean _default_nav_tab_name?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
703
704
		//init template args
705
		$this->_template_args = array(
706
			'admin_page_header' => '',
707
			'admin_page_content' => '',
708
			'post_body_content' => '',
709
			'before_list_table' => '',
710
			'after_list_table' => ''
711
		);
712
	}
713
714
715
716
717
	/**
718
	 * route_admin_request
719
	 *
720
	 * @see _route_admin_request()
721
	 * @access public
722
	 * @return void|exception error
723
	 */
724
	public function route_admin_request() {
725
		try {
726
			$this->_route_admin_request();
727
		} catch ( EE_Error $e ) {
728
			$e->get_error();
729
		}
730
	}
731
732
733
734
	public function set_wp_page_slug($wp_page_slug) {
735
		$this->_wp_page_slug = $wp_page_slug;
736
737
		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
738
		if ( is_network_admin() ) {
739
			$this->_wp_page_slug .= '-network';
740
		}
741
	}
742
743
	/**
744
	 * _verify_routes
745
	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
746
	 *
747
	 * @access protected
748
	 * @return void
749
	 */
750
	protected function _verify_routes() {
751
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
752
753
		if ( !$this->_current_page && !defined( 'DOING_AJAX')) return FALSE;
754
755
		$this->_route = FALSE;
756
		$func = FALSE;
0 ignored issues
show
Unused Code introduced by
$func is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
757
		$args = array();
0 ignored issues
show
Unused Code introduced by
$args is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
758
759
		// check that the page_routes array is not empty
760
		if ( empty( $this->_page_routes )) {
761
			// user error msg
762
			$error_msg = sprintf( __('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title );
763
			// developer error msg
764
			$error_msg .=  '||' . $error_msg . __( ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso' );
765
			throw new EE_Error( $error_msg );
766
		}
767
768
		// and that the requested page route exists
769
		if ( array_key_exists( $this->_req_action, $this->_page_routes )) {
770
			$this->_route = $this->_page_routes[ $this->_req_action ];
771
			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
772 View Code Duplication
		} else {
773
			// user error msg
774
			$error_msg =  sprintf( __( 'The requested page route does not exist for the %s admin page.', 'event_espresso' ), $this->_admin_page_title );
775
			// developer error msg
776
			$error_msg .=  '||' . $error_msg . sprintf( __( ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso' ), $this->_req_action );
777
			throw new EE_Error( $error_msg );
778
		}
779
780
		// and that a default route exists
781
		if ( ! array_key_exists( 'default', $this->_page_routes )) {
782
			// user error msg
783
			$error_msg = sprintf( __( 'A default page route has not been set for the % admin page.', 'event_espresso' ), $this->_admin_page_title );
784
			// developer error msg
785
			$error_msg .=  '||' . $error_msg . __( ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso' );
786
			throw new EE_Error( $error_msg );
787
		}
788
789
790
		//first lets' catch if the UI request has EVER been set.
791
		if ( $this->_is_UI_request === NULL ) {
792
			//lets set if this is a UI request or not.
793
			$this->_is_UI_request = ( ! isset( $this->_req_data['noheader'] ) || $this->_req_data['noheader'] !== TRUE ) ? TRUE : FALSE;
794
795
796
			//wait a minute... we might have a noheader in the route array
797
			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader'] ) && $this->_route['noheader'] ? FALSE : $this->_is_UI_request;
798
		}
799
800
		$this->_set_current_labels();
801
802
	}
803
804
805
806
807
	/**
808
	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
809
	 * @param  string $route the route name we're verifying
810
	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
811
	 */
812
	protected function _verify_route( $route ) {
813
		if ( array_key_exists( $this->_req_action, $this->_page_routes )) {
814
			return true;
815 View Code Duplication
		} else {
816
			// user error msg
817
			$error_msg =  sprintf( __( 'The given page route does not exist for the %s admin page.', 'event_espresso' ), $this->_admin_page_title );
818
			// developer error msg
819
			$error_msg .=  '||' . $error_msg . sprintf( __( ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso' ), $route );
820
			throw new EE_Error( $error_msg );
821
		}
822
	}
823
824
825
826
827
	/**
828
	 * perform nonce verification
829
	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
830
	 * @param  string $nonce     The nonce sent
831
	 * @param  string $nonce_ref The nonce reference string (name0)
832
	 * @return mixed (bool|die)
833
	 */
834
	protected function _verify_nonce( $nonce, $nonce_ref ) {
835
		// verify nonce against expected value
836
		if ( ! wp_verify_nonce( $nonce, $nonce_ref) ) {
837
			// these are not the droids you are looking for !!!
838
			$msg = sprintf(__('%sNonce Fail.%s' , 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>' );
839
			if ( WP_DEBUG ) {
840
				$msg .= "\n  " . sprintf( __('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso' ), __CLASS__  );
841
			}
842
			if ( ! defined( 'DOING_AJAX' )) {
843
				wp_die( $msg );
844
			} else {
845
				EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
846
				$this->_return_json();
847
			}
848
		}
849
	}
850
851
852
853
854
	/**
855
	 * _route_admin_request()
856
	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are some doodads to work the magic and handle the flingjangy.
857
	 * Translation:  Checks if the requested action is listed in the page routes and then will try to load the corresponding method.
858
	 *
859
	 * @access protected
860
	 * @return void
861
	 */
862
	protected function _route_admin_request() {
863
		if (  ! $this->_is_UI_request )
864
			$this->_verify_routes();
865
866
		$nonce_check = isset( $this->_route_config['require_nonce'] ) ? $this->_route_config['require_nonce'] : TRUE;
867
868 View Code Duplication
		if ( $this->_req_action != 'default' && $nonce_check ) {
869
			// set nonce from post data
870
			$nonce = isset($this->_req_data[ $this->_req_nonce  ]) ? sanitize_text_field( $this->_req_data[ $this->_req_nonce  ] ) : '';
871
			$this->_verify_nonce( $nonce, $this->_req_nonce );
872
		}
873
		//set the nav_tabs array but ONLY if this is  UI_request
874
		if ( $this->_is_UI_request )
875
			$this->_set_nav_tabs();
876
877
		// grab callback function
878
		$func = is_array( $this->_route ) ? $this->_route['func'] : $this->_route;
879
880
		// check if callback has args
881
		$args = is_array( $this->_route ) && isset( $this->_route['args'] ) ? $this->_route['args'] : array();
882
883
		$error_msg = '';
884
885
		//action right before calling route (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
886
		if ( !did_action('AHEE__EE_Admin_Page__route_admin_request')) {
887
			do_action( 'AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this );
888
		}
889
890
		//right before calling the route, let's remove _wp_http_referer from the $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
891
		$_SERVER['REQUEST_URI'] = remove_query_arg( '_wp_http_referer', wp_unslash( $_SERVER['REQUEST_URI'] ) );
892
893
		if ( ! empty( $func )) {
894
			$base_call = $addon_call = FALSE;
895
			//try to access page route via this class
896
			if ( ! is_array( $func ) && method_exists( $this, $func ) && ( $base_call = call_user_func_array( array( $this, &$func  ), $args ) ) === FALSE ) {
897
				// user error msg
898
				$error_msg =  __( 'An error occurred. The  requested page route could not be found.', 'event_espresso' );
899
				// developer error msg
900
				$error_msg .= '||' . sprintf( __( 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', 'event_espresso' ), $func );
901
			}
902
903
			//for pluggability by addons first let's see if just the function exists (this will also work in the case where $func is an array indicating class/method)
904
			$args['admin_page_object'] = $this; //send along this admin page object for access by addons.
905
906
			if ( $base_call === FALSE && ( $addon_call = call_user_func_array( $func, $args ) )=== FALSE ) {
907
				$error_msg = __('An error occurred. The requested page route could not be found', 'event_espresso' );
908
				$error_msg .= '||' . sprintf( __('Page route "%s" could not be called.  Check that the spelling for the function name and action in the "_page_routes" array filtered by your plugin is correct.', 'event_espresso'), $func );
909
			}
910
911
912
			if ( !empty( $error_msg ) && $base_call === FALSE && $addon_call === FALSE )
913
				throw new EE_Error( $error_msg );
914
		}
915
916
		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
917
		//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.
918
		if ( $this->_is_UI_request === FALSE && is_array( $this->_route) && ! empty( $this->_route['headers_sent_route'] ) ) {
919
			$this->_reset_routing_properties( $this->_route['headers_sent_route'] );
920
		}
921
	}
922
923
924
925
926
	/**
927
	 * This method just allows the resetting of page properties in the case where a no headers
928
	 * route redirects to a headers route in its route config.
929
	 *
930
	 * @since   4.3.0
931
	 *
932
	 * @param  string    $new_route   New (non header) route to redirect to.
933
	 * @return   void
934
	 */
935
	protected function _reset_routing_properties( $new_route ) {
936
		$this->_is_UI_request = TRUE;
937
		//now we set the current route to whatever the headers_sent_route is set at
938
		$this->_req_data['action'] = $new_route;
939
		//rerun page setup
940
		$this->_page_setup();
941
	}
942
943
944
945
946
	/**
947
	 * _add_query_arg
948
	 * adds nonce to array of arguments then calls WP add_query_arg function
949
	 *(internally just uses EEH_URL's function with the same name)
950
	 * 	@access public
951
	 *	@param array $args
952
	 *	@param string $url
953
	 *	@param bool $sticky if true, then the existing Request params will be appended to the generated
954
	 *	                    		url in an associative array indexed by the key 'wp_referer';
955
	 *	                    		Example usage:
956
	 *
957
	 *	                    		If the current page is:
958
	 *	                    		http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
959
	 *	                    		&action=default&event_id=20&month_range=March%202015
960
	 *	                    		&_wpnonce=5467821
961
	 *
962
	 *	                    		and you call:
963
	 *
964
	 *	                    		EE_Admin_Page::add_query_args_and_nonce(
965
	 *	                    			array(
966
	 *	                    				'action' => 'resend_something',
967
	 *	                    				'page=>espresso_registrations'
968
	 *	                    				),
969
	 *	                    			$some_url,
970
	 *	                    			true
971
	 *	                    		 );
972
	 *
973
	 *	                    		It will produce a url in this structure:
974
	 *
975
	 *	                      		http://{$some_url}/?page=espresso_registrations&action=resend_something
976
	 *	                        	&wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
977
	 *	                        	month_range]=March%202015
978
	 * @param   bool    $exclude_nonce  If true, the the nonce will be excluded from the generated nonce.
979
	 * 	@return string
980
	 */
981
	public static function add_query_args_and_nonce( $args = array(), $url = false, $sticky = false, $exclude_nonce = false ) {
982
		EE_Registry::instance()->load_helper('URL');
983
984
		//if there is a _wp_http_referer include the values from the request but only if sticky = true
985
		if ( $sticky ) {
986
			$request = $_REQUEST;
987
			unset( $request['_wp_http_referer'] );
988
			unset( $request['wp_referer'] );
989
			foreach ( $request as $key => $value ) {
990
				//do not add nonces
991
				if ( strpos( $key, 'nonce' ) !== false ) {
992
					continue;
993
				}
994
				$args['wp_referer[' . $key . ']'] = $value;
995
			}
996
		}
997
998
		return EEH_URL::add_query_args_and_nonce( $args, $url, $exclude_nonce );
0 ignored issues
show
Bug introduced by
It seems like $url defined by parameter $url on line 981 can also be of type false; however, EEH_URL::add_query_args_and_nonce() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
999
	}
1000
1001
1002
1003
1004
	/**
1005
	 * This returns a generated link that will load the related help tab.
1006
	 *
1007
	 *
1008
	 * @param  string $help_tab_id the id for the connected help tab
1009
	 * @param  string $icon_style (optional) include css class for the style you want to use for the help icon.
1010
	 * @param  string $help_text (optional) send help text you want to use for the link if default not to be used
1011
	 * @uses EEH_Template::get_help_tab_link()
1012
	 * @return string              generated link
1013
	 */
1014
	protected function _get_help_tab_link( $help_tab_id, $icon_style = FALSE, $help_text = FALSE ) {
1015
		return EEH_Template::get_help_tab_link( $help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text );
1016
	}
1017
1018
1019
1020
1021
	/**
1022
	 * _add_help_tabs
1023
	 *
1024
	 * Note child classes define their help tabs within the page_config array.
1025
	 * @link http://codex.wordpress.org/Function_Reference/add_help_tab
1026
	 *
1027
	 * @access protected
1028
	 * @return void
1029
	 */
1030
	protected function _add_help_tabs() {
1031
		$tour_buttons = '';
1032
		if ( isset( $this->_page_config[$this->_req_action] ) ) {
1033
			$config = $this->_page_config[$this->_req_action];
1034
1035
			//is there a help tour for the current route?  if there is let's setup the tour buttons
1036
			if ( isset( $this->_help_tour[$this->_req_action]) ) {
1037
				$tb = array();
1038
				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1039
				foreach ( $this->_help_tour['tours'] as $tour ) {
1040
					//if this is the end tour then we don't need to setup a button
1041
					if ( $tour instanceof EE_Help_Tour_final_stop )
1042
						continue;
1043
					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1044
				}
1045
				$tour_buttons .= implode('<br />', $tb);
1046
				$tour_buttons .= '</div></div>';
1047
			}
1048
1049
			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1050
			if ( is_array( $config ) && isset( $config['help_sidebar'] ) ) {
1051
				//check that the callback given is valid
1052
				if ( !method_exists($this, $config['help_sidebar'] ) )
1053
					throw new EE_Error( sprintf( __('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', 'event_espresso'), $config['help_sidebar'], get_class($this) ) );
1054
1055
				$content = apply_filters( 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func( array( $this, $config['help_sidebar'] ) ) );
1056
1057
				$content .= $tour_buttons; //add help tour buttons.
1058
1059
				//do we have any help tours setup?  Cause if we do we want to add the buttons
1060
				$this->_current_screen->set_help_sidebar($content);
1061
			}
1062
1063
			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1064
			if ( !isset( $config['help_sidebar'] ) && !empty( $tour_buttons ) ) {
1065
				$this->_current_screen->set_help_sidebar($tour_buttons);
1066
			}
1067
1068
			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1069
			if ( !isset( $config['help_tabs'] ) && !empty($tour_buttons) ) {
1070
				$_ht['id'] = $this->page_slug;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$_ht was never initialized. Although not strictly required by PHP, it is generally a good practice to add $_ht = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1071
				$_ht['title'] = __('Help Tours', 'event_espresso');
1072
				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1073
				$this->_current_screen->add_help_tab($_ht);
1074
				}/**/
1075
1076
1077
			if ( !isset( $config['help_tabs'] ) ) return; //no help tabs for this route
1078
1079
			foreach ( (array) $config['help_tabs'] as $tab_id => $cfg ) {
1080
				//we're here so there ARE help tabs!
1081
1082
				//make sure we've got what we need
1083
				if ( !isset( $cfg['title'] ) )
1084
					throw new EE_Error( __('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso') );
1085
1086
1087
				if ( !isset($cfg['filename']) && !isset( $cfg['callback'] ) && !isset( $cfg['content'] ) )
1088
					throw new EE_Error( __('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', 'event_espresso') );
1089
1090
1091
1092
				//first priority goes to content.
1093
				if ( !empty($cfg['content'] ) ) {
1094
					$content = !empty($cfg['content']) ? $cfg['content'] : NULL;
1095
1096
				//second priority goes to filename
1097
				} else if ( !empty($cfg['filename'] ) ) {
1098
					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1099
1100
1101
					//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)
1102
					$file_path = !is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1103
1104
					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1105 View Code Duplication
					if ( !is_readable($file_path) && !isset($cfg['callback']) ) {
1106
						EE_Error::add_error( sprintf( __('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', 'event_espresso'), $tab_id, key($config), $file_path ), __FILE__, __FUNCTION__, __LINE__ );
1107
						return;
1108
					}
1109
					$template_args['admin_page_obj'] = $this;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template_args = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1110
					$content = EEH_Template::display_template($file_path, $template_args, true);
0 ignored issues
show
Bug introduced by
The variable $template_args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1111
				} else {
1112
					$content = '';
1113
				}
1114
1115
1116
				//check if callback is valid
1117
				if ( empty($content) && ( !isset($cfg['callback']) || !method_exists( $this, $cfg['callback'] ) ) ) {
1118
					EE_Error::add_error( sprintf( __('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.', 'event_espresso'), $cfg['title'] ), __FILE__, __FUNCTION__, __LINE__ );
1119
					return;
1120
				}
1121
1122
				//setup config array for help tab method
1123
				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1124
				$_ht = array(
1125
					'id' => $id,
1126
					'title' => $cfg['title'],
1127
					'callback' => isset( $cfg['callback'] ) && empty($content) ? array( $this, $cfg['callback'] ) : NULL,
1128
					'content' => $content
1129
					);
1130
1131
				$this->_current_screen->add_help_tab( $_ht );
1132
			}
1133
		}
1134
	}
1135
1136
1137
1138
	/**
1139
	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1140
	 *
1141
	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1142
	 * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1143
	 * @access protected
1144
	 * @return void
1145
	 */
1146
	protected function _add_help_tour() {
1147
		$tours = array();
1148
		$this->_help_tour = array();
1149
1150
		//exit early if help tours are turned off globally
1151
		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || ( defined( 'EE_DISABLE_HELP_TOURS' ) && EE_DISABLE_HELP_TOURS ) )
1152
			return;
1153
1154
		//loop through _page_config to find any help_tour defined
1155
		foreach ( $this->_page_config as $route => $config ) {
1156
			//we're only going to set things up for this route
1157
			if ( $route !== $this->_req_action )
1158
				continue;
1159
1160
			if ( isset( $config['help_tour'] ) ) {
1161
1162
				foreach( $config['help_tour'] as $tour ) {
1163
					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1164
					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1165
					$file_path = !is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1166
1167
					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1168
					if ( !is_readable($file_path) ) {
1169
						EE_Error::add_error( sprintf( __('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), $file_path, $tour ), __FILE__, __FUNCTION__, __LINE__ );
1170
						return;
1171
					}
1172
1173
					require_once $file_path;
1174 View Code Duplication
					if ( !class_exists( $tour ) ) {
1175
						$error_msg[] = sprintf( __('Something went wrong with loading the %s Help Tour Class.', 'event_espresso' ), $tour);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$error_msg was never initialized. Although not strictly required by PHP, it is generally a good practice to add $error_msg = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1176
						$error_msg[] = $error_msg[0] . "\r\n" . sprintf( __( 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this) );
1177
						throw new EE_Error( implode( '||', $error_msg ));
1178
					}
1179
					$a = new ReflectionClass($tour);
1180
					$tour_obj = $a->newInstance($this->_is_caf);
1181
1182
					$tours[] = $tour_obj;
1183
					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator( $tour_obj );
1184
				}
1185
1186
				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1187
				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1188
				$tours[] = $end_stop_tour;
1189
				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator( $end_stop_tour );
1190
			}
1191
		}
1192
1193
		if ( !empty( $tours ) )
1194
			$this->_help_tour['tours'] = $tours;
1195
1196
		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1197
	}
1198
1199
1200
1201
1202
	/**
1203
	 * This simply sets up any qtips that have been defined in the page config
1204
	 *
1205
	 * @access protected
1206
	 * @return void
1207
	 */
1208
	protected function _add_qtips() {
1209
		if ( isset( $this->_route_config['qtips'] ) ) {
1210
			$qtips = (array) $this->_route_config['qtips'];
1211
			//load qtip loader
1212
			EE_Registry::instance()->load_helper('Qtip_Loader', array(), TRUE);
1213
			$path = array(
1214
				$this->_get_dir() . '/qtips/',
1215
				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/'
1216
				);
1217
			EEH_Qtip_Loader::instance()->register($qtips, $path);
1218
		}
1219
	}
1220
1221
1222
1223
1224
	/**
1225
	 * _set_nav_tabs
1226
	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1227
	 *
1228
	 * @access protected
1229
	 * @return void
1230
	 */
1231
	protected function _set_nav_tabs() {
1232
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1233
		$i = 0;
1234
		foreach ( $this->_page_config as $slug => $config ) {
1235
			if ( !is_array( $config ) || ( is_array($config) && (isset($config['nav']) && !$config['nav'] ) || !isset($config['nav'] ) ) )
1236
				continue; //no nav tab for this config
1237
1238
			//check for persistent flag
1239
			if ( isset( $config['nav']['persistent']) && !$config['nav']['persistent'] && $slug !== $this->_req_action )
1240
				continue; //nav tab is only to appear when route requested.
1241
1242
			if ( ! $this->check_user_access( $slug, TRUE ) )
1243
				continue; //no nav tab becasue current user does not have access.
1244
1245
			$css_class = isset( $config['css_class'] ) ? $config['css_class'] . ' ' : '';
1246
			$this->_nav_tabs[$slug] = array(
1247
				'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce( array( 'action'=>$slug ), $this->_admin_base_url ),
1248
				'link_text' => isset( $config['nav']['label'] ) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug ) ),
1249
				'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1250
				'order' => isset( $config['nav']['order'] ) ? $config['nav']['order'] : $i
1251
				);
1252
			$i++;
1253
		}
1254
1255
		//if $this->_nav_tabs is empty then lets set the default
1256
		if ( empty( $this->_nav_tabs ) ) {
1257
			$this->_nav_tabs[$this->default_nav_tab_name] = array(
0 ignored issues
show
Bug introduced by
The property default_nav_tab_name does not seem to exist. Did you mean _default_nav_tab_name?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1258
				'url' => $this->admin_base_url,
0 ignored issues
show
Bug introduced by
The property admin_base_url does not seem to exist. Did you mean _admin_base_url?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1259
				'link_text' => ucwords( str_replace( '_', ' ', $this->default_nav_tab_name ) ),
0 ignored issues
show
Bug introduced by
The property default_nav_tab_name does not seem to exist. Did you mean _default_nav_tab_name?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1260
				'css_class' => 'nav-tab-active',
1261
				'order' => 10
1262
				);
1263
		}
1264
1265
		//now let's sort the tabs according to order
1266
		usort( $this->_nav_tabs, array($this, '_sort_nav_tabs' ));
1267
1268
	}
1269
1270
1271
1272
1273
1274
	/**
1275
	 * _set_current_labels
1276
	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1277
	 *
1278
	 * @access private
1279
	 * @return void
1280
	 */
1281
	private function _set_current_labels() {
1282
		if ( is_array($this->_route_config) && isset($this->_route_config['labels']) ) {
1283
			foreach ( $this->_route_config['labels'] as $label => $text ) {
1284
				if ( is_array($text) ) {
1285
					foreach ( $text as $sublabel => $subtext ) {
1286
						$this->_labels[$label][$sublabel] = $subtext;
1287
					}
1288
				} else {
1289
					$this->_labels[$label] = $text;
1290
				}
1291
			}
1292
		}
1293
	}
1294
1295
1296
1297
1298
1299
1300
	/**
1301
	 * 		verifies user access for this admin page
1302
	 * 		@param string $route_to_check if present then the capability for the route matching this string is checked.
1303
	 * 		@param bool   $verify_only Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1304
	*		@return 		BOOL|wp_die()
0 ignored issues
show
Documentation introduced by
The doc-type BOOL|wp_die() could not be parsed: Expected "|" or "end of type", but got "(" at position 11. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1305
	*/
1306
	public function check_user_access( $route_to_check = '', $verify_only = FALSE ) {
1307
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1308
		$route_to_check = empty( $route_to_check ) ? $this->_req_action : $route_to_check;
1309
		$capability = ! empty( $route_to_check ) && isset( $this->_page_routes[$route_to_check] ) && is_array( $this->_page_routes[$route_to_check] ) && ! empty( $this->_page_routes[$route_to_check]['capability'] ) ? $this->_page_routes[$route_to_check]['capability'] : NULL;
1310
1311
		if ( empty( $capability ) && empty( $route_to_check )  ) {
1312
			$capability = is_array( $this->_route ) && empty( $this->_route['capability'] ) ? 'manage_options' : $this->_route['capability'];
1313
		} else {
1314
			$capability = empty( $capability ) ? 'manage_options' : $capability;
1315
		}
1316
1317
		$id = is_array( $this->_route ) && ! empty( $this->_route['obj_id'] ) ? $this->_route['obj_id'] : 0;
1318
1319
		if (( ! function_exists( 'is_admin' ) || ! EE_Registry::instance()->CAP->current_user_can( $capability, $this->page_slug . '_' . $route_to_check, $id ) ) && ! defined( 'DOING_AJAX')) {
1320
			if ( $verify_only ) {
1321
				return FALSE;
1322
			} else {
1323
				wp_die( __('You do not have access to this route.', 'event_espresso' ) );
1324
			}
1325
		}
1326
		return TRUE;
1327
	}
1328
1329
1330
1331
1332
1333
1334
1335
	/**
1336
	 * admin_init_global
1337
	 * This runs all the code that we want executed within the WP admin_init hook.
1338
	 * This method executes for ALL EE Admin pages.
1339
	 *
1340
	 * @access public
1341
	 * @return void
1342
	 */
1343
	public function admin_init_global() {
1344
	}
1345
1346
1347
1348
1349
1350
1351
	/**
1352
	 * wp_loaded_global
1353
	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1354
	 *
1355
	 * @access public
1356
	 * @return void
1357
	 */
1358
	public function wp_loaded() {}
1359
1360
1361
1362
1363
1364
1365
	/**
1366
	 * admin_notices
1367
	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1368
	 *
1369
	 * @access public
1370
	 * @return void
1371
	 */
1372
	public function admin_notices_global() {
1373
		$this->_display_no_javascript_warning();
1374
		$this->_display_espresso_notices();
1375
	}
1376
1377
1378
1379
1380
	public function network_admin_notices_global() {
1381
		$this->_display_no_javascript_warning();
1382
		$this->_display_espresso_notices();
1383
	}
1384
1385
1386
1387
1388
	/**
1389
	 * admin_footer_scripts_global
1390
	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1391
	 *
1392
	 * @access public
1393
	 * @return void
1394
	 */
1395
	public function admin_footer_scripts_global() {
1396
		$this->_add_admin_page_ajax_loading_img();
1397
		$this->_add_admin_page_overlay();
0 ignored issues
show
Unused Code introduced by
The call to the method EE_Admin_Page::_add_admin_page_overlay() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
1398
1399
		//if metaboxes are present we need to add the nonce field
1400
		if ( ( isset($this->_route_config['metaboxes']) || ( isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'] ) || isset($this->_route_config['list_table']) ) ) {
1401
			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1402
			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1403
		}
1404
	}
1405
1406
1407
1408
1409
1410
	/**
1411
	 * admin_footer_global
1412
	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1413
	 *
1414
	 * @access  public
1415
	 * @return  void
1416
	 */
1417
	public function admin_footer_global() {
1418
		//dialog container for dialog helper
1419
		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1420
		$d_cont .= '<div class="ee-notices"></div>';
1421
		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1422
		$d_cont .= '</div>';
1423
		echo $d_cont;
1424
1425
		//help tour stuff?
1426
		if ( isset( $this->_help_tour[$this->_req_action] ) ) {
1427
			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1428
		}
1429
1430
		//current set timezone for timezone js
1431
		EE_Registry::instance()->load_helper('DTT_Helper');
1432
		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1433
	}
1434
1435
1436
	/**
1437
	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1438
	 *
1439
	 * For child classes:
1440
	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for the help popup content on that page.
1441
	 * Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the 'edit_event' route you should have a method named "_help_popup_content_edit_route".
1442
	 * In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format
1443
	 * array(
1444
	 * 	'help_trigger_id' => array(
1445
	 * 		'title' => __('localized title for popup', 'event_espresso'),
1446
	 * 		'content' => __('localized content for popup', 'event_espresso')
1447
	 * 	)
1448
	 * );
1449
	 *
1450
	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1451
	 *
1452
	 *
1453
	 * @access protected
1454
	 * @return string content
1455
	 */
1456
	protected function _set_help_popup_content( $help_array = array(), $display = FALSE ) {
1457
		$content = '';
1458
1459
		$help_array = empty( $help_array ) ? $this->_get_help_content() : $help_array;
1460
		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1461
1462
1463
		//loop through the array and setup content
1464
		foreach ( $help_array as $trigger => $help ) {
1465
			//make sure the array is setup properly
1466
			if ( !isset($help['title']) || !isset($help['content'] ) ) {
1467
				throw new EE_Error( __('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', 'event_espresso') );
1468
			}
1469
1470
			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1471
			$template_args = array(
1472
				'help_popup_id' => $trigger,
1473
				'help_popup_title' => $help['title'],
1474
				'help_popup_content' => $help['content']
1475
				);
1476
1477
			$content .= EEH_Template::display_template( $template_path, $template_args, TRUE );
1478
		}
1479
1480
		if ( $display )
1481
			echo $content;
1482
		else
1483
			return $content;
1484
	}
1485
1486
1487
1488
1489
	/**
1490
	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1491
	 *
1492
	 * @access private
1493
	 * @return array properly formatted array for help popup content
1494
	 */
1495
	private function _get_help_content() {
1496
		//what is the method we're looking for?
1497
		$method_name = '_help_popup_content_' . $this->_req_action;
1498
1499
		//if method doesn't exist let's get out.
1500
		if ( !method_exists( $this, $method_name ) )
1501
			return array();
1502
1503
		//k we're good to go let's retrieve the help array
1504
		$help_array = call_user_func( array( $this, $method_name ) );
1505
1506
		//make sure we've got an array!
1507
		if ( !is_array($help_array) ) {
1508
			throw new EE_Error( __('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso' ) );
1509
		}
1510
1511
		return $help_array;
1512
	}
1513
1514
1515
1516
	/**
1517
	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1518
	 *
1519
	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1520
	 *
1521
	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1522
	 *
1523
	 *
1524
	 * @access protected
1525
	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1526
	 * @param boolean $display    if false then we return the trigger string
1527
	 * @param array $dimensions an array of dimensions for the box (array(h,w))
1528
	 * @return string
1529
	 */
1530
	protected function _set_help_trigger( $trigger_id, $display = TRUE, $dimensions = array( '400', '640') ) {
1531
1532
		if ( defined('DOING_AJAX') ) return;
1533
1534
		//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
1535
		$help_array = $this->_get_help_content();
1536
		$help_content = '';
1537
1538
		if ( empty( $help_array ) || !isset( $help_array[$trigger_id] ) ) {
1539
			$help_array[$trigger_id] = array(
1540
				'title' => __('Missing Content', 'event_espresso'),
1541
				'content' => __('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.)', 'event_espresso')
1542
				);
1543
			$help_content = $this->_set_help_popup_content( $help_array, FALSE );
1544
		}
1545
1546
		//let's setup the trigger
1547
		$content = '<a class="ee-dialog" href="?height='. $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1548
		$content = $content . $help_content;
1549
1550
		if ( $display )
1551
			echo $content;
1552
		else
1553
			return $content;
1554
	}
1555
1556
1557
	/**
1558
	 * _add_global_screen_options
1559
	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1560
	 * This particular method will add_screen_options on ALL EE_Admin Pages
1561
	 * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1562
	 * see also WP_Screen object documents...
1563
	 * @link http://codex.wordpress.org/Class_Reference/WP_Screen
1564
	 *
1565
	 * @abstract
1566
	 * @access private
1567
	 * @return void
1568
	 */
1569
	private function _add_global_screen_options() {}
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
	/**
1580
	 * _add_global_feature_pointers
1581
	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1582
	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1583
	 * Note: this is just a placeholder for now.  Implementation will come down the road
1584
	 * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1585
	 * @link http://eamann.com/tech/wordpress-portland/
1586
	 *
1587
	 * @abstract
1588
	 * @access protected
1589
	 * @return void
1590
	 */
1591
	private function _add_global_feature_pointers() {}
1592
1593
1594
1595
1596
1597
1598
	/**
1599
	 * load_global_scripts_styles
1600
	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1601
	 *
1602
	 * @return void
1603
	 */
1604
	public function load_global_scripts_styles() {
1605
		/** STYLES **/
1606
		// add debugging styles
1607
		if ( WP_DEBUG ) {
1608
			add_action('admin_head', array( $this, 'add_xdebug_style' ));
1609
		}
1610
1611
		//register all styles
1612
		wp_register_style( 'espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(),EVENT_ESPRESSO_VERSION );
1613
1614
		wp_register_style('jquery-jq-plot-css', JQPLOT_URL . 'jquery.jqplot.min.css', array('jquery'), EVENT_ESPRESSO_VERSION );
1615
		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1616
		//helpers styles
1617
		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION );
1618
		//enqueue global styles
1619
		wp_enqueue_style('ee-admin-css');
1620
1621
1622
		/** SCRIPTS **/
1623
1624
		//register all scripts
1625
		wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1626
		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, TRUE );
1627
		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array( 'espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true );
1628
1629
		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true );
1630
		// register jQuery Validate - see /includes/functions/wp_hooks.php
1631
		add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1632
		add_filter('FHEE_load_joyride', '__return_true');
1633
1634
		//script for sorting tables
1635
		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE);
1636
		//script for parsing uri's
1637
		wp_register_script( 'ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, TRUE );
1638
		//and parsing associative serialized form elements
1639
		wp_register_script( 'ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1640
		//helpers scripts
1641
		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1642
		wp_register_script( 'ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, TRUE );
1643
		wp_register_script( 'ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, TRUE );
1644
		wp_register_script( 'ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon','ee-moment'), EVENT_ESPRESSO_VERSION, TRUE );
1645
1646
		//excanvas
1647
		wp_register_script('excanvas', JQPLOT_URL . 'excanvas.min.js', array(), EVENT_ESPRESSO_VERSION, FALSE );
1648
1649
		//jqplot library
1650
		wp_register_script('jqplot', JQPLOT_URL . 'jquery.jqplot.min.js', array('jquery'), '', FALSE);
1651
		wp_register_script('jqplot-barRenderer', JQPLOT_URL . 'plugins/jqplot.barRenderer.min.js', array('jqplot'), '', FALSE);
1652
		wp_register_script('jqplot-canvasTextRenderer', JQPLOT_URL . 'plugins/jqplot.canvasTextRenderer.min.js', array('jqplot'), '', FALSE);
1653
		wp_register_script('jqplot-canvasAxisTickRenderer', JQPLOT_URL . 'plugins/jqplot.canvasAxisTickRenderer.min.js', array('jqplot'), '', FALSE);
1654
		wp_register_script('jqplot-categoryAxisRenderer', JQPLOT_URL . 'plugins/jqplot.categoryAxisRenderer.min.js', array('jqplot'), '', FALSE);
1655
		wp_register_script('jqplot-dateAxisRenderer', JQPLOT_URL . 'plugins/jqplot.dateAxisRenderer.min.js', array('jqplot'), '', FALSE);
1656
		wp_register_script('jqplot-highlighter', JQPLOT_URL . 'plugins/jqplot.highlighter.min.js', array('jqplot'), '', FALSE);
1657
		wp_register_script('jqplot-pointLabels', JQPLOT_URL . 'plugins/jqplot.pointLabels.min.js', array('jqplot'), '', FALSE);
1658
		wp_register_script('jqplot-all', EE_ADMIN_URL . 'assets/ee-admin-jqlot-all.js', array('jqplot-pointLabels', 'jqplot-highlighter', 'jqplot-dateAxisRenderer', 'jqplot-categoryAxisRenderer', 'jqplot-canvasAxisTickRenderer', 'jqplot-canvasTextRenderer', 'jqplot-barRenderer'), EVENT_ESPRESSO_VERSION, FALSE );
1659
1660
1661
		//enqueue global scripts
1662
1663
		//taking care of metaboxes
1664
		if ( ( isset($this->_route_config['metaboxes'] ) || isset($this->_route_config['has_metaboxes']) ) && empty( $this->_cpt_route) ) {
0 ignored issues
show
Bug introduced by
The property _cpt_route does not seem to exist. Did you mean _route?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1665
			wp_enqueue_script('dashboard');
1666
		}
1667
1668
		//enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1669
		if ( ! isset( $this->_route_config['has_help_popups']) || ( isset( $this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'] ) ) {
1670
			wp_enqueue_script('ee_admin_js');
1671
			wp_enqueue_style('ee-admin-css');
1672
		}
1673
1674
1675
		//localize script for ajax lazy loading
1676
		$lazy_loader_container_ids = apply_filters( 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content') );
1677
		wp_localize_script( 'ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1678
1679
1680
		/**
1681
		 * help tour stuff
1682
		 */
1683
		if ( !empty( $this->_help_tour ) ) {
1684
1685
			//register the js for kicking things off
1686
			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, TRUE );
1687
1688
			//setup tours for the js tour object
1689
			foreach ( $this->_help_tour['tours'] as $tour ) {
1690
				$tours[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tours was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tours = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1691
					'id' => $tour->get_slug(),
1692
					'options' => $tour->get_options()
1693
					);
1694
			}
1695
1696
			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours ) );
0 ignored issues
show
Bug introduced by
The variable $tours does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1697
1698
			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1699
		}
1700
	}
1701
1702
1703
1704
1705
	/**
1706
	*		admin_footer_scripts_eei18n_js_strings
1707
	*
1708
	*		@access 		public
1709
	*		@return 		void
1710
	*/
1711
	public function admin_footer_scripts_eei18n_js_strings() {
1712
1713
		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1714
		EE_Registry::$i18n_js_strings['confirm_delete'] = __( '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!!!', 'event_espresso' );
1715
1716
		EE_Registry::$i18n_js_strings['January'] = __( 'January', 'event_espresso' );
1717
		EE_Registry::$i18n_js_strings['February'] = __( 'February', 'event_espresso' );
1718
		EE_Registry::$i18n_js_strings['March'] = __( 'March', 'event_espresso' );
1719
		EE_Registry::$i18n_js_strings['April'] = __( 'April', 'event_espresso' );
1720
		EE_Registry::$i18n_js_strings['May'] = __( 'May', 'event_espresso' );
1721
		EE_Registry::$i18n_js_strings['June'] = __( 'June', 'event_espresso' );
1722
		EE_Registry::$i18n_js_strings['July'] = __( 'July', 'event_espresso' );
1723
		EE_Registry::$i18n_js_strings['August'] = __( 'August', 'event_espresso' );
1724
		EE_Registry::$i18n_js_strings['September'] = __( 'September', 'event_espresso' );
1725
		EE_Registry::$i18n_js_strings['October'] = __( 'October', 'event_espresso' );
1726
		EE_Registry::$i18n_js_strings['November'] = __( 'November', 'event_espresso' );
1727
		EE_Registry::$i18n_js_strings['December'] = __( 'December', 'event_espresso' );
1728
		EE_Registry::$i18n_js_strings['Jan'] = __( 'Jan', 'event_espresso' );
1729
		EE_Registry::$i18n_js_strings['Feb'] = __( 'Feb', 'event_espresso' );
1730
		EE_Registry::$i18n_js_strings['Mar'] = __( 'Mar', 'event_espresso' );
1731
		EE_Registry::$i18n_js_strings['Apr'] = __( 'Apr', 'event_espresso' );
1732
		EE_Registry::$i18n_js_strings['May'] = __( 'May', 'event_espresso' );
1733
		EE_Registry::$i18n_js_strings['Jun'] = __( 'Jun', 'event_espresso' );
1734
		EE_Registry::$i18n_js_strings['Jul'] = __( 'Jul', 'event_espresso' );
1735
		EE_Registry::$i18n_js_strings['Aug'] = __( 'Aug', 'event_espresso' );
1736
		EE_Registry::$i18n_js_strings['Sep'] = __( 'Sep', 'event_espresso' );
1737
		EE_Registry::$i18n_js_strings['Oct'] = __( 'Oct', 'event_espresso' );
1738
		EE_Registry::$i18n_js_strings['Nov'] = __( 'Nov', 'event_espresso' );
1739
		EE_Registry::$i18n_js_strings['Dec'] = __( 'Dec', 'event_espresso' );
1740
1741
		EE_Registry::$i18n_js_strings['Sunday'] = __( 'Sunday', 'event_espresso' );
1742
		EE_Registry::$i18n_js_strings['Monday'] = __( 'Monday', 'event_espresso' );
1743
		EE_Registry::$i18n_js_strings['Tuesday'] = __( 'Tuesday', 'event_espresso' );
1744
		EE_Registry::$i18n_js_strings['Wednesday'] = __( 'Wednesday', 'event_espresso' );
1745
		EE_Registry::$i18n_js_strings['Thursday'] = __( 'Thursday', 'event_espresso' );
1746
		EE_Registry::$i18n_js_strings['Friday'] = __( 'Friday', 'event_espresso' );
1747
		EE_Registry::$i18n_js_strings['Saturday'] = __( 'Saturday', 'event_espresso' );
1748
		EE_Registry::$i18n_js_strings['Sun'] = __( 'Sun', 'event_espresso' );
1749
		EE_Registry::$i18n_js_strings['Mon'] = __( 'Mon', 'event_espresso' );
1750
		EE_Registry::$i18n_js_strings['Tue'] = __( 'Tue', 'event_espresso' );
1751
		EE_Registry::$i18n_js_strings['Wed'] = __( 'Wed', 'event_espresso' );
1752
		EE_Registry::$i18n_js_strings['Thu'] = __( 'Thu', 'event_espresso' );
1753
		EE_Registry::$i18n_js_strings['Fri'] = __( 'Fri', 'event_espresso' );
1754
		EE_Registry::$i18n_js_strings['Sat'] = __( 'Sat', 'event_espresso' );
1755
1756
		//setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1757
		//admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1758
		//espresso_core is listed as a dependency of ee_admin_js.
1759
		wp_localize_script( 'espresso_core', 'eei18n', EE_Registry::$i18n_js_strings );
1760
1761
	}
1762
1763
1764
1765
	/**
1766
	*		load enhanced xdebug styles for ppl with failing eyesight
1767
	*
1768
	*		@access 		public
1769
	*		@return 		void
1770
	*/
1771
	public function add_xdebug_style() {
1772
		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1773
	}
1774
1775
1776
	/************************/
1777
	/** LIST TABLE METHODS **/
1778
	/************************/
1779
1780
1781
1782
1783
1784
	/**
1785
	 * this sets up the list table if the current view requires it.
1786
	 *
1787
	 * @access protected
1788
	 * @return void
1789
	 */
1790
	protected function _set_list_table() {
1791
1792
		//first is this a list_table view?
1793
		if ( !isset($this->_route_config['list_table']) )
1794
			return; //not a list_table view so get out.
1795
1796
		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1797
1798
		if ( call_user_func( array( $this, '_set_list_table_views_' . $this->_req_action ) ) === FALSE ) {
1799
			//user error msg
1800
			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso' );
1801
			//developer error msg
1802
			$error_msg .= '||' . sprintf( __('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.', 'event_espresso' ), $this->_req_action, '_set_list_table_views_' . $this->_req_action );
1803
			throw new EE_Error( $error_msg );
1804
		}
1805
1806
		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1807
		$this->_views = apply_filters( 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views );
1808
		$this->_views = apply_filters( 'FHEE_list_table_views_' . $this->page_slug, $this->_views );
1809
		$this->_views = apply_filters( 'FHEE_list_table_views', $this->_views );
1810
1811
		$this->_set_list_table_view();
1812
		$this->_set_list_table_object();
1813
1814
	}
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
	/**
1826
	 * 		set current view for List Table
1827
	*		@access public
1828
	*		@return array
1829
	*/
1830
	protected function _set_list_table_view() {
1831
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1832
1833
1834
		// looking at active items or dumpster diving ?
1835
		if ( ! isset( $this->_req_data['status'] ) || ! array_key_exists( $this->_req_data['status'], $this->_views )) {
1836
			$this->_view = isset( $this->_views['in_use'] ) ? 'in_use' : 'all';
1837
		} else {
1838
			$this->_view = sanitize_key( $this->_req_data['status'] );
1839
		}
1840
	}
1841
1842
1843
1844
	/**
1845
	 * _set_list_table_object
1846
	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1847
	 */
1848
	protected function _set_list_table_object() {
1849
		if ( isset($this->_route_config['list_table'] ) ) {
1850 View Code Duplication
			if ( !class_exists( $this->_route_config['list_table'] ) )
1851
				throw new EE_Error( sprintf( __('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.', 'event_espresso'), $this->_route_config['list_table'], get_class($this) ) );
1852
			$a = new ReflectionClass($this->_route_config['list_table']);
1853
			$this->_list_table_object = $a->newInstance($this);
1854
		}
1855
	}
1856
1857
1858
1859
1860
1861
	/**
1862
	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1863
	 *
1864
	 * @param array $extra_query_args Optional. An array of extra query args to add to the generated
1865
	 *                                		          	urls.  The array should be indexed by the view it is being
1866
	 *                                		          	added to.
1867
	 *
1868
	 * @return array
1869
	 */
1870
	public function get_list_table_view_RLs( $extra_query_args = array() ) {
1871
1872
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1873
1874
		if ( empty( $this->_views )) {
1875
			$this->_views = array();
1876
		}
1877
1878
		// cycle thru views
1879
		foreach ( $this->_views as $key => $view ) {
1880
			$query_args = array();
1881
			// check for current view
1882
			$this->_views[ $key ]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1883
			$query_args['action'] = $this->_req_action;
1884
			$query_args[$this->_req_action.'_nonce'] = wp_create_nonce( $query_args['action'] . '_nonce' );
1885
			$query_args['status'] = $view['slug'];
1886
			//merge any other arguments sent in.
1887
			if ( isset( $extra_query_args[$view['slug']] ) ) {
1888
				$query_args = array_merge( $query_args, $extra_query_args[$view['slug']] );
1889
			}
1890
			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce( $query_args, $this->_admin_base_url );
1891
		}
1892
1893
		return $this->_views;
1894
	}
1895
1896
1897
1898
1899
	/**
1900
	 * _entries_per_page_dropdown
1901
	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1902
	 * @todo: Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1903
	 * @access protected
1904
	 * @param int $max_entries total number of rows in the table
1905
	 * @return string
1906
	*/
1907
	protected function _entries_per_page_dropdown( $max_entries = FALSE ) {
1908
1909
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1910
		$values = array( 10, 25, 50, 100 );
1911
		$per_page = ( ! empty( $this->_req_data['per_page'] )) ? absint( $this->_req_data['per_page'] ) : 10;
1912
1913
		if ( $max_entries ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $max_entries of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1914
			$values[] = $max_entries;
1915
			sort( $values );
1916
		}
1917
1918
		$entries_per_page_dropdown = '
1919
			<div id="entries-per-page-dv" class="alignleft actions">
1920
				<label class="hide-if-no-js">
1921
					Show
1922
					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1923
1924
		foreach ( $values as $value ) {
1925
			if ( $value < $max_entries ) {
1926
				$selected = $value == $per_page ?  ' selected="' . $per_page . '"' : '';
1927
				$entries_per_page_dropdown .= '
1928
						<option value="'.$value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1929
			}
1930
		}
1931
1932
		$selected = $max_entries == $per_page ?  ' selected="' . $per_page . '"' : '';
1933
		$entries_per_page_dropdown .= '
1934
						<option value="'.$max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1935
1936
		$entries_per_page_dropdown .= '
1937
					</select>
1938
					entries
1939
				</label>
1940
				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1941
			</div>
1942
		';
1943
		return $entries_per_page_dropdown;
1944
	}
1945
1946
1947
1948
1949
	/**
1950
	 * 		_set_search_attributes
1951
	*		@access 		protected
1952
	*		@return 		void
1953
	*/
1954
	public function _set_search_attributes() {
1955
		$this->_template_args['search']['btn_label'] = sprintf( __( 'Search %s', 'event_espresso' ), empty( $this->_search_btn_label ) ? $this->page_label : $this->_search_btn_label );
1956
		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1957
	}
1958
1959
	/*** END LIST TABLE METHODS **/
1960
	/*****************************/
1961
1962
1963
1964
1965
1966
	/**
1967
	 * 		_add_registered_metaboxes
1968
	 * 		this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1969
	 *
1970
	 * @link http://codex.wordpress.org/Function_Reference/add_meta_box
1971
	 * @access private
1972
	 * @return void
1973
	*/
1974
	private function _add_registered_meta_boxes() {
1975
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1976
1977
		//we only add meta boxes if the page_route calls for it
1978
		if ( is_array($this->_route_config) && isset( $this->_route_config['metaboxes'] ) && is_array($this->_route_config['metaboxes']) ) {
1979
1980
1981
			//this simply loops through the callbacks provided and checks if there is a corresponding callback registered by the child - if there is then we go ahead and process the metabox loader.
1982
			foreach ( $this->_route_config['metaboxes'] as $metabox_callback ) {
1983
				if ( call_user_func( array($this, &$metabox_callback) ) === FALSE ) {
1984
					// user error msg
1985
				$error_msg =  __( 'An error occurred. The  requested metabox could not be found.', 'event_espresso' );
1986
				// developer error msg
1987
				$error_msg .= '||' . sprintf( __( '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.', 'event_espresso' ), $metabox_callback );
1988
				throw new EE_Error( $error_msg );
1989
				}
1990
			}
1991
		}
1992
	}
1993
1994
1995
1996
1997
	/**
1998
	 * _add_screen_columns
1999
	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
2000
	 *
2001
	 * @access private
2002
	 * @return void
2003
	 */
2004
	private function _add_screen_columns() {
2005
		if ( is_array($this->_route_config) && isset( $this->_route_config['columns'] ) && is_array($this->_route_config['columns']) && count( $this->_route_config['columns'] == 2 ) ) {
2006
2007
			add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1] ) );
2008
			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2009
			$screen_id = $this->_current_screen->id;
2010
			$screen_columns = (int) get_user_option("screen_layout_$screen_id");
2011
			$total_columns = !empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
2012
			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2013
			$this->_template_args['current_page'] = $this->_wp_page_slug;
2014
			$this->_template_args['screen'] = $this->_current_screen;
2015
			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
2016
2017
			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2018
			$this->_route_config['has_metaboxes'] = TRUE;
2019
		}
2020
	}
2021
2022
2023
2024
	/**********************************/
2025
	/** GLOBALLY AVAILABLE METABOXES **/
2026
2027
	/**
2028
	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get loaded on.
2029
	 */
2030
2031
	private function _espresso_news_post_box() {
2032
		$news_box_title = apply_filters( 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __( 'New @ Event Espresso', 'event_espresso' ) );
2033
		add_meta_box( 'espresso_news_post_box', $news_box_title, array(
2034
			$this,
2035
			'espresso_news_post_box'
2036
		), $this->_wp_page_slug, 'side' );
2037
	}
2038
2039
2040
	/**
2041
	 * Code for setting up espresso ratings request metabox.
2042
	 */
2043
	protected function _espresso_ratings_request() {
2044
		if ( ! apply_filters( 'FHEE_show_ratings_request_meta_box', true ) ) {
2045
			return '';
2046
		}
2047
		$ratings_box_title = apply_filters( 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso') );
2048
		add_meta_box( 'espresso_ratings_request', $ratings_box_title, array(
2049
			$this,
2050
			'espresso_ratings_request'
2051
		), $this->_wp_page_slug, 'side' );
2052
	}
2053
2054
2055
	/**
2056
	 * Code for setting up espresso ratings request metabox content.
2057
	 */
2058
	public function espresso_ratings_request() {
2059
		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
2060
		EE_Registry::instance()->load_helper( 'Template' );
2061
		EEH_Template::display_template( $template_path, array() );
2062
	}
2063
2064
2065
2066
2067
	public static function cached_rss_display( $rss_id, $url ) {
2068
		$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
2069
		$doing_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX );
2070
		$pre = '<div class="espresso-rss-display">' . "\n\t";
2071
		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2072
		$post = '</div>' . "\n";
2073
2074
		$cache_key = 'ee_rss_' . md5( $rss_id );
2075
		if ( FALSE != ( $output = get_transient( $cache_key ) ) ) {
2076
			echo $pre . $output . $post;
2077
			return TRUE;
2078
		}
2079
2080
		if ( ! $doing_ajax ) {
2081
			echo $pre . $loading . $post;
2082
			return FALSE;
2083
		}
2084
2085
		ob_start();
2086
		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5) );
2087
		set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
2088
		return TRUE;
2089
2090
	}
2091
2092
2093
	public function espresso_news_post_box() {
2094
		?>
2095
	  <div class="padding">
2096
	  	<div id="espresso_news_post_box_content" class="infolinks">
2097
	  		<?php
2098
	  		// Get RSS Feed(s)
2099
	  		$feed_url = apply_filters( 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/' );
2100
	  		$url = urlencode($feed_url);
2101
	  		self::cached_rss_display( 'espresso_news_post_box_content', $url );
2102
2103
	  		?>
2104
	  	</div>
2105
	  	<?php do_action( 'AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2106
	  </div>
2107
		<?php
2108
	}
2109
2110
2111
	private function _espresso_links_post_box() {
2112
		//Hiding until we actually have content to put in here...
2113
		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2114
	}
2115
2116
	public function espresso_links_post_box() {
2117
		   //Hiding until we actually have content to put in here...
2118
		   //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2119
			//EEH_Template::display_template( $templatepath );
2120
		}
2121
2122
2123
2124
	protected function _espresso_sponsors_post_box() {
2125
2126
		$show_sponsors = apply_filters( 'FHEE_show_sponsors_meta_box', TRUE );
2127
		if ( $show_sponsors )
2128
			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array( $this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2129
	}
2130
2131
2132
	public function espresso_sponsors_post_box() {
2133
		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2134
		EEH_Template::display_template( $templatepath );
2135
	}
2136
2137
2138
2139
	private function _publish_post_box() {
2140
		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2141
2142
		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2143
		if ( !empty( $this->_labels['publishbox'] ) ) {
2144
			$box_label = is_array( $this->_labels['publishbox'] ) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2145
		} else {
2146
			$box_label = __('Publish', 'event_espresso');
2147
		}
2148
2149
		$box_label = apply_filters( 'FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this );
2150
2151
		add_meta_box( $meta_box_ref, $box_label, array( $this, 'editor_overview' ), $this->_current_screen->id, 'side', 'high' );
2152
2153
	}
2154
2155
2156
2157
	public function editor_overview() {
2158
		//if we have extra content set let's add it in if not make sure its empty
2159
		$this->_template_args['publish_box_extra_content'] = isset( $this->_template_args['publish_box_extra_content'] ) ? $this->_template_args['publish_box_extra_content'] : '';
2160
		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2161
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2162
	}
2163
2164
2165
	/** end of globally available metaboxes section **/
2166
	/*************************************************/
2167
2168
2169
2170
	/**
2171
	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2172
	 * protected method.
2173
	 *
2174
	 * @see $this->_set_publish_post_box_vars for param details
2175
	 * @since 4.6.0
2176
	 */
2177
	public function set_publish_post_box_vars( $name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true ) {
2178
		$this->_set_publish_post_box_vars( $name, $id, $delete, $save_close_redirect_URL, $both_btns );
0 ignored issues
show
Documentation introduced by
$id is of type boolean, but the function expects a false|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$delete is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2179
	}
2180
2181
2182
	/**
2183
	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2184
	 *
2185
	 * Note: currently there is no validation for this.  However if you want the delete button, the
2186
	 * save, and save and close buttons to work properly, then you will want to include a
2187
	 * values for the name and id arguments.
2188
	 *
2189
	 * @todo  Add in validation for name/id arguments.
2190
	 *
2191
	 * @param	string	$name		key used for the action ID (i.e. event_id)
2192
	 * @param	int		$id	id attached to the item published
2193
	 * @param	string	$delete	page route callback for the delete action
2194
	 * @param	string	$post_save_redirect_URL	custom URL to redirect to after Save & Close has been completed
0 ignored issues
show
Bug introduced by
There is no parameter named $post_save_redirect_URL. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2195
	 * @param	boolean	$both_btns	whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2196
	 */
2197
	protected function _set_publish_post_box_vars( $name = NULL, $id = FALSE, $delete = FALSE, $save_close_redirect_URL = NULL, $both_btns = TRUE ) {
2198
2199
		// if Save & Close, use a custom redirect URL or default to the main page?
2200
		$save_close_redirect_URL = ! empty( $save_close_redirect_URL ) ? $save_close_redirect_URL : $this->_admin_base_url;
2201
		// create the Save & Close and Save buttons
2202
		$this->_set_save_buttons( $both_btns, array(), array(), $save_close_redirect_URL );
2203
		//if we have extra content set let's add it in if not make sure its empty
2204
		$this->_template_args['publish_box_extra_content'] = isset( $this->_template_args['publish_box_extra_content'] ) ? $this->_template_args['publish_box_extra_content'] : '';
2205
2206
2207
		if ( $delete && ! empty( $id )  ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $delete of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2208
			$delete = is_bool($delete) ? 'delete' : $delete; //make sure we have a default if just true is sent.
2209
			$delete_link_args = array( $name => $id );
2210
			$delete = $this->get_action_link_or_button( $delete, $delete, $delete_link_args, 'submitdelete deletion');
2211
		}
2212
2213
		$this->_template_args['publish_delete_link'] = !empty( $id ) ? $delete : '';
2214
		if ( ! empty( $name ) && ! empty( $id ) ) {
2215
			$hidden_field_arr[$name] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$hidden_field_arr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $hidden_field_arr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2216
				'type' => 'hidden',
2217
				'value' => $id
2218
				);
2219
			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2220
		} else {
2221
			$hf = '';
2222
		}
2223
		// add hidden field
2224
		$this->_template_args['publish_hidden_fields'] = ! empty( $hf ) ? $hf[$name]['field'] : $hf;
2225
2226
	}
2227
2228
2229
2230
2231
	/**
2232
	 * 		displays an error message to ppl who have javascript disabled
2233
	*		@access 		private
2234
	*		@return 		string
2235
	*/
2236
	private function _display_no_javascript_warning() {
2237
		?>
2238
		<noscript>
2239
			<div id="no-js-message" class="error">
2240
				<p style="font-size:1.3em;">
2241
					<span style="color:red;"><?php _e( 'Warning!', 'event_espresso' ); ?></span>
2242
					<?php _e( '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.', 'event_espresso' ); ?>
2243
				</p>
2244
			</div>
2245
		</noscript>
2246
		<?php
2247
	}
2248
2249
2250
2251
2252
2253
2254
2255
2256
	/**
2257
	 * 		displays espresso success and/or error notices
2258
	*		@access 		private
2259
	*		@return 		string
2260
	*/
2261
	private function _display_espresso_notices() {
2262
		$notices = $this->_get_transient( TRUE );
2263
		echo stripslashes($notices);
2264
	}
2265
2266
2267
2268
2269
2270
2271
	/**
2272
	*		spinny things pacify the masses
2273
	*		@access private
2274
	*		@return string
2275
	*/
2276
	protected function _add_admin_page_ajax_loading_img() {
2277
		?>
2278
			<div id="espresso-ajax-loading" class="ajax-loading-grey">
2279
				<span class="ee-spinner ee-spin"></span><span class="hidden"><?php _e('loading...', 'event_espresso'); ?></span>
2280
			</div>
2281
		<?php
2282
	}
2283
2284
2285
2286
2287
2288
	/**
2289
	*		add admin page overlay for modal boxes
2290
	*		@access private
2291
	*		@return string
2292
	*/
2293
	protected function _add_admin_page_overlay() {
2294
		?>
2295
		<div id="espresso-admin-page-overlay-dv" class=""></div>
2296
		<?php
2297
	}
2298
2299
2300
2301
2302
2303
2304
	/**
2305
	 * facade for add_meta_box
2306
	 * @param string  $action        where the metabox get's displayed
2307
	 * @param string  $title         Title of Metabox (output in metabox header)
2308
	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2309
	 * @param array  $callback_args an array of args supplied for the metabox
2310
	 * @param string  $column        what metabox column
2311
	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2312
	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2313
	 */
2314
	public function _add_admin_page_meta_box( $action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true ) {
2315
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, $callback );
2316
2317
		//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.
2318
		if ( empty( $callback_args ) && $create_func ) {
2319
			$callback_args = array(
2320
				'template_path' => $this->_template_path,
2321
				'template_args' => $this->_template_args,
2322
				);
2323
		}
2324
2325
		//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)
2326
		$call_back_func = $create_func ? create_function('$post, $metabox', 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
2327
2328
		add_meta_box( str_replace( '_', '-', $action ) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args );
2329
	}
2330
2331
2332
2333
2334
2335
	/**
2336
	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2337
	 * @return [type] [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2338
	 */
2339
	public function display_admin_page_with_metabox_columns() {
2340
		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2341
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $this->_column_template_path, $this->_template_args, TRUE);
2342
2343
		//the final wrapper
2344
		$this->admin_page_wrapper();
2345
	}
2346
2347
2348
2349
2350
2351
2352
2353
	/**
2354
	*		generates  HTML wrapper for an admin details page
2355
	*		@access public
2356
	*		@return void
2357
	*/
2358
	public function display_admin_page_with_sidebar() {
2359
2360
		$this->_display_admin_page(TRUE);
2361
	}
2362
2363
2364
2365
2366
	/**
2367
	*		generates  HTML wrapper for an admin details page (except no sidebar)
2368
	*		@access public
2369
	*		@return void
2370
	*/
2371
	public function display_admin_page_with_no_sidebar() {
2372
		$this->_display_admin_page();
2373
	}
2374
2375
2376
2377
2378
	/**
2379
	 * generates HTML wrapper for an EE about admin page (no sidebar)
2380
	 * @access public
2381
	 * @return void
2382
	 */
2383
	public function display_about_admin_page() {
2384
		$this->_display_admin_page( FALSE, TRUE );
2385
	}
2386
2387
2388
2389
2390
	/**
2391
	 * display_admin_page
2392
	 * contains the code for actually displaying an admin page
2393
	 *
2394
	 * @access private
2395
	 * @param  boolean $sidebar true with sidebar, false without
2396
	 * @param  boolean $about   use the about admin wrapper instead of the default.
2397
	 * @return html           admin_page
2398
	 */
2399
	private function _display_admin_page($sidebar = false, $about = FALSE) {
2400
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2401
2402
		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2403
		do_action( 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' );
2404
2405
		// set current wp page slug - looks like: event-espresso_page_event_categories
2406
		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2407
		$this->_template_args['current_page'] = $this->_wp_page_slug;
2408
2409
		$template_path = $sidebar ?  EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2410
2411
		if ( defined('DOING_AJAX' ) )
2412
			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2413
2414
		$template_path = !empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2415
2416
		$this->_template_args['post_body_content'] = isset( $this->_template_args['admin_page_content'] ) ? $this->_template_args['admin_page_content'] : '';
2417
		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2418
		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2419
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2420
2421
2422
		// the final template wrapper
2423
		$this->admin_page_wrapper($about);
2424
	}
2425
2426
2427
2428
2429
2430
	/**
2431
	 * This is used to display caf preview pages.
2432
	 *
2433
	 * @since 4.3.2
2434
	 *
2435
	 * @param string $utm_campaign_source what is the key used for google analytics link
2436
	 * @param bool   $display_sidebar whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2437
	 * @return void
2438
	 */
2439
	public function display_admin_caf_preview_page( $utm_campaign_source = '', $display_sidebar = TRUE ) {
2440
		//let's generate a default preview action button if there isn't one already present.
2441
		$this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso');
2442
		$buy_now_url = add_query_arg(
2443
			array(
2444
				'ee_ver' => 'ee4',
2445
				'utm_source' => 'ee4_plugin_admin',
2446
				'utm_medium' => 'link',
2447
				'utm_campaign' => $utm_campaign_source,
2448
				'utm_content' => 'buy_now_button'
2449
			),
2450
		'http://eventespresso.com/pricing/'
2451
		);
2452
		$this->_template_args['preview_action_button'] = ! isset( $this->_template_args['preview_action_button'] ) ? $this->get_action_link_or_button( '', 'buy_now', array(), 'button-primary button-large', $buy_now_url, true ) : $this->_template_args['preview_action_button'];
2453
		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2454
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2455
		$this->_display_admin_page( $display_sidebar );
2456
	}
2457
2458
2459
	/**
2460
	 * display_admin_list_table_page_with_sidebar
2461
	 * generates HTML wrapper for an admin_page with list_table
2462
	 *
2463
	 * @access public
2464
	 * @return html
2465
	 */
2466
	public function display_admin_list_table_page_with_sidebar() {
2467
		$this->_display_admin_list_table_page(TRUE);
2468
	}
2469
2470
	/**
2471
	 * display_admin_list_table_page_with_no_sidebar
2472
	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2473
	 *
2474
	 * @access public
2475
	 * @return html
2476
	 */
2477
	public function display_admin_list_table_page_with_no_sidebar() {
2478
		$this->_display_admin_list_table_page();
2479
	}
2480
2481
2482
2483
	/**
2484
	 * generates html wrapper for an admin_list_table page
2485
	 * @access private
2486
	 * @param boolean $sidebar whether to display with sidebar or not.
2487
	 * @return html
2488
	 */
2489
	private function _display_admin_list_table_page( $sidebar = false ) {
2490
		//setup search attributes
2491
		$this->_set_search_attributes();
2492
		$this->_template_args['current_page'] = $this->_wp_page_slug;
2493
		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2494
2495
		$this->_template_args['table_url'] = defined( 'DOING_AJAX') ? add_query_arg( array( 'noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url ) : add_query_arg( array( 'route' => $this->_req_action), $this->_admin_base_url);
2496
		$this->_template_args['list_table'] = $this->_list_table_object;
2497
		$this->_template_args['current_route'] = $this->_req_action;
2498
		$this->_template_args['list_table_class'] = get_class( $this->_list_table_object );
2499
2500
		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2501
		if( ! empty( $ajax_sorting_callback )) {
2502
			$sortable_list_table_form_fields = wp_nonce_field( $ajax_sorting_callback . '_nonce', $ajax_sorting_callback . '_nonce', FALSE, FALSE );
2503
//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2504
//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2505
			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug .'" />';
2506
			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2507
		} else {
2508
			$sortable_list_table_form_fields = '';
2509
		}
2510
2511
		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2512
		$hidden_form_fields = isset( $this->_template_args['list_table_hidden_fields'] ) ? $this->_template_args['list_table_hidden_fields'] : '';
2513
		$nonce_ref = $this->_req_action . '_nonce';
2514
		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce( $nonce_ref ) . '">';
2515
		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2516
2517
		//display message about search results?
2518
		$this->_template_args['before_list_table'] .= apply_filters( 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', !empty( $this->_req_data['s'] ) ? '<p class="ee-search-results">' . sprintf( __('Displaying search results for the search string: <strong><em>%s</em></strong>', 'event_espresso'), trim($this->_req_data['s'], '%') ) . '</p>' : '', $this->page_slug, $this->_req_data, $this->_req_action );
2519
2520
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2521
2522
		// the final template wrapper
2523
		if ( $sidebar )
2524
			$this->display_admin_page_with_sidebar();
2525
		else
2526
			$this->display_admin_page_with_no_sidebar();
2527
	}
2528
2529
2530
2531
2532
2533
	/**
2534
	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2535
	 *
2536
	 * $items are expected in an array in the following format:
2537
	 * $legend_items = array(
2538
	 * 		'item_id' => array(
2539
	 * 			'icon' => 'http://url_to_icon_being_described.png',
2540
	 * 			'desc' => __('localized description of item');
2541
	 * 		)
2542
	 * );
2543
	 * @param  array $items  see above for format of array
2544
	 * @return string        html string of legend
2545
	 */
2546
	protected function _display_legend( $items ) {
2547
		$template_args['items'] = apply_filters( 'FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template_args = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2548
		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2549
		return EEH_Template::display_template($legend_template, $template_args, TRUE);
2550
	}
2551
2552
2553
2554
2555
	/**
2556
	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2557
	 *
2558
	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2559
	 *
2560
	 * The returned json object is created from an array in the following format:
2561
	 * array(
2562
	 * 	'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2563
	 * 	'success' => FALSE, //(default FALSE) - contains any special success message.
2564
	 * 	'notices' => '', // - contains any EE_Error formatted notices
2565
	 * 	'content' => 'string can be html', //this is a string of formatted content (can be html)
2566
	 * 	'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any specific template args that might be included in here)
2567
	 * )
2568
	 *
2569
	 * The json object is populated by whatever is set in the $_template_args property.
2570
	 *
2571
	 * @return json object
2572
	 */
2573
	protected function _return_json( $sticky_notices = FALSE ) {
2574
2575
		//make sure any EE_Error notices have been handled.
2576
		$this->_process_notices( array(), TRUE, $sticky_notices );
2577
2578
2579
		$data = isset( $this->_template_args['data'] ) ? $this->_template_args['data'] : array();
2580
		unset($this->_template_args['data']);
2581
		$json = array(
2582
			'error' => isset( $this->_template_args['error'] ) ? $this->_template_args['error'] : FALSE,
2583
			'success' => isset( $this->_template_args['success'] ) ? $this->_template_args['success'] : FALSE,
2584
			'notices' => EE_Error::get_notices(),
2585
			'content' => isset( $this->_template_args['admin_page_content'] ) ? $this->_template_args['admin_page_content'] : '',
2586
			'data' => array_merge( $data, array('template_args' => $this->_template_args ) ),
2587
			'isEEajax' => TRUE //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2588
			);
2589
2590
2591
		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2592
		if ( NULL === error_get_last() || ! headers_sent() )
2593
			header('Content-Type: application/json; charset=UTF-8');
2594
                if( function_exists( 'wp_json_encode' ) ) {
2595
                    echo wp_json_encode( $json );
2596
                } else {
2597
                    echo json_encode( $json );
2598
                }
2599
		exit();
2600
	}
2601
2602
2603
2604
	/**
2605
	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2606
	 * @return json_obj|EE_Error
2607
	 */
2608
	public function return_json() {
2609
		if ( defined('DOING_AJAX') && DOING_AJAX )
2610
			$this->_return_json();
2611
2612
		else {
2613
			throw new EE_Error( sprintf( __('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__ ) );
2614
		}
2615
	}
2616
2617
2618
2619
2620
	/**
2621
	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2622
	 *
2623
	 * @param EE_Admin_Hooks object $hook_obj This will be the object for the EE_Admin_Hooks child
2624
	 *
2625
	 * @access public
2626
	 * @return void
2627
	 */
2628
	public function set_hook_object( EE_Admin_Hooks $hook_obj ) {
2629
		$this->_hook_obj = $hook_obj;
2630
	}
2631
2632
2633
2634
2635
2636
	/**
2637
	*		generates  HTML wrapper with Tabbed nav for an admin page
2638
	*		@access public
2639
	*		@param  boolean $about whether to use the special about page wrapper or default.
2640
	*		@return void
2641
	*/
2642
	public function admin_page_wrapper($about = FALSE) {
2643
2644
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2645
2646
		$this->_nav_tabs = $this->_get_main_nav_tabs();
2647
2648
		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2649
		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2650
2651
		$this->_template_args['before_admin_page_content'] = apply_filters( 'FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, isset( $this->_template_args['before_admin_page_content'] ) ? $this->_template_args['before_admin_page_content'] : '');
2652
		$this->_template_args['after_admin_page_content'] = apply_filters( 'FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, isset( $this->_template_args['after_admin_page_content'] ) ? $this->_template_args['after_admin_page_content'] : '');
2653
2654
		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2655
2656
2657
2658
		// load settings page wrapper template
2659
		$template_path = !defined( 'DOING_AJAX' ) ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2660
2661
		//about page?
2662
		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2663
2664
2665
		if ( defined( 'DOING_AJAX' ) ) {
2666
			$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2667
2668
			$this->_return_json();
2669
		} else {
2670
			EEH_Template::display_template( $template_path, $this->_template_args );
2671
		}
2672
2673
	}
2674
2675
2676
2677
	/**
2678
	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2679
	 * @return string html
2680
	 */
2681
	protected function _get_main_nav_tabs() {
2682
		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2683
		EE_Registry::instance()->load_helper( 'Tabbed_Content' );
2684
		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
0 ignored issues
show
Bug introduced by
It seems like $this->_nav_tabs can also be of type string; however, EEH_Tabbed_Content::display_admin_nav_tabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
2685
	}
2686
2687
2688
2689
2690
2691
2692
2693
2694
	/**
2695
	*		sort nav tabs
2696
	*		@access public
2697
	*		@return void
2698
	*/
2699
	private function _sort_nav_tabs( $a, $b ) {
2700
		if ($a['order'] == $b['order']) {
2701
	        return 0;
2702
	    }
2703
	    return ($a['order'] < $b['order']) ? -1 : 1;
2704
	}
2705
2706
2707
2708
2709
2710
	/**
2711
	 * 	generates HTML for the forms used on admin pages
2712
	 * 	@access protected
2713
	 * 	@param	array $input_vars - array of input field details
2714
	 * 	@param	array $id - used for defining unique identifiers for the form.
2715
	 * 	@param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use)
2716
	 * 	@return string
2717
	 * 	@uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2718
	 * 	@uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2719
	 */
2720
	protected function _generate_admin_form_fields( $input_vars = array(), $generator = 'string', $id = FALSE ) {
2721
		EE_Registry::instance()->load_helper( 'Form_Fields' );
2722
		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2723
		return $content;
2724
	}
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
	/**
2735
	 * generates the "Save" and "Save & Close" buttons for edit forms
2736
	 *
2737
	 * @access protected
2738
	 * @param bool $both if true then both buttons will be generated.  If false then just the "Save & Close" button.
2739
	 * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2740
	 * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2741
	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2742
	 */
2743
	protected function _set_save_buttons($both = TRUE, $text = array(), $actions = array(), $referrer = NULL ) {
2744
		//make sure $text and $actions are in an array
2745
		$text = (array) $text;
2746
		$actions = (array) $actions;
2747
		$referrer_url = empty($referrer) ? '' : $referrer;
0 ignored issues
show
Unused Code introduced by
$referrer_url is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2748
		$referrer_url = !$referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] .'" />' : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer .'" />';
2749
2750
		$button_text = !empty($text) ? $text : array( __('Save', 'event_espresso'), __('Save and Close', 'event_espresso') );
2751
		$default_names = array( 'save', 'save_and_close' );
2752
2753
		//add in a hidden index for the current page (so save and close redirects properly)
2754
		$this->_template_args['save_buttons'] = $referrer_url;
2755
2756
		foreach ( $button_text as $key => $button ) {
2757
			$ref = $default_names[$key];
2758
			$id = $this->_current_view . '_' . $ref;
2759
			$name = !empty($actions) ? $actions[$key] : $ref;
2760
			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2761
			if ( !$both ) break;
2762
		}
2763
2764
	}
2765
2766
2767
	/**
2768
	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2769
	 *
2770
	 * @see $this->_set_add_edit_form_tags() for details on params
2771
	 * @since 4.6.0
2772
	 *
2773
	 */
2774
	public function set_add_edit_form_tags( $route = '', $additional_hidden_fields = array() ) {
2775
		$this->_set_add_edit_form_tags( $route, $additional_hidden_fields );
2776
	}
2777
2778
2779
2780
	/**
2781
	 * set form open and close tags on add/edit pages.
2782
	 *
2783
	 * @access protected
2784
	 * @param string $route the route you want the form to direct to
2785
	 * @param array $additional_hidden_fields any additional hidden fields required in the form header
2786
	 * @return void
2787
	 */
2788
	protected function _set_add_edit_form_tags( $route = '', $additional_hidden_fields = array() ) {
2789
2790
		if ( empty( $route )) {
2791
			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2792
			$dev_msg = $user_msg . "\n" . sprintf( __('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__ );
2793
			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
2794
		}
2795
		// open form
2796
		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2797
		// add nonce
2798
		$nonce = wp_nonce_field( $route . '_nonce', $route . '_nonce', FALSE, FALSE );
2799
//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2800
		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2801
		// add REQUIRED form action
2802
		$hidden_fields = array(
2803
				'action' => array( 'type' => 'hidden', 'value' => $route ),
2804
			);
2805
		// merge arrays
2806
		$hidden_fields = is_array( $additional_hidden_fields) ? array_merge( $hidden_fields, $additional_hidden_fields ) : $hidden_fields;
2807
		// generate form fields
2808
		$form_fields = $this->_generate_admin_form_fields( $hidden_fields, 'array' );
2809
		// add fields to form
2810
		foreach ( $form_fields as $field_name => $form_field ) {
0 ignored issues
show
Bug introduced by
The expression $form_fields of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
2811
			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2812
		}
2813
2814
		// close form
2815
		$this->_template_args['after_admin_page_content'] = '</form>';
2816
2817
	}
2818
2819
2820
2821
	/**
2822
	 * Public Wrapper for _redirect_after_action() method since its
2823
	 * discovered it would be useful for external code to have access.
2824
	 *
2825
	 * @see EE_Admin_Page::_redirect_after_action() for params.
2826
	 * @since 4.5.0
2827
	 */
2828
	public function redirect_after_action( $success = FALSE, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = FALSE ) {
2829
		$this->_redirect_after_action( $success, $what, $action_desc, $query_args, $override_overwrite );
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a false|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2830
	}
2831
2832
2833
2834
	/**
2835
	 * 	_redirect_after_action
2836
	 *	@param int 		$success 	- whether success was for two or more records, or just one, or none
2837
	 *	@param string 	$what 		- what the action was performed on
2838
	 *	@param string 	$action_desc 	- what was done ie: updated, deleted, etc
2839
	 *	@param int 		$query_args		- an array of query_args to be added to the URL to redirect to after the admin action is completed
2840
	 *	@param BOOL     $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2841
	 *	@access protected
2842
	 *	@return void
2843
	 */
2844
	protected function _redirect_after_action( $success = FALSE, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = FALSE ) {
2845
2846
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2847
2848
		//class name for actions/filters.
2849
		$classname = get_class($this);
2850
2851
		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2852
		$redirect_url = isset( $query_args['page'] ) ? admin_url('admin.php') : $this->_admin_base_url;
2853
		$notices = EE_Error::get_notices( FALSE );
2854
2855
		// overwrite default success messages //BUT ONLY if overwrite not overridden
2856
		if ( ! $override_overwrite || ! empty( $notices['errors'] )) {
2857
			EE_Error::overwrite_success();
2858
		}
2859
		// how many records affected ? more than one record ? or just one ?
2860
		if ( $success > 1 && empty( $notices['errors'] )) {
2861
			// set plural msg
2862
			EE_Error::add_success( sprintf( __('The "%s" have been successfully %s.', 'event_espresso'), $what, $action_desc ), __FILE__, __FUNCTION__, __LINE__);
2863
		} else if ( $success == 1 && empty( $notices['errors'] )) {
2864
			// set singular msg
2865
			EE_Error::add_success( sprintf( __('The "%s" has been successfully %s.', 'event_espresso'), $what, $action_desc), __FILE__, __FUNCTION__, __LINE__ );
2866
		}
2867
2868
		// check that $query_args isn't something crazy
2869
		if ( ! is_array( $query_args )) {
2870
			$query_args = array();
2871
		}
2872
2873
		/**
2874
		 * Allow injecting actions before the query_args are modified for possible different
2875
		 * redirections on save and close actions
2876
		 *
2877
		 * @since 4.2.0
2878
		 *
2879
		 * @param array $query_args   The original query_args array coming into the
2880
		 *                          		method.
2881
		 */
2882
		do_action( 'AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args );
2883
2884
		//calculate where we're going (if we have a "save and close" button pushed)
2885
		if ( isset($this->_req_data['save_and_close'] ) && isset($this->_req_data['save_and_close_referrer'] ) ) {
2886
			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2887
			$parsed_url = parse_url( $this->_req_data['save_and_close_referrer'] );
2888
			// regenerate query args array from refferer URL
2889
			parse_str( $parsed_url['query'], $query_args );
2890
			// correct page and action will be in the query args now
2891
			$redirect_url = admin_url( 'admin.php' );
2892
		}
2893
2894
		//merge any default query_args set in _default_route_query_args property
2895
		if ( ! empty( $this->_default_route_query_args ) && ! $this->_is_UI_request ) {
2896
			$args_to_merge = array();
2897
			foreach ( $this->_default_route_query_args as $query_param => $query_value ) {
2898
				//is there a wp_referer array in our _default_route_query_args property?
2899
				if ( $query_param == 'wp_referer'  ) {
2900
					$query_value = (array) $query_value;
2901
					foreach ( $query_value as $reference => $value ) {
2902
						if ( strpos( $reference, 'nonce' ) !== false ) {
2903
							continue;
2904
						}
2905
2906
						//finally we will override any arguments in the referer with
2907
						//what might be set on the _default_route_query_args array.
2908
						if ( isset( $this->_default_route_query_args[$reference] ) ) {
2909
							$args_to_merge[$reference] = urlencode( $this->_default_route_query_args[$reference] );
2910
						} else {
2911
							$args_to_merge[$reference] = urlencode( $value );
2912
						}
2913
					}
2914
					continue;
2915
				}
2916
2917
				$args_to_merge[$query_param] = $query_value;
2918
			}
2919
2920
			//now let's merge these arguments but override with what was specifically sent in to the
2921
			//redirect.
2922
			$query_args = array_merge( $args_to_merge, $query_args );
2923
		}
2924
2925
		$this->_process_notices($query_args);
0 ignored issues
show
Bug introduced by
It seems like $query_args defined by parameter $query_args on line 2844 can also be of type null; however, EE_Admin_Page::_process_notices() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
2926
2927
2928
		// generate redirect url
2929
2930
		// if redirecting to anything other than the main page, add a nonce
2931
		if ( isset( $query_args['action'] )) {
2932
			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2933
			$query_args['_wpnonce'] = wp_create_nonce( $query_args['action'] . '_nonce' );
2934
		}
2935
2936
		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2937
		do_action( 'AHEE_redirect_' . $classname . $this->_req_action, $query_args );
2938
2939
		$redirect_url = apply_filters( 'FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce( $query_args, $redirect_url ), $query_args );
2940
2941
2942
		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2943
		if ( defined('DOING_AJAX' ) ) {
2944
			$default_data = array(
2945
				'close' => TRUE,
2946
				'redirect_url' => $redirect_url,
2947
				'where' => 'main',
2948
				'what' => 'append',
2949
				);
2950
2951
			$this->_template_args['success'] = $success;
2952
			$this->_template_args['data'] = !empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data'] ): $default_data;
2953
			$this->_return_json();
2954
		}
2955
2956
		wp_safe_redirect( $redirect_url );
2957
		exit();
2958
	}
2959
2960
2961
2962
2963
	/**
2964
	 * process any notices before redirecting (or returning ajax request)
2965
	 * This method sets the $this->_template_args['notices'] attribute;
2966
	 *
2967
	 * @param  array  $query_args any query args that need to be used for notice transient ('action')
2968
	 * @param bool    $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2969
	 * @param bool    $sticky_notices      This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2970
	 * @return void
2971
	 */
2972
	protected function _process_notices( $query_args = array(), $skip_route_verify = FALSE , $sticky_notices = TRUE ) {
2973
2974
		$this->_template_args['notices'] = EE_Error::get_notices();
2975
2976
		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2977
		if ( ! defined( 'DOING_AJAX' ) || $sticky_notices ) {
2978
			$route = isset( $query_args['action'] ) ? $query_args['action'] : 'default';
2979
			$this->_add_transient( $route, $this->_template_args['notices'], TRUE, $skip_route_verify );
0 ignored issues
show
Documentation introduced by
$this->_template_args['notices'] is of type null|string|array<string...ng","errors":"string"}>, but the function expects a object<data>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2980
		}
2981
	}
2982
2983
2984
2985
2986
	/**
2987
	 * get_action_link_or_button
2988
	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2989
	 *
2990
	 * @param string $action use this to indicate which action the url is generated with.
2991
	 * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property.
2992
	 * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2993
	 * @param string $class Use this to give the class for the button. Defaults to 'button-primary'
2994
	 * @param string $base_url If this is not provided the _admin_base_url will be used as the default for the button base_url.  Otherwise this value will be used.
2995
	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2996
	 *
2997
	 * @throws EE_Error
2998
	 *
2999
	 * @return string html for button
3000
	 */
3001
	public function get_action_link_or_button($action, $type = 'add', $extra_request = array(), $class = 'button-primary', $base_url = FALSE, $exclude_nonce = false ) {
3002
		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3003
		if ( !isset($this->_page_routes[$action]) && !$base_url )
0 ignored issues
show
Bug Best Practice introduced by
The expression $base_url of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
3004
			throw new EE_Error( sprintf( __('There is no page route for given action for the button.  This action was given: %s', 'event_espresso'), $action) );
3005
3006
		if ( !isset( $this->_labels['buttons'][$type] ) )
3007
			throw new EE_Error( sprintf( __('There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', 'event_espresso'), $type) );
3008
3009
		//finally check user access for this button.
3010
		$has_access = $this->check_user_access( $action, TRUE );
3011
		if ( ! $has_access ) {
3012
			return '';
3013
		}
3014
3015
		$_base_url = !$base_url ? $this->_admin_base_url : $base_url;
3016
3017
		$query_args = array(
3018
			'action' => $action  );
3019
3020
		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3021
		if ( !empty($extra_request) )
3022
			$query_args = array_merge( $extra_request, $query_args );
3023
3024
		$url = self::add_query_args_and_nonce( $query_args, $_base_url, false, $exclude_nonce );
3025
3026
		$button = EEH_Template::get_button_or_link( $url, $this->_labels['buttons'][$type], $class );
3027
3028
		return $button;
3029
	}
3030
3031
3032
3033
3034
3035
3036
	/**
3037
	 * _per_page_screen_option
3038
	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3039
	 * @return void
3040
	 */
3041
	protected function _per_page_screen_option() {
3042
		$option = 'per_page';
3043
		$args = array(
3044
			'label' => $this->_admin_page_title,
3045
			'default' => 10,
3046
			'option' => $this->_current_page . '_' . $this->_current_view . '_per_page'
3047
			);
3048
		//ONLY add the screen option if the user has access to it.
3049
		if ( $this->check_user_access( $this->_current_view, true ) ) {
3050
			add_screen_option( $option, $args );
3051
		}
3052
	}
3053
3054
3055
3056
3057
	/**
3058
	 * set_per_page_screen_option
3059
	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3060
	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3061
	 *
3062
	 * @access private
3063
	 * @return void
3064
	 */
3065
	private function _set_per_page_screen_options() {
3066
		if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {
3067
			check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
3068
3069
			if ( !$user = wp_get_current_user() )
3070
			return;
3071
			$option = $_POST['wp_screen_options']['option'];
3072
			$value = $_POST['wp_screen_options']['value'];
3073
3074
			if ( $option != sanitize_key( $option ) )
3075
				return;
3076
3077
			$map_option = $option;
3078
3079
			$option = str_replace('-', '_', $option);
3080
3081
			switch ( $map_option ) {
3082
				case $this->_current_page . '_' .  $this->_current_view . '_per_page':
3083
					$value = (int) $value;
3084
					if ( $value < 1 || $value > 999 )
3085
						return;
3086
					break;
3087
				default:
3088
					$value = apply_filters( 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value );
3089
					if ( false === $value )
3090
						return;
3091
					break;
3092
			}
3093
3094
			update_user_meta($user->ID, $option, $value);
3095
			wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
3096
			exit;
3097
		}
3098
	}
3099
3100
3101
3102
	/**
3103
	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3104
	 * @param array $data array that will be assigned to template args.
3105
	 */
3106
	public function set_template_args( $data ) {
3107
		$this->_template_args = array_merge( $this->_template_args, (array) $data );
3108
	}
3109
3110
3111
3112
3113
	/**
3114
	 * This makes available the WP transient system for temporarily moving data between routes
3115
	 *
3116
	 * @access protected
3117
	 * @param route $route the route that should receive the transient
3118
	 * @param data $data  the data that gets sent
3119
	 * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3120
	 * @param bool $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3121
	 * @return void
3122
	 */
3123
	protected function _add_transient( $route, $data, $notices = FALSE, $skip_route_verify = FALSE ) {
3124
		$user_id = get_current_user_id();
3125
3126
		if ( !$skip_route_verify )
3127
			$this->_verify_route($route);
3128
3129
3130
		//now let's set the string for what kind of transient we're setting
3131
		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3132
		$data = $notices ? array( 'notices' => $data ) : $data;
3133
		//is there already a transient for this route?  If there is then let's ADD to that transient
3134
		$existing = is_multisite() && is_network_admin() ? get_site_transient( $transient ) : get_transient( $transient );
3135
		if ( $existing ) {
3136
			$data = array_merge( (array) $data, (array) $existing );
3137
		}
3138
3139
		if ( is_multisite() && is_network_admin() ) {
3140
			set_site_transient( $transient, $data, 8 );
3141
		} else {
3142
			set_transient( $transient, $data, 8 );
3143
		}
3144
	}
3145
3146
3147
3148
3149
	/**
3150
	 * this retrieves the temporary transient that has been set for moving data between routes.
3151
	 * @param bool $notices true we get notices transient. False we just return normal route transient
3152
	 * @return mixed data
3153
	 */
3154
	protected function _get_transient( $notices = FALSE, $route = FALSE ) {
3155
		$user_id = get_current_user_id();
3156
		$route = !$route ? $this->_req_action : $route;
3157
		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3158
		$data = is_multisite() && is_network_admin() ? get_site_transient( $transient ) : get_transient( $transient );
3159
		//delete transient after retrieval (just in case it hasn't expired);
3160
		if ( is_multisite() && is_network_admin() ) {
3161
			delete_site_transient( $transient );
3162
		} else {
3163
			delete_transient( $transient );
3164
		}
3165
		return $notices && isset( $data['notices'] ) ? $data['notices'] : $data;
3166
	}
3167
3168
3169
3170
3171
	/**
3172
	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3173
	 *
3174
	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3175
	 * @return void
3176
	 */
3177
	protected function _transient_garbage_collection() {
3178
		global $wpdb;
3179
3180
		//retrieve all existing transients
3181
		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3182
		if ( $results = $wpdb->get_results( $query ) ) {
3183
			foreach ( $results as $result ) {
3184
				$transient = str_replace( '_transient_', '', $result->option_name );
3185
				get_transient( $transient );
3186
				if ( is_multisite() && is_network_admin() ) {
3187
					get_site_transient( $transient );
3188
				}
3189
			}
3190
		}
3191
	}
3192
3193
3194
3195
3196
3197
	/**
3198
	 * get_view
3199
	 *
3200
	 * @access public
3201
	 * @return string content of _view property
3202
	 */
3203
	public function get_view() {
3204
		return $this->_view;
3205
	}
3206
3207
3208
3209
3210
	/**
3211
	 * getter for the protected $_views property
3212
	 *
3213
	 * @return array
3214
	 */
3215
	public function get_views() {
3216
		return $this->_views;
3217
	}
3218
3219
3220
3221
3222
	/**
3223
	 * get_current_page
3224
	 *
3225
	 * @access public
3226
	 * @return string _current_page property value
3227
	 */
3228
	public function get_current_page() {
3229
		return $this->_current_page;
3230
	}
3231
3232
3233
3234
3235
	/**
3236
	 * get_current_view
3237
	 *
3238
	 * @access public
3239
	 * @return string _current_view property value
3240
	 */
3241
	public function get_current_view() {
3242
		return $this->_current_view;
3243
	}
3244
3245
3246
3247
	/**
3248
	 * get_current_screen
3249
	 *
3250
	 * @access public
3251
	 * @return object The current WP_Screen object
3252
	 */
3253
	public function get_current_screen() {
3254
		return $this->_current_screen;
3255
	}
3256
3257
3258
	/**
3259
	 * get_current_page_view_url
3260
	 *
3261
	 * @access public
3262
	 * @return string This returns the url for the current_page_view.
3263
	 */
3264
	public function get_current_page_view_url() {
3265
		return $this->_current_page_view_url;
3266
	}
3267
3268
3269
3270
3271
	/**
3272
	 * just returns the _req_data property
3273
	 * @return array
3274
	 */
3275
	public function get_request_data() {
3276
		return $this->_req_data;
3277
	}
3278
3279
3280
3281
	/**
3282
	 * returns the _req_data protected property
3283
	 * @return string
3284
	 */
3285
	public function get_req_action() {
3286
		return $this->_req_action;
3287
	}
3288
3289
3290
	/**
3291
	 * @return bool  value of $_is_caf property
3292
	 */
3293
	public function is_caf() {
3294
		return $this->_is_caf;
3295
	}
3296
3297
3298
3299
3300
	/**
3301
	 * updates  espresso configuration settings
3302
	 *
3303
	 * @access 	protected
3304
	 * @param string $tab
3305
	 * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
3306
	 * @param string $file	file where error occurred
3307
	 * @param string $func function  where error occurred
3308
	 * @param string $line	line no where error occurred
3309
	 * @return boolean
3310
	 */
3311
	protected function _update_espresso_configuration( $tab, $config, $file = '', $func = '', $line = '' ) {
3312
3313
		//remove any options that are NOT going to be saved with the config settings.
3314
		if ( isset( $config->core->ee_ueip_optin ) ) {
3315
			$config->core->ee_ueip_has_notified = TRUE;
3316
			// TODO: remove the following two lines and make sure values are migrated from 3.1
3317
			update_option( 'ee_ueip_optin', $config->core->ee_ueip_optin);
3318
			update_option( 'ee_ueip_has_notified', TRUE );
3319
		}
3320
		// and save it (note we're also doing the network save here)
3321
		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config( FALSE, FALSE ) : TRUE;
3322
		$config_saved = EE_Config::instance()->update_espresso_config( FALSE, FALSE );
3323
		if ( $config_saved && $net_saved ) {
3324
			EE_Error::add_success( sprintf( __('"%s" have been successfully updated.', 'event_espresso'), $tab ));
3325
			return TRUE;
3326
		} else {
3327
			EE_Error::add_error( sprintf( __('The "%s" were not updated.', 'event_espresso'), $tab ), $file, $func, $line  );
3328
			return FALSE;
3329
		}
3330
	}
3331
3332
3333
3334
3335
3336
	/**
3337
	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3338
	 * @return array
3339
	 */
3340
	public function get_yes_no_values(){
3341
		return $this->_yes_no_values;
3342
	}
3343
3344
3345
3346
	protected function _get_dir() {
3347
		$reflector = new ReflectionClass(get_class($this));
3348
		return dirname($reflector->getFileName());
3349
	}
3350
3351
3352
3353
3354
	/**
3355
	 * A helper for getting a "next link".
3356
	 *
3357
	 * @param string $url   The url to link to
3358
	 * @param string $class The class to use.
3359
	 *
3360
	 * @return string
3361
	 */
3362
	protected function _next_link( $url, $class = 'dashicons dashicons-arrow-right' ) {
3363
		return '<a class="' . $class . '" href="' . $url . '"></a>';
3364
	}
3365
3366
3367
3368
3369
	/**
3370
	 * A helper for getting a "previous link".
3371
	 *
3372
	 * @param string $url   The url to link to
3373
	 * @param string $class The class to use.
3374
	 *
3375
	 * @return string
3376
	 */
3377
	protected function _previous_link( $url, $class = 'dashicons dashicons-arrow-left' ) {
3378
		return '<a class="' . $class . '" href="' . $url . '"></a>';
3379
	}
3380
3381
3382
3383
3384
3385
3386
3387
	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3388
3389
3390
3391
3392
	/**
3393
	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller 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 _req_data array.
3394
	 * @return bool success/fail
3395
	 */
3396
	protected function _process_resend_registration() {
3397
		$this->_template_args['success'] = EED_Messages::process_resend( $this->_req_data );
3398
		do_action( 'AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data );
3399
		return $this->_template_args['success'];
3400
	}
3401
3402
3403
3404
	/**
3405
	 * This automatically processes any payment message notifications when manual payment has been applied.
3406
	 *
3407
	 * @access protected
3408
	 * @param \EE_Payment $payment
3409
	 * @return bool success/fail
3410
	 */
3411
	protected function _process_payment_notification( EE_Payment $payment ) {
3412
		add_filter( 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true' );
3413
		$success = apply_filters( 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', FALSE, $payment );
3414
		$this->_template_args['success'] = $success;
3415
		return $success;
3416
	}
3417
3418
3419
}
3420
// end of file:  includes/core/admin/EE_Admin_Page.core.php
3421