Completed
Branch BUG-9623-config-log (fadf4a)
by
unknown
534:14 queued 517:23
created

EE_Admin::debug_log()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 13
rs 8.8571
cc 5
eloc 9
nc 5
nop 3
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			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
11
 * @ link					http://www.eventespresso.com
12
 * @ version		 	4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 *
16
 * EE_Admin
17
 *
18
 * @package			Event Espresso
19
 * @subpackage	/core/admin/
20
 * @author				Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
final class EE_Admin {
25
26
	/**
27
	 * @access private
28
	 * @var EE_Admin $_instance
29
	 */
30
	private static $_instance;
31
32
33
34
	/**
35
	 *@ singleton method used to instantiate class object
36
	 *@ access public
37
	 *@ return class instance
38
	 *
39
	 * @throws \EE_Error
40
	 */
41
	public static function instance() {
42
		// check if class object is instantiated
43
		if (  ! self::$_instance instanceof EE_Admin ) {
44
			self::$_instance = new self();
45
		}
46
		return self::$_instance;
47
	}
48
49
50
51
	/**
52
	 * class constructor
53
	 *
54
	 * @throws \EE_Error
55
	 */
56
	protected function __construct() {
57
		// define global EE_Admin constants
58
		$this->_define_all_constants();
59
		// set autoloaders for our admin page classes based on included path information
60
		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN );
61
		// admin hooks
62
		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
63
		// load EE_Request_Handler early
64
		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' ));
65
		add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' ));
66
		// post shortcode tracking
67
		add_action(
68
			'AHEE__EE_System__initialize_last',
69
			array( 'EventEspresso\core\admin\PostShortcodeTracking', 'set_hooks_admin' )
70
		);
71
		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
72
		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
73
		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
74
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
75
		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
76
		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
77
		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
78
		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
79
80
		//reset Environment config (we only do this on admin page loads);
81
		EE_Registry::instance()->CFG->environment->recheck_values();
82
83
		do_action( 'AHEE__EE_Admin__loaded' );
84
	}
85
86
87
88
89
90
	/**
91
	 * _define_all_constants
92
	 * define constants that are set globally for all admin pages
93
	 *
94
	 * @access private
95
	 * @return void
96
	 */
97
	private function _define_all_constants() {
98
		define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
99
		define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
100
		define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
101
		define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
102
		define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ));
103
	}
104
105
106
107
	/**
108
	 *    filter_plugin_actions - adds links to the Plugins page listing
109
	 *
110
	 * @access 	public
111
	 * @param 	array 	$links
112
	 * @param 	string 	$plugin
113
	 * @return 	array
114
	 */
115
	public function filter_plugin_actions( $links, $plugin ) {
116
		// set $main_file in stone
117
		static $main_file;
118
		// if $main_file is not set yet
119
		if ( ! $main_file ) {
120
			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
121
		}
122
		 if ( $plugin === $main_file ) {
123
		 	// compare current plugin to this one
124
			if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) {
125
				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>';
126
				array_unshift( $links, $maintenance_link );
127
			} else {
128
				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
129
				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
130
				// add before other links
131
				array_unshift( $links, $org_settings_link, $events_link );
132
			}
133
		}
134
		return $links;
135
	}
136
137
138
139
	/**
140
	 *	_get_request
141
	 *
142
	 *	@access public
143
	 *	@return void
144
	 */
145
	public function get_request() {
146
		EE_Registry::instance()->load_core( 'Request_Handler' );
147
		EE_Registry::instance()->load_core( 'CPT_Strategy' );
148
	}
149
150
151
152
	/**
153
	 *    hide_admin_pages_except_maintenance_mode
154
	 *
155
	 * @access public
156
	 * @param array $admin_page_folder_names
157
	 * @return array
158
	 */
159
	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
0 ignored issues
show
Unused Code introduced by
The parameter $admin_page_folder_names is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
160
		return array(
161
			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
162
			'about' => EE_ADMIN_PAGES . 'about' . DS,
163
			'support' => EE_ADMIN_PAGES . 'support' . DS
164
		);
