Completed
Branch FET-11146-improve-messages-dat... (304d27)
by
unknown
113:38 queued 102:27
created

EE_Admin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
use EventEspresso\core\exceptions\InvalidDataTypeException;
4
use EventEspresso\core\exceptions\InvalidInterfaceException;
5
use EventEspresso\core\interfaces\InterminableInterface;
6
use EventEspresso\core\services\container\exceptions\ServiceNotFoundException;
7
use EventEspresso\core\services\loaders\LoaderFactory;
8
use EventEspresso\core\services\notifications\PersistentAdminNoticeManager;
9
10
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
11
12
13
14
/**
15
 * EE_Admin
16
 *
17
 * @package               Event Espresso
18
 * @subpackage            /core/admin/
19
 * @author                Brent Christensen
20
 */
21
final class EE_Admin implements InterminableInterface
22
{
23
24
    /**
25
     * @var EE_Admin $_instance
26
     */
27
    private static $_instance;
28
29
    /**
30
     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
31
     */
32
    private $persistent_admin_notice_manager;
33
34
    /**
35
     * @singleton method used to instantiate class object
36
     * @return EE_Admin
37
     * @throws EE_Error
38
     */
39
    public static function instance()
40
    {
41
        // check if class object is instantiated
42
        if (! self::$_instance instanceof EE_Admin) {
43
            self::$_instance = new self();
44
        }
45
        return self::$_instance;
46
    }
47
48
49
    /**
50
     * @return EE_Admin
51
     * @throws EE_Error
52
     */
53
    public static function reset()
54
    {
55
        self::$_instance = null;
56
        return self::instance();
57
    }
58
59
60
    /**
61
     * class constructor
62
     *
63
     * @throws EE_Error
64
     * @throws InvalidDataTypeException
65
     * @throws InvalidInterfaceException
66
     * @throws InvalidArgumentException
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
        //reset Environment config (we only do this on admin page loads);
88
        EE_Registry::instance()->CFG->environment->recheck_values();
89
        do_action('AHEE__EE_Admin__loaded');
90
    }
91
92
93
94
    /**
95
     * _define_all_constants
96
     * define constants that are set globally for all admin pages
97
     *
98
     * @return void
99
     */
100 View Code Duplication
    private function _define_all_constants()
101
    {
102
        if (! defined('EE_ADMIN_URL')) {
103
            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
104
            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
105
            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
106
            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
107
            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
108
        }
109
    }
110
111
112
    /**
113
     * filter_plugin_actions - adds links to the Plugins page listing
114
     *
115
     * @param    array  $links
116
     * @param    string $plugin
117
     * @return    array
118
     */
119
    public function filter_plugin_actions($links, $plugin)
120
    {
121
        // set $main_file in stone
122
        static $main_file;
123
        // if $main_file is not set yet
124
        if (! $main_file) {
125
            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
126
        }
127
        if ($plugin === $main_file) {
128
            // compare current plugin to this one
129
            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
130
                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
131
                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
132
                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
133
                                    . '</a>';
134
                array_unshift($links, $maintenance_link);
135
            } else {
136
                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
137
                                     . esc_html__('Settings', 'event_espresso')
138
                                     . '</a>';
139
                $events_link       = '<a href="admin.php?page=espresso_events">'
140
                                     . esc_html__('Events', 'event_espresso')
141
                                     . '</a>';
142
                // add before other links
143
                array_unshift($links, $org_settings_link, $events_link);
144
            }
145
        }
146
        return $links;
147
    }
148
149
150
    /**
151
     * _get_request
152
     *
153
     * @return void
154
     * @throws EE_Error
155
     * @throws InvalidArgumentException
156
     * @throws InvalidDataTypeException
157
     * @throws InvalidInterfaceException
158
     * @throws ReflectionException
159
     */
160
    public function get_request()
