Completed
Branch BUG-9623-config-log (1352ef)
by
unknown
373:04 queued 358:05
created

EE_Admin_Page   F

Complexity

Total Complexity 450

Size/Duplication

Total Lines 3406
Duplicated Lines 1.29 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 450
lcom 1
cbo 15
dl 44
loc 3406
rs 0.6314
c 3
b 0
f 3

121 Methods

Rating   Name   Duplication   Size   Complexity  
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
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
A _sort_nav_tabs() 0 6 3
B __construct() 0 41 3
_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
A ajax_metabox_content() 0 7 3
F _page_setup() 0 92 24
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
A _verify_nonce() 0 16 4
F _route_admin_request() 5 60 23
A _reset_routing_properties() 0 7 1
A add_query_args_and_nonce() 0 19 4
A _get_help_tab_link() 0 3 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
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
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
A _add_global_screen_options() 0 1 1
A _add_global_feature_pointers() 0 1 1
C load_global_scripts_styles() 0 83 10
A admin_footer_scripts_eei18n_js_strings() 0 51 1
F _return_json() 0 30 10
A return_json() 0 8 3
A set_hook_object() 0 3 1
B admin_page_wrapper() 0 32 6
A _get_main_nav_tabs() 0 5 1
A _generate_admin_form_fields() 0 5 2
C _set_save_buttons() 0 22 7
A set_add_edit_form_tags() 0 3 1
B _set_add_edit_form_tags() 0 30 4
A redirect_after_action() 0 3 1
F _redirect_after_action() 0 115 21
C _process_notices() 9 26 12
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
A set_template_args() 0 3 1
C _add_transient() 0 22 9
B _get_transient() 0 13 9
B _transient_garbage_collection() 0 15 5
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
B _update_espresso_configuration() 0 20 5
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
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
59
	/**
60
	 * @var array $_template_args
61
	 */
62
	protected $_template_args = array();
63
64
	//this will hold the list table object for a given view.
65
	protected $_list_table_object;
66
67
	//bools
68
	protected $_is_UI_request = NULL; //this starts at null so we can have no header routes progress through two states.
69
	protected $_routing;
70
71
	//list table args
72
	protected $_view;
73
	protected $_views;
74
75
76
	//action => method pairs used for routing incoming requests
77
	protected $_page_routes;
78
	protected $_page_config;
79
80
	//the current page route and route config
81
	protected $_route;
82
	protected $_route_config;
83
84
	/**
85
	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
86
	 * actions.
87
	 *
88
	 * @since 4.6.x
89
	 * @var array.
90
	 */
91
	protected $_default_route_query_args;
92
93
	//set via request page and action args.
94
	protected $_current_page;
95
	protected $_current_view;
96
	protected $_current_page_view_url;
97
98
	//sanitized request action (and nonce)
99
	/**
100
	 * @var string $_req_action
101
	 */
102
	protected $_req_action;
103
104
	/**
105
	 * @var string $_req_nonce
106
	 */
107
	protected $_req_nonce;
108
109
	//search related
110
	protected $_search_btn_label;
111
	protected $_search_box_callback;
112
113
	/**
114
	 * WP Current Screen object
115
	 *
116
	 * @var WP_Screen
117
	 */
118
	protected $_current_screen;
119
120
	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
121
	protected $_hook_obj;
122
123
	//for holding incoming request data
124
	protected $_req_data;
125
126
	// yes / no array for admin form fields
127
	protected $_yes_no_values = array();
128
129
	//some default things shared by all child classes
130
	protected $_default_espresso_metaboxes;
131
132
	/**
133
	 * 	EE_Registry Object
134
	 *	@var 	EE_Registry
135
	 * 	@access 	protected
136
	 */
137
	protected $EE = NULL;
138
139
140
141
	/**
142
	 * This is just a property that flags whether the given route is a caffeinated route or not.
143
	 * @var boolean
144
	 */
145
	protected $_is_caf = FALSE;
146
147
148
149
150
151
	/**
152
	 * 		@Constructor
153
	 *
154
	 * 		@param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
155
	 * 		@access public
156
	 */
157
	public function __construct( $routing = TRUE ) {
158
159
		if ( strpos( $this->_get_dir(), 'caffeinated' ) !== false )
160
			$this->_is_caf = TRUE;
161
162
		$this->_yes_no_values = array(
163
			array('id' => TRUE, 'text' => __('Yes', 'event_espresso')),
164
			array('id' => FALSE, 'text' => __('No', 'event_espresso'))
165
		);
166
167
168
169
		//set the _req_data property.
170
		$this->_req_data = array_merge( $_GET, $_POST );
171
172
173
		//routing enabled?
174
		$this->_routing = $routing;
175
176
		//set initial page props (child method)
177
		$this->_init_page_props();
178
179
		//set global defaults
180
		$this->_set_defaults();
181
182
		//set early because incoming requests could be ajax related and we need to register those hooks.
183
		$this->_global_ajax_hooks();
184
		$this->_ajax_hooks();
185
186
187
		//other_page_hooks have to be early too.
188
		$this->_do_other_page_hooks();
189
190
		//This just allows us to have extending clases do something specific before the parent constructor runs _page_setup.
191
		if ( method_exists( $this, '_before_page_setup' ) )
192
			$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...
193
194
		//set up page dependencies
195
		$this->_page_setup();
196
197
	}
198
199
200
201
202
	/**
203
	 * _init_page_props
204
	 * Child classes use to set at least the following properties:
205
	 * $page_slug.
206
	 * $page_label.
207
	 *
208
	 * @abstract
209
	 * @access protected
210
	 * @return void
211
	 */
212
	abstract protected function _init_page_props();
213
214
215
216
	/**
217
	 * _ajax_hooks
218
	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
219
	 * Note: within the ajax callback methods.
220
	 *
221
	 * @abstract
222
	 * @access protected
223
	 * @return void
224
	 */
225
	abstract protected function _ajax_hooks();
226
227
228
229
230
	/**
231
	 * _define_page_props
232
	 * child classes define page properties in here.  Must include at least:
233
	 * $_admin_base_url = base_url for all admin pages
234
	 * $_admin_page_title = default admin_page_title for admin pages
235
	 * $_labels = array of default labels for various automatically generated elements:
236
	 * 	array(
237
	 * 		'buttons' => array(
238
	 * 			'add' => __('label for add new button'),
239
	 * 	 		'edit' => __('label for edit button'),
240
	 * 	  		'delete' => __('label for delete button')
241
	 * 	  	 	)
242
	 * 	  	)
243
	 *
244
	 * @abstract
245
	 * @access protected
246
	 * @return void
247
	 */
248
	abstract protected function _define_page_props();
249
250
251
252
253
254
	/**
255
	 * _set_page_routes
256
	 * 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
257
	 * $this->_page_routes = array(
258
	 * 		'default' => array(
259
	 * 			'func' => '_default_method_handling_route',
260
	 * 			'args' => array('array','of','args'),
261
	 * 			'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
262
	 *			'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.
263
	 *			'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
264
	 *			'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
265
	 * 		),
266
	 * 		'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
267
	 * 		)
268
	 *
269
	 * )
270
	 *
271
	 *
272
	 * @abstract
273
	 * @access protected
274
	 * @return void
275
	 */
276
	abstract protected function _set_page_routes();
277
278
279
280
281
282
283
	/**
284
	 * _set_page_config
285
	 * 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.
286
	 * Format:
287
	 * $this->_page_config = array(
288
	 * 		'default' => array(
289
	 * 			'labels' => array(
290
	 * 				'buttons' => array(
291
	 * 					'add' => __('label for adding item'),
292
	 * 				 	'edit' => __('label for editing item'),
293
	 * 				  	'delete' => __('label for deleting item')
294
	 * 			    ),
295
	 * 			    'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
296
	 * 			), //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
297
	 * 			'nav' => array(
298
	 * 				'label' => __('Label for Tab', 'event_espresso').
299
	 *     			'url' => 'http://someurl', //automatically generated UNLESS you define
300
	 *     			'css_class' => 'css-class', //automatically generated UNLESS you define
301
	 *     			'order' => 10, //required to indicate tab position.
302
	 *     			'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
303
	 *     		'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
304
	 *     		'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
305
	 *     		'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.
306
	 *     		'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.
307
	 *     		'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.
308
	 *     		'help_tabs' => array( //this is used for adding help tabs to a page
309
	 *     			'tab_id' => array(
310
	 *     				'title' => 'tab_title',
311
	 *     				'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)
312
	 *     				'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
313
	 *     				),
314
	 *     			'tab2_id' => array(
315
	 *     			 	'title' => 'tab2 title',
316
	 *     			 	'filename' => 'file_name_2'
317
	 *     			 	'callback' => 'callback_method_for_content',
318
	 *     			 ),
319
	 *     	   	'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/
320
	 *     		'help_tour' => array(
321
	 *     			'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)
322
	 *     		),
323
	 *     		'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
324
	 *     		)
325
	 *
326
	 * )
327
	 *
328
	 *
329
	 * @abstract
330
	 * @access protected
331
	 * @return void
332
	 */
333
	abstract protected function _set_page_config();
334
335
336
337
338
339
	/** end sample help_tour methods **/
340
341
342
	/**
343
	 * _add_screen_options
344
	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
	 * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
347
	 * see also WP_Screen object documents...
348
	 * @link http://codex.wordpress.org/Class_Reference/WP_Screen
349
	 *
350
	 * @abstract
351
	 * @access protected
352
	 * @return void
353
	 */
354
	abstract protected function _add_screen_options();
355
356
357
358
359
360
361
362
	/**
363
	 * _add_feature_pointers
364
	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
365
	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
366
	 * Note: this is just a placeholder for now.  Implementation will come down the road
367
	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
368
	 * @link http://eamann.com/tech/wordpress-portland/
369
	 *
370
	 * @abstract
371
	 * @access protected
372
	 * @return void
373
	 */
374
	abstract protected function _add_feature_pointers();
375
376
377
378
379
380
	/**
381
	 * load_scripts_styles
382
	 * 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)
383
	 *
384
	 * @abstract
385
	 * @access public
386
	 * @return void
387
	 */
388
	abstract public function load_scripts_styles();
389
390
391
392
393
394
395
	/**
396
	 * admin_init
397
	 * 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.
398
	 *
399
	 * @abstract
400
	 * @access public
401
	 * @return void
402
	 */
403
	abstract public function admin_init();
404
405
406
407
408
409
410
	/**
411
	 * admin_notices
412
	 * 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.
413
	 *
414
	 * @abstract
415
	 * @access public
416
	 * @return void
417
	 */
418
	abstract public function admin_notices();
419
420
421
422
423
424
	/**
425
	 * admin_footer_scripts
426
	 * 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.
427
	 *
428
	 * @access public
429
	 * @return void
430
	 */
431
	abstract public function admin_footer_scripts();
432
433
434
435
436
437
438
	/**
439
	 * admin_footer
440
	 * 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.
441
	 *
442
	 * @access  public
443
	 * @return void
444
	 */
445
	public function admin_footer() {}
446
447
448
449
450
	/**
451
	 * _global_ajax_hooks
452
	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
453
	 * Note: within the ajax callback methods.
454
	 *
455
	 * @abstract
456
	 * @access protected
457
	 * @return void
458
	 */
459
	protected function _global_ajax_hooks() {
460
		//for lazy loading of metabox content
461
		add_action( 'wp_ajax_espresso-ajax-content', array( $this, 'ajax_metabox_content'), 10 );
462
	}
463
464
465
466
	public function ajax_metabox_content() {
467
		$contentid = isset( $this->_req_data['contentid'] ) ? $this->_req_data['contentid'] : '';
468
		$url = isset( $this->_req_data['contenturl'] ) ? $this->_req_data['contenturl'] : '';
469
470
		self::cached_rss_display( $contentid, $url );
471
		wp_die();
472
	}
473
474
475
476
	/**
477
	 * _page_setup
478
	 * 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.
479
	 *
480
	 * @final
481
	 * @access protected
482
	 * @return void
483
	 */