165
	}
166
167
168
169
	/**
170
	* init- should fire after shortcode, module,  addon, other plugin (default priority), and even EE_Front_Controller's init phases have run
171
	*
172
	* @access public
173
	* @return void
174
	*/
175
	public function init() {
176
		//only enable most of the EE_Admin IF we're not in full maintenance mode
177
		if ( EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance ){
178
			//ok so we want to enable the entire admin
179
			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
180
			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
181
			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
182
			//at a glance dashboard widget
183
			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 );
184
			//filter for get_edit_post_link used on comments for custom post types
185
			add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 );
186
		}
187
		// run the admin page factory but ONLY if we are doing an ee admin ajax request
188
		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
189
			try {
190
				//this loads the controller for the admin pages which will setup routing etc
191
				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
192
			} catch ( EE_Error $e ) {
193
				$e->get_error();
194
			}
195
		}
196
		add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
197
		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
198
		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
199
		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
200
		//exclude EE critical pages from all nav menus and wp_list_pages
201
		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
202
	}
203
204
205
206
207
	/**
208
	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from the list of options.
209
	 *
210
	 * the wp function "wp_nav_menu_item_post_type_meta_box" found in wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that to override any queries found in the existing query for the given post type.  Note that _default_query is not a normal property on the post_type object.  It's found ONLY in this particular context.
211
	 * @param  object $post_type WP post type object
212
	 * @return object            WP post type object
213
	 */
214
	public function remove_pages_from_nav_menu( $post_type ) {
215
		//if this isn't the "pages" post type let's get out
216
		if ( $post_type->name !== 'page' ) {
217
			return $post_type;
218
		}
219
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
220
221
		$post_type->_default_query = array(
222
			'post__not_in' => $critical_pages );
223
		return $post_type;
224
	}
225
226
227
228
	/**
229
	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our metaboxes get shown as well
230
	 *
231
	 * @access public
232
	 * @return void
233
	 */
234
	public function enable_hidden_ee_nav_menu_metaboxes() {
235
		global $wp_meta_boxes, $pagenow;
236
		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
237
			return;
238
		}
239
		$user = wp_get_current_user();
240
		//has this been done yet?
241
		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
242
			return;
243
		}
244
245
		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
246
		$initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) );
247
248
		if ( is_array( $hidden_meta_boxes ) ) {
249
			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
250
				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
251
					unset( $hidden_meta_boxes[ $key ] );
252
				}
253
			}
254
		}
255
256
		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
257
		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
258
	}
259
260
261
262
263
264
265
	/**
266
	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
267
	 *
268
	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
269
	 *
270
	 * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by addons etc.
271
	 *
272
	 * @access public
273
	 * @return void
274
	 */
275
	public function register_custom_nav_menu_boxes() {
276
		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
277
	}
278
279
280
281
282
	/**
283
	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
284
	 *
285
	 * @since   4.3.0
286
	 *
287
	 * @param string $link    the original link generated by wp
288
	 * @param int      $id      post id
289
	 *
290
	 * @return string  the (maybe) modified link
291
	 */
292
	public function modify_edit_post_link( $link, $id ) {
293
		if ( ! $post = get_post( $id ) ){
294
			return $link;
295
		}
296
		if ( $post->post_type === 'espresso_attendees' ) {
297
			$query_args = array(
298
				'action' => 'edit_attendee',
299
				'post' => $id
300
			);
301
			EE_Registry::instance()->load_helper('URL');
302
			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
303
		}
304
		return $link;
305
	}
306
307
308
309
310
	public function ee_cpt_archive_pages() {
311
		global $nav_menu_selected_id;
312
313
		$db_fields = false;
314
		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
315
		$current_tab = 'event-archives';
316
317
		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
318
			$current_tab = 'search';
319
		}/**/
320
321
		$removed_args = array(
322
			'action',
323
			'customlink-tab',
324
			'edit-menu-item',
325
			'menu-item',
326
			'page-tab',
327
			'_wpnonce',
328
		);
