Completed
Branch BUG-10725-paypal-express-dupli... (d2dd3a)
by
unknown
12:24 queued 12s
created

EE_Admin::enqueue_admin_scripts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
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
		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
67
		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
68
		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
69
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
70
		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
71
		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
72
		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
73
		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
74
75
		//reset Environment config (we only do this on admin page loads);
76
		EE_Registry::instance()->CFG->environment->recheck_values();
77
78
		do_action( 'AHEE__EE_Admin__loaded' );
79
	}
80
81
82
83
84
85
	/**
86
	 * _define_all_constants
87
	 * define constants that are set globally for all admin pages
88
	 *
89
	 * @access private
90
	 * @return void
91
	 */
92
	private function _define_all_constants() {
93
		define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
94
		define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
95
		define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
96
		define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
97
		define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ));
98
	}
99
100
101
102
	/**
103
	 *    filter_plugin_actions - adds links to the Plugins page listing
104
	 *
105
	 * @access 	public
106
	 * @param 	array 	$links
107
	 * @param 	string 	$plugin
108
	 * @return 	array
109
	 */
110
	public function filter_plugin_actions( $links, $plugin ) {
111
		// set $main_file in stone
112
		static $main_file;
113
		// if $main_file is not set yet
114
		if ( ! $main_file ) {
115
			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
116
		}
117
		 if ( $plugin === $main_file ) {
118
		 	// compare current plugin to this one
119
			if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) {
120
				$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>';
121
				array_unshift( $links, $maintenance_link );
122
			} else {
123
				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
124
				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
125
				// add before other links
126
				array_unshift( $links, $org_settings_link, $events_link );
127
			}
128
		}
129
		return $links;
130
	}
131
132
133
134
	/**
135
	 *	_get_request
136
	 *
137
	 *	@access public
138
	 *	@return void
139
	 */
140
	public function get_request() {
141
		EE_Registry::instance()->load_core( 'Request_Handler' );
142
		EE_Registry::instance()->load_core( 'CPT_Strategy' );
143
	}
144
145
146
147
	/**
148
	 *    hide_admin_pages_except_maintenance_mode
149
	 *
150
	 * @access public
151
	 * @param array $admin_page_folder_names
152
	 * @return array
153
	 */
154
	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
155
		return array(
156
			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
157
			'about' => EE_ADMIN_PAGES . 'about' . DS,
158
			'support' => EE_ADMIN_PAGES . 'support' . DS
159
		);
160
	}
161
162
163
164
	/**
165
	* init- should fire after shortcode, module,  addon, other plugin (default priority), and even EE_Front_Controller's init phases have run
166
	*
167
	* @access public
168
	* @return void
169
	*/
170
	public function init() {
171
		//only enable most of the EE_Admin IF we're not in full maintenance mode
172
		if ( EE_Maintenance_Mode::instance()->models_can_query() ){
173
			//ok so we want to enable the entire admin
174
			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
175
			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
176
			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
177
			//at a glance dashboard widget
178
			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 );
179
			//filter for get_edit_post_link used on comments for custom post types
180
			add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 );
181
		}
182
		// run the admin page factory but ONLY if we are doing an ee admin ajax request
183
		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
184
			try {
185
				//this loads the controller for the admin pages which will setup routing etc
186
				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
187
			} catch ( EE_Error $e ) {
188
				$e->get_error();
189
			}
190
		}
191
		add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
192
		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
193
		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
194
		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
195
		//exclude EE critical pages from all nav menus and wp_list_pages
196
		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
197
	}
198
199
200
201
202
	/**
203
	 * 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.
204
	 *
205
	 * 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.
206
	 * @param  object $post_type WP post type object
207
	 * @return object            WP post type object
208
	 */
209
	public function remove_pages_from_nav_menu( $post_type ) {
210
		//if this isn't the "pages" post type let's get out
211
		if ( $post_type->name !== 'page' ) {
212
			return $post_type;
213
		}
214
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
215
216
		$post_type->_default_query = array(
217
			'post__not_in' => $critical_pages );
218
		return $post_type;
219
	}
220
221
222
223
	/**
224
	 * 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
225
	 *
226
	 * @access public
227
	 * @return void
228
	 */