484
	final protected function _page_setup() {
485
486
		//requires?
487
		EE_Registry::instance()->load_helper('Template');
488
489
490
		//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.
491
		add_action( 'admin_init', array( $this, 'admin_init_global' ), 5 );
492
493
494
		//next verify if we need to load anything...
495
		$this->_current_page = !empty( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : FALSE;
496
		$this->page_folder = strtolower( str_replace( '_Admin_Page', '', str_replace( 'Extend_', '', get_class($this) ) ) );
497
498
		global $ee_menu_slugs;
499
		$ee_menu_slugs = (array) $ee_menu_slugs;
500
501
		if ( ( !$this->_current_page || ! isset( $ee_menu_slugs[$this->_current_page] ) ) && !defined( 'DOING_AJAX') ) return FALSE;
502
503
504
		// 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
505
		if ( isset( $this->_req_data['action2'] ) && $this->_req_data['action'] == -1 ) {
506
			$this->_req_data['action'] = ! empty( $this->_req_data['action2'] ) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
507
		}
508
		// then set blank or -1 action values to 'default'
509
		$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';
510
511
		//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.
512
		$this->_req_action = $this->_req_action == 'default' && isset( $this->_req_data['route'] ) ? $this->_req_data['route'] : $this->_req_action;
513
514
		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
515
		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
516
517
		$this->_current_view = $this->_req_action;
518
		$this->_req_nonce = $this->_req_action . '_nonce';
519
		$this->_define_page_props();
520
521
		$this->_current_page_view_url = add_query_arg( array( 'page' => $this->_current_page, 'action' => $this->_current_view ),  $this->_admin_base_url );
522
523
		//default things
524
		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box' );
525
526
		//set page configs
527
		$this->_set_page_routes();
528
		$this->_set_page_config();
529
530
		//let's include any referrer data in our default_query_args for this route for "stickiness".
531
		if ( isset( $this->_req_data['wp_referer'] ) ) {
532
			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
533
		}
534
535
		//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
536
		if ( method_exists( $this, '_extend_page_config' ) )
537
			$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...
538
539
		//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.
540
		if ( method_exists( $this, '_extend_page_config_for_cpt' ) )
541
			$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...
542
543
		//filter routes and page_config so addons can add their stuff. Filtering done per class
544
		$this->_page_routes = apply_filters( 'FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this );
545
		$this->_page_config = apply_filters( 'FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this );
546
547
548
		//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
549
		if ( method_exists( $this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view ) ) {
550
			add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view ), 10, 2 );
551
		}
552
553
554
		//next route only if routing enabled
555
		if ( $this->_routing && !defined('DOING_AJAX') ) {
556
557
			$this->_verify_routes();
558
559
			//next let's just check user_access and kill if no access
560
			$this->check_user_access();
561
562
			if ( $this->_is_UI_request ) {
563
				//admin_init stuff - global, all views for this page class, specific view
564
				add_action( 'admin_init', array( $this, 'admin_init' ), 10 );
565
				if ( method_exists( $this, 'admin_init_' . $this->_current_view )) {
566
					add_action( 'admin_init', array( $this, 'admin_init_' . $this->_current_view ), 15 );
567
				}
568
569
			} else {
570
				//hijack regular WP loading and route admin request immediately
571
				@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...
572
				$this->route_admin_request();
573
			}
574
		}
575
	}
576
577
578
579
580
581
	/**
582
	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
583
	 *
584
	 * @access private
585
	 * @return void
586
	 */
587
	private function _do_other_page_hooks() {
588
		$registered_pages = apply_filters( 'FHEE_do_other_page_hooks_' . $this->page_slug, array() );
589
590
		foreach ( $registered_pages as $page ) {
591
592
			//now let's setup the file name and class that should be present
593
			$classname = str_replace('.class.php', '', $page);
594
595
			//autoloaders should take care of loading file
596 View Code Duplication
			if ( !class_exists( $classname ) ) {
597
				$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...
598
				$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 );
599
				throw new EE_Error( implode( '||', $error_msg ));
600
			}
601
602
			$a = new ReflectionClass($classname);
603
604
			//notice we are passing the instance of this class to the hook object.
605
			$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...
606
		}
607
	}
608
609
610
611
	public function load_page_dependencies() {
612
		try {
613
			$this->_load_page_dependencies();
614
		} catch ( EE_Error $e ) {
615
			$e->get_error();
616
		}
617
	}
618
619
620
621
	/**
622
	 * load_page_dependencies
623
	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
624
	 * @access public
625
	 * @return void
626
	 */
627
	protected function _load_page_dependencies() {
628
		//let's set the current_screen and screen options to override what WP set
629
		$this->_current_screen = get_current_screen();
630
631
		//load admin_notices - global, page class, and view specific
632
		add_action( 'admin_notices', array( $this, 'admin_notices_global'), 5 );
633
		add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 );
634
		if ( method_exists( $this, 'admin_notices_' . $this->_current_view ) ) {
635
			add_action( 'admin_notices', array( $this, 'admin_notices_' . $this->_current_view ), 15 );
636
		}
637
638
		//load network admin_notices - global, page class, and view specific
639
		add_action( 'network_admin_notices', array( $this, 'network_admin_notices_global'), 5 );
640
		if ( method_exists( $this, 'network_admin_notices_' . $this->_current_view ) ) {
641
			add_action( 'network_admin_notices', array( $this, 'network_admin_notices_' . $this->_current_view ) );
642
		}
643
644
		//this will save any per_page screen options if they are present
645
		$this->_set_per_page_screen_options();
646
647
		//setup list table properties
648
		$this->_set_list_table();
649
650
		// 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.
651
		$this->_add_registered_meta_boxes();
652
		$this->_add_screen_columns();
653
654
		//add screen options - global, page child class, and view specific
655
		$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...
656
		$this->_add_screen_options();
657
		if ( method_exists( $this, '_add_screen_options_' . $this->_current_view ) )
658
			call_user_func( array( $this, '_add_screen_options_' . $this->_current_view ) );
659
660
661
		//add help tab(s) and tours- set via page_config and qtips.
662
		$this->_add_help_tour();
663
		$this->_add_help_tabs();
664
		$this->_add_qtips();
665
666
		//add feature_pointers - global, page child class, and view specific
667
		$this->_add_feature_pointers();
668
		$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...
669
		if ( method_exists( $this, '_add_feature_pointer_' . $this->_current_view ) )
670
			call_user_func( array( $this, '_add_feature_pointer_' . $this->_current_view ) );
671
672
		//enqueue scripts/styles - global, page class, and view specific
673
		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5 );
674
		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10 );
675
		if ( method_exists( $this, 'load_scripts_styles_' . $this->_current_view ) )
676
			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view ), 15 );
677
678
		add_action('admin_enqueue_scripts', array( $this, 'admin_footer_scripts_eei18n_js_strings' ), 100 );
679
680
		//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
681
		add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts_global' ), 99 );
682
		add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts' ), 100 );
683
		if ( method_exists( $this, 'admin_footer_scripts_' . $this->_current_view ) )
684
			add_action('admin_print_footer_scripts', array( $this, 'admin_footer_scripts_' . $this->_current_view ), 101 );
685
686
		//admin footer scripts
687
		add_action('admin_footer', array( $this, 'admin_footer_global' ), 99 );
688
		add_action('admin_footer', array( $this, 'admin_footer'), 100 );
689
		if ( method_exists( $this, 'admin_footer_' . $this->_current_view ) )
690
			add_action('admin_footer', array( $this, 'admin_footer_' . $this->_current_view ), 101 );
691
692
693
		do_action( 'FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug );
694
		//targeted hook
695
		do_action( 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action );
696
697
	}
698
699
700
701
702
703
	/**
704
	 * _set_defaults
705
	 * This sets some global defaults for class properties.
706
	 */
707
	private function _set_defaults() {
708
		$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...
709
710
		$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...
711
712
		$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...
713
714
		//init template args
715
		$this->_template_args = array(
716
			'admin_page_header' => '',
717
			'admin_page_content' => '',
718
			'post_body_content' => '',
719
			'before_list_table' => '',
720
			'after_list_table' => ''
721
		);
722
	}
723
724
725
726
727
	/**
728
	 * route_admin_request
729
	 *
730
	 * @see _route_admin_request()
731
	 * @access public
732
	 * @return void|exception error
733
	 */
734
	public function route_admin_request() {
735
		try {
736
			$this->_route_admin_request();
737
		} catch ( EE_Error $e ) {
738
			$e->get_error();
739
		}
740
	}
741
742
743
744
	public function set_wp_page_slug($wp_page_slug) {
745
		$this->_wp_page_slug = $wp_page_slug;
746
747
		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
748
		if ( is_network_admin() ) {
749
			$this->_wp_page_slug .= '-network';
750
		}
751
	}
752
753
	/**
754
	 * _verify_routes
755
	 * 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.
756
	 *
757
	 * @access protected
758
	 * @return void
759
	 */
760
	protected function _verify_routes() {
761
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
762
763
		if ( !$this->_current_page && !defined( 'DOING_AJAX')) return FALSE;
764
765
		$this->_route = FALSE;
766
		$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...
767
		$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...
768
769
		// check that the page_routes array is not empty
770
		if ( empty( $this->_page_routes )) {
771
			// user error msg
772
			$error_msg = sprintf( __('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title );
773
			// developer error msg
774
			$error_msg .=  '||' . $error_msg . __( ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso' );
775
			throw new EE_Error( $error_msg );
776
		}
777
778
		// and that the requested page route exists
779
		if ( array_key_exists( $this->_req_action, $this->_page_routes )) {
780
			$this->_route = $this->_page_routes[ $this->_req_action ];
781
			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
782 View Code Duplication
		} else {
783
			// user error msg
784
			$error_msg =  sprintf( __( 'The requested page route does not exist for the %s admin page.', 'event_espresso' ), $this->_admin_page_title );
785
			// developer error msg
786
			$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 );
787
			throw new EE_Error( $error_msg );
788
		}
789
790
		// and that a default route exists
791
		if ( ! array_key_exists( 'default', $this->_page_routes )) {
792
			// user error msg
793
			$error_msg = sprintf( __( 'A default page route has not been set for the % admin page.', 'event_espresso' ), $this->_admin_page_title );
794
			// developer error msg
795
			$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' );
796
			throw new EE_Error( $error_msg );
797
		}
798
799
800
		//first lets' catch if the UI request has EVER been set.
801
		if ( $this->_is_UI_request === NULL ) {
802
			//lets set if this is a UI request or not.
803
			$this->_is_UI_request = ( ! isset( $this->_req_data['noheader'] ) || $this->_req_data['noheader'] !== TRUE ) ? TRUE : FALSE;
804
805
806
			//wait a minute... we might have a noheader in the route array
807
			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader'] ) && $this->_route['noheader'] ? FALSE : $this->_is_UI_request;
808
		}
809
810
		$this->_set_current_labels();
811
812
	}
813
814
815
816
817
	/**
818
	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
819
	 * @param  string $route the route name we're verifying
820
	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
821
	 */
822
	protected function _verify_route( $route ) {
823
		if ( array_key_exists( $this->_req_action, $this->_page_routes )) {
824
			return true;
825 View Code Duplication
		} else {
826
			// user error msg
827
			$error_msg =  sprintf( __( 'The given page route does not exist for the %s admin page.', 'event_espresso' ), $this->_admin_page_title );
828
			// developer error msg
829
			$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 );
830
			throw new EE_Error( $error_msg );
831
		}
832
	}
833
834
835
836
837
	/**
838
	 * perform nonce verification
839
	 * 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!)
840
	 * @param  string $nonce     The nonce sent
841
	 * @param  string $nonce_ref The nonce reference string (name0)
842
	 * @return mixed (bool|die)
843
	 */
844
	protected function _verify_nonce( $nonce, $nonce_ref ) {
845
		// verify nonce against expected value
846
		if ( ! wp_verify_nonce( $nonce, $nonce_ref) ) {
847
			// these are not the droids you are looking for !!!
848
			$msg = sprintf(__('%sNonce Fail.%s' , 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>' );
849
			if ( WP_DEBUG ) {
850
				$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__  );
851
			}
852
			if ( ! defined( 'DOING_AJAX' )) {
853
				wp_die( $msg );
854
			} else {
855
				EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
856
				$this->_return_json();
857
			}
858
		}
859
	}
860
861
862
863
864
	/**
865
	 * _route_admin_request()
866
	 * 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.
867
	 * Translation:  Checks if the requested action is listed in the page routes and then will try to load the corresponding method.
868
	 *
869
	 * @access protected
870
	 * @return void
871
	 */
872
	protected function _route_admin_request() {
873
		if (  ! $this->_is_UI_request )
874
			$this->_verify_routes();
875
876
		$nonce_check = isset( $this->_route_config['require_nonce'] ) ? $this->_route_config['require_nonce'] : TRUE;
877
878 View Code Duplication
		if ( $this->_req_action != 'default' && $nonce_check ) {
879
			// set nonce from post data
880
			$nonce = isset($this->_req_data[ $this->_req_nonce  ]) ? sanitize_text_field( $this->_req_data[ $this->_req_nonce  ] ) : '';
881
			$this->_verify_nonce( $nonce, $this->_req_nonce );
882
		}
883
		//set the nav_tabs array but ONLY if this is  UI_request
884
		if ( $this->_is_UI_request )
885
			$this->_set_nav_tabs();
886
887
		// grab callback function
888
		$func = is_array( $this->_route ) ? $this->_route['func'] : $this->_route;
889
890
		// check if callback has args
891
		$args = is_array( $this->_route ) && isset( $this->_route['args'] ) ? $this->_route['args'] : array();
892
893
		$error_msg = '';
894
895
		//action right before calling route (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
896
		if ( !did_action('AHEE__EE_Admin_Page__route_admin_request')) {
897
			do_action( 'AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this );
898
		}
899
900
		//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).
901
		$_SERVER['REQUEST_URI'] = remove_query_arg( '_wp_http_referer', wp_unslash( $_SERVER['REQUEST_URI'] ) );
902
903
		if ( ! empty( $func )) {
904
			$base_call = $addon_call = FALSE;
905
			//try to access page route via this class
906
			if ( ! is_array( $func ) && method_exists( $this, $func ) && ( $base_call = call_user_func_array( array( $this, &$func  ), $args ) ) === FALSE ) {
907
				// user error msg
908
				$error_msg =  __( 'An error occurred. The  requested page route could not be found.', 'event_espresso' );
909
				// developer error msg
910
				$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 );
911
			}
912
913
			//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)
914
			$args['admin_page_object'] = $this; //send along this admin page object for access by addons.
915
916
			if ( $base_call === FALSE && ( $addon_call = call_user_func_array( $func, $args ) )=== FALSE ) {
917
				$error_msg = __('An error occurred. The requested page route could not be found', 'event_espresso' );
918
				$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 );
919
			}
920
921
922
			if ( !empty( $error_msg ) && $base_call === FALSE && $addon_call === FALSE )
923
				throw new EE_Error( $error_msg );
924
		}
925
926
		//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.
927
		//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.
928
		if ( $this->_is_UI_request === FALSE && is_array( $this->_route) && ! empty( $this->_route['headers_sent_route'] ) ) {
929
			$this->_reset_routing_properties( $this->_route['headers_sent_route'] );
930
		}
931
	}
932
933
934
935
936
	/**
937
	 * This method just allows the resetting of page properties in the case where a no headers
938
	 * route redirects to a headers route in its route config.
939
	 *
940
	 * @since   4.3.0
941
	 *
942
	 * @param  string    $new_route   New (non header) route to redirect to.
943
	 * @return   void
944
	 */
945
	protected function _reset_routing_properties( $new_route ) {
946
		$this->_is_UI_request = TRUE;
947
		//now we set the current route to whatever the headers_sent_route is set at
948
		$this->_req_data['action'] = $new_route;
949
		//rerun page setup
950
		$this->_page_setup();
951
	}
952
953
954
955
956
	/**
957
	 * _add_query_arg
958
	 * adds nonce to array of arguments then calls WP add_query_arg function
959
	 *(internally just uses EEH_URL's function with the same name)
960
	 * 	@access public
961
	 *	@param array $args
962
	 *	@param string $url
963
	 *	@param bool $sticky if true, then the existing Request params will be appended to the generated
964
	 *	                    		url in an associative array indexed by the key 'wp_referer';
965
	 *	                    		Example usage:
966
	 *
967
	 *	                    		If the current page is:
968
	 *	                    		http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
969
	 *	                    		&action=default&event_id=20&month_range=March%202015
970
	 *	                    		&_wpnonce=5467821
971
	 *
972
	 *	                    		and you call:
973
	 *
974
	 *	                    		EE_Admin_Page::add_query_args_and_nonce(
975
	 *	                    			array(
976
	 *	                    				'action' => 'resend_something',
977
	 *	                    				'page=>espresso_registrations'
978
	 *	                    				),
979
	 *	                    			$some_url,
980
	 *	                    			true
981
	 *	                    		 );
982
	 *
983
	 *	                    		It will produce a url in this structure:
984
	 *
985
	 *	                      		http://{$some_url}/?page=espresso_registrations&action=resend_something
986
	 *	                        	&wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
987
	 *	                        	month_range]=March%202015
988
	 * @param   bool    $exclude_nonce  If true, the the nonce will be excluded from the generated nonce.
989
	 * 	@return string
990
	 */
991
	public static function add_query_args_and_nonce( $args = array(), $url = false, $sticky = false, $exclude_nonce = false ) {
992
		EE_Registry::instance()->load_helper('URL');
993
994
		//if there is a _wp_http_referer include the values from the request but only if sticky = true
995
		if ( $sticky ) {
996
			$request = $_REQUEST;
997
			unset( $request['_wp_http_referer'] );
998
			unset( $request['wp_referer'] );
999
			foreach ( $request as $key => $value ) {
1000
				//do not add nonces
1001
				if ( strpos( $key, 'nonce' ) !== false ) {
1002
					continue;
1003
				}
1004
				$args['wp_referer[' . $key . ']'] = $value;
1005
			}
1006
		}
1007
1008
		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 991 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...
1009
	}
1010
1011
1012
1013
1014
	/**
1015
	 * This returns a generated link that will load the related help tab.
1016
	 *
1017
	 *
1018
	 * @param  string $help_tab_id the id for the connected help tab
1019
	 * @param  string $icon_style (optional) include css class for the style you want to use for the help icon.
1020
	 * @param  string $help_text (optional) send help text you want to use for the link if default not to be used
1021
	 * @uses EEH_Template::get_help_tab_link()
1022
	 * @return string              generated link
1023
	 */
1024
	protected function _get_help_tab_link( $help_tab_id, $icon_style = FALSE, $help_text = FALSE ) {
1025
		return EEH_Template::get_help_tab_link( $help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text );
1026
	}
1027
1028
1029
1030
1031
	/**
1032
	 * _add_help_tabs
1033
	 *
1034
	 * Note child classes define their help tabs within the page_config array.
1035
	 * @link http://codex.wordpress.org/Function_Reference/add_help_tab
1036
	 *
1037
	 * @access protected
1038
	 * @return void
1039
	 */
1040
	protected function _add_help_tabs() {
1041
		$tour_buttons = '';
1042
		if ( isset( $this->_page_config[$this->_req_action] ) ) {
1043
			$config = $this->_page_config[$this->_req_action];
1044
1045
			//is there a help tour for the current route?  if there is let's setup the tour buttons
1046
			if ( isset( $this->_help_tour[$this->_req_action]) ) {
1047
				$tb = array();
1048
				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1049
				foreach ( $this->_help_tour['tours'] as $tour ) {
1050
					//if this is the end tour then we don't need to setup a button
1051
					if ( $tour instanceof EE_Help_Tour_final_stop )
1052
						continue;
1053
					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1054
				}
1055
				$tour_buttons .= implode('<br />', $tb);
1056
				$tour_buttons .= '</div></div>';
1057
			}
1058
1059
			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1060
			if ( is_array( $config ) && isset( $config['help_sidebar'] ) ) {
1061
				//check that the callback given is valid
1062
				if ( !method_exists($this, $config['help_sidebar'] ) )
1063
					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) ) );
1064
1065
				$content = apply_filters( 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func( array( $this, $config['help_sidebar'] ) ) );
1066
1067
				$content .= $tour_buttons; //add help tour buttons.
1068
1069
				//do we have any help tours setup?  Cause if we do we want to add the buttons
1070
				$this->_current_screen->set_help_sidebar($content);
1071
			}