329
330
		?>
331
		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
332
			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
333
				<li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>>
334
					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
335
						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
336
					</a>
337
				</li>
338
			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
339
				<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
340
					<a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all">
341
						<?php _e( 'View All' ); ?>
342
					</a>
343
				</li>
344
				<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
345
					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-search" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-extra-nav-menu-pages-search">
346
						<?php _e( 'Search'); ?>
347
					</a>
348
				</li> -->
349
			</ul><!-- .posttype-tabs -->
350
 			<?php */ ?>
351
352
			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
353
			echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
354
			?>">
355
				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
356
					<?php
357
					$pages = $this->_get_extra_nav_menu_pages_items();
358
					$args['walker'] = $walker;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $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...
359
					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
360
					?>
361
				</ul>
362
			</div><!-- /.tabs-panel -->
363
364
			<p class="button-controls">
365
				<span class="list-controls">
366
					<a href="<?php
367
						echo esc_url( add_query_arg(
368
							array(
369
								'extra-nav-menu-pages-tab' => 'event-archives',
370
								'selectall' => 1,
371
							),
372
							remove_query_arg( $removed_args )
373
						));
374
					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
375
				</span>
376
377
				<span class="add-to-menu">
378
					<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" />
379
					<span class="spinner"></span>
380
				</span>
381
			</p>
382
383
		</div><!-- /.posttypediv -->
384
385
		<?php
386
	}
387
388
389
390
	/**
391
	 * Returns an array of event archive nav items.
392
	 *
393
	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever method we use for getting the extra nav menu items
394
	 * @return array
395
	 */
396 View Code Duplication
	private function _get_extra_nav_menu_pages_items() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
		$menuitems[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$menuitems was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menuitems = 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...
398
			'title' => __('Event List', 'event_espresso'),
399
			'url' => get_post_type_archive_link( 'espresso_events' ),
400
			'description' => __('Archive page for all events.', 'event_espresso')
401
		);
402
		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
403
	}
404
405
406
407
	/**
408
	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with the properties and converts it to the menu item object.
409
	 *
410
	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
411
	 * @param $menu_item_values
412
	 * @return stdClass
413
	 */
414
	private function _setup_extra_nav_menu_pages_items( $menu_item_values ) {
415
		$menu_item = new stdClass();
416
		$keys = array(
417
			'ID' => 0,
418
			'db_id' => 0,
419
			'menu_item_parent' => 0,
420
			'object_id' => -1,
421
			'post_parent' => 0,
422
			'type' => 'custom',
423
			'object' => '',
424
			'type_label' => __('Extra Nav Menu Item', 'event_espresso'),
425
			'title' => '',
426
			'url' => '',
427
			'target' => '',
428
			'attr_title' => '',
429
			'description' => '',
430
			'classes' => array(),
431
			'xfn' => ''
432
		);
433
434
		foreach ( $keys as $key => $value) {
435
			$menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value;
436
		}
437
		return $menu_item;
438
	}
439
440
441
	/**
442
	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an EE_Admin_Page route is called.
443
	 *
444
	 * @return void
445
	 */
446
	public function route_admin_request() {}
447
448
449
450
	/**
451
	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
452
	 * @return void
453
	 */
454
	public function wp_loaded() {}
455
456
457
458
459
	/**
460
	* admin_init
461
	*
462
	* @access public
463
	* @return void
464
	*/
465
	public function admin_init() {
466
467
		/**
468
		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
469
		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
470
		 * - check if doing post processing.
471
		 * - check if doing post processing of one of EE CPTs
472
		 * - instantiate the corresponding EE CPT model for the post_type being processed.
473
		 */
474
		if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) {
475
			EE_Registry::instance()->load_core( 'Register_CPTs' );
476
			EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
477
		}
478
479
480
		/**
481
		 * This code is for removing any set EE critical pages from the "Static Page" option dropdowns on the
482
		 * 'options-reading.php' core WordPress admin settings page.  This is for user-proofing.
483
		 */
