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