Completed
Pull Request — FET/Gutenberg/11400/block-mana... (#317)
by
unknown
13:28
created
core/services/editor/EditorBlockRegistrationManager.php 2 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -42,165 +42,165 @@
 block discarded – undo
42 42
 class EditorBlockRegistrationManager extends EditorBlockManager
43 43
 {
44 44
 
45
-    /**
46
-     * @var AssetRegisterCollection $asset_register_collection
47
-     */
48
-    protected $asset_register_collection;
49
-
50
-
51
-    /**
52
-     * EditorBlockRegistrationManager constructor.
53
-     *
54
-     * @param AssetRegisterCollection $asset_register_collection
55
-     * @param EditorBlockCollection   $blocks
56
-     * @param RequestInterface        $request
57
-     * @param DomainInterface         $domain
58
-     * @param Registry                $registry
59
-     */
60
-    public function __construct(
61
-        AssetRegisterCollection $asset_register_collection,
62
-        EditorBlockCollection $blocks,
63
-        RequestInterface $request,
64
-        DomainInterface $domain,
65
-        Registry $registry
66
-    ) {
67
-        parent::__construct($blocks, $request, $domain, $registry);
68
-        $this->asset_register_collection = $asset_register_collection;
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *  Returns the name of a hookpoint to be used to call initialize()
75
-     *
76
-     * @return string
77
-     */
78
-    public function init_hook()
79
-    {
80
-        return 'AHEE__EE_System__set_hooks_for_core';
81
-    }
82
-
83
-
84
-    /**
85
-     * Perform any early setup required for block editors to functions
86
-     *
87
-     * @return void
88
-     * @throws Exception
89
-     */
90
-    public function initialize()
91
-    {
92
-        $this->loadEditorBlocks();
93
-        add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
94
-    }
95
-
96
-
97
-    /**
98
-     * @return CollectionInterface|EditorBlockInterface[]
99
-     * @throws ReflectionException
100
-     * @throws InvalidArgumentException
101
-     * @throws EE_Error
102
-     * @throws InvalidClassException
103
-     * @throws InvalidDataTypeException
104
-     * @throws InvalidEntityException
105
-     * @throws InvalidFilePathException
106
-     * @throws InvalidIdentifierException
107
-     * @throws InvalidInterfaceException
108
-     */
109
-    protected function populateEditorBlockCollection()
110
-    {
111
-        $loader = new CollectionLoader(
112
-            new CollectionDetails(
113
-            // collection name
114
-                'shortcodes',
115
-                // collection interface
116
-                'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
117
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
118
-                apply_filters(
119
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
120
-                    array(
121
-                        // 'EventEspresso\core\domain\entities\editor\blocks\common',
122
-                        // 'EventEspresso\core\domain\entities\editor\blocks\editor',
123
-                        'EventEspresso\core\domain\entities\editor\blocks\widgets',
124
-                    )
125
-                ),
126
-                // filepaths to classes to add
127
-                array(),
128
-                // file mask to use if parsing folder for files to add
129
-                '',
130
-                // what to use as identifier for collection entities
131
-                // using CLASS NAME prevents duplicates (works like a singleton)
132
-                CollectionDetails::ID_CLASS_NAME
133
-            ),
134
-            $this->blocks
135
-        );
136
-        return $loader->getCollection();
137
-    }
138
-
139
-
140
-    /**
141
-     * populates the EditorBlockCollection and calls initialize() on all installed blocks
142
-     *
143
-     * @return void
144
-     * @throws Exception
145
-     */
146
-    public function loadEditorBlocks()
147
-    {
148
-        try {
149
-            $this->populateEditorBlockCollection();
150
-            // cycle thru block loaders and initialize each loader
151
-            foreach ($this->blocks as $block) {
152
-                $block->initialize();
153
-            }
154
-        } catch (Exception $exception) {
155
-            new ExceptionStackTraceDisplay($exception);
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * calls registerBlock() and load assets for all installed blocks
162
-     *
163
-     * @return void
164
-     * @throws Exception
165
-     */
166
-    public function registerEditorBlocks()
167
-    {
168
-        try {
169
-            // cycle thru block loader folders
170
-            foreach ($this->blocks as $block) {
171
-                // perform any setup required for the block
172
-                $block_type = $block->registerBlock();
173
-                if (! $block_type instanceof WP_Block_Type) {
174
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
175
-                }
176
-                if(! $this->asset_register_collection->has($block->assetRegister())){
177
-                    $this->asset_register_collection->add($block->assetRegister());
178
-                }
179
-                do_action(
180
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
181
-                    $block,
182
-                    $block_type
183
-                );
184
-            }
185
-            if ($this->asset_register_collection->hasObjects()) {
186
-                $this->asset_register_collection->registerManifestFile();
187
-                // register primary assets
188
-                add_action('enqueue_block_assets', array($this, 'registerAssets'));
189
-            }
190
-        } catch (Exception $exception) {
191
-            new ExceptionStackTraceDisplay($exception);
192
-        }
193
-    }
194
-
195
-
196
-    /**
197
-     * Registers assets for all classes in the AssetRegisterCollection
198
-     */
199
-    public function registerAssets()
200
-    {
201
-        $this->asset_register_collection->registerScripts();
202
-        $this->asset_register_collection->registerStyles();
203
-    }
45
+	/**
46
+	 * @var AssetRegisterCollection $asset_register_collection
47
+	 */
48
+	protected $asset_register_collection;
49
+
50
+
51
+	/**
52
+	 * EditorBlockRegistrationManager constructor.
53
+	 *
54
+	 * @param AssetRegisterCollection $asset_register_collection
55
+	 * @param EditorBlockCollection   $blocks
56
+	 * @param RequestInterface        $request
57
+	 * @param DomainInterface         $domain
58
+	 * @param Registry                $registry
59
+	 */
60
+	public function __construct(
61
+		AssetRegisterCollection $asset_register_collection,
62
+		EditorBlockCollection $blocks,
63
+		RequestInterface $request,
64
+		DomainInterface $domain,
65
+		Registry $registry
66
+	) {
67
+		parent::__construct($blocks, $request, $domain, $registry);
68
+		$this->asset_register_collection = $asset_register_collection;
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *  Returns the name of a hookpoint to be used to call initialize()
75
+	 *
76
+	 * @return string
77
+	 */
78
+	public function init_hook()
79
+	{
80
+		return 'AHEE__EE_System__set_hooks_for_core';
81
+	}
82
+
83
+
84
+	/**
85
+	 * Perform any early setup required for block editors to functions
86
+	 *
87
+	 * @return void
88
+	 * @throws Exception
89
+	 */
90
+	public function initialize()
91
+	{
92
+		$this->loadEditorBlocks();
93
+		add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return CollectionInterface|EditorBlockInterface[]
99
+	 * @throws ReflectionException
100
+	 * @throws InvalidArgumentException
101
+	 * @throws EE_Error
102
+	 * @throws InvalidClassException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws InvalidEntityException
105
+	 * @throws InvalidFilePathException
106
+	 * @throws InvalidIdentifierException
107
+	 * @throws InvalidInterfaceException
108
+	 */
109
+	protected function populateEditorBlockCollection()
110
+	{
111
+		$loader = new CollectionLoader(
112
+			new CollectionDetails(
113
+			// collection name
114
+				'shortcodes',
115
+				// collection interface
116
+				'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
117
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
118
+				apply_filters(
119
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
120
+					array(
121
+						// 'EventEspresso\core\domain\entities\editor\blocks\common',
122
+						// 'EventEspresso\core\domain\entities\editor\blocks\editor',
123
+						'EventEspresso\core\domain\entities\editor\blocks\widgets',
124
+					)
125
+				),
126
+				// filepaths to classes to add
127
+				array(),
128
+				// file mask to use if parsing folder for files to add
129
+				'',
130
+				// what to use as identifier for collection entities
131
+				// using CLASS NAME prevents duplicates (works like a singleton)
132
+				CollectionDetails::ID_CLASS_NAME
133
+			),
134
+			$this->blocks
135
+		);
136
+		return $loader->getCollection();
137
+	}
138
+
139
+
140
+	/**
141
+	 * populates the EditorBlockCollection and calls initialize() on all installed blocks
142
+	 *
143
+	 * @return void
144
+	 * @throws Exception
145
+	 */
146
+	public function loadEditorBlocks()
147
+	{
148
+		try {
149
+			$this->populateEditorBlockCollection();
150
+			// cycle thru block loaders and initialize each loader
151
+			foreach ($this->blocks as $block) {
152
+				$block->initialize();
153
+			}
154
+		} catch (Exception $exception) {
155
+			new ExceptionStackTraceDisplay($exception);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * calls registerBlock() and load assets for all installed blocks
162
+	 *
163
+	 * @return void
164
+	 * @throws Exception
165
+	 */
166
+	public function registerEditorBlocks()
167
+	{
168
+		try {
169
+			// cycle thru block loader folders
170
+			foreach ($this->blocks as $block) {
171
+				// perform any setup required for the block
172
+				$block_type = $block->registerBlock();
173
+				if (! $block_type instanceof WP_Block_Type) {
174
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
175
+				}
176
+				if(! $this->asset_register_collection->has($block->assetRegister())){
177
+					$this->asset_register_collection->add($block->assetRegister());
178
+				}
179
+				do_action(
180
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
181
+					$block,
182
+					$block_type
183
+				);
184
+			}
185
+			if ($this->asset_register_collection->hasObjects()) {
186
+				$this->asset_register_collection->registerManifestFile();
187
+				// register primary assets
188
+				add_action('enqueue_block_assets', array($this, 'registerAssets'));
189
+			}
190
+		} catch (Exception $exception) {
191
+			new ExceptionStackTraceDisplay($exception);
192
+		}
193
+	}
194
+
195
+
196
+	/**
197
+	 * Registers assets for all classes in the AssetRegisterCollection
198
+	 */
199
+	public function registerAssets()
200
+	{
201
+		$this->asset_register_collection->registerScripts();
202
+		$this->asset_register_collection->registerStyles();
203
+	}
204 204
 
205 205
 
206 206
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -170,10 +170,10 @@
 block discarded – undo
170 170
             foreach ($this->blocks as $block) {
171 171
                 // perform any setup required for the block
172 172
                 $block_type = $block->registerBlock();
173
-                if (! $block_type instanceof WP_Block_Type) {
173
+                if ( ! $block_type instanceof WP_Block_Type) {
174 174
                     throw new InvalidEntityException($block_type, 'WP_Block_Type');
175 175
                 }
176
-                if(! $this->asset_register_collection->has($block->assetRegister())){
176
+                if ( ! $this->asset_register_collection->has($block->assetRegister())) {
177 177
                     $this->asset_register_collection->add($block->assetRegister());
178 178
                 }
179 179
                 do_action(
Please login to merge, or discard this patch.
core/services/assets/AssetRegisterCollection.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -20,55 +20,55 @@
 block discarded – undo
20 20
 class AssetRegisterCollection extends Collection implements AssetRegisterInterface
21 21
 {
22 22
 
23
-    /**
24
-     * Collection constructor
25
-     *
26
-     * @throws InvalidInterfaceException
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct('EventEspresso\core\services\assets\AssetRegisterInterface');
31
-    }
23
+	/**
24
+	 * Collection constructor
25
+	 *
26
+	 * @throws InvalidInterfaceException
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct('EventEspresso\core\services\assets\AssetRegisterInterface');
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * @return  void
36
-     */
37
-    public function registerManifestFile()
38
-    {
39
-        $this->rewind();
40
-        while ($this->valid()) {
41
-            $this->current()->registerManifestFile();
42
-            $this->next();
43
-        }
44
-        $this->rewind();
45
-    }
34
+	/**
35
+	 * @return  void
36
+	 */
37
+	public function registerManifestFile()
38
+	{
39
+		$this->rewind();
40
+		while ($this->valid()) {
41
+			$this->current()->registerManifestFile();
42
+			$this->next();
43
+		}
44
+		$this->rewind();
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * @return  void
50
-     */
51
-    public function registerScripts()
52
-    {
53
-        $this->rewind();
54
-        while ($this->valid()) {
55
-            $this->current()->registerScripts();
56
-            $this->next();
57
-        }
58
-        $this->rewind();
59
-    }
48
+	/**
49
+	 * @return  void
50
+	 */
51
+	public function registerScripts()
52
+	{
53
+		$this->rewind();
54
+		while ($this->valid()) {
55
+			$this->current()->registerScripts();
56
+			$this->next();
57
+		}
58
+		$this->rewind();
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * @return void
64
-     */
65
-    public function registerStyles()
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $this->current()->registerStyles();
70
-            $this->next();
71
-        }
72
-        $this->rewind();
73
-    }
62
+	/**
63
+	 * @return void
64
+	 */
65
+	public function registerStyles()
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$this->current()->registerStyles();
70
+			$this->next();
71
+		}
72
+		$this->rewind();
73
+	}
74 74
 }
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/assets/AssetRegisterInterface.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,20 +17,20 @@
 block discarded – undo
17 17
 interface AssetRegisterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @return  void
22
-     */
23
-    public function registerManifestFile();
20
+	/**
21
+	 * @return  void
22
+	 */
23
+	public function registerManifestFile();
24 24
 
25 25
 
26
-    /**
27
-     * @return  void
28
-     */
29
-    public function registerScripts();
26
+	/**
27
+	 * @return  void
28
+	 */
29
+	public function registerScripts();
30 30
 
31 31
 
32
-    /**
33
-     * @return void
34
-     */
35
-    public function registerStyles();
32
+	/**
33
+	 * @return void
34
+	 */
35
+	public function registerStyles();
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +693 added lines, -693 removed lines patch added patch discarded remove patch
@@ -26,704 +26,704 @@
 block discarded – undo
26 26
 class Registry
27 27
 {
28 28
 
29
-    const ASSET_TYPE_CSS           = 'css';
30
-    const ASSET_TYPE_JS            = 'js';
31
-    const ASSET_NAMESPACE_CORE     = 'core';
32
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
33
-
34
-    /**
35
-     * @var EE_Template_Config $template_config
36
-     */
37
-    protected $template_config;
38
-
39
-    /**
40
-     * @var EE_Currency_Config $currency_config
41
-     */
42
-    protected $currency_config;
43
-
44
-    /**
45
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $jsdata = array();
50
-
51
-
52
-    /**
53
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
-     * page source.
55
-     * @var array
56
-     */
57
-    protected $script_handles_with_data = array();
58
-
59
-
60
-    /**
61
-     * @var DomainInterface
62
-     */
63
-    protected $domain;
64
-
65
-
66
-    /**
67
-     * @var I18nRegistry
68
-     */
69
-    private $i18n_registry;
70
-
71
-
72
-
73
-    /**
74
-     * Holds the manifest data obtained from registered manifest files.
75
-     * Manifests are maps of asset chunk name to actual built asset file names.
76
-     * Shape of this array is:
77
-     *
78
-     * array(
79
-     *  'some_namespace_slug' => array(
80
-     *      'some_chunk_name' => array(
81
-     *          'js' => 'filename.js'
82
-     *          'css' => 'filename.js'
83
-     *      ),
84
-     *      'url_base' => 'https://baseurl.com/to/assets
85
-     *  )
86
-     * )
87
-     *
88
-     * @var array
89
-     */
90
-    private $manifest_data = array();
91
-
92
-
93
-    /**
94
-     * Registry constructor.
95
-     * Hooking into WP actions for script registry.
96
-     *
97
-     * @param EE_Template_Config $template_config
98
-     * @param EE_Currency_Config $currency_config
99
-     * @param I18nRegistry       $i18n_registry
100
-     * @param DomainInterface    $domain
101
-     * @throws InvalidArgumentException
102
-     * @throws InvalidFilePathException
103
-     */
104
-    public function __construct(
105
-        EE_Template_Config $template_config,
106
-        EE_Currency_Config $currency_config,
107
-        I18nRegistry $i18n_registry,
108
-        DomainInterface $domain
109
-    ) {
110
-        $this->template_config = $template_config;
111
-        $this->currency_config = $currency_config;
112
-        $this->domain = $domain;
113
-        $this->i18n_registry = $i18n_registry;
114
-        $this->registerManifestFile(
115
-            self::ASSET_NAMESPACE_CORE,
116
-            $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . self::FILE_NAME_BUILD_MANIFEST
118
-        );
119
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
-    }
126
-
127
-
128
-    /**
129
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
-     * translation handling.
131
-     *
132
-     * @return I18nRegistry
133
-     */
134
-    public function getI18nRegistry()
135
-    {
136
-        return $this->i18n_registry;
137
-    }
138
-
139
-    /**
140
-     * Callback for the WP script actions.
141
-     * Used to register globally accessible core scripts.
142
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
-     *
144
-     */
145
-    public function scripts()
146
-    {
147
-        global $wp_version;
148
-        wp_register_script(
149
-            'ee-manifest',
150
-            $this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'manifest'),
151
-            array(),
152
-            null,
153
-            true
154
-        );
155
-        wp_register_script(
156
-            'eejs-core',
157
-            $this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'eejs'),
158
-            array('ee-manifest'),
159
-            null,
160
-            true
161
-        );
162
-        wp_register_script(
163
-            'ee-vendor-react',
164
-            $this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'reactVendor'),
165
-            array('eejs-core'),
166
-            null,
167
-            true
168
-        );
169
-        //only run this if WordPress 4.4.0 > is in use.
170
-        if (version_compare($wp_version, '4.4.0', '>')) {
171
-            //js.api
172
-            wp_register_script(
173
-                'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
-                array('underscore', 'eejs-core'),
176
-                EVENT_ESPRESSO_VERSION,
177
-                true
178
-            );
179
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
181
-        }
182
-        if (! is_admin()) {
183
-            $this->loadCoreCss();
184
-        }
185
-        $this->registerTranslationsForHandles(array('eejs-core'));
186
-        $this->loadCoreJs();
187
-        $this->loadJqueryValidate();
188
-        $this->loadAccountingJs();
189
-        $this->loadQtipJs();
190
-        $this->registerAdminAssets();
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * Call back for the script print in frontend and backend.
197
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
198
-     *
199
-     * @since 4.9.31.rc.015
200
-     */
201
-    public function enqueueData()
202
-    {
203
-        $this->removeAlreadyRegisteredDataForScriptHandles();
204
-        wp_add_inline_script(
205
-            'eejs-core',
206
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
207
-            'before'
208
-        );
209
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
210
-        $this->localizeAccountingJs();
211
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
212
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * Used to add data to eejs.data object.
219
-     * Note:  Overriding existing data is not allowed.
220
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
221
-     * If the data you add is something like this:
222
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
223
-     * It will be exposed in the page source as:
224
-     *  eejs.data.my_plugin_data.foo == gar
225
-     *
226
-     * @param string       $key   Key used to access your data
227
-     * @param string|array $value Value to attach to key
228
-     * @throws InvalidArgumentException
229
-     */
230
-    public function addData($key, $value)
231
-    {
232
-        if ($this->verifyDataNotExisting($key)) {
233
-            $this->jsdata[$key] = $value;
234
-        }
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
241
-     * elements in an array.
242
-     * When you use this method, the value you include will be appended to the end of an array on $key.
243
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
244
-     * object like this, eejs.data.test = [ my_data,
245
-     * ]
246
-     * If there has already been a scalar value attached to the data object given key, then
247
-     * this will throw an exception.
248
-     *
249
-     * @param string       $key   Key to attach data to.
250
-     * @param string|array $value Value being registered.
251
-     * @throws InvalidArgumentException
252
-     */
253
-    public function pushData($key, $value)
254
-    {
255
-        if (isset($this->jsdata[$key])
256
-            && ! is_array($this->jsdata[$key])
257
-        ) {
258
-            throw new invalidArgumentException(
259
-                sprintf(
260
-                    __(
261
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
29
+	const ASSET_TYPE_CSS           = 'css';
30
+	const ASSET_TYPE_JS            = 'js';
31
+	const ASSET_NAMESPACE_CORE     = 'core';
32
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
33
+
34
+	/**
35
+	 * @var EE_Template_Config $template_config
36
+	 */
37
+	protected $template_config;
38
+
39
+	/**
40
+	 * @var EE_Currency_Config $currency_config
41
+	 */
42
+	protected $currency_config;
43
+
44
+	/**
45
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $jsdata = array();
50
+
51
+
52
+	/**
53
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
+	 * page source.
55
+	 * @var array
56
+	 */
57
+	protected $script_handles_with_data = array();
58
+
59
+
60
+	/**
61
+	 * @var DomainInterface
62
+	 */
63
+	protected $domain;
64
+
65
+
66
+	/**
67
+	 * @var I18nRegistry
68
+	 */
69
+	private $i18n_registry;
70
+
71
+
72
+
73
+	/**
74
+	 * Holds the manifest data obtained from registered manifest files.
75
+	 * Manifests are maps of asset chunk name to actual built asset file names.
76
+	 * Shape of this array is:
77
+	 *
78
+	 * array(
79
+	 *  'some_namespace_slug' => array(
80
+	 *      'some_chunk_name' => array(
81
+	 *          'js' => 'filename.js'
82
+	 *          'css' => 'filename.js'
83
+	 *      ),
84
+	 *      'url_base' => 'https://baseurl.com/to/assets
85
+	 *  )
86
+	 * )
87
+	 *
88
+	 * @var array
89
+	 */
90
+	private $manifest_data = array();
91
+
92
+
93
+	/**
94
+	 * Registry constructor.
95
+	 * Hooking into WP actions for script registry.
96
+	 *
97
+	 * @param EE_Template_Config $template_config
98
+	 * @param EE_Currency_Config $currency_config
99
+	 * @param I18nRegistry       $i18n_registry
100
+	 * @param DomainInterface    $domain
101
+	 * @throws InvalidArgumentException
102
+	 * @throws InvalidFilePathException
103
+	 */
104
+	public function __construct(
105
+		EE_Template_Config $template_config,
106
+		EE_Currency_Config $currency_config,
107
+		I18nRegistry $i18n_registry,
108
+		DomainInterface $domain
109
+	) {
110
+		$this->template_config = $template_config;
111
+		$this->currency_config = $currency_config;
112
+		$this->domain = $domain;
113
+		$this->i18n_registry = $i18n_registry;
114
+		$this->registerManifestFile(
115
+			self::ASSET_NAMESPACE_CORE,
116
+			$this->domain->distributionAssetsUrl(),
117
+			$this->domain->distributionAssetsPath() . self::FILE_NAME_BUILD_MANIFEST
118
+		);
119
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
+	}
126
+
127
+
128
+	/**
129
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
+	 * translation handling.
131
+	 *
132
+	 * @return I18nRegistry
133
+	 */
134
+	public function getI18nRegistry()
135
+	{
136
+		return $this->i18n_registry;
137
+	}
138
+
139
+	/**
140
+	 * Callback for the WP script actions.
141
+	 * Used to register globally accessible core scripts.
142
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
+	 *
144
+	 */
145
+	public function scripts()
146
+	{
147
+		global $wp_version;
148
+		wp_register_script(
149
+			'ee-manifest',
150
+			$this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'manifest'),
151
+			array(),
152
+			null,
153
+			true
154
+		);
155
+		wp_register_script(
156
+			'eejs-core',
157
+			$this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'eejs'),
158
+			array('ee-manifest'),
159
+			null,
160
+			true
161
+		);
162
+		wp_register_script(
163
+			'ee-vendor-react',
164
+			$this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'reactVendor'),
165
+			array('eejs-core'),
166
+			null,
167
+			true
168
+		);
169
+		//only run this if WordPress 4.4.0 > is in use.
170
+		if (version_compare($wp_version, '4.4.0', '>')) {
171
+			//js.api
172
+			wp_register_script(
173
+				'eejs-api',
174
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
+				array('underscore', 'eejs-core'),
176
+				EVENT_ESPRESSO_VERSION,
177
+				true
178
+			);
179
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
181
+		}
182
+		if (! is_admin()) {
183
+			$this->loadCoreCss();
184
+		}
185
+		$this->registerTranslationsForHandles(array('eejs-core'));
186
+		$this->loadCoreJs();
187
+		$this->loadJqueryValidate();
188
+		$this->loadAccountingJs();
189
+		$this->loadQtipJs();
190
+		$this->registerAdminAssets();
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * Call back for the script print in frontend and backend.
197
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
198
+	 *
199
+	 * @since 4.9.31.rc.015
200
+	 */
201
+	public function enqueueData()
202
+	{
203
+		$this->removeAlreadyRegisteredDataForScriptHandles();
204
+		wp_add_inline_script(
205
+			'eejs-core',
206
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
207
+			'before'
208
+		);
209
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
210
+		$this->localizeAccountingJs();
211
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
212
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * Used to add data to eejs.data object.
219
+	 * Note:  Overriding existing data is not allowed.
220
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
221
+	 * If the data you add is something like this:
222
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
223
+	 * It will be exposed in the page source as:
224
+	 *  eejs.data.my_plugin_data.foo == gar
225
+	 *
226
+	 * @param string       $key   Key used to access your data
227
+	 * @param string|array $value Value to attach to key
228
+	 * @throws InvalidArgumentException
229
+	 */
230
+	public function addData($key, $value)
231
+	{
232
+		if ($this->verifyDataNotExisting($key)) {
233
+			$this->jsdata[$key] = $value;
234
+		}
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
241
+	 * elements in an array.
242
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
243
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
244
+	 * object like this, eejs.data.test = [ my_data,
245
+	 * ]
246
+	 * If there has already been a scalar value attached to the data object given key, then
247
+	 * this will throw an exception.
248
+	 *
249
+	 * @param string       $key   Key to attach data to.
250
+	 * @param string|array $value Value being registered.
251
+	 * @throws InvalidArgumentException
252
+	 */
253
+	public function pushData($key, $value)
254
+	{
255
+		if (isset($this->jsdata[$key])
256
+			&& ! is_array($this->jsdata[$key])
257
+		) {
258
+			throw new invalidArgumentException(
259
+				sprintf(
260
+					__(
261
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
262 262
                          push values to this data element when it is an array.',
263
-                        'event_espresso'
264
-                    ),
265
-                    $key,
266
-                    __METHOD__
267
-                )
268
-            );
269
-        }
270
-        $this->jsdata[$key][] = $value;
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * Used to set content used by javascript for a template.
277
-     * Note: Overrides of existing registered templates are not allowed.
278
-     *
279
-     * @param string $template_reference
280
-     * @param string $template_content
281
-     * @throws InvalidArgumentException
282
-     */
283
-    public function addTemplate($template_reference, $template_content)
284
-    {
285
-        if (! isset($this->jsdata['templates'])) {
286
-            $this->jsdata['templates'] = array();
287
-        }
288
-        //no overrides allowed.
289
-        if (isset($this->jsdata['templates'][$template_reference])) {
290
-            throw new invalidArgumentException(
291
-                sprintf(
292
-                    __(
293
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
294
-                        'event_espresso'
295
-                    ),
296
-                    $template_reference
297
-                )
298
-            );
299
-        }
300
-        $this->jsdata['templates'][$template_reference] = $template_content;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * Retrieve the template content already registered for the given reference.
307
-     *
308
-     * @param string $template_reference
309
-     * @return string
310
-     */
311
-    public function getTemplate($template_reference)
312
-    {
313
-        return isset($this->jsdata['templates'][$template_reference])
314
-            ? $this->jsdata['templates'][$template_reference]
315
-            : '';
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * Retrieve registered data.
322
-     *
323
-     * @param string $key Name of key to attach data to.
324
-     * @return mixed                If there is no for the given key, then false is returned.
325
-     */
326
-    public function getData($key)
327
-    {
328
-        return isset($this->jsdata[$key])
329
-            ? $this->jsdata[$key]
330
-            : false;
331
-    }
332
-
333
-
334
-    /**
335
-     * Get the actual asset path for asset manifests.
336
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
337
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
338
-     *                           asset file location.
339
-     * @param string $chunk_name
340
-     * @param string $asset_type
341
-     * @return string
342
-     * @since 4.9.59.p
343
-     */
344
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
345
-    {
346
-        $url = isset(
347
-            $this->manifest_data[$namespace][$chunk_name][$asset_type],
348
-            $this->manifest_data[$namespace]['url_base']
349
-        )
350
-            ? $this->manifest_data[$namespace]['url_base']
351
-              . $this->manifest_data[$namespace][$chunk_name][$asset_type]
352
-            : $chunk_name;
353
-        return apply_filters(
354
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
355
-            $url,
356
-            $namespace,
357
-            $chunk_name,
358
-            $asset_type
359
-        );
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * Return the url to a js file for the given namespace and chunk name.
366
-     *
367
-     * @param string $namespace
368
-     * @param string $chunk_name
369
-     * @return string
370
-     */
371
-    public function getJsUrl($namespace, $chunk_name)
372
-    {
373
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
374
-    }
375
-
376
-
377
-    /**
378
-     * Return the url to a css file for the given namespace and chunk name.
379
-     *
380
-     * @param string $namespace
381
-     * @param string $chunk_name
382
-     * @return string
383
-     */
384
-    public function getCssUrl($namespace, $chunk_name)
385
-    {
386
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
387
-    }
388
-
389
-
390
-    /**
391
-     * Used to register a js/css manifest file with the registered_manifest_files property.
392
-     *
393
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
394
-     * @param string $url_base      The url base for the manifest file location.
395
-     * @param string $manifest_file The absolute path to the manifest file.
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidFilePathException
398
-     * @since 4.9.59.p
399
-     */
400
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
401
-    {
402
-        if (isset($this->manifest_data[$namespace])) {
403
-            throw new InvalidArgumentException(
404
-                sprintf(
405
-                    esc_html__(
406
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
407
-                        'event_espresso'
408
-                    ),
409
-                    $namespace
410
-                )
411
-            );
412
-        }
413
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
414
-            if (is_admin()) {
415
-                EE_Error::add_error(
416
-                    sprintf(
417
-                        esc_html__(
418
-                            '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',
419
-                            'event_espresso'
420
-                        ),
421
-                        'Event Espresso',
422
-                        $url_base,
423
-                        'plugins_url',
424
-                        'WP_PLUGIN_URL'
425
-                    ),
426
-                    __FILE__,
427
-                    __FUNCTION__,
428
-                    __LINE__
429
-                );
430
-            }
431
-            return;
432
-        }
433
-        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
434
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
435
-            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
436
-        }
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * Decodes json from the provided manifest file.
443
-     *
444
-     * @since 4.9.59.p
445
-     * @param string $manifest_file Path to manifest file.
446
-     * @return array
447
-     * @throws InvalidFilePathException
448
-     */
449
-    private function decodeManifestFile($manifest_file)
450
-    {
451
-        if (! file_exists($manifest_file)) {
452
-            throw new InvalidFilePathException($manifest_file);
453
-        }
454
-        return json_decode(file_get_contents($manifest_file), true);
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Verifies whether the given data exists already on the jsdata array.
461
-     * Overriding data is not allowed.
462
-     *
463
-     * @param string $key Index for data.
464
-     * @return bool        If valid then return true.
465
-     * @throws InvalidArgumentException if data already exists.
466
-     */
467
-    protected function verifyDataNotExisting($key)
468
-    {
469
-        if (isset($this->jsdata[$key])) {
470
-            if (is_array($this->jsdata[$key])) {
471
-                throw new InvalidArgumentException(
472
-                    sprintf(
473
-                        __(
474
-                            'The value for %1$s already exists in the Registry::eejs object.
263
+						'event_espresso'
264
+					),
265
+					$key,
266
+					__METHOD__
267
+				)
268
+			);
269
+		}
270
+		$this->jsdata[$key][] = $value;
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * Used to set content used by javascript for a template.
277
+	 * Note: Overrides of existing registered templates are not allowed.
278
+	 *
279
+	 * @param string $template_reference
280
+	 * @param string $template_content
281
+	 * @throws InvalidArgumentException
282
+	 */
283
+	public function addTemplate($template_reference, $template_content)
284
+	{
285
+		if (! isset($this->jsdata['templates'])) {
286
+			$this->jsdata['templates'] = array();
287
+		}
288
+		//no overrides allowed.
289
+		if (isset($this->jsdata['templates'][$template_reference])) {
290
+			throw new invalidArgumentException(
291
+				sprintf(
292
+					__(
293
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
294
+						'event_espresso'
295
+					),
296
+					$template_reference
297
+				)
298
+			);
299
+		}
300
+		$this->jsdata['templates'][$template_reference] = $template_content;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * Retrieve the template content already registered for the given reference.
307
+	 *
308
+	 * @param string $template_reference
309
+	 * @return string
310
+	 */
311
+	public function getTemplate($template_reference)
312
+	{
313
+		return isset($this->jsdata['templates'][$template_reference])
314
+			? $this->jsdata['templates'][$template_reference]
315
+			: '';
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * Retrieve registered data.
322
+	 *
323
+	 * @param string $key Name of key to attach data to.
324
+	 * @return mixed                If there is no for the given key, then false is returned.
325
+	 */
326
+	public function getData($key)
327
+	{
328
+		return isset($this->jsdata[$key])
329
+			? $this->jsdata[$key]
330
+			: false;
331
+	}
332
+
333
+
334
+	/**
335
+	 * Get the actual asset path for asset manifests.
336
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
337
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
338
+	 *                           asset file location.
339
+	 * @param string $chunk_name
340
+	 * @param string $asset_type
341
+	 * @return string
342
+	 * @since 4.9.59.p
343
+	 */
344
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
345
+	{
346
+		$url = isset(
347
+			$this->manifest_data[$namespace][$chunk_name][$asset_type],
348
+			$this->manifest_data[$namespace]['url_base']
349
+		)
350
+			? $this->manifest_data[$namespace]['url_base']
351
+			  . $this->manifest_data[$namespace][$chunk_name][$asset_type]
352
+			: $chunk_name;
353
+		return apply_filters(
354
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
355
+			$url,
356
+			$namespace,
357
+			$chunk_name,
358
+			$asset_type
359
+		);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * Return the url to a js file for the given namespace and chunk name.
366
+	 *
367
+	 * @param string $namespace
368
+	 * @param string $chunk_name
369
+	 * @return string
370
+	 */
371
+	public function getJsUrl($namespace, $chunk_name)
372
+	{
373
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Return the url to a css file for the given namespace and chunk name.
379
+	 *
380
+	 * @param string $namespace
381
+	 * @param string $chunk_name
382
+	 * @return string
383
+	 */
384
+	public function getCssUrl($namespace, $chunk_name)
385
+	{
386
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
392
+	 *
393
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
394
+	 * @param string $url_base      The url base for the manifest file location.
395
+	 * @param string $manifest_file The absolute path to the manifest file.
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidFilePathException
398
+	 * @since 4.9.59.p
399
+	 */
400
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
401
+	{
402
+		if (isset($this->manifest_data[$namespace])) {
403
+			throw new InvalidArgumentException(
404
+				sprintf(
405
+					esc_html__(
406
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
407
+						'event_espresso'
408
+					),
409
+					$namespace
410
+				)
411
+			);
412
+		}
413
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
414
+			if (is_admin()) {
415
+				EE_Error::add_error(
416
+					sprintf(
417
+						esc_html__(
418
+							'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',
419
+							'event_espresso'
420
+						),
421
+						'Event Espresso',
422
+						$url_base,
423
+						'plugins_url',
424
+						'WP_PLUGIN_URL'
425
+					),
426
+					__FILE__,
427
+					__FUNCTION__,
428
+					__LINE__
429
+				);
430
+			}
431
+			return;
432
+		}
433
+		$this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
434
+		if (! isset($this->manifest_data[$namespace]['url_base'])) {
435
+			$this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
436
+		}
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * Decodes json from the provided manifest file.
443
+	 *
444
+	 * @since 4.9.59.p
445
+	 * @param string $manifest_file Path to manifest file.
446
+	 * @return array
447
+	 * @throws InvalidFilePathException
448
+	 */
449
+	private function decodeManifestFile($manifest_file)
450
+	{
451
+		if (! file_exists($manifest_file)) {
452
+			throw new InvalidFilePathException($manifest_file);
453
+		}
454
+		return json_decode(file_get_contents($manifest_file), true);
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Verifies whether the given data exists already on the jsdata array.
461
+	 * Overriding data is not allowed.
462
+	 *
463
+	 * @param string $key Index for data.
464
+	 * @return bool        If valid then return true.
465
+	 * @throws InvalidArgumentException if data already exists.
466
+	 */
467
+	protected function verifyDataNotExisting($key)
468
+	{
469
+		if (isset($this->jsdata[$key])) {
470
+			if (is_array($this->jsdata[$key])) {
471
+				throw new InvalidArgumentException(
472
+					sprintf(
473
+						__(
474
+							'The value for %1$s already exists in the Registry::eejs object.
475 475
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
476 476
                             %2$s method to push your value to the array.',
477
-                            'event_espresso'
478
-                        ),
479
-                        $key,
480
-                        'pushData()'
481
-                    )
482
-                );
483
-            }
484
-            throw new InvalidArgumentException(
485
-                sprintf(
486
-                    __(
487
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
477
+							'event_espresso'
478
+						),
479
+						$key,
480
+						'pushData()'
481
+					)
482
+				);
483
+			}
484
+			throw new InvalidArgumentException(
485
+				sprintf(
486
+					__(
487
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
488 488
                         allowed.  Consider attaching your value to a different key',
489
-                        'event_espresso'
490
-                    ),
491
-                    $key
492
-                )
493
-            );
494
-        }
495
-        return true;
496
-    }
497
-
498
-
499
-
500
-    /**
501
-     * registers core default stylesheets
502
-     */
503
-    private function loadCoreCss()
504
-    {
505
-        if ($this->template_config->enable_default_style) {
506
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
507
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
508
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
509
-            wp_register_style(
510
-                'espresso_default',
511
-                $default_stylesheet_path,
512
-                array('dashicons'),
513
-                EVENT_ESPRESSO_VERSION
514
-            );
515
-            //Load custom style sheet if available
516
-            if ($this->template_config->custom_style_sheet !== null) {
517
-                wp_register_style(
518
-                    'espresso_custom_css',
519
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
520
-                    array('espresso_default'),
521
-                    EVENT_ESPRESSO_VERSION
522
-                );
523
-            }
524
-        }
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * registers core default javascript
531
-     */
532
-    private function loadCoreJs()
533
-    {
534
-        // load core js
535
-        wp_register_script(
536
-            'espresso_core',
537
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
538
-            array('jquery'),
539
-            EVENT_ESPRESSO_VERSION,
540
-            true
541
-        );
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * registers jQuery Validate for form validation
548
-     */
549
-    private function loadJqueryValidate()
550
-    {
551
-        // register jQuery Validate and additional methods
552
-        wp_register_script(
553
-            'jquery-validate',
554
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
555
-            array('jquery'),
556
-            '1.15.0',
557
-            true
558
-        );
559
-        wp_register_script(
560
-            'jquery-validate-extra-methods',
561
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
562
-            array('jquery', 'jquery-validate'),
563
-            '1.15.0',
564
-            true
565
-        );
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     * registers accounting.js for performing client-side calculations
572
-     */
573
-    private function loadAccountingJs()
574
-    {
575
-        //accounting.js library
576
-        // @link http://josscrowcroft.github.io/accounting.js/
577
-        wp_register_script(
578
-            'ee-accounting-core',
579
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
580
-            array('underscore'),
581
-            '0.3.2',
582
-            true
583
-        );
584
-        wp_register_script(
585
-            'ee-accounting',
586
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
587
-            array('ee-accounting-core'),
588
-            EVENT_ESPRESSO_VERSION,
589
-            true
590
-        );
591
-    }
592
-
593
-
594
-
595
-    /**
596
-     * registers accounting.js for performing client-side calculations
597
-     */
598
-    private function localizeAccountingJs()
599
-    {
600
-        wp_localize_script(
601
-            'ee-accounting',
602
-            'EE_ACCOUNTING_CFG',
603
-            array(
604
-                'currency' => array(
605
-                    'symbol'    => $this->currency_config->sign,
606
-                    'format'    => array(
607
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
608
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
609
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
610
-                    ),
611
-                    'decimal'   => $this->currency_config->dec_mrk,
612
-                    'thousand'  => $this->currency_config->thsnds,
613
-                    'precision' => $this->currency_config->dec_plc,
614
-                ),
615
-                'number'   => array(
616
-                    'precision' => $this->currency_config->dec_plc,
617
-                    'thousand'  => $this->currency_config->thsnds,
618
-                    'decimal'   => $this->currency_config->dec_mrk,
619
-                ),
620
-            )
621
-        );
622
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * registers assets for cleaning your ears
629
-     */
630
-    private function loadQtipJs()
631
-    {
632
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
633
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
634
-        if (apply_filters('FHEE_load_qtip', false)) {
635
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
636
-        }
637
-    }
638
-
639
-
640
-    /**
641
-     * This is used to set registered script handles that have data.
642
-     * @param string $script_handle
643
-     */
644
-    private function addRegisteredScriptHandlesWithData($script_handle)
645
-    {
646
-        $this->script_handles_with_data[$script_handle] = $script_handle;
647
-    }
648
-
649
-
650
-    /**i
489
+						'event_espresso'
490
+					),
491
+					$key
492
+				)
493
+			);
494
+		}
495
+		return true;
496
+	}
497
+
498
+
499
+
500
+	/**
501
+	 * registers core default stylesheets
502
+	 */
503
+	private function loadCoreCss()
504
+	{
505
+		if ($this->template_config->enable_default_style) {
506
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
507
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
508
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
509
+			wp_register_style(
510
+				'espresso_default',
511
+				$default_stylesheet_path,
512
+				array('dashicons'),
513
+				EVENT_ESPRESSO_VERSION
514
+			);
515
+			//Load custom style sheet if available
516
+			if ($this->template_config->custom_style_sheet !== null) {
517
+				wp_register_style(
518
+					'espresso_custom_css',
519
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
520
+					array('espresso_default'),
521
+					EVENT_ESPRESSO_VERSION
522
+				);
523
+			}
524
+		}
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * registers core default javascript
531
+	 */
532
+	private function loadCoreJs()
533
+	{
534
+		// load core js
535
+		wp_register_script(
536
+			'espresso_core',
537
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
538
+			array('jquery'),
539
+			EVENT_ESPRESSO_VERSION,
540
+			true
541
+		);
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * registers jQuery Validate for form validation
548
+	 */
549
+	private function loadJqueryValidate()
550
+	{
551
+		// register jQuery Validate and additional methods
552
+		wp_register_script(
553
+			'jquery-validate',
554
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
555
+			array('jquery'),
556
+			'1.15.0',
557
+			true
558
+		);
559
+		wp_register_script(
560
+			'jquery-validate-extra-methods',
561
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
562
+			array('jquery', 'jquery-validate'),
563
+			'1.15.0',
564
+			true
565
+		);
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 * registers accounting.js for performing client-side calculations
572
+	 */
573
+	private function loadAccountingJs()
574
+	{
575
+		//accounting.js library
576
+		// @link http://josscrowcroft.github.io/accounting.js/
577
+		wp_register_script(
578
+			'ee-accounting-core',
579
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
580
+			array('underscore'),
581
+			'0.3.2',
582
+			true
583
+		);
584
+		wp_register_script(
585
+			'ee-accounting',
586
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
587
+			array('ee-accounting-core'),
588
+			EVENT_ESPRESSO_VERSION,
589
+			true
590
+		);
591
+	}
592
+
593
+
594
+
595
+	/**
596
+	 * registers accounting.js for performing client-side calculations
597
+	 */
598
+	private function localizeAccountingJs()
599
+	{
600
+		wp_localize_script(
601
+			'ee-accounting',
602
+			'EE_ACCOUNTING_CFG',
603
+			array(
604
+				'currency' => array(
605
+					'symbol'    => $this->currency_config->sign,
606
+					'format'    => array(
607
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
608
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
609
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
610
+					),
611
+					'decimal'   => $this->currency_config->dec_mrk,
612
+					'thousand'  => $this->currency_config->thsnds,
613
+					'precision' => $this->currency_config->dec_plc,
614
+				),
615
+				'number'   => array(
616
+					'precision' => $this->currency_config->dec_plc,
617
+					'thousand'  => $this->currency_config->thsnds,
618
+					'decimal'   => $this->currency_config->dec_mrk,
619
+				),
620
+			)
621
+		);
622
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * registers assets for cleaning your ears
629
+	 */
630
+	private function loadQtipJs()
631
+	{
632
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
633
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
634
+		if (apply_filters('FHEE_load_qtip', false)) {
635
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
636
+		}
637
+	}
638
+
639
+
640
+	/**
641
+	 * This is used to set registered script handles that have data.
642
+	 * @param string $script_handle
643
+	 */
644
+	private function addRegisteredScriptHandlesWithData($script_handle)
645
+	{
646
+		$this->script_handles_with_data[$script_handle] = $script_handle;
647
+	}
648
+
649
+
650
+	/**i
651 651
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
652 652
      * Dependency stored in WP_Scripts if its set.
653 653
      */
654
-    private function removeAlreadyRegisteredDataForScriptHandles()
655
-    {
656
-        if (empty($this->script_handles_with_data)) {
657
-            return;
658
-        }
659
-        foreach ($this->script_handles_with_data as $script_handle) {
660
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
661
-        }
662
-    }
663
-
664
-
665
-    /**
666
-     * Removes any data dependency registered in WP_Scripts if its set.
667
-     * @param string $script_handle
668
-     */
669
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
670
-    {
671
-        if (isset($this->script_handles_with_data[$script_handle])) {
672
-            global $wp_scripts;
673
-            $unset_handle = false;
674
-            if ($wp_scripts->get_data($script_handle, 'data')) {
675
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
676
-                $unset_handle = true;
677
-            }
678
-            //deal with inline_scripts
679
-            if ($wp_scripts->get_data($script_handle, 'before')) {
680
-                unset($wp_scripts->registered[$script_handle]->extra['before']);
681
-                $unset_handle = true;
682
-            }
683
-            if ($wp_scripts->get_data($script_handle, 'after')) {
684
-                unset($wp_scripts->registered[$script_handle]->extra['after']);
685
-            }
686
-            if ($unset_handle) {
687
-                unset($this->script_handles_with_data[$script_handle]);
688
-            }
689
-        }
690
-    }
691
-
692
-
693
-    /**
694
-     * Registers assets that are used in the WordPress admin.
695
-     */
696
-    private function registerAdminAssets()
697
-    {
698
-        wp_register_script(
699
-            'ee-wp-plugins-page',
700
-            $this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'wp-plugins-page'),
701
-            array(
702
-                'jquery',
703
-                'ee-vendor-react'
704
-            ),
705
-            null,
706
-            true
707
-        );
708
-        wp_register_style(
709
-            'ee-wp-plugins-page',
710
-            $this->getCssUrl(self::ASSET_NAMESPACE_CORE, 'wp-plugins-page'),
711
-            array(),
712
-            null
713
-        );
714
-        $this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
715
-    }
716
-
717
-
718
-    /**
719
-     * All handles that are registered via the registry that might have translations have their translations registered
720
-     *
721
-     * @param array $handles_to_register
722
-     */
723
-    private function registerTranslationsForHandles(array $handles_to_register)
724
-    {
725
-        foreach($handles_to_register as $handle) {
726
-            $this->i18n_registry->registerScriptI18n($handle);
727
-        }
728
-    }
654
+	private function removeAlreadyRegisteredDataForScriptHandles()
655
+	{
656
+		if (empty($this->script_handles_with_data)) {
657
+			return;
658
+		}
659
+		foreach ($this->script_handles_with_data as $script_handle) {
660
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
661
+		}
662
+	}
663
+
664
+
665
+	/**
666
+	 * Removes any data dependency registered in WP_Scripts if its set.
667
+	 * @param string $script_handle
668
+	 */
669
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
670
+	{
671
+		if (isset($this->script_handles_with_data[$script_handle])) {
672
+			global $wp_scripts;
673
+			$unset_handle = false;
674
+			if ($wp_scripts->get_data($script_handle, 'data')) {
675
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
676
+				$unset_handle = true;
677
+			}
678
+			//deal with inline_scripts
679
+			if ($wp_scripts->get_data($script_handle, 'before')) {
680
+				unset($wp_scripts->registered[$script_handle]->extra['before']);
681
+				$unset_handle = true;
682
+			}
683
+			if ($wp_scripts->get_data($script_handle, 'after')) {
684
+				unset($wp_scripts->registered[$script_handle]->extra['after']);
685
+			}
686
+			if ($unset_handle) {
687
+				unset($this->script_handles_with_data[$script_handle]);
688
+			}
689
+		}
690
+	}
691
+
692
+
693
+	/**
694
+	 * Registers assets that are used in the WordPress admin.
695
+	 */
696
+	private function registerAdminAssets()
697
+	{
698
+		wp_register_script(
699
+			'ee-wp-plugins-page',
700
+			$this->getJsUrl(self::ASSET_NAMESPACE_CORE, 'wp-plugins-page'),
701
+			array(
702
+				'jquery',
703
+				'ee-vendor-react'
704
+			),
705
+			null,
706
+			true
707
+		);
708
+		wp_register_style(
709
+			'ee-wp-plugins-page',
710
+			$this->getCssUrl(self::ASSET_NAMESPACE_CORE, 'wp-plugins-page'),
711
+			array(),
712
+			null
713
+		);
714
+		$this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
715
+	}
716
+
717
+
718
+	/**
719
+	 * All handles that are registered via the registry that might have translations have their translations registered
720
+	 *
721
+	 * @param array $handles_to_register
722
+	 */
723
+	private function registerTranslationsForHandles(array $handles_to_register)
724
+	{
725
+		foreach($handles_to_register as $handle) {
726
+			$this->i18n_registry->registerScriptI18n($handle);
727
+		}
728
+	}
729 729
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $this->registerManifestFile(
115 115
             self::ASSET_NAMESPACE_CORE,
116 116
             $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . self::FILE_NAME_BUILD_MANIFEST
117
+            $this->domain->distributionAssetsPath().self::FILE_NAME_BUILD_MANIFEST
118 118
         );
119 119
         add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120 120
         add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             //js.api
172 172
             wp_register_script(
173 173
                 'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
174
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
175 175
                 array('underscore', 'eejs-core'),
176 176
                 EVENT_ESPRESSO_VERSION,
177 177
                 true
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
             $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180 180
             $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
181 181
         }
182
-        if (! is_admin()) {
182
+        if ( ! is_admin()) {
183 183
             $this->loadCoreCss();
184 184
         }
185 185
         $this->registerTranslationsForHandles(array('eejs-core'));
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         $this->removeAlreadyRegisteredDataForScriptHandles();
204 204
         wp_add_inline_script(
205 205
             'eejs-core',
206
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
206
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
207 207
             'before'
208 208
         );
209 209
         wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      */
283 283
     public function addTemplate($template_reference, $template_content)
284 284
     {
285
-        if (! isset($this->jsdata['templates'])) {
285
+        if ( ! isset($this->jsdata['templates'])) {
286 286
             $this->jsdata['templates'] = array();
287 287
         }
288 288
         //no overrides allowed.
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             return;
432 432
         }
433 433
         $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
434
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
434
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
435 435
             $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
436 436
         }
437 437
     }
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
      */
449 449
     private function decodeManifestFile($manifest_file)
450 450
     {
451
-        if (! file_exists($manifest_file)) {
451
+        if ( ! file_exists($manifest_file)) {
452 452
             throw new InvalidFilePathException($manifest_file);
453 453
         }
454 454
         return json_decode(file_get_contents($manifest_file), true);
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
     private function loadCoreCss()
504 504
     {
505 505
         if ($this->template_config->enable_default_style) {
506
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
506
+            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
507 507
                 ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
508
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
508
+                : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css';
509 509
             wp_register_style(
510 510
                 'espresso_default',
511 511
                 $default_stylesheet_path,
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
             if ($this->template_config->custom_style_sheet !== null) {
517 517
                 wp_register_style(
518 518
                     'espresso_custom_css',
519
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
519
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
520 520
                     array('espresso_default'),
521 521
                     EVENT_ESPRESSO_VERSION
522 522
                 );
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         // load core js
535 535
         wp_register_script(
536 536
             'espresso_core',
537
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
537
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
538 538
             array('jquery'),
539 539
             EVENT_ESPRESSO_VERSION,
540 540
             true
@@ -551,14 +551,14 @@  discard block
 block discarded – undo
551 551
         // register jQuery Validate and additional methods
552 552
         wp_register_script(
553 553
             'jquery-validate',
554
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
554
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
555 555
             array('jquery'),
556 556
             '1.15.0',
557 557
             true
558 558
         );
559 559
         wp_register_script(
560 560
             'jquery-validate-extra-methods',
561
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
561
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
562 562
             array('jquery', 'jquery-validate'),
563 563
             '1.15.0',
564 564
             true
@@ -576,14 +576,14 @@  discard block
 block discarded – undo
576 576
         // @link http://josscrowcroft.github.io/accounting.js/
577 577
         wp_register_script(
578 578
             'ee-accounting-core',
579
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
579
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
580 580
             array('underscore'),
581 581
             '0.3.2',
582 582
             true
583 583
         );
584 584
         wp_register_script(
585 585
             'ee-accounting',
586
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
586
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
587 587
             array('ee-accounting-core'),
588 588
             EVENT_ESPRESSO_VERSION,
589 589
             true
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
      */
723 723
     private function registerTranslationsForHandles(array $handles_to_register)
724 724
     {
725
-        foreach($handles_to_register as $handle) {
725
+        foreach ($handles_to_register as $handle) {
726 726
             $this->i18n_registry->registerScriptI18n($handle);
727 727
         }
728 728
     }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1278 added lines, -1278 removed lines patch added patch discarded remove patch
@@ -32,1284 +32,1284 @@
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
-     */
39
-    const req_type_normal = 0;
40
-
41
-    /**
42
-     * Indicates this is a brand new installation of EE so we should install
43
-     * tables and default data etc
44
-     */
45
-    const req_type_new_activation = 1;
46
-
47
-    /**
48
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
-     * and we just exited maintenance mode). We MUST check the database is setup properly
50
-     * and that default data is setup too
51
-     */
52
-    const req_type_reactivation = 2;
53
-
54
-    /**
55
-     * indicates that EE has been upgraded since its previous request.
56
-     * We may have data migration scripts to call and will want to trigger maintenance mode
57
-     */
58
-    const req_type_upgrade = 3;
59
-
60
-    /**
61
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
-     */
63
-    const req_type_downgrade = 4;
64
-
65
-    /**
66
-     * @deprecated since version 4.6.0.dev.006
67
-     * Now whenever a new_activation is detected the request type is still just
68
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
-     * (Specifically, when the migration manager indicates migrations are finished
72
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
-     */
74
-    const req_type_activation_but_not_installed = 5;
75
-
76
-    /**
77
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
-     */
79
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
-
81
-
82
-    /**
83
-     * @var EE_System $_instance
84
-     */
85
-    private static $_instance;
86
-
87
-    /**
88
-     * @var EE_Registry $registry
89
-     */
90
-    private $registry;
91
-
92
-    /**
93
-     * @var LoaderInterface $loader
94
-     */
95
-    private $loader;
96
-
97
-    /**
98
-     * @var EE_Capabilities $capabilities
99
-     */
100
-    private $capabilities;
101
-
102
-    /**
103
-     * @var RequestInterface $request
104
-     */
105
-    private $request;
106
-
107
-    /**
108
-     * @var EE_Maintenance_Mode $maintenance_mode
109
-     */
110
-    private $maintenance_mode;
111
-
112
-    /**
113
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
-     *
116
-     * @var int $_req_type
117
-     */
118
-    private $_req_type;
119
-
120
-    /**
121
-     * Whether or not there was a non-micro version change in EE core version during this request
122
-     *
123
-     * @var boolean $_major_version_change
124
-     */
125
-    private $_major_version_change = false;
126
-
127
-    /**
128
-     * A Context DTO dedicated solely to identifying the current request type.
129
-     *
130
-     * @var RequestTypeContextCheckerInterface $request_type
131
-     */
132
-    private $request_type;
133
-
134
-
135
-
136
-    /**
137
-     * @singleton method used to instantiate class object
138
-     * @param EE_Registry|null         $registry
139
-     * @param LoaderInterface|null     $loader
140
-     * @param RequestInterface|null          $request
141
-     * @param EE_Maintenance_Mode|null $maintenance_mode
142
-     * @return EE_System
143
-     */
144
-    public static function instance(
145
-        EE_Registry $registry = null,
146
-        LoaderInterface $loader = null,
147
-        RequestInterface $request = null,
148
-        EE_Maintenance_Mode $maintenance_mode = null
149
-    ) {
150
-        // check if class object is instantiated
151
-        if (! self::$_instance instanceof EE_System) {
152
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
-        }
154
-        return self::$_instance;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * resets the instance and returns it
161
-     *
162
-     * @return EE_System
163
-     */
164
-    public static function reset()
165
-    {
166
-        self::$_instance->_req_type = null;
167
-        //make sure none of the old hooks are left hanging around
168
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
-        //we need to reset the migration manager in order for it to detect DMSs properly
170
-        EE_Data_Migration_Manager::reset();
171
-        self::instance()->detect_activations_or_upgrades();
172
-        self::instance()->perform_activations_upgrades_and_migrations();
173
-        return self::instance();
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * sets hooks for running rest of system
180
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
-     * starting EE Addons from any other point may lead to problems
182
-     *
183
-     * @param EE_Registry         $registry
184
-     * @param LoaderInterface     $loader
185
-     * @param RequestInterface          $request
186
-     * @param EE_Maintenance_Mode $maintenance_mode
187
-     */
188
-    private function __construct(
189
-        EE_Registry $registry,
190
-        LoaderInterface $loader,
191
-        RequestInterface $request,
192
-        EE_Maintenance_Mode $maintenance_mode
193
-    ) {
194
-        $this->registry         = $registry;
195
-        $this->loader           = $loader;
196
-        $this->request          = $request;
197
-        $this->maintenance_mode = $maintenance_mode;
198
-        do_action('AHEE__EE_System__construct__begin', $this);
199
-        add_action(
200
-            'AHEE__EE_Bootstrap__load_espresso_addons',
201
-            array($this, 'loadCapabilities'),
202
-            5
203
-        );
204
-        add_action(
205
-            'AHEE__EE_Bootstrap__load_espresso_addons',
206
-            array($this, 'loadCommandBus'),
207
-            7
208
-        );
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            array($this, 'loadPluginApi'),
212
-            9
213
-        );
214
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__load_espresso_addons',
217
-            array($this, 'load_espresso_addons')
218
-        );
219
-        // when an ee addon is activated, we want to call the core hook(s) again
220
-        // because the newly-activated addon didn't get a chance to run at all
221
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
-        // detect whether install or upgrade
223
-        add_action(
224
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
-            array($this, 'detect_activations_or_upgrades'),
226
-            3
227
-        );
228
-        // load EE_Config, EE_Textdomain, etc
229
-        add_action(
230
-            'AHEE__EE_Bootstrap__load_core_configuration',
231
-            array($this, 'load_core_configuration'),
232
-            5
233
-        );
234
-        // load EE_Config, EE_Textdomain, etc
235
-        add_action(
236
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
-            array($this, 'register_shortcodes_modules_and_widgets'),
238
-            7
239
-        );
240
-        // you wanna get going? I wanna get going... let's get going!
241
-        add_action(
242
-            'AHEE__EE_Bootstrap__brew_espresso',
243
-            array($this, 'brew_espresso'),
244
-            9
245
-        );
246
-        //other housekeeping
247
-        //exclude EE critical pages from wp_list_pages
248
-        add_filter(
249
-            'wp_list_pages_excludes',
250
-            array($this, 'remove_pages_from_wp_list_pages'),
251
-            10
252
-        );
253
-        // ALL EE Addons should use the following hook point to attach their initial setup too
254
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
-        do_action('AHEE__EE_System__construct__complete', $this);
256
-    }
257
-
258
-
259
-    /**
260
-     * load and setup EE_Capabilities
261
-     *
262
-     * @return void
263
-     * @throws EE_Error
264
-     */
265
-    public function loadCapabilities()
266
-    {
267
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
268
-        add_action(
269
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
270
-            function ()
271
-            {
272
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * create and cache the CommandBus, and also add middleware
281
-     * The CapChecker middleware requires the use of EE_Capabilities
282
-     * which is why we need to load the CommandBus after Caps are set up
283
-     *
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function loadCommandBus()
288
-    {
289
-        $this->loader->getShared(
290
-            'CommandBusInterface',
291
-            array(
292
-                null,
293
-                apply_filters(
294
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
-                    array(
296
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
-                    )
299
-                ),
300
-            )
301
-        );
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @return void
308
-     * @throws EE_Error
309
-     */
310
-    public function loadPluginApi()
311
-    {
312
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
313
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
314
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
-        $this->loader->getShared('EE_Request_Handler');
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $addon_name
321
-     * @param string $version_constant
322
-     * @param string $min_version_required
323
-     * @param string $load_callback
324
-     * @param string $plugin_file_constant
325
-     * @return void
326
-     */
327
-    private function deactivateIncompatibleAddon(
328
-        $addon_name,
329
-        $version_constant,
330
-        $min_version_required,
331
-        $load_callback,
332
-        $plugin_file_constant
333
-    ) {
334
-        if (! defined($version_constant)) {
335
-            return;
336
-        }
337
-        $addon_version = constant($version_constant);
338
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
-            if (! function_exists('deactivate_plugins')) {
341
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
-            }
343
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
-            EE_Error::add_error(
346
-                sprintf(
347
-                    esc_html__(
348
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
-                        'event_espresso'
350
-                    ),
351
-                    $addon_name,
352
-                    $min_version_required
353
-                ),
354
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
-            );
356
-            EE_Error::get_notices(false, true);
357
-        }
358
-    }
359
-
360
-
361
-    /**
362
-     * load_espresso_addons
363
-     * allow addons to load first so that they can set hooks for running DMS's, etc
364
-     * this is hooked into both:
365
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
366
-     *        which runs during the WP 'plugins_loaded' action at priority 5
367
-     *    and the WP 'activate_plugin' hook point
368
-     *
369
-     * @access public
370
-     * @return void
371
-     */
372
-    public function load_espresso_addons()
373
-    {
374
-        $this->deactivateIncompatibleAddon(
375
-            'Wait Lists',
376
-            'EE_WAIT_LISTS_VERSION',
377
-            '1.0.0.beta.074',
378
-            'load_espresso_wait_lists',
379
-            'EE_WAIT_LISTS_PLUGIN_FILE'
380
-        );
381
-        $this->deactivateIncompatibleAddon(
382
-            'Automated Upcoming Event Notifications',
383
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
-            '1.0.0.beta.091',
385
-            'load_espresso_automated_upcoming_event_notification',
386
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
-        );
388
-        do_action('AHEE__EE_System__load_espresso_addons');
389
-        //if the WP API basic auth plugin isn't already loaded, load it now.
390
-        //We want it for mobile apps. Just include the entire plugin
391
-        //also, don't load the basic auth when a plugin is getting activated, because
392
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
-        //and causes a fatal error
394
-        if (
395
-            $this->request->getRequestParam('activate') !== 'true'
396
-            && ! function_exists('json_basic_auth_handler')
397
-            && ! function_exists('json_basic_auth_error')
398
-            && ! in_array(
399
-                $this->request->getRequestParam('action'),
400
-                array('activate', 'activate-selected'),
401
-                true
402
-            )
403
-        ) {
404
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
-        }
406
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * detect_activations_or_upgrades
413
-     * Checks for activation or upgrade of core first;
414
-     * then also checks if any registered addons have been activated or upgraded
415
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
-     * which runs during the WP 'plugins_loaded' action at priority 3
417
-     *
418
-     * @access public
419
-     * @return void
420
-     */
421
-    public function detect_activations_or_upgrades()
422
-    {
423
-        //first off: let's make sure to handle core
424
-        $this->detect_if_activation_or_upgrade();
425
-        foreach ($this->registry->addons as $addon) {
426
-            if ($addon instanceof EE_Addon) {
427
-                //detect teh request type for that addon
428
-                $addon->detect_activation_or_upgrade();
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * detect_if_activation_or_upgrade
437
-     * Takes care of detecting whether this is a brand new install or code upgrade,
438
-     * and either setting up the DB or setting up maintenance mode etc.
439
-     *
440
-     * @access public
441
-     * @return void
442
-     */
443
-    public function detect_if_activation_or_upgrade()
444
-    {
445
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
-        // check if db has been updated, or if its a brand-new installation
447
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
-        $request_type       = $this->detect_req_type($espresso_db_update);
449
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
-        switch ($request_type) {
451
-            case EE_System::req_type_new_activation:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
-                $this->_handle_core_version_change($espresso_db_update);
454
-                break;
455
-            case EE_System::req_type_reactivation:
456
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
-                $this->_handle_core_version_change($espresso_db_update);
458
-                break;
459
-            case EE_System::req_type_upgrade:
460
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
-                //migrations may be required now that we've upgraded
462
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
463
-                $this->_handle_core_version_change($espresso_db_update);
464
-                //				echo "done upgrade";die;
465
-                break;
466
-            case EE_System::req_type_downgrade:
467
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
-                //its possible migrations are no longer required
469
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
470
-                $this->_handle_core_version_change($espresso_db_update);
471
-                break;
472
-            case EE_System::req_type_normal:
473
-            default:
474
-                break;
475
-        }
476
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Updates the list of installed versions and sets hooks for
483
-     * initializing the database later during the request
484
-     *
485
-     * @param array $espresso_db_update
486
-     */
487
-    private function _handle_core_version_change($espresso_db_update)
488
-    {
489
-        $this->update_list_of_installed_versions($espresso_db_update);
490
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
-        add_action(
492
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
-            array($this, 'initialize_db_if_no_migrations_required')
494
-        );
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
-     * information about what versions of EE have been installed and activated,
502
-     * NOT necessarily the state of the database
503
-     *
504
-     * @param mixed $espresso_db_update           the value of the WordPress option.
505
-     *                                            If not supplied, fetches it from the options table
506
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
-     */
508
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
-    {
510
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
-        if (! $espresso_db_update) {
512
-            $espresso_db_update = get_option('espresso_db_update');
513
-        }
514
-        // check that option is an array
515
-        if (! is_array($espresso_db_update)) {
516
-            // if option is FALSE, then it never existed
517
-            if ($espresso_db_update === false) {
518
-                // make $espresso_db_update an array and save option with autoload OFF
519
-                $espresso_db_update = array();
520
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
-            } else {
522
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
523
-                $espresso_db_update = array($espresso_db_update => array());
524
-                update_option('espresso_db_update', $espresso_db_update);
525
-            }
526
-        } else {
527
-            $corrected_db_update = array();
528
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
-                    //the key is an int, and the value IS NOT an array
532
-                    //so it must be numerically-indexed, where values are versions installed...
533
-                    //fix it!
534
-                    $version_string                         = $should_be_array;
535
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
536
-                } else {
537
-                    //ok it checks out
538
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
-                }
540
-            }
541
-            $espresso_db_update = $corrected_db_update;
542
-            update_option('espresso_db_update', $espresso_db_update);
543
-        }
544
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
-        return $espresso_db_update;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * Does the traditional work of setting up the plugin's database and adding default data.
552
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
-     * so that it will be done when migrations are finished
556
-     *
557
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
-     *                                       This is a resource-intensive job
560
-     *                                       so we prefer to only do it when necessary
561
-     * @return void
562
-     * @throws EE_Error
563
-     */
564
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
-    {
566
-        $request_type = $this->detect_req_type();
567
-        //only initialize system if we're not in maintenance mode.
568
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
-            update_option('ee_flush_rewrite_rules', true);
570
-            if ($verify_schema) {
571
-                EEH_Activation::initialize_db_and_folders();
572
-            }
573
-            EEH_Activation::initialize_db_content();
574
-            EEH_Activation::system_initialization();
575
-            if ($initialize_addons_too) {
576
-                $this->initialize_addons();
577
-            }
578
-        } else {
579
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
580
-        }
581
-        if ($request_type === EE_System::req_type_new_activation
582
-            || $request_type === EE_System::req_type_reactivation
583
-            || (
584
-                $request_type === EE_System::req_type_upgrade
585
-                && $this->is_major_version_change()
586
-            )
587
-        ) {
588
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
589
-        }
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * Initializes the db for all registered addons
596
-     *
597
-     * @throws EE_Error
598
-     */
599
-    public function initialize_addons()
600
-    {
601
-        //foreach registered addon, make sure its db is up-to-date too
602
-        foreach ($this->registry->addons as $addon) {
603
-            if ($addon instanceof EE_Addon) {
604
-                $addon->initialize_db_if_no_migrations_required();
605
-            }
606
-        }
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
613
-     *
614
-     * @param    array  $version_history
615
-     * @param    string $current_version_to_add version to be added to the version history
616
-     * @return    boolean success as to whether or not this option was changed
617
-     */
618
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
619
-    {
620
-        if (! $version_history) {
621
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
622
-        }
623
-        if ($current_version_to_add === null) {
624
-            $current_version_to_add = espresso_version();
625
-        }
626
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
627
-        // re-save
628
-        return update_option('espresso_db_update', $version_history);
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * Detects if the current version indicated in the has existed in the list of
635
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
636
-     *
637
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
638
-     *                                  If not supplied, fetches it from the options table.
639
-     *                                  Also, caches its result so later parts of the code can also know whether
640
-     *                                  there's been an update or not. This way we can add the current version to
641
-     *                                  espresso_db_update, but still know if this is a new install or not
642
-     * @return int one of the constants on EE_System::req_type_
643
-     */
644
-    public function detect_req_type($espresso_db_update = null)
645
-    {
646
-        if ($this->_req_type === null) {
647
-            $espresso_db_update          = ! empty($espresso_db_update)
648
-                ? $espresso_db_update
649
-                : $this->fix_espresso_db_upgrade_option();
650
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
651
-                $espresso_db_update,
652
-                'ee_espresso_activation', espresso_version()
653
-            );
654
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
655
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
656
-        }
657
-        return $this->_req_type;
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Returns whether or not there was a non-micro version change (ie, change in either
664
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
665
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
666
-     *
667
-     * @param $activation_history
668
-     * @return bool
669
-     */
670
-    private function _detect_major_version_change($activation_history)
671
-    {
672
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
673
-        $previous_version_parts = explode('.', $previous_version);
674
-        $current_version_parts  = explode('.', espresso_version());
675
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
676
-               && ($previous_version_parts[0] !== $current_version_parts[0]
677
-                   || $previous_version_parts[1] !== $current_version_parts[1]
678
-               );
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     * Returns true if either the major or minor version of EE changed during this request.
685
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
686
-     *
687
-     * @return bool
688
-     */
689
-    public function is_major_version_change()
690
-    {
691
-        return $this->_major_version_change;
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
-     * just activated to (for core that will always be espresso_version())
701
-     *
702
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
703
-     *                                                 ee plugin. for core that's 'espresso_db_update'
704
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
705
-     *                                                 indicate that this plugin was just activated
706
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
707
-     *                                                 espresso_version())
708
-     * @return int one of the constants on EE_System::req_type_*
709
-     */
710
-    public static function detect_req_type_given_activation_history(
711
-        $activation_history_for_addon,
712
-        $activation_indicator_option_name,
713
-        $version_to_upgrade_to
714
-    ) {
715
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
716
-        if ($activation_history_for_addon) {
717
-            //it exists, so this isn't a completely new install
718
-            //check if this version already in that list of previously installed versions
719
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
720
-                //it a version we haven't seen before
721
-                if ($version_is_higher === 1) {
722
-                    $req_type = EE_System::req_type_upgrade;
723
-                } else {
724
-                    $req_type = EE_System::req_type_downgrade;
725
-                }
726
-                delete_option($activation_indicator_option_name);
727
-            } else {
728
-                // its not an update. maybe a reactivation?
729
-                if (get_option($activation_indicator_option_name, false)) {
730
-                    if ($version_is_higher === -1) {
731
-                        $req_type = EE_System::req_type_downgrade;
732
-                    } elseif ($version_is_higher === 0) {
733
-                        //we've seen this version before, but it's an activation. must be a reactivation
734
-                        $req_type = EE_System::req_type_reactivation;
735
-                    } else {//$version_is_higher === 1
736
-                        $req_type = EE_System::req_type_upgrade;
737
-                    }
738
-                    delete_option($activation_indicator_option_name);
739
-                } else {
740
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
741
-                    if ($version_is_higher === -1) {
742
-                        $req_type = EE_System::req_type_downgrade;
743
-                    } elseif ($version_is_higher === 0) {
744
-                        //we've seen this version before and it's not an activation. its normal request
745
-                        $req_type = EE_System::req_type_normal;
746
-                    } else {//$version_is_higher === 1
747
-                        $req_type = EE_System::req_type_upgrade;
748
-                    }
749
-                }
750
-            }
751
-        } else {
752
-            //brand new install
753
-            $req_type = EE_System::req_type_new_activation;
754
-            delete_option($activation_indicator_option_name);
755
-        }
756
-        return $req_type;
757
-    }
758
-
759
-
760
-
761
-    /**
762
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
763
-     * the $activation_history_for_addon
764
-     *
765
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
766
-     *                                             sometimes containing 'unknown-date'
767
-     * @param string $version_to_upgrade_to        (current version)
768
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
769
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
770
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
771
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
772
-     */
773
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
774
-    {
775
-        //find the most recently-activated version
776
-        $most_recently_active_version =
777
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
778
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
779
-    }
780
-
781
-
782
-
783
-    /**
784
-     * Gets the most recently active version listed in the activation history,
785
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
786
-     *
787
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
788
-     *                                   sometimes containing 'unknown-date'
789
-     * @return string
790
-     */
791
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
792
-    {
793
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
794
-        $most_recently_active_version            = '0.0.0.dev.000';
795
-        if (is_array($activation_history)) {
796
-            foreach ($activation_history as $version => $times_activated) {
797
-                //check there is a record of when this version was activated. Otherwise,
798
-                //mark it as unknown
799
-                if (! $times_activated) {
800
-                    $times_activated = array('unknown-date');
801
-                }
802
-                if (is_string($times_activated)) {
803
-                    $times_activated = array($times_activated);
804
-                }
805
-                foreach ($times_activated as $an_activation) {
806
-                    if ($an_activation !== 'unknown-date'
807
-                        && $an_activation
808
-                           > $most_recently_active_version_activation) {
809
-                        $most_recently_active_version            = $version;
810
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
811
-                            ? '1970-01-01 00:00:00'
812
-                            : $an_activation;
813
-                    }
814
-                }
815
-            }
816
-        }
817
-        return $most_recently_active_version;
818
-    }
819
-
820
-
821
-
822
-    /**
823
-     * This redirects to the about EE page after activation
824
-     *
825
-     * @return void
826
-     */
827
-    public function redirect_to_about_ee()
828
-    {
829
-        $notices = EE_Error::get_notices(false);
830
-        //if current user is an admin and it's not an ajax or rest request
831
-        if (
832
-            ! isset($notices['errors'])
833
-            && $this->request->isAdmin()
834
-            && apply_filters(
835
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
836
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
837
-            )
838
-        ) {
839
-            $query_params = array('page' => 'espresso_about');
840
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
841
-                $query_params['new_activation'] = true;
842
-            }
843
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
844
-                $query_params['reactivation'] = true;
845
-            }
846
-            $url = add_query_arg($query_params, admin_url('admin.php'));
847
-            wp_safe_redirect($url);
848
-            exit();
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     * load_core_configuration
856
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
857
-     * which runs during the WP 'plugins_loaded' action at priority 5
858
-     *
859
-     * @return void
860
-     * @throws ReflectionException
861
-     */
862
-    public function load_core_configuration()
863
-    {
864
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
865
-        $this->loader->getShared('EE_Load_Textdomain');
866
-        //load textdomain
867
-        EE_Load_Textdomain::load_textdomain();
868
-        // load and setup EE_Config and EE_Network_Config
869
-        $config = $this->loader->getShared('EE_Config');
870
-        $this->loader->getShared('EE_Network_Config');
871
-        // setup autoloaders
872
-        // enable logging?
873
-        if ($config->admin->use_full_logging) {
874
-            $this->loader->getShared('EE_Log');
875
-        }
876
-        // check for activation errors
877
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
878
-        if ($activation_errors) {
879
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
880
-            update_option('ee_plugin_activation_errors', false);
881
-        }
882
-        // get model names
883
-        $this->_parse_model_names();
884
-        //load caf stuff a chance to play during the activation process too.
885
-        $this->_maybe_brew_regular();
886
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
887
-    }
888
-
889
-
890
-
891
-    /**
892
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
893
-     *
894
-     * @return void
895
-     * @throws ReflectionException
896
-     */
897
-    private function _parse_model_names()
898
-    {
899
-        //get all the files in the EE_MODELS folder that end in .model.php
900
-        $models                 = glob(EE_MODELS . '*.model.php');
901
-        $model_names            = array();
902
-        $non_abstract_db_models = array();
903
-        foreach ($models as $model) {
904
-            // get model classname
905
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
906
-            $short_name      = str_replace('EEM_', '', $classname);
907
-            $reflectionClass = new ReflectionClass($classname);
908
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
909
-                $non_abstract_db_models[ $short_name ] = $classname;
910
-            }
911
-            $model_names[ $short_name ] = $classname;
912
-        }
913
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
914
-        $this->registry->non_abstract_db_models = apply_filters(
915
-            'FHEE__EE_System__parse_implemented_model_names',
916
-            $non_abstract_db_models
917
-        );
918
-    }
919
-
920
-
921
-    /**
922
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
923
-     * that need to be setup before our EE_System launches.
924
-     *
925
-     * @return void
926
-     * @throws DomainException
927
-     * @throws InvalidArgumentException
928
-     * @throws InvalidDataTypeException
929
-     * @throws InvalidInterfaceException
930
-     * @throws InvalidClassException
931
-     * @throws InvalidFilePathException
932
-     */
933
-    private function _maybe_brew_regular()
934
-    {
935
-        /** @var Domain $domain */
936
-        $domain = DomainFactory::getShared(
937
-            new FullyQualifiedName(
938
-                'EventEspresso\core\domain\Domain'
939
-            ),
940
-            array(
941
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
942
-                Version::fromString(espresso_version())
943
-            )
944
-        );
945
-        if ($domain->isCaffeinated()) {
946
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
947
-        }
948
-    }
949
-
950
-
951
-
952
-    /**
953
-     * register_shortcodes_modules_and_widgets
954
-     * generate lists of shortcodes and modules, then verify paths and classes
955
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
956
-     * which runs during the WP 'plugins_loaded' action at priority 7
957
-     *
958
-     * @access public
959
-     * @return void
960
-     * @throws Exception
961
-     */
962
-    public function register_shortcodes_modules_and_widgets()
963
-    {
964
-        try {
965
-            // load, register, and add shortcodes the new way
966
-            if ($this->request->isFrontend() || $this->request->isIframe()) {
967
-                $this->loader->getShared(
968
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
969
-                    array(
970
-                        // and the old way, but we'll put it under control of the new system
971
-                        EE_Config::getLegacyShortcodesManager(),
972
-                    )
973
-                );
974
-            }
975
-            if (function_exists('register_block_type')) {
976
-                // or the even newer newer new way
977
-                if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
978
-                    $this->loader->getShared(
979
-                        'EventEspresso\core\services\editor\EditorBlockRegistrationManager'
980
-                    );
981
-                }
982
-            }
983
-        } catch (Exception $exception) {
984
-            new ExceptionStackTraceDisplay($exception);
985
-        }
986
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
987
-        // check for addons using old hook point
988
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
989
-            $this->_incompatible_addon_error();
990
-        }
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     * _incompatible_addon_error
997
-     *
998
-     * @access public
999
-     * @return void
1000
-     */
1001
-    private function _incompatible_addon_error()
1002
-    {
1003
-        // get array of classes hooking into here
1004
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1005
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
1006
-        );
1007
-        if (! empty($class_names)) {
1008
-            $msg = __(
1009
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1010
-                'event_espresso'
1011
-            );
1012
-            $msg .= '<ul>';
1013
-            foreach ($class_names as $class_name) {
1014
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1015
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1016
-                        $class_name
1017
-                    ) . '</b></li>';
1018
-            }
1019
-            $msg .= '</ul>';
1020
-            $msg .= __(
1021
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1022
-                'event_espresso'
1023
-            );
1024
-            // save list of incompatible addons to wp-options for later use
1025
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1026
-            if (is_admin()) {
1027
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
-            }
1029
-        }
1030
-    }
1031
-
1032
-
1033
-
1034
-    /**
1035
-     * brew_espresso
1036
-     * begins the process of setting hooks for initializing EE in the correct order
1037
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1038
-     * which runs during the WP 'plugins_loaded' action at priority 9
1039
-     *
1040
-     * @return void
1041
-     */
1042
-    public function brew_espresso()
1043
-    {
1044
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1045
-        // load some final core systems
1046
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1047
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1048
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1049
-        add_action('init', array($this, 'load_controllers'), 7);
1050
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1051
-        add_action('init', array($this, 'initialize'), 10);
1052
-        add_action('init', array($this, 'initialize_last'), 100);
1053
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1054
-            // pew pew pew
1055
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1056
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1057
-        }
1058
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1059
-    }
1060
-
1061
-
1062
-
1063
-    /**
1064
-     *    set_hooks_for_core
1065
-     *
1066
-     * @access public
1067
-     * @return    void
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function set_hooks_for_core()
1071
-    {
1072
-        $this->_deactivate_incompatible_addons();
1073
-        do_action('AHEE__EE_System__set_hooks_for_core');
1074
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1075
-        //caps need to be initialized on every request so that capability maps are set.
1076
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1077
-        $this->registry->CAP->init_caps();
1078
-    }
1079
-
1080
-
1081
-
1082
-    /**
1083
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1084
-     * deactivates any addons considered incompatible with the current version of EE
1085
-     */
1086
-    private function _deactivate_incompatible_addons()
1087
-    {
1088
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1089
-        if (! empty($incompatible_addons)) {
1090
-            $active_plugins = get_option('active_plugins', array());
1091
-            foreach ($active_plugins as $active_plugin) {
1092
-                foreach ($incompatible_addons as $incompatible_addon) {
1093
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1094
-                        unset($_GET['activate']);
1095
-                        espresso_deactivate_plugin($active_plugin);
1096
-                    }
1097
-                }
1098
-            }
1099
-        }
1100
-    }
1101
-
1102
-
1103
-
1104
-    /**
1105
-     *    perform_activations_upgrades_and_migrations
1106
-     *
1107
-     * @access public
1108
-     * @return    void
1109
-     */
1110
-    public function perform_activations_upgrades_and_migrations()
1111
-    {
1112
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1113
-    }
1114
-
1115
-
1116
-
1117
-    /**
1118
-     *    load_CPTs_and_session
1119
-     *
1120
-     * @access public
1121
-     * @return    void
1122
-     */
1123
-    public function load_CPTs_and_session()
1124
-    {
1125
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1126
-        // register Custom Post Types
1127
-        $this->loader->getShared('EE_Register_CPTs');
1128
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     * load_controllers
1135
-     * this is the best place to load any additional controllers that needs access to EE core.
1136
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1137
-     * time
1138
-     *
1139
-     * @access public
1140
-     * @return void
1141
-     */
1142
-    public function load_controllers()
1143
-    {
1144
-        do_action('AHEE__EE_System__load_controllers__start');
1145
-        // let's get it started
1146
-        if (
1147
-            ! $this->maintenance_mode->level()
1148
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1149
-        ) {
1150
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1151
-            $this->loader->getShared('EE_Front_Controller');
1152
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1153
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1154
-            $this->loader->getShared('EE_Admin');
1155
-        }
1156
-        do_action('AHEE__EE_System__load_controllers__complete');
1157
-    }
1158
-
1159
-
1160
-
1161
-    /**
1162
-     * core_loaded_and_ready
1163
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1164
-     *
1165
-     * @access public
1166
-     * @return void
1167
-     */
1168
-    public function core_loaded_and_ready()
1169
-    {
1170
-        if (
1171
-            $this->request->isAdmin()
1172
-            || $this->request->isEeAjax()
1173
-            || $this->request->isFrontend()
1174
-        ) {
1175
-            $this->loader->getShared('EE_Session');
1176
-        }
1177
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1178
-        // load_espresso_template_tags
1179
-        if (
1180
-            is_readable(EE_PUBLIC . 'template_tags.php')
1181
-            && (
1182
-                $this->request->isFrontend()
1183
-                || $this->request->isAdmin()
1184
-                || $this->request->isIframe()
1185
-                || $this->request->isFeed()
1186
-            )
1187
-        ) {
1188
-            require_once EE_PUBLIC . 'template_tags.php';
1189
-        }
1190
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1191
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1192
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1193
-        }
1194
-    }
1195
-
1196
-
1197
-
1198
-    /**
1199
-     * initialize
1200
-     * this is the best place to begin initializing client code
1201
-     *
1202
-     * @access public
1203
-     * @return void
1204
-     */
1205
-    public function initialize()
1206
-    {
1207
-        do_action('AHEE__EE_System__initialize');
1208
-    }
1209
-
1210
-
1211
-
1212
-    /**
1213
-     * initialize_last
1214
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1215
-     * initialize has done so
1216
-     *
1217
-     * @access public
1218
-     * @return void
1219
-     */
1220
-    public function initialize_last()
1221
-    {
1222
-        do_action('AHEE__EE_System__initialize_last');
1223
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1224
-    }
1225
-
1226
-
1227
-
1228
-    /**
1229
-     * @return void
1230
-     * @throws EE_Error
1231
-     */
1232
-    public function addEspressoToolbar()
1233
-    {
1234
-        $this->loader->getShared(
1235
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1236
-            array($this->registry->CAP)
1237
-        );
1238
-    }
1239
-
1240
-
1241
-
1242
-    /**
1243
-     * do_not_cache
1244
-     * sets no cache headers and defines no cache constants for WP plugins
1245
-     *
1246
-     * @access public
1247
-     * @return void
1248
-     */
1249
-    public static function do_not_cache()
1250
-    {
1251
-        // set no cache constants
1252
-        if (! defined('DONOTCACHEPAGE')) {
1253
-            define('DONOTCACHEPAGE', true);
1254
-        }
1255
-        if (! defined('DONOTCACHCEOBJECT')) {
1256
-            define('DONOTCACHCEOBJECT', true);
1257
-        }
1258
-        if (! defined('DONOTCACHEDB')) {
1259
-            define('DONOTCACHEDB', true);
1260
-        }
1261
-        // add no cache headers
1262
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1263
-        // plus a little extra for nginx and Google Chrome
1264
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1265
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1266
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1267
-    }
1268
-
1269
-
1270
-
1271
-    /**
1272
-     *    extra_nocache_headers
1273
-     *
1274
-     * @access    public
1275
-     * @param $headers
1276
-     * @return    array
1277
-     */
1278
-    public static function extra_nocache_headers($headers)
1279
-    {
1280
-        // for NGINX
1281
-        $headers['X-Accel-Expires'] = 0;
1282
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1283
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1284
-        return $headers;
1285
-    }
1286
-
1287
-
1288
-
1289
-    /**
1290
-     *    nocache_headers
1291
-     *
1292
-     * @access    public
1293
-     * @return    void
1294
-     */
1295
-    public static function nocache_headers()
1296
-    {
1297
-        nocache_headers();
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1304
-     * never returned with the function.
1305
-     *
1306
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1307
-     * @return array
1308
-     */
1309
-    public function remove_pages_from_wp_list_pages($exclude_array)
1310
-    {
1311
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1312
-    }
35
+	/**
36
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
+	 */
39
+	const req_type_normal = 0;
40
+
41
+	/**
42
+	 * Indicates this is a brand new installation of EE so we should install
43
+	 * tables and default data etc
44
+	 */
45
+	const req_type_new_activation = 1;
46
+
47
+	/**
48
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
50
+	 * and that default data is setup too
51
+	 */
52
+	const req_type_reactivation = 2;
53
+
54
+	/**
55
+	 * indicates that EE has been upgraded since its previous request.
56
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
57
+	 */
58
+	const req_type_upgrade = 3;
59
+
60
+	/**
61
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
+	 */
63
+	const req_type_downgrade = 4;
64
+
65
+	/**
66
+	 * @deprecated since version 4.6.0.dev.006
67
+	 * Now whenever a new_activation is detected the request type is still just
68
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
+	 * (Specifically, when the migration manager indicates migrations are finished
72
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
+	 */
74
+	const req_type_activation_but_not_installed = 5;
75
+
76
+	/**
77
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
+	 */
79
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
+
81
+
82
+	/**
83
+	 * @var EE_System $_instance
84
+	 */
85
+	private static $_instance;
86
+
87
+	/**
88
+	 * @var EE_Registry $registry
89
+	 */
90
+	private $registry;
91
+
92
+	/**
93
+	 * @var LoaderInterface $loader
94
+	 */
95
+	private $loader;
96
+
97
+	/**
98
+	 * @var EE_Capabilities $capabilities
99
+	 */
100
+	private $capabilities;
101
+
102
+	/**
103
+	 * @var RequestInterface $request
104
+	 */
105
+	private $request;
106
+
107
+	/**
108
+	 * @var EE_Maintenance_Mode $maintenance_mode
109
+	 */
110
+	private $maintenance_mode;
111
+
112
+	/**
113
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
+	 *
116
+	 * @var int $_req_type
117
+	 */
118
+	private $_req_type;
119
+
120
+	/**
121
+	 * Whether or not there was a non-micro version change in EE core version during this request
122
+	 *
123
+	 * @var boolean $_major_version_change
124
+	 */
125
+	private $_major_version_change = false;
126
+
127
+	/**
128
+	 * A Context DTO dedicated solely to identifying the current request type.
129
+	 *
130
+	 * @var RequestTypeContextCheckerInterface $request_type
131
+	 */
132
+	private $request_type;
133
+
134
+
135
+
136
+	/**
137
+	 * @singleton method used to instantiate class object
138
+	 * @param EE_Registry|null         $registry
139
+	 * @param LoaderInterface|null     $loader
140
+	 * @param RequestInterface|null          $request
141
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
142
+	 * @return EE_System
143
+	 */
144
+	public static function instance(
145
+		EE_Registry $registry = null,
146
+		LoaderInterface $loader = null,
147
+		RequestInterface $request = null,
148
+		EE_Maintenance_Mode $maintenance_mode = null
149
+	) {
150
+		// check if class object is instantiated
151
+		if (! self::$_instance instanceof EE_System) {
152
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
+		}
154
+		return self::$_instance;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * resets the instance and returns it
161
+	 *
162
+	 * @return EE_System
163
+	 */
164
+	public static function reset()
165
+	{
166
+		self::$_instance->_req_type = null;
167
+		//make sure none of the old hooks are left hanging around
168
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
+		//we need to reset the migration manager in order for it to detect DMSs properly
170
+		EE_Data_Migration_Manager::reset();
171
+		self::instance()->detect_activations_or_upgrades();
172
+		self::instance()->perform_activations_upgrades_and_migrations();
173
+		return self::instance();
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * sets hooks for running rest of system
180
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
+	 * starting EE Addons from any other point may lead to problems
182
+	 *
183
+	 * @param EE_Registry         $registry
184
+	 * @param LoaderInterface     $loader
185
+	 * @param RequestInterface          $request
186
+	 * @param EE_Maintenance_Mode $maintenance_mode
187
+	 */
188
+	private function __construct(
189
+		EE_Registry $registry,
190
+		LoaderInterface $loader,
191
+		RequestInterface $request,
192
+		EE_Maintenance_Mode $maintenance_mode
193
+	) {
194
+		$this->registry         = $registry;
195
+		$this->loader           = $loader;
196
+		$this->request          = $request;
197
+		$this->maintenance_mode = $maintenance_mode;
198
+		do_action('AHEE__EE_System__construct__begin', $this);
199
+		add_action(
200
+			'AHEE__EE_Bootstrap__load_espresso_addons',
201
+			array($this, 'loadCapabilities'),
202
+			5
203
+		);
204
+		add_action(
205
+			'AHEE__EE_Bootstrap__load_espresso_addons',
206
+			array($this, 'loadCommandBus'),
207
+			7
208
+		);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			array($this, 'loadPluginApi'),
212
+			9
213
+		);
214
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__load_espresso_addons',
217
+			array($this, 'load_espresso_addons')
218
+		);
219
+		// when an ee addon is activated, we want to call the core hook(s) again
220
+		// because the newly-activated addon didn't get a chance to run at all
221
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
+		// detect whether install or upgrade
223
+		add_action(
224
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
+			array($this, 'detect_activations_or_upgrades'),
226
+			3
227
+		);
228
+		// load EE_Config, EE_Textdomain, etc
229
+		add_action(
230
+			'AHEE__EE_Bootstrap__load_core_configuration',
231
+			array($this, 'load_core_configuration'),
232
+			5
233
+		);
234
+		// load EE_Config, EE_Textdomain, etc
235
+		add_action(
236
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
+			array($this, 'register_shortcodes_modules_and_widgets'),
238
+			7
239
+		);
240
+		// you wanna get going? I wanna get going... let's get going!
241
+		add_action(
242
+			'AHEE__EE_Bootstrap__brew_espresso',
243
+			array($this, 'brew_espresso'),
244
+			9
245
+		);
246
+		//other housekeeping
247
+		//exclude EE critical pages from wp_list_pages
248
+		add_filter(
249
+			'wp_list_pages_excludes',
250
+			array($this, 'remove_pages_from_wp_list_pages'),
251
+			10
252
+		);
253
+		// ALL EE Addons should use the following hook point to attach their initial setup too
254
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
+		do_action('AHEE__EE_System__construct__complete', $this);
256
+	}
257
+
258
+
259
+	/**
260
+	 * load and setup EE_Capabilities
261
+	 *
262
+	 * @return void
263
+	 * @throws EE_Error
264
+	 */
265
+	public function loadCapabilities()
266
+	{
267
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
268
+		add_action(
269
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
270
+			function ()
271
+			{
272
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * create and cache the CommandBus, and also add middleware
281
+	 * The CapChecker middleware requires the use of EE_Capabilities
282
+	 * which is why we need to load the CommandBus after Caps are set up
283
+	 *
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function loadCommandBus()
288
+	{
289
+		$this->loader->getShared(
290
+			'CommandBusInterface',
291
+			array(
292
+				null,
293
+				apply_filters(
294
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
+					array(
296
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
+					)
299
+				),
300
+			)
301
+		);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @return void
308
+	 * @throws EE_Error
309
+	 */
310
+	public function loadPluginApi()
311
+	{
312
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
313
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
314
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
+		$this->loader->getShared('EE_Request_Handler');
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $addon_name
321
+	 * @param string $version_constant
322
+	 * @param string $min_version_required
323
+	 * @param string $load_callback
324
+	 * @param string $plugin_file_constant
325
+	 * @return void
326
+	 */
327
+	private function deactivateIncompatibleAddon(
328
+		$addon_name,
329
+		$version_constant,
330
+		$min_version_required,
331
+		$load_callback,
332
+		$plugin_file_constant
333
+	) {
334
+		if (! defined($version_constant)) {
335
+			return;
336
+		}
337
+		$addon_version = constant($version_constant);
338
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
+			if (! function_exists('deactivate_plugins')) {
341
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
+			}
343
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
+			EE_Error::add_error(
346
+				sprintf(
347
+					esc_html__(
348
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
+						'event_espresso'
350
+					),
351
+					$addon_name,
352
+					$min_version_required
353
+				),
354
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
+			);
356
+			EE_Error::get_notices(false, true);
357
+		}
358
+	}
359
+
360
+
361
+	/**
362
+	 * load_espresso_addons
363
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
364
+	 * this is hooked into both:
365
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
366
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
367
+	 *    and the WP 'activate_plugin' hook point
368
+	 *
369
+	 * @access public
370
+	 * @return void
371
+	 */
372
+	public function load_espresso_addons()
373
+	{
374
+		$this->deactivateIncompatibleAddon(
375
+			'Wait Lists',
376
+			'EE_WAIT_LISTS_VERSION',
377
+			'1.0.0.beta.074',
378
+			'load_espresso_wait_lists',
379
+			'EE_WAIT_LISTS_PLUGIN_FILE'
380
+		);
381
+		$this->deactivateIncompatibleAddon(
382
+			'Automated Upcoming Event Notifications',
383
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
+			'1.0.0.beta.091',
385
+			'load_espresso_automated_upcoming_event_notification',
386
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
+		);
388
+		do_action('AHEE__EE_System__load_espresso_addons');
389
+		//if the WP API basic auth plugin isn't already loaded, load it now.
390
+		//We want it for mobile apps. Just include the entire plugin
391
+		//also, don't load the basic auth when a plugin is getting activated, because
392
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
+		//and causes a fatal error
394
+		if (
395
+			$this->request->getRequestParam('activate') !== 'true'
396
+			&& ! function_exists('json_basic_auth_handler')
397
+			&& ! function_exists('json_basic_auth_error')
398
+			&& ! in_array(
399
+				$this->request->getRequestParam('action'),
400
+				array('activate', 'activate-selected'),
401
+				true
402
+			)
403
+		) {
404
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
+		}
406
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * detect_activations_or_upgrades
413
+	 * Checks for activation or upgrade of core first;
414
+	 * then also checks if any registered addons have been activated or upgraded
415
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
+	 * which runs during the WP 'plugins_loaded' action at priority 3
417
+	 *
418
+	 * @access public
419
+	 * @return void
420
+	 */
421
+	public function detect_activations_or_upgrades()
422
+	{
423
+		//first off: let's make sure to handle core
424
+		$this->detect_if_activation_or_upgrade();
425
+		foreach ($this->registry->addons as $addon) {
426
+			if ($addon instanceof EE_Addon) {
427
+				//detect teh request type for that addon
428
+				$addon->detect_activation_or_upgrade();
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * detect_if_activation_or_upgrade
437
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
438
+	 * and either setting up the DB or setting up maintenance mode etc.
439
+	 *
440
+	 * @access public
441
+	 * @return void
442
+	 */
443
+	public function detect_if_activation_or_upgrade()
444
+	{
445
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
+		// check if db has been updated, or if its a brand-new installation
447
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
+		$request_type       = $this->detect_req_type($espresso_db_update);
449
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
+		switch ($request_type) {
451
+			case EE_System::req_type_new_activation:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
+				$this->_handle_core_version_change($espresso_db_update);
454
+				break;
455
+			case EE_System::req_type_reactivation:
456
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
+				$this->_handle_core_version_change($espresso_db_update);
458
+				break;
459
+			case EE_System::req_type_upgrade:
460
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
+				//migrations may be required now that we've upgraded
462
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
463
+				$this->_handle_core_version_change($espresso_db_update);
464
+				//				echo "done upgrade";die;
465
+				break;
466
+			case EE_System::req_type_downgrade:
467
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
+				//its possible migrations are no longer required
469
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
470
+				$this->_handle_core_version_change($espresso_db_update);
471
+				break;
472
+			case EE_System::req_type_normal:
473
+			default:
474
+				break;
475
+		}
476
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Updates the list of installed versions and sets hooks for
483
+	 * initializing the database later during the request
484
+	 *
485
+	 * @param array $espresso_db_update
486
+	 */
487
+	private function _handle_core_version_change($espresso_db_update)
488
+	{
489
+		$this->update_list_of_installed_versions($espresso_db_update);
490
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
+		add_action(
492
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
+			array($this, 'initialize_db_if_no_migrations_required')
494
+		);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
+	 * information about what versions of EE have been installed and activated,
502
+	 * NOT necessarily the state of the database
503
+	 *
504
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
505
+	 *                                            If not supplied, fetches it from the options table
506
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
+	 */
508
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
+	{
510
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
+		if (! $espresso_db_update) {
512
+			$espresso_db_update = get_option('espresso_db_update');
513
+		}
514
+		// check that option is an array
515
+		if (! is_array($espresso_db_update)) {
516
+			// if option is FALSE, then it never existed
517
+			if ($espresso_db_update === false) {
518
+				// make $espresso_db_update an array and save option with autoload OFF
519
+				$espresso_db_update = array();
520
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
+			} else {
522
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
523
+				$espresso_db_update = array($espresso_db_update => array());
524
+				update_option('espresso_db_update', $espresso_db_update);
525
+			}
526
+		} else {
527
+			$corrected_db_update = array();
528
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
+					//the key is an int, and the value IS NOT an array
532
+					//so it must be numerically-indexed, where values are versions installed...
533
+					//fix it!
534
+					$version_string                         = $should_be_array;
535
+					$corrected_db_update[ $version_string ] = array('unknown-date');
536
+				} else {
537
+					//ok it checks out
538
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
+				}
540
+			}
541
+			$espresso_db_update = $corrected_db_update;
542
+			update_option('espresso_db_update', $espresso_db_update);
543
+		}
544
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
+		return $espresso_db_update;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * Does the traditional work of setting up the plugin's database and adding default data.
552
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
+	 * so that it will be done when migrations are finished
556
+	 *
557
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
+	 *                                       This is a resource-intensive job
560
+	 *                                       so we prefer to only do it when necessary
561
+	 * @return void
562
+	 * @throws EE_Error
563
+	 */
564
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
+	{
566
+		$request_type = $this->detect_req_type();
567
+		//only initialize system if we're not in maintenance mode.
568
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
+			update_option('ee_flush_rewrite_rules', true);
570
+			if ($verify_schema) {
571
+				EEH_Activation::initialize_db_and_folders();
572
+			}
573
+			EEH_Activation::initialize_db_content();
574
+			EEH_Activation::system_initialization();
575
+			if ($initialize_addons_too) {
576
+				$this->initialize_addons();
577
+			}
578
+		} else {
579
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
580
+		}
581
+		if ($request_type === EE_System::req_type_new_activation
582
+			|| $request_type === EE_System::req_type_reactivation
583
+			|| (
584
+				$request_type === EE_System::req_type_upgrade
585
+				&& $this->is_major_version_change()
586
+			)
587
+		) {
588
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
589
+		}
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * Initializes the db for all registered addons
596
+	 *
597
+	 * @throws EE_Error
598
+	 */
599
+	public function initialize_addons()
600
+	{
601
+		//foreach registered addon, make sure its db is up-to-date too
602
+		foreach ($this->registry->addons as $addon) {
603
+			if ($addon instanceof EE_Addon) {
604
+				$addon->initialize_db_if_no_migrations_required();
605
+			}
606
+		}
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
613
+	 *
614
+	 * @param    array  $version_history
615
+	 * @param    string $current_version_to_add version to be added to the version history
616
+	 * @return    boolean success as to whether or not this option was changed
617
+	 */
618
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
619
+	{
620
+		if (! $version_history) {
621
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
622
+		}
623
+		if ($current_version_to_add === null) {
624
+			$current_version_to_add = espresso_version();
625
+		}
626
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
627
+		// re-save
628
+		return update_option('espresso_db_update', $version_history);
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * Detects if the current version indicated in the has existed in the list of
635
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
636
+	 *
637
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
638
+	 *                                  If not supplied, fetches it from the options table.
639
+	 *                                  Also, caches its result so later parts of the code can also know whether
640
+	 *                                  there's been an update or not. This way we can add the current version to
641
+	 *                                  espresso_db_update, but still know if this is a new install or not
642
+	 * @return int one of the constants on EE_System::req_type_
643
+	 */
644
+	public function detect_req_type($espresso_db_update = null)
645
+	{
646
+		if ($this->_req_type === null) {
647
+			$espresso_db_update          = ! empty($espresso_db_update)
648
+				? $espresso_db_update
649
+				: $this->fix_espresso_db_upgrade_option();
650
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
651
+				$espresso_db_update,
652
+				'ee_espresso_activation', espresso_version()
653
+			);
654
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
655
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
656
+		}
657
+		return $this->_req_type;
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Returns whether or not there was a non-micro version change (ie, change in either
664
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
665
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
666
+	 *
667
+	 * @param $activation_history
668
+	 * @return bool
669
+	 */
670
+	private function _detect_major_version_change($activation_history)
671
+	{
672
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
673
+		$previous_version_parts = explode('.', $previous_version);
674
+		$current_version_parts  = explode('.', espresso_version());
675
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
676
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
677
+				   || $previous_version_parts[1] !== $current_version_parts[1]
678
+			   );
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 * Returns true if either the major or minor version of EE changed during this request.
685
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
686
+	 *
687
+	 * @return bool
688
+	 */
689
+	public function is_major_version_change()
690
+	{
691
+		return $this->_major_version_change;
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
+	 * just activated to (for core that will always be espresso_version())
701
+	 *
702
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
703
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
704
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
705
+	 *                                                 indicate that this plugin was just activated
706
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
707
+	 *                                                 espresso_version())
708
+	 * @return int one of the constants on EE_System::req_type_*
709
+	 */
710
+	public static function detect_req_type_given_activation_history(
711
+		$activation_history_for_addon,
712
+		$activation_indicator_option_name,
713
+		$version_to_upgrade_to
714
+	) {
715
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
716
+		if ($activation_history_for_addon) {
717
+			//it exists, so this isn't a completely new install
718
+			//check if this version already in that list of previously installed versions
719
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
720
+				//it a version we haven't seen before
721
+				if ($version_is_higher === 1) {
722
+					$req_type = EE_System::req_type_upgrade;
723
+				} else {
724
+					$req_type = EE_System::req_type_downgrade;
725
+				}
726
+				delete_option($activation_indicator_option_name);
727
+			} else {
728
+				// its not an update. maybe a reactivation?
729
+				if (get_option($activation_indicator_option_name, false)) {
730
+					if ($version_is_higher === -1) {
731
+						$req_type = EE_System::req_type_downgrade;
732
+					} elseif ($version_is_higher === 0) {
733
+						//we've seen this version before, but it's an activation. must be a reactivation
734
+						$req_type = EE_System::req_type_reactivation;
735
+					} else {//$version_is_higher === 1
736
+						$req_type = EE_System::req_type_upgrade;
737
+					}
738
+					delete_option($activation_indicator_option_name);
739
+				} else {
740
+					//we've seen this version before and the activation indicate doesn't show it was just activated
741
+					if ($version_is_higher === -1) {
742
+						$req_type = EE_System::req_type_downgrade;
743
+					} elseif ($version_is_higher === 0) {
744
+						//we've seen this version before and it's not an activation. its normal request
745
+						$req_type = EE_System::req_type_normal;
746
+					} else {//$version_is_higher === 1
747
+						$req_type = EE_System::req_type_upgrade;
748
+					}
749
+				}
750
+			}
751
+		} else {
752
+			//brand new install
753
+			$req_type = EE_System::req_type_new_activation;
754
+			delete_option($activation_indicator_option_name);
755
+		}
756
+		return $req_type;
757
+	}
758
+
759
+
760
+
761
+	/**
762
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
763
+	 * the $activation_history_for_addon
764
+	 *
765
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
766
+	 *                                             sometimes containing 'unknown-date'
767
+	 * @param string $version_to_upgrade_to        (current version)
768
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
769
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
770
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
771
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
772
+	 */
773
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
774
+	{
775
+		//find the most recently-activated version
776
+		$most_recently_active_version =
777
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
778
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
779
+	}
780
+
781
+
782
+
783
+	/**
784
+	 * Gets the most recently active version listed in the activation history,
785
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
786
+	 *
787
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
788
+	 *                                   sometimes containing 'unknown-date'
789
+	 * @return string
790
+	 */
791
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
792
+	{
793
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
794
+		$most_recently_active_version            = '0.0.0.dev.000';
795
+		if (is_array($activation_history)) {
796
+			foreach ($activation_history as $version => $times_activated) {
797
+				//check there is a record of when this version was activated. Otherwise,
798
+				//mark it as unknown
799
+				if (! $times_activated) {
800
+					$times_activated = array('unknown-date');
801
+				}
802
+				if (is_string($times_activated)) {
803
+					$times_activated = array($times_activated);
804
+				}
805
+				foreach ($times_activated as $an_activation) {
806
+					if ($an_activation !== 'unknown-date'
807
+						&& $an_activation
808
+						   > $most_recently_active_version_activation) {
809
+						$most_recently_active_version            = $version;
810
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
811
+							? '1970-01-01 00:00:00'
812
+							: $an_activation;
813
+					}
814
+				}
815
+			}
816
+		}
817
+		return $most_recently_active_version;
818
+	}
819
+
820
+
821
+
822
+	/**
823
+	 * This redirects to the about EE page after activation
824
+	 *
825
+	 * @return void
826
+	 */
827
+	public function redirect_to_about_ee()
828
+	{
829
+		$notices = EE_Error::get_notices(false);
830
+		//if current user is an admin and it's not an ajax or rest request
831
+		if (
832
+			! isset($notices['errors'])
833
+			&& $this->request->isAdmin()
834
+			&& apply_filters(
835
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
836
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
837
+			)
838
+		) {
839
+			$query_params = array('page' => 'espresso_about');
840
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
841
+				$query_params['new_activation'] = true;
842
+			}
843
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
844
+				$query_params['reactivation'] = true;
845
+			}
846
+			$url = add_query_arg($query_params, admin_url('admin.php'));
847
+			wp_safe_redirect($url);
848
+			exit();
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 * load_core_configuration
856
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
857
+	 * which runs during the WP 'plugins_loaded' action at priority 5
858
+	 *
859
+	 * @return void
860
+	 * @throws ReflectionException
861
+	 */
862
+	public function load_core_configuration()
863
+	{
864
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
865
+		$this->loader->getShared('EE_Load_Textdomain');
866
+		//load textdomain
867
+		EE_Load_Textdomain::load_textdomain();
868
+		// load and setup EE_Config and EE_Network_Config
869
+		$config = $this->loader->getShared('EE_Config');
870
+		$this->loader->getShared('EE_Network_Config');
871
+		// setup autoloaders
872
+		// enable logging?
873
+		if ($config->admin->use_full_logging) {
874
+			$this->loader->getShared('EE_Log');
875
+		}
876
+		// check for activation errors
877
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
878
+		if ($activation_errors) {
879
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
880
+			update_option('ee_plugin_activation_errors', false);
881
+		}
882
+		// get model names
883
+		$this->_parse_model_names();
884
+		//load caf stuff a chance to play during the activation process too.
885
+		$this->_maybe_brew_regular();
886
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
887
+	}
888
+
889
+
890
+
891
+	/**
892
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
893
+	 *
894
+	 * @return void
895
+	 * @throws ReflectionException
896
+	 */
897
+	private function _parse_model_names()
898
+	{
899
+		//get all the files in the EE_MODELS folder that end in .model.php
900
+		$models                 = glob(EE_MODELS . '*.model.php');
901
+		$model_names            = array();
902
+		$non_abstract_db_models = array();
903
+		foreach ($models as $model) {
904
+			// get model classname
905
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
906
+			$short_name      = str_replace('EEM_', '', $classname);
907
+			$reflectionClass = new ReflectionClass($classname);
908
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
909
+				$non_abstract_db_models[ $short_name ] = $classname;
910
+			}
911
+			$model_names[ $short_name ] = $classname;
912
+		}
913
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
914
+		$this->registry->non_abstract_db_models = apply_filters(
915
+			'FHEE__EE_System__parse_implemented_model_names',
916
+			$non_abstract_db_models
917
+		);
918
+	}
919
+
920
+
921
+	/**
922
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
923
+	 * that need to be setup before our EE_System launches.
924
+	 *
925
+	 * @return void
926
+	 * @throws DomainException
927
+	 * @throws InvalidArgumentException
928
+	 * @throws InvalidDataTypeException
929
+	 * @throws InvalidInterfaceException
930
+	 * @throws InvalidClassException
931
+	 * @throws InvalidFilePathException
932
+	 */
933
+	private function _maybe_brew_regular()
934
+	{
935
+		/** @var Domain $domain */
936
+		$domain = DomainFactory::getShared(
937
+			new FullyQualifiedName(
938
+				'EventEspresso\core\domain\Domain'
939
+			),
940
+			array(
941
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
942
+				Version::fromString(espresso_version())
943
+			)
944
+		);
945
+		if ($domain->isCaffeinated()) {
946
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
947
+		}
948
+	}
949
+
950
+
951
+
952
+	/**
953
+	 * register_shortcodes_modules_and_widgets
954
+	 * generate lists of shortcodes and modules, then verify paths and classes
955
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
956
+	 * which runs during the WP 'plugins_loaded' action at priority 7
957
+	 *
958
+	 * @access public
959
+	 * @return void
960
+	 * @throws Exception
961
+	 */
962
+	public function register_shortcodes_modules_and_widgets()
963
+	{
964
+		try {
965
+			// load, register, and add shortcodes the new way
966
+			if ($this->request->isFrontend() || $this->request->isIframe()) {
967
+				$this->loader->getShared(
968
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
969
+					array(
970
+						// and the old way, but we'll put it under control of the new system
971
+						EE_Config::getLegacyShortcodesManager(),
972
+					)
973
+				);
974
+			}
975
+			if (function_exists('register_block_type')) {
976
+				// or the even newer newer new way
977
+				if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
978
+					$this->loader->getShared(
979
+						'EventEspresso\core\services\editor\EditorBlockRegistrationManager'
980
+					);
981
+				}
982
+			}
983
+		} catch (Exception $exception) {
984
+			new ExceptionStackTraceDisplay($exception);
985
+		}
986
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
987
+		// check for addons using old hook point
988
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
989
+			$this->_incompatible_addon_error();
990
+		}
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 * _incompatible_addon_error
997
+	 *
998
+	 * @access public
999
+	 * @return void
1000
+	 */
1001
+	private function _incompatible_addon_error()
1002
+	{
1003
+		// get array of classes hooking into here
1004
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1005
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
1006
+		);
1007
+		if (! empty($class_names)) {
1008
+			$msg = __(
1009
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1010
+				'event_espresso'
1011
+			);
1012
+			$msg .= '<ul>';
1013
+			foreach ($class_names as $class_name) {
1014
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1015
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1016
+						$class_name
1017
+					) . '</b></li>';
1018
+			}
1019
+			$msg .= '</ul>';
1020
+			$msg .= __(
1021
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1022
+				'event_espresso'
1023
+			);
1024
+			// save list of incompatible addons to wp-options for later use
1025
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1026
+			if (is_admin()) {
1027
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
+			}
1029
+		}
1030
+	}
1031
+
1032
+
1033
+
1034
+	/**
1035
+	 * brew_espresso
1036
+	 * begins the process of setting hooks for initializing EE in the correct order
1037
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1038
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1039
+	 *
1040
+	 * @return void
1041
+	 */
1042
+	public function brew_espresso()
1043
+	{
1044
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1045
+		// load some final core systems
1046
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1047
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1048
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1049
+		add_action('init', array($this, 'load_controllers'), 7);
1050
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1051
+		add_action('init', array($this, 'initialize'), 10);
1052
+		add_action('init', array($this, 'initialize_last'), 100);
1053
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1054
+			// pew pew pew
1055
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1056
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1057
+		}
1058
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1059
+	}
1060
+
1061
+
1062
+
1063
+	/**
1064
+	 *    set_hooks_for_core
1065
+	 *
1066
+	 * @access public
1067
+	 * @return    void
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function set_hooks_for_core()
1071
+	{
1072
+		$this->_deactivate_incompatible_addons();
1073
+		do_action('AHEE__EE_System__set_hooks_for_core');
1074
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1075
+		//caps need to be initialized on every request so that capability maps are set.
1076
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1077
+		$this->registry->CAP->init_caps();
1078
+	}
1079
+
1080
+
1081
+
1082
+	/**
1083
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1084
+	 * deactivates any addons considered incompatible with the current version of EE
1085
+	 */
1086
+	private function _deactivate_incompatible_addons()
1087
+	{
1088
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1089
+		if (! empty($incompatible_addons)) {
1090
+			$active_plugins = get_option('active_plugins', array());
1091
+			foreach ($active_plugins as $active_plugin) {
1092
+				foreach ($incompatible_addons as $incompatible_addon) {
1093
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1094
+						unset($_GET['activate']);
1095
+						espresso_deactivate_plugin($active_plugin);
1096
+					}
1097
+				}
1098
+			}
1099
+		}
1100
+	}
1101
+
1102
+
1103
+
1104
+	/**
1105
+	 *    perform_activations_upgrades_and_migrations
1106
+	 *
1107
+	 * @access public
1108
+	 * @return    void
1109
+	 */
1110
+	public function perform_activations_upgrades_and_migrations()
1111
+	{
1112
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1113
+	}
1114
+
1115
+
1116
+
1117
+	/**
1118
+	 *    load_CPTs_and_session
1119
+	 *
1120
+	 * @access public
1121
+	 * @return    void
1122
+	 */
1123
+	public function load_CPTs_and_session()
1124
+	{
1125
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1126
+		// register Custom Post Types
1127
+		$this->loader->getShared('EE_Register_CPTs');
1128
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 * load_controllers
1135
+	 * this is the best place to load any additional controllers that needs access to EE core.
1136
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1137
+	 * time
1138
+	 *
1139
+	 * @access public
1140
+	 * @return void
1141
+	 */
1142
+	public function load_controllers()
1143
+	{
1144
+		do_action('AHEE__EE_System__load_controllers__start');
1145
+		// let's get it started
1146
+		if (
1147
+			! $this->maintenance_mode->level()
1148
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1149
+		) {
1150
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1151
+			$this->loader->getShared('EE_Front_Controller');
1152
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1153
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1154
+			$this->loader->getShared('EE_Admin');
1155
+		}
1156
+		do_action('AHEE__EE_System__load_controllers__complete');
1157
+	}
1158
+
1159
+
1160
+
1161
+	/**
1162
+	 * core_loaded_and_ready
1163
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1164
+	 *
1165
+	 * @access public
1166
+	 * @return void
1167
+	 */
1168
+	public function core_loaded_and_ready()
1169
+	{
1170
+		if (
1171
+			$this->request->isAdmin()
1172
+			|| $this->request->isEeAjax()
1173
+			|| $this->request->isFrontend()
1174
+		) {
1175
+			$this->loader->getShared('EE_Session');
1176
+		}
1177
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1178
+		// load_espresso_template_tags
1179
+		if (
1180
+			is_readable(EE_PUBLIC . 'template_tags.php')
1181
+			&& (
1182
+				$this->request->isFrontend()
1183
+				|| $this->request->isAdmin()
1184
+				|| $this->request->isIframe()
1185
+				|| $this->request->isFeed()
1186
+			)
1187
+		) {
1188
+			require_once EE_PUBLIC . 'template_tags.php';
1189
+		}
1190
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1191
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1192
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1193
+		}
1194
+	}
1195
+
1196
+
1197
+
1198
+	/**
1199
+	 * initialize
1200
+	 * this is the best place to begin initializing client code
1201
+	 *
1202
+	 * @access public
1203
+	 * @return void
1204
+	 */
1205
+	public function initialize()
1206
+	{
1207
+		do_action('AHEE__EE_System__initialize');
1208
+	}
1209
+
1210
+
1211
+
1212
+	/**
1213
+	 * initialize_last
1214
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1215
+	 * initialize has done so
1216
+	 *
1217
+	 * @access public
1218
+	 * @return void
1219
+	 */
1220
+	public function initialize_last()
1221
+	{
1222
+		do_action('AHEE__EE_System__initialize_last');
1223
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1224
+	}
1225
+
1226
+
1227
+
1228
+	/**
1229
+	 * @return void
1230
+	 * @throws EE_Error
1231
+	 */
1232
+	public function addEspressoToolbar()
1233
+	{
1234
+		$this->loader->getShared(
1235
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1236
+			array($this->registry->CAP)
1237
+		);
1238
+	}
1239
+
1240
+
1241
+
1242
+	/**
1243
+	 * do_not_cache
1244
+	 * sets no cache headers and defines no cache constants for WP plugins
1245
+	 *
1246
+	 * @access public
1247
+	 * @return void
1248
+	 */
1249
+	public static function do_not_cache()
1250
+	{
1251
+		// set no cache constants
1252
+		if (! defined('DONOTCACHEPAGE')) {
1253
+			define('DONOTCACHEPAGE', true);
1254
+		}
1255
+		if (! defined('DONOTCACHCEOBJECT')) {
1256
+			define('DONOTCACHCEOBJECT', true);
1257
+		}
1258
+		if (! defined('DONOTCACHEDB')) {
1259
+			define('DONOTCACHEDB', true);
1260
+		}
1261
+		// add no cache headers
1262
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1263
+		// plus a little extra for nginx and Google Chrome
1264
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1265
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1266
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1267
+	}
1268
+
1269
+
1270
+
1271
+	/**
1272
+	 *    extra_nocache_headers
1273
+	 *
1274
+	 * @access    public
1275
+	 * @param $headers
1276
+	 * @return    array
1277
+	 */
1278
+	public static function extra_nocache_headers($headers)
1279
+	{
1280
+		// for NGINX
1281
+		$headers['X-Accel-Expires'] = 0;
1282
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1283
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1284
+		return $headers;
1285
+	}
1286
+
1287
+
1288
+
1289
+	/**
1290
+	 *    nocache_headers
1291
+	 *
1292
+	 * @access    public
1293
+	 * @return    void
1294
+	 */
1295
+	public static function nocache_headers()
1296
+	{
1297
+		nocache_headers();
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1304
+	 * never returned with the function.
1305
+	 *
1306
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1307
+	 * @return array
1308
+	 */
1309
+	public function remove_pages_from_wp_list_pages($exclude_array)
1310
+	{
1311
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1312
+	}
1313 1313
 
1314 1314
 
1315 1315
 
Please login to merge, or discard this patch.
core/domain/DomainInterface.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -16,67 +16,67 @@
 block discarded – undo
16 16
 interface DomainInterface extends InterminableInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @return string
21
-     * @throws DomainException
22
-     */
23
-    public function pluginFile();
19
+	/**
20
+	 * @return string
21
+	 * @throws DomainException
22
+	 */
23
+	public function pluginFile();
24 24
 
25 25
 
26
-    /**
27
-     * @return string
28
-     * @throws DomainException
29
-     */
30
-    public function pluginBasename();
26
+	/**
27
+	 * @return string
28
+	 * @throws DomainException
29
+	 */
30
+	public function pluginBasename();
31 31
 
32 32
 
33
-    /**
34
-     * @return string
35
-     */
36
-    public function pluginPath();
33
+	/**
34
+	 * @return string
35
+	 */
36
+	public function pluginPath();
37 37
 
38 38
 
39
-    /**
40
-     * @return string
41
-     * @throws DomainException
42
-     */
43
-    public function pluginUrl();
39
+	/**
40
+	 * @return string
41
+	 * @throws DomainException
42
+	 */
43
+	public function pluginUrl();
44 44
 
45 45
 
46
-    /**
47
-     * @return string
48
-     * @throws DomainException
49
-     */
50
-    public function version();
46
+	/**
47
+	 * @return string
48
+	 * @throws DomainException
49
+	 */
50
+	public function version();
51 51
 
52 52
 
53
-    /**
54
-     * @return string
55
-     */
56
-    public function sourceAssetsPath();
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function sourceAssetsPath();
57 57
 
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function sourceAssetsUrl();
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function sourceAssetsUrl();
63 63
 
64 64
 
65
-    /**
66
-     * @return string
67
-     */
68
-    public function distributionAssetsPath();
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function distributionAssetsPath();
69 69
 
70 70
 
71
-    /**
72
-     * @return string
73
-     */
74
-    public function distributionAssetsUrl();
71
+	/**
72
+	 * @return string
73
+	 */
74
+	public function distributionAssetsUrl();
75 75
 
76 76
 
77
-    /**
78
-     * @return string
79
-     */
80
-    public function assetNamespace();
77
+	/**
78
+	 * @return string
79
+	 */
80
+	public function assetNamespace();
81 81
 
82 82
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -20,175 +20,175 @@
 block discarded – undo
20 20
 abstract class DomainBase implements DomainInterface
21 21
 {
22 22
 
23
-    /**
24
-     * Equivalent to `__FILE__` for main plugin file.
25
-     *
26
-     * @var FilePath
27
-     */
28
-    private $plugin_file;
29
-
30
-    /**
31
-     * String indicating version for plugin
32
-     *
33
-     * @var string
34
-     */
35
-    private $version;
36
-
37
-    /**
38
-     * @var string $plugin_basename
39
-     */
40
-    private $plugin_basename;
41
-
42
-    /**
43
-     * @var string $plugin_path
44
-     */
45
-    private $plugin_path;
46
-
47
-    /**
48
-     * @var string $plugin_url
49
-     */
50
-    private $plugin_url;
51
-
52
-    /**
53
-     * @var string $asset_namespace
54
-     */
55
-    private $asset_namespace;
56
-
57
-
58
-
59
-    /**
60
-     * Initializes internal properties.
61
-     *
62
-     * @param FilePath $plugin_file
63
-     * @param Version  $version
64
-     */
65
-    public function __construct(FilePath $plugin_file, Version $version)
66
-    {
67
-        $this->plugin_file = $plugin_file;
68
-        $this->version = $version;
69
-        $this->plugin_basename = plugin_basename($this->pluginFile());
70
-        $this->plugin_path = plugin_dir_path($this->pluginFile());
71
-        $this->plugin_url = plugin_dir_url($this->pluginFile());
72
-        $this->setAssetNamespace();
73
-    }
74
-
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function pluginFile()
80
-    {
81
-        return (string) $this->plugin_file;
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * @return string
88
-     */
89
-    public function pluginBasename()
90
-    {
91
-        return $this->plugin_basename;
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * @return string
98
-     */
99
-    public function pluginPath()
100
-    {
101
-        return $this->plugin_path;
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * @return string
108
-     */
109
-    public function pluginUrl()
110
-    {
111
-        return $this->plugin_url;
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public function version()
120
-    {
121
-        return (string) $this->version;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return Version
128
-     */
129
-    public function versionValueObject()
130
-    {
131
-        return $this->version;
132
-    }
133
-
134
-
135
-    /**
136
-     * @return string
137
-     */
138
-    public function sourceAssetsPath()
139
-    {
140
-        return $this->pluginPath() . 'assets/src/';
141
-    }
142
-
143
-
144
-    /**
145
-     * @return string
146
-     */
147
-    public function sourceAssetsUrl()
148
-    {
149
-        return $this->pluginUrl() . 'assets/src/';
150
-    }
151
-
152
-
153
-    /**
154
-     * @return string
155
-     */
156
-    public function distributionAssetsPath()
157
-    {
158
-        return $this->pluginPath() . 'assets/dist/';
159
-    }
160
-
161
-
162
-    /**
163
-     * @return string
164
-     */
165
-    public function distributionAssetsUrl()
166
-    {
167
-        return $this->pluginUrl() . 'assets/dist/';
168
-    }
169
-
170
-
171
-    /**
172
-     * @return string
173
-     */
174
-    public function assetNamespace()
175
-    {
176
-        return $this->asset_namespace;
177
-    }
178
-
179
-
180
-    /**
181
-     * @return void
182
-     */
183
-    private function setAssetNamespace()
184
-    {
185
-        $asset_namespace  = explode('/', $this->plugin_basename);
186
-        $asset_namespace = reset($asset_namespace);
187
-        $asset_namespace = $asset_namespace === 'event-espresso-core'
188
-            ? Registry::ASSET_NAMESPACE_CORE
189
-            : $asset_namespace;
190
-        $this->asset_namespace = $asset_namespace;
191
-    }
23
+	/**
24
+	 * Equivalent to `__FILE__` for main plugin file.
25
+	 *
26
+	 * @var FilePath
27
+	 */
28
+	private $plugin_file;
29
+
30
+	/**
31
+	 * String indicating version for plugin
32
+	 *
33
+	 * @var string
34
+	 */
35
+	private $version;
36
+
37
+	/**
38
+	 * @var string $plugin_basename
39
+	 */
40
+	private $plugin_basename;
41
+
42
+	/**
43
+	 * @var string $plugin_path
44
+	 */
45
+	private $plugin_path;
46
+
47
+	/**
48
+	 * @var string $plugin_url
49
+	 */
50
+	private $plugin_url;
51
+
52
+	/**
53
+	 * @var string $asset_namespace
54
+	 */
55
+	private $asset_namespace;
56
+
57
+
58
+
59
+	/**
60
+	 * Initializes internal properties.
61
+	 *
62
+	 * @param FilePath $plugin_file
63
+	 * @param Version  $version
64
+	 */
65
+	public function __construct(FilePath $plugin_file, Version $version)
66
+	{
67
+		$this->plugin_file = $plugin_file;
68
+		$this->version = $version;
69
+		$this->plugin_basename = plugin_basename($this->pluginFile());
70
+		$this->plugin_path = plugin_dir_path($this->pluginFile());
71
+		$this->plugin_url = plugin_dir_url($this->pluginFile());
72
+		$this->setAssetNamespace();
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function pluginFile()
80
+	{
81
+		return (string) $this->plugin_file;
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * @return string
88
+	 */
89
+	public function pluginBasename()
90
+	{
91
+		return $this->plugin_basename;
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * @return string
98
+	 */
99
+	public function pluginPath()
100
+	{
101
+		return $this->plugin_path;
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * @return string
108
+	 */
109
+	public function pluginUrl()
110
+	{
111
+		return $this->plugin_url;
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public function version()
120
+	{
121
+		return (string) $this->version;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return Version
128
+	 */
129
+	public function versionValueObject()
130
+	{
131
+		return $this->version;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return string
137
+	 */
138
+	public function sourceAssetsPath()
139
+	{
140
+		return $this->pluginPath() . 'assets/src/';
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return string
146
+	 */
147
+	public function sourceAssetsUrl()
148
+	{
149
+		return $this->pluginUrl() . 'assets/src/';
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return string
155
+	 */
156
+	public function distributionAssetsPath()
157
+	{
158
+		return $this->pluginPath() . 'assets/dist/';
159
+	}
160
+
161
+
162
+	/**
163
+	 * @return string
164
+	 */
165
+	public function distributionAssetsUrl()
166
+	{
167
+		return $this->pluginUrl() . 'assets/dist/';
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return string
173
+	 */
174
+	public function assetNamespace()
175
+	{
176
+		return $this->asset_namespace;
177
+	}
178
+
179
+
180
+	/**
181
+	 * @return void
182
+	 */
183
+	private function setAssetNamespace()
184
+	{
185
+		$asset_namespace  = explode('/', $this->plugin_basename);
186
+		$asset_namespace = reset($asset_namespace);
187
+		$asset_namespace = $asset_namespace === 'event-espresso-core'
188
+			? Registry::ASSET_NAMESPACE_CORE
189
+			: $asset_namespace;
190
+		$this->asset_namespace = $asset_namespace;
191
+	}
192 192
 
193 193
 
194 194
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function sourceAssetsPath()
139 139
     {
140
-        return $this->pluginPath() . 'assets/src/';
140
+        return $this->pluginPath().'assets/src/';
141 141
     }
142 142
 
143 143
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public function sourceAssetsUrl()
148 148
     {
149
-        return $this->pluginUrl() . 'assets/src/';
149
+        return $this->pluginUrl().'assets/src/';
150 150
     }
151 151
 
152 152
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function distributionAssetsPath()
157 157
     {
158
-        return $this->pluginPath() . 'assets/dist/';
158
+        return $this->pluginPath().'assets/dist/';
159 159
     }
160 160
 
161 161
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public function distributionAssetsUrl()
166 166
     {
167
-        return $this->pluginUrl() . 'assets/dist/';
167
+        return $this->pluginUrl().'assets/dist/';
168 168
     }
169 169
 
170 170
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     private function setAssetNamespace()
184 184
     {
185
-        $asset_namespace  = explode('/', $this->plugin_basename);
185
+        $asset_namespace = explode('/', $this->plugin_basename);
186 186
         $asset_namespace = reset($asset_namespace);
187 187
         $asset_namespace = $asset_namespace === 'event-espresso-core'
188 188
             ? Registry::ASSET_NAMESPACE_CORE
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/CoreBlocksAssetRegister.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@
 block discarded – undo
20 20
  */
21 21
 class CoreBlocksAssetRegister extends EditorBlockAssetRegister
22 22
 {
23
-    /**
24
-     * CoreBlocksAssetRegister constructor.
25
-     *
26
-     * @param DomainInterface $domain
27
-     * @param Registry        $registry
28
-     */
29
-    public function __construct(DomainInterface $domain, Registry $registry) {
30
-        parent::__construct(
31
-            'core-blocks',
32
-            array(),
33
-            'core-blocks',
34
-            array(),
35
-            $domain,
36
-            $registry
37
-        );
38
-    }
23
+	/**
24
+	 * CoreBlocksAssetRegister constructor.
25
+	 *
26
+	 * @param DomainInterface $domain
27
+	 * @param Registry        $registry
28
+	 */
29
+	public function __construct(DomainInterface $domain, Registry $registry) {
30
+		parent::__construct(
31
+			'core-blocks',
32
+			array(),
33
+			'core-blocks',
34
+			array(),
35
+			$domain,
36
+			$registry
37
+		);
38
+	}
39 39
 }
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/widgets/EventAttendees.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@
 block discarded – undo
20 20
 class EventAttendees extends EditorBlock
21 21
 {
22 22
 
23
-    const BLOCK_TYPE = 'widgets-event-attendees';
24
-
25
-
26
-    /**
27
-     * Perform any early setup required by the block
28
-     * including setting the block type and supported post types
29
-     *
30
-     * @return void
31
-     */
32
-    public function initialize()
33
-    {
34
-        $this->setEditorBlockType(EventAttendees::BLOCK_TYPE);
35
-        $this->setSupportedPostTypes(array('espresso_events', 'post', 'page'));
36
-        $this->setAttributes(array());
37
-        $this->setAssetRegisterFqcn('EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetRegister');
38
-    }
23
+	const BLOCK_TYPE = 'widgets-event-attendees';
24
+
25
+
26
+	/**
27
+	 * Perform any early setup required by the block
28
+	 * including setting the block type and supported post types
29
+	 *
30
+	 * @return void
31
+	 */
32
+	public function initialize()
33
+	{
34
+		$this->setEditorBlockType(EventAttendees::BLOCK_TYPE);
35
+		$this->setSupportedPostTypes(array('espresso_events', 'post', 'page'));
36
+		$this->setAttributes(array());
37
+		$this->setAssetRegisterFqcn('EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetRegister');
38
+	}
39 39
 }
Please login to merge, or discard this patch.