Completed
Pull Request — master (#331)
by Darren
24:00
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.64.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.64.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Indentation   +958 added lines, -958 removed lines patch added patch discarded remove patch
@@ -20,487 +20,487 @@  discard block
 block discarded – undo
20 20
 final class EE_Admin implements InterminableInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Admin $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
-     */
31
-    private $persistent_admin_notice_manager;
32
-
33
-    /**
34
-     * @var LoaderInterface
35
-     */
36
-    protected $loader;
37
-
38
-    /**
39
-     * @singleton method used to instantiate class object
40
-     * @return EE_Admin
41
-     * @throws EE_Error
42
-     */
43
-    public static function instance()
44
-    {
45
-        // check if class object is instantiated
46
-        if (! self::$_instance instanceof EE_Admin) {
47
-            self::$_instance = new self();
48
-        }
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-    /**
54
-     * @return EE_Admin
55
-     * @throws EE_Error
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-    /**
65
-     * class constructor
66
-     *
67
-     * @throws EE_Error
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws InvalidArgumentException
71
-     */
72
-    protected function __construct()
73
-    {
74
-        // define global EE_Admin constants
75
-        $this->_define_all_constants();
76
-        // set autoloaders for our admin page classes based on included path information
77
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
-        // admin hooks
79
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
-        // load EE_Request_Handler early
81
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
-        add_action('admin_init', array($this, 'admin_init'), 100);
86
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
-        add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
-        // reset Environment config (we only do this on admin page loads);
93
-        EE_Registry::instance()->CFG->environment->recheck_values();
94
-        do_action('AHEE__EE_Admin__loaded');
95
-    }
96
-
97
-
98
-    /**
99
-     * _define_all_constants
100
-     * define constants that are set globally for all admin pages
101
-     *
102
-     * @return void
103
-     */
104
-    private function _define_all_constants()
105
-    {
106
-        if (! defined('EE_ADMIN_URL')) {
107
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
108
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
109
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
110
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
111
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
112
-        }
113
-    }
114
-
115
-
116
-    /**
117
-     * filter_plugin_actions - adds links to the Plugins page listing
118
-     *
119
-     * @param    array  $links
120
-     * @param    string $plugin
121
-     * @return    array
122
-     */
123
-    public function filter_plugin_actions($links, $plugin)
124
-    {
125
-        // set $main_file in stone
126
-        static $main_file;
127
-        // if $main_file is not set yet
128
-        if (! $main_file) {
129
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
130
-        }
131
-        if ($plugin === $main_file) {
132
-            // compare current plugin to this one
133
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
134
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
135
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
136
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
137
-                                    . '</a>';
138
-                array_unshift($links, $maintenance_link);
139
-            } else {
140
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
141
-                                     . esc_html__('Settings', 'event_espresso')
142
-                                     . '</a>';
143
-                $events_link = '<a href="admin.php?page=espresso_events">'
144
-                               . esc_html__('Events', 'event_espresso')
145
-                               . '</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
-     * _get_request
156
-     *
157
-     * @return void
158
-     * @throws EE_Error
159
-     * @throws InvalidArgumentException
160
-     * @throws InvalidDataTypeException
161
-     * @throws InvalidInterfaceException
162
-     * @throws ReflectionException
163
-     */
164
-    public function get_request()
165
-    {
166
-        EE_Registry::instance()->load_core('Request_Handler');
167
-        EE_Registry::instance()->load_core('CPT_Strategy');
168
-    }
169
-
170
-
171
-    /**
172
-     * hide_admin_pages_except_maintenance_mode
173
-     *
174
-     * @param array $admin_page_folder_names
175
-     * @return array
176
-     */
177
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
-    {
179
-        return array(
180
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
-        );
184
-    }
185
-
186
-
187
-    /**
188
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
189
-     * EE_Front_Controller's init phases have run
190
-     *
191
-     * @return void
192
-     * @throws EE_Error
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidInterfaceException
196
-     * @throws ReflectionException
197
-     * @throws ServiceNotFoundException
198
-     */
199
-    public function init()
200
-    {
201
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
202
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
203
-            $this->initModelsReady();
204
-        }
205
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
206
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
207
-            try {
208
-                // this loads the controller for the admin pages which will setup routing etc
209
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
210
-            } catch (EE_Error $e) {
211
-                $e->get_error();
212
-            }
213
-        }
214
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
215
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
216
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
217
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
218
-        // exclude EE critical pages from all nav menus and wp_list_pages
219
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
220
-    }
221
-
222
-
223
-    /**
224
-     * Gets the loader (and if it wasn't previously set, sets it)
225
-     * @return LoaderInterface
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidInterfaceException
229
-     */
230
-    protected function getLoader()
231
-    {
232
-        if (! $this->loader instanceof LoaderInterface) {
233
-            $this->loader = LoaderFactory::getLoader();
234
-        }
235
-        return $this->loader;
236
-    }
237
-
238
-
239
-    /**
240
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
-     * (ie, the site isn't in maintenance mode)
242
-     * @since 4.9.63.p
243
-     * @return void
244
-     */
245
-    protected function initModelsReady()
246
-    {
247
-        // ok so we want to enable the entire admin
248
-        $this->persistent_admin_notice_manager = $this->getLoader()->getShared(
249
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
250
-        );
251
-        $this->persistent_admin_notice_manager->setReturnUrl(
252
-            EE_Admin_Page::add_query_args_and_nonce(
253
-                array(
254
-                    'page'   => EE_Registry::instance()->REQ->get('page', ''),
255
-                    'action' => EE_Registry::instance()->REQ->get('action', ''),
256
-                ),
257
-                EE_ADMIN_URL
258
-            )
259
-        );
260
-        $this->maybeSetDatetimeWarningNotice();
261
-        // at a glance dashboard widget
262
-        add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
263
-        // filter for get_edit_post_link used on comments for custom post types
264
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
265
-    }
266
-
267
-
268
-    /**
269
-     *    get_persistent_admin_notices
270
-     *
271
-     * @access    public
272
-     * @return void
273
-     * @throws EE_Error
274
-     * @throws InvalidArgumentException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function maybeSetDatetimeWarningNotice()
279
-    {
280
-        // add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
281
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
282
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
283
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
284
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
285
-            && ! get_option('timezone_string')
286
-            && EEM_Event::instance()->count() > 0
287
-        ) {
288
-            new PersistentAdminNotice(
289
-                'datetime_fix_notice',
290
-                sprintf(
291
-                    esc_html__(
292
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
293
-                        'event_espresso'
294
-                    ),
295
-                    '<strong>',
296
-                    '</strong>',
297
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
298
-                    '</a>',
299
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
300
-                        array(
301
-                            'page'   => 'espresso_maintenance_settings',
302
-                            'action' => 'datetime_tools',
303
-                        ),
304
-                        admin_url('admin.php')
305
-                    ) . '">'
306
-                ),
307
-                false,
308
-                'manage_options',
309
-                'datetime_fix_persistent_notice'
310
-            );
311
-        }
312
-    }
313
-
314
-
315
-    /**
316
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
317
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
318
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
319
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
320
-     * normal property on the post_type object.  It's found ONLY in this particular context.
321
-     *
322
-     * @param WP_Post $post_type WP post type object
323
-     * @return WP_Post
324
-     * @throws InvalidArgumentException
325
-     * @throws InvalidDataTypeException
326
-     * @throws InvalidInterfaceException
327
-     */
328
-    public function remove_pages_from_nav_menu($post_type)
329
-    {
330
-        // if this isn't the "pages" post type let's get out
331
-        if ($post_type->name !== 'page') {
332
-            return $post_type;
333
-        }
334
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
335
-        $post_type->_default_query = array(
336
-            'post__not_in' => $critical_pages,
337
-        );
338
-        return $post_type;
339
-    }
340
-
341
-
342
-    /**
343
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
344
-     * metaboxes get shown as well
345
-     *
346
-     * @return void
347
-     */
348
-    public function enable_hidden_ee_nav_menu_metaboxes()
349
-    {
350
-        global $wp_meta_boxes, $pagenow;
351
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
352
-            return;
353
-        }
354
-        $user = wp_get_current_user();
355
-        // has this been done yet?
356
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
357
-            return;
358
-        }
359
-
360
-        $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
361
-        $initial_meta_boxes = apply_filters(
362
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
363
-            array(
364
-                'nav-menu-theme-locations',
365
-                'add-page',
366
-                'add-custom-links',
367
-                'add-category',
368
-                'add-espresso_events',
369
-                'add-espresso_venues',
370
-                'add-espresso_event_categories',
371
-                'add-espresso_venue_categories',
372
-                'add-post-type-post',
373
-                'add-post-type-page',
374
-            )
375
-        );
376
-
377
-        if (is_array($hidden_meta_boxes)) {
378
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
379
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
380
-                    unset($hidden_meta_boxes[ $key ]);
381
-                }
382
-            }
383
-        }
384
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
385
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
386
-    }
387
-
388
-
389
-    /**
390
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
391
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
392
-     *
393
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
394
-     *         addons etc.
395
-     * @return void
396
-     */
397
-    public function register_custom_nav_menu_boxes()
398
-    {
399
-        add_meta_box(
400
-            'add-extra-nav-menu-pages',
401
-            esc_html__('Event Espresso Pages', 'event_espresso'),
402
-            array($this, 'ee_cpt_archive_pages'),
403
-            'nav-menus',
404
-            'side',
405
-            'core'
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
412
-     *
413
-     * @since   4.3.0
414
-     * @param string $link the original link generated by wp
415
-     * @param int    $id   post id
416
-     * @return string  the (maybe) modified link
417
-     */
418
-    public function modify_edit_post_link($link, $id)
419
-    {
420
-        if (! $post = get_post($id)) {
421
-            return $link;
422
-        }
423
-        if ($post->post_type === 'espresso_attendees') {
424
-            $query_args = array(
425
-                'action' => 'edit_attendee',
426
-                'post'   => $id,
427
-            );
428
-            return EEH_URL::add_query_args_and_nonce(
429
-                $query_args,
430
-                admin_url('admin.php?page=espresso_registrations')
431
-            );
432
-        }
433
-        return $link;
434
-    }
435
-
436
-
437
-    public function ee_cpt_archive_pages()
438
-    {
439
-        global $nav_menu_selected_id;
440
-        $db_fields = false;
441
-        $walker = new Walker_Nav_Menu_Checklist($db_fields);
442
-        $current_tab = 'event-archives';
443
-        $removed_args = array(
444
-            'action',
445
-            'customlink-tab',
446
-            'edit-menu-item',
447
-            'menu-item',
448
-            'page-tab',
449
-            '_wpnonce',
450
-        );
451
-        ?>
23
+	/**
24
+	 * @var EE_Admin $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
+	 */
31
+	private $persistent_admin_notice_manager;
32
+
33
+	/**
34
+	 * @var LoaderInterface
35
+	 */
36
+	protected $loader;
37
+
38
+	/**
39
+	 * @singleton method used to instantiate class object
40
+	 * @return EE_Admin
41
+	 * @throws EE_Error
42
+	 */
43
+	public static function instance()
44
+	{
45
+		// check if class object is instantiated
46
+		if (! self::$_instance instanceof EE_Admin) {
47
+			self::$_instance = new self();
48
+		}
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return EE_Admin
55
+	 * @throws EE_Error
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+	/**
65
+	 * class constructor
66
+	 *
67
+	 * @throws EE_Error
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws InvalidArgumentException
71
+	 */
72
+	protected function __construct()
73
+	{
74
+		// define global EE_Admin constants
75
+		$this->_define_all_constants();
76
+		// set autoloaders for our admin page classes based on included path information
77
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
+		// admin hooks
79
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
+		// load EE_Request_Handler early
81
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
+		add_action('admin_init', array($this, 'admin_init'), 100);
86
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
+		add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
+		// reset Environment config (we only do this on admin page loads);
93
+		EE_Registry::instance()->CFG->environment->recheck_values();
94
+		do_action('AHEE__EE_Admin__loaded');
95
+	}
96
+
97
+
98
+	/**
99
+	 * _define_all_constants
100
+	 * define constants that are set globally for all admin pages
101
+	 *
102
+	 * @return void
103
+	 */
104
+	private function _define_all_constants()
105
+	{
106
+		if (! defined('EE_ADMIN_URL')) {
107
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
108
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
109
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
110
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
111
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
112
+		}
113
+	}
114
+
115
+
116
+	/**
117
+	 * filter_plugin_actions - adds links to the Plugins page listing
118
+	 *
119
+	 * @param    array  $links
120
+	 * @param    string $plugin
121
+	 * @return    array
122
+	 */
123
+	public function filter_plugin_actions($links, $plugin)
124
+	{
125
+		// set $main_file in stone
126
+		static $main_file;
127
+		// if $main_file is not set yet
128
+		if (! $main_file) {
129
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
130
+		}
131
+		if ($plugin === $main_file) {
132
+			// compare current plugin to this one
133
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
134
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
135
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
136
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
137
+									. '</a>';
138
+				array_unshift($links, $maintenance_link);
139
+			} else {
140
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
141
+									 . esc_html__('Settings', 'event_espresso')
142
+									 . '</a>';
143
+				$events_link = '<a href="admin.php?page=espresso_events">'
144
+							   . esc_html__('Events', 'event_espresso')
145
+							   . '</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
+	 * _get_request
156
+	 *
157
+	 * @return void
158
+	 * @throws EE_Error
159
+	 * @throws InvalidArgumentException
160
+	 * @throws InvalidDataTypeException
161
+	 * @throws InvalidInterfaceException
162
+	 * @throws ReflectionException
163
+	 */
164
+	public function get_request()
165
+	{
166
+		EE_Registry::instance()->load_core('Request_Handler');
167
+		EE_Registry::instance()->load_core('CPT_Strategy');
168
+	}
169
+
170
+
171
+	/**
172
+	 * hide_admin_pages_except_maintenance_mode
173
+	 *
174
+	 * @param array $admin_page_folder_names
175
+	 * @return array
176
+	 */
177
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
+	{
179
+		return array(
180
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
+		);
184
+	}
185
+
186
+
187
+	/**
188
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
189
+	 * EE_Front_Controller's init phases have run
190
+	 *
191
+	 * @return void
192
+	 * @throws EE_Error
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidInterfaceException
196
+	 * @throws ReflectionException
197
+	 * @throws ServiceNotFoundException
198
+	 */
199
+	public function init()
200
+	{
201
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
202
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
203
+			$this->initModelsReady();
204
+		}
205
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
206
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
207
+			try {
208
+				// this loads the controller for the admin pages which will setup routing etc
209
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
210
+			} catch (EE_Error $e) {
211
+				$e->get_error();
212
+			}
213
+		}
214
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
215
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
216
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
217
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
218
+		// exclude EE critical pages from all nav menus and wp_list_pages
219
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Gets the loader (and if it wasn't previously set, sets it)
225
+	 * @return LoaderInterface
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidInterfaceException
229
+	 */
230
+	protected function getLoader()
231
+	{
232
+		if (! $this->loader instanceof LoaderInterface) {
233
+			$this->loader = LoaderFactory::getLoader();
234
+		}
235
+		return $this->loader;
236
+	}
237
+
238
+
239
+	/**
240
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
+	 * (ie, the site isn't in maintenance mode)
242
+	 * @since 4.9.63.p
243
+	 * @return void
244
+	 */
245
+	protected function initModelsReady()
246
+	{
247
+		// ok so we want to enable the entire admin
248
+		$this->persistent_admin_notice_manager = $this->getLoader()->getShared(
249
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
250
+		);
251
+		$this->persistent_admin_notice_manager->setReturnUrl(
252
+			EE_Admin_Page::add_query_args_and_nonce(
253
+				array(
254
+					'page'   => EE_Registry::instance()->REQ->get('page', ''),
255
+					'action' => EE_Registry::instance()->REQ->get('action', ''),
256
+				),
257
+				EE_ADMIN_URL
258
+			)
259
+		);
260
+		$this->maybeSetDatetimeWarningNotice();
261
+		// at a glance dashboard widget
262
+		add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
263
+		// filter for get_edit_post_link used on comments for custom post types
264
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
265
+	}
266
+
267
+
268
+	/**
269
+	 *    get_persistent_admin_notices
270
+	 *
271
+	 * @access    public
272
+	 * @return void
273
+	 * @throws EE_Error
274
+	 * @throws InvalidArgumentException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function maybeSetDatetimeWarningNotice()
279
+	{
280
+		// add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
281
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
282
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
283
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
284
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
285
+			&& ! get_option('timezone_string')
286
+			&& EEM_Event::instance()->count() > 0
287
+		) {
288
+			new PersistentAdminNotice(
289
+				'datetime_fix_notice',
290
+				sprintf(
291
+					esc_html__(
292
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
293
+						'event_espresso'
294
+					),
295
+					'<strong>',
296
+					'</strong>',
297
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
298
+					'</a>',
299
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
300
+						array(
301
+							'page'   => 'espresso_maintenance_settings',
302
+							'action' => 'datetime_tools',
303
+						),
304
+						admin_url('admin.php')
305
+					) . '">'
306
+				),
307
+				false,
308
+				'manage_options',
309
+				'datetime_fix_persistent_notice'
310
+			);
311
+		}
312
+	}
313
+
314
+
315
+	/**
316
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
317
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
318
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
319
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
320
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
321
+	 *
322
+	 * @param WP_Post $post_type WP post type object
323
+	 * @return WP_Post
324
+	 * @throws InvalidArgumentException
325
+	 * @throws InvalidDataTypeException
326
+	 * @throws InvalidInterfaceException
327
+	 */
328
+	public function remove_pages_from_nav_menu($post_type)
329
+	{
330
+		// if this isn't the "pages" post type let's get out
331
+		if ($post_type->name !== 'page') {
332
+			return $post_type;
333
+		}
334
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
335
+		$post_type->_default_query = array(
336
+			'post__not_in' => $critical_pages,
337
+		);
338
+		return $post_type;
339
+	}
340
+
341
+
342
+	/**
343
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
344
+	 * metaboxes get shown as well
345
+	 *
346
+	 * @return void
347
+	 */
348
+	public function enable_hidden_ee_nav_menu_metaboxes()
349
+	{
350
+		global $wp_meta_boxes, $pagenow;
351
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
352
+			return;
353
+		}
354
+		$user = wp_get_current_user();
355
+		// has this been done yet?
356
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
357
+			return;
358
+		}
359
+
360
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
361
+		$initial_meta_boxes = apply_filters(
362
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
363
+			array(
364
+				'nav-menu-theme-locations',
365
+				'add-page',
366
+				'add-custom-links',
367
+				'add-category',
368
+				'add-espresso_events',
369
+				'add-espresso_venues',
370
+				'add-espresso_event_categories',
371
+				'add-espresso_venue_categories',
372
+				'add-post-type-post',
373
+				'add-post-type-page',
374
+			)
375
+		);
376
+
377
+		if (is_array($hidden_meta_boxes)) {
378
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
379
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
380
+					unset($hidden_meta_boxes[ $key ]);
381
+				}
382
+			}
383
+		}
384
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
385
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
386
+	}
387
+
388
+
389
+	/**
390
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
391
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
392
+	 *
393
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
394
+	 *         addons etc.
395
+	 * @return void
396
+	 */
397
+	public function register_custom_nav_menu_boxes()
398
+	{
399
+		add_meta_box(
400
+			'add-extra-nav-menu-pages',
401
+			esc_html__('Event Espresso Pages', 'event_espresso'),
402
+			array($this, 'ee_cpt_archive_pages'),
403
+			'nav-menus',
404
+			'side',
405
+			'core'
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
412
+	 *
413
+	 * @since   4.3.0
414
+	 * @param string $link the original link generated by wp
415
+	 * @param int    $id   post id
416
+	 * @return string  the (maybe) modified link
417
+	 */
418
+	public function modify_edit_post_link($link, $id)
419
+	{
420
+		if (! $post = get_post($id)) {
421
+			return $link;
422
+		}
423
+		if ($post->post_type === 'espresso_attendees') {
424
+			$query_args = array(
425
+				'action' => 'edit_attendee',
426
+				'post'   => $id,
427
+			);
428
+			return EEH_URL::add_query_args_and_nonce(
429
+				$query_args,
430
+				admin_url('admin.php?page=espresso_registrations')
431
+			);
432
+		}
433
+		return $link;
434
+	}
435
+
436
+
437
+	public function ee_cpt_archive_pages()
438
+	{
439
+		global $nav_menu_selected_id;
440
+		$db_fields = false;
441
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
442
+		$current_tab = 'event-archives';
443
+		$removed_args = array(
444
+			'action',
445
+			'customlink-tab',
446
+			'edit-menu-item',
447
+			'menu-item',
448
+			'page-tab',
449
+			'_wpnonce',
450
+		);
451
+		?>
452 452
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
453 453
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
454 454
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
455 455
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
456 456
                        href="<?php
457
-                        if ($nav_menu_selected_id) {
458
-                            echo esc_url(
459
-                                add_query_arg(
460
-                                    'extra-nav-menu-pages-tab',
461
-                                    'event-archives',
462
-                                    remove_query_arg($removed_args)
463
-                                )
464
-                            );
465
-                        }
466
-                        ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
457
+						if ($nav_menu_selected_id) {
458
+							echo esc_url(
459
+								add_query_arg(
460
+									'extra-nav-menu-pages-tab',
461
+									'event-archives',
462
+									remove_query_arg($removed_args)
463
+								)
464
+							);
465
+						}
466
+						?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
467 467
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
468 468
                     </a>
469 469
                 </li>
470 470
             </ul><!-- .posttype-tabs -->
471 471
 
472 472
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
473
-            echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
474
-            ?>">
473
+			echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
474
+			?>">
475 475
                 <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
476 476
                     <?php
477
-                    $pages = $this->_get_extra_nav_menu_pages_items();
478
-                    $args['walker'] = $walker;
479
-                    echo walk_nav_menu_tree(
480
-                        array_map(
481
-                            array($this, '_setup_extra_nav_menu_pages_items'),
482
-                            $pages
483
-                        ),
484
-                        0,
485
-                        (object) $args
486
-                    );
487
-                    ?>
477
+					$pages = $this->_get_extra_nav_menu_pages_items();
478
+					$args['walker'] = $walker;
479
+					echo walk_nav_menu_tree(
480
+						array_map(
481
+							array($this, '_setup_extra_nav_menu_pages_items'),
482
+							$pages
483
+						),
484
+						0,
485
+						(object) $args
486
+					);
487
+					?>
488 488
                 </ul>
489 489
             </div><!-- /.tabs-panel -->
490 490
 
491 491
             <p class="button-controls">
492 492
                 <span class="list-controls">
493 493
                     <a href="<?php
494
-                             echo esc_url(
495
-                                 add_query_arg(
496
-                                     array(
497
-                                         'extra-nav-menu-pages-tab' => 'event-archives',
498
-                                         'selectall'                => 1,
499
-                                     ),
500
-                                     remove_query_arg($removed_args)
501
-                                 )
502
-                             );
503
-                        ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
494
+							 echo esc_url(
495
+								 add_query_arg(
496
+									 array(
497
+										 'extra-nav-menu-pages-tab' => 'event-archives',
498
+										 'selectall'                => 1,
499
+									 ),
500
+									 remove_query_arg($removed_args)
501
+								 )
502
+							 );
503
+						?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
504 504
                 </span>
505 505
                 <span class="add-to-menu">
506 506
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -513,500 +513,500 @@  discard block
 block discarded – undo
513 513
 
514 514
         </div><!-- /.posttypediv -->
515 515
         <?php
516
-    }
517
-
518
-
519
-    /**
520
-     * Returns an array of event archive nav items.
521
-     *
522
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
523
-     *        method we use for getting the extra nav menu items
524
-     * @return array
525
-     */
526
-    private function _get_extra_nav_menu_pages_items()
527
-    {
528
-        $menuitems[] = array(
529
-            'title'       => esc_html__('Event List', 'event_espresso'),
530
-            'url'         => get_post_type_archive_link('espresso_events'),
531
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
532
-        );
533
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
534
-    }
535
-
536
-
537
-    /**
538
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
539
-     * the properties and converts it to the menu item object.
540
-     *
541
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
542
-     * @param $menu_item_values
543
-     * @return stdClass
544
-     */
545
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
546
-    {
547
-        $menu_item = new stdClass();
548
-        $keys = array(
549
-            'ID'               => 0,
550
-            'db_id'            => 0,
551
-            'menu_item_parent' => 0,
552
-            'object_id'        => -1,
553
-            'post_parent'      => 0,
554
-            'type'             => 'custom',
555
-            'object'           => '',
556
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
557
-            'title'            => '',
558
-            'url'              => '',
559
-            'target'           => '',
560
-            'attr_title'       => '',
561
-            'description'      => '',
562
-            'classes'          => array(),
563
-            'xfn'              => '',
564
-        );
565
-
566
-        foreach ($keys as $key => $value) {
567
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
568
-        }
569
-        return $menu_item;
570
-    }
571
-
572
-
573
-    /**
574
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
575
-     * EE_Admin_Page route is called.
576
-     *
577
-     * @return void
578
-     */
579
-    public function route_admin_request()
580
-    {
581
-    }
582
-
583
-
584
-    /**
585
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
586
-     *
587
-     * @return void
588
-     */
589
-    public function wp_loaded()
590
-    {
591
-    }
592
-
593
-
594
-    /**
595
-     * admin_init
596
-     *
597
-     * @return void
598
-     * @throws EE_Error
599
-     * @throws InvalidArgumentException
600
-     * @throws InvalidDataTypeException
601
-     * @throws InvalidInterfaceException
602
-     * @throws ReflectionException
603
-     */
604
-    public function admin_init()
605
-    {
606
-        /**
607
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
608
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
609
-         * - check if doing post processing.
610
-         * - check if doing post processing of one of EE CPTs
611
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
612
-         */
613
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
614
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
615
-            $custom_post_types = $this->getLoader()->getShared(
616
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
617
-            );
618
-            $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
619
-        }
620
-
621
-
622
-        /**
623
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
624
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
625
-         * Pages" tab in the EE General Settings Admin page.
626
-         * This is for user-proofing.
627
-         */
628
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
629
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
630
-            $this->adminInitModelsReady();
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
637
-     */
638
-    protected function adminInitModelsReady()
639
-    {
640
-        if (function_exists('wp_add_privacy_policy_content')) {
641
-            $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
642
-        }
643
-    }
644
-
645
-
646
-    /**
647
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
648
-     *
649
-     * @param string $output Current output.
650
-     * @return string
651
-     * @throws InvalidArgumentException
652
-     * @throws InvalidDataTypeException
653
-     * @throws InvalidInterfaceException
654
-     */
655
-    public function modify_dropdown_pages($output)
656
-    {
657
-        // get critical pages
658
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
659
-
660
-        // split current output by line break for easier parsing.
661
-        $split_output = explode("\n", $output);
662
-
663
-        // loop through to remove any critical pages from the array.
664
-        foreach ($critical_pages as $page_id) {
665
-            $needle = 'value="' . $page_id . '"';
666
-            foreach ($split_output as $key => $haystack) {
667
-                if (strpos($haystack, $needle) !== false) {
668
-                    unset($split_output[ $key ]);
669
-                }
670
-            }
671
-        }
672
-        // replace output with the new contents
673
-        return implode("\n", $split_output);
674
-    }
675
-
676
-
677
-    /**
678
-     * enqueue all admin scripts that need loaded for admin pages
679
-     *
680
-     * @return void
681
-     */
682
-    public function enqueue_admin_scripts()
683
-    {
684
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
685
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
686
-        // calls.
687
-        wp_enqueue_script(
688
-            'ee-inject-wp',
689
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
690
-            array('jquery'),
691
-            EVENT_ESPRESSO_VERSION,
692
-            true
693
-        );
694
-        // register cookie script for future dependencies
695
-        wp_register_script(
696
-            'jquery-cookie',
697
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
698
-            array('jquery'),
699
-            '2.1',
700
-            true
701
-        );
702
-        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
703
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
704
-        if (apply_filters('FHEE_load_joyride', false)) {
705
-            // joyride style
706
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
707
-            wp_register_style(
708
-                'ee-joyride-css',
709
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
710
-                array('joyride-css'),
711
-                EVENT_ESPRESSO_VERSION
712
-            );
713
-            wp_register_script(
714
-                'joyride-modernizr',
715
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
716
-                array(),
717
-                '2.1',
718
-                true
719
-            );
720
-            // joyride JS
721
-            wp_register_script(
722
-                'jquery-joyride',
723
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
724
-                array('jquery-cookie', 'joyride-modernizr'),
725
-                '2.1',
726
-                true
727
-            );
728
-            // wanna go for a joyride?
729
-            wp_enqueue_style('ee-joyride-css');
730
-            wp_enqueue_script('jquery-joyride');
731
-        }
732
-    }
733
-
734
-
735
-    /**
736
-     * display_admin_notices
737
-     *
738
-     * @return void
739
-     */
740
-    public function display_admin_notices()
741
-    {
742
-        echo EE_Error::get_notices();
743
-    }
744
-
745
-
746
-    /**
747
-     * @param array $elements
748
-     * @return array
749
-     * @throws EE_Error
750
-     * @throws InvalidArgumentException
751
-     * @throws InvalidDataTypeException
752
-     * @throws InvalidInterfaceException
753
-     */
754
-    public function dashboard_glance_items($elements)
755
-    {
756
-        $elements = is_array($elements) ? $elements : array($elements);
757
-        $events = EEM_Event::instance()->count();
758
-        $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
759
-            array('page' => 'espresso_events'),
760
-            admin_url('admin.php')
761
-        );
762
-        $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
763
-        $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
764
-        $registrations = EEM_Registration::instance()->count(
765
-            array(
766
-                array(
767
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
768
-                ),
769
-            )
770
-        );
771
-        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
772
-            array('page' => 'espresso_registrations'),
773
-            admin_url('admin.php')
774
-        );
775
-        $items['registrations']['text'] = sprintf(
776
-            _n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
777
-            number_format_i18n($registrations)
778
-        );
779
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
780
-
781
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
782
-
783
-        foreach ($items as $type => $item_properties) {
784
-            $elements[] = sprintf(
785
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
786
-                $item_properties['url'],
787
-                $item_properties['title'],
788
-                $item_properties['text']
789
-            );
790
-        }
791
-        return $elements;
792
-    }
793
-
794
-
795
-    /**
796
-     * check_for_invalid_datetime_formats
797
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
798
-     * their selected format can be parsed by PHP
799
-     *
800
-     * @param    $value
801
-     * @param    $option
802
-     * @throws EE_Error
803
-     * @return    string
804
-     */
805
-    public function check_for_invalid_datetime_formats($value, $option)
806
-    {
807
-        // check for date_format or time_format
808
-        switch ($option) {
809
-            case 'date_format':
810
-                $date_time_format = $value . ' ' . get_option('time_format');
811
-                break;
812
-            case 'time_format':
813
-                $date_time_format = get_option('date_format') . ' ' . $value;
814
-                break;
815
-            default:
816
-                $date_time_format = false;
817
-        }
818
-        // do we have a date_time format to check ?
819
-        if ($date_time_format) {
820
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
821
-
822
-            if (is_array($error_msg)) {
823
-                $msg = '<p>'
824
-                       . sprintf(
825
-                           esc_html__(
826
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
827
-                               'event_espresso'
828
-                           ),
829
-                           date($date_time_format),
830
-                           $date_time_format
831
-                       )
832
-                       . '</p><p><ul>';
833
-
834
-
835
-                foreach ($error_msg as $error) {
836
-                    $msg .= '<li>' . $error . '</li>';
837
-                }
838
-
839
-                $msg .= '</ul></p><p>'
840
-                        . sprintf(
841
-                            esc_html__(
842
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
843
-                                'event_espresso'
844
-                            ),
845
-                            '<span style="color:#D54E21;">',
846
-                            '</span>'
847
-                        )
848
-                        . '</p>';
849
-
850
-                // trigger WP settings error
851
-                add_settings_error(
852
-                    'date_format',
853
-                    'date_format',
854
-                    $msg
855
-                );
856
-
857
-                // set format to something valid
858
-                switch ($option) {
859
-                    case 'date_format':
860
-                        $value = 'F j, Y';
861
-                        break;
862
-                    case 'time_format':
863
-                        $value = 'g:i a';
864
-                        break;
865
-                }
866
-            }
867
-        }
868
-        return $value;
869
-    }
870
-
871
-
872
-    /**
873
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
874
-     *
875
-     * @param $content
876
-     * @return    string
877
-     */
878
-    public function its_eSpresso($content)
879
-    {
880
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
881
-    }
882
-
883
-
884
-    /**
885
-     * espresso_admin_footer
886
-     *
887
-     * @return    string
888
-     */
889
-    public function espresso_admin_footer()
890
-    {
891
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
892
-    }
893
-
894
-
895
-    /**
896
-     * static method for registering ee admin page.
897
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
898
-     *
899
-     * @since      4.3.0
900
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
901
-     * @see        EE_Register_Admin_Page::register()
902
-     * @param       $page_basename
903
-     * @param       $page_path
904
-     * @param array $config
905
-     * @return void
906
-     * @throws EE_Error
907
-     */
908
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
909
-    {
910
-        EE_Error::doing_it_wrong(
911
-            __METHOD__,
912
-            sprintf(
913
-                esc_html__(
914
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
915
-                    'event_espresso'
916
-                ),
917
-                $page_basename
918
-            ),
919
-            '4.3'
920
-        );
921
-        if (class_exists('EE_Register_Admin_Page')) {
922
-            $config['page_path'] = $page_path;
923
-        }
924
-        EE_Register_Admin_Page::register($page_basename, $config);
925
-    }
926
-
927
-
928
-    /**
929
-     * @deprecated 4.8.41
930
-     * @param  int      $post_ID
931
-     * @param  \WP_Post $post
932
-     * @return void
933
-     */
934
-    public static function parse_post_content_on_save($post_ID, $post)
935
-    {
936
-        EE_Error::doing_it_wrong(
937
-            __METHOD__,
938
-            esc_html__('Usage is deprecated', 'event_espresso'),
939
-            '4.8.41'
940
-        );
941
-    }
942
-
943
-
944
-    /**
945
-     * @deprecated 4.8.41
946
-     * @param  $option
947
-     * @param  $old_value
948
-     * @param  $value
949
-     * @return void
950
-     */
951
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
952
-    {
953
-        EE_Error::doing_it_wrong(
954
-            __METHOD__,
955
-            esc_html__('Usage is deprecated', 'event_espresso'),
956
-            '4.8.41'
957
-        );
958
-    }
959
-
960
-
961
-    /**
962
-     * @deprecated 4.9.27
963
-     * @return void
964
-     */
965
-    public function get_persistent_admin_notices()
966
-    {
967
-        EE_Error::doing_it_wrong(
968
-            __METHOD__,
969
-            sprintf(
970
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
971
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
972
-            ),
973
-            '4.9.27'
974
-        );
975
-    }
976
-
977
-
978
-    /**
979
-     * @deprecated 4.9.27
980
-     * @throws InvalidInterfaceException
981
-     * @throws InvalidDataTypeException
982
-     * @throws DomainException
983
-     */
984
-    public function dismiss_ee_nag_notice_callback()
985
-    {
986
-        EE_Error::doing_it_wrong(
987
-            __METHOD__,
988
-            sprintf(
989
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
990
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
991
-            ),
992
-            '4.9.27'
993
-        );
994
-        $this->persistent_admin_notice_manager->dismissNotice();
995
-    }
996
-
997
-
998
-    /**
999
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1000
-     *
1001
-     * @throws InvalidArgumentException
1002
-     * @throws InvalidDataTypeException
1003
-     * @throws InvalidInterfaceException
1004
-     */
1005
-    public function hookIntoWpPluginsPage()
1006
-    {
1007
-        $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1008
-        $this->getLoader()
1009
-                     ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1010
-                     ->decafUpsells();
1011
-    }
516
+	}
517
+
518
+
519
+	/**
520
+	 * Returns an array of event archive nav items.
521
+	 *
522
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
523
+	 *        method we use for getting the extra nav menu items
524
+	 * @return array
525
+	 */
526
+	private function _get_extra_nav_menu_pages_items()
527
+	{
528
+		$menuitems[] = array(
529
+			'title'       => esc_html__('Event List', 'event_espresso'),
530
+			'url'         => get_post_type_archive_link('espresso_events'),
531
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
532
+		);
533
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
534
+	}
535
+
536
+
537
+	/**
538
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
539
+	 * the properties and converts it to the menu item object.
540
+	 *
541
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
542
+	 * @param $menu_item_values
543
+	 * @return stdClass
544
+	 */
545
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
546
+	{
547
+		$menu_item = new stdClass();
548
+		$keys = array(
549
+			'ID'               => 0,
550
+			'db_id'            => 0,
551
+			'menu_item_parent' => 0,
552
+			'object_id'        => -1,
553
+			'post_parent'      => 0,
554
+			'type'             => 'custom',
555
+			'object'           => '',
556
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
557
+			'title'            => '',
558
+			'url'              => '',
559
+			'target'           => '',
560
+			'attr_title'       => '',
561
+			'description'      => '',
562
+			'classes'          => array(),
563
+			'xfn'              => '',
564
+		);
565
+
566
+		foreach ($keys as $key => $value) {
567
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
568
+		}
569
+		return $menu_item;
570
+	}
571
+
572
+
573
+	/**
574
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
575
+	 * EE_Admin_Page route is called.
576
+	 *
577
+	 * @return void
578
+	 */
579
+	public function route_admin_request()
580
+	{
581
+	}
582
+
583
+
584
+	/**
585
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
586
+	 *
587
+	 * @return void
588
+	 */
589
+	public function wp_loaded()
590
+	{
591
+	}
592
+
593
+
594
+	/**
595
+	 * admin_init
596
+	 *
597
+	 * @return void
598
+	 * @throws EE_Error
599
+	 * @throws InvalidArgumentException
600
+	 * @throws InvalidDataTypeException
601
+	 * @throws InvalidInterfaceException
602
+	 * @throws ReflectionException
603
+	 */
604
+	public function admin_init()
605
+	{
606
+		/**
607
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
608
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
609
+		 * - check if doing post processing.
610
+		 * - check if doing post processing of one of EE CPTs
611
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
612
+		 */
613
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
614
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
615
+			$custom_post_types = $this->getLoader()->getShared(
616
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
617
+			);
618
+			$custom_post_types->getCustomPostTypeModels($_POST['post_type']);
619
+		}
620
+
621
+
622
+		/**
623
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
624
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
625
+		 * Pages" tab in the EE General Settings Admin page.
626
+		 * This is for user-proofing.
627
+		 */
628
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
629
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
630
+			$this->adminInitModelsReady();
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
637
+	 */
638
+	protected function adminInitModelsReady()
639
+	{
640
+		if (function_exists('wp_add_privacy_policy_content')) {
641
+			$this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
642
+		}
643
+	}
644
+
645
+
646
+	/**
647
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
648
+	 *
649
+	 * @param string $output Current output.
650
+	 * @return string
651
+	 * @throws InvalidArgumentException
652
+	 * @throws InvalidDataTypeException
653
+	 * @throws InvalidInterfaceException
654
+	 */
655
+	public function modify_dropdown_pages($output)
656
+	{
657
+		// get critical pages
658
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
659
+
660
+		// split current output by line break for easier parsing.
661
+		$split_output = explode("\n", $output);
662
+
663
+		// loop through to remove any critical pages from the array.
664
+		foreach ($critical_pages as $page_id) {
665
+			$needle = 'value="' . $page_id . '"';
666
+			foreach ($split_output as $key => $haystack) {
667
+				if (strpos($haystack, $needle) !== false) {
668
+					unset($split_output[ $key ]);
669
+				}
670
+			}
671
+		}
672
+		// replace output with the new contents
673
+		return implode("\n", $split_output);
674
+	}
675
+
676
+
677
+	/**
678
+	 * enqueue all admin scripts that need loaded for admin pages
679
+	 *
680
+	 * @return void
681
+	 */
682
+	public function enqueue_admin_scripts()
683
+	{
684
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
685
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
686
+		// calls.
687
+		wp_enqueue_script(
688
+			'ee-inject-wp',
689
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
690
+			array('jquery'),
691
+			EVENT_ESPRESSO_VERSION,
692
+			true
693
+		);
694
+		// register cookie script for future dependencies
695
+		wp_register_script(
696
+			'jquery-cookie',
697
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
698
+			array('jquery'),
699
+			'2.1',
700
+			true
701
+		);
702
+		// joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
703
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
704
+		if (apply_filters('FHEE_load_joyride', false)) {
705
+			// joyride style
706
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
707
+			wp_register_style(
708
+				'ee-joyride-css',
709
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
710
+				array('joyride-css'),
711
+				EVENT_ESPRESSO_VERSION
712
+			);
713
+			wp_register_script(
714
+				'joyride-modernizr',
715
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
716
+				array(),
717
+				'2.1',
718
+				true
719
+			);
720
+			// joyride JS
721
+			wp_register_script(
722
+				'jquery-joyride',
723
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
724
+				array('jquery-cookie', 'joyride-modernizr'),
725
+				'2.1',
726
+				true
727
+			);
728
+			// wanna go for a joyride?
729
+			wp_enqueue_style('ee-joyride-css');
730
+			wp_enqueue_script('jquery-joyride');
731
+		}
732
+	}
733
+
734
+
735
+	/**
736
+	 * display_admin_notices
737
+	 *
738
+	 * @return void
739
+	 */
740
+	public function display_admin_notices()
741
+	{
742
+		echo EE_Error::get_notices();
743
+	}
744
+
745
+
746
+	/**
747
+	 * @param array $elements
748
+	 * @return array
749
+	 * @throws EE_Error
750
+	 * @throws InvalidArgumentException
751
+	 * @throws InvalidDataTypeException
752
+	 * @throws InvalidInterfaceException
753
+	 */
754
+	public function dashboard_glance_items($elements)
755
+	{
756
+		$elements = is_array($elements) ? $elements : array($elements);
757
+		$events = EEM_Event::instance()->count();
758
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
759
+			array('page' => 'espresso_events'),
760
+			admin_url('admin.php')
761
+		);
762
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
763
+		$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
764
+		$registrations = EEM_Registration::instance()->count(
765
+			array(
766
+				array(
767
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
768
+				),
769
+			)
770
+		);
771
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
772
+			array('page' => 'espresso_registrations'),
773
+			admin_url('admin.php')
774
+		);
775
+		$items['registrations']['text'] = sprintf(
776
+			_n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
777
+			number_format_i18n($registrations)
778
+		);
779
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
780
+
781
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
782
+
783
+		foreach ($items as $type => $item_properties) {
784
+			$elements[] = sprintf(
785
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
786
+				$item_properties['url'],
787
+				$item_properties['title'],
788
+				$item_properties['text']
789
+			);
790
+		}
791
+		return $elements;
792
+	}
793
+
794
+
795
+	/**
796
+	 * check_for_invalid_datetime_formats
797
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
798
+	 * their selected format can be parsed by PHP
799
+	 *
800
+	 * @param    $value
801
+	 * @param    $option
802
+	 * @throws EE_Error
803
+	 * @return    string
804
+	 */
805
+	public function check_for_invalid_datetime_formats($value, $option)
806
+	{
807
+		// check for date_format or time_format
808
+		switch ($option) {
809
+			case 'date_format':
810
+				$date_time_format = $value . ' ' . get_option('time_format');
811
+				break;
812
+			case 'time_format':
813
+				$date_time_format = get_option('date_format') . ' ' . $value;
814
+				break;
815
+			default:
816
+				$date_time_format = false;
817
+		}
818
+		// do we have a date_time format to check ?
819
+		if ($date_time_format) {
820
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
821
+
822
+			if (is_array($error_msg)) {
823
+				$msg = '<p>'
824
+					   . sprintf(
825
+						   esc_html__(
826
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
827
+							   'event_espresso'
828
+						   ),
829
+						   date($date_time_format),
830
+						   $date_time_format
831
+					   )
832
+					   . '</p><p><ul>';
833
+
834
+
835
+				foreach ($error_msg as $error) {
836
+					$msg .= '<li>' . $error . '</li>';
837
+				}
838
+
839
+				$msg .= '</ul></p><p>'
840
+						. sprintf(
841
+							esc_html__(
842
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
843
+								'event_espresso'
844
+							),
845
+							'<span style="color:#D54E21;">',
846
+							'</span>'
847
+						)
848
+						. '</p>';
849
+
850
+				// trigger WP settings error
851
+				add_settings_error(
852
+					'date_format',
853
+					'date_format',
854
+					$msg
855
+				);
856
+
857
+				// set format to something valid
858
+				switch ($option) {
859
+					case 'date_format':
860
+						$value = 'F j, Y';
861
+						break;
862
+					case 'time_format':
863
+						$value = 'g:i a';
864
+						break;
865
+				}
866
+			}
867
+		}
868
+		return $value;
869
+	}
870
+
871
+
872
+	/**
873
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
874
+	 *
875
+	 * @param $content
876
+	 * @return    string
877
+	 */
878
+	public function its_eSpresso($content)
879
+	{
880
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
881
+	}
882
+
883
+
884
+	/**
885
+	 * espresso_admin_footer
886
+	 *
887
+	 * @return    string
888
+	 */
889
+	public function espresso_admin_footer()
890
+	{
891
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
892
+	}
893
+
894
+
895
+	/**
896
+	 * static method for registering ee admin page.
897
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
898
+	 *
899
+	 * @since      4.3.0
900
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
901
+	 * @see        EE_Register_Admin_Page::register()
902
+	 * @param       $page_basename
903
+	 * @param       $page_path
904
+	 * @param array $config
905
+	 * @return void
906
+	 * @throws EE_Error
907
+	 */
908
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
909
+	{
910
+		EE_Error::doing_it_wrong(
911
+			__METHOD__,
912
+			sprintf(
913
+				esc_html__(
914
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
915
+					'event_espresso'
916
+				),
917
+				$page_basename
918
+			),
919
+			'4.3'
920
+		);
921
+		if (class_exists('EE_Register_Admin_Page')) {
922
+			$config['page_path'] = $page_path;
923
+		}
924
+		EE_Register_Admin_Page::register($page_basename, $config);
925
+	}
926
+
927
+
928
+	/**
929
+	 * @deprecated 4.8.41
930
+	 * @param  int      $post_ID
931
+	 * @param  \WP_Post $post
932
+	 * @return void
933
+	 */
934
+	public static function parse_post_content_on_save($post_ID, $post)
935
+	{
936
+		EE_Error::doing_it_wrong(
937
+			__METHOD__,
938
+			esc_html__('Usage is deprecated', 'event_espresso'),
939
+			'4.8.41'
940
+		);
941
+	}
942
+
943
+
944
+	/**
945
+	 * @deprecated 4.8.41
946
+	 * @param  $option
947
+	 * @param  $old_value
948
+	 * @param  $value
949
+	 * @return void
950
+	 */
951
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
952
+	{
953
+		EE_Error::doing_it_wrong(
954
+			__METHOD__,
955
+			esc_html__('Usage is deprecated', 'event_espresso'),
956
+			'4.8.41'
957
+		);
958
+	}
959
+
960
+
961
+	/**
962
+	 * @deprecated 4.9.27
963
+	 * @return void
964
+	 */
965
+	public function get_persistent_admin_notices()
966
+	{
967
+		EE_Error::doing_it_wrong(
968
+			__METHOD__,
969
+			sprintf(
970
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
971
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
972
+			),
973
+			'4.9.27'
974
+		);
975
+	}
976
+
977
+
978
+	/**
979
+	 * @deprecated 4.9.27
980
+	 * @throws InvalidInterfaceException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws DomainException
983
+	 */
984
+	public function dismiss_ee_nag_notice_callback()
985
+	{
986
+		EE_Error::doing_it_wrong(
987
+			__METHOD__,
988
+			sprintf(
989
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
990
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
991
+			),
992
+			'4.9.27'
993
+		);
994
+		$this->persistent_admin_notice_manager->dismissNotice();
995
+	}
996
+
997
+
998
+	/**
999
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1000
+	 *
1001
+	 * @throws InvalidArgumentException
1002
+	 * @throws InvalidDataTypeException
1003
+	 * @throws InvalidInterfaceException
1004
+	 */
1005
+	public function hookIntoWpPluginsPage()
1006
+	{
1007
+		$this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1008
+		$this->getLoader()
1009
+					 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1010
+					 ->decafUpsells();
1011
+	}
1012 1012
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +575 added lines, -575 removed lines patch added patch discarded remove patch
@@ -23,586 +23,586 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
-
28
-    /**
29
-     * @var AssetCollection $assets
30
-     */
31
-    protected $assets;
32
-
33
-    /**
34
-     * @var I18nRegistry
35
-     */
36
-    private $i18n_registry;
37
-
38
-    /**
39
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $jsdata = array();
44
-
45
-    /**
46
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
-     * page source.
48
-     *
49
-     * @var array
50
-     */
51
-    private $script_handles_with_data = array();
52
-
53
-
54
-    /**
55
-     * Holds the manifest data obtained from registered manifest files.
56
-     * Manifests are maps of asset chunk name to actual built asset file names.
57
-     * Shape of this array is:
58
-     * array(
59
-     *  'some_namespace_slug' => array(
60
-     *      'some_chunk_name' => array(
61
-     *          'js' => 'filename.js'
62
-     *          'css' => 'filename.js'
63
-     *      ),
64
-     *      'url_base' => 'https://baseurl.com/to/assets
65
-     *  )
66
-     * )
67
-     *
68
-     * @var array
69
-     */
70
-    private $manifest_data = array();
71
-
72
-
73
-    /**
74
-     * Registry constructor.
75
-     * Hooking into WP actions for script registry.
76
-     *
77
-     * @param AssetCollection $assets
78
-     * @param I18nRegistry    $i18n_registry
79
-     */
80
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
-    {
82
-        $this->assets = $assets;
83
-        $this->i18n_registry = $i18n_registry;
84
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
-    }
93
-
94
-
95
-    /**
96
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
-     * translation handling.
98
-     *
99
-     * @return I18nRegistry
100
-     */
101
-    public function getI18nRegistry()
102
-    {
103
-        return $this->i18n_registry;
104
-    }
105
-
106
-
107
-    /**
108
-     * Callback for the wp_enqueue_scripts actions used to register assets.
109
-     *
110
-     * @since 4.9.62.p
111
-     * @throws Exception
112
-     */
113
-    public function registerScriptsAndStyles()
114
-    {
115
-        try {
116
-            $this->registerScripts($this->assets->getJavascriptAssets());
117
-            $this->registerStyles($this->assets->getStylesheetAssets());
118
-        } catch (Exception $exception) {
119
-            new ExceptionStackTraceDisplay($exception);
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * Registers JS assets with WP core
126
-     *
127
-     * @since 4.9.62.p
128
-     * @param JavascriptAsset[] $scripts
129
-     * @throws AssetRegistrationException
130
-     * @throws InvalidDataTypeException
131
-     */
132
-    public function registerScripts(array $scripts)
133
-    {
134
-        foreach ($scripts as $script) {
135
-            // skip to next script if this has already been done
136
-            if ($script->isRegistered()) {
137
-                continue;
138
-            }
139
-            do_action(
140
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
-                $script
142
-            );
143
-            $registered = wp_register_script(
144
-                $script->handle(),
145
-                $script->source(),
146
-                $script->dependencies(),
147
-                $script->version(),
148
-                $script->loadInFooter()
149
-            );
150
-            if (! $registered && $this->debug()) {
151
-                throw new AssetRegistrationException($script->handle());
152
-            }
153
-            $script->setRegistered($registered);
154
-            if ($script->requiresTranslation()) {
155
-                $this->registerTranslation($script->handle());
156
-            }
157
-            do_action(
158
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
-                $script
160
-            );
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Registers CSS assets with WP core
167
-     *
168
-     * @since 4.9.62.p
169
-     * @param StylesheetAsset[] $styles
170
-     * @throws InvalidDataTypeException
171
-     */
172
-    public function registerStyles(array $styles)
173
-    {
174
-        foreach ($styles as $style) {
175
-            // skip to next style if this has already been done
176
-            if ($style->isRegistered()) {
177
-                continue;
178
-            }
179
-            do_action(
180
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
-                $style
182
-            );
183
-            wp_register_style(
184
-                $style->handle(),
185
-                $style->source(),
186
-                $style->dependencies(),
187
-                $style->version(),
188
-                $style->media()
189
-            );
190
-            $style->setRegistered();
191
-            do_action(
192
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
-                $style
194
-            );
195
-        }
196
-    }
197
-
198
-
199
-    /**
200
-     * Call back for the script print in frontend and backend.
201
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
-     *
203
-     * @since 4.9.31.rc.015
204
-     */
205
-    public function enqueueData()
206
-    {
207
-        $this->removeAlreadyRegisteredDataForScriptHandles();
208
-        wp_add_inline_script(
209
-            'eejs-core',
210
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
-            'before'
212
-        );
213
-        $scripts = $this->assets->getJavascriptAssetsWithData();
214
-        foreach ($scripts as $script) {
215
-            $this->addRegisteredScriptHandlesWithData($script->handle());
216
-            if ($script->hasInlineDataCallback()) {
217
-                $localize = $script->inlineDataCallback();
218
-                $localize();
219
-            }
220
-        }
221
-    }
222
-
223
-
224
-    /**
225
-     * Used to add data to eejs.data object.
226
-     * Note:  Overriding existing data is not allowed.
227
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
-     * If the data you add is something like this:
229
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
-     * It will be exposed in the page source as:
231
-     *  eejs.data.my_plugin_data.foo == gar
232
-     *
233
-     * @param string       $key   Key used to access your data
234
-     * @param string|array $value Value to attach to key
235
-     * @throws InvalidArgumentException
236
-     */
237
-    public function addData($key, $value)
238
-    {
239
-        if ($this->verifyDataNotExisting($key)) {
240
-            $this->jsdata[ $key ] = $value;
241
-        }
242
-    }
243
-
244
-
245
-    /**
246
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
-     * elements in an array.
248
-     * When you use this method, the value you include will be appended to the end of an array on $key.
249
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
250
-     * object like this, eejs.data.test = [ my_data,
251
-     * ]
252
-     * If there has already been a scalar value attached to the data object given key, then
253
-     * this will throw an exception.
254
-     *
255
-     * @param string       $key   Key to attach data to.
256
-     * @param string|array $value Value being registered.
257
-     * @throws InvalidArgumentException
258
-     */
259
-    public function pushData($key, $value)
260
-    {
261
-        if (isset($this->jsdata[ $key ])
262
-            && ! is_array($this->jsdata[ $key ])
263
-        ) {
264
-            if (! $this->debug()) {
265
-                return;
266
-            }
267
-            throw new InvalidArgumentException(
268
-                sprintf(
269
-                    __(
270
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
+
28
+	/**
29
+	 * @var AssetCollection $assets
30
+	 */
31
+	protected $assets;
32
+
33
+	/**
34
+	 * @var I18nRegistry
35
+	 */
36
+	private $i18n_registry;
37
+
38
+	/**
39
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $jsdata = array();
44
+
45
+	/**
46
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
+	 * page source.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $script_handles_with_data = array();
52
+
53
+
54
+	/**
55
+	 * Holds the manifest data obtained from registered manifest files.
56
+	 * Manifests are maps of asset chunk name to actual built asset file names.
57
+	 * Shape of this array is:
58
+	 * array(
59
+	 *  'some_namespace_slug' => array(
60
+	 *      'some_chunk_name' => array(
61
+	 *          'js' => 'filename.js'
62
+	 *          'css' => 'filename.js'
63
+	 *      ),
64
+	 *      'url_base' => 'https://baseurl.com/to/assets
65
+	 *  )
66
+	 * )
67
+	 *
68
+	 * @var array
69
+	 */
70
+	private $manifest_data = array();
71
+
72
+
73
+	/**
74
+	 * Registry constructor.
75
+	 * Hooking into WP actions for script registry.
76
+	 *
77
+	 * @param AssetCollection $assets
78
+	 * @param I18nRegistry    $i18n_registry
79
+	 */
80
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
+	{
82
+		$this->assets = $assets;
83
+		$this->i18n_registry = $i18n_registry;
84
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
+	}
93
+
94
+
95
+	/**
96
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
+	 * translation handling.
98
+	 *
99
+	 * @return I18nRegistry
100
+	 */
101
+	public function getI18nRegistry()
102
+	{
103
+		return $this->i18n_registry;
104
+	}
105
+
106
+
107
+	/**
108
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
109
+	 *
110
+	 * @since 4.9.62.p
111
+	 * @throws Exception
112
+	 */
113
+	public function registerScriptsAndStyles()
114
+	{
115
+		try {
116
+			$this->registerScripts($this->assets->getJavascriptAssets());
117
+			$this->registerStyles($this->assets->getStylesheetAssets());
118
+		} catch (Exception $exception) {
119
+			new ExceptionStackTraceDisplay($exception);
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * Registers JS assets with WP core
126
+	 *
127
+	 * @since 4.9.62.p
128
+	 * @param JavascriptAsset[] $scripts
129
+	 * @throws AssetRegistrationException
130
+	 * @throws InvalidDataTypeException
131
+	 */
132
+	public function registerScripts(array $scripts)
133
+	{
134
+		foreach ($scripts as $script) {
135
+			// skip to next script if this has already been done
136
+			if ($script->isRegistered()) {
137
+				continue;
138
+			}
139
+			do_action(
140
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
+				$script
142
+			);
143
+			$registered = wp_register_script(
144
+				$script->handle(),
145
+				$script->source(),
146
+				$script->dependencies(),
147
+				$script->version(),
148
+				$script->loadInFooter()
149
+			);
150
+			if (! $registered && $this->debug()) {
151
+				throw new AssetRegistrationException($script->handle());
152
+			}
153
+			$script->setRegistered($registered);
154
+			if ($script->requiresTranslation()) {
155
+				$this->registerTranslation($script->handle());
156
+			}
157
+			do_action(
158
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
+				$script
160
+			);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Registers CSS assets with WP core
167
+	 *
168
+	 * @since 4.9.62.p
169
+	 * @param StylesheetAsset[] $styles
170
+	 * @throws InvalidDataTypeException
171
+	 */
172
+	public function registerStyles(array $styles)
173
+	{
174
+		foreach ($styles as $style) {
175
+			// skip to next style if this has already been done
176
+			if ($style->isRegistered()) {
177
+				continue;
178
+			}
179
+			do_action(
180
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
+				$style
182
+			);
183
+			wp_register_style(
184
+				$style->handle(),
185
+				$style->source(),
186
+				$style->dependencies(),
187
+				$style->version(),
188
+				$style->media()
189
+			);
190
+			$style->setRegistered();
191
+			do_action(
192
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
+				$style
194
+			);
195
+		}
196
+	}
197
+
198
+
199
+	/**
200
+	 * Call back for the script print in frontend and backend.
201
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
+	 *
203
+	 * @since 4.9.31.rc.015
204
+	 */
205
+	public function enqueueData()
206
+	{
207
+		$this->removeAlreadyRegisteredDataForScriptHandles();
208
+		wp_add_inline_script(
209
+			'eejs-core',
210
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
+			'before'
212
+		);
213
+		$scripts = $this->assets->getJavascriptAssetsWithData();
214
+		foreach ($scripts as $script) {
215
+			$this->addRegisteredScriptHandlesWithData($script->handle());
216
+			if ($script->hasInlineDataCallback()) {
217
+				$localize = $script->inlineDataCallback();
218
+				$localize();
219
+			}
220
+		}
221
+	}
222
+
223
+
224
+	/**
225
+	 * Used to add data to eejs.data object.
226
+	 * Note:  Overriding existing data is not allowed.
227
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
+	 * If the data you add is something like this:
229
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
+	 * It will be exposed in the page source as:
231
+	 *  eejs.data.my_plugin_data.foo == gar
232
+	 *
233
+	 * @param string       $key   Key used to access your data
234
+	 * @param string|array $value Value to attach to key
235
+	 * @throws InvalidArgumentException
236
+	 */
237
+	public function addData($key, $value)
238
+	{
239
+		if ($this->verifyDataNotExisting($key)) {
240
+			$this->jsdata[ $key ] = $value;
241
+		}
242
+	}
243
+
244
+
245
+	/**
246
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
+	 * elements in an array.
248
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
249
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
250
+	 * object like this, eejs.data.test = [ my_data,
251
+	 * ]
252
+	 * If there has already been a scalar value attached to the data object given key, then
253
+	 * this will throw an exception.
254
+	 *
255
+	 * @param string       $key   Key to attach data to.
256
+	 * @param string|array $value Value being registered.
257
+	 * @throws InvalidArgumentException
258
+	 */
259
+	public function pushData($key, $value)
260
+	{
261
+		if (isset($this->jsdata[ $key ])
262
+			&& ! is_array($this->jsdata[ $key ])
263
+		) {
264
+			if (! $this->debug()) {
265
+				return;
266
+			}
267
+			throw new InvalidArgumentException(
268
+				sprintf(
269
+					__(
270
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
271 271
                          push values to this data element when it is an array.',
272
-                        'event_espresso'
273
-                    ),
274
-                    $key,
275
-                    __METHOD__
276
-                )
277
-            );
278
-        }
279
-        $this->jsdata[ $key ][] = $value;
280
-    }
281
-
282
-
283
-    /**
284
-     * Used to set content used by javascript for a template.
285
-     * Note: Overrides of existing registered templates are not allowed.
286
-     *
287
-     * @param string $template_reference
288
-     * @param string $template_content
289
-     * @throws InvalidArgumentException
290
-     */
291
-    public function addTemplate($template_reference, $template_content)
292
-    {
293
-        if (! isset($this->jsdata['templates'])) {
294
-            $this->jsdata['templates'] = array();
295
-        }
296
-        //no overrides allowed.
297
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
298
-            if (! $this->debug()) {
299
-                return;
300
-            }
301
-            throw new InvalidArgumentException(
302
-                sprintf(
303
-                    __(
304
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
305
-                        'event_espresso'
306
-                    ),
307
-                    $template_reference
308
-                )
309
-            );
310
-        }
311
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
312
-    }
313
-
314
-
315
-    /**
316
-     * Retrieve the template content already registered for the given reference.
317
-     *
318
-     * @param string $template_reference
319
-     * @return string
320
-     */
321
-    public function getTemplate($template_reference)
322
-    {
323
-        return isset($this->jsdata['templates'][ $template_reference ])
324
-            ? $this->jsdata['templates'][ $template_reference ]
325
-            : '';
326
-    }
327
-
328
-
329
-    /**
330
-     * Retrieve registered data.
331
-     *
332
-     * @param string $key Name of key to attach data to.
333
-     * @return mixed                If there is no for the given key, then false is returned.
334
-     */
335
-    public function getData($key)
336
-    {
337
-        return isset($this->jsdata[ $key ])
338
-            ? $this->jsdata[ $key ]
339
-            : false;
340
-    }
341
-
342
-
343
-    /**
344
-     * Verifies whether the given data exists already on the jsdata array.
345
-     * Overriding data is not allowed.
346
-     *
347
-     * @param string $key Index for data.
348
-     * @return bool        If valid then return true.
349
-     * @throws InvalidArgumentException if data already exists.
350
-     */
351
-    protected function verifyDataNotExisting($key)
352
-    {
353
-        if (isset($this->jsdata[ $key ])) {
354
-            if (! $this->debug()) {
355
-                return false;
356
-            }
357
-            if (is_array($this->jsdata[ $key ])) {
358
-                throw new InvalidArgumentException(
359
-                    sprintf(
360
-                        __(
361
-                            'The value for %1$s already exists in the Registry::eejs object.
272
+						'event_espresso'
273
+					),
274
+					$key,
275
+					__METHOD__
276
+				)
277
+			);
278
+		}
279
+		$this->jsdata[ $key ][] = $value;
280
+	}
281
+
282
+
283
+	/**
284
+	 * Used to set content used by javascript for a template.
285
+	 * Note: Overrides of existing registered templates are not allowed.
286
+	 *
287
+	 * @param string $template_reference
288
+	 * @param string $template_content
289
+	 * @throws InvalidArgumentException
290
+	 */
291
+	public function addTemplate($template_reference, $template_content)
292
+	{
293
+		if (! isset($this->jsdata['templates'])) {
294
+			$this->jsdata['templates'] = array();
295
+		}
296
+		//no overrides allowed.
297
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
298
+			if (! $this->debug()) {
299
+				return;
300
+			}
301
+			throw new InvalidArgumentException(
302
+				sprintf(
303
+					__(
304
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
305
+						'event_espresso'
306
+					),
307
+					$template_reference
308
+				)
309
+			);
310
+		}
311
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
312
+	}
313
+
314
+
315
+	/**
316
+	 * Retrieve the template content already registered for the given reference.
317
+	 *
318
+	 * @param string $template_reference
319
+	 * @return string
320
+	 */
321
+	public function getTemplate($template_reference)
322
+	{
323
+		return isset($this->jsdata['templates'][ $template_reference ])
324
+			? $this->jsdata['templates'][ $template_reference ]
325
+			: '';
326
+	}
327
+
328
+
329
+	/**
330
+	 * Retrieve registered data.
331
+	 *
332
+	 * @param string $key Name of key to attach data to.
333
+	 * @return mixed                If there is no for the given key, then false is returned.
334
+	 */
335
+	public function getData($key)
336
+	{
337
+		return isset($this->jsdata[ $key ])
338
+			? $this->jsdata[ $key ]
339
+			: false;
340
+	}
341
+
342
+
343
+	/**
344
+	 * Verifies whether the given data exists already on the jsdata array.
345
+	 * Overriding data is not allowed.
346
+	 *
347
+	 * @param string $key Index for data.
348
+	 * @return bool        If valid then return true.
349
+	 * @throws InvalidArgumentException if data already exists.
350
+	 */
351
+	protected function verifyDataNotExisting($key)
352
+	{
353
+		if (isset($this->jsdata[ $key ])) {
354
+			if (! $this->debug()) {
355
+				return false;
356
+			}
357
+			if (is_array($this->jsdata[ $key ])) {
358
+				throw new InvalidArgumentException(
359
+					sprintf(
360
+						__(
361
+							'The value for %1$s already exists in the Registry::eejs object.
362 362
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
363 363
                             %2$s method to push your value to the array.',
364
-                            'event_espresso'
365
-                        ),
366
-                        $key,
367
-                        'pushData()'
368
-                    )
369
-                );
370
-            }
371
-            throw new InvalidArgumentException(
372
-                sprintf(
373
-                    __(
374
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
364
+							'event_espresso'
365
+						),
366
+						$key,
367
+						'pushData()'
368
+					)
369
+				);
370
+			}
371
+			throw new InvalidArgumentException(
372
+				sprintf(
373
+					__(
374
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
375 375
                         allowed.  Consider attaching your value to a different key',
376
-                        'event_espresso'
377
-                    ),
378
-                    $key
379
-                )
380
-            );
381
-        }
382
-        return true;
383
-    }
384
-
385
-
386
-    /**
387
-     * Get the actual asset path for asset manifests.
388
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
389
-     *
390
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
391
-     *                           asset file location.
392
-     * @param string $chunk_name
393
-     * @param string $asset_type
394
-     * @return string
395
-     * @since 4.9.59.p
396
-     */
397
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
398
-    {
399
-        $url = isset(
400
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
401
-            $this->manifest_data[ $namespace ]['url_base']
402
-        )
403
-            ? $this->manifest_data[ $namespace ]['url_base']
404
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
405
-            : $chunk_name;
406
-        return apply_filters(
407
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
408
-            $url,
409
-            $namespace,
410
-            $chunk_name,
411
-            $asset_type
412
-        );
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Return the url to a js file for the given namespace and chunk name.
419
-     *
420
-     * @param string $namespace
421
-     * @param string $chunk_name
422
-     * @return string
423
-     */
424
-    public function getJsUrl($namespace, $chunk_name)
425
-    {
426
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
427
-    }
428
-
429
-
430
-    /**
431
-     * Return the url to a css file for the given namespace and chunk name.
432
-     *
433
-     * @param string $namespace
434
-     * @param string $chunk_name
435
-     * @return string
436
-     */
437
-    public function getCssUrl($namespace, $chunk_name)
438
-    {
439
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
440
-    }
441
-
442
-
443
-    /**
444
-     * @since 4.9.62.p
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidFilePathException
447
-     */
448
-    public function registerManifestFiles()
449
-    {
450
-        $manifest_files = $this->assets->getManifestFiles();
451
-        foreach ($manifest_files as $manifest_file) {
452
-            $this->registerManifestFile(
453
-                $manifest_file->assetNamespace(),
454
-                $manifest_file->urlBase(),
455
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
456
-            );
457
-        }
458
-    }
459
-
460
-
461
-    /**
462
-     * Used to register a js/css manifest file with the registered_manifest_files property.
463
-     *
464
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
465
-     * @param string $url_base      The url base for the manifest file location.
466
-     * @param string $manifest_file The absolute path to the manifest file.
467
-     * @throws InvalidArgumentException
468
-     * @throws InvalidFilePathException
469
-     * @since 4.9.59.p
470
-     */
471
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
472
-    {
473
-        if (isset($this->manifest_data[ $namespace ])) {
474
-            if (! $this->debug()) {
475
-                return;
476
-            }
477
-            throw new InvalidArgumentException(
478
-                sprintf(
479
-                    esc_html__(
480
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
481
-                        'event_espresso'
482
-                    ),
483
-                    $namespace
484
-                )
485
-            );
486
-        }
487
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
488
-            if (is_admin()) {
489
-                EE_Error::add_error(
490
-                    sprintf(
491
-                        esc_html__(
492
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
493
-                            'event_espresso'
494
-                        ),
495
-                        'Event Espresso',
496
-                        $url_base,
497
-                        'plugins_url',
498
-                        'WP_PLUGIN_URL'
499
-                    ),
500
-                    __FILE__,
501
-                    __FUNCTION__,
502
-                    __LINE__
503
-                );
504
-            }
505
-            return;
506
-        }
507
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
508
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
509
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
510
-        }
511
-    }
512
-
513
-
514
-    /**
515
-     * Decodes json from the provided manifest file.
516
-     *
517
-     * @since 4.9.59.p
518
-     * @param string $manifest_file Path to manifest file.
519
-     * @return array
520
-     * @throws InvalidFilePathException
521
-     */
522
-    private function decodeManifestFile($manifest_file)
523
-    {
524
-        if (! file_exists($manifest_file)) {
525
-            throw new InvalidFilePathException($manifest_file);
526
-        }
527
-        return json_decode(file_get_contents($manifest_file), true);
528
-    }
529
-
530
-
531
-    /**
532
-     * This is used to set registered script handles that have data.
533
-     *
534
-     * @param string $script_handle
535
-     */
536
-    private function addRegisteredScriptHandlesWithData($script_handle)
537
-    {
538
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
539
-    }
540
-
541
-
542
-    /**i
376
+						'event_espresso'
377
+					),
378
+					$key
379
+				)
380
+			);
381
+		}
382
+		return true;
383
+	}
384
+
385
+
386
+	/**
387
+	 * Get the actual asset path for asset manifests.
388
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
389
+	 *
390
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
391
+	 *                           asset file location.
392
+	 * @param string $chunk_name
393
+	 * @param string $asset_type
394
+	 * @return string
395
+	 * @since 4.9.59.p
396
+	 */
397
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
398
+	{
399
+		$url = isset(
400
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
401
+			$this->manifest_data[ $namespace ]['url_base']
402
+		)
403
+			? $this->manifest_data[ $namespace ]['url_base']
404
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
405
+			: $chunk_name;
406
+		return apply_filters(
407
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
408
+			$url,
409
+			$namespace,
410
+			$chunk_name,
411
+			$asset_type
412
+		);
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Return the url to a js file for the given namespace and chunk name.
419
+	 *
420
+	 * @param string $namespace
421
+	 * @param string $chunk_name
422
+	 * @return string
423
+	 */
424
+	public function getJsUrl($namespace, $chunk_name)
425
+	{
426
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
427
+	}
428
+
429
+
430
+	/**
431
+	 * Return the url to a css file for the given namespace and chunk name.
432
+	 *
433
+	 * @param string $namespace
434
+	 * @param string $chunk_name
435
+	 * @return string
436
+	 */
437
+	public function getCssUrl($namespace, $chunk_name)
438
+	{
439
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
440
+	}
441
+
442
+
443
+	/**
444
+	 * @since 4.9.62.p
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidFilePathException
447
+	 */
448
+	public function registerManifestFiles()
449
+	{
450
+		$manifest_files = $this->assets->getManifestFiles();
451
+		foreach ($manifest_files as $manifest_file) {
452
+			$this->registerManifestFile(
453
+				$manifest_file->assetNamespace(),
454
+				$manifest_file->urlBase(),
455
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
456
+			);
457
+		}
458
+	}
459
+
460
+
461
+	/**
462
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
463
+	 *
464
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
465
+	 * @param string $url_base      The url base for the manifest file location.
466
+	 * @param string $manifest_file The absolute path to the manifest file.
467
+	 * @throws InvalidArgumentException
468
+	 * @throws InvalidFilePathException
469
+	 * @since 4.9.59.p
470
+	 */
471
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
472
+	{
473
+		if (isset($this->manifest_data[ $namespace ])) {
474
+			if (! $this->debug()) {
475
+				return;
476
+			}
477
+			throw new InvalidArgumentException(
478
+				sprintf(
479
+					esc_html__(
480
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
481
+						'event_espresso'
482
+					),
483
+					$namespace
484
+				)
485
+			);
486
+		}
487
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
488
+			if (is_admin()) {
489
+				EE_Error::add_error(
490
+					sprintf(
491
+						esc_html__(
492
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
493
+							'event_espresso'
494
+						),
495
+						'Event Espresso',
496
+						$url_base,
497
+						'plugins_url',
498
+						'WP_PLUGIN_URL'
499
+					),
500
+					__FILE__,
501
+					__FUNCTION__,
502
+					__LINE__
503
+				);
504
+			}
505
+			return;
506
+		}
507
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
508
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
509
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
510
+		}
511
+	}
512
+
513
+
514
+	/**
515
+	 * Decodes json from the provided manifest file.
516
+	 *
517
+	 * @since 4.9.59.p
518
+	 * @param string $manifest_file Path to manifest file.
519
+	 * @return array
520
+	 * @throws InvalidFilePathException
521
+	 */
522
+	private function decodeManifestFile($manifest_file)
523
+	{
524
+		if (! file_exists($manifest_file)) {
525
+			throw new InvalidFilePathException($manifest_file);
526
+		}
527
+		return json_decode(file_get_contents($manifest_file), true);
528
+	}
529
+
530
+
531
+	/**
532
+	 * This is used to set registered script handles that have data.
533
+	 *
534
+	 * @param string $script_handle
535
+	 */
536
+	private function addRegisteredScriptHandlesWithData($script_handle)
537
+	{
538
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
539
+	}
540
+
541
+
542
+	/**i
543 543
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
544 544
      * Dependency stored in WP_Scripts if its set.
545 545
      */
546
-    private function removeAlreadyRegisteredDataForScriptHandles()
547
-    {
548
-        if (empty($this->script_handles_with_data)) {
549
-            return;
550
-        }
551
-        foreach ($this->script_handles_with_data as $script_handle) {
552
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * Removes any data dependency registered in WP_Scripts if its set.
559
-     *
560
-     * @param string $script_handle
561
-     */
562
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
563
-    {
564
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
565
-            global $wp_scripts;
566
-            $unset_handle = false;
567
-            if ($wp_scripts->get_data($script_handle, 'data')) {
568
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
569
-                $unset_handle = true;
570
-            }
571
-            //deal with inline_scripts
572
-            if ($wp_scripts->get_data($script_handle, 'before')) {
573
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
574
-                $unset_handle = true;
575
-            }
576
-            if ($wp_scripts->get_data($script_handle, 'after')) {
577
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
578
-            }
579
-            if ($unset_handle) {
580
-                unset($this->script_handles_with_data[ $script_handle ]);
581
-            }
582
-        }
583
-    }
584
-
585
-
586
-    /**
587
-     * register translations for a registered script
588
-     *
589
-     * @param string $handle
590
-     */
591
-    public function registerTranslation($handle)
592
-    {
593
-        $this->i18n_registry->registerScriptI18n($handle);
594
-    }
595
-
596
-
597
-    /**
598
-     * @since 4.9.63.p
599
-     * @return bool
600
-     */
601
-    private function debug()
602
-    {
603
-        return apply_filters(
604
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
605
-            defined('EE_DEBUG') && EE_DEBUG
606
-        );
607
-    }
546
+	private function removeAlreadyRegisteredDataForScriptHandles()
547
+	{
548
+		if (empty($this->script_handles_with_data)) {
549
+			return;
550
+		}
551
+		foreach ($this->script_handles_with_data as $script_handle) {
552
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * Removes any data dependency registered in WP_Scripts if its set.
559
+	 *
560
+	 * @param string $script_handle
561
+	 */
562
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
563
+	{
564
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
565
+			global $wp_scripts;
566
+			$unset_handle = false;
567
+			if ($wp_scripts->get_data($script_handle, 'data')) {
568
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
569
+				$unset_handle = true;
570
+			}
571
+			//deal with inline_scripts
572
+			if ($wp_scripts->get_data($script_handle, 'before')) {
573
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
574
+				$unset_handle = true;
575
+			}
576
+			if ($wp_scripts->get_data($script_handle, 'after')) {
577
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
578
+			}
579
+			if ($unset_handle) {
580
+				unset($this->script_handles_with_data[ $script_handle ]);
581
+			}
582
+		}
583
+	}
584
+
585
+
586
+	/**
587
+	 * register translations for a registered script
588
+	 *
589
+	 * @param string $handle
590
+	 */
591
+	public function registerTranslation($handle)
592
+	{
593
+		$this->i18n_registry->registerScriptI18n($handle);
594
+	}
595
+
596
+
597
+	/**
598
+	 * @since 4.9.63.p
599
+	 * @return bool
600
+	 */
601
+	private function debug()
602
+	{
603
+		return apply_filters(
604
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
605
+			defined('EE_DEBUG') && EE_DEBUG
606
+		);
607
+	}
608 608
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -21,192 +21,192 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * returns TRUE or FALSE
110
-     * depending on whether the object is within the Collection
111
-     * based on the supplied $identifier and type
112
-     *
113
-     * @param  mixed $identifier
114
-     * @param string $type
115
-     * @return bool
116
-     * @since 4.9.63.p
117
-     */
118
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
-    {
120
-        $this->rewind();
121
-        while ($this->valid()) {
122
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
-                $this->rewind();
124
-                return true;
125
-            }
126
-            $this->next();
127
-        }
128
-        return false;
129
-    }
130
-
131
-
132
-    /**
133
-     * returns TRUE or FALSE
134
-     * depending on whether the Javascript Asset is within the Collection
135
-     * based on the supplied $identifier
136
-     *
137
-     * @param  mixed $identifier
138
-     * @return bool
139
-     * @since 4.9.63.p
140
-     */
141
-    public function hasJavascriptAsset($identifier)
142
-    {
143
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
-    }
145
-
146
-
147
-    /**
148
-     * returns TRUE or FALSE
149
-     * depending on whether the Stylesheet Asset is within the Collection
150
-     * based on the supplied $identifier
151
-     *
152
-     * @param  mixed $identifier
153
-     * @return bool
154
-     * @since 4.9.63.p
155
-     */
156
-    public function hasStylesheetAsset($identifier)
157
-    {
158
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
-    }
160
-
161
-    /**
162
-     * returns the object from the Collection
163
-     * based on the supplied $identifier and type
164
-     *
165
-     * @param  mixed $identifier
166
-     * @param string $type
167
-     * @return JavascriptAsset|StylesheetAsset
168
-     * @since 4.9.63.p
169
-     */
170
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
-    {
172
-        $this->rewind();
173
-        while ($this->valid()) {
174
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
-                /** @var JavascriptAsset|StylesheetAsset $object */
176
-                $object = $this->current();
177
-                $this->rewind();
178
-                return $object;
179
-            }
180
-            $this->next();
181
-        }
182
-        return null;
183
-    }
184
-
185
-
186
-    /**
187
-     * returns the Stylesheet Asset from the Collection
188
-     * based on the supplied $identifier
189
-     *
190
-     * @param  mixed $identifier
191
-     * @return StylesheetAsset
192
-     * @since 4.9.63.p
193
-     */
194
-    public function getStylesheetAsset($identifier)
195
-    {
196
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
-    }
198
-
199
-
200
-    /**
201
-     * returns the Javascript Asset from the Collection
202
-     * based on the supplied $identifier
203
-     *
204
-     * @param  mixed $identifier
205
-     * @return JavascriptAsset
206
-     * @since 4.9.63.p
207
-     */
208
-    public function getJavascriptAsset($identifier)
209
-    {
210
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * returns TRUE or FALSE
110
+	 * depending on whether the object is within the Collection
111
+	 * based on the supplied $identifier and type
112
+	 *
113
+	 * @param  mixed $identifier
114
+	 * @param string $type
115
+	 * @return bool
116
+	 * @since 4.9.63.p
117
+	 */
118
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
+	{
120
+		$this->rewind();
121
+		while ($this->valid()) {
122
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
+				$this->rewind();
124
+				return true;
125
+			}
126
+			$this->next();
127
+		}
128
+		return false;
129
+	}
130
+
131
+
132
+	/**
133
+	 * returns TRUE or FALSE
134
+	 * depending on whether the Javascript Asset is within the Collection
135
+	 * based on the supplied $identifier
136
+	 *
137
+	 * @param  mixed $identifier
138
+	 * @return bool
139
+	 * @since 4.9.63.p
140
+	 */
141
+	public function hasJavascriptAsset($identifier)
142
+	{
143
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
+	}
145
+
146
+
147
+	/**
148
+	 * returns TRUE or FALSE
149
+	 * depending on whether the Stylesheet Asset is within the Collection
150
+	 * based on the supplied $identifier
151
+	 *
152
+	 * @param  mixed $identifier
153
+	 * @return bool
154
+	 * @since 4.9.63.p
155
+	 */
156
+	public function hasStylesheetAsset($identifier)
157
+	{
158
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
+	}
160
+
161
+	/**
162
+	 * returns the object from the Collection
163
+	 * based on the supplied $identifier and type
164
+	 *
165
+	 * @param  mixed $identifier
166
+	 * @param string $type
167
+	 * @return JavascriptAsset|StylesheetAsset
168
+	 * @since 4.9.63.p
169
+	 */
170
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
+	{
172
+		$this->rewind();
173
+		while ($this->valid()) {
174
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
+				/** @var JavascriptAsset|StylesheetAsset $object */
176
+				$object = $this->current();
177
+				$this->rewind();
178
+				return $object;
179
+			}
180
+			$this->next();
181
+		}
182
+		return null;
183
+	}
184
+
185
+
186
+	/**
187
+	 * returns the Stylesheet Asset from the Collection
188
+	 * based on the supplied $identifier
189
+	 *
190
+	 * @param  mixed $identifier
191
+	 * @return StylesheetAsset
192
+	 * @since 4.9.63.p
193
+	 */
194
+	public function getStylesheetAsset($identifier)
195
+	{
196
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
+	}
198
+
199
+
200
+	/**
201
+	 * returns the Javascript Asset from the Collection
202
+	 * based on the supplied $identifier
203
+	 *
204
+	 * @param  mixed $identifier
205
+	 * @return JavascriptAsset
206
+	 * @since 4.9.63.p
207
+	 */
208
+	public function getJavascriptAsset($identifier)
209
+	{
210
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
+	}
212 212
 }
Please login to merge, or discard this patch.