229
	public function enable_hidden_ee_nav_menu_metaboxes() {
230
		global $wp_meta_boxes, $pagenow;
231
		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
232
			return;
233
		}
234
		$user = wp_get_current_user();
235
		//has this been done yet?
236
		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
237
			return;
238
		}
239
240
		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
241
		$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' ) );
242
243
		if ( is_array( $hidden_meta_boxes ) ) {
244
			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
245
				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
246
					unset( $hidden_meta_boxes[ $key ] );
247
				}
248
			}
249
		}
250
251
		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
252
		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
253
	}
254
255
256
257
258
259
260
	/**
261
	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
262
	 *
263
	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
264
	 *
265
	 * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by addons etc.
266
	 *
267
	 * @access public
268
	 * @return void
269
	 */
270
	public function register_custom_nav_menu_boxes() {
271
		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
272
	}
273
274
275
276
277
	/**
278
	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
279
	 *
280
	 * @since   4.3.0
281
	 *
282
	 * @param string $link    the original link generated by wp
283
	 * @param int      $id      post id
284
	 *
285
	 * @return string  the (maybe) modified link
286
	 */
287
	public function modify_edit_post_link( $link, $id ) {
288
		if ( ! $post = get_post( $id ) ){
289
			return $link;
290
		}
291
		if ( $post->post_type === 'espresso_attendees' ) {
292
			$query_args = array(
293
				'action' => 'edit_attendee',
294
				'post' => $id
295
			);
296
			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
297
		}
298
		return $link;
299
	}
300
301
302
303
304
	public function ee_cpt_archive_pages() {
305
		global $nav_menu_selected_id;
306
307
		$db_fields = false;
308
		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
309
		$current_tab = 'event-archives';
310
311
		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
312
			$current_tab = 'search';
313
		}/**/
314
315
		$removed_args = array(
316
			'action',
317
			'customlink-tab',
318
			'edit-menu-item',
319
			'menu-item',
320
			'page-tab',
321
			'_wpnonce',
322
		);
323
324
		?>
325
		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
326
			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
327
				<li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>>
328
					<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">
329
						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
330
					</a>
331
				</li>
332
			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
333
				<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
334
					<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">
335
						<?php _e( 'View All' ); ?>
336
					</a>
337
				</li>
338
				<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
339
					<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">
340
						<?php _e( 'Search'); ?>
341
					</a>
342
				</li> -->
343
			</ul><!-- .posttype-tabs -->
344
 			<?php */ ?>
345
346
			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
347
			echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
348
			?>">
349
				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
350
					<?php
351
					$pages = $this->_get_extra_nav_menu_pages_items();
352
					$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...
353
					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
354
					?>
355
				</ul>
356
			</div><!-- /.tabs-panel -->
357
358
			<p class="button-controls">
359
				<span class="list-controls">
360
					<a href="<?php
361
						echo esc_url( add_query_arg(
362
							array(
363
								'extra-nav-menu-pages-tab' => 'event-archives',
364
								'selectall' => 1,
365
							),
366
							remove_query_arg( $removed_args )
367
						));
368
					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
369
				</span>
370
371
				<span class="add-to-menu">
372
					<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' ); ?>" />
373
					<span class="spinner"></span>
374
				</span>
375
			</p>
376
377
		</div><!-- /.posttypediv -->
378
379
		<?php
380
	}
381
382
383
384
	/**
385
	 * Returns an array of event archive nav items.
386
	 *
387
	 * @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
388
	 * @return array
389
	 */
390 View Code Duplication
	private function _get_extra_nav_menu_pages_items() {
391
		$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...
392
			'title' => __('Event List', 'event_espresso'),
393
			'url' => get_post_type_archive_link( 'espresso_events' ),
394
			'description' => __('Archive page for all events.', 'event_espresso')
395
		);
396
		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
397
	}
398
399
400
401
	/**
402
	 * 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.
403
	 *
404
	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
405
	 * @param $menu_item_values
406
	 * @return stdClass
407
	 */
