Completed
Branch master (1a0f27)
by
unknown
19:05 queued 17:30
created
core/admin/EE_Admin_Page_Init.core.php 2 patches
Indentation   +446 added lines, -446 removed lines patch added patch discarded remove patch
@@ -17,451 +17,451 @@
 block discarded – undo
17 17
 abstract class EE_Admin_Page_Init extends EE_Base
18 18
 {
19 19
 
20
-    // identity properties (set in _set_defaults and _set_init_properties)
21
-    public $label;
20
+	// identity properties (set in _set_defaults and _set_init_properties)
21
+	public $label;
22 22
 
23
-    /**
24
-     * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
25
-     * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
26
-     *
27
-     * @var string
28
-     */
29
-    public $capability;
30
-
31
-
32
-    /**
33
-     * This holds the menu map object for this admin page.
34
-     *
35
-     * @var EE_Admin_Page_Menu_Map
36
-     */
37
-    protected $_menu_map;
38
-
39
-    /**
40
-     * deprecated
41
-     */
42
-    public $menu_label;
43
-
44
-    public $menu_slug;
45
-
46
-
47
-    // set in _set_defaults
48
-    protected $_folder_name;
49
-
50
-    protected $_folder_path;
51
-
52
-    protected $_file_name;
53
-
54
-    public $hook_file;
55
-
56
-    protected $_wp_page_slug;
57
-
58
-    protected $_routing;
59
-
60
-
61
-    // will hold page object.
62
-    protected $_loaded_page_object;
63
-
64
-
65
-    // for caf
66
-    protected $_files_hooked;
67
-
68
-    protected $_hook_paths;
69
-
70
-    // load_page?
71
-    private $_load_page;
72
-
73
-    /**
74
-     * @var LoaderInterface
75
-     */
76
-    protected $loader;
77
-
78
-    /**
79
-     * @var RequestInterface
80
-     */
81
-    protected $request;
82
-
83
-
84
-    /**
85
-     * @Constructor
86
-     * @return void
87
-     */
88
-    public function __construct(RequestInterface $request = null)
89
-    {
90
-        $this->loader = LoaderFactory::getLoader();
91
-        $this->request = $request instanceof RequestInterface
92
-            ? $request
93
-            : $this->loader->getShared(RequestInterface::class);
94
-        // set global defaults
95
-        $this->_set_defaults();
96
-        // set properties that are always available with objects.
97
-        $this->_set_init_properties();
98
-        // global styles/scripts across all wp admin pages
99
-        add_action('admin_enqueue_scripts', [$this, 'load_wp_global_scripts_styles'], 5);
100
-        // load initial stuff.
101
-        $this->_set_file_and_folder_name();
102
-        $this->_set_menu_map();
103
-        if (! $this->verifyMenuMapSet()) {
104
-            return;
105
-        }
106
-        // set default capability
107
-        $this->_set_capability();
108
-    }
109
-
110
-
111
-    /**
112
-     * _set_init_properties
113
-     * Child classes use to set the following properties:
114
-     * $label
115
-     *
116
-     * @abstract
117
-     * @return void
118
-     */
119
-    abstract protected function _set_init_properties();
120
-
121
-
122
-    /**
123
-     * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
124
-     * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
125
-     *
126
-     * @since 4.4.0
127
-     * @ return void.
128
-     */
129
-    protected function _set_menu_map()
130
-    {
131
-        return [];
132
-    }
133
-
134
-
135
-    /**
136
-     * @return bool
137
-     * @since   4.10.14.p
138
-     */
139
-    private function verifyMenuMapSet()
140
-    {
141
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
142
-            EE_Error::doing_it_wrong(
143
-                get_class($this) . '::$_menu_map',
144
-                sprintf(
145
-                    esc_html__(
146
-                        'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
147
-                        'event_espresso'
148
-                    ),
149
-                    get_class($this)
150
-                ),
151
-                '4.4.0'
152
-            );
153
-            return true;
154
-        }
155
-        return false;
156
-    }
157
-
158
-
159
-    /**
160
-     * returns the menu map for this admin page
161
-     *
162
-     * @return EE_Admin_Page_Menu_Map
163
-     * @since 4.4.0
164
-     */
165
-    public function get_menu_map()
166
-    {
167
-        return $this->_menu_map;
168
-    }
169
-
170
-
171
-    /**
172
-     * This loads scripts and styles for the EE_Admin system
173
-     * that must be available on ALL WP admin pages (i.e. EE_menu items)
174
-     *
175
-     * @return void
176
-     */
177
-    public function load_wp_global_scripts_styles()
178
-    {
179
-        wp_register_style(
180
-            'espresso_menu',
181
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
182
-            ['dashicons'],
183
-            EVENT_ESPRESSO_VERSION
184
-        );
185
-        wp_enqueue_style('espresso_menu');
186
-    }
187
-
188
-
189
-    /**
190
-     * this sets default properties (might be overridden in _set_init_properties);
191
-     *
192
-     * @return  void
193
-     */
194
-    private function _set_defaults()
195
-    {
196
-        $this->_file_name    = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
197
-        $this->_routing      = true;
198
-        $this->_load_page    = false;
199
-        $this->_files_hooked = $this->_hook_paths = [];
200
-        // menu_map
201
-        $this->_menu_map = $this->get_menu_map();
202
-    }
203
-
204
-
205
-    protected function _set_capability()
206
-    {
207
-        $capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
208
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
209
-    }
210
-
211
-
212
-    /**
213
-     * initialize_admin_page
214
-     * This method is what executes the loading of the specific page class for the given dir_name as called by the
215
-     * EE_Admin_Init class.
216
-     *
217
-     * @return void
218
-     * @uses    _initialize_admin_page()
219
-     */
220
-    public function initialize_admin_page()
221
-    {
222
-        // let's check user access first
223
-        $this->_check_user_access();
224
-        if (! is_object($this->_loaded_page_object)) {
225
-            return;
226
-        }
227
-        $this->_loaded_page_object->route_admin_request();
228
-    }
229
-
230
-
231
-    /**
232
-     * @param string $wp_page_slug
233
-     * @throws EE_Error
234
-     */
235
-    public function set_page_dependencies($wp_page_slug)
236
-    {
237
-        if (! $this->_load_page) {
238
-            return;
239
-        }
240
-        if (! is_object($this->_loaded_page_object)) {
241
-            $msg[] = esc_html__(
242
-                'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
243
-                'event_espresso'
244
-            );
245
-            $msg[] = $msg[0] . "\r\n"
246
-                     . sprintf(
247
-                         esc_html__(
248
-                             'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
249
-                             'event_espresso'
250
-                         ),
251
-                         $this->_file_name,
252
-                         $this->_file_name,
253
-                         $this->_folder_path . $this->_file_name,
254
-                         $this->_menu_map->menu_slug
255
-                     );
256
-            throw new EE_Error(implode('||', $msg));
257
-        }
258
-        $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
259
-        $page_hook = 'load-' . $wp_page_slug;
260
-        // hook into page load hook so all page specific stuff gets loaded.
261
-        if (! empty($wp_page_slug)) {
262
-            add_action($page_hook, [$this->_loaded_page_object, 'load_page_dependencies']);
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     * This executes the initial page loads for EE_Admin pages to take care of any ajax or other code needing to run
269
-     * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
270
-     *
271
-     * @return void
272
-     */
273
-    public function do_initial_loads()
274
-    {
275
-        // no loading or initializing if menu map is setup incorrectly.
276
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
277
-            return;
278
-        }
279
-        $this->_initialize_admin_page();
280
-    }
281
-
282
-
283
-    /**
284
-     * all we're doing here is setting the $_file_name property for later use.
285
-     *
286
-     * @return void
287
-     */
288
-    private function _set_file_and_folder_name()
289
-    {
290
-        $bt = debug_backtrace();
291
-        // for more reliable determination of folder name
292
-        // we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
293
-        $class = get_class($this);
294
-        foreach ($bt as $index => $values) {
295
-            if (isset($values['class']) && $values['class'] == $class) {
296
-                $file_index         = $index - 1;
297
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
298
-                if (! empty($this->_folder_name)) {
299
-                    break;
300
-                }
301
-            }
302
-        }
303
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
304
-        $this->_file_name   = preg_replace('/^ee/', 'EE', $this->_folder_name);
305
-        $this->_file_name   = ucwords(str_replace('_', ' ', $this->_file_name));
306
-        $this->_file_name   = str_replace(' ', '_', $this->_file_name);
307
-    }
308
-
309
-
310
-    /**
311
-     * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
312
-     * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
313
-     * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
314
-     * events_Messages_Hooks.class.php
315
-     *
316
-     * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
317
-     *                     files/classes
318
-     * @return array
319
-     */
320
-    public function register_hooks($extend = false)
321
-    {
322
-
323
-        // get a list of files in the directory that have the "Hook" in their name an
324
-        // if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
325
-        if ($extend) {
326
-            $hook_files_glob_path = apply_filters(
327
-                'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
328
-                EE_CORE_CAF_ADMIN_EXTEND
329
-                . $this->_folder_name
330
-                . '/*'
331
-                . $this->_file_name
332
-                . '_Hooks_Extend.class.php'
333
-            );
334
-            $this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
335
-        }
336
-        // loop through decaf folders
337
-        $hook_files_glob_path = apply_filters(
338
-            'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
339
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
340
-        );
341
-        $this->_hook_paths    = array_merge(
342
-            $this->_register_hook_files($hook_files_glob_path),
343
-            $this->_hook_paths
344
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
345
-        return $this->_hook_paths;
346
-    }
347
-
348
-
349
-    protected function _register_hook_files($hook_files_glob_path, $extend = false)
350
-    {
351
-        $hook_paths = glob($hook_files_glob_path);
352
-        if (empty($hook_paths)) {
353
-            return [];
354
-        }
355
-        foreach ($hook_paths as $file) {
356
-            // lets get the linked admin.
357
-            $hook_file = $extend
358
-                ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
359
-                : str_replace($this->_folder_path, '', $file);
360
-            $replace         = $extend
361
-                ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
362
-                : '_' . $this->_file_name . '_Hooks.class.php';
363
-            $rel_admin       = str_replace($replace, '', $hook_file);
364
-            $rel_admin       = strtolower($rel_admin);
365
-            // make sure we haven't already got a hook setup for this page path
366
-            if (in_array($rel_admin, $this->_files_hooked)) {
367
-                continue;
368
-            }
369
-            $this->hook_file = $hook_file;
370
-            $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
371
-            add_filter($rel_admin_hook, [$this, 'load_admin_hook']);
372
-            $this->_files_hooked[] = $rel_admin;
373
-        }
374
-        return $hook_paths;
375
-    }
376
-
377
-
378
-    public function load_admin_hook($registered_pages)
379
-    {
380
-        return array_merge((array) $this->hook_file, $registered_pages);
381
-    }
382
-
383
-
384
-    /**
385
-     * _initialize_admin_page
386
-     *
387
-     * @see  initialize_admin_page() for info
388
-     */
389
-    protected function _initialize_admin_page()
390
-    {
391
-        // JUST CHECK WE'RE ON RIGHT PAGE.
392
-        $page = $this->request->getRequestParam('page');
393
-        $page = $this->request->getRequestParam('current_page', $page);
394
-        $menu_slug = $this->_menu_map->menu_slug;
395
-
396
-
397
-        if ($this->_routing && ($page === '' || $page !== $menu_slug)) {
398
-            // not on the right page so let's get out.
399
-            return;
400
-        }
401
-        $this->_load_page = true;
402
-
403
-        // we don't need to do a page_request check here because it's only called via WP menu system.
404
-        $admin_page  = $this->_file_name . '_Admin_Page';
405
-        $hook_suffix = "{$menu_slug}_{$admin_page}";
406
-        $admin_page  = apply_filters(
407
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
408
-            $admin_page
409
-        );
410
-        if (empty($admin_page)) {
411
-            return;
412
-        }
413
-        // define requested admin page class name then load the file and instantiate
414
-        $path_to_file = str_replace(['\\', '/'], '/', $this->_folder_path . $admin_page . '.core.php');
415
-        // so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be:
416
-        // FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
417
-        $path_to_file = apply_filters(
418
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
419
-            $path_to_file
420
-        );
421
-        if (! is_readable($path_to_file)) {
422
-            return;
423
-        }
424
-        // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
425
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
426
-        do_action("AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_{$menu_slug}");
427
-        require_once($path_to_file);
428
-        $this->_loaded_page_object = $this->loader->getShared($admin_page, [$this->_routing]);
429
-
430
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
431
-        do_action("AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_{$menu_slug}");
432
-    }
433
-
434
-
435
-    public function get_admin_page_name()
436
-    {
437
-        return $this->_file_name . '_Admin_Page';
438
-    }
439
-
440
-
441
-    /**
442
-     * @return mixed
443
-     */
444
-    public function loaded_page_object()
445
-    {
446
-        return $this->_loaded_page_object;
447
-    }
448
-
449
-    /**
450
-     * _check_user_access
451
-     * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
452
-     * WordPress die message.
453
-     *
454
-     * @return void  wp_die if fail
455
-     */
456
-    private function _check_user_access()
457
-    {
458
-        if (
459
-            ! EE_Registry::instance()->CAP->current_user_can(
460
-                $this->_menu_map->capability,
461
-                $this->_menu_map->menu_slug
462
-            )
463
-        ) {
464
-            wp_die(esc_html__('You don\'t have access to this page.', 'event_espresso'), '', ['back_link' => true]);
465
-        }
466
-    }
23
+	/**
24
+	 * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
25
+	 * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
26
+	 *
27
+	 * @var string
28
+	 */
29
+	public $capability;
30
+
31
+
32
+	/**
33
+	 * This holds the menu map object for this admin page.
34
+	 *
35
+	 * @var EE_Admin_Page_Menu_Map
36
+	 */
37
+	protected $_menu_map;
38
+
39
+	/**
40
+	 * deprecated
41
+	 */
42
+	public $menu_label;
43
+
44
+	public $menu_slug;
45
+
46
+
47
+	// set in _set_defaults
48
+	protected $_folder_name;
49
+
50
+	protected $_folder_path;
51
+
52
+	protected $_file_name;
53
+
54
+	public $hook_file;
55
+
56
+	protected $_wp_page_slug;
57
+
58
+	protected $_routing;
59
+
60
+
61
+	// will hold page object.
62
+	protected $_loaded_page_object;
63
+
64
+
65
+	// for caf
66
+	protected $_files_hooked;
67
+
68
+	protected $_hook_paths;
69
+
70
+	// load_page?
71
+	private $_load_page;
72
+
73
+	/**
74
+	 * @var LoaderInterface
75
+	 */
76
+	protected $loader;
77
+
78
+	/**
79
+	 * @var RequestInterface
80
+	 */
81
+	protected $request;
82
+
83
+
84
+	/**
85
+	 * @Constructor
86
+	 * @return void
87
+	 */
88
+	public function __construct(RequestInterface $request = null)
89
+	{
90
+		$this->loader = LoaderFactory::getLoader();
91
+		$this->request = $request instanceof RequestInterface
92
+			? $request
93
+			: $this->loader->getShared(RequestInterface::class);
94
+		// set global defaults
95
+		$this->_set_defaults();
96
+		// set properties that are always available with objects.
97
+		$this->_set_init_properties();
98
+		// global styles/scripts across all wp admin pages
99
+		add_action('admin_enqueue_scripts', [$this, 'load_wp_global_scripts_styles'], 5);
100
+		// load initial stuff.
101
+		$this->_set_file_and_folder_name();
102
+		$this->_set_menu_map();
103
+		if (! $this->verifyMenuMapSet()) {
104
+			return;
105
+		}
106
+		// set default capability
107
+		$this->_set_capability();
108
+	}
109
+
110
+
111
+	/**
112
+	 * _set_init_properties
113
+	 * Child classes use to set the following properties:
114
+	 * $label
115
+	 *
116
+	 * @abstract
117
+	 * @return void
118
+	 */
119
+	abstract protected function _set_init_properties();
120
+
121
+
122
+	/**
123
+	 * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
124
+	 * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
125
+	 *
126
+	 * @since 4.4.0
127
+	 * @ return void.
128
+	 */
129
+	protected function _set_menu_map()
130
+	{
131
+		return [];
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return bool
137
+	 * @since   4.10.14.p
138
+	 */
139
+	private function verifyMenuMapSet()
140
+	{
141
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
142
+			EE_Error::doing_it_wrong(
143
+				get_class($this) . '::$_menu_map',
144
+				sprintf(
145
+					esc_html__(
146
+						'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
147
+						'event_espresso'
148
+					),
149
+					get_class($this)
150
+				),
151
+				'4.4.0'
152
+			);
153
+			return true;
154
+		}
155
+		return false;
156
+	}
157
+
158
+
159
+	/**
160
+	 * returns the menu map for this admin page
161
+	 *
162
+	 * @return EE_Admin_Page_Menu_Map
163
+	 * @since 4.4.0
164
+	 */
165
+	public function get_menu_map()
166
+	{
167
+		return $this->_menu_map;
168
+	}
169
+
170
+
171
+	/**
172
+	 * This loads scripts and styles for the EE_Admin system
173
+	 * that must be available on ALL WP admin pages (i.e. EE_menu items)
174
+	 *
175
+	 * @return void
176
+	 */
177
+	public function load_wp_global_scripts_styles()
178
+	{
179
+		wp_register_style(
180
+			'espresso_menu',
181
+			EE_ADMIN_URL . 'assets/admin-menu-styles.css',
182
+			['dashicons'],
183
+			EVENT_ESPRESSO_VERSION
184
+		);
185
+		wp_enqueue_style('espresso_menu');
186
+	}
187
+
188
+
189
+	/**
190
+	 * this sets default properties (might be overridden in _set_init_properties);
191
+	 *
192
+	 * @return  void
193
+	 */
194
+	private function _set_defaults()
195
+	{
196
+		$this->_file_name    = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
197
+		$this->_routing      = true;
198
+		$this->_load_page    = false;
199
+		$this->_files_hooked = $this->_hook_paths = [];
200
+		// menu_map
201
+		$this->_menu_map = $this->get_menu_map();
202
+	}
203
+
204
+
205
+	protected function _set_capability()
206
+	{
207
+		$capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
208
+		$this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
209
+	}
210
+
211
+
212
+	/**
213
+	 * initialize_admin_page
214
+	 * This method is what executes the loading of the specific page class for the given dir_name as called by the
215
+	 * EE_Admin_Init class.
216
+	 *
217
+	 * @return void
218
+	 * @uses    _initialize_admin_page()
219
+	 */
220
+	public function initialize_admin_page()
221
+	{
222
+		// let's check user access first
223
+		$this->_check_user_access();
224
+		if (! is_object($this->_loaded_page_object)) {
225
+			return;
226
+		}
227
+		$this->_loaded_page_object->route_admin_request();
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param string $wp_page_slug
233
+	 * @throws EE_Error
234
+	 */
235
+	public function set_page_dependencies($wp_page_slug)
236
+	{
237
+		if (! $this->_load_page) {
238
+			return;
239
+		}
240
+		if (! is_object($this->_loaded_page_object)) {
241
+			$msg[] = esc_html__(
242
+				'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
243
+				'event_espresso'
244
+			);
245
+			$msg[] = $msg[0] . "\r\n"
246
+					 . sprintf(
247
+						 esc_html__(
248
+							 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
249
+							 'event_espresso'
250
+						 ),
251
+						 $this->_file_name,
252
+						 $this->_file_name,
253
+						 $this->_folder_path . $this->_file_name,
254
+						 $this->_menu_map->menu_slug
255
+					 );
256
+			throw new EE_Error(implode('||', $msg));
257
+		}
258
+		$this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
259
+		$page_hook = 'load-' . $wp_page_slug;
260
+		// hook into page load hook so all page specific stuff gets loaded.
261
+		if (! empty($wp_page_slug)) {
262
+			add_action($page_hook, [$this->_loaded_page_object, 'load_page_dependencies']);
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 * This executes the initial page loads for EE_Admin pages to take care of any ajax or other code needing to run
269
+	 * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
270
+	 *
271
+	 * @return void
272
+	 */
273
+	public function do_initial_loads()
274
+	{
275
+		// no loading or initializing if menu map is setup incorrectly.
276
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
277
+			return;
278
+		}
279
+		$this->_initialize_admin_page();
280
+	}
281
+
282
+
283
+	/**
284
+	 * all we're doing here is setting the $_file_name property for later use.
285
+	 *
286
+	 * @return void
287
+	 */
288
+	private function _set_file_and_folder_name()
289
+	{
290
+		$bt = debug_backtrace();
291
+		// for more reliable determination of folder name
292
+		// we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
293
+		$class = get_class($this);
294
+		foreach ($bt as $index => $values) {
295
+			if (isset($values['class']) && $values['class'] == $class) {
296
+				$file_index         = $index - 1;
297
+				$this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
298
+				if (! empty($this->_folder_name)) {
299
+					break;
300
+				}
301
+			}
302
+		}
303
+		$this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
304
+		$this->_file_name   = preg_replace('/^ee/', 'EE', $this->_folder_name);
305
+		$this->_file_name   = ucwords(str_replace('_', ' ', $this->_file_name));
306
+		$this->_file_name   = str_replace(' ', '_', $this->_file_name);
307
+	}
308
+
309
+
310
+	/**
311
+	 * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
312
+	 * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
313
+	 * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
314
+	 * events_Messages_Hooks.class.php
315
+	 *
316
+	 * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
317
+	 *                     files/classes
318
+	 * @return array
319
+	 */
320
+	public function register_hooks($extend = false)
321
+	{
322
+
323
+		// get a list of files in the directory that have the "Hook" in their name an
324
+		// if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
325
+		if ($extend) {
326
+			$hook_files_glob_path = apply_filters(
327
+				'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
328
+				EE_CORE_CAF_ADMIN_EXTEND
329
+				. $this->_folder_name
330
+				. '/*'
331
+				. $this->_file_name
332
+				. '_Hooks_Extend.class.php'
333
+			);
334
+			$this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
335
+		}
336
+		// loop through decaf folders
337
+		$hook_files_glob_path = apply_filters(
338
+			'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
339
+			$this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
340
+		);
341
+		$this->_hook_paths    = array_merge(
342
+			$this->_register_hook_files($hook_files_glob_path),
343
+			$this->_hook_paths
344
+		);  // making sure any extended hook paths are later in the array than the core hook paths!
345
+		return $this->_hook_paths;
346
+	}
347
+
348
+
349
+	protected function _register_hook_files($hook_files_glob_path, $extend = false)
350
+	{
351
+		$hook_paths = glob($hook_files_glob_path);
352
+		if (empty($hook_paths)) {
353
+			return [];
354
+		}
355
+		foreach ($hook_paths as $file) {
356
+			// lets get the linked admin.
357
+			$hook_file = $extend
358
+				? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
359
+				: str_replace($this->_folder_path, '', $file);
360
+			$replace         = $extend
361
+				? '_' . $this->_file_name . '_Hooks_Extend.class.php'
362
+				: '_' . $this->_file_name . '_Hooks.class.php';
363
+			$rel_admin       = str_replace($replace, '', $hook_file);
364
+			$rel_admin       = strtolower($rel_admin);
365
+			// make sure we haven't already got a hook setup for this page path
366
+			if (in_array($rel_admin, $this->_files_hooked)) {
367
+				continue;
368
+			}
369
+			$this->hook_file = $hook_file;
370
+			$rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
371
+			add_filter($rel_admin_hook, [$this, 'load_admin_hook']);
372
+			$this->_files_hooked[] = $rel_admin;
373
+		}
374
+		return $hook_paths;
375
+	}
376
+
377
+
378
+	public function load_admin_hook($registered_pages)
379
+	{
380
+		return array_merge((array) $this->hook_file, $registered_pages);
381
+	}
382
+
383
+
384
+	/**
385
+	 * _initialize_admin_page
386
+	 *
387
+	 * @see  initialize_admin_page() for info
388
+	 */
389
+	protected function _initialize_admin_page()
390
+	{
391
+		// JUST CHECK WE'RE ON RIGHT PAGE.
392
+		$page = $this->request->getRequestParam('page');
393
+		$page = $this->request->getRequestParam('current_page', $page);
394
+		$menu_slug = $this->_menu_map->menu_slug;
395
+
396
+
397
+		if ($this->_routing && ($page === '' || $page !== $menu_slug)) {
398
+			// not on the right page so let's get out.
399
+			return;
400
+		}
401
+		$this->_load_page = true;
402
+
403
+		// we don't need to do a page_request check here because it's only called via WP menu system.
404
+		$admin_page  = $this->_file_name . '_Admin_Page';
405
+		$hook_suffix = "{$menu_slug}_{$admin_page}";
406
+		$admin_page  = apply_filters(
407
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
408
+			$admin_page
409
+		);
410
+		if (empty($admin_page)) {
411
+			return;
412
+		}
413
+		// define requested admin page class name then load the file and instantiate
414
+		$path_to_file = str_replace(['\\', '/'], '/', $this->_folder_path . $admin_page . '.core.php');
415
+		// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be:
416
+		// FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
417
+		$path_to_file = apply_filters(
418
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
419
+			$path_to_file
420
+		);
421
+		if (! is_readable($path_to_file)) {
422
+			return;
423
+		}
424
+		// This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
425
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
426
+		do_action("AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_{$menu_slug}");
427
+		require_once($path_to_file);
428
+		$this->_loaded_page_object = $this->loader->getShared($admin_page, [$this->_routing]);
429
+
430
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
431
+		do_action("AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_{$menu_slug}");
432
+	}
433
+
434
+
435
+	public function get_admin_page_name()
436
+	{
437
+		return $this->_file_name . '_Admin_Page';
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return mixed
443
+	 */
444
+	public function loaded_page_object()
445
+	{
446
+		return $this->_loaded_page_object;
447
+	}
448
+
449
+	/**
450
+	 * _check_user_access
451
+	 * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
452
+	 * WordPress die message.
453
+	 *
454
+	 * @return void  wp_die if fail
455
+	 */
456
+	private function _check_user_access()
457
+	{
458
+		if (
459
+			! EE_Registry::instance()->CAP->current_user_can(
460
+				$this->_menu_map->capability,
461
+				$this->_menu_map->menu_slug
462
+			)
463
+		) {
464
+			wp_die(esc_html__('You don\'t have access to this page.', 'event_espresso'), '', ['back_link' => true]);
465
+		}
466
+	}
467 467
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         // load initial stuff.
101 101
         $this->_set_file_and_folder_name();
102 102
         $this->_set_menu_map();
103
-        if (! $this->verifyMenuMapSet()) {
103
+        if ( ! $this->verifyMenuMapSet()) {
104 104
             return;
105 105
         }
106 106
         // set default capability
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     {
141 141
         if (empty($this->_menu_map) || is_array($this->_menu_map)) {
142 142
             EE_Error::doing_it_wrong(
143
-                get_class($this) . '::$_menu_map',
143
+                get_class($this).'::$_menu_map',
144 144
                 sprintf(
145 145
                     esc_html__(
146 146
                         'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     {
179 179
         wp_register_style(
180 180
             'espresso_menu',
181
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
181
+            EE_ADMIN_URL.'assets/admin-menu-styles.css',
182 182
             ['dashicons'],
183 183
             EVENT_ESPRESSO_VERSION
184 184
         );
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
     protected function _set_capability()
206 206
     {
207 207
         $capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
208
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
208
+        $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability);
209 209
     }
210 210
 
211 211
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     {
222 222
         // let's check user access first
223 223
         $this->_check_user_access();
224
-        if (! is_object($this->_loaded_page_object)) {
224
+        if ( ! is_object($this->_loaded_page_object)) {
225 225
             return;
226 226
         }
227 227
         $this->_loaded_page_object->route_admin_request();
@@ -234,15 +234,15 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function set_page_dependencies($wp_page_slug)
236 236
     {
237
-        if (! $this->_load_page) {
237
+        if ( ! $this->_load_page) {
238 238
             return;
239 239
         }
240
-        if (! is_object($this->_loaded_page_object)) {
240
+        if ( ! is_object($this->_loaded_page_object)) {
241 241
             $msg[] = esc_html__(
242 242
                 'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
243 243
                 'event_espresso'
244 244
             );
245
-            $msg[] = $msg[0] . "\r\n"
245
+            $msg[] = $msg[0]."\r\n"
246 246
                      . sprintf(
247 247
                          esc_html__(
248 248
                              'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
                          ),
251 251
                          $this->_file_name,
252 252
                          $this->_file_name,
253
-                         $this->_folder_path . $this->_file_name,
253
+                         $this->_folder_path.$this->_file_name,
254 254
                          $this->_menu_map->menu_slug
255 255
                      );
256 256
             throw new EE_Error(implode('||', $msg));
257 257
         }
258 258
         $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
259
-        $page_hook = 'load-' . $wp_page_slug;
259
+        $page_hook = 'load-'.$wp_page_slug;
260 260
         // hook into page load hook so all page specific stuff gets loaded.
261
-        if (! empty($wp_page_slug)) {
261
+        if ( ! empty($wp_page_slug)) {
262 262
             add_action($page_hook, [$this->_loaded_page_object, 'load_page_dependencies']);
263 263
         }
264 264
     }
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
         foreach ($bt as $index => $values) {
295 295
             if (isset($values['class']) && $values['class'] == $class) {
296 296
                 $file_index         = $index - 1;
297
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
298
-                if (! empty($this->_folder_name)) {
297
+                $this->_folder_name = basename(dirname($bt[$file_index]['file']));
298
+                if ( ! empty($this->_folder_name)) {
299 299
                     break;
300 300
                 }
301 301
             }
302 302
         }
303
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
303
+        $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.'/';
304 304
         $this->_file_name   = preg_replace('/^ee/', 'EE', $this->_folder_name);
305 305
         $this->_file_name   = ucwords(str_replace('_', ' ', $this->_file_name));
306 306
         $this->_file_name   = str_replace(' ', '_', $this->_file_name);
@@ -331,17 +331,17 @@  discard block
 block discarded – undo
331 331
                 . $this->_file_name
332 332
                 . '_Hooks_Extend.class.php'
333 333
             );
334
-            $this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
334
+            $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
335 335
         }
336 336
         // loop through decaf folders
337 337
         $hook_files_glob_path = apply_filters(
338 338
             'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
339
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
339
+            $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php'
340 340
         );
341
-        $this->_hook_paths    = array_merge(
341
+        $this->_hook_paths = array_merge(
342 342
             $this->_register_hook_files($hook_files_glob_path),
343 343
             $this->_hook_paths
344
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
344
+        ); // making sure any extended hook paths are later in the array than the core hook paths!
345 345
         return $this->_hook_paths;
346 346
     }
347 347
 
@@ -355,11 +355,11 @@  discard block
 block discarded – undo
355 355
         foreach ($hook_paths as $file) {
356 356
             // lets get the linked admin.
357 357
             $hook_file = $extend
358
-                ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
358
+                ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.'/', '', $file)
359 359
                 : str_replace($this->_folder_path, '', $file);
360 360
             $replace         = $extend
361
-                ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
362
-                : '_' . $this->_file_name . '_Hooks.class.php';
361
+                ? '_'.$this->_file_name.'_Hooks_Extend.class.php'
362
+                : '_'.$this->_file_name.'_Hooks.class.php';
363 363
             $rel_admin       = str_replace($replace, '', $hook_file);
364 364
             $rel_admin       = strtolower($rel_admin);
365 365
             // make sure we haven't already got a hook setup for this page path
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                 continue;
368 368
             }
369 369
             $this->hook_file = $hook_file;
370
-            $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
370
+            $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin;
371 371
             add_filter($rel_admin_hook, [$this, 'load_admin_hook']);
372 372
             $this->_files_hooked[] = $rel_admin;
373 373
         }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $this->_load_page = true;
402 402
 
403 403
         // we don't need to do a page_request check here because it's only called via WP menu system.
404
-        $admin_page  = $this->_file_name . '_Admin_Page';
404
+        $admin_page  = $this->_file_name.'_Admin_Page';
405 405
         $hook_suffix = "{$menu_slug}_{$admin_page}";
406 406
         $admin_page  = apply_filters(
407 407
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
@@ -411,14 +411,14 @@  discard block
 block discarded – undo
411 411
             return;
412 412
         }
413 413
         // define requested admin page class name then load the file and instantiate
414
-        $path_to_file = str_replace(['\\', '/'], '/', $this->_folder_path . $admin_page . '.core.php');
414
+        $path_to_file = str_replace(['\\', '/'], '/', $this->_folder_path.$admin_page.'.core.php');
415 415
         // so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be:
416 416
         // FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
417 417
         $path_to_file = apply_filters(
418 418
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
419 419
             $path_to_file
420 420
         );
421
-        if (! is_readable($path_to_file)) {
421
+        if ( ! is_readable($path_to_file)) {
422 422
             return;
423 423
         }
424 424
         // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 
435 435
     public function get_admin_page_name()
436 436
     {
437
-        return $this->_file_name . '_Admin_Page';
437
+        return $this->_file_name.'_Admin_Page';
438 438
     }
439 439
 
440 440
 
Please login to merge, or discard this patch.
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.6.2');
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.6.2');
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.10.15.rc.011');
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.10.15.rc.011');
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.