1072
1073
			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1074
			if ( !isset( $config['help_sidebar'] ) && !empty( $tour_buttons ) ) {
1075
				$this->_current_screen->set_help_sidebar($tour_buttons);
1076
			}
1077
1078
			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1079
			if ( !isset( $config['help_tabs'] ) && !empty($tour_buttons) ) {
1080
				$_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...
1081
				$_ht['title'] = __('Help Tours', 'event_espresso');
1082
				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1083
				$this->_current_screen->add_help_tab($_ht);
1084
				}/**/
1085
1086
1087
			if ( !isset( $config['help_tabs'] ) ) return; //no help tabs for this route
1088
1089
			foreach ( (array) $config['help_tabs'] as $tab_id => $cfg ) {
1090
				//we're here so there ARE help tabs!
1091
1092
				//make sure we've got what we need
1093
				if ( !isset( $cfg['title'] ) )
1094
					throw new EE_Error( __('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso') );
1095
1096
1097
				if ( !isset($cfg['filename']) && !isset( $cfg['callback'] ) && !isset( $cfg['content'] ) )
1098
					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') );
1099
1100
1101
1102
				//first priority goes to content.
1103
				if ( !empty($cfg['content'] ) ) {
1104
					$content = !empty($cfg['content']) ? $cfg['content'] : NULL;
1105
1106
				//second priority goes to filename
1107
				} else if ( !empty($cfg['filename'] ) ) {
1108
					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1109
1110
1111
					//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)
1112
					$file_path = !is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1113
1114
					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1115 View Code Duplication
					if ( !is_readable($file_path) && !isset($cfg['callback']) ) {
1116
						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__ );
1117
						return;
1118
					}
1119
					$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...
1120
					$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...
1121
				} else {
1122
					$content = '';
1123
				}
1124
1125
1126
				//check if callback is valid
1127
				if ( empty($content) && ( !isset($cfg['callback']) || !method_exists( $this, $cfg['callback'] ) ) ) {
1128
					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__ );
1129
					return;
1130
				}
1131
1132
				//setup config array for help tab method
1133
				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1134
				$_ht = array(
1135
					'id' => $id,
1136
					'title' => $cfg['title'],
1137
					'callback' => isset( $cfg['callback'] ) && empty($content) ? array( $this, $cfg['callback'] ) : NULL,
1138
					'content' => $content
1139
					);
1140
1141
				$this->_current_screen->add_help_tab( $_ht );
1142
			}
1143
		}
1144
	}
1145
1146
1147
1148
	/**
1149
	 * 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
1150
	 *
1151
	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1152
	 * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1153
	 * @access protected
1154
	 * @return void
1155
	 */
1156
	protected function _add_help_tour() {
1157
		$tours = array();
1158
		$this->_help_tour = array();
1159
1160
		//exit early if help tours are turned off globally
1161
		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || ( defined( 'EE_DISABLE_HELP_TOURS' ) && EE_DISABLE_HELP_TOURS ) )
1162
			return;
1163
1164
		//loop through _page_config to find any help_tour defined
1165
		foreach ( $this->_page_config as $route => $config ) {
1166
			//we're only going to set things up for this route
1167
			if ( $route !== $this->_req_action )
1168
				continue;
1169
1170
			if ( isset( $config['help_tour'] ) ) {
1171
1172
				foreach( $config['help_tour'] as $tour ) {
1173
					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1174
					//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
1175
					$file_path = !is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1176
1177
					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1178
					if ( !is_readable($file_path) ) {
1179
						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__ );
1180
						return;
1181
					}
1182
1183
					require_once $file_path;
1184 View Code Duplication
					if ( !class_exists( $tour ) ) {
1185
						$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...
1186
						$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) );
1187
						throw new EE_Error( implode( '||', $error_msg ));
1188
					}
1189
					$a = new ReflectionClass($tour);
1190
					$tour_obj = $a->newInstance($this->_is_caf);
1191
1192
					$tours[] = $tour_obj;
1193
					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator( $tour_obj );
1194
				}
1195
1196
				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1197
				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1198
				$tours[] = $end_stop_tour;
1199
				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator( $end_stop_tour );
1200
			}
1201
		}
1202
1203
		if ( !empty( $tours ) )
1204
			$this->_help_tour['tours'] = $tours;
1205
1206
		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1207
	}
1208
1209
1210
1211
1212
	/**
1213
	 * This simply sets up any qtips that have been defined in the page config
1214
	 *
1215
	 * @access protected
1216
	 * @return void
1217
	 */
1218
	protected function _add_qtips() {
1219
		if ( isset( $this->_route_config['qtips'] ) ) {
1220
			$qtips = (array) $this->_route_config['qtips'];
1221
			//load qtip loader
1222
			EE_Registry::instance()->load_helper('Qtip_Loader', array(), TRUE);
1223
			$path = array(
1224
				$this->_get_dir() . '/qtips/',
1225
				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/'
1226
				);
1227
			EEH_Qtip_Loader::instance()->register($qtips, $path);
1228
		}
1229
	}
1230
1231
1232
1233
1234
	/**
1235
	 * _set_nav_tabs
1236
	 * 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.
1237
	 *
1238
	 * @access protected
1239
	 * @return void
1240
	 */
1241
	protected function _set_nav_tabs() {
1242
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1243
		$i = 0;
1244
		foreach ( $this->_page_config as $slug => $config ) {
1245
			if ( !is_array( $config ) || ( is_array($config) && (isset($config['nav']) && !$config['nav'] ) || !isset($config['nav'] ) ) )
1246
				continue; //no nav tab for this config
1247
1248
			//check for persistent flag
1249
			if ( isset( $config['nav']['persistent']) && !$config['nav']['persistent'] && $slug !== $this->_req_action )
1250
				continue; //nav tab is only to appear when route requested.
1251
1252
			if ( ! $this->check_user_access( $slug, TRUE ) )
1253
				continue; //no nav tab becasue current user does not have access.
1254
1255
			$css_class = isset( $config['css_class'] ) ? $config['css_class'] . ' ' : '';
1256
			$this->_nav_tabs[$slug] = array(
1257
				'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce( array( 'action'=>$slug ), $this->_admin_base_url ),
1258
				'link_text' => isset( $config['nav']['label'] ) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug ) ),
1259
				'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1260
				'order' => isset( $config['nav']['order'] ) ? $config['nav']['order'] : $i
1261
				);
1262
			$i++;
1263
		}
1264
1265
		//if $this->_nav_tabs is empty then lets set the default
1266
		if ( empty( $this->_nav_tabs ) ) {
1267
			$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...
1268
				'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...
1269
				'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...
1270
				'css_class' => 'nav-tab-active',
1271
				'order' => 10
1272
				);
1273
		}
1274
1275
		//now let's sort the tabs according to order
1276
		usort( $this->_nav_tabs, array($this, '_sort_nav_tabs' ));
1277
1278
	}
1279
1280
1281
1282
1283
1284
	/**
1285
	 * _set_current_labels
1286
	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1287
	 *
1288
	 * @access private
1289
	 * @return void
1290
	 */
1291
	private function _set_current_labels() {
1292
		if ( is_array($this->_route_config) && isset($this->_route_config['labels']) ) {
1293
			foreach ( $this->_route_config['labels'] as $label => $text ) {
1294
				if ( is_array($text) ) {
1295
					foreach ( $text as $sublabel => $subtext ) {
1296
						$this->_labels[$label][$sublabel] = $subtext;
1297
					}
1298
				} else {
1299
					$this->_labels[$label] = $text;
1300
				}
1301
			}
1302
		}
1303
	}
1304
1305
1306
1307
1308
1309
1310
	/**
1311
	 * 		verifies user access for this admin page
1312
	 * 		@param string $route_to_check if present then the capability for the route matching this string is checked.
1313
	 * 		@param bool   $verify_only Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1314
	*		@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...
1315
	*/
