1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use EventEspresso\core\interfaces\InterminableInterface; |
4
|
|
|
|
5
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.'); |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* EE_Admin |
9
|
|
|
* |
10
|
|
|
* @package Event Espresso |
11
|
|
|
* @subpackage /core/admin/ |
12
|
|
|
* @author Brent Christensen |
13
|
|
|
* ------------------------------------------------------------------------ |
14
|
|
|
*/ |
15
|
|
|
final class EE_Admin implements InterminableInterface |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @access private |
20
|
|
|
* @var EE_Admin $_instance |
21
|
|
|
*/ |
22
|
|
|
private static $_instance; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
*@ singleton method used to instantiate class object |
27
|
|
|
*@ access public |
28
|
|
|
*@ return class instance |
29
|
|
|
* |
30
|
|
|
* @throws \EE_Error |
31
|
|
|
*/ |
32
|
|
|
public static function instance() |
33
|
|
|
{ |
34
|
|
|
// check if class object is instantiated |
35
|
|
|
if (! self::$_instance instanceof EE_Admin) { |
36
|
|
|
self::$_instance = new self(); |
37
|
|
|
} |
38
|
|
|
return self::$_instance; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return EE_Admin |
44
|
|
|
* @throws EE_Error |
45
|
|
|
*/ |
46
|
|
|
public static function reset() |
47
|
|
|
{ |
48
|
|
|
self::$_instance = null; |
49
|
|
|
return self::instance(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* class constructor |
55
|
|
|
* |
56
|
|
|
* @throws \EE_Error |
57
|
|
|
*/ |
58
|
|
|
protected function __construct() |
59
|
|
|
{ |
60
|
|
|
// define global EE_Admin constants |
61
|
|
|
$this->_define_all_constants(); |
62
|
|
|
// set autoloaders for our admin page classes based on included path information |
63
|
|
|
EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
64
|
|
|
// admin hooks |
65
|
|
|
add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
66
|
|
|
// load EE_Request_Handler early |
67
|
|
|
add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
68
|
|
|
add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
69
|
|
|
add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
70
|
|
|
add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
71
|
|
|
add_action('admin_init', array($this, 'admin_init'), 100); |
72
|
|
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
73
|
|
|
add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
74
|
|
|
add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
75
|
|
|
add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
76
|
|
|
add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
77
|
|
|
|
78
|
|
|
//reset Environment config (we only do this on admin page loads); |
79
|
|
|
EE_Registry::instance()->CFG->environment->recheck_values(); |
80
|
|
|
|
81
|
|
|
do_action('AHEE__EE_Admin__loaded'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* _define_all_constants |
87
|
|
|
* define constants that are set globally for all admin pages |
88
|
|
|
* |
89
|
|
|
* @access private |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
private function _define_all_constants() |
93
|
|
|
{ |
94
|
|
|
if (! defined('EE_ADMIN_URL')) { |
95
|
|
|
define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
96
|
|
|
define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
97
|
|
|
define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
98
|
|
|
define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
99
|
|
|
define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* filter_plugin_actions - adds links to the Plugins page listing |
106
|
|
|
* |
107
|
|
|
* @access public |
108
|
|
|
* @param array $links |
109
|
|
|
* @param string $plugin |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
public function filter_plugin_actions($links, $plugin) |
113
|
|
|
{ |
114
|
|
|
// set $main_file in stone |
115
|
|
|
static $main_file; |
116
|
|
|
// if $main_file is not set yet |
117
|
|
|
if (! $main_file) { |
118
|
|
|
$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
119
|
|
|
} |
120
|
|
|
if ($plugin === $main_file) { |
121
|
|
|
// compare current plugin to this one |
122
|
|
|
if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
123
|
|
|
$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
124
|
|
|
. ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
125
|
|
|
. esc_html__('Maintenance Mode Active', 'event_espresso') |
126
|
|
|
. '</a>'; |
127
|
|
|
array_unshift($links, $maintenance_link); |
128
|
|
|
} else { |
129
|
|
|
$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
130
|
|
|
. esc_html__('Settings', 'event_espresso') |
131
|
|
|
. '</a>'; |
132
|
|
|
$events_link = '<a href="admin.php?page=espresso_events">' |
133
|
|
|
. esc_html__('Events', 'event_espresso') |
134
|
|
|
. '</a>'; |
135
|
|
|
// add before other links |
136
|
|
|
array_unshift($links, $org_settings_link, $events_link); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
return $links; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* _get_request |
145
|
|
|
* |
146
|
|
|
* @access public |
147
|
|
|
* @return void |
148
|
|
|
* @throws EE_Error |
149
|
|
|
* @throws ReflectionException |
150
|
|
|
*/ |
151
|
|
|
public function get_request() |
152
|
|
|
{ |
153
|
|
|
EE_Registry::instance()->load_core('Request_Handler'); |
154
|
|
|
EE_Registry::instance()->load_core('CPT_Strategy'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* hide_admin_pages_except_maintenance_mode |
160
|
|
|
* |
161
|
|
|
* @access public |
162
|
|
|
* @param array $admin_page_folder_names |
163
|
|
|
* @return array |
164
|
|
|
*/ |
165
|
|
|
public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
166
|
|
|
{ |
167
|
|
|
return array( |
168
|
|
|
'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
169
|
|
|
'about' => EE_ADMIN_PAGES . 'about' . DS, |
170
|
|
|
'support' => EE_ADMIN_PAGES . 'support' . DS, |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* init- should fire after shortcode, module, addon, other plugin (default priority), and even |
177
|
|
|
* EE_Front_Controller's init phases have run |
178
|
|
|
* |
179
|
|
|
* @access public |
180
|
|
|
* @return void |
181
|
|
|
* @throws EE_Error |
182
|
|
|
* @throws ReflectionException |
183
|
|
|
*/ |
184
|
|
|
public function init() |
185
|
|
|
{ |
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
|
|
|
* this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
217
|
|
|
* the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
218
|
|
|
* wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
219
|
|
|
* to override any queries found in the existing query for the given post type. Note that _default_query is not a |
220
|
|
|
* normal property on the post_type object. It's found ONLY in this particular context. |
221
|
|
|
* |
222
|
|
|
* @param object $post_type WP post type object |
223
|
|
|
* @return object WP post type object |
224
|
|
|
*/ |
225
|
|
|
public function remove_pages_from_nav_menu($post_type) |
226
|
|
|
{ |
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
|
|
|
); |
236
|
|
|
return $post_type; |
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 |
242
|
|
|
* metaboxes get shown as well |
243
|
|
|
* |
244
|
|
|
* @access public |
245
|
|
|
* @return void |
246
|
|
|
*/ |
247
|
|
|
public function enable_hidden_ee_nav_menu_metaboxes() |
248
|
|
|
{ |
249
|
|
|
global $wp_meta_boxes, $pagenow; |
250
|
|
|
if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
251
|
|
|
return; |
252
|
|
|
} |
253
|
|
|
$user = wp_get_current_user(); |
254
|
|
|
//has this been done yet? |
255
|
|
|
if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
256
|
|
|
return; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
260
|
|
|
$initial_meta_boxes = apply_filters( |
261
|
|
|
'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
262
|
|
|
array( |
263
|
|
|
'nav-menu-theme-locations', |
264
|
|
|
'add-page', |
265
|
|
|
'add-custom-links', |
266
|
|
|
'add-category', |
267
|
|
|
'add-espresso_events', |
268
|
|
|
'add-espresso_venues', |
269
|
|
|
'add-espresso_event_categories', |
270
|
|
|
'add-espresso_venue_categories', |
271
|
|
|
'add-post-type-post', |
272
|
|
|
'add-post-type-page', |
273
|
|
|
) |
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( |
301
|
|
|
'add-extra-nav-menu-pages', |
302
|
|
|
esc_html__('Event Espresso Pages', 'event_espresso'), |
303
|
|
|
array($this, 'ee_cpt_archive_pages'), |
304
|
|
|
'nav-menus', |
305
|
|
|
'side', |
306
|
|
|
'core' |
307
|
|
|
); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Use this to edit the post link for our cpts so that the edit link points to the correct page. |
313
|
|
|
* |
314
|
|
|
* @since 4.3.0 |
315
|
|
|
* @param string $link the original link generated by wp |
316
|
|
|
* @param int $id post id |
317
|
|
|
* @return string the (maybe) modified link |
318
|
|
|
*/ |
319
|
|
|
public function modify_edit_post_link($link, $id) |
320
|
|
|
{ |
321
|
|
|
if (! $post = get_post($id)) { |
322
|
|
|
return $link; |
323
|
|
|
} |
324
|
|
|
if ($post->post_type === 'espresso_attendees') { |
325
|
|
|
$query_args = array( |
326
|
|
|
'action' => 'edit_attendee', |
327
|
|
|
'post' => $id, |
328
|
|
|
); |
329
|
|
|
return EEH_URL::add_query_args_and_nonce( |
330
|
|
|
$query_args, |
331
|
|
|
admin_url('admin.php?page=espresso_registrations') |
332
|
|
|
); |
333
|
|
|
} |
334
|
|
|
return $link; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
public function ee_cpt_archive_pages() |
339
|
|
|
{ |
340
|
|
|
global $nav_menu_selected_id; |
341
|
|
|
|
342
|
|
|
$db_fields = false; |
343
|
|
|
$walker = new Walker_Nav_Menu_Checklist($db_fields); |
344
|
|
|
$current_tab = 'event-archives'; |
345
|
|
|
|
346
|
|
|
/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
347
|
|
|
$current_tab = 'search'; |
348
|
|
|
}/**/ |
349
|
|
|
|
350
|
|
|
$removed_args = array( |
351
|
|
|
'action', |
352
|
|
|
'customlink-tab', |
353
|
|
|
'edit-menu-item', |
354
|
|
|
'menu-item', |
355
|
|
|
'page-tab', |
356
|
|
|
'_wpnonce', |
357
|
|
|
); |
358
|
|
|
|
359
|
|
|
?> |
360
|
|
|
<div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
361
|
|
|
<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
362
|
|
|
<li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
363
|
|
|
<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
364
|
|
|
href="<?php if ($nav_menu_selected_id) { |
365
|
|
|
echo esc_url( |
366
|
|
|
add_query_arg( |
367
|
|
|
'extra-nav-menu-pages-tab', |
368
|
|
|
'event-archives', |
369
|
|
|
remove_query_arg($removed_args) |
370
|
|
|
) |
371
|
|
|
); |
372
|
|
|
} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
373
|
|
|
<?php _e('Event Archive Pages', 'event_espresso'); ?> |
374
|
|
|
</a> |
375
|
|
|
</li> |
376
|
|
|
|
377
|
|
|
<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
378
|
|
|
echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
379
|
|
|
?>"> |
380
|
|
|
<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
381
|
|
|
<?php |
382
|
|
|
$pages = $this->_get_extra_nav_menu_pages_items(); |
383
|
|
|
$args['walker'] = $walker; |
|
|
|
|
384
|
|
|
echo walk_nav_menu_tree( |
385
|
|
|
array_map( |
386
|
|
|
array($this, '_setup_extra_nav_menu_pages_items'), |
387
|
|
|
$pages |
388
|
|
|
), |
389
|
|
|
0, |
390
|
|
|
(object) $args |
391
|
|
|
); |
392
|
|
|
?> |
393
|
|
|
</ul> |
394
|
|
|
</div><!-- /.tabs-panel --> |
395
|
|
|
|
396
|
|
|
<p class="button-controls"> |
397
|
|
|
<span class="list-controls"> |
398
|
|
|
<a href="<?php |
399
|
|
|
echo esc_url(add_query_arg( |
400
|
|
|
array( |
401
|
|
|
'extra-nav-menu-pages-tab' => 'event-archives', |
402
|
|
|
'selectall' => 1, |
403
|
|
|
), |
404
|
|
|
remove_query_arg($removed_args) |
405
|
|
|
)); |
406
|
|
|
?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
407
|
|
|
</span> |
408
|
|
|
<span class="add-to-menu"> |
409
|
|
|
<input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
410
|
|
|
class="button-secondary submit-add-to-menu right" |
411
|
|
|
value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" |
412
|
|
|
id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>"/> |
413
|
|
|
<span class="spinner"></span> |
414
|
|
|
</span> |
415
|
|
|
</p> |
416
|
|
|
|
417
|
|
|
</div><!-- /.posttypediv --> |
418
|
|
|
<?php |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Returns an array of event archive nav items. |
424
|
|
|
* |
425
|
|
|
* @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
426
|
|
|
* method we use for getting the extra nav menu items |
427
|
|
|
* @return array |
428
|
|
|
*/ |
429
|
|
|
private function _get_extra_nav_menu_pages_items() |
430
|
|
|
{ |
431
|
|
|
$menuitems[] = array( |
|
|
|
|
432
|
|
|
'title' => esc_html__('Event List', 'event_espresso'), |
433
|
|
|
'url' => get_post_type_archive_link('espresso_events'), |
434
|
|
|
'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
435
|
|
|
); |
436
|
|
|
return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
442
|
|
|
* the properties and converts it to the menu item object. |
443
|
|
|
* |
444
|
|
|
* @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
445
|
|
|
* @param $menu_item_values |
446
|
|
|
* @return stdClass |
447
|
|
|
*/ |
448
|
|
|
private function _setup_extra_nav_menu_pages_items($menu_item_values) |
449
|
|
|
{ |
450
|
|
|
$menu_item = new stdClass(); |
451
|
|
|
$keys = array( |
452
|
|
|
'ID' => 0, |
453
|
|
|
'db_id' => 0, |
454
|
|
|
'menu_item_parent' => 0, |
455
|
|
|
'object_id' => -1, |
456
|
|
|
'post_parent' => 0, |
457
|
|
|
'type' => 'custom', |
458
|
|
|
'object' => '', |
459
|
|
|
'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
460
|
|
|
'title' => '', |
461
|
|
|
'url' => '', |
462
|
|
|
'target' => '', |
463
|
|
|
'attr_title' => '', |
464
|
|
|
'description' => '', |
465
|
|
|
'classes' => array(), |
466
|
|
|
'xfn' => '', |
467
|
|
|
); |
468
|
|
|
|
469
|
|
|
foreach ($keys as $key => $value) { |
470
|
|
|
$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
471
|
|
|
} |
472
|
|
|
return $menu_item; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
478
|
|
|
* EE_Admin_Page route is called. |
479
|
|
|
* |
480
|
|
|
* @return void |
481
|
|
|
*/ |
482
|
|
|
public function route_admin_request() |
483
|
|
|
{ |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
489
|
|
|
* |
490
|
|
|
* @return void |
491
|
|
|
*/ |
492
|
|
|
public function wp_loaded() |
493
|
|
|
{ |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* admin_init |
499
|
|
|
* |
500
|
|
|
* @access public |
501
|
|
|
* @return void |
502
|
|
|
* @throws EE_Error |
503
|
|
|
* @throws ReflectionException |
504
|
|
|
*/ |
505
|
|
|
public function admin_init() |
506
|
|
|
{ |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
510
|
|
|
* so any hooking into core WP routes is taken care of. So in this next few lines of code: |
511
|
|
|
* - check if doing post processing. |
512
|
|
|
* - check if doing post processing of one of EE CPTs |
513
|
|
|
* - instantiate the corresponding EE CPT model for the post_type being processed. |
514
|
|
|
*/ |
515
|
|
|
if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
516
|
|
|
EE_Registry::instance()->load_core('Register_CPTs'); |
517
|
|
|
EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
523
|
|
|
* critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
524
|
|
|
* Pages" tab in the EE General Settings Admin page. |
525
|
|
|
* This is for user-proofing. |
526
|
|
|
*/ |
527
|
|
|
add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
533
|
|
|
* |
534
|
|
|
* @param string $output Current output. |
535
|
|
|
* @return string |
536
|
|
|
*/ |
537
|
|
|
public function modify_dropdown_pages($output) |
538
|
|
|
{ |
539
|
|
|
//get critical pages |
540
|
|
|
$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
541
|
|
|
|
542
|
|
|
//split current output by line break for easier parsing. |
543
|
|
|
$split_output = explode("\n", $output); |
544
|
|
|
|
545
|
|
|
//loop through to remove any critical pages from the array. |
546
|
|
|
foreach ($critical_pages as $page_id) { |
547
|
|
|
$needle = 'value="' . $page_id . '"'; |
548
|
|
|
foreach ($split_output as $key => $haystack) { |
549
|
|
|
if (strpos($haystack, $needle) !== false) { |
550
|
|
|
unset($split_output[$key]); |
551
|
|
|
} |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
//replace output with the new contents |
556
|
|
|
return implode("\n", $split_output); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* enqueue all admin scripts that need loaded for admin pages |
562
|
|
|
* |
563
|
|
|
* @access public |
564
|
|
|
* @return void |
565
|
|
|
*/ |
566
|
|
|
public function enqueue_admin_scripts() |
567
|
|
|
{ |
568
|
|
|
// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
569
|
|
|
// Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
570
|
|
|
// calls. |
571
|
|
|
wp_enqueue_script( |
572
|
|
|
'ee-inject-wp', |
573
|
|
|
EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
574
|
|
|
array('jquery'), |
575
|
|
|
EVENT_ESPRESSO_VERSION, |
576
|
|
|
true |
577
|
|
|
); |
578
|
|
|
// register cookie script for future dependencies |
579
|
|
|
wp_register_script( |
580
|
|
|
'jquery-cookie', |
581
|
|
|
EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
582
|
|
|
array('jquery'), |
583
|
|
|
'2.1', |
584
|
|
|
true |
585
|
|
|
); |
586
|
|
|
//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
587
|
|
|
// via: add_filter('FHEE_load_joyride', '__return_true' ); |
588
|
|
|
if (apply_filters('FHEE_load_joyride', false)) { |
589
|
|
|
//joyride style |
590
|
|
|
wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
591
|
|
|
wp_register_style( |
592
|
|
|
'ee-joyride-css', |
593
|
|
|
EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
594
|
|
|
array('joyride-css'), |
595
|
|
|
EVENT_ESPRESSO_VERSION |
596
|
|
|
); |
597
|
|
|
wp_register_script( |
598
|
|
|
'joyride-modernizr', |
599
|
|
|
EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
600
|
|
|
array(), |
601
|
|
|
'2.1', |
602
|
|
|
true |
603
|
|
|
); |
604
|
|
|
//joyride JS |
605
|
|
|
wp_register_script( |
606
|
|
|
'jquery-joyride', |
607
|
|
|
EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
608
|
|
|
array('jquery-cookie', 'joyride-modernizr'), |
609
|
|
|
'2.1', |
610
|
|
|
true |
611
|
|
|
); |
612
|
|
|
// wanna go for a joyride? |
613
|
|
|
wp_enqueue_style('ee-joyride-css'); |
614
|
|
|
wp_enqueue_script('jquery-joyride'); |
615
|
|
|
} |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* display_admin_notices |
621
|
|
|
* |
622
|
|
|
* @access public |
623
|
|
|
* @return string |
624
|
|
|
*/ |
625
|
|
|
public function display_admin_notices() |
626
|
|
|
{ |
627
|
|
|
//add non-dismissable notice for datetime changes. Only valid if EE version is greater than 4.9.46.p and the |
628
|
|
|
// site does not have a timezone_string set. |
629
|
|
|
if (EE_Register_Addon::_meets_min_core_version_requirement( |
630
|
|
|
'4.9.46.p' |
631
|
|
|
) |
632
|
|
|
&& ! get_option('timezone_string') |
633
|
|
|
) { |
634
|
|
|
EE_Error::add_attention( |
635
|
|
|
sprintf( |
636
|
|
|
esc_html__( |
637
|
|
|
'%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website. Read more about it %3$shere%4$s.', |
638
|
|
|
'event_espresso' |
639
|
|
|
), |
640
|
|
|
'<strong>', |
641
|
|
|
'</strong>', |
642
|
|
|
'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
643
|
|
|
'</a>' |
644
|
|
|
) |
645
|
|
|
); |
646
|
|
|
} |
647
|
|
|
echo EE_Error::get_notices(); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* get_persistent_admin_notices |
653
|
|
|
* |
654
|
|
|
* @access public |
655
|
|
|
* @return void |
656
|
|
|
*/ |
657
|
|
|
public function get_persistent_admin_notices() |
658
|
|
|
{ |
659
|
|
|
// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
660
|
|
|
$args = array( |
661
|
|
|
'page' => EE_Registry::instance()->REQ->is_set('page') |
662
|
|
|
? EE_Registry::instance()->REQ->get('page') |
663
|
|
|
: '', |
664
|
|
|
'action' => EE_Registry::instance()->REQ->is_set('action') |
665
|
|
|
? EE_Registry::instance()->REQ->get('action') |
666
|
|
|
: '', |
667
|
|
|
); |
668
|
|
|
$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
669
|
|
|
echo EE_Error::get_persistent_admin_notices($return_url); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
|
673
|
|
|
/** |
674
|
|
|
* dismiss_persistent_admin_notice |
675
|
|
|
* |
676
|
|
|
* @access public |
677
|
|
|
* @return void |
678
|
|
|
*/ |
679
|
|
|
public function dismiss_ee_nag_notice_callback() |
680
|
|
|
{ |
681
|
|
|
EE_Error::dismiss_persistent_admin_notice(); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* @param array $elements |
687
|
|
|
* @return array |
688
|
|
|
* @throws \EE_Error |
689
|
|
|
*/ |
690
|
|
|
public function dashboard_glance_items($elements) |
691
|
|
|
{ |
692
|
|
|
$elements = is_array($elements) ? $elements : array($elements); |
693
|
|
|
$events = EEM_Event::instance()->count(); |
694
|
|
|
$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
|
|
|
695
|
|
|
array('page' => 'espresso_events'), |
696
|
|
|
admin_url('admin.php') |
697
|
|
|
); |
698
|
|
|
$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
699
|
|
|
$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
700
|
|
|
$registrations = EEM_Registration::instance()->count( |
701
|
|
|
array( |
702
|
|
|
array( |
703
|
|
|
'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
704
|
|
|
), |
705
|
|
|
) |
706
|
|
|
); |
707
|
|
|
$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
708
|
|
|
array('page' => 'espresso_registrations'), |
709
|
|
|
admin_url('admin.php') |
710
|
|
|
); |
711
|
|
|
$items['registrations']['text'] = sprintf( |
712
|
|
|
_n('%s Registration', '%s Registrations', $registrations), |
713
|
|
|
number_format_i18n($registrations) |
714
|
|
|
); |
715
|
|
|
$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
716
|
|
|
|
717
|
|
|
$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
718
|
|
|
|
719
|
|
|
foreach ($items as $type => $item_properties) { |
720
|
|
|
$elements[] = sprintf( |
721
|
|
|
'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
722
|
|
|
$item_properties['url'], |
723
|
|
|
$item_properties['title'], |
724
|
|
|
$item_properties['text'] |
725
|
|
|
); |
726
|
|
|
} |
727
|
|
|
return $elements; |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* check_for_invalid_datetime_formats |
733
|
|
|
* if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
734
|
|
|
* their selected format can be parsed by PHP |
735
|
|
|
* |
736
|
|
|
* @access public |
737
|
|
|
* @param $value |
738
|
|
|
* @param $option |
739
|
|
|
* @throws EE_Error |
740
|
|
|
* @return string |
741
|
|
|
*/ |
742
|
|
|
public function check_for_invalid_datetime_formats($value, $option) |
743
|
|
|
{ |
744
|
|
|
// check for date_format or time_format |
745
|
|
|
switch ($option) { |
746
|
|
|
case 'date_format': |
747
|
|
|
$date_time_format = $value . ' ' . get_option('time_format'); |
748
|
|
|
break; |
749
|
|
|
case 'time_format': |
750
|
|
|
$date_time_format = get_option('date_format') . ' ' . $value; |
751
|
|
|
break; |
752
|
|
|
default: |
753
|
|
|
$date_time_format = false; |
754
|
|
|
} |
755
|
|
|
// do we have a date_time format to check ? |
756
|
|
|
if ($date_time_format) { |
|
|
|
|
757
|
|
|
$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
758
|
|
|
|
759
|
|
|
if (is_array($error_msg)) { |
760
|
|
|
$msg = '<p>' |
761
|
|
|
. sprintf( |
762
|
|
|
esc_html__( |
763
|
|
|
'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
764
|
|
|
'event_espresso' |
765
|
|
|
), |
766
|
|
|
date($date_time_format), |
767
|
|
|
$date_time_format |
768
|
|
|
) |
769
|
|
|
. '</p><p><ul>'; |
770
|
|
|
|
771
|
|
|
|
772
|
|
|
foreach ($error_msg as $error) { |
773
|
|
|
$msg .= '<li>' . $error . '</li>'; |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
$msg .= '</ul></p><p>' |
777
|
|
|
. sprintf( |
778
|
|
|
esc_html__( |
779
|
|
|
'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
780
|
|
|
'event_espresso' |
781
|
|
|
), |
782
|
|
|
'<span style="color:#D54E21;">', |
783
|
|
|
'</span>' |
784
|
|
|
) |
785
|
|
|
. '</p>'; |
786
|
|
|
|
787
|
|
|
// trigger WP settings error |
788
|
|
|
add_settings_error( |
789
|
|
|
'date_format', |
790
|
|
|
'date_format', |
791
|
|
|
$msg |
792
|
|
|
); |
793
|
|
|
|
794
|
|
|
// set format to something valid |
795
|
|
|
switch ($option) { |
796
|
|
|
case 'date_format': |
797
|
|
|
$value = 'F j, Y'; |
798
|
|
|
break; |
799
|
|
|
case 'time_format': |
800
|
|
|
$value = 'g:i a'; |
801
|
|
|
break; |
802
|
|
|
} |
803
|
|
|
} |
804
|
|
|
} |
805
|
|
|
return $value; |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
811
|
|
|
* |
812
|
|
|
* @access public |
813
|
|
|
* @param $content |
814
|
|
|
* @return string |
815
|
|
|
*/ |
816
|
|
|
public function its_eSpresso($content) |
817
|
|
|
{ |
818
|
|
|
return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
|
822
|
|
|
/** |
823
|
|
|
* espresso_admin_footer |
824
|
|
|
* |
825
|
|
|
* @access public |
826
|
|
|
* @return string |
827
|
|
|
*/ |
828
|
|
|
public function espresso_admin_footer() |
829
|
|
|
{ |
830
|
|
|
return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* static method for registering ee admin page. |
836
|
|
|
* This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
837
|
|
|
* |
838
|
|
|
* @since 4.3.0 |
839
|
|
|
* @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
840
|
|
|
* @see EE_Register_Admin_Page::register() |
841
|
|
|
* @param $page_basename |
842
|
|
|
* @param $page_path |
843
|
|
|
* @param array $config |
844
|
|
|
* @return void |
845
|
|
|
* @throws EE_Error |
846
|
|
|
*/ |
847
|
|
|
public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
848
|
|
|
{ |
849
|
|
|
EE_Error::doing_it_wrong( |
850
|
|
|
__METHOD__, |
851
|
|
|
sprintf( |
852
|
|
|
esc_html__( |
853
|
|
|
'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
854
|
|
|
'event_espresso' |
855
|
|
|
), |
856
|
|
|
$page_basename |
857
|
|
|
), |
858
|
|
|
'4.3' |
859
|
|
|
); |
860
|
|
|
if (class_exists('EE_Register_Admin_Page')) { |
861
|
|
|
$config['page_path'] = $page_path; |
862
|
|
|
} |
863
|
|
|
EE_Register_Admin_Page::register($page_basename, $config); |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
|
867
|
|
|
/** |
868
|
|
|
* @deprecated 4.8.41 |
869
|
|
|
* @access public |
870
|
|
|
* @param int $post_ID |
871
|
|
|
* @param \WP_Post $post |
872
|
|
|
* @return void |
873
|
|
|
*/ |
874
|
|
|
public static function parse_post_content_on_save($post_ID, $post) |
875
|
|
|
{ |
876
|
|
|
EE_Error::doing_it_wrong( |
877
|
|
|
__METHOD__, |
878
|
|
|
esc_html__('Usage is deprecated', 'event_espresso'), |
879
|
|
|
'4.8.41' |
880
|
|
|
); |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* @deprecated 4.8.41 |
886
|
|
|
* @access public |
887
|
|
|
* @param $option |
888
|
|
|
* @param $old_value |
889
|
|
|
* @param $value |
890
|
|
|
* @return void |
891
|
|
|
*/ |
892
|
|
|
public function reset_page_for_posts_on_change($option, $old_value, $value) |
893
|
|
|
{ |
894
|
|
|
EE_Error::doing_it_wrong( |
895
|
|
|
__METHOD__, |
896
|
|
|
esc_html__('Usage is deprecated', 'event_espresso'), |
897
|
|
|
'4.8.41' |
898
|
|
|
); |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
|
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.