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