1316
	public function check_user_access( $route_to_check = '', $verify_only = FALSE ) {
1317
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1318
		$route_to_check = empty( $route_to_check ) ? $this->_req_action : $route_to_check;
1319
		$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;
1320
1321
		if ( empty( $capability ) && empty( $route_to_check )  ) {
1322
			$capability = is_array( $this->_route ) && empty( $this->_route['capability'] ) ? 'manage_options' : $this->_route['capability'];
1323
		} else {
1324
			$capability = empty( $capability ) ? 'manage_options' : $capability;
1325
		}
1326
1327
		$id = is_array( $this->_route ) && ! empty( $this->_route['obj_id'] ) ? $this->_route['obj_id'] : 0;
1328
1329
		if (( ! function_exists( 'is_admin' ) || ! EE_Registry::instance()->CAP->current_user_can( $capability, $this->page_slug . '_' . $route_to_check, $id ) ) && ! defined( 'DOING_AJAX')) {
1330
			if ( $verify_only ) {
1331
				return FALSE;
1332
			} else {
1333
				wp_die( __('You do not have access to this route.', 'event_espresso' ) );
1334
			}
1335
		}
1336
		return TRUE;
1337
	}
1338
1339
1340
1341
1342
1343
1344
1345
	/**
1346
	 * admin_init_global
1347
	 * This runs all the code that we want executed within the WP admin_init hook.
1348
	 * This method executes for ALL EE Admin pages.
1349
	 *
1350
	 * @access public
1351
	 * @return void
1352
	 */
1353
	public function admin_init_global() {
1354
	}
1355
1356
1357
1358
1359
1360
1361
	/**
1362
	 * wp_loaded_global
1363
	 * 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
1364
	 *
1365
	 * @access public
1366
	 * @return void
1367
	 */
1368
	public function wp_loaded() {}
1369
1370
1371
1372
1373
1374
1375
	/**
1376
	 * admin_notices
1377
	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1378
	 *
1379
	 * @access public
1380
	 * @return void
1381
	 */
1382
	public function admin_notices_global() {
1383
		$this->_display_no_javascript_warning();
1384
		$this->_display_espresso_notices();
1385
	}
1386
1387
1388
1389
1390
	public function network_admin_notices_global() {
1391
		$this->_display_no_javascript_warning();
1392
		$this->_display_espresso_notices();
1393
	}
1394
1395
1396
1397
1398
	/**
1399
	 * admin_footer_scripts_global
1400
	 * 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.
1401
	 *
1402
	 * @access public
1403
	 * @return void
1404
	 */
1405
	public function admin_footer_scripts_global() {
1406
		$this->_add_admin_page_ajax_loading_img();
1407
		$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...
1408
1409
		//if metaboxes are present we need to add the nonce field
1410
		if ( ( isset($this->_route_config['metaboxes']) || ( isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'] ) || isset($this->_route_config['list_table']) ) ) {
1411
			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1412
			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1413
		}
1414
	}
1415
1416
1417
1418
1419
1420
	/**
1421
	 * admin_footer_global
1422
	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1423
	 *
1424
	 * @access  public
1425
	 * @return  void
1426
	 */
1427
	public function admin_footer_global() {
1428
		//dialog container for dialog helper
1429
		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1430
		$d_cont .= '<div class="ee-notices"></div>';
1431
		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1432
		$d_cont .= '</div>';
1433
		echo $d_cont;
1434
1435
		//help tour stuff?
1436
		if ( isset( $this->_help_tour[$this->_req_action] ) ) {
1437
			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1438
		}
1439
1440
		//current set timezone for timezone js
1441
		EE_Registry::instance()->load_helper('DTT_Helper');
1442
		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1443
	}
1444
1445
1446
	/**
1447
	 * 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.
1448
	 *
1449
	 * For child classes:
1450
	 * 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.
1451
	 * 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".
1452
	 * In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format
1453
	 * array(
1454
	 * 	'help_trigger_id' => array(
1455
	 * 		'title' => __('localized title for popup', 'event_espresso'),
1456
	 * 		'content' => __('localized content for popup', 'event_espresso')
1457
	 * 	)
1458
	 * );
1459
	 *
1460
	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1461
	 *
1462
	 *
1463
	 * @access protected
1464
	 * @return string content
1465
	 */
1466
	protected function _set_help_popup_content( $help_array = array(), $display = FALSE ) {
1467
		$content = '';
1468
1469
		$help_array = empty( $help_array ) ? $this->_get_help_content() : $help_array;
1470
		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1471
1472
1473
		//loop through the array and setup content
1474
		foreach ( $help_array as $trigger => $help ) {
1475
			//make sure the array is setup properly
1476
			if ( !isset($help['title']) || !isset($help['content'] ) ) {
1477
				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') );
1478
			}
1479
1480
			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1481
			$template_args = array(
1482
				'help_popup_id' => $trigger,
1483
				'help_popup_title' => $help['title'],
1484
				'help_popup_content' => $help['content']
1485
				);
1486
1487
			$content .= EEH_Template::display_template( $template_path, $template_args, TRUE );
1488
		}
1489
1490
		if ( $display )
1491
			echo $content;
1492
		else
1493
			return $content;
1494
	}
1495
1496
1497
1498
1499
	/**
1500
	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1501
	 *
1502
	 * @access private
1503
	 * @return array properly formatted array for help popup content
1504
	 */
1505
	private function _get_help_content() {
1506
		//what is the method we're looking for?
1507
		$method_name = '_help_popup_content_' . $this->_req_action;
1508
1509
		//if method doesn't exist let's get out.
1510
		if ( !method_exists( $this, $method_name ) )
1511
			return array();
1512
1513
		//k we're good to go let's retrieve the help array
1514
		$help_array = call_user_func( array( $this, $method_name ) );
1515
1516
		//make sure we've got an array!
1517
		if ( !is_array($help_array) ) {
1518
			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' ) );
1519
		}
1520
1521
		return $help_array;
1522
	}
1523
1524
1525
1526
	/**
1527
	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1528
	 *
1529
	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1530
	 *
1531
	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1532
	 *
1533
	 *
1534
	 * @access protected
1535
	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1536
	 * @param boolean $display    if false then we return the trigger string
1537
	 * @param array $dimensions an array of dimensions for the box (array(h,w))
1538
	 * @return string
1539
	 */
1540
	protected function _set_help_trigger( $trigger_id, $display = TRUE, $dimensions = array( '400', '640') ) {
1541
1542
		if ( defined('DOING_AJAX') ) return;
1543
1544
		//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
1545
		$help_array = $this->_get_help_content();
1546
		$help_content = '';
1547
1548
		if ( empty( $help_array ) || !isset( $help_array[$trigger_id] ) ) {
1549
			$help_array[$trigger_id] = array(
1550
				'title' => __('Missing Content', 'event_espresso'),
1551
				'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')
1552
				);
1553
			$help_content = $this->_set_help_popup_content( $help_array, FALSE );
1554
		}
1555
1556
		//let's setup the trigger
1557
		$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>';
1558
		$content = $content . $help_content;
1559
1560
		if ( $display )
1561
			echo $content;
1562
		else
1563
			return $content;
1564
	}
1565
1566
1567
	/**
1568
	 * _add_global_screen_options
1569
	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1570
	 * This particular method will add_screen_options on ALL EE_Admin Pages
1571
	 * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1572
	 * see also WP_Screen object documents...
1573
	 * @link http://codex.wordpress.org/Class_Reference/WP_Screen
1574
	 *
1575
	 * @abstract
1576
	 * @access private
1577
	 * @return void
1578
	 */
1579
	private function _add_global_screen_options() {}
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
	/**
1590
	 * _add_global_feature_pointers
1591
	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1592
	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1593
	 * Note: this is just a placeholder for now.  Implementation will come down the road
1594
	 * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1595
	 * @link http://eamann.com/tech/wordpress-portland/
1596
	 *
1597
	 * @abstract
1598
	 * @access protected
1599
	 * @return void
1600
	 */
1601
	private function _add_global_feature_pointers() {}
1602
1603
1604
1605
1606
1607
1608
	/**
1609
	 * load_global_scripts_styles
1610
	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1611
	 *
1612
	 * @return void
1613
	 */
1614
	public function load_global_scripts_styles() {
1615
		/** STYLES **/
1616
		// add debugging styles
1617
		if ( WP_DEBUG ) {
1618
			add_action('admin_head', array( $this, 'add_xdebug_style' ));
1619
		}
1620
1621
		//register all styles
1622
		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 );
1623
		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1624
		//helpers styles
1625
		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION );
1626
		//enqueue global styles
1627
		wp_enqueue_style('ee-admin-css');
1628
1629
1630
		/** SCRIPTS **/
1631
1632
		//register all scripts
1633
		wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1634
		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, TRUE );
1635
		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 );
1636
1637
		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 );
1638
		// register jQuery Validate - see /includes/functions/wp_hooks.php
1639
		add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1640
		add_filter('FHEE_load_joyride', '__return_true');
1641
1642
		//script for sorting tables
1643
		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);
1644
		//script for parsing uri's
1645
		wp_register_script( 'ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, TRUE );
1646
		//and parsing associative serialized form elements
1647
		wp_register_script( 'ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1648
		//helpers scripts
1649
		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1650
		wp_register_script( 'ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, TRUE );
1651
		wp_register_script( 'ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, TRUE );
1652
		wp_register_script( 'ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon','ee-moment'), EVENT_ESPRESSO_VERSION, TRUE );
1653
1654
		//google charts
1655
		wp_register_script( 'google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false );
1656
1657
		//enqueue global scripts
1658
1659
		//taking care of metaboxes
1660
		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...
1661
			wp_enqueue_script('dashboard');
1662
		}
1663
1664
		//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
1665
		if ( ! isset( $this->_route_config['has_help_popups']) || ( isset( $this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'] ) ) {
1666
			wp_enqueue_script('ee_admin_js');
1667
			wp_enqueue_style('ee-admin-css');
1668
		}
1669
1670
1671
		//localize script for ajax lazy loading
1672
		$lazy_loader_container_ids = apply_filters( 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content') );
1673
		wp_localize_script( 'ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1674
1675
1676
		/**
1677
		 * help tour stuff
1678
		 */
1679
		if ( !empty( $this->_help_tour ) ) {
1680
1681
			//register the js for kicking things off
1682
			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, TRUE );
1683
1684
			//setup tours for the js tour object
1685
			foreach ( $this->_help_tour['tours'] as $tour ) {
1686
				$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...
1687
					'id' => $tour->get_slug(),
1688
					'options' => $tour->get_options()
1689
					);
1690
			}
1691
1692
			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...
1693
1694
			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1695
		}
1696
	}
1697
1698
1699
1700
1701
	/**
1702
	*		admin_footer_scripts_eei18n_js_strings
1703
	*
1704
	*		@access 		public
1705
	*		@return 		void
1706
	*/
1707
	public function admin_footer_scripts_eei18n_js_strings() {
1708
1709
		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1710
		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' );
1711
1712
		EE_Registry::$i18n_js_strings['January'] = __( 'January', 'event_espresso' );
1713
		EE_Registry::$i18n_js_strings['February'] = __( 'February', 'event_espresso' );
1714
		EE_Registry::$i18n_js_strings['March'] = __( 'March', 'event_espresso' );
1715
		EE_Registry::$i18n_js_strings['April'] = __( 'April', 'event_espresso' );
1716
		EE_Registry::$i18n_js_strings['May'] = __( 'May', 'event_espresso' );
1717
		EE_Registry::$i18n_js_strings['June'] = __( 'June', 'event_espresso' );
1718
		EE_Registry::$i18n_js_strings['July'] = __( 'July', 'event_espresso' );
1719
		EE_Registry::$i18n_js_strings['August'] = __( 'August', 'event_espresso' );
1720
		EE_Registry::$i18n_js_strings['September'] = __( 'September', 'event_espresso' );
1721
		EE_Registry::$i18n_js_strings['October'] = __( 'October', 'event_espresso' );
1722
		EE_Registry::$i18n_js_strings['November'] = __( 'November', 'event_espresso' );
1723
		EE_Registry::$i18n_js_strings['December'] = __( 'December', 'event_espresso' );
1724
		EE_Registry::$i18n_js_strings['Jan'] = __( 'Jan', 'event_espresso' );
1725
		EE_Registry::$i18n_js_strings['Feb'] = __( 'Feb', 'event_espresso' );
1726
		EE_Registry::$i18n_js_strings['Mar'] = __( 'Mar', 'event_espresso' );
1727
		EE_Registry::$i18n_js_strings['Apr'] = __( 'Apr', 'event_espresso' );
1728
		EE_Registry::$i18n_js_strings['May'] = __( 'May', 'event_espresso' );
1729
		EE_Registry::$i18n_js_strings['Jun'] = __( 'Jun', 'event_espresso' );
1730
		EE_Registry::$i18n_js_strings['Jul'] = __( 'Jul', 'event_espresso' );
1731
		EE_Registry::$i18n_js_strings['Aug'] = __( 'Aug', 'event_espresso' );
1732
		EE_Registry::$i18n_js_strings['Sep'] = __( 'Sep', 'event_espresso' );
1733
		EE_Registry::$i18n_js_strings['Oct'] = __( 'Oct', 'event_espresso' );
1734
		EE_Registry::$i18n_js_strings['Nov'] = __( 'Nov', 'event_espresso' );
1735
		EE_Registry::$i18n_js_strings['Dec'] = __( 'Dec', 'event_espresso' );
1736
1737
		EE_Registry::$i18n_js_strings['Sunday'] = __( 'Sunday', 'event_espresso' );
1738
		EE_Registry::$i18n_js_strings['Monday'] = __( 'Monday', 'event_espresso' );
1739
		EE_Registry::$i18n_js_strings['Tuesday'] = __( 'Tuesday', 'event_espresso' );
1740
		EE_Registry::$i18n_js_strings['Wednesday'] = __( 'Wednesday', 'event_espresso' );
1741
		EE_Registry::$i18n_js_strings['Thursday'] = __( 'Thursday', 'event_espresso' );
1742
		EE_Registry::$i18n_js_strings['Friday'] = __( 'Friday', 'event_espresso' );
1743
		EE_Registry::$i18n_js_strings['Saturday'] = __( 'Saturday', 'event_espresso' );
1744
		EE_Registry::$i18n_js_strings['Sun'] = __( 'Sun', 'event_espresso' );
1745
		EE_Registry::$i18n_js_strings['Mon'] = __( 'Mon', 'event_espresso' );
1746
		EE_Registry::$i18n_js_strings['Tue'] = __( 'Tue', 'event_espresso' );
1747
		EE_Registry::$i18n_js_strings['Wed'] = __( 'Wed', 'event_espresso' );
1748
		EE_Registry::$i18n_js_strings['Thu'] = __( 'Thu', 'event_espresso' );
1749
		EE_Registry::$i18n_js_strings['Fri'] = __( 'Fri', 'event_espresso' );
1750
		EE_Registry::$i18n_js_strings['Sat'] = __( 'Sat', 'event_espresso' );
1751
1752
		//setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1753
		//admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1754
		//espresso_core is listed as a dependency of ee_admin_js.
1755
		wp_localize_script( 'espresso_core', 'eei18n', EE_Registry::$i18n_js_strings );
1756
1757
	}
1758
1759
1760
1761
	/**
1762
	*		load enhanced xdebug styles for ppl with failing eyesight
1763
	*
1764
	*		@access 		public
1765
	*		@return 		void
1766
	*/
1767
	public function add_xdebug_style() {
1768
		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1769
	}
1770
1771
1772
	/************************/
1773
	/** LIST TABLE METHODS **/
1774
	/************************/
1775
1776
1777
1778
1779
1780
	/**
1781
	 * this sets up the list table if the current view requires it.
1782
	 *
1783
	 * @access protected
1784
	 * @return void
1785
	 */
1786
	protected function _set_list_table() {
1787
1788
		//first is this a list_table view?
1789
		if ( !isset($this->_route_config['list_table']) )
1790
			return; //not a list_table view so get out.
1791
1792
		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1793
1794
		if ( call_user_func( array( $this, '_set_list_table_views_' . $this->_req_action ) ) === FALSE ) {
1795
			//user error msg
1796
			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso' );
1797
			//developer error msg
1798
			$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 );
1799
			throw new EE_Error( $error_msg );
1800
		}
1801
1802
		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1803
		$this->_views = apply_filters( 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views );
1804
		$this->_views = apply_filters( 'FHEE_list_table_views_' . $this->page_slug, $this->_views );
1805
		$this->_views = apply_filters( 'FHEE_list_table_views', $this->_views );
1806
1807
		$this->_set_list_table_view();
1808
		$this->_set_list_table_object();
1809
1810
	}
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
	/**
1822
	 * 		set current view for List Table
1823
	*		@access public
1824
	*		@return array
1825
	*/
1826
	protected function _set_list_table_view() {
1827
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1828
1829
1830
		// looking at active items or dumpster diving ?
1831
		if ( ! isset( $this->_req_data['status'] ) || ! array_key_exists( $this->_req_data['status'], $this->_views )) {
1832
			$this->_view = isset( $this->_views['in_use'] ) ? 'in_use' : 'all';
1833
		} else {
1834
			$this->_view = sanitize_key( $this->_req_data['status'] );
1835
		}
1836
	}
1837
1838
1839
1840
	/**
1841
	 * _set_list_table_object
1842
	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1843
	 */
1844
	protected function _set_list_table_object() {
1845
		if ( isset($this->_route_config['list_table'] ) ) {
1846 View Code Duplication
			if ( !class_exists( $this->_route_config['list_table'] ) )
1847
				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) ) );
1848
			$a = new ReflectionClass($this->_route_config['list_table']);
1849
			$this->_list_table_object = $a->newInstance($this);
1850
		}
1851
	}