484
		global $pagenow;
485
		if ( $pagenow === 'options-reading.php' ) {
486
			add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
487
		}
488
489
	}
490
491
492
	/**
493
	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
494
	 *
495
	 * @param string $output  Current output.
496
	 * @return string
497
	 */
498
	public function modify_dropdown_pages( $output ) {
499
		//get critical pages
500
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
501
502
		//split current output by line break for easier parsing.
503
		$split_output = explode( "\n", $output );
504
505
		//loop through to remove any critical pages from the array.
506
		foreach ( $critical_pages as $page_id ) {
507
			$needle = 'value="' . $page_id . '"';
508
			foreach( $split_output as $key => $haystack ) {
509
				if( strpos( $haystack, $needle ) !== false ) {
510
					unset( $split_output[$key] );
511
				}
512
			}
513
		}
514
515
		//replace output with the new contents
516
		return implode( "\n", $split_output );
517
	}
518
519
520
521
	/**
522
	 * enqueue all admin scripts that need loaded for admin pages
523
	 *
524
	 * @access public
525
	 * @return void
526
	 */
527
	public function enqueue_admin_scripts() {
528
		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
529
		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
530
		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
531
		// register cookie script for future dependencies
532
		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
533
		// jquery_validate loading is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
534
		if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
535
			// register jQuery Validate
536
			wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE);
537
		}
538
		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' );
539
		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
540
			//joyride style
541
			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
542
			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
543
			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
544
			//joyride JS
545
			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
546
			// wanna go for a joyride?
547
			wp_enqueue_style('ee-joyride-css');
548
			wp_enqueue_script('jquery-joyride');
549
		}
550
		//qtip is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtips', '__return_true' );
551
		if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) {
552
			EE_Registry::instance()->load_helper('Qtip_Loader');
553
			EEH_Qtip_Loader::instance()->register_and_enqueue();
554
		}
555
		//accounting.js library
556
		// @link http://josscrowcroft.github.io/accounting.js/
557
		if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) {
558
			wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE );
559
			wp_register_script( 'ee-accounting-core', EE_THIRD_PARTY_URL . 'accounting/accounting.js', array('underscore'), '0.3.2', TRUE );
560
			wp_enqueue_script( 'ee-accounting' );
561
			// array of settings to get converted to JSON array via wp_localize_script
562
			$currency_config = array(
563
				'currency' => array(
564
					'symbol' => EE_Registry::instance()->CFG->currency->sign,
565
					'format' => array(
566
						'pos' => EE_Registry::instance()->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
567
						'neg' => EE_Registry::instance()->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
568
						'zero' => EE_Registry::instance()->CFG->currency->sign_b4 ? '%s--' : '--%s'
569
						 ),
570
					'decimal' => EE_Registry::instance()->CFG->currency->dec_mrk,
571
					'thousand' => EE_Registry::instance()->CFG->currency->thsnds,
572
					'precision' => EE_Registry::instance()->CFG->currency->dec_plc
573
					),
574
				'number' => array(
575
					'precision' => EE_Registry::instance()->CFG->currency->dec_plc,
576
					'thousand' => EE_Registry::instance()->CFG->currency->thsnds,
577
					'decimal' => EE_Registry::instance()->CFG->currency->dec_mrk
578
					)
579
				);
580
			wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
581
		}
582
	}
583
584
585
586
	/**
587
	 * 	display_admin_notices
588
	 *
589
	 *  @access 	public
590
	 *  @return 	string
591
	 */
592
	public function display_admin_notices() {
593
		echo EE_Error::get_notices();
594
	}
595
596
597
598
	/**
599
	 * 	get_persistent_admin_notices
600
	 *
601
	 *  	@access 	public
602
	 *  	@return 		void
603
	 */
604
	public function get_persistent_admin_notices() {
605
		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
606
		$args = array(
607
			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
608
			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
609
		);
610
		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
611
		echo EE_Error::get_persistent_admin_notices( $return_url );
612
	}