161
    {
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
     * @param array $admin_page_folder_names
172
     * @return array
173
     */
174
    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
175
    {
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
187
     * EE_Front_Controller's init phases have run
188
     *
189
     * @return void
190
     * @throws EE_Error
191
     * @throws InvalidArgumentException
192
     * @throws InvalidDataTypeException
193
     * @throws InvalidInterfaceException
194
     * @throws ReflectionException
195
     * @throws ServiceNotFoundException
196
     */
197
    public function init()
198
    {
199
        //only enable most of the EE_Admin IF we're not in full maintenance mode
200
        if (EE_Maintenance_Mode::instance()->models_can_query()) {
201
            //ok so we want to enable the entire admin
202
            $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
203
                'EventEspresso\core\services\notifications\PersistentAdminNoticeManager',
204
                array(
205
                    EE_Admin_Page::add_query_args_and_nonce(
206
                        array(
207
                            'page'   => EE_Registry::instance()->REQ->get('page', ''),
208
                            'action' => EE_Registry::instance()->REQ->get('action', ''),
209
                        ),
210
                        EE_ADMIN_URL
211
                    ),
212
                )
213
            );
214
            //at a glance dashboard widget
215
            add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
216
            //filter for get_edit_post_link used on comments for custom post types
217
            add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
218
        }
219
        // run the admin page factory but ONLY if we are doing an ee admin ajax request
220
        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
221
            try {
222
                //this loads the controller for the admin pages which will setup routing etc
223
                EE_Registry::instance()->load_core('Admin_Page_Loader');
224
            } catch (EE_Error $e) {
225
                $e->get_error();
226
            }
227
        }
228
        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
229
        //make sure our CPTs and custom taxonomy metaboxes get shown for first time users
230
        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
231
        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
232
        //exclude EE critical pages from all nav menus and wp_list_pages
233
        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
234
    }
235
236
237
238
    /**
239
     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
240
     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
241
     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
242
     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
243
     * normal property on the post_type object.  It's found ONLY in this particular context.
244
     *
245
     * @param WP_Post $post_type WP post type object
246
     * @return WP_Post
247
     * @throws InvalidArgumentException
248
     * @throws InvalidDataTypeException
249
     * @throws InvalidInterfaceException
250
     */
251
    public function remove_pages_from_nav_menu($post_type)
252
    {
253
        //if this isn't the "pages" post type let's get out
254
        if ($post_type->name !== 'page') {
255
            return $post_type;
256
        }
257
        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
258
        $post_type->_default_query = array(
259
            'post__not_in' => $critical_pages,
260
        );
261
        return $post_type;
262
    }
263
264
265
266
    /**
267
     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
268
     * metaboxes get shown as well
269
     *
270
     * @return void
271
     */
272
    public function enable_hidden_ee_nav_menu_metaboxes()
273
    {
274
        global $wp_meta_boxes, $pagenow;
275
        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
276
            return;
277
        }
278
        $user = wp_get_current_user();
279
        //has this been done yet?
280
        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
281
            return;
282
        }
283
284
        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
285
        $initial_meta_boxes = apply_filters(
286
            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
287
            array(
288
                'nav-menu-theme-locations',
289
                'add-page',
290
                'add-custom-links',
291
                'add-category',
292
                'add-espresso_events',
293
                'add-espresso_venues',
294
                'add-espresso_event_categories',
295
                'add-espresso_venue_categories',
296
                'add-post-type-post',
297
                'add-post-type-page',
298
            )
299
        );
300
301
        if (is_array($hidden_meta_boxes)) {
302
            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
303
                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
304
                    unset($hidden_meta_boxes[$key]);
305
                }
306
            }
307
        }
308
        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
309
        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
310
    }
311
312
313
314
    /**
315
     * This method simply registers custom nav menu boxes for "nav_menus.php route"
316
     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
317
     *
318
     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
319
     *         addons etc.
320
     * @return void
321
     */
322
    public function register_custom_nav_menu_boxes()
323
    {
324
        add_meta_box(
325
            'add-extra-nav-menu-pages',
326
            esc_html__('Event Espresso Pages', 'event_espresso'),
327
            array($this, 'ee_cpt_archive_pages'),
328
            'nav-menus',
329
            'side',
330
            'core'
331
        );
332
    }
333
334
335
336
    /**
337
     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
338
     *
339
     * @since   4.3.0
340
     * @param string $link the original link generated by wp
341
     * @param int    $id   post id
342
     * @return string  the (maybe) modified link
343
     */
344
    public function modify_edit_post_link($link, $id)
345
    {
346
        if (! $post = get_post($id)) {
347
            return $link;
348
        }
349
        if ($post->post_type === 'espresso_attendees') {
350
            $query_args = array(
351
                'action' => 'edit_attendee',
352
                'post'   => $id,
353
            );
354
            return EEH_URL::add_query_args_and_nonce(
355
                $query_args,
356
                admin_url('admin.php?page=espresso_registrations')
357
            );
358
        }
359
        return $link;
360
    }
361
362
363
364
    public function ee_cpt_archive_pages()