1852
1853
1854
1855
1856
1857
	/**
1858
	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1859
	 *
1860
	 * @param array $extra_query_args Optional. An array of extra query args to add to the generated
1861
	 *                                		          	urls.  The array should be indexed by the view it is being
1862
	 *                                		          	added to.
1863
	 *
1864
	 * @return array
1865
	 */
1866
	public function get_list_table_view_RLs( $extra_query_args = array() ) {
1867
1868
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1869
1870
		if ( empty( $this->_views )) {
1871
			$this->_views = array();
1872
		}
1873
1874
		// cycle thru views
1875
		foreach ( $this->_views as $key => $view ) {
1876
			$query_args = array();
1877
			// check for current view
1878
			$this->_views[ $key ]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1879
			$query_args['action'] = $this->_req_action;
1880
			$query_args[$this->_req_action.'_nonce'] = wp_create_nonce( $query_args['action'] . '_nonce' );
1881
			$query_args['status'] = $view['slug'];
1882
			//merge any other arguments sent in.
1883
			if ( isset( $extra_query_args[$view['slug']] ) ) {
1884
				$query_args = array_merge( $query_args, $extra_query_args[$view['slug']] );
1885
			}
1886
			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce( $query_args, $this->_admin_base_url );
1887
		}
1888
1889
		return $this->_views;
1890
	}
1891
1892
1893
1894
1895
	/**
1896
	 * _entries_per_page_dropdown
1897
	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1898
	 * @todo: Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1899
	 * @access protected
1900
	 * @param int $max_entries total number of rows in the table
1901
	 * @return string
1902
	*/
1903
	protected function _entries_per_page_dropdown( $max_entries = FALSE ) {
1904
1905
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1906
		$values = array( 10, 25, 50, 100 );
1907
		$per_page = ( ! empty( $this->_req_data['per_page'] )) ? absint( $this->_req_data['per_page'] ) : 10;
1908
1909
		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...
1910
			$values[] = $max_entries;
1911
			sort( $values );
1912
		}
1913
1914
		$entries_per_page_dropdown = '
1915
			<div id="entries-per-page-dv" class="alignleft actions">
1916
				<label class="hide-if-no-js">
1917
					Show
1918
					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1919
1920
		foreach ( $values as $value ) {
1921
			if ( $value < $max_entries ) {
1922
				$selected = $value == $per_page ?  ' selected="' . $per_page . '"' : '';
1923
				$entries_per_page_dropdown .= '
1924
						<option value="'.$value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1925
			}
1926
		}
1927
1928
		$selected = $max_entries == $per_page ?  ' selected="' . $per_page . '"' : '';
1929
		$entries_per_page_dropdown .= '
1930
						<option value="'.$max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1931
1932
		$entries_per_page_dropdown .= '
1933
					</select>
1934
					entries
1935
				</label>
1936
				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1937
			</div>
1938
		';
1939
		return $entries_per_page_dropdown;
1940
	}
1941
1942
1943
1944
1945
	/**
1946
	 * 		_set_search_attributes
1947
	*		@access 		protected
1948
	*		@return 		void
1949
	*/
1950
	public function _set_search_attributes() {
1951
		$this->_template_args['search']['btn_label'] = sprintf( __( 'Search %s', 'event_espresso' ), empty( $this->_search_btn_label ) ? $this->page_label : $this->_search_btn_label );
1952
		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1953
	}
1954
1955
	/*** END LIST TABLE METHODS **/
1956
	/*****************************/
1957
1958
1959
1960
1961
1962
	/**
1963
	 * 		_add_registered_metaboxes
1964
	 * 		this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1965
	 *
1966
	 * @link http://codex.wordpress.org/Function_Reference/add_meta_box
1967
	 * @access private
1968
	 * @return void
1969
	*/
1970
	private function _add_registered_meta_boxes() {
1971
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1972
1973
		//we only add meta boxes if the page_route calls for it
1974
		if ( is_array($this->_route_config) && isset( $this->_route_config['metaboxes'] ) && is_array($this->_route_config['metaboxes']) ) {
1975
1976
1977
			//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.
1978
			foreach ( $this->_route_config['metaboxes'] as $metabox_callback ) {
1979
				if ( call_user_func( array($this, &$metabox_callback) ) === FALSE ) {
1980
					// user error msg
1981
				$error_msg =  __( 'An error occurred. The  requested metabox could not be found.', 'event_espresso' );
1982
				// developer error msg
1983
				$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 );
1984
				throw new EE_Error( $error_msg );
1985
				}
1986
			}
1987
		}
1988
	}
1989
1990
1991
1992
1993
	/**
1994
	 * _add_screen_columns
1995
	 * 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.
1996
	 *
1997
	 * @access private
1998
	 * @return void
1999
	 */
2000
	private function _add_screen_columns() {
2001
		if ( is_array($this->_route_config) && isset( $this->_route_config['columns'] ) && is_array($this->_route_config['columns']) && count( $this->_route_config['columns'] == 2 ) ) {
2002
2003
			add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1] ) );
2004
			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2005
			$screen_id = $this->_current_screen->id;
2006
			$screen_columns = (int) get_user_option("screen_layout_$screen_id");
2007
			$total_columns = !empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
2008
			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2009
			$this->_template_args['current_page'] = $this->_wp_page_slug;
2010
			$this->_template_args['screen'] = $this->_current_screen;
2011
			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
2012
2013
			//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.
2014
			$this->_route_config['has_metaboxes'] = TRUE;
2015
		}
2016
	}
2017
2018
2019
2020
	/**********************************/
2021
	/** GLOBALLY AVAILABLE METABOXES **/
2022
2023
	/**
2024
	 * 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.
2025
	 */
2026
2027
	private function _espresso_news_post_box() {
2028
		$news_box_title = apply_filters( 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __( 'New @ Event Espresso', 'event_espresso' ) );
2029
		add_meta_box( 'espresso_news_post_box', $news_box_title, array(
2030
			$this,
2031
			'espresso_news_post_box'
2032
		), $this->_wp_page_slug, 'side' );
2033
	}
2034
2035
2036
	/**
2037
	 * Code for setting up espresso ratings request metabox.
2038
	 */
2039
	protected function _espresso_ratings_request() {
2040
		if ( ! apply_filters( 'FHEE_show_ratings_request_meta_box', true ) ) {
2041
			return '';
2042
		}
2043
		$ratings_box_title = apply_filters( 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso') );
2044
		add_meta_box( 'espresso_ratings_request', $ratings_box_title, array(
2045
			$this,
2046
			'espresso_ratings_request'
2047
		), $this->_wp_page_slug, 'side' );
2048
	}
2049
2050
2051
	/**
2052
	 * Code for setting up espresso ratings request metabox content.
2053
	 */
2054
	public function espresso_ratings_request() {
2055
		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
2056
		EE_Registry::instance()->load_helper( 'Template' );
2057
		EEH_Template::display_template( $template_path, array() );
2058
	}
2059
2060
2061
2062
2063
	public static function cached_rss_display( $rss_id, $url ) {
2064
		$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
2065
		$doing_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX );
2066
		$pre = '<div class="espresso-rss-display">' . "\n\t";
2067
		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2068
		$post = '</div>' . "\n";
2069
2070
		$cache_key = 'ee_rss_' . md5( $rss_id );
2071
		if ( FALSE != ( $output = get_transient( $cache_key ) ) ) {
2072
			echo $pre . $output . $post;
2073
			return TRUE;
2074
		}
2075
2076
		if ( ! $doing_ajax ) {
2077
			echo $pre . $loading . $post;
2078
			return FALSE;
2079
		}
2080
2081
		ob_start();
2082
		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5) );
2083
		set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
2084
		return TRUE;
2085
2086
	}
