Completed
Branch fix-uxip-dismiss (8e6a70)
by
unknown
65:15 queued 53:00
created
core/services/routing/Router.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -15,230 +15,230 @@
 block discarded – undo
15 15
 class Router
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Dependency_Map $dependency_map
20
-     */
21
-    protected $dependency_map;
22
-
23
-    /**
24
-     * @var LoaderInterface $loader
25
-     */
26
-    protected $loader;
27
-
28
-    /**
29
-     * @var RouteHandler $route_handler
30
-     */
31
-    protected $route_handler;
32
-
33
-    /**
34
-     * @var string $route_request_type
35
-     */
36
-    protected $route_request_type;
37
-
38
-
39
-    /**
40
-     * RoutingSwitch constructor.
41
-     *
42
-     * @param EE_Dependency_Map $dependency_map
43
-     * @param LoaderInterface   $loader
44
-     * @param RouteHandler      $router
45
-     */
46
-    public function __construct(EE_Dependency_Map $dependency_map, LoaderInterface $loader, RouteHandler $router)
47
-    {
48
-        $this->dependency_map = $dependency_map;
49
-        $this->loader         = $loader;
50
-        $this->route_handler  = $router;
51
-    }
52
-
53
-
54
-    /**
55
-     * @throws Exception
56
-     */
57
-    public function loadPrimaryRoutes()
58
-    {
59
-        do_action(
60
-            'AHEE__EventEspresso_core_services_routing_Router__loadPrimaryRoutes',
61
-            $this->route_handler,
62
-            $this->route_request_type,
63
-            $this->dependency_map
64
-        );
65
-        $this->dependency_map->registerDependencies(
66
-            'EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests',
67
-            Route::getFullDependencies()
68
-        );
69
-        $this->dependency_map->registerDependencies(
70
-            'EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests',
71
-            Route::getFullDependencies()
72
-        );
73
-        // now load and prep all primary Routes
74
-        $this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests');
75
-        $this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests');
76
-        $this->route_request_type = $this->route_handler->getRouteRequestType();
77
-    }
78
-
79
-
80
-    /**
81
-     *
82
-     * @throws Exception
83
-     */
84
-    public function registerShortcodesModulesAndWidgets()
85
-    {
86
-        do_action(
87
-            'AHEE__EventEspresso_core_services_routing_Router__registerShortcodesModulesAndWidgets',
88
-            $this->route_handler,
89
-            $this->route_request_type,
90
-            $this->dependency_map
91
-        );
92
-        switch ($this->route_request_type) {
93
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
94
-                break;
95
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
96
-                $this->route_handler->addRoute(
97
-                    'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests'
98
-                );
99
-                break;
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     *
106
-     * @throws Exception
107
-     * @throws Exception
108
-     * @throws Exception
109
-     * @throws Exception
110
-     */
111
-    public function brewEspresso()
112
-    {
113
-        do_action(
114
-            'AHEE__EventEspresso_core_services_routing_Router__brewEspresso',
115
-            $this->route_handler,
116
-            $this->route_request_type,
117
-            $this->dependency_map
118
-        );
119
-        $this->route_handler->addRoute(
120
-            'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'
121
-        );
122
-        switch ($this->route_request_type) {
123
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
124
-                break;
125
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
126
-                $this->route_handler->addRoute(
127
-                    'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'
128
-                );
129
-                $this->route_handler->addRoute(
130
-                    'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'
131
-                );
132
-                break;
133
-        }
134
-    }
135
-
136
-
137
-    /**
138
-     *
139
-     * @throws Exception
140
-     * @throws Exception
141
-     * @throws Exception
142
-     * @throws Exception
143
-     * @throws Exception
144
-     * @throws Exception
145
-     * @throws Exception
146
-     * @throws Exception
147
-     * @throws Exception
148
-     * @throws Exception
149
-     */
150
-    public function loadControllers()
151
-    {
152
-        do_action(
153
-            'AHEE__EventEspresso_core_services_routing_Router__loadControllers',
154
-            $this->route_handler,
155
-            $this->route_request_type,
156
-            $this->dependency_map
157
-        );
158
-        $this->route_handler->addRoute(
159
-            'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'
160
-        );
161
-        switch ($this->route_request_type) {
162
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
163
-                $this->route_handler->addRoute(
164
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
165
-                );
166
-                break;
167
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
168
-                $this->route_handler->addRoute(
169
-                    'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'
170
-                );
171
-                $this->route_handler->addRoute(
172
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'
173
-                );
174
-                $this->route_handler->addRoute(
175
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'
176
-                );
177
-                $this->route_handler->addRoute(
178
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'
179
-                );
180
-                $this->route_handler->addRoute(
181
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'
182
-                );
183
-                $this->route_handler->addRoute(
184
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
185
-                );
186
-                $this->route_handler->addRoute(
187
-                    'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'
188
-                );
189
-                break;
190
-        }
191
-    }
192
-
193
-
194
-    /**
195
-     *
196
-     * @throws Exception
197
-     * @throws Exception
198
-     */
199
-    public function coreLoadedAndReady()
200
-    {
201
-        do_action(
202
-            'AHEE__EventEspresso_core_services_routing_Router__coreLoadedAndReady',
203
-            $this->route_handler,
204
-            $this->route_request_type,
205
-            $this->dependency_map
206
-        );
207
-        switch ($this->route_request_type) {
208
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
209
-                break;
210
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
211
-                $this->route_handler->addRoute(
212
-                    'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'
213
-                );
214
-                $this->route_handler->addRoute(
215
-                    'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'
216
-                );
217
-                break;
218
-        }
219
-    }
220
-
221
-
222
-    /**
223
-     *
224
-     * @throws Exception
225
-     */
226
-    public function initializeLast()
227
-    {
228
-        do_action(
229
-            'AHEE__EventEspresso_core_services_routing_Router__initializeLast',
230
-            $this->route_handler,
231
-            $this->route_request_type,
232
-            $this->dependency_map
233
-        );
234
-        switch ($this->route_request_type) {
235
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
236
-                break;
237
-            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
238
-                $this->route_handler->addRoute(
239
-                    'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests'
240
-                );
241
-                break;
242
-        }
243
-    }
18
+	/**
19
+	 * @var EE_Dependency_Map $dependency_map
20
+	 */
21
+	protected $dependency_map;
22
+
23
+	/**
24
+	 * @var LoaderInterface $loader
25
+	 */
26
+	protected $loader;
27
+
28
+	/**
29
+	 * @var RouteHandler $route_handler
30
+	 */
31
+	protected $route_handler;
32
+
33
+	/**
34
+	 * @var string $route_request_type
35
+	 */
36
+	protected $route_request_type;
37
+
38
+
39
+	/**
40
+	 * RoutingSwitch constructor.
41
+	 *
42
+	 * @param EE_Dependency_Map $dependency_map
43
+	 * @param LoaderInterface   $loader
44
+	 * @param RouteHandler      $router
45
+	 */
46
+	public function __construct(EE_Dependency_Map $dependency_map, LoaderInterface $loader, RouteHandler $router)
47
+	{
48
+		$this->dependency_map = $dependency_map;
49
+		$this->loader         = $loader;
50
+		$this->route_handler  = $router;
51
+	}
52
+
53
+
54
+	/**
55
+	 * @throws Exception
56
+	 */
57
+	public function loadPrimaryRoutes()
58
+	{
59
+		do_action(
60
+			'AHEE__EventEspresso_core_services_routing_Router__loadPrimaryRoutes',
61
+			$this->route_handler,
62
+			$this->route_request_type,
63
+			$this->dependency_map
64
+		);
65
+		$this->dependency_map->registerDependencies(
66
+			'EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests',
67
+			Route::getFullDependencies()
68
+		);
69
+		$this->dependency_map->registerDependencies(
70
+			'EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests',
71
+			Route::getFullDependencies()
72
+		);
73
+		// now load and prep all primary Routes
74
+		$this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests');
75
+		$this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests');
76
+		$this->route_request_type = $this->route_handler->getRouteRequestType();
77
+	}
78
+
79
+
80
+	/**
81
+	 *
82
+	 * @throws Exception
83
+	 */
84
+	public function registerShortcodesModulesAndWidgets()
85
+	{
86
+		do_action(
87
+			'AHEE__EventEspresso_core_services_routing_Router__registerShortcodesModulesAndWidgets',
88
+			$this->route_handler,
89
+			$this->route_request_type,
90
+			$this->dependency_map
91
+		);
92
+		switch ($this->route_request_type) {
93
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
94
+				break;
95
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
96
+				$this->route_handler->addRoute(
97
+					'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests'
98
+				);
99
+				break;
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 *
106
+	 * @throws Exception
107
+	 * @throws Exception
108
+	 * @throws Exception
109
+	 * @throws Exception
110
+	 */
111
+	public function brewEspresso()
112
+	{
113
+		do_action(
114
+			'AHEE__EventEspresso_core_services_routing_Router__brewEspresso',
115
+			$this->route_handler,
116
+			$this->route_request_type,
117
+			$this->dependency_map
118
+		);
119
+		$this->route_handler->addRoute(
120
+			'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'
121
+		);
122
+		switch ($this->route_request_type) {
123
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
124
+				break;
125
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
126
+				$this->route_handler->addRoute(
127
+					'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'
128
+				);
129
+				$this->route_handler->addRoute(
130
+					'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'
131
+				);
132
+				break;
133
+		}
134
+	}
135
+
136
+
137
+	/**
138
+	 *
139
+	 * @throws Exception
140
+	 * @throws Exception
141
+	 * @throws Exception
142
+	 * @throws Exception
143
+	 * @throws Exception
144
+	 * @throws Exception
145
+	 * @throws Exception
146
+	 * @throws Exception
147
+	 * @throws Exception
148
+	 * @throws Exception
149
+	 */
150
+	public function loadControllers()
151
+	{
152
+		do_action(
153
+			'AHEE__EventEspresso_core_services_routing_Router__loadControllers',
154
+			$this->route_handler,
155
+			$this->route_request_type,
156
+			$this->dependency_map
157
+		);
158
+		$this->route_handler->addRoute(
159
+			'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'
160
+		);
161
+		switch ($this->route_request_type) {
162
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
163
+				$this->route_handler->addRoute(
164
+					'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
165
+				);
166
+				break;
167
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
168
+				$this->route_handler->addRoute(
169
+					'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'
170
+				);
171
+				$this->route_handler->addRoute(
172
+					'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'
173
+				);
174
+				$this->route_handler->addRoute(
175
+					'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'
176
+				);
177
+				$this->route_handler->addRoute(
178
+					'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'
179
+				);
180
+				$this->route_handler->addRoute(
181
+					'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'
182
+				);
183
+				$this->route_handler->addRoute(
184
+					'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
185
+				);
186
+				$this->route_handler->addRoute(
187
+					'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'
188
+				);
189
+				break;
190
+		}
191
+	}
192
+
193
+
194
+	/**
195
+	 *
196
+	 * @throws Exception
197
+	 * @throws Exception
198
+	 */
199
+	public function coreLoadedAndReady()
200
+	{
201
+		do_action(
202
+			'AHEE__EventEspresso_core_services_routing_Router__coreLoadedAndReady',
203
+			$this->route_handler,
204
+			$this->route_request_type,
205
+			$this->dependency_map
206
+		);
207
+		switch ($this->route_request_type) {
208
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
209
+				break;
210
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
211
+				$this->route_handler->addRoute(
212
+					'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'
213
+				);
214
+				$this->route_handler->addRoute(
215
+					'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'
216
+				);
217
+				break;
218
+		}
219
+	}
220
+
221
+
222
+	/**
223
+	 *
224
+	 * @throws Exception
225
+	 */
226
+	public function initializeLast()
227
+	{
228
+		do_action(
229
+			'AHEE__EventEspresso_core_services_routing_Router__initializeLast',
230
+			$this->route_handler,
231
+			$this->route_request_type,
232
+			$this->dependency_map
233
+		);
234
+		switch ($this->route_request_type) {
235
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
236
+				break;
237
+			case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
238
+				$this->route_handler->addRoute(
239
+					'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests'
240
+				);
241
+				break;
242
+		}
243
+	}
244 244
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/PueRequests.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -16,72 +16,72 @@
 block discarded – undo
16 16
 class PueRequests extends Route
17 17
 {
18 18
 
19
-    /**
20
-     * returns true if the current request matches this route
21
-     *
22
-     * @return bool
23
-     * @since   $VID:$
24
-     */
25
-    public function matchesCurrentRequest(): bool
26
-    {
27
-        return ($this->request->isAdmin() || $this->request->isAdminAjax())
28
-               && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true);
29
-    }
19
+	/**
20
+	 * returns true if the current request matches this route
21
+	 *
22
+	 * @return bool
23
+	 * @since   $VID:$
24
+	 */
25
+	public function matchesCurrentRequest(): bool
26
+	{
27
+		return ($this->request->isAdmin() || $this->request->isAdminAjax())
28
+			   && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * @since $VID:$
34
-     */
35
-    protected function registerDependencies()
36
-    {
37
-        $this->dependency_map->registerDependencies(
38
-            'EventEspresso\core\services\licensing\LicenseService',
39
-            [
40
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
41
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
42
-            ]
43
-        );
44
-        $this->dependency_map->registerDependencies(
45
-            'EventEspresso\core\domain\services\pue\Stats',
46
-            [
47
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
48
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
49
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
50
-            ]
51
-        );
52
-        $this->dependency_map->registerDependencies(
53
-            'EventEspresso\core\domain\services\pue\Config',
54
-            [
55
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
56
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
57
-            ]
58
-        );
59
-        $this->dependency_map->registerDependencies(
60
-            'EventEspresso\core\domain\services\pue\StatsGatherer',
61
-            [
62
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
63
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
64
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
65
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
66
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
67
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
68
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
69
-            ]
70
-        );
71
-    }
32
+	/**
33
+	 * @since $VID:$
34
+	 */
35
+	protected function registerDependencies()
36
+	{
37
+		$this->dependency_map->registerDependencies(
38
+			'EventEspresso\core\services\licensing\LicenseService',
39
+			[
40
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
41
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
42
+			]
43
+		);
44
+		$this->dependency_map->registerDependencies(
45
+			'EventEspresso\core\domain\services\pue\Stats',
46
+			[
47
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
48
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
49
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
50
+			]
51
+		);
52
+		$this->dependency_map->registerDependencies(
53
+			'EventEspresso\core\domain\services\pue\Config',
54
+			[
55
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
56
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
57
+			]
58
+		);
59
+		$this->dependency_map->registerDependencies(
60
+			'EventEspresso\core\domain\services\pue\StatsGatherer',
61
+			[
62
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
63
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
64
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
65
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
66
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
67
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
68
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
69
+			]
70
+		);
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * implements logic required to run during request
76
-     *
77
-     * @return bool
78
-     * @since   $VID:$
79
-     */
80
-    protected function requestHandler(): bool
81
-    {
82
-        // pew pew pew
83
-        $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
84
-        do_action('AHEE__EE_System__brew_espresso__after_pue_init');
85
-        return true;
86
-    }
74
+	/**
75
+	 * implements logic required to run during request
76
+	 *
77
+	 * @return bool
78
+	 * @since   $VID:$
79
+	 */
80
+	protected function requestHandler(): bool
81
+	{
82
+		// pew pew pew
83
+		$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
84
+		do_action('AHEE__EE_System__brew_espresso__after_pue_init');
85
+		return true;
86
+	}
87 87
 }
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -17,40 +17,40 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @type Psr4Autoloader
22
-     */
23
-    protected static $psr4_loader;
24
-
25
-
26
-    /**
27
-     * @return void
28
-     * @throws EE_Error
29
-     */
30
-    public function initializeAutoloader()
31
-    {
32
-        static $initialized = false;
33
-        if (! $initialized) {
34
-            // instantiate PSR4 autoloader
35
-            espresso_load_required('Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php');
36
-            EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
37
-            // register the autoloader
38
-            EE_Psr4AutoloaderInit::$psr4_loader->register();
39
-            // register the base directories for the namespace prefix
40
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
41
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
42
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
43
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EETests', EE_PLUGIN_DIR_PATH . 'tests');
44
-            $initialized = true;
45
-        }
46
-    }
47
-
48
-
49
-    /**
50
-     * @return Psr4Autoloader
51
-     */
52
-    public static function psr4_loader(): Psr4Autoloader
53
-    {
54
-        return self::$psr4_loader;
55
-    }
20
+	/**
21
+	 * @type Psr4Autoloader
22
+	 */
23
+	protected static $psr4_loader;
24
+
25
+
26
+	/**
27
+	 * @return void
28
+	 * @throws EE_Error
29
+	 */
30
+	public function initializeAutoloader()
31
+	{
32
+		static $initialized = false;
33
+		if (! $initialized) {
34
+			// instantiate PSR4 autoloader
35
+			espresso_load_required('Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php');
36
+			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
37
+			// register the autoloader
38
+			EE_Psr4AutoloaderInit::$psr4_loader->register();
39
+			// register the base directories for the namespace prefix
40
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
41
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
42
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
43
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EETests', EE_PLUGIN_DIR_PATH . 'tests');
44
+			$initialized = true;
45
+		}
46
+	}
47
+
48
+
49
+	/**
50
+	 * @return Psr4Autoloader
51
+	 */
52
+	public static function psr4_loader(): Psr4Autoloader
53
+	{
54
+		return self::$psr4_loader;
55
+	}
56 56
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,17 +30,17 @@
 block discarded – undo
30 30
     public function initializeAutoloader()
31 31
     {
32 32
         static $initialized = false;
33
-        if (! $initialized) {
33
+        if ( ! $initialized) {
34 34
             // instantiate PSR4 autoloader
35
-            espresso_load_required('Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php');
35
+            espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php');
36 36
             EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
37 37
             // register the autoloader
38 38
             EE_Psr4AutoloaderInit::$psr4_loader->register();
39 39
             // register the base directories for the namespace prefix
40 40
             EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
41
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
41
+            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
42 42
             EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
43
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EETests', EE_PLUGIN_DIR_PATH . 'tests');
43
+            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EETests', EE_PLUGIN_DIR_PATH.'tests');
44 44
             $initialized = true;
45 45
         }
46 46
     }
Please login to merge, or discard this patch.
core/EE_Addon.core.php 1 patch
Indentation   +855 added lines, -855 removed lines patch added patch discarded remove patch
@@ -19,806 +19,806 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * prefix to be added onto an addon's plugin slug to make a wp option name
24
-     * which will be used to store the plugin's activation history
25
-     */
26
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
-
28
-    /**
29
-     * @var $_version
30
-     * @type string
31
-     */
32
-    protected $_version = '';
33
-
34
-    /**
35
-     * @var $_min_core_version
36
-     * @type string
37
-     */
38
-    protected $_min_core_version = '';
39
-
40
-    /**
41
-     * derived from plugin 'main_file_path using plugin_basename()
42
-     *
43
-     * @type string $_plugin_basename
44
-     */
45
-    protected $_plugin_basename = '';
46
-
47
-    /**
48
-     * A non-internationalized name to identify this addon for use in URLs, etc
49
-     *
50
-     * @type string $_plugin_slug
51
-     */
52
-    protected $_plugin_slug = '';
53
-
54
-    /**
55
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
-     *
57
-     * @type string _addon_name
58
-     */
59
-    protected $_addon_name = '';
60
-
61
-    /**
62
-     * one of the EE_System::req_type_* constants
63
-     *
64
-     * @type int $_req_type
65
-     */
66
-    protected $_req_type;
67
-
68
-    /**
69
-     * page slug to be used when generating the "Settings" link on the WP plugin page
70
-     *
71
-     * @type string $_plugin_action_slug
72
-     */
73
-    protected $_plugin_action_slug = '';
74
-
75
-    /**
76
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
-     * that can be used for adding upgrading/marketing info
78
-     *
79
-     * @type array $_plugins_page_row
80
-     */
81
-    protected $_plugins_page_row = [];
82
-
83
-
84
-    /**
85
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
-     *
87
-     * @type string
88
-     */
89
-    protected $_main_plugin_file;
90
-
91
-    /**
92
-     *    This is the slug used to identify this add-on within the plugin update engine.
93
-     *
94
-     * @type string
95
-     */
96
-    protected $pue_slug = '';
97
-
98
-
99
-    /**
100
-     * @var EE_Dependency_Map $dependency_map
101
-     */
102
-    private $dependency_map;
103
-
104
-
105
-    /**
106
-     * @var DomainInterface $domain
107
-     */
108
-    private $domain;
109
-
110
-
111
-    /**
112
-     * @param EE_Dependency_Map|null $dependency_map [optional]
113
-     * @param DomainInterface|null   $domain         [optional]
114
-     */
115
-    public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
116
-    {
117
-        if ($dependency_map instanceof EE_Dependency_Map) {
118
-            $this->setDependencyMap($dependency_map);
119
-        }
120
-        if ($domain instanceof DomainInterface) {
121
-            $this->setDomain($domain);
122
-        }
123
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', [$this, 'admin_init']);
124
-    }
125
-
126
-
127
-    /**
128
-     * @param EE_Dependency_Map $dependency_map
129
-     */
130
-    public function setDependencyMap($dependency_map)
131
-    {
132
-        $this->dependency_map = $dependency_map;
133
-    }
134
-
135
-
136
-    /**
137
-     * @return EE_Dependency_Map
138
-     */
139
-    public function dependencyMap(): ?EE_Dependency_Map
140
-    {
141
-        return $this->dependency_map;
142
-    }
143
-
144
-
145
-    /**
146
-     * @param DomainInterface $domain
147
-     */
148
-    public function setDomain(DomainInterface $domain)
149
-    {
150
-        $this->domain = $domain;
151
-    }
152
-
153
-
154
-    /**
155
-     * @return DomainInterface
156
-     */
157
-    public function domain(): ?DomainInterface
158
-    {
159
-        return $this->domain;
160
-    }
161
-
162
-
163
-    /**
164
-     * @param string $version
165
-     */
166
-    public function set_version(string $version = '')
167
-    {
168
-        $this->_version = $version;
169
-    }
170
-
171
-
172
-    /**
173
-     * get__version
174
-     *
175
-     * @return string
176
-     */
177
-    public function version(): string
178
-    {
179
-        return $this->_version;
180
-    }
181
-
182
-
183
-    /**
184
-     * @param mixed $min_core_version
185
-     */
186
-    public function set_min_core_version($min_core_version = null)
187
-    {
188
-        $this->_min_core_version = $min_core_version;
189
-    }
190
-
191
-
192
-    /**
193
-     * get__min_core_version
194
-     *
195
-     * @return string
196
-     */
197
-    public function min_core_version(): string
198
-    {
199
-        return $this->_min_core_version;
200
-    }
201
-
202
-
203
-    /**
204
-     * Sets addon_name
205
-     *
206
-     * @param string $addon_name
207
-     */
208
-    public function set_name(string $addon_name)
209
-    {
210
-        $this->_addon_name = $addon_name;
211
-    }
212
-
213
-
214
-    /**
215
-     * Gets addon_name
216
-     *
217
-     * @return string
218
-     */
219
-    public function name(): string
220
-    {
221
-        return $this->_addon_name;
222
-    }
223
-
224
-
225
-    /**
226
-     * @return string
227
-     */
228
-    public function plugin_basename(): string
229
-    {
230
-
231
-        return $this->_plugin_basename;
232
-    }
233
-
234
-
235
-    /**
236
-     * @param string $plugin_basename
237
-     */
238
-    public function set_plugin_basename(string $plugin_basename)
239
-    {
240
-
241
-        $this->_plugin_basename = $plugin_basename;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return string
247
-     */
248
-    public function plugin_slug(): string
249
-    {
250
-
251
-        return $this->_plugin_slug;
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $plugin_slug
257
-     */
258
-    public function set_plugin_slug(string $plugin_slug)
259
-    {
260
-
261
-        $this->_plugin_slug = $plugin_slug;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function plugin_action_slug(): string
269
-    {
270
-
271
-        return $this->_plugin_action_slug;
272
-    }
273
-
274
-
275
-    /**
276
-     * @param string $plugin_action_slug
277
-     */
278
-    public function set_plugin_action_slug(string $plugin_action_slug)
279
-    {
280
-
281
-        $this->_plugin_action_slug = $plugin_action_slug;
282
-    }
283
-
284
-
285
-    /**
286
-     * @return array
287
-     */
288
-    public function get_plugins_page_row(): array
289
-    {
290
-
291
-        return $this->_plugins_page_row;
292
-    }
293
-
294
-
295
-    /**
296
-     * @param array|string $plugins_page_row
297
-     */
298
-    public function set_plugins_page_row(array $plugins_page_row = [])
299
-    {
300
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
301
-        if (! is_array($plugins_page_row)
302
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
303
-        ) {
304
-            $plugins_page_row = [];
305
-        }
306
-        $this->_plugins_page_row = (array) $plugins_page_row;
307
-    }
308
-
309
-
310
-    /**
311
-     * Called when EE core detects this addon has been activated for the first time.
312
-     * If the site isn't in maintenance mode, should setup the addon's database
313
-     *
314
-     * @return void
315
-     */
316
-    public function new_install()
317
-    {
318
-        $classname = get_class($this);
319
-        do_action("AHEE__{$classname}__new_install");
320
-        do_action('AHEE__EE_Addon__new_install', $this);
321
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
322
-        add_action(
323
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
324
-            [$this, 'initialize_db_if_no_migrations_required']
325
-        );
326
-    }
327
-
328
-
329
-    /**
330
-     * Called when EE core detects this addon has been reactivated. When this happens,
331
-     * it's good to just check that your data is still intact
332
-     *
333
-     * @return void
334
-     */
335
-    public function reactivation()
336
-    {
337
-        $classname = get_class($this);
338
-        do_action("AHEE__{$classname}__reactivation");
339
-        do_action('AHEE__EE_Addon__reactivation', $this);
340
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
341
-        add_action(
342
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
-            [$this, 'initialize_db_if_no_migrations_required']
344
-        );
345
-    }
346
-
347
-
348
-    /**
349
-     * Called when the registered deactivation hook for this addon fires.
350
-     *
351
-     * @throws EE_Error
352
-     */
353
-    public function deactivation()
354
-    {
355
-        $classname = get_class($this);
356
-        do_action("AHEE__{$classname}__deactivation");
357
-        do_action('AHEE__EE_Addon__deactivation', $this);
358
-        // check if the site no longer needs to be in maintenance mode
359
-        EE_Register_Addon::deregister($this->name());
360
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
361
-    }
362
-
363
-
364
-    /**
365
-     * Takes care of double-checking that we're not in maintenance mode, and then
366
-     * initializing this addon's necessary initial data. This is called by default on new activations
367
-     * and reactivations.
368
-     *
369
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
370
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
371
-     * @return void
372
-     * @throws EE_Error
373
-     * @throws InvalidInterfaceException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidArgumentException
376
-     * @throws ReflectionException
377
-     */
378
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
379
-    {
380
-        if ($verify_schema === '') {
381
-            // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
382
-            // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
383
-            // calls them with an argument of an empty string (ie ""), which evaluates to false
384
-            // so we need to treat the empty string as if nothing had been passed, and should instead use the default
385
-            $verify_schema = true;
386
-        }
387
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
388
-            if ($verify_schema) {
389
-                $this->initialize_db();
390
-            }
391
-            $this->initialize_default_data();
392
-            // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
393
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
394
-                [
395
-                    'slug'    => $this->name(),
396
-                    'version' => $this->version(),
397
-                ]
398
-            );
399
-            /* make sure core's data is a-ok
22
+	/**
23
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
24
+	 * which will be used to store the plugin's activation history
25
+	 */
26
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
+
28
+	/**
29
+	 * @var $_version
30
+	 * @type string
31
+	 */
32
+	protected $_version = '';
33
+
34
+	/**
35
+	 * @var $_min_core_version
36
+	 * @type string
37
+	 */
38
+	protected $_min_core_version = '';
39
+
40
+	/**
41
+	 * derived from plugin 'main_file_path using plugin_basename()
42
+	 *
43
+	 * @type string $_plugin_basename
44
+	 */
45
+	protected $_plugin_basename = '';
46
+
47
+	/**
48
+	 * A non-internationalized name to identify this addon for use in URLs, etc
49
+	 *
50
+	 * @type string $_plugin_slug
51
+	 */
52
+	protected $_plugin_slug = '';
53
+
54
+	/**
55
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
+	 *
57
+	 * @type string _addon_name
58
+	 */
59
+	protected $_addon_name = '';
60
+
61
+	/**
62
+	 * one of the EE_System::req_type_* constants
63
+	 *
64
+	 * @type int $_req_type
65
+	 */
66
+	protected $_req_type;
67
+
68
+	/**
69
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
70
+	 *
71
+	 * @type string $_plugin_action_slug
72
+	 */
73
+	protected $_plugin_action_slug = '';
74
+
75
+	/**
76
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
+	 * that can be used for adding upgrading/marketing info
78
+	 *
79
+	 * @type array $_plugins_page_row
80
+	 */
81
+	protected $_plugins_page_row = [];
82
+
83
+
84
+	/**
85
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
+	 *
87
+	 * @type string
88
+	 */
89
+	protected $_main_plugin_file;
90
+
91
+	/**
92
+	 *    This is the slug used to identify this add-on within the plugin update engine.
93
+	 *
94
+	 * @type string
95
+	 */
96
+	protected $pue_slug = '';
97
+
98
+
99
+	/**
100
+	 * @var EE_Dependency_Map $dependency_map
101
+	 */
102
+	private $dependency_map;
103
+
104
+
105
+	/**
106
+	 * @var DomainInterface $domain
107
+	 */
108
+	private $domain;
109
+
110
+
111
+	/**
112
+	 * @param EE_Dependency_Map|null $dependency_map [optional]
113
+	 * @param DomainInterface|null   $domain         [optional]
114
+	 */
115
+	public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
116
+	{
117
+		if ($dependency_map instanceof EE_Dependency_Map) {
118
+			$this->setDependencyMap($dependency_map);
119
+		}
120
+		if ($domain instanceof DomainInterface) {
121
+			$this->setDomain($domain);
122
+		}
123
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', [$this, 'admin_init']);
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param EE_Dependency_Map $dependency_map
129
+	 */
130
+	public function setDependencyMap($dependency_map)
131
+	{
132
+		$this->dependency_map = $dependency_map;
133
+	}
134
+
135
+
136
+	/**
137
+	 * @return EE_Dependency_Map
138
+	 */
139
+	public function dependencyMap(): ?EE_Dependency_Map
140
+	{
141
+		return $this->dependency_map;
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param DomainInterface $domain
147
+	 */
148
+	public function setDomain(DomainInterface $domain)
149
+	{
150
+		$this->domain = $domain;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return DomainInterface
156
+	 */
157
+	public function domain(): ?DomainInterface
158
+	{
159
+		return $this->domain;
160
+	}
161
+
162
+
163
+	/**
164
+	 * @param string $version
165
+	 */
166
+	public function set_version(string $version = '')
167
+	{
168
+		$this->_version = $version;
169
+	}
170
+
171
+
172
+	/**
173
+	 * get__version
174
+	 *
175
+	 * @return string
176
+	 */
177
+	public function version(): string
178
+	{
179
+		return $this->_version;
180
+	}
181
+
182
+
183
+	/**
184
+	 * @param mixed $min_core_version
185
+	 */
186
+	public function set_min_core_version($min_core_version = null)
187
+	{
188
+		$this->_min_core_version = $min_core_version;
189
+	}
190
+
191
+
192
+	/**
193
+	 * get__min_core_version
194
+	 *
195
+	 * @return string
196
+	 */
197
+	public function min_core_version(): string
198
+	{
199
+		return $this->_min_core_version;
200
+	}
201
+
202
+
203
+	/**
204
+	 * Sets addon_name
205
+	 *
206
+	 * @param string $addon_name
207
+	 */
208
+	public function set_name(string $addon_name)
209
+	{
210
+		$this->_addon_name = $addon_name;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Gets addon_name
216
+	 *
217
+	 * @return string
218
+	 */
219
+	public function name(): string
220
+	{
221
+		return $this->_addon_name;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return string
227
+	 */
228
+	public function plugin_basename(): string
229
+	{
230
+
231
+		return $this->_plugin_basename;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @param string $plugin_basename
237
+	 */
238
+	public function set_plugin_basename(string $plugin_basename)
239
+	{
240
+
241
+		$this->_plugin_basename = $plugin_basename;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return string
247
+	 */
248
+	public function plugin_slug(): string
249
+	{
250
+
251
+		return $this->_plugin_slug;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $plugin_slug
257
+	 */
258
+	public function set_plugin_slug(string $plugin_slug)
259
+	{
260
+
261
+		$this->_plugin_slug = $plugin_slug;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function plugin_action_slug(): string
269
+	{
270
+
271
+		return $this->_plugin_action_slug;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @param string $plugin_action_slug
277
+	 */
278
+	public function set_plugin_action_slug(string $plugin_action_slug)
279
+	{
280
+
281
+		$this->_plugin_action_slug = $plugin_action_slug;
282
+	}
283
+
284
+
285
+	/**
286
+	 * @return array
287
+	 */
288
+	public function get_plugins_page_row(): array
289
+	{
290
+
291
+		return $this->_plugins_page_row;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param array|string $plugins_page_row
297
+	 */
298
+	public function set_plugins_page_row(array $plugins_page_row = [])
299
+	{
300
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
301
+		if (! is_array($plugins_page_row)
302
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
303
+		) {
304
+			$plugins_page_row = [];
305
+		}
306
+		$this->_plugins_page_row = (array) $plugins_page_row;
307
+	}
308
+
309
+
310
+	/**
311
+	 * Called when EE core detects this addon has been activated for the first time.
312
+	 * If the site isn't in maintenance mode, should setup the addon's database
313
+	 *
314
+	 * @return void
315
+	 */
316
+	public function new_install()
317
+	{
318
+		$classname = get_class($this);
319
+		do_action("AHEE__{$classname}__new_install");
320
+		do_action('AHEE__EE_Addon__new_install', $this);
321
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
322
+		add_action(
323
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
324
+			[$this, 'initialize_db_if_no_migrations_required']
325
+		);
326
+	}
327
+
328
+
329
+	/**
330
+	 * Called when EE core detects this addon has been reactivated. When this happens,
331
+	 * it's good to just check that your data is still intact
332
+	 *
333
+	 * @return void
334
+	 */
335
+	public function reactivation()
336
+	{
337
+		$classname = get_class($this);
338
+		do_action("AHEE__{$classname}__reactivation");
339
+		do_action('AHEE__EE_Addon__reactivation', $this);
340
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
341
+		add_action(
342
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
+			[$this, 'initialize_db_if_no_migrations_required']
344
+		);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Called when the registered deactivation hook for this addon fires.
350
+	 *
351
+	 * @throws EE_Error
352
+	 */
353
+	public function deactivation()
354
+	{
355
+		$classname = get_class($this);
356
+		do_action("AHEE__{$classname}__deactivation");
357
+		do_action('AHEE__EE_Addon__deactivation', $this);
358
+		// check if the site no longer needs to be in maintenance mode
359
+		EE_Register_Addon::deregister($this->name());
360
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
361
+	}
362
+
363
+
364
+	/**
365
+	 * Takes care of double-checking that we're not in maintenance mode, and then
366
+	 * initializing this addon's necessary initial data. This is called by default on new activations
367
+	 * and reactivations.
368
+	 *
369
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
370
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
371
+	 * @return void
372
+	 * @throws EE_Error
373
+	 * @throws InvalidInterfaceException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidArgumentException
376
+	 * @throws ReflectionException
377
+	 */
378
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
379
+	{
380
+		if ($verify_schema === '') {
381
+			// wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
382
+			// (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
383
+			// calls them with an argument of an empty string (ie ""), which evaluates to false
384
+			// so we need to treat the empty string as if nothing had been passed, and should instead use the default
385
+			$verify_schema = true;
386
+		}
387
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
388
+			if ($verify_schema) {
389
+				$this->initialize_db();
390
+			}
391
+			$this->initialize_default_data();
392
+			// @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
393
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
394
+				[
395
+					'slug'    => $this->name(),
396
+					'version' => $this->version(),
397
+				]
398
+			);
399
+			/* make sure core's data is a-ok
400 400
              * (at the time of writing, we especially want to verify all the caps are present
401 401
              * because payment method type capabilities are added dynamically, and it's
402 402
              * possible this addon added a payment method. But it's also possible
403 403
              * other data needs to be verified)
404 404
              */
405
-            EEH_Activation::initialize_db_content();
406
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
407
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
408
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
409
-            );
410
-            $rewrite_rules->flushRewriteRules();
411
-            // in case there are lots of addons being activated at once, let's force garbage collection
412
-            // to help avoid memory limit errors
413
-            // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
414
-            gc_collect_cycles();
415
-        } else {
416
-            // ask the data migration manager to init this addon's data
417
-            // when migrations are finished because we can't do it now
418
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
419
-        }
420
-    }
421
-
422
-
423
-    /**
424
-     * Used to setup this addon's database tables, but not necessarily any default
425
-     * data in them. The default is to actually use the most up-to-date data migration script
426
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
427
-     * methods to setup the db.
428
-     *
429
-     * @throws EE_Error
430
-     * @throws ReflectionException
431
-     */
432
-    public function initialize_db()
433
-    {
434
-        // find the migration script that sets the database to be compatible with the code
435
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
436
-        if ($current_dms_name) {
437
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
438
-            $current_data_migration_script->set_migrating(false);
439
-            $current_data_migration_script->schema_changes_before_migration();
440
-            $current_data_migration_script->schema_changes_after_migration();
441
-            if ($current_data_migration_script->get_errors()) {
442
-                foreach ($current_data_migration_script->get_errors() as $error) {
443
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
444
-                }
445
-            }
446
-        }
447
-        // if not DMS was found that should be ok. This addon just doesn't require any database changes
448
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
449
-            [
450
-                'slug'    => $this->name(),
451
-                'version' => $this->version(),
452
-            ]
453
-        );
454
-    }
455
-
456
-
457
-    /**
458
-     * If you want to setup default data for the addon, override this method, and call
459
-     * parent::initialize_default_data() from within it. This is normally called
460
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
461
-     * and should verify default data is present (but this is also called
462
-     * on reactivations and just after migrations, so please verify you actually want
463
-     * to ADD default data, because it may already be present).
464
-     * However, please call this parent (currently it just fires a hook which other
465
-     * addons may be depending on)
466
-     */
467
-    public function initialize_default_data()
468
-    {
469
-        /**
470
-         * Called when an addon is ensuring its default data is set (possibly called
471
-         * on a reactivation, so first check for the absence of other data before setting
472
-         * default data)
473
-         *
474
-         * @param EE_Addon $addon the addon that called this
475
-         */
476
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
477
-        // override to insert default data. It is safe to use the models here
478
-        // because the site should not be in maintenance mode
479
-    }
480
-
481
-
482
-    /**
483
-     * EE Core detected that this addon has been upgraded. We should check if there
484
-     * are any new migration scripts, and if so put the site into maintenance mode until
485
-     * they're ran
486
-     *
487
-     * @return void
488
-     */
489
-    public function upgrade()
490
-    {
491
-        $classname = get_class($this);
492
-        do_action("AHEE__{$classname}__upgrade");
493
-        do_action('AHEE__EE_Addon__upgrade', $this);
494
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
495
-        // also it's possible there is new default data that needs to be added
496
-        add_action(
497
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
498
-            [$this, 'initialize_db_if_no_migrations_required']
499
-        );
500
-    }
501
-
502
-
503
-    /**
504
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
505
-     */
506
-    public function downgrade()
507
-    {
508
-        $classname = get_class($this);
509
-        do_action("AHEE__{$classname}__downgrade");
510
-        do_action('AHEE__EE_Addon__downgrade', $this);
511
-        // it's possible there's old default data that needs to be double-checked
512
-        add_action(
513
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
514
-            [$this, 'initialize_db_if_no_migrations_required']
515
-        );
516
-    }
517
-
518
-
519
-    /**
520
-     * set_db_update_option_name
521
-     * Until we do something better, we'll just check for migration scripts upon
522
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
523
-     *
524
-     * @return bool
525
-     */
526
-    public function set_db_update_option_name(): bool
527
-    {
528
-        EE_Error::doing_it_wrong(
529
-            __FUNCTION__,
530
-            esc_html__(
531
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
532
-                'event_espresso'
533
-            ),
534
-            '4.3.0.alpha.016'
535
-        );
536
-        // let's just handle this on the next request, ok? right now we're just not really ready
537
-        return $this->set_activation_indicator_option();
538
-    }
539
-
540
-
541
-    /**
542
-     * Returns the name of the activation indicator option
543
-     * (an option which is set temporarily to indicate that this addon was just activated)
544
-     *
545
-     * @return string
546
-     * @deprecated since version 4.3.0.alpha.016
547
-     */
548
-    public function get_db_update_option_name(): string
549
-    {
550
-        EE_Error::doing_it_wrong(
551
-            __FUNCTION__,
552
-            esc_html__(
553
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
554
-                'event_espresso'
555
-            ),
556
-            '4.3.0.alpha.016'
557
-        );
558
-        return $this->get_activation_indicator_option_name();
559
-    }
560
-
561
-
562
-    /**
563
-     * When the addon is activated, this should be called to set a wordpress option that
564
-     * indicates it was activated. This is especially useful for detecting reactivations.
565
-     *
566
-     * @return bool
567
-     */
568
-    public function set_activation_indicator_option(): bool
569
-    {
570
-        // let's just handle this on the next request, ok? right now we're just not really ready
571
-        return update_option($this->get_activation_indicator_option_name(), true);
572
-    }
573
-
574
-
575
-    /**
576
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
577
-     *
578
-     * @return string
579
-     */
580
-    public function get_activation_indicator_option_name(): string
581
-    {
582
-        return 'ee_activation_' . $this->name();
583
-    }
584
-
585
-
586
-    /**
587
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
588
-     *
589
-     * @param int $req_type
590
-     */
591
-    public function set_req_type(int $req_type)
592
-    {
593
-        $this->_req_type = $req_type;
594
-    }
595
-
596
-
597
-    /**
598
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
599
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
600
-     * EE_System when it is checking for new install or upgrades of addons
601
-     */
602
-    public function detect_req_type(): int
603
-    {
604
-        if (! $this->_req_type) {
605
-            $this->detect_activation_or_upgrade();
606
-        }
607
-        return $this->_req_type;
608
-    }
609
-
610
-
611
-    /**
612
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
613
-     * Should only be called once per request
614
-     *
615
-     * @return void
616
-     */
617
-    public function detect_activation_or_upgrade()
618
-    {
619
-        $activation_history_for_addon = $this->get_activation_history();
620
-        $request_type                 = EE_System::detect_req_type_given_activation_history(
621
-            $activation_history_for_addon,
622
-            $this->get_activation_indicator_option_name(),
623
-            $this->version()
624
-        );
625
-        $this->set_req_type($request_type);
626
-        $classname = get_class($this);
627
-        switch ($request_type) {
628
-            case EE_System::req_type_new_activation:
629
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
630
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
631
-                $this->new_install();
632
-                $this->update_list_of_installed_versions($activation_history_for_addon);
633
-                break;
634
-            case EE_System::req_type_reactivation:
635
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
636
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
637
-                $this->reactivation();
638
-                $this->update_list_of_installed_versions($activation_history_for_addon);
639
-                break;
640
-            case EE_System::req_type_upgrade:
641
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
642
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
643
-                $this->upgrade();
644
-                $this->update_list_of_installed_versions($activation_history_for_addon);
645
-                break;
646
-            case EE_System::req_type_downgrade:
647
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
648
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
649
-                $this->downgrade();
650
-                $this->update_list_of_installed_versions($activation_history_for_addon);
651
-                break;
652
-            case EE_System::req_type_normal:
653
-            default:
654
-                break;
655
-        }
656
-
657
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
658
-    }
659
-
660
-
661
-    /**
662
-     * Updates the version history for this addon
663
-     *
664
-     * @param array  $version_history
665
-     * @param string $current_version_to_add
666
-     * @return boolean success
667
-     */
668
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
669
-    {
670
-        if (! $version_history) {
671
-            $version_history = $this->get_activation_history();
672
-        }
673
-        if ($current_version_to_add === null) {
674
-            $current_version_to_add = $this->version();
675
-        }
676
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
677
-        return update_option($this->get_activation_history_option_name(), $version_history);
678
-    }
679
-
680
-
681
-    /**
682
-     * Gets the name of the wp option that stores the activation history
683
-     * of this addon
684
-     *
685
-     * @return string
686
-     */
687
-    public function get_activation_history_option_name(): string
688
-    {
689
-        return self::ee_addon_version_history_option_prefix . $this->name();
690
-    }
691
-
692
-
693
-    /**
694
-     * Gets the wp option which stores the activation history for this addon
695
-     *
696
-     * @return array
697
-     */
698
-    public function get_activation_history(): array
699
-    {
700
-        return get_option($this->get_activation_history_option_name(), []);
701
-    }
702
-
703
-
704
-    /**
705
-     * @param string $config_section
706
-     */
707
-    public function set_config_section($config_section = '')
708
-    {
709
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
710
-    }
711
-
712
-
713
-    /**
714
-     * Sets the filepath to the main plugin file
715
-     *
716
-     * @param string $filepath
717
-     */
718
-    public function set_main_plugin_file(string $filepath)
719
-    {
720
-        $this->_main_plugin_file = $filepath;
721
-    }
722
-
723
-
724
-    /**
725
-     * gets the filepath to teh main file
726
-     *
727
-     * @return string
728
-     */
729
-    public function get_main_plugin_file(): string
730
-    {
731
-        return $this->_main_plugin_file;
732
-    }
733
-
734
-
735
-    /**
736
-     * Gets the filename (no path) of the main file (the main file loaded
737
-     * by WP)
738
-     *
739
-     * @return string
740
-     */
741
-    public function get_main_plugin_file_basename(): string
742
-    {
743
-        return plugin_basename($this->get_main_plugin_file());
744
-    }
745
-
746
-
747
-    /**
748
-     * Gets the folder name which contains the main plugin file
749
-     *
750
-     * @return string
751
-     */
752
-    public function get_main_plugin_file_dirname(): string
753
-    {
754
-        return dirname($this->get_main_plugin_file());
755
-    }
756
-
757
-
758
-    /**
759
-     * sets hooks used in the admin
760
-     *
761
-     * @return void
762
-     */
763
-    public function admin_init()
764
-    {
765
-        // is admin and not in M-Mode ?
766
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
767
-            add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2);
768
-            add_filter('after_plugin_row_' . $this->_plugin_basename, [$this, 'after_plugin_row'], 10, 3);
769
-        }
770
-    }
771
-
772
-
773
-    /**
774
-     * plugin_actions
775
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
776
-     *
777
-     * @param array  $links
778
-     * @param string $file
779
-     * @return array
780
-     */
781
-    public function plugin_action_links(array $links, string $file): array
782
-    {
783
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
784
-            // before other links
785
-            array_unshift(
786
-                $links,
787
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
788
-                . esc_html__('Settings', 'event_espresso')
789
-                . '</a>'
790
-            );
791
-        }
792
-        return $links;
793
-    }
794
-
795
-
796
-    /**
797
-     * after_plugin_row
798
-     * Add additional content to the plugins page plugin row
799
-     * Inserts another row
800
-     *
801
-     * @param string $plugin_file
802
-     * @param array  $plugin_data
803
-     * @param string $status
804
-     * @return void
805
-     */
806
-    public function after_plugin_row(string $plugin_file, array $plugin_data, string $status)
807
-    {
808
-        $after_plugin_row = '';
809
-        $plugins_page_row = $this->get_plugins_page_row();
810
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
811
-            $class       = $status ? 'active' : 'inactive';
812
-            $link_text   = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
813
-            $link_url    = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
814
-            $description = isset($plugins_page_row['description'])
815
-                ? $plugins_page_row['description']
816
-                : '';
817
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
818
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
819
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
820
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
821
-                $after_plugin_row .= '<style>
405
+			EEH_Activation::initialize_db_content();
406
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
407
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
408
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
409
+			);
410
+			$rewrite_rules->flushRewriteRules();
411
+			// in case there are lots of addons being activated at once, let's force garbage collection
412
+			// to help avoid memory limit errors
413
+			// EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
414
+			gc_collect_cycles();
415
+		} else {
416
+			// ask the data migration manager to init this addon's data
417
+			// when migrations are finished because we can't do it now
418
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
419
+		}
420
+	}
421
+
422
+
423
+	/**
424
+	 * Used to setup this addon's database tables, but not necessarily any default
425
+	 * data in them. The default is to actually use the most up-to-date data migration script
426
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
427
+	 * methods to setup the db.
428
+	 *
429
+	 * @throws EE_Error
430
+	 * @throws ReflectionException
431
+	 */
432
+	public function initialize_db()
433
+	{
434
+		// find the migration script that sets the database to be compatible with the code
435
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
436
+		if ($current_dms_name) {
437
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
438
+			$current_data_migration_script->set_migrating(false);
439
+			$current_data_migration_script->schema_changes_before_migration();
440
+			$current_data_migration_script->schema_changes_after_migration();
441
+			if ($current_data_migration_script->get_errors()) {
442
+				foreach ($current_data_migration_script->get_errors() as $error) {
443
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
444
+				}
445
+			}
446
+		}
447
+		// if not DMS was found that should be ok. This addon just doesn't require any database changes
448
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
449
+			[
450
+				'slug'    => $this->name(),
451
+				'version' => $this->version(),
452
+			]
453
+		);
454
+	}
455
+
456
+
457
+	/**
458
+	 * If you want to setup default data for the addon, override this method, and call
459
+	 * parent::initialize_default_data() from within it. This is normally called
460
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
461
+	 * and should verify default data is present (but this is also called
462
+	 * on reactivations and just after migrations, so please verify you actually want
463
+	 * to ADD default data, because it may already be present).
464
+	 * However, please call this parent (currently it just fires a hook which other
465
+	 * addons may be depending on)
466
+	 */
467
+	public function initialize_default_data()
468
+	{
469
+		/**
470
+		 * Called when an addon is ensuring its default data is set (possibly called
471
+		 * on a reactivation, so first check for the absence of other data before setting
472
+		 * default data)
473
+		 *
474
+		 * @param EE_Addon $addon the addon that called this
475
+		 */
476
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
477
+		// override to insert default data. It is safe to use the models here
478
+		// because the site should not be in maintenance mode
479
+	}
480
+
481
+
482
+	/**
483
+	 * EE Core detected that this addon has been upgraded. We should check if there
484
+	 * are any new migration scripts, and if so put the site into maintenance mode until
485
+	 * they're ran
486
+	 *
487
+	 * @return void
488
+	 */
489
+	public function upgrade()
490
+	{
491
+		$classname = get_class($this);
492
+		do_action("AHEE__{$classname}__upgrade");
493
+		do_action('AHEE__EE_Addon__upgrade', $this);
494
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
495
+		// also it's possible there is new default data that needs to be added
496
+		add_action(
497
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
498
+			[$this, 'initialize_db_if_no_migrations_required']
499
+		);
500
+	}
501
+
502
+
503
+	/**
504
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
505
+	 */
506
+	public function downgrade()
507
+	{
508
+		$classname = get_class($this);
509
+		do_action("AHEE__{$classname}__downgrade");
510
+		do_action('AHEE__EE_Addon__downgrade', $this);
511
+		// it's possible there's old default data that needs to be double-checked
512
+		add_action(
513
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
514
+			[$this, 'initialize_db_if_no_migrations_required']
515
+		);
516
+	}
517
+
518
+
519
+	/**
520
+	 * set_db_update_option_name
521
+	 * Until we do something better, we'll just check for migration scripts upon
522
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
523
+	 *
524
+	 * @return bool
525
+	 */
526
+	public function set_db_update_option_name(): bool
527
+	{
528
+		EE_Error::doing_it_wrong(
529
+			__FUNCTION__,
530
+			esc_html__(
531
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
532
+				'event_espresso'
533
+			),
534
+			'4.3.0.alpha.016'
535
+		);
536
+		// let's just handle this on the next request, ok? right now we're just not really ready
537
+		return $this->set_activation_indicator_option();
538
+	}
539
+
540
+
541
+	/**
542
+	 * Returns the name of the activation indicator option
543
+	 * (an option which is set temporarily to indicate that this addon was just activated)
544
+	 *
545
+	 * @return string
546
+	 * @deprecated since version 4.3.0.alpha.016
547
+	 */
548
+	public function get_db_update_option_name(): string
549
+	{
550
+		EE_Error::doing_it_wrong(
551
+			__FUNCTION__,
552
+			esc_html__(
553
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
554
+				'event_espresso'
555
+			),
556
+			'4.3.0.alpha.016'
557
+		);
558
+		return $this->get_activation_indicator_option_name();
559
+	}
560
+
561
+
562
+	/**
563
+	 * When the addon is activated, this should be called to set a wordpress option that
564
+	 * indicates it was activated. This is especially useful for detecting reactivations.
565
+	 *
566
+	 * @return bool
567
+	 */
568
+	public function set_activation_indicator_option(): bool
569
+	{
570
+		// let's just handle this on the next request, ok? right now we're just not really ready
571
+		return update_option($this->get_activation_indicator_option_name(), true);
572
+	}
573
+
574
+
575
+	/**
576
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
577
+	 *
578
+	 * @return string
579
+	 */
580
+	public function get_activation_indicator_option_name(): string
581
+	{
582
+		return 'ee_activation_' . $this->name();
583
+	}
584
+
585
+
586
+	/**
587
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
588
+	 *
589
+	 * @param int $req_type
590
+	 */
591
+	public function set_req_type(int $req_type)
592
+	{
593
+		$this->_req_type = $req_type;
594
+	}
595
+
596
+
597
+	/**
598
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
599
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
600
+	 * EE_System when it is checking for new install or upgrades of addons
601
+	 */
602
+	public function detect_req_type(): int
603
+	{
604
+		if (! $this->_req_type) {
605
+			$this->detect_activation_or_upgrade();
606
+		}
607
+		return $this->_req_type;
608
+	}
609
+
610
+
611
+	/**
612
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
613
+	 * Should only be called once per request
614
+	 *
615
+	 * @return void
616
+	 */
617
+	public function detect_activation_or_upgrade()
618
+	{
619
+		$activation_history_for_addon = $this->get_activation_history();
620
+		$request_type                 = EE_System::detect_req_type_given_activation_history(
621
+			$activation_history_for_addon,
622
+			$this->get_activation_indicator_option_name(),
623
+			$this->version()
624
+		);
625
+		$this->set_req_type($request_type);
626
+		$classname = get_class($this);
627
+		switch ($request_type) {
628
+			case EE_System::req_type_new_activation:
629
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
630
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
631
+				$this->new_install();
632
+				$this->update_list_of_installed_versions($activation_history_for_addon);
633
+				break;
634
+			case EE_System::req_type_reactivation:
635
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
636
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
637
+				$this->reactivation();
638
+				$this->update_list_of_installed_versions($activation_history_for_addon);
639
+				break;
640
+			case EE_System::req_type_upgrade:
641
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
642
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
643
+				$this->upgrade();
644
+				$this->update_list_of_installed_versions($activation_history_for_addon);
645
+				break;
646
+			case EE_System::req_type_downgrade:
647
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
648
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
649
+				$this->downgrade();
650
+				$this->update_list_of_installed_versions($activation_history_for_addon);
651
+				break;
652
+			case EE_System::req_type_normal:
653
+			default:
654
+				break;
655
+		}
656
+
657
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
658
+	}
659
+
660
+
661
+	/**
662
+	 * Updates the version history for this addon
663
+	 *
664
+	 * @param array  $version_history
665
+	 * @param string $current_version_to_add
666
+	 * @return boolean success
667
+	 */
668
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
669
+	{
670
+		if (! $version_history) {
671
+			$version_history = $this->get_activation_history();
672
+		}
673
+		if ($current_version_to_add === null) {
674
+			$current_version_to_add = $this->version();
675
+		}
676
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
677
+		return update_option($this->get_activation_history_option_name(), $version_history);
678
+	}
679
+
680
+
681
+	/**
682
+	 * Gets the name of the wp option that stores the activation history
683
+	 * of this addon
684
+	 *
685
+	 * @return string
686
+	 */
687
+	public function get_activation_history_option_name(): string
688
+	{
689
+		return self::ee_addon_version_history_option_prefix . $this->name();
690
+	}
691
+
692
+
693
+	/**
694
+	 * Gets the wp option which stores the activation history for this addon
695
+	 *
696
+	 * @return array
697
+	 */
698
+	public function get_activation_history(): array
699
+	{
700
+		return get_option($this->get_activation_history_option_name(), []);
701
+	}
702
+
703
+
704
+	/**
705
+	 * @param string $config_section
706
+	 */
707
+	public function set_config_section($config_section = '')
708
+	{
709
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
710
+	}
711
+
712
+
713
+	/**
714
+	 * Sets the filepath to the main plugin file
715
+	 *
716
+	 * @param string $filepath
717
+	 */
718
+	public function set_main_plugin_file(string $filepath)
719
+	{
720
+		$this->_main_plugin_file = $filepath;
721
+	}
722
+
723
+
724
+	/**
725
+	 * gets the filepath to teh main file
726
+	 *
727
+	 * @return string
728
+	 */
729
+	public function get_main_plugin_file(): string
730
+	{
731
+		return $this->_main_plugin_file;
732
+	}
733
+
734
+
735
+	/**
736
+	 * Gets the filename (no path) of the main file (the main file loaded
737
+	 * by WP)
738
+	 *
739
+	 * @return string
740
+	 */
741
+	public function get_main_plugin_file_basename(): string
742
+	{
743
+		return plugin_basename($this->get_main_plugin_file());
744
+	}
745
+
746
+
747
+	/**
748
+	 * Gets the folder name which contains the main plugin file
749
+	 *
750
+	 * @return string
751
+	 */
752
+	public function get_main_plugin_file_dirname(): string
753
+	{
754
+		return dirname($this->get_main_plugin_file());
755
+	}
756
+
757
+
758
+	/**
759
+	 * sets hooks used in the admin
760
+	 *
761
+	 * @return void
762
+	 */
763
+	public function admin_init()
764
+	{
765
+		// is admin and not in M-Mode ?
766
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
767
+			add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2);
768
+			add_filter('after_plugin_row_' . $this->_plugin_basename, [$this, 'after_plugin_row'], 10, 3);
769
+		}
770
+	}
771
+
772
+
773
+	/**
774
+	 * plugin_actions
775
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
776
+	 *
777
+	 * @param array  $links
778
+	 * @param string $file
779
+	 * @return array
780
+	 */
781
+	public function plugin_action_links(array $links, string $file): array
782
+	{
783
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
784
+			// before other links
785
+			array_unshift(
786
+				$links,
787
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
788
+				. esc_html__('Settings', 'event_espresso')
789
+				. '</a>'
790
+			);
791
+		}
792
+		return $links;
793
+	}
794
+
795
+
796
+	/**
797
+	 * after_plugin_row
798
+	 * Add additional content to the plugins page plugin row
799
+	 * Inserts another row
800
+	 *
801
+	 * @param string $plugin_file
802
+	 * @param array  $plugin_data
803
+	 * @param string $status
804
+	 * @return void
805
+	 */
806
+	public function after_plugin_row(string $plugin_file, array $plugin_data, string $status)
807
+	{
808
+		$after_plugin_row = '';
809
+		$plugins_page_row = $this->get_plugins_page_row();
810
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
811
+			$class       = $status ? 'active' : 'inactive';
812
+			$link_text   = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
813
+			$link_url    = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
814
+			$description = isset($plugins_page_row['description'])
815
+				? $plugins_page_row['description']
816
+				: '';
817
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
818
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
819
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
820
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
821
+				$after_plugin_row .= '<style>
822 822
 .ee-button,
823 823
 .ee-button:active,
824 824
 .ee-button:visited {
@@ -855,67 +855,67 @@  discard block
 block discarded – undo
855 855
 }
856 856
 .ee-button:active { top:0; }
857 857
 </style>';
858
-                $after_plugin_row .= '
858
+				$after_plugin_row .= '
859 859
 <p class="ee-addon-upsell-info-dv">
860 860
 	<a class="ee-button" href="' . $link_url . '">'
861
-                                     . $link_text
862
-                                     . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
863
-                                     . '</a>
861
+									 . $link_text
862
+									 . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
863
+									 . '</a>
864 864
 </p>';
865
-                $after_plugin_row .= '</td>';
866
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
867
-                $after_plugin_row .= $description;
868
-                $after_plugin_row .= '</td>';
869
-                $after_plugin_row .= '</tr>';
870
-            } else {
871
-                $after_plugin_row .= $description;
872
-            }
873
-        }
874
-
875
-        echo $after_plugin_row;
876
-    }
877
-
878
-
879
-    /**
880
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
881
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
882
-     * for back compat reasons.
883
-     *
884
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
885
-     *
886
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
887
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
888
-     * callback does not get run/set in that request.
889
-     *
890
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
891
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
892
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
893
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
894
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
895
-     * to call `parent::deactivation`.
896
-     *
897
-     * @since 4.9.26
898
-     */
899
-    public function after_registration()
900
-    {
901
-        // cricket chirp... cricket chirp...
902
-    }
903
-
904
-
905
-    /**
906
-     * @return string
907
-     */
908
-    public function getPueSlug(): string
909
-    {
910
-        return $this->pue_slug;
911
-    }
912
-
913
-
914
-    /**
915
-     * @param string $pue_slug
916
-     */
917
-    public function setPueSlug(string $pue_slug)
918
-    {
919
-        $this->pue_slug = $pue_slug;
920
-    }
865
+				$after_plugin_row .= '</td>';
866
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
867
+				$after_plugin_row .= $description;
868
+				$after_plugin_row .= '</td>';
869
+				$after_plugin_row .= '</tr>';
870
+			} else {
871
+				$after_plugin_row .= $description;
872
+			}
873
+		}
874
+
875
+		echo $after_plugin_row;
876
+	}
877
+
878
+
879
+	/**
880
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
881
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
882
+	 * for back compat reasons.
883
+	 *
884
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
885
+	 *
886
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
887
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
888
+	 * callback does not get run/set in that request.
889
+	 *
890
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
891
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
892
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
893
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
894
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
895
+	 * to call `parent::deactivation`.
896
+	 *
897
+	 * @since 4.9.26
898
+	 */
899
+	public function after_registration()
900
+	{
901
+		// cricket chirp... cricket chirp...
902
+	}
903
+
904
+
905
+	/**
906
+	 * @return string
907
+	 */
908
+	public function getPueSlug(): string
909
+	{
910
+		return $this->pue_slug;
911
+	}
912
+
913
+
914
+	/**
915
+	 * @param string $pue_slug
916
+	 */
917
+	public function setPueSlug(string $pue_slug)
918
+	{
919
+		$this->pue_slug = $pue_slug;
920
+	}
921 921
 }
Please login to merge, or discard this patch.