365
    {
366
        global $nav_menu_selected_id;
367
        $db_fields   = false;
368
        $walker      = new Walker_Nav_Menu_Checklist($db_fields);
369
        $current_tab = 'event-archives';
370
        $removed_args = array(
371
            'action',
372
            'customlink-tab',
373
            'edit-menu-item',
374
            'menu-item',
375
            'page-tab',
376
            '_wpnonce',
377
        );
378
        ?>
379
        <div id="posttype-extra-nav-menu-pages" class="posttypediv">
380
            <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
381
                <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
382
                    <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
383
                       href="<?php if ($nav_menu_selected_id) {
384
                            echo esc_url(
385
                                add_query_arg(
386
                                    'extra-nav-menu-pages-tab',
387
                                    'event-archives',
388
                                    remove_query_arg($removed_args)
389
                                )
390
                            );
391
                       } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
392
                        <?php _e('Event Archive Pages', 'event_espresso'); ?>
393
                    </a>
394
                </li>
395
            </ul><!-- .posttype-tabs -->
396
397
            <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
398
                echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
399
                ?>">
400
                    <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
401
                        <?php
402
                        $pages          = $this->_get_extra_nav_menu_pages_items();
403
                        $args['walker'] = $walker;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
404
                        echo walk_nav_menu_tree(
405
                            array_map(
406
                                array($this, '_setup_extra_nav_menu_pages_items'),
407
                                $pages
408
                            ),
409
                            0,
410
                            (object) $args
411
                        );
412
                        ?>
413
                    </ul>
414
                </div><!-- /.tabs-panel -->
415
416
                <p class="button-controls">
417
                <span class="list-controls">
418
                    <a href="<?php
419
                    echo esc_url(add_query_arg(
420
                        array(
421
                            'extra-nav-menu-pages-tab' => 'event-archives',
422
                            'selectall'                => 1,
423
                        ),
424
                        remove_query_arg($removed_args)
425
                    ));
426
                    ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
427
                </span>
428
                <span class="add-to-menu">
429
                    <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
430
                       class="button-secondary submit-add-to-menu right"
431
                       value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item"
432
                       id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>"/>
433
                    <span class="spinner"></span>
434
                </span>
435
                </p>
436
437
        </div><!-- /.posttypediv -->
438
        <?php
439
    }
440
441
442
    /**
443
     * Returns an array of event archive nav items.
444
     *
445
     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
446
     *        method we use for getting the extra nav menu items
447
     * @return array
448
     */
449
    private function _get_extra_nav_menu_pages_items()
450
    {
451
        $menuitems[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$menuitems was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menuitems = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
452
            'title'       => esc_html__('Event List', 'event_espresso'),
453
            'url'         => get_post_type_archive_link('espresso_events'),
454
            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
455
        );
456
        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
457
    }
458
459
460
    /**
461
     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
462
     * the properties and converts it to the menu item object.
463
     *
464
     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
465
     * @param $menu_item_values
466
     * @return stdClass
467
     */
468
    private function _setup_extra_nav_menu_pages_items($menu_item_values)
469
    {
470
        $menu_item = new stdClass();
471
        $keys      = array(
472
            'ID'               => 0,
473
            'db_id'            => 0,
474
            'menu_item_parent' => 0,
475
            'object_id'        => -1,
476
            'post_parent'      => 0,
477
            'type'             => 'custom',
478
            'object'           => '',
479
            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
480
            'title'            => '',
481
            'url'              => '',
482
            'target'           => '',
483
            'attr_title'       => '',
484
            'description'      => '',
485
            'classes'          => array(),
486
            'xfn'              => '',
487
        );
488
489
        foreach ($keys as $key => $value) {
490
            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
491
        }
492
        return $menu_item;
493
    }
494
495
496
    /**
497
     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
498
     * EE_Admin_Page route is called.
499
     *
500
     * @return void
501
     */
502
    public function route_admin_request()
503
    {
504
    }
505
506
507
    /**
508
     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
509
     *
510
     * @return void
511
     */
512
    public function wp_loaded()
513
    {
514
    }
515
516
517
    /**
518
     * admin_init
519
     *
520
     * @return void
521
     * @throws EE_Error
522
     * @throws InvalidArgumentException
523
     * @throws InvalidDataTypeException
524
     * @throws InvalidInterfaceException
525
     * @throws ReflectionException
526
     */
527
    public function admin_init()
528
    {
529
530
        /**
531
         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
532
         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
533
         * - check if doing post processing.
534
         * - check if doing post processing of one of EE CPTs
535
         * - instantiate the corresponding EE CPT model for the post_type being processed.
536
         */
537
        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
538
            EE_Registry::instance()->load_core('Register_CPTs');
539
            EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
540
        }
