Completed
Branch FET-9795-new-interfaces (4c886e)
by
unknown
633:15 queued 618:38
created

EE_Admin::init()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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