408
	private function _setup_extra_nav_menu_pages_items( $menu_item_values ) {
409
		$menu_item = new stdClass();
410
		$keys = array(
411
			'ID' => 0,
412
			'db_id' => 0,
413
			'menu_item_parent' => 0,
414
			'object_id' => -1,
415
			'post_parent' => 0,
416
			'type' => 'custom',
417
			'object' => '',
418
			'type_label' => __('Extra Nav Menu Item', 'event_espresso'),
419
			'title' => '',
420
			'url' => '',
421
			'target' => '',
422
			'attr_title' => '',
423
			'description' => '',
424
			'classes' => array(),
425
			'xfn' => ''
426
		);
427
428
		foreach ( $keys as $key => $value) {
429
			$menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value;
430
		}
431
		return $menu_item;
432
	}
433
434
435
	/**
436
	 * 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.
437
	 *
438
	 * @return void
439
	 */
440
	public function route_admin_request() {}
441
442
443
444
	/**
445
	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
446
	 * @return void
447
	 */
448
	public function wp_loaded() {}
449
450
451
452
453
	/**
454
	* admin_init
455
	*
456
	* @access public
457
	* @return void
458
	*/
459
	public function admin_init() {
460
461
		/**
462
		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
463
		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
464
		 * - check if doing post processing.
465
		 * - check if doing post processing of one of EE CPTs
466
		 * - instantiate the corresponding EE CPT model for the post_type being processed.
467
		 */
468
		if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) {
469
			EE_Registry::instance()->load_core( 'Register_CPTs' );
470
			EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
471
		}
472
473
474
		/**
475
		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
476
         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical Pages"
477
         * tab in the EE General Settings Admin page.
478
         * This is for user-proofing.
479
		 */
480
        add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
481
482
	}
483
484
485
	/**
486
	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
487
	 *
488
	 * @param string $output  Current output.
489
	 * @return string
490
	 */
491
	public function modify_dropdown_pages( $output ) {
492
		//get critical pages
493
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
494
495
		//split current output by line break for easier parsing.
496
		$split_output = explode( "\n", $output );
497
498
		//loop through to remove any critical pages from the array.
499
		foreach ( $critical_pages as $page_id ) {
500
			$needle = 'value="' . $page_id . '"';
501
			foreach( $split_output as $key => $haystack ) {
502
				if( strpos( $haystack, $needle ) !== false ) {
503
					unset( $split_output[$key] );
504
				}
505
			}
506
		}
507
508
		//replace output with the new contents
509
		return implode( "\n", $split_output );
510
	}
511
512
513
514
	/**
515
	 * enqueue all admin scripts that need loaded for admin pages
516
	 *
517
	 * @access public
518
	 * @return void
519
	 */
520
	public function enqueue_admin_scripts() {
521
		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
522
		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
523
		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
524
		// register cookie script for future dependencies
525
		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
526
		//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' );
527
		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
528
			//joyride style
529
			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
530
			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
531
			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
532
			//joyride JS
533
			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
534
			// wanna go for a joyride?
535
			wp_enqueue_style('ee-joyride-css');
536
			wp_enqueue_script('jquery-joyride');
537
		}
538
	}
539
540
541
542
	/**
543
	 * 	display_admin_notices
544
	 *
545
	 *  @access 	public
546
	 *  @return 	string
547
	 */
548
	public function display_admin_notices() {
549
		echo EE_Error::get_notices();
550
	}
551
552
553
554
	/**
555
	 * 	get_persistent_admin_notices
556
	 *
557
	 *  	@access 	public
558
	 *  	@return 		void
559
	 */
560
	public function get_persistent_admin_notices() {
561
		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
562
		$args = array(
563
			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
564
			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
565
		);
566
		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
567
		echo EE_Error::get_persistent_admin_notices( $return_url );
568
	}
569
570
571
572
	/**
573
	* 	dismiss_persistent_admin_notice
574
	*
575
	*	@access 	public
576
	* 	@return 		void
577
	*/
578
	public function dismiss_ee_nag_notice_callback() {
579
		EE_Error::dismiss_persistent_admin_notice();
580
	}
581
582
583
584
    /**
585
     * @param array $elements
586
     * @return array
587
     * @throws \EE_Error
588
     */