541
542
543
        /**
544
         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
545
         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
546
         * Pages" tab in the EE General Settings Admin page.
547
         * This is for user-proofing.
548
         */
549
        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
550
    }
551
552
553
    /**
554
     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
555
     *
556
     * @param string $output Current output.
557
     * @return string
558
     * @throws InvalidArgumentException
559
     * @throws InvalidDataTypeException
560
     * @throws InvalidInterfaceException
561
     */
562
    public function modify_dropdown_pages($output)
563
    {
564
        //get critical pages
565
        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
566
567
        //split current output by line break for easier parsing.
568
        $split_output = explode("\n", $output);
569
570
        //loop through to remove any critical pages from the array.
571
        foreach ($critical_pages as $page_id) {
572
            $needle = 'value="' . $page_id . '"';
573
            foreach ($split_output as $key => $haystack) {
574
                if (strpos($haystack, $needle) !== false) {
575
                    unset($split_output[$key]);
576
                }
577
            }
578
        }
579
        //replace output with the new contents
580
        return implode("\n", $split_output);
581
    }
582
583
584
    /**
585
     * enqueue all admin scripts that need loaded for admin pages
586
     *
587
     * @return void
588
     */
589
    public function enqueue_admin_scripts()
590
    {
591
        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
592
        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
593
        // calls.
594
        wp_enqueue_script(
595
            'ee-inject-wp',
596
            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
597
            array('jquery'),
598
            EVENT_ESPRESSO_VERSION,
599
            true
600
        );
601
        // register cookie script for future dependencies
602
        wp_register_script(
603
            'jquery-cookie',
604
            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
605
            array('jquery'),
606
            '2.1',
607
            true
608
        );
609
        //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
610
        // via: add_filter('FHEE_load_joyride', '__return_true' );
611
        if (apply_filters('FHEE_load_joyride', false)) {
612
            //joyride style
613
            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
614
            wp_register_style(
615
                'ee-joyride-css',
616
                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
617
                array('joyride-css'),
618
                EVENT_ESPRESSO_VERSION
619
            );
620
            wp_register_script(
621
                'joyride-modernizr',
622
                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
623
                array(),
624
                '2.1',
625
                true
626
            );
627
            //joyride JS
628
            wp_register_script(
629
                'jquery-joyride',
630
                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
631
                array('jquery-cookie', 'joyride-modernizr'),
632
                '2.1',
633
                true
634
            );
635
            // wanna go for a joyride?
636
            wp_enqueue_style('ee-joyride-css');
637
            wp_enqueue_script('jquery-joyride');
638
        }
639
    }
640
641
642
    /**
643
     * display_admin_notices
644
     *
645
     * @return void
646
     */
647
    public function display_admin_notices()
648
    {
649
        echo EE_Error::get_notices();
650
    }
651
652
653
654
    /**
655
     * @param array $elements
656
     * @return array
657
     * @throws EE_Error
658
     * @throws InvalidArgumentException
659
     * @throws InvalidDataTypeException
660
     * @throws InvalidInterfaceException
661
     */
662
    public function dashboard_glance_items($elements)
663
    {
664
        $elements                        = is_array($elements) ? $elements : array($elements);
665
        $events                          = EEM_Event::instance()->count();
666
        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
667
            array('page' => 'espresso_events'),
668
            admin_url('admin.php')
669
        );
670
        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
671
        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
672
        $registrations                   = EEM_Registration::instance()->count(
673
            array(
674
                array(
675
                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
676
                ),
677
            )
678
        );
679
        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
680
            array('page' => 'espresso_registrations'),
681
            admin_url('admin.php')
682
        );
683
        $items['registrations']['text']  = sprintf(
684
            _n('%s Registration', '%s Registrations', $registrations),
685
            number_format_i18n($registrations)
686
        );
687
        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
688
689
        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
690
691
        foreach ($items as $type => $item_properties) {
692
            $elements[] = sprintf(
693
                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
694
                $item_properties['url'],
695
                $item_properties['title'],
696
                $item_properties['text']
697
            );
698
        }
699
        return $elements;
700
    }
701
702
703
    /**
704
     * check_for_invalid_datetime_formats
705
     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
706
     * their selected format can be parsed by PHP
707
     *
708
     * @param    $value
709
     * @param    $option
710
     * @throws EE_Error
711
     * @return    string
712
     */
713
    public function check_for_invalid_datetime_formats($value, $option)