2087
2088
2089
	public function espresso_news_post_box() {
2090
		?>
2091
	  <div class="padding">
2092
	  	<div id="espresso_news_post_box_content" class="infolinks">
2093
	  		<?php
2094
	  		// Get RSS Feed(s)
2095
	  		$feed_url = apply_filters( 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/' );
2096
	  		$url = urlencode($feed_url);
2097
	  		self::cached_rss_display( 'espresso_news_post_box_content', $url );
2098
2099
	  		?>
2100
	  	</div>
2101
	  	<?php do_action( 'AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2102
	  </div>
2103
		<?php
2104
	}
2105
2106
2107
	private function _espresso_links_post_box() {
2108
		//Hiding until we actually have content to put in here...
2109
		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2110
	}
2111
2112
	public function espresso_links_post_box() {
2113
		   //Hiding until we actually have content to put in here...
2114
		   //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2115
			//EEH_Template::display_template( $templatepath );
2116
		}
2117
2118
2119
2120
	protected function _espresso_sponsors_post_box() {
2121
2122
		$show_sponsors = apply_filters( 'FHEE_show_sponsors_meta_box', TRUE );
2123
		if ( $show_sponsors )
2124
			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array( $this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2125
	}
2126
2127
2128
	public function espresso_sponsors_post_box() {
2129
		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2130
		EEH_Template::display_template( $templatepath );
2131
	}
2132
2133
2134
2135
	private function _publish_post_box() {
2136
		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2137
2138
		//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)
2139
		if ( !empty( $this->_labels['publishbox'] ) ) {
2140
			$box_label = is_array( $this->_labels['publishbox'] ) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2141
		} else {
2142
			$box_label = __('Publish', 'event_espresso');
2143
		}
2144
2145
		$box_label = apply_filters( 'FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this );
2146
2147
		add_meta_box( $meta_box_ref, $box_label, array( $this, 'editor_overview' ), $this->_current_screen->id, 'side', 'high' );
2148
2149
	}
2150
2151
2152
2153
	public function editor_overview() {
2154
		//if we have extra content set let's add it in if not make sure its empty
2155
		$this->_template_args['publish_box_extra_content'] = isset( $this->_template_args['publish_box_extra_content'] ) ? $this->_template_args['publish_box_extra_content'] : '';
2156
		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2157
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2158
	}
2159
2160
2161
	/** end of globally available metaboxes section **/
2162
	/*************************************************/
2163
2164
2165
2166
	/**
2167
	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2168
	 * protected method.
2169
	 *
2170
	 * @see $this->_set_publish_post_box_vars for param details
2171
	 * @since 4.6.0
2172
	 */
2173
	public function set_publish_post_box_vars( $name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true ) {
2174
		$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...
2175
	}
2176
2177
2178
	/**
2179
	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2180
	 *
2181
	 * Note: currently there is no validation for this.  However if you want the delete button, the
2182
	 * save, and save and close buttons to work properly, then you will want to include a
2183
	 * values for the name and id arguments.
2184
	 *
2185
	 * @todo  Add in validation for name/id arguments.
2186
	 *
2187
	 * @param	string	$name		key used for the action ID (i.e. event_id)
2188
	 * @param	int		$id	id attached to the item published
2189
	 * @param	string	$delete	page route callback for the delete action
2190
	 * @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...
2191
	 * @param	boolean	$both_btns	whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2192
	 */
2193
	protected function _set_publish_post_box_vars( $name = NULL, $id = FALSE, $delete = FALSE, $save_close_redirect_URL = NULL, $both_btns = TRUE ) {
2194
2195
		// if Save & Close, use a custom redirect URL or default to the main page?
2196
		$save_close_redirect_URL = ! empty( $save_close_redirect_URL ) ? $save_close_redirect_URL : $this->_admin_base_url;
2197
		// create the Save & Close and Save buttons
2198
		$this->_set_save_buttons( $both_btns, array(), array(), $save_close_redirect_URL );
2199
		//if we have extra content set let's add it in if not make sure its empty
2200
		$this->_template_args['publish_box_extra_content'] = isset( $this->_template_args['publish_box_extra_content'] ) ? $this->_template_args['publish_box_extra_content'] : '';
2201
2202
2203
		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...
2204
			$delete = is_bool($delete) ? 'delete' : $delete; //make sure we have a default if just true is sent.
2205
			$delete_link_args = array( $name => $id );
2206
			$delete = $this->get_action_link_or_button( $delete, $delete, $delete_link_args, 'submitdelete deletion');
2207
		}
2208
2209
		$this->_template_args['publish_delete_link'] = !empty( $id ) ? $delete : '';
2210
		if ( ! empty( $name ) && ! empty( $id ) ) {
2211
			$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...
2212
				'type' => 'hidden',
2213
				'value' => $id
2214
				);
2215
			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2216
		} else {
2217
			$hf = '';
2218
		}
2219
		// add hidden field
2220
		$this->_template_args['publish_hidden_fields'] = ! empty( $hf ) ? $hf[$name]['field'] : $hf;
2221
2222
	}
2223
2224
2225
2226
2227
	/**
2228
	 * 		displays an error message to ppl who have javascript disabled
2229
	*		@access 		private
2230
	*		@return 		string
2231
	*/
2232
	private function _display_no_javascript_warning() {
2233
		?>
2234
		<noscript>
2235
			<div id="no-js-message" class="error">
2236
				<p style="font-size:1.3em;">
2237
					<span style="color:red;"><?php _e( 'Warning!', 'event_espresso' ); ?></span>
2238
					<?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' ); ?>
2239
				</p>
2240
			</div>
2241
		</noscript>
2242
		<?php
2243
	}
2244
2245
2246
2247
2248
2249
2250
2251
2252
	/**
2253
	 * 		displays espresso success and/or error notices
2254
	*		@access 		private
2255
	*		@return 		string
2256
	*/
2257
	private function _display_espresso_notices() {
2258
		$notices = $this->_get_transient( TRUE );
2259
		echo stripslashes($notices);
2260
	}
2261
2262
2263
2264
2265
2266
2267
	/**
2268
	*		spinny things pacify the masses
2269
	*		@access private
2270
	*		@return string
2271
	*/
2272
	protected function _add_admin_page_ajax_loading_img() {
2273
		?>
2274
			<div id="espresso-ajax-loading" class="ajax-loading-grey">
2275
				<span class="ee-spinner ee-spin"></span><span class="hidden"><?php _e('loading...', 'event_espresso'); ?></span>
2276
			</div>
2277
		<?php
2278
	}
2279
2280
2281
2282
2283
2284
	/**
2285
	*		add admin page overlay for modal boxes
2286
	*		@access private
2287
	*		@return string
2288
	*/
2289
	protected function _add_admin_page_overlay() {
2290
		?>
2291
		<div id="espresso-admin-page-overlay-dv" class=""></div>
2292
		<?php
2293
	}
2294
2295
2296
2297
2298
2299
2300
	/**
2301
	 * facade for add_meta_box
2302
	 * @param string  $action        where the metabox get's displayed
2303
	 * @param string  $title         Title of Metabox (output in metabox header)
2304
	 * @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.
2305
	 * @param array  $callback_args an array of args supplied for the metabox
2306
	 * @param string  $column        what metabox column
2307
	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2308
	 * @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.
2309
	 */
2310
	public function _add_admin_page_meta_box( $action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true ) {
2311
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, $callback );
2312
2313
		//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.
2314
		if ( empty( $callback_args ) && $create_func ) {
2315
			$callback_args = array(
2316
				'template_path' => $this->_template_path,
2317
				'template_args' => $this->_template_args,
2318
				);
2319
		}
2320
2321
		//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)
2322
		$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...
2323
2324
		add_meta_box( str_replace( '_', '-', $action ) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args );
2325
	}
2326
2327
2328
2329
2330
2331
	/**
2332
	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2333
	 * @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...
2334
	 */
2335
	public function display_admin_page_with_metabox_columns() {
2336
		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2337
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $this->_column_template_path, $this->_template_args, TRUE);
2338
2339
		//the final wrapper
2340
		$this->admin_page_wrapper();
2341
	}
2342
2343
2344
2345
2346
2347
2348
2349
	/**
2350
	*		generates  HTML wrapper for an admin details page
2351
	*		@access public
2352
	*		@return void
2353
	*/
2354
	public function display_admin_page_with_sidebar() {
2355
2356
		$this->_display_admin_page(TRUE);
2357
	}
2358
2359
2360
2361
2362
	/**
2363
	*		generates  HTML wrapper for an admin details page (except no sidebar)
2364
	*		@access public
2365
	*		@return void
2366
	*/
2367
	public function display_admin_page_with_no_sidebar() {
2368
		$this->_display_admin_page();
2369
	}
2370
2371
2372
2373
2374
	/**
2375
	 * generates HTML wrapper for an EE about admin page (no sidebar)
2376
	 * @access public
2377
	 * @return void
2378
	 */
2379
	public function display_about_admin_page() {
2380
		$this->_display_admin_page( FALSE, TRUE );
2381
	}
2382
2383
2384
2385
2386
	/**
2387
	 * display_admin_page
2388
	 * contains the code for actually displaying an admin page
2389
	 *
2390
	 * @access private
2391
	 * @param  boolean $sidebar true with sidebar, false without
2392
	 * @param  boolean $about   use the about admin wrapper instead of the default.
2393
	 * @return html           admin_page
2394
	 */
2395
	private function _display_admin_page($sidebar = false, $about = FALSE) {
2396
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2397
2398
		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2399
		do_action( 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' );
2400
2401
		// set current wp page slug - looks like: event-espresso_page_event_categories
2402
		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2403
		$this->_template_args['current_page'] = $this->_wp_page_slug;
2404
2405
		$template_path = $sidebar ?  EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2406
2407
		if ( defined('DOING_AJAX' ) )
2408
			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2409
2410
		$template_path = !empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2411
2412
		$this->_template_args['post_body_content'] = isset( $this->_template_args['admin_page_content'] ) ? $this->_template_args['admin_page_content'] : '';
2413
		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2414
		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2415
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2416
2417
2418
		// the final template wrapper
2419
		$this->admin_page_wrapper($about);
2420
	}
2421
2422
2423
2424
2425
2426
	/**
2427
	 * This is used to display caf preview pages.
2428
	 *
2429
	 * @since 4.3.2
2430
	 *
2431
	 * @param string $utm_campaign_source what is the key used for google analytics link
2432
	 * @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.
2433
	 * @return void
2434
	 */
2435
	public function display_admin_caf_preview_page( $utm_campaign_source = '', $display_sidebar = TRUE ) {
2436
		//let's generate a default preview action button if there isn't one already present.
2437
		$this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso');
2438
		$buy_now_url = add_query_arg(
2439
			array(
2440
				'ee_ver' => 'ee4',
2441
				'utm_source' => 'ee4_plugin_admin',
2442
				'utm_medium' => 'link',
2443
				'utm_campaign' => $utm_campaign_source,
2444
				'utm_content' => 'buy_now_button'
2445
			),
2446
		'http://eventespresso.com/pricing/'
2447
		);
2448
		$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'];
2449
		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2450
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2451
		$this->_display_admin_page( $display_sidebar );
2452
	}
2453
2454
2455
	/**
2456
	 * display_admin_list_table_page_with_sidebar
2457
	 * generates HTML wrapper for an admin_page with list_table
2458
	 *
2459
	 * @access public
2460
	 * @return html
2461
	 */
2462
	public function display_admin_list_table_page_with_sidebar() {
2463
		$this->_display_admin_list_table_page(TRUE);
2464
	}
2465
2466
	/**
2467
	 * display_admin_list_table_page_with_no_sidebar
2468
	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2469
	 *
2470
	 * @access public
2471
	 * @return html
2472
	 */
2473
	public function display_admin_list_table_page_with_no_sidebar() {
2474
		$this->_display_admin_list_table_page();
2475
	}
2476
2477
2478
2479
	/**
2480
	 * generates html wrapper for an admin_list_table page
2481
	 * @access private
2482
	 * @param boolean $sidebar whether to display with sidebar or not.
2483
	 * @return html
2484
	 */
2485
	private function _display_admin_list_table_page( $sidebar = false ) {
2486
		//setup search attributes
2487
		$this->_set_search_attributes();
2488
		$this->_template_args['current_page'] = $this->_wp_page_slug;
2489
		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2490
2491
		$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);
2492
		$this->_template_args['list_table'] = $this->_list_table_object;
2493
		$this->_template_args['current_route'] = $this->_req_action;
2494
		$this->_template_args['list_table_class'] = get_class( $this->_list_table_object );
2495
2496
		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2497
		if( ! empty( $ajax_sorting_callback )) {
2498
			$sortable_list_table_form_fields = wp_nonce_field( $ajax_sorting_callback . '_nonce', $ajax_sorting_callback . '_nonce', FALSE, FALSE );
2499
//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2500
//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2501
			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug .'" />';
2502
			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2503
		} else {
2504
			$sortable_list_table_form_fields = '';
2505
		}
2506
2507
		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2508
		$hidden_form_fields = isset( $this->_template_args['list_table_hidden_fields'] ) ? $this->_template_args['list_table_hidden_fields'] : '';
2509
		$nonce_ref = $this->_req_action . '_nonce';
2510
		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce( $nonce_ref ) . '">';
2511
		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2512
2513
		//display message about search results?
2514
		$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 );
2515
2516
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2517
2518
		// the final template wrapper
2519
		if ( $sidebar )
2520
			$this->display_admin_page_with_sidebar();
2521
		else
2522
			$this->display_admin_page_with_no_sidebar();
2523
	}
2524
2525
2526
2527
2528
2529
	/**
2530
	 * 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.
2531
	 *
2532
	 * $items are expected in an array in the following format:
2533
	 * $legend_items = array(
2534
	 * 		'item_id' => array(
2535
	 * 			'icon' => 'http://url_to_icon_being_described.png',
2536
	 * 			'desc' => __('localized description of item');
2537
	 * 		)
2538
	 * );
2539
	 * @param  array $items  see above for format of array
2540
	 * @return string        html string of legend
2541
	 */
2542
	protected function _display_legend( $items ) {
2543
		$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...
2544
		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2545
		return EEH_Template::display_template($legend_template, $template_args, TRUE);
2546
	}
2547
2548
2549
2550
2551
	/**
2552
	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2553
	 *
2554
	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2555
	 *
2556
	 * The returned json object is created from an array in the following format:
2557
	 * array(
2558
	 * 	'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2559
	 * 	'success' => FALSE, //(default FALSE) - contains any special success message.
2560
	 * 	'notices' => '', // - contains any EE_Error formatted notices
2561
	 * 	'content' => 'string can be html', //this is a string of formatted content (can be html)
2562
	 * 	'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)
2563
	 * )
2564
	 *
2565
	 * The json object is populated by whatever is set in the $_template_args property.
2566
	 *
2567
	 * @return json object
2568
	 */
