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