714
    {
715
        // check for date_format or time_format
716
        switch ($option) {
717
            case 'date_format':
718
                $date_time_format = $value . ' ' . get_option('time_format');
719
                break;
720
            case 'time_format':
721
                $date_time_format = get_option('date_format') . ' ' . $value;
722
                break;
723
            default:
724
                $date_time_format = false;
725
        }
726
        // do we have a date_time format to check ?
727
        if ($date_time_format) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date_time_format of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
728
            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
729
730
            if (is_array($error_msg)) {
731
                $msg = '<p>'
732
                       . sprintf(
733
                           esc_html__(
734
                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
735
                               'event_espresso'
736
                           ),
737
                           date($date_time_format),
738
                           $date_time_format
739
                       )
740
                       . '</p><p><ul>';
741
742
743
                foreach ($error_msg as $error) {
744
                    $msg .= '<li>' . $error . '</li>';
745
                }
746
747
                $msg .= '</ul></p><p>'
748
                        . sprintf(
749
                            esc_html__(
750
                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
751
                                'event_espresso'
752
                            ),
753
                            '<span style="color:#D54E21;">',
754
                            '</span>'
755
                        )
756
                        . '</p>';
757
758
                // trigger WP settings error
759
                add_settings_error(
760
                    'date_format',
761
                    'date_format',
762
                    $msg
763
                );
764
765
                // set format to something valid
766
                switch ($option) {
767
                    case 'date_format':
768
                        $value = 'F j, Y';
769
                        break;
770
                    case 'time_format':
771
                        $value = 'g:i a';
772
                        break;
773
                }
774
            }
775
        }
776
        return $value;
777
    }
778
779
780
    /**
781
     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
782
     *
783
     * @param $content
784
     * @return    string
785
     */
786
    public function its_eSpresso($content)
787
    {
788
        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
789
    }
790
791
792
    /**
793
     * espresso_admin_footer
794
     *
795
     * @return    string
796
     */
797
    public function espresso_admin_footer()
798
    {
799
        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
800
    }
801
802
803
    /**
804
     * static method for registering ee admin page.
805
     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
806
     *
807
     * @since      4.3.0
808
     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
809
     * @see        EE_Register_Admin_Page::register()
810
     * @param       $page_basename
811
     * @param       $page_path
812
     * @param array $config
813
     * @return void
814
     * @throws EE_Error
815
     */
816
    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
817
    {
818
        EE_Error::doing_it_wrong(
819
            __METHOD__,
820
            sprintf(
821
                esc_html__(
822
                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
823
                    'event_espresso'
824
                ),
825
                $page_basename
826
            ),
827
            '4.3'
828
        );
829
        if (class_exists('EE_Register_Admin_Page')) {
830
            $config['page_path'] = $page_path;
831
        }
832
        EE_Register_Admin_Page::register($page_basename, $config);
833
    }
834
835
836
    /**
837
     * @deprecated 4.8.41
838
     * @param  int      $post_ID
839
     * @param  \WP_Post $post
840
     * @return void
841
     */
842
    public static function parse_post_content_on_save($post_ID, $post)
843
    {
844
        EE_Error::doing_it_wrong(
845
            __METHOD__,
846
            esc_html__('Usage is deprecated', 'event_espresso'),
847
            '4.8.41'
848
        );
849
    }
850
851
852
    /**
853
     * @deprecated 4.8.41
854
     * @param  $option
855
     * @param  $old_value
856
     * @param  $value
857
     * @return void
858
     */
859
    public function reset_page_for_posts_on_change($option, $old_value, $value)
860
    {
861
        EE_Error::doing_it_wrong(
862
            __METHOD__,
863
            esc_html__('Usage is deprecated', 'event_espresso'),
864
            '4.8.41'
865
        );
866
    }
867
868
869
870
    /**
871
     * @deprecated 4.9.27
872
     * @return void
873
     */
874
    public function get_persistent_admin_notices()
875
    {
876
        EE_Error::doing_it_wrong(
877
            __METHOD__,
878
            sprintf(
879
                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
880
                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
881
            ),
882
            '4.9.27'
883
        );
884
    }
885
886
887
888
    /**
889
     * @deprecated 4.9.27
890
     * @throws InvalidInterfaceException
891
     * @throws InvalidDataTypeException
892
     * @throws DomainException
893
     */
894
    public function dismiss_ee_nag_notice_callback()
895
    {
896
        EE_Error::doing_it_wrong(
897
            __METHOD__,
898
            sprintf(
899
                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
900
                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
901
            ),
902
            '4.9.27'
903
        );
904
        $this->persistent_admin_notice_manager->dismissNotice();
905
    }
906
}
907