2569
	protected function _return_json( $sticky_notices = false ) {
2570
2571
		//make sure any EE_Error notices have been handled.
2572
		$this->_process_notices( array(), true, $sticky_notices );
2573
2574
2575
		$data = isset( $this->_template_args['data'] ) ? $this->_template_args['data'] : array();
2576
		unset($this->_template_args['data']);
2577
		$json = array(
2578
			'error' => isset( $this->_template_args['error'] ) ? $this->_template_args['error'] : false,
2579
			'success' => isset( $this->_template_args['success'] ) ? $this->_template_args['success'] : false,
2580
			'errors' => isset( $this->_template_args['errors'] ) ? $this->_template_args['errors'] : false,
2581
			'attention' => isset( $this->_template_args['attention'] ) ? $this->_template_args['attention'] : false,
2582
			'notices' => EE_Error::get_notices(),
2583
			'content' => isset( $this->_template_args['admin_page_content'] ) ? $this->_template_args['admin_page_content'] : '',
2584
			'data' => array_merge( $data, array('template_args' => $this->_template_args ) ),
2585
			'isEEajax' => TRUE //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2586
			);
2587
2588
2589
		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2590
		if ( NULL === error_get_last() || ! headers_sent() )
2591
			header('Content-Type: application/json; charset=UTF-8');
2592
                if( function_exists( 'wp_json_encode' ) ) {
2593
                    echo wp_json_encode( $json );
2594
                } else {
2595
                    echo json_encode( $json );
2596
                }
2597
		exit();
2598
	}
2599
2600
2601
2602
	/**
2603
	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2604
	 * @return json_obj|EE_Error
2605
	 */