613
614
615
616
	/**
617
	* 	dismiss_persistent_admin_notice
618
	*
619
	*	@access 	public
620
	* 	@return 		void
621
	*/
622
	public function dismiss_ee_nag_notice_callback() {
623
		EE_Error::dismiss_persistent_admin_notice();
624
	}
625
626
627
628
	/**
629
	 * @param $elements
630
	 * @return array
631
	 */
632
	public function dashboard_glance_items( $elements ) {
633
		$events = EEM_Event::instance()->count();
634
		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = 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...
635
		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
636
		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
637
		$registrations = EEM_Registration::instance()->count(
638
			array(
639
				array(
640
					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
641
				)
642
			)
643
		);
644
		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
645
		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
646
		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
647
648
		$items = apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
649
650
		foreach ( $items as $type => $item_properties ) {
651
			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
652
		}
653
		return $elements;
654
	}
655
656
657
	/**
658
	 *    check_for_invalid_datetime_formats
659
	 *
660
	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that their selected format can be parsed by PHP
661
	 *
662
	 * @access    public
663
	 * @param    $value
664
	 * @param    $option
665
	 * @throws EE_Error
666
	 * @return    string
667
	 */
668
	public function check_for_invalid_datetime_formats( $value, $option ) {
669
		EE_Registry::instance()->load_helper( 'DTT_Helper' );
670
		// check for date_format or time_format
671
		switch ( $option ) {
672
			case 'date_format' :
673
				$date_time_format = $value . ' ' . get_option('time_format');
674
				break;
675
			case 'time_format' :
676
				$date_time_format = get_option('date_format') . ' ' . $value;
677
				break;
678
			default :
679
				$date_time_format = FALSE;
680
		}
681
		// do we have a date_time format to check ?
682
		if ( $date_time_format ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date_time_format of type string|false 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...
683
			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
684
685
			if ( is_array( $error_msg ) ) {
686
				$msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format  ) . '</p><p><ul>';
687
688
689
				foreach ( $error_msg as $error ) {
690
					$msg .= '<li>' . $error . '</li>';
691
				}
692
693
				$msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>';
694
695
				// trigger WP settings error
696
				add_settings_error(
697
					'date_format',
698
					'date_format',
699
					$msg
700
				);
701
702
				// set format to something valid
703
				switch ( $option ) {
704
					case 'date_format' :
705
						$value = 'F j, Y';
706
						break;
707
					case 'time_format' :
708
						$value = 'g:i a';
709
						break;
710
				}
711
			}
712
		}
713
		return $value;
714
	}
715
716
717
718
	/**
719
	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
720
	 *
721
	 * @access    public
722
	 * @param $content
723
	 * @return    string
724
	 */
725
	public function its_eSpresso( $content ) {
726
		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
727
	}
728
729
730
731
	/**
732
	 * 	espresso_admin_footer
733
	 *
734
	 *  @access 	public
735
	 *  @return 	string
736
	 */
737
	public function espresso_admin_footer() {
738
		return sprintf(
739
			__( 'Event Registration and Ticketing Powered by %sEvent Registration Powered by Event Espresso%s', 'event_espresso' ),
740
			'<a href="https://eventespresso.com/" title="',
741
			'">' . EVENT_ESPRESSO_POWERED_BY . '</a>'
742
		);
743
	}
744
745
746
747
	/**
748
	 * static method for registering ee admin page.
749
	 *
750
	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
751
	 *
752
	 * @since      4.3.0
753
	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
754
	 * @see        EE_Register_Admin_Page::register()
755
	 *
756
	 * @param       $page_basename
757
	 * @param       $page_path
758
	 * @param array $config
759
	 * @return void
760
	 */
761
	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
762
		EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' );
763
		if ( class_exists( 'EE_Register_Admin_Page' ) ) {
764
			$config['page_path'] = $page_path;
765
		}
766
		EE_Register_Admin_Page::register( $page_basename, $config );
767
768
	}
769
770
771
}
772
// End of file EE_Admin.core.php
773
// Location: /core/admin/EE_Admin.core.php
774