589
	public function dashboard_glance_items($elements) {
590
        $elements = is_array($elements) ? $elements : array($elements);
591
		$events = EEM_Event::instance()->count();
592
		$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...
593
		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
594
		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
595
		$registrations = EEM_Registration::instance()->count(
596
			array(
597
				array(
598
					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
599
				)
600
			)
601
		);
602
		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
603
		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
604
		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
605
606
		$items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
607
608
		foreach ( $items as $type => $item_properties ) {
609
			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
610
		}
611
		return $elements;
612
	}
613
614
615
	/**
616
	 *    check_for_invalid_datetime_formats
617
	 *
618
	 *    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
619
	 *
620
	 * @access    public
621
	 * @param    $value
622
	 * @param    $option
623
	 * @throws EE_Error
624
	 * @return    string
625
	 */
626
	public function check_for_invalid_datetime_formats( $value, $option ) {
627
		// check for date_format or time_format
628
		switch ( $option ) {
629
			case 'date_format' :
630
				$date_time_format = $value . ' ' . get_option('time_format');
631
				break;
632
			case 'time_format' :
633
				$date_time_format = get_option('date_format') . ' ' . $value;
634
				break;
635
			default :
636
				$date_time_format = FALSE;
637
		}
638
		// do we have a date_time format to check ?
639
		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...
640
			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
641
642
			if ( is_array( $error_msg ) ) {
643
				$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>';
644
645
646
				foreach ( $error_msg as $error ) {
647
					$msg .= '<li>' . $error . '</li>';
648
				}
649
650
				$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>';
651
652
				// trigger WP settings error
653
				add_settings_error(
654
					'date_format',
655
					'date_format',
656
					$msg
657
				);
658
659
				// set format to something valid
660
				switch ( $option ) {
661
					case 'date_format' :
662
						$value = 'F j, Y';
663
						break;
664
					case 'time_format' :
665
						$value = 'g:i a';
666
						break;
667
				}
668
			}
669
		}
670
		return $value;
671
	}
672
673
674
675
	/**
676
	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
677
	 *
678
	 * @access    public
679
	 * @param $content
680
	 * @return    string
681
	 */
682
	public function its_eSpresso( $content ) {
683
		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
684
	}
685
686
687
688
	/**
689
	 * 	espresso_admin_footer
690
	 *
691
	 *  @access 	public
692
	 *  @return 	string
693
	 */
694
	public function espresso_admin_footer() {
695
		return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' ));
696
	}
697
698
699
700
	/**
701
	 * static method for registering ee admin page.
702
	 *
703
	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
704
	 *
705
	 * @since      4.3.0
706
	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
707
	 * @see        EE_Register_Admin_Page::register()
708
	 *
709
	 * @param       $page_basename
710
	 * @param       $page_path
711
	 * @param array $config
712
	 * @return void
713
	 */
714
	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
715
		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' );
716
		if ( class_exists( 'EE_Register_Admin_Page' ) ) {
717
			$config['page_path'] = $page_path;
718
		}
719
		EE_Register_Admin_Page::register( $page_basename, $config );
720
721
	}
722
723
724
725
	/**
726
	 * @deprecated 4.8.41
727
	 * @access     public
728
	 * @param  int      $post_ID
729
	 * @param  \WP_Post $post
730
	 * @return void
731
	 */
732
	public static function parse_post_content_on_save( $post_ID, $post ) {
733
		EE_Error::doing_it_wrong(
734
			__METHOD__,
735
			__('Usage is deprecated', 'event_espresso'),
736
			'4.8.41'
737
		);
738
	}
739
740
741
742
	/**
743
	 * @deprecated 4.8.41
744
	 * @access     public
745
	 * @param  $option
746
	 * @param  $old_value
747
	 * @param  $value
748
	 * @return void
749
	 */
750
	public function reset_page_for_posts_on_change( $option, $old_value, $value ) {
751
		EE_Error::doing_it_wrong(
752
			__METHOD__,
753
			__('Usage is deprecated', 'event_espresso'),
754
			'4.8.41'
755
		);
756
	}
757
758
}
759
// End of file EE_Admin.core.php
760
// Location: /core/admin/EE_Admin.core.php
761