2606
	public function return_json() {
2607
		if ( defined('DOING_AJAX') && DOING_AJAX )
2608
			$this->_return_json();
2609
2610
		else {
2611
			throw new EE_Error( sprintf( __('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__ ) );
2612
		}
2613
	}
2614
2615
2616
2617
2618
	/**
2619
	 * 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.
2620
	 *
2621
	 * @param EE_Admin_Hooks object $hook_obj This will be the object for the EE_Admin_Hooks child
2622
	 *
2623
	 * @access public
2624
	 * @return void
2625
	 */
2626
	public function set_hook_object( EE_Admin_Hooks $hook_obj ) {
2627
		$this->_hook_obj = $hook_obj;
2628
	}
2629
2630
2631
2632
2633
2634
	/**
2635
	*		generates  HTML wrapper with Tabbed nav for an admin page
2636
	*		@access public
2637
	*		@param  boolean $about whether to use the special about page wrapper or default.
2638
	*		@return void
2639
	*/
2640
	public function admin_page_wrapper($about = FALSE) {
2641
2642
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2643
2644
		$this->_nav_tabs = $this->_get_main_nav_tabs();
2645
2646
		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2647
		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2648
2649
		$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'] : '');
2650
		$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'] : '');
2651
2652
		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2653
2654
2655
2656
		// load settings page wrapper template
2657
		$template_path = !defined( 'DOING_AJAX' ) ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2658
2659
		//about page?
2660
		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2661
2662
2663
		if ( defined( 'DOING_AJAX' ) ) {
2664
			$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2665
2666
			$this->_return_json();
2667
		} else {
2668
			EEH_Template::display_template( $template_path, $this->_template_args );
2669
		}
2670
2671
	}
2672
2673
2674
2675
	/**
2676
	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2677
	 * @return string html
2678
	 */
2679
	protected function _get_main_nav_tabs() {
2680
		//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)
2681
		EE_Registry::instance()->load_helper( 'Tabbed_Content' );
2682
		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...
2683
	}
2684
2685
2686
2687
2688
2689
2690
2691
2692
	/**
2693
	*		sort nav tabs
2694
	*		@access public
2695
	*		@return void
2696
	*/
2697
	private function _sort_nav_tabs( $a, $b ) {
2698
		if ($a['order'] == $b['order']) {
2699
	        return 0;
2700
	    }
2701
	    return ($a['order'] < $b['order']) ? -1 : 1;
2702
	}
2703
2704
2705
2706
2707
2708
	/**
2709
	 * 	generates HTML for the forms used on admin pages
2710
	 * 	@access protected
2711
	 * 	@param	array $input_vars - array of input field details
2712
	 * 	@param	array $id - used for defining unique identifiers for the form.
2713
	 * 	@param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use)
2714
	 * 	@return string
2715
	 * 	@uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2716
	 * 	@uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2717
	 */
2718
	protected function _generate_admin_form_fields( $input_vars = array(), $generator = 'string', $id = FALSE ) {
2719
		EE_Registry::instance()->load_helper( 'Form_Fields' );
2720
		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2721
		return $content;
2722
	}
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
	/**
2733
	 * generates the "Save" and "Save & Close" buttons for edit forms
2734
	 *
2735
	 * @access protected
2736
	 * @param bool $both if true then both buttons will be generated.  If false then just the "Save & Close" button.
2737
	 * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2738
	 * @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.
2739
	 * @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).
2740
	 */
2741
	protected function _set_save_buttons($both = TRUE, $text = array(), $actions = array(), $referrer = NULL ) {
2742
		//make sure $text and $actions are in an array
2743
		$text = (array) $text;
2744
		$actions = (array) $actions;
2745
		$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...
2746
		$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 .'" />';
2747
2748
		$button_text = !empty($text) ? $text : array( __('Save', 'event_espresso'), __('Save and Close', 'event_espresso') );
2749
		$default_names = array( 'save', 'save_and_close' );
2750
2751
		//add in a hidden index for the current page (so save and close redirects properly)
2752
		$this->_template_args['save_buttons'] = $referrer_url;
2753
2754
		foreach ( $button_text as $key => $button ) {
2755
			$ref = $default_names[$key];
2756
			$id = $this->_current_view . '_' . $ref;
2757
			$name = !empty($actions) ? $actions[$key] : $ref;
2758
			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2759
			if ( !$both ) break;
2760
		}
2761
2762
	}
2763
2764
2765
	/**
2766
	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2767
	 *
2768
	 * @see $this->_set_add_edit_form_tags() for details on params
2769
	 * @since 4.6.0
2770
	 *
2771
	 */
2772
	public function set_add_edit_form_tags( $route = '', $additional_hidden_fields = array() ) {
2773
		$this->_set_add_edit_form_tags( $route, $additional_hidden_fields );
2774
	}
2775
2776
2777
2778
	/**
2779
	 * set form open and close tags on add/edit pages.
2780
	 *
2781
	 * @access protected
2782
	 * @param string $route the route you want the form to direct to
2783
	 * @param array $additional_hidden_fields any additional hidden fields required in the form header
2784
	 * @return void
2785
	 */
2786
	protected function _set_add_edit_form_tags( $route = '', $additional_hidden_fields = array() ) {
2787
2788
		if ( empty( $route )) {
2789
			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2790
			$dev_msg = $user_msg . "\n" . sprintf( __('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__ );
2791
			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
2792
		}
2793
		// open form
2794
		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2795
		// add nonce
2796
		$nonce = wp_nonce_field( $route . '_nonce', $route . '_nonce', FALSE, FALSE );
2797
//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2798
		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2799
		// add REQUIRED form action
2800
		$hidden_fields = array(
2801
				'action' => array( 'type' => 'hidden', 'value' => $route ),
2802
			);
2803
		// merge arrays
2804
		$hidden_fields = is_array( $additional_hidden_fields) ? array_merge( $hidden_fields, $additional_hidden_fields ) : $hidden_fields;
2805
		// generate form fields
2806
		$form_fields = $this->_generate_admin_form_fields( $hidden_fields, 'array' );
2807
		// add fields to form
2808
		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...
2809
			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2810
		}
2811
2812
		// close form
2813
		$this->_template_args['after_admin_page_content'] = '</form>';
2814
2815
	}
2816
2817
2818
2819
	/**
2820
	 * Public Wrapper for _redirect_after_action() method since its
2821
	 * discovered it would be useful for external code to have access.
2822
	 *
2823
	 * @see EE_Admin_Page::_redirect_after_action() for params.
2824
	 * @since 4.5.0
2825
	 */
2826
	public function redirect_after_action( $success = FALSE, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = FALSE ) {
2827
		$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 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...
2828
	}
2829
2830
2831
2832
	/**
2833
	 *    _redirect_after_action
2834
	 *
2835
	 * @param int $success - whether success was for two or more records, or just one, or none
2836
	 *	@param string 	$what 		- what the action was performed on
2837
	 *	@param string 	$action_desc 	- what was done ie: updated, deleted, etc
2838
	 *	@param array 	$query_args		- an array of query_args to be added to the URL to redirect to after the admin action is completed
2839
	 *	@param BOOL     $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2840
	 *	@access protected
2841
	 *	@return void
2842
	 */
2843
	protected function _redirect_after_action( $success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = FALSE ) {
2844
2845
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2846
2847
		//class name for actions/filters.
2848
		$classname = get_class($this);
2849
2850
		//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
2851
		$redirect_url = isset( $query_args['page'] ) ? admin_url('admin.php') : $this->_admin_base_url;
2852
		$notices = EE_Error::get_notices( FALSE );
2853
2854
		// overwrite default success messages //BUT ONLY if overwrite not overridden
2855
		if ( ! $override_overwrite || ! empty( $notices['errors'] )) {
2856
			EE_Error::overwrite_success();
2857
		}
2858
		// how many records affected ? more than one record ? or just one ?
2859
		if ( $success > 1 && empty( $notices['errors'] )) {
2860
			// set plural msg
2861
			EE_Error::add_success( sprintf( __('The "%s" have been successfully %s.', 'event_espresso'), $what, $action_desc ), __FILE__, __FUNCTION__, __LINE__);
2862
		} else if ( $success == 1 && empty( $notices['errors'] )) {
2863
			// set singular msg
2864
			EE_Error::add_success( sprintf( __('The "%s" has been successfully %s.', 'event_espresso'), $what, $action_desc), __FILE__, __FUNCTION__, __LINE__ );
2865
		}
2866
2867
		// check that $query_args isn't something crazy
2868
		if ( ! is_array( $query_args )) {
2869
			$query_args = array();
2870
		}
2871
2872
		/**
2873
		 * Allow injecting actions before the query_args are modified for possible different
2874
		 * redirections on save and close actions
2875
		 *
2876
		 * @since 4.2.0
2877
		 *
2878
		 * @param array $query_args   The original query_args array coming into the
2879
		 *                          		method.
2880
		 */
2881
		do_action( 'AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args );
2882
2883
		//calculate where we're going (if we have a "save and close" button pushed)
2884
		if ( isset($this->_req_data['save_and_close'] ) && isset($this->_req_data['save_and_close_referrer'] ) ) {
2885
			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2886
			$parsed_url = parse_url( $this->_req_data['save_and_close_referrer'] );
2887
			// regenerate query args array from refferer URL
2888
			parse_str( $parsed_url['query'], $query_args );
2889
			// correct page and action will be in the query args now
2890
			$redirect_url = admin_url( 'admin.php' );
2891
		}
2892
2893
		//merge any default query_args set in _default_route_query_args property
2894
		if ( ! empty( $this->_default_route_query_args ) && ! $this->_is_UI_request ) {
2895
			$args_to_merge = array();
2896
			foreach ( $this->_default_route_query_args as $query_param => $query_value ) {
2897
				//is there a wp_referer array in our _default_route_query_args property?
2898
				if ( $query_param == 'wp_referer'  ) {
2899
					$query_value = (array) $query_value;
2900
					foreach ( $query_value as $reference => $value ) {
2901
						if ( strpos( $reference, 'nonce' ) !== false ) {
2902
							continue;
2903
						}
2904
2905
						//finally we will override any arguments in the referer with
2906
						//what might be set on the _default_route_query_args array.
2907
						if ( isset( $this->_default_route_query_args[$reference] ) ) {
2908
							$args_to_merge[$reference] = urlencode( $this->_default_route_query_args[$reference] );
2909
						} else {
2910
							$args_to_merge[$reference] = urlencode( $value );
2911
						}
2912
					}
2913
					continue;
2914
				}
2915
2916
				$args_to_merge[$query_param] = $query_value;
2917
			}
2918
2919
			//now let's merge these arguments but override with what was specifically sent in to the
2920
			//redirect.
2921
			$query_args = array_merge( $args_to_merge, $query_args );
2922
		}
2923
2924
		$this->_process_notices($query_args);
0 ignored issues
show
Bug introduced by
It seems like $query_args can also be of type null; however, EE_Admin_Page::_process_notices() 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...
2925
2926
2927
		// generate redirect url
2928
2929
		// if redirecting to anything other than the main page, add a nonce
2930
		if ( isset( $query_args['action'] )) {
2931
			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2932
			$query_args['_wpnonce'] = wp_create_nonce( $query_args['action'] . '_nonce' );
2933
		}
2934
2935
		//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).
2936
		do_action( 'AHEE_redirect_' . $classname . $this->_req_action, $query_args );
2937
2938
		$redirect_url = apply_filters( 'FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce( $query_args, $redirect_url ), $query_args );
2939
2940
2941
		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2942
		if ( defined('DOING_AJAX' ) ) {
2943
			$default_data = array(
2944
				'close' => TRUE,
2945
				'redirect_url' => $redirect_url,
2946
				'where' => 'main',
2947
				'what' => 'append',
2948
				);
2949
2950
			$this->_template_args['success'] = $success;
2951
			$this->_template_args['data'] = !empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data'] ): $default_data;
2952
			$this->_return_json();
2953
		}
2954
2955
		wp_safe_redirect( $redirect_url );
2956
		exit();
2957
	}
2958
2959
2960
2961
2962
	/**
2963
	 * process any notices before redirecting (or returning ajax request)
2964
	 * This method sets the $this->_template_args['notices'] attribute;
2965
	 *
2966
	 * @param  array  $query_args any query args that need to be used for notice transient ('action')
2967
	 * @param bool    $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2968
	 * @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.
2969
	 * @return void
2970
	 */
2971
	protected function _process_notices( $query_args = array(), $skip_route_verify = FALSE , $sticky_notices = TRUE ) {
2972
2973
		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2974
		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
2975
			$notices = EE_Error::get_notices( false );
2976 View Code Duplication
			if ( empty( $this->_template_args['success'] ) ) {
2977
				$this->_template_args['success'] = isset( $notices['success'] ) ? $notices['success'] : false;
2978
			}
2979
2980 View Code Duplication
			if ( empty( $this->_template_args['errors'] ) ) {
2981
				$this->_template_args['errors'] = isset( $notices['errors'] ) ? $notices['errors'] : false;
2982
			}
2983
2984 View Code Duplication
			if ( empty( $this->_template_args['attention'] ) ) {
2985
				$this->_template_args['attention'] = isset( $notices['attention'] ) ? $notices['attention'] : false;
2986
			}
2987
		}
2988
2989
		$this->_template_args['notices'] = EE_Error::get_notices();
2990
2991
		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2992
		if ( ! defined( 'DOING_AJAX' ) || $sticky_notices ) {
2993
			$route = isset( $query_args['action'] ) ? $query_args['action'] : 'default';
2994
			$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...
2995
		}
2996
	}
2997
2998
2999
3000
3001
	/**
3002
	 * get_action_link_or_button
3003
	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3004
	 *
3005
	 * @param string $action use this to indicate which action the url is generated with.
3006
	 * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property.
3007
	 * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3008
	 * @param string $class Use this to give the class for the button. Defaults to 'button-primary'
3009
	 * @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.
3010
	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3011
	 *
3012
	 * @throws EE_Error
3013
	 *
3014
	 * @return string html for button
3015
	 */
3016
	public function get_action_link_or_button($action, $type = 'add', $extra_request = array(), $class = 'button-primary', $base_url = FALSE, $exclude_nonce = false ) {
3017
		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3018
		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...
3019
			throw new EE_Error( sprintf( __('There is no page route for given action for the button.  This action was given: %s', 'event_espresso'), $action) );
3020
3021
		if ( !isset( $this->_labels['buttons'][$type] ) )
3022
			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) );
3023
3024
		//finally check user access for this button.
3025
		$has_access = $this->check_user_access( $action, TRUE );
3026
		if ( ! $has_access ) {
3027
			return '';
3028
		}
3029
3030
		$_base_url = !$base_url ? $this->_admin_base_url : $base_url;
3031
3032
		$query_args = array(
3033
			'action' => $action  );
3034
3035
		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3036
		if ( !empty($extra_request) )
3037
			$query_args = array_merge( $extra_request, $query_args );
3038
3039
		$url = self::add_query_args_and_nonce( $query_args, $_base_url, false, $exclude_nonce );
3040
3041
		$button = EEH_Template::get_button_or_link( $url, $this->_labels['buttons'][$type], $class );
3042
3043
		return $button;
3044
	}
3045
3046
3047
3048
3049
3050
3051
	/**
3052
	 * _per_page_screen_option
3053
	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3054
	 * @return void
3055
	 */
3056
	protected function _per_page_screen_option() {
3057
		$option = 'per_page';
3058
		$args = array(
3059
			'label' => $this->_admin_page_title,
3060
			'default' => 10,
3061
			'option' => $this->_current_page . '_' . $this->_current_view . '_per_page'
3062
			);
3063
		//ONLY add the screen option if the user has access to it.
3064
		if ( $this->check_user_access( $this->_current_view, true ) ) {
3065
			add_screen_option( $option, $args );
3066
		}
3067
	}
3068
3069
3070
3071
3072
	/**
3073
	 * set_per_page_screen_option
3074
	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3075
	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3076
	 *
3077
	 * @access private
3078
	 * @return void
3079
	 */
3080
	private function _set_per_page_screen_options() {
3081
		if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {
3082
			check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
3083
3084
			if ( !$user = wp_get_current_user() )
3085
			return;
3086
			$option = $_POST['wp_screen_options']['option'];
3087
			$value = $_POST['wp_screen_options']['value'];
3088
3089
			if ( $option != sanitize_key( $option ) )
3090
				return;
3091
3092
			$map_option = $option;
3093
3094
			$option = str_replace('-', '_', $option);
3095
3096
			switch ( $map_option ) {
3097
				case $this->_current_page . '_' .  $this->_current_view . '_per_page':
3098
					$value = (int) $value;
3099
					if ( $value < 1 || $value > 999 )
3100
						return;
3101
					break;
3102
				default:
3103
					$value = apply_filters( 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value );
3104
					if ( false === $value )
3105
						return;
3106
					break;
3107
			}
3108
3109
			update_user_meta($user->ID, $option, $value);
3110
			wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
3111
			exit;
3112
		}
3113
	}
3114
3115
3116
3117
	/**
3118
	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3119
	 * @param array $data array that will be assigned to template args.
3120
	 */
3121
	public function set_template_args( $data ) {
3122
		$this->_template_args = array_merge( $this->_template_args, (array) $data );
3123
	}
3124
3125
3126
3127
3128
	/**
3129
	 * This makes available the WP transient system for temporarily moving data between routes
3130
	 *
3131
	 * @access protected
3132
	 * @param route $route the route that should receive the transient
3133
	 * @param data $data  the data that gets sent
3134
	 * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3135
	 * @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.
3136
	 * @return void
3137
	 */
3138
	protected function _add_transient( $route, $data, $notices = FALSE, $skip_route_verify = FALSE ) {
3139
		$user_id = get_current_user_id();
3140
3141
		if ( !$skip_route_verify )
3142
			$this->_verify_route($route);
3143
3144
3145
		//now let's set the string for what kind of transient we're setting
3146
		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3147
		$data = $notices ? array( 'notices' => $data ) : $data;
3148
		//is there already a transient for this route?  If there is then let's ADD to that transient
3149
		$existing = is_multisite() && is_network_admin() ? get_site_transient( $transient ) : get_transient( $transient );
3150
		if ( $existing ) {
3151
			$data = array_merge( (array) $data, (array) $existing );
3152
		}
3153
3154
		if ( is_multisite() && is_network_admin() ) {
3155
			set_site_transient( $transient, $data, 8 );
3156
		} else {
3157
			set_transient( $transient, $data, 8 );
3158
		}
3159
	}
3160
3161
3162
3163
3164
	/**
3165
	 * this retrieves the temporary transient that has been set for moving data between routes.
3166
	 * @param bool $notices true we get notices transient. False we just return normal route transient
3167
	 * @return mixed data
3168
	 */
3169
	protected function _get_transient( $notices = FALSE, $route = FALSE ) {
3170
		$user_id = get_current_user_id();
3171
		$route = !$route ? $this->_req_action : $route;
3172
		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3173
		$data = is_multisite() && is_network_admin() ? get_site_transient( $transient ) : get_transient( $transient );
3174
		//delete transient after retrieval (just in case it hasn't expired);
3175
		if ( is_multisite() && is_network_admin() ) {
3176
			delete_site_transient( $transient );
3177
		} else {
3178
			delete_transient( $transient );
3179
		}
3180
		return $notices && isset( $data['notices'] ) ? $data['notices'] : $data;
3181
	}
3182
3183
3184
3185
3186
	/**
3187
	 * 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.
3188
	 *
3189
	 * 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.)
3190
	 * @return void
3191
	 */
3192
	protected function _transient_garbage_collection() {
3193
		global $wpdb;
3194
3195
		//retrieve all existing transients
3196
		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3197
		if ( $results = $wpdb->get_results( $query ) ) {
3198
			foreach ( $results as $result ) {
3199
				$transient = str_replace( '_transient_', '', $result->option_name );
3200
				get_transient( $transient );
3201
				if ( is_multisite() && is_network_admin() ) {
3202
					get_site_transient( $transient );
3203
				}
3204
			}
3205
		}
3206
	}
3207
3208
3209
3210
3211
3212
	/**
3213
	 * get_view
3214
	 *
3215
	 * @access public
3216
	 * @return string content of _view property
3217
	 */
3218
	public function get_view() {
3219
		return $this->_view;
3220
	}
3221
3222
3223
3224
3225
	/**
3226
	 * getter for the protected $_views property
3227
	 *
3228
	 * @return array
3229
	 */
3230
	public function get_views() {
3231
		return $this->_views;
3232
	}
3233
3234
3235
3236
3237
	/**
3238
	 * get_current_page
3239
	 *
3240
	 * @access public
3241
	 * @return string _current_page property value
3242
	 */
3243
	public function get_current_page() {
3244
		return $this->_current_page;
3245
	}
3246
3247
3248
3249
3250
	/**
3251
	 * get_current_view
3252
	 *
3253
	 * @access public
3254
	 * @return string _current_view property value
3255
	 */
3256
	public function get_current_view() {
3257
		return $this->_current_view;
3258
	}
3259
3260
3261
3262
	/**
3263
	 * get_current_screen
3264
	 *
3265
	 * @access public
3266
	 * @return object The current WP_Screen object
3267
	 */
3268
	public function get_current_screen() {
3269
		return $this->_current_screen;
3270
	}
3271
3272
3273
	/**
3274
	 * get_current_page_view_url
3275
	 *
3276
	 * @access public
3277
	 * @return string This returns the url for the current_page_view.
3278
	 */
3279
	public function get_current_page_view_url() {
3280
		return $this->_current_page_view_url;
3281
	}
3282
3283
3284
3285
3286
	/**
3287
	 * just returns the _req_data property
3288
	 * @return array
3289
	 */
3290
	public function get_request_data() {
3291
		return $this->_req_data;
3292
	}
3293
3294
3295
3296
	/**
3297
	 * returns the _req_data protected property
3298
	 * @return string
3299
	 */
3300
	public function get_req_action() {
3301
		return $this->_req_action;
3302
	}
3303
3304
3305
	/**
3306
	 * @return bool  value of $_is_caf property
3307
	 */
3308
	public function is_caf() {
3309
		return $this->_is_caf;
3310
	}
3311
3312
3313
3314
3315
	/**
3316
	 * updates  espresso configuration settings
3317
	 *
3318
	 * @access 	protected
3319
	 * @param string $tab
3320
	 * @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...
3321
	 * @param string $file	file where error occurred
3322
	 * @param string $func function  where error occurred
3323
	 * @param string $line	line no where error occurred
3324
	 * @return boolean
3325
	 */
3326
	protected function _update_espresso_configuration( $tab, $config, $file = '', $func = '', $line = '' ) {
3327
3328
		//remove any options that are NOT going to be saved with the config settings.
3329
		if ( isset( $config->core->ee_ueip_optin ) ) {
3330
			$config->core->ee_ueip_has_notified = TRUE;
3331
			// TODO: remove the following two lines and make sure values are migrated from 3.1
3332
			update_option( 'ee_ueip_optin', $config->core->ee_ueip_optin);
3333
			update_option( 'ee_ueip_has_notified', TRUE );
3334
		}
3335
		// and save it (note we're also doing the network save here)
3336
		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config( FALSE, FALSE ) : TRUE;
3337
		$config_saved = EE_Config::instance()->update_espresso_config( FALSE, FALSE );
3338
		if ( $config_saved && $net_saved ) {
3339
			EE_Error::add_success( sprintf( __('"%s" have been successfully updated.', 'event_espresso'), $tab ));
3340
			return TRUE;
3341
		} else {
3342
			EE_Error::add_error( sprintf( __('The "%s" were not updated.', 'event_espresso'), $tab ), $file, $func, $line  );
3343
			return FALSE;
3344
		}
3345
	}
3346
3347
3348
3349
3350
3351
	/**
3352
	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3353
	 * @return array
3354
	 */
3355
	public function get_yes_no_values(){
3356
		return $this->_yes_no_values;
3357
	}
3358
3359
3360
3361
	protected function _get_dir() {
3362
		$reflector = new ReflectionClass(get_class($this));
3363
		return dirname($reflector->getFileName());
3364
	}
3365
3366
3367
3368
3369
	/**
3370
	 * A helper for getting a "next 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 _next_link( $url, $class = 'dashicons dashicons-arrow-right' ) {
3378
		return '<a class="' . $class . '" href="' . $url . '"></a>';
3379
	}
3380
3381
3382
3383
3384
	/**
3385
	 * A helper for getting a "previous link".
3386
	 *
3387
	 * @param string $url   The url to link to
3388
	 * @param string $class The class to use.
3389
	 *
3390
	 * @return string
3391
	 */
3392
	protected function _previous_link( $url, $class = 'dashicons dashicons-arrow-left' ) {
3393
		return '<a class="' . $class . '" href="' . $url . '"></a>';
3394
	}
3395
3396
3397
3398
3399
3400
3401
3402
	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3403
3404
3405
3406
3407
	/**
3408
	 * 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.
3409
	 * @return bool success/fail
3410
	 */
3411
	protected function _process_resend_registration() {
3412
		$this->_template_args['success'] = EED_Messages::process_resend( $this->_req_data );
3413
		do_action( 'AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data );
3414
		return $this->_template_args['success'];
3415
	}
3416
3417
3418
3419
	/**
3420
	 * This automatically processes any payment message notifications when manual payment has been applied.
3421
	 *
3422
	 * @access protected
3423
	 * @param \EE_Payment $payment
3424
	 * @return bool success/fail
3425
	 */
3426
	protected function _process_payment_notification( EE_Payment $payment ) {
3427
		add_filter( 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true' );
3428
		$success = apply_filters( 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', FALSE, $payment );
3429
		$this->_template_args['success'] = $success;
3430
		return $success;
3431
	}
3432
3433
3434
}
3435
// end of file:  includes/core/admin/EE_Admin_